Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug component #2574

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,4 @@ testenv
.cache
.clangd
.llvm/
examples/blocks/src/nypd/nypdccrb.arrow
6 changes: 3 additions & 3 deletions examples/blocks/src/covid/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
sort: [["deathIncrease", "col desc"]],
expressions: {
[`Parsed "date" bucket by week`]: `var year := integer(floor("date" / 10000));
var month := integer(floor("date" / 100)) - year * 100;
var day := integer("date" % 100);
bucket(date(year, month, day), \'W\')`,
var month := integer(floor("date" / 100)) - year * 100;
var day := integer("date" % 100);
bucket(date(year, month, day), \'W\')`,
},
aggregates: {},
};
Expand Down
249 changes: 249 additions & 0 deletions examples/blocks/src/dataset/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
<!--

Copyright (c) 2017, the Perspective Authors.

This file is part of the Perspective library, distributed under the terms of
the Apache License 2.0. The full license can be found in the LICENSE file.

-->

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />

<script type="module" src="/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.js"></script>
<script type="module" src="/node_modules/@finos/perspective-viewer-datagrid/dist/cdn/perspective-viewer-datagrid.js"></script>
<script type="module" src="/node_modules/@finos/perspective-viewer-d3fc/dist/cdn/perspective-viewer-d3fc.js"></script>

<link rel="stylesheet" crossorigin="anonymous" href="/node_modules/@finos/perspective-viewer/dist/css/themes.css" />

<style>

perspective-viewer {
flex: 1;
margin: 24px;
overflow: visible;
}

#app {
display: flex;
flex-direction: column;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #f2f4f6;
}

#controls {
display: flex;
margin: 24px 24px 0px 40px;
}

.range {
position: relative;
display: inline-flex;
flex-direction: column;
margin-right: 24px;
}

span, input, button {
font-family: "Open Sans";
font-size: 12px;
background: none;
margin: 0px;
border-color: #ccc;
color: #666;
padding: 6px 12px 6px 0px;
}

input {
height: 14px;
border-width: 0px;
border-style: solid;
border-bottom-width: 1px;
color: inherit;
outline: none;
}

input[type=range] {
margin-top: 2px;
}

input[type=number] {
font-family: "Roboto Mono";
}

input:focus {
border-color: #1a7da1;
}

input::placeholder {
color: #ccc;
}

button {
border: 1px solid #ccc;
text-transform: uppercase;
text-align: center;
text-decoration: none;
display: inline-block;
padding-left: 12px;
height: 28px;
outline: none;
}

button:hover {
cursor: pointer;
}

#run {
justify-self: center;
margin-right: 24px;
height: 83px;
width: 80px;
}

</style>
</head>

<body>

<div id="app">
<div id="controls">
<button id="run">Run</button>
<div class="range">
<span>Rows</span>
<input id="num_rows" min="25" max="1000000" type="number" placeholder="#" value="10000"></input>
<input id="num_batches" min="1" max="100" type="number" placeholder="#" value="1"></input>
</div>
<div class="range">
<span>Float columns</span>
<input id="num_float" min="0" max="50" type="number" placeholder="#" value="5"></input>
</div>
<div class="range">
<span>Integer columns</span>
<input id="num_integer" min="0" max="50" type="number" placeholder="#" value="5"></input>
</div>
<div class="range">
<span>String columns</span>
<input id="num_string" min="0" max="50" type="number" placeholder="#" value="5"></input>
<input id="num_strings" min="1" max="500" type="number" placeholder="Unique Strings" value="50"></input>
</div>
<div class="range">
<span>Datetime columns</span>
<input id="num_datetime" min="0" max="50" type="number" placeholder="#" value="5"></input>
</div>
<div class="range">
<span>Bool columns</span>
<input id="num_boolean" min="0" max="50" type="number" placeholder="#" value="1"></input>
</div>
</div>

<perspective-viewer
editable
id="viewer">

</perspective-viewer>
</div>

<script type="module">

import perspective from "/node_modules/@finos/perspective/dist/cdn/perspective.js";
const WORKER = perspective.worker();

const choose = x => x[Math.floor(Math.random() * x.length)];
const range = (x, y) => Math.random() * (y - x) + x;
const rand_string = () => Math.random().toString(36).substring(7);
const strings = choices => new Array(choices).fill(null).map(rand_string);
const colname = (name, x) => `${name.charAt(0).toUpperCase() + name.slice(1)} ${x}`;

function* col_iter() {
for (const name of ["float", "integer", "string", "datetime", "boolean"]) {
const ncols = window[`num_${name}`].value;
for (let x = 0; x < ncols; x ++) {
yield [name, x];;
}
}
}

const assign = fn => {
const obj = {};
for (const [name, x] of col_iter()) {
obj[colname(name, x)] = fn(name, x);
}
return obj;
}

const new_schema = () => assign(x => x);

let STRINGS;
function reset_strings_cache() {
STRINGS = {};
}

reset_strings_cache();

