Skip to content
Draft
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
38 changes: 38 additions & 0 deletions packages/viewer-datagrid/src/css/regular_table.css
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ tbody th:last-of-type {
overflow: hidden;
text-overflow: ellipsis;
}

tbody th:empty {
background-image: linear-gradient(
to right,
Expand Down Expand Up @@ -316,12 +317,44 @@ regular-table:not(.flat-group-rollup-mode) {
.psp-align-right {
text-align: right;
}

.psp-color-mode-label-bar {
position: relative;
isolation: isolate;
}

.psp-label-bar {
inset: 0;
pointer-events: none;
display: flex;
align-items: center;
justify-content: flex-end;
padding: 0px;
}

.psp-label-bar-fill {
position: absolute;
top: 10%;
height: 80%;
background: var(--psp-label-bar-color);
pointer-events: none;
}

.psp-label-bar-text {
position: relative;
color: var(--psp-label-bar-bg);
mix-blend-mode: difference;
pointer-events: none;
}

.psp-align-left {
text-align: left;
}

.psp-positive:not(:focus) {
color: var(--psp-datagrid--pos-cell--color);
}

.psp-negative:not(:focus) {
color: var(--psp-datagrid--neg-cell--color);
}
Expand Down Expand Up @@ -363,6 +396,7 @@ regular-table table {

th.psp-header-leaf {
border-bottom-width: 0px;

span {
height: 23px;
min-height: 23px;
Expand Down Expand Up @@ -479,6 +513,7 @@ regular-table table tbody tr:hover + tr:after {
rgba(0, 128, 255, 0.5)
);
}

100% {
background-color: var(
--pulse--background-color-end,
Expand All @@ -494,6 +529,7 @@ regular-table table tbody tr:hover + tr:after {
rgba(0, 128, 255, 0.5)
);
}

100% {
background-color: var(
--pulse--background-color-end,
Expand All @@ -509,6 +545,7 @@ regular-table table tbody tr:hover + tr:after {
rgba(255, 25, 0, 0.5)
);
}

100% {
background-color: var(
--pulse--background-color-end,
Expand All @@ -524,6 +561,7 @@ regular-table table tbody tr:hover + tr:after {
rgba(255, 25, 0, 0.5)
);
}

100% {
background-color: var(
--pulse--background-color-end,
Expand Down
9 changes: 3 additions & 6 deletions packages/viewer-datagrid/src/ts/custom_elements/datagrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,11 @@ export class HTMLPerspectiveViewerDatagridPluginElement
this.regular_table.clear();
}

async save(): Promise<any> {
save(): any {
return save.call(this);
}

async restore(
token: DatagridPluginConfig,
columns_config?: ColumnsConfig,
): Promise<any> {
restore(token: DatagridPluginConfig, columns_config?: ColumnsConfig): void {
return restore.call(this, token, columns_config ?? {});
}

Expand All @@ -243,7 +240,7 @@ export class HTMLPerspectiveViewerDatagridPluginElement
}
}

async delete(): Promise<void> {
delete(): void {
this.disconnectedCallback();
this._toolbar = undefined;
if ((this.regular_table as any).table_model) {
Expand Down
44 changes: 37 additions & 7 deletions packages/viewer-datagrid/src/ts/data_listener/format_cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export function format_cell(
const plugin: ColumnConfig = plugins[title] || {};
const is_numeric = type === "integer" || type === "float";

if (is_numeric && plugin?.number_fg_mode === "bar") {
if (
is_numeric &&
(plugin?.number_fg_mode === "bar" ||
plugin?.number_fg_mode === "label-bar")
) {
const a = Math.max(
0,
Math.min(
Expand All @@ -54,15 +58,41 @@ export function format_cell(
),
);

const div = this._div_factory.get();
const anchor = (val as number) >= 0 ? "left" : "right";
const pct = (a * 100).toFixed(2);
div.setAttribute(
"style",
`width:calc(${pct}% - 4px);position:absolute;${anchor}:2px;height:80%;top:10%;pointer-events:none;`,
);

return div;
if (plugin.number_fg_mode === "bar") {
const div = this._div_factory.get();
div.className = "psp-bar";
div.setAttribute(
"style",
`width:calc(${pct}% - 4px);position:absolute;${anchor}:2px;height:80%;top:10%;pointer-events:none;`,
);

return div;
} else {
const wrapper = this._div_factory.get();
wrapper.setAttribute("style", "");
wrapper.className = "psp-label-bar";
while (wrapper.firstChild) {
wrapper.removeChild(wrapper.firstChild);
}
const bar = document.createElement("div");
bar.className = "psp-label-bar-fill";
bar.setAttribute(
"style",
`width:calc(${pct}% - 4px);${anchor}:2px;`,
);
const label = document.createElement("span");
label.className = "psp-label-bar-text";
const formatter = FORMAT_CACHE.get(type, plugin);
label.textContent = formatter
? formatter.format(val)
: (val as string);
wrapper.appendChild(bar);
wrapper.appendChild(label);
return wrapper;
}
} else if (plugin?.format === "link" && type === "string") {
const anchor = document.createElement("a");
anchor.setAttribute("href", val as string);
Expand Down
17 changes: 13 additions & 4 deletions packages/viewer-datagrid/src/ts/model/column_overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export function restore_column_size_overrides(
this._cached_column_sizes = old_sizes;
}

const overrides: Record<number, number | undefined> = {};
const regular_table = this.regular_table as RegularTableWithOverrides;
const overrides: Record<number, number | undefined> = {
...regular_table.saveColumnSizes(),
};
const { group_by } = this.model!._config;
const tree_header_offset = group_by?.length > 0 ? group_by.length + 1 : 0;

Expand All @@ -57,15 +60,21 @@ export function restore_column_size_overrides(
| undefined;
} else {
const index = this.model!._column_paths.indexOf(key);
// Skip keys that don't resolve to a known column — e.g. on the
// first draw after `activate`, `_column_paths` has not yet been
// populated by the data listener, so we leave any existing
// `regular-table` widths untouched rather than clobbering them
// with garbage indices.
if (index === -1) {
continue;
}
overrides[index + tree_header_offset] = old_sizes[key] as
| number
| undefined;
}
}

(this.regular_table as RegularTableWithOverrides).restoreColumnSizes(
overrides,
);
regular_table.restoreColumnSizes(overrides);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions packages/viewer-datagrid/src/ts/model/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export function toggle_edit_mode(
if (this._edit_button !== undefined) {
this._edit_button.dataset.editMode = mode;
}

this.dataset.editMode = mode;
}

export function toggle_scroll_lock(
Expand Down
1 change: 1 addition & 0 deletions packages/viewer-datagrid/src/ts/plugin/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ export function save(

return JSON.parse(JSON.stringify(token));
}

return {};
}
5 changes: 5 additions & 0 deletions packages/viewer-datagrid/src/ts/style_handlers/body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ export function applyBodyCellStyles(
plugin?.number_fg_mode === "bar" && is_numeric,
);

td.classList.toggle(
"psp-color-mode-label-bar",
plugin?.number_fg_mode === "label-bar" && is_numeric,
);

// Apply row header styling
if (isHeader) {
cell_style_row_header.call(this, regularTable, td, metadata as any);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ function isEditableMode(
const has_pivots =
model._config.group_by.length === 0 &&
model._config.split_by.length === 0;

const selectable = viewer.hasAttribute("selectable");
const plugin = viewer.children[0] as
| (DatagridPluginElement & { dataset: DOMStringMap })
| undefined;
const editable = allowed || plugin?.dataset?.editMode === "EDIT";
const editable = allowed || model._edit_mode === "EDIT";
return has_pivots && !selectable && editable;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function applyGroupHeaderStyles(
);

td.classList.toggle("psp-color-mode-bar", false);
td.classList.toggle("psp-color-mode-label-bar", false);
td.classList.toggle("psp-header-sort-asc", false);
td.classList.toggle("psp-header-sort-desc", false);
td.classList.toggle("psp-header-sort-col-asc", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ export function cell_style_numeric(
) {
(td.children[0] as HTMLElement).style.background = gradhex;
}
} else if (plugin?.number_fg_mode === "label-bar") {
td.style.color = "";
td.style.setProperty("--psp-label-bar-color", gradhex);
td.style.setProperty("--psp-label-bar-bg", hex);
} else if (plugin?.number_fg_mode === "color" || !plugin?.number_fg_mode) {
td.style.color = hex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ impl Component for NumberColumnStyle {
<NumberField ..self.max_value_props(Fg, ctx) />
</>
},
NumberForegroundMode::LabelBar => html! {
<>
<div class="row">
<ColorRangeSelector ..self.color_props("label-bar-color", Fg, false, ctx) />
</div>
<NumberField ..self.max_value_props(Fg, ctx) />
</>
},
};

let bg_controls = match self.bg_mode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub enum NumberForegroundMode {

#[serde(rename = "bar")]
Bar,

#[serde(rename = "label-bar")]
LabelBar,
}

impl FromStr for NumberForegroundMode {
Expand All @@ -38,6 +41,7 @@ impl FromStr for NumberForegroundMode {
match s {
"color" => Ok(Self::Color),
"bar" => Ok(Self::Bar),
"label-bar" => Ok(Self::LabelBar),
x => Err(format!("Unknown NumberForegroundMode::{x}")),
}
}
Expand All @@ -53,7 +57,7 @@ impl NumberForegroundMode {
}

pub fn needs_gradient(&self) -> bool {
*self == Self::Bar
*self == Self::Bar || *self == Self::LabelBar
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ impl PerspectiveDebugPluginElement {
ApiFuture::default()
}

pub fn save(&self) -> ApiFuture<()> {
ApiFuture::default()
pub fn save(&self) -> ApiResult<JsValue> {
Ok(JsValue::null())
}

pub fn restore(&self) -> ApiFuture<()> {
ApiFuture::default()
pub fn restore(&self, _config: Option<JsValue>) -> ApiResult<()> {
Ok(())
}

pub fn delete(&self) -> ApiFuture<()> {
Expand Down
10 changes: 5 additions & 5 deletions rust/perspective-viewer/src/ts/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,17 @@ export interface IPerspectiveViewerPlugin {
* reload. For example, `@perspective-dev/viewer-d3fc` uses
* `plugin_config` to remember the user-repositionable legend coordinates.
*/
save(): Promise<any>;
save(): any;

/**
* Restore this plugin to a state previously returned by `save()`.
*/
restore(config: any): Promise<void>;
restore(config: any): void;

/**
* Free any resources acquired by this plugin and prepare to be deleted.
*/
delete(): Promise<void>;
delete(): void;
}

/**
Expand Down Expand Up @@ -265,11 +265,11 @@ export class HTMLPerspectiveViewerPluginElement
// Not Implemented
}

async save(): Promise<any> {
save(): any {
// Not Implemented
}

async restore(): Promise<void> {
restore(): void {
// Not Implemented
}

Expand Down
2 changes: 1 addition & 1 deletion rust/perspective-viewer/test/js/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const DEFAULT_CONFIG: ViewerConfigUpdate = {
group_by: [],
group_rollup_mode: "rollup",
plugin: "",
plugin_config: {},
plugin_config: null,
settings: false,
sort: [],
split_by: [],
Expand Down
2 changes: 1 addition & 1 deletion rust/perspective-viewer/test/js/viewer_api/dom.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const RESULT = {
filter: [],
group_by: [],
plugin: "Debug",
plugin_config: {},
plugin_config: null,
settings: false,
sort: [],
split_by: [],
Expand Down
Loading
Loading