const get_dict = xs => {
STRINGS[xs] = STRINGS[xs] || strings(parseInt(num_strings.value));
return STRINGS[xs];
}

const CELL_ARGS = {
"float": () => range(-10, 10),
"integer": () => Math.floor(range(-10, 10)),
"string" : xs => choose(get_dict(xs)),
"datetime": () => new Date(),
"boolean": () => choose([true, false, null])
};

const new_row = () => assign((name, x) => CELL_ARGS[name](x));

const gen_data = async () => {
reset_strings_cache();
let nrows = num_rows.value;
let rows = [];
const batch_size = Math.floor(nrows / num_batches.value);
const tbl = await WORKER.table(new_schema());
(function batch() {
while (nrows > 0) {
rows.push(new_row());
nrows--;
if (nrows % batch_size === 0) {
tbl.update(rows);
rows = [];
setTimeout(batch, 100);
break;
}
}
})();
return tbl;
}

// GUI

const make_run_click_callback = (state) => async () => {
const old_table = state.table
state.table = gen_data();
await window.viewer.load(state.table);
if (old_table) {
old_table.then(old_table => {
if (old_table) {
old_table.delete();
}
});
}
}

// Main

window.addEventListener("DOMContentLoaded", async function () {
run.addEventListener("click", make_run_click_callback({}));
run.dispatchEvent(new Event("click"));
});

</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,25 @@ export function style_selected_column(regularTable, viewer, selectedColumn) {
const group_header_trs = Array.from(
regularTable.children[0].children[0].children
);

const len = group_header_trs.length;
const settings_open = viewer.hasAttribute("settings");
if (len <= 1) {
group_header_trs[0]?.removeAttribute("id");
} else {
group_header_trs.forEach((tr, i) => {
const offset = settings_open ? 1 : 0;
let id =
i === len - 2
i === len - (offset + 1)
? "psp-column-titles"
: i === len - 1
: i === len - offset
? "psp-column-edit-buttons"
: null;
id ? tr.setAttribute("id", id) : tr.removeAttribute("id");
});
}

const settings_open = viewer.hasAttribute("settings");
viewer.classList.toggle("psp-menu-open", !!selectedColumn);

if (settings_open && len >= 2) {
// if settings_open, you will never have less than 2 trs unless the
// table is empty, but possibly more e.g. with group-by.
Expand All @@ -58,7 +59,7 @@ export function style_selected_column(regularTable, viewer, selectedColumn) {
const title = titles[i];
const editBtn = editBtns[i];

let open = title.innerText === selectedColumn;
let open = title.textContent === selectedColumn;
title.classList.toggle("psp-menu-open", open);
editBtn.classList.toggle("psp-menu-open", open);
if (this._config.columns.length > 1) {
Expand Down
9 changes: 6 additions & 3 deletions rust/perspective-viewer/src/less/column-selector.less
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
:host {
#add-expression-button:before {
content: var(--add-expression-button--content, "New Column");
text-transform: uppercase;
font-size: 0.8333333em;
}

.column-selector-column-title {
Expand Down Expand Up @@ -499,9 +501,10 @@
// Inactive Columns are the columns in the column selector not currently
// selected for the `columns` field of the `ViewConfig`.
#sub-columns {
& > div:not(:empty) {
margin-bottom: 6px;
}
padding-bottom: 8px;
// & > div:not(:empty) {
// margin-bottom: 6px;
// }

&:empty {
display: none;
Expand Down
6 changes: 6 additions & 0 deletions rust/perspective-viewer/src/less/column-settings-panel.less
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
margin-top: 4px;
}

#attributes-tab {
flex-direction: column;
display: flex;
overflow: hidden;
}

#attributes-tab > .split-panel-child {
min-height: 200px;
flex: 0 1 auto;
Expand Down
2 changes: 1 addition & 1 deletion rust/perspective-viewer/src/less/column-style.less
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
select {
cursor: pointer;
font-size: 10px;
height: 24px;
height: 22px;
// padding-bottom: 2px;
// border-bottom: 1px solid var(--input--border-color, #ccc);
padding: 0 8px;
Expand Down
2 changes: 1 addition & 1 deletion rust/perspective-viewer/src/less/config-selector.less
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
&:before {
font-family: var(--button--font-family, inherit);
color: var(--inactive--color, #666);
content: var(--transpose-button--content, "\21C4");
content: var(--transpose-button--content, "Swap");
}
}
}
Expand Down
15 changes: 13 additions & 2 deletions rust/perspective-viewer/src/less/containers/tabs.less
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,24 @@
}
}
}

#format-tab {
overflow: scroll;
}

.tab-content {
@include scrollbar;
flex: 1 1 auto;
overflow: hidden;
display: flex;
flex-direction: column;
.tab-section:last-child {
padding: 12px 8px 12px 8px;
}

.tab-section {
padding: 8px 8px 12px 8px;
flex: 0 1 auto;
padding: 12px 8px 0px 8px;
flex: 0 0 auto;
overflow: hidden;
}

Expand Down
Loading
Loading