@aquera/nile-visualization 2.9.27 → 2.9.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/internal/dashboard-adapters.d.ts +4 -0
- package/dist/src/internal/dashboard-adapters.js +9 -3
- package/dist/src/internal/highcharts-provider.js +1 -0
- package/dist/src/nile-chart/nile-chart.css.js +4 -0
- package/dist/src/nile-dashboard-builder/gridstack-css.d.ts +1 -0
- package/dist/src/nile-dashboard-builder/gridstack-css.js +6 -0
- package/dist/src/nile-dashboard-builder/index.d.ts +1 -0
- package/dist/src/nile-dashboard-builder/index.js +2 -0
- package/dist/src/nile-dashboard-builder/nile-dashboard-builder.css.d.ts +1 -0
- package/dist/src/nile-dashboard-builder/nile-dashboard-builder.css.js +80 -0
- package/dist/src/nile-dashboard-builder/nile-dashboard-builder.d.ts +66 -0
- package/dist/src/nile-dashboard-builder/nile-dashboard-builder.js +317 -0
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -35,6 +35,10 @@ To run a local development server that serves the basic demo located in `demo/in
|
|
|
35
35
|
## Release Notes
|
|
36
36
|
|
|
37
37
|
In this section, you can find the updates for each release of `nile-visualization`. It's a good practice to maintain detailed release notes to help users and developers understand what changes have been made from one version to another and how these changes might affect their projects.
|
|
38
|
+
|
|
39
|
+
#### Version 2.9.28 (July 22, 2026)
|
|
40
|
+
- Nile Dashboard Builder: Added Nile Dashboard Builder Component (UIF-1309)
|
|
41
|
+
|
|
38
42
|
#### Version 2.9.27 (July 15, 2026)
|
|
39
43
|
- Nile Filter Chart: Added the `date-picker` control variant — set `variant: 'date-picker'` on a filter control to render a calendar field. Configurable via `selection` (`single` for one date, `multi` for a start/end range), `dateFormat` (default `MM/DD/YYYY`), `dateType` (`absolute` | `relative`), `hideDateTypes` (lock the absolute/relative switcher), `showClearButton`, and `hoist` (switch the popup to `position: fixed` to escape a clipping ancestor). The date-picker fills its container — size it by constraining the wrapping element. See `src/nile-filter-chart/date-picker.md` (UIF-1298)
|
|
40
44
|
- Nile Chart: Added the `noPadding` config option — set `noPadding: true` on the chart config to remove the chart body padding and drop the card's own border/shadow, so the content sits flush to the card edges (the card becomes a transparent, layout-only wrapper); reflected as the `no-padding` attribute (UIF-1298)
|
package/dist/src/index.d.ts
CHANGED
|
@@ -107,6 +107,8 @@ export { NileWidgetViewer } from './nile-widget-viewer/index.js';
|
|
|
107
107
|
export type { NileWidgetConfig, NileWidgetChartConfig, NileWidgetKpiConfig, WidgetLayout, } from './nile-widget-viewer/index.js';
|
|
108
108
|
export { NileDashboardViewer } from './nile-dashboard-viewer/index.js';
|
|
109
109
|
export type { NileDashboardConfig } from './nile-dashboard-viewer/index.js';
|
|
110
|
+
export { NileDashboardBuilder } from './nile-dashboard-builder/index.js';
|
|
111
|
+
export { fromApiDashboardResponse } from './internal/dashboard-adapters.js';
|
|
110
112
|
export { NileExecutiveSummary } from './nile-executive-summary/index.js';
|
|
111
113
|
export type { NileExecutiveSummaryConfig } from './nile-executive-summary/index.js';
|
|
112
114
|
export { NileChartList } from './nile-chart-list/index.js';
|
package/dist/src/index.js
CHANGED
|
@@ -57,6 +57,8 @@ export { NileAiSender } from './nile-ai-sender/index.js';
|
|
|
57
57
|
export { NileAiPanel } from './nile-ai-panel/index.js';
|
|
58
58
|
export { NileWidgetViewer } from './nile-widget-viewer/index.js';
|
|
59
59
|
export { NileDashboardViewer } from './nile-dashboard-viewer/index.js';
|
|
60
|
+
export { NileDashboardBuilder } from './nile-dashboard-builder/index.js';
|
|
61
|
+
export { fromApiDashboardResponse } from './internal/dashboard-adapters.js';
|
|
60
62
|
export { NileExecutiveSummary } from './nile-executive-summary/index.js';
|
|
61
63
|
export { NileChartList } from './nile-chart-list/index.js';
|
|
62
64
|
//# sourceMappingURL=index.js.map
|
|
@@ -5,10 +5,14 @@ import type { NileDashboardConfig } from './types/dashboard-config.type.js';
|
|
|
5
5
|
*
|
|
6
6
|
* Handles:
|
|
7
7
|
* - `widgetType` → `type` rename
|
|
8
|
+
* - `config` (data-visualizer-ui / angular-gridster2) → `nileConfig`
|
|
8
9
|
* - Gridster-native layout keys (`cols`/`rows`) → canonical (`w`/`h`)
|
|
9
10
|
* - API chart `series[].data[].value` → `data[].y` (pie/donut)
|
|
10
11
|
* - Multi-series format for bar/line/column/area etc.
|
|
11
12
|
* - KPI sub-object: adds the `type: 'kpi'` discriminator
|
|
12
13
|
* - Nested `{ success, data: { ... } }` API envelope
|
|
14
|
+
*
|
|
15
|
+
* The result plugs straight into `<nile-dashboard-viewer>` or
|
|
16
|
+
* `<nile-dashboard-builder>` (`.config`).
|
|
13
17
|
*/
|
|
14
18
|
export declare function fromApiDashboardResponse(apiResponse: unknown): NileDashboardConfig;
|
|
@@ -73,14 +73,16 @@ function normalizeLayout(raw) {
|
|
|
73
73
|
function adaptWidget(apiWidget) {
|
|
74
74
|
const layout = normalizeLayout(apiWidget.layout);
|
|
75
75
|
const widgetType = apiWidget.widgetType ?? apiWidget.type;
|
|
76
|
-
// Already
|
|
77
|
-
|
|
76
|
+
// Already Nile-ready `{ chart, aq }` — under `nileConfig` (our shape) or
|
|
77
|
+
// `config` (data-visualizer-ui / angular-gridster2 shape). Pass through.
|
|
78
|
+
const nileConfig = apiWidget.nileConfig ?? apiWidget.config;
|
|
79
|
+
if (nileConfig) {
|
|
78
80
|
return {
|
|
79
81
|
id: apiWidget.id,
|
|
80
82
|
title: apiWidget.title,
|
|
81
83
|
type: widgetType,
|
|
82
84
|
layout,
|
|
83
|
-
nileConfig
|
|
85
|
+
nileConfig,
|
|
84
86
|
};
|
|
85
87
|
}
|
|
86
88
|
if (widgetType === 'chart' && apiWidget.chart) {
|
|
@@ -110,11 +112,15 @@ function adaptWidget(apiWidget) {
|
|
|
110
112
|
*
|
|
111
113
|
* Handles:
|
|
112
114
|
* - `widgetType` → `type` rename
|
|
115
|
+
* - `config` (data-visualizer-ui / angular-gridster2) → `nileConfig`
|
|
113
116
|
* - Gridster-native layout keys (`cols`/`rows`) → canonical (`w`/`h`)
|
|
114
117
|
* - API chart `series[].data[].value` → `data[].y` (pie/donut)
|
|
115
118
|
* - Multi-series format for bar/line/column/area etc.
|
|
116
119
|
* - KPI sub-object: adds the `type: 'kpi'` discriminator
|
|
117
120
|
* - Nested `{ success, data: { ... } }` API envelope
|
|
121
|
+
*
|
|
122
|
+
* The result plugs straight into `<nile-dashboard-viewer>` or
|
|
123
|
+
* `<nile-dashboard-builder>` (`.config`).
|
|
118
124
|
*/
|
|
119
125
|
export function fromApiDashboardResponse(apiResponse) {
|
|
120
126
|
const raw = apiResponse;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const gridstackCss: import("lit").CSSResult;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// gridstack CSS inlined so it can be injected into the component's shadow root.
|
|
2
|
+
// Source: gridstack@12.6.0 dist/gridstack.min.css
|
|
3
|
+
// Re-paste from node_modules/gridstack/dist/gridstack.min.css when bumping the gridstack version.
|
|
4
|
+
import { unsafeCSS } from 'lit';
|
|
5
|
+
export const gridstackCss = unsafeCSS(`.grid-stack{position:relative}.grid-stack-rtl{direction:ltr}.grid-stack-rtl>.grid-stack-item{direction:rtl}.grid-stack-placeholder>.placeholder-content{background-color:rgba(0,0,0,.1);margin:0;position:absolute;width:auto;z-index:0!important}.grid-stack>.grid-stack-item{position:absolute;padding:0;top:0;width:var(--gs-column-width);height:var(--gs-cell-height)}.grid-stack>.grid-stack-item>.grid-stack-item-content{margin:0;position:absolute;width:auto;overflow-x:hidden;overflow-y:auto}.grid-stack>.grid-stack-item.size-to-content:not(.size-to-content-max)>.grid-stack-item-content{overflow-y:hidden}.grid-stack:not(.grid-stack-rtl)>.grid-stack-item{left:0}.grid-stack.grid-stack-rtl>.grid-stack-item{right:0}.grid-stack>.grid-stack-item>.grid-stack-item-content,.grid-stack>.grid-stack-placeholder>.placeholder-content{top:var(--gs-item-margin-top);right:var(--gs-item-margin-right);bottom:var(--gs-item-margin-bottom);left:var(--gs-item-margin-left)}.grid-stack-item>.ui-resizable-handle{position:absolute;font-size:.1px;display:block;-ms-touch-action:none;touch-action:none}.grid-stack-item.ui-resizable-autohide>.ui-resizable-handle,.grid-stack-item.ui-resizable-disabled>.ui-resizable-handle{display:none}.grid-stack-item>.ui-resizable-ne,.grid-stack-item>.ui-resizable-nw,.grid-stack-item>.ui-resizable-se,.grid-stack-item>.ui-resizable-sw{background-image:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="%23666" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 20 20"><path d="m10 3 2 2H8l2-2v14l-2-2h4l-2 2"/></svg>');background-repeat:no-repeat;background-position:center}.grid-stack-item>.ui-resizable-ne{transform:rotate(45deg)}.grid-stack-item>.ui-resizable-sw{transform:rotate(45deg)}.grid-stack-item>.ui-resizable-nw{transform:rotate(-45deg)}.grid-stack-item>.ui-resizable-se{transform:rotate(-45deg)}.grid-stack-item>.ui-resizable-nw{cursor:nw-resize;width:20px;height:20px;top:var(--gs-item-margin-top);left:var(--gs-item-margin-left)}.grid-stack-item>.ui-resizable-n{cursor:n-resize;height:10px;top:var(--gs-item-margin-top);left:25px;right:25px}.grid-stack-item>.ui-resizable-ne{cursor:ne-resize;width:20px;height:20px;top:var(--gs-item-margin-top);right:var(--gs-item-margin-right)}.grid-stack-item>.ui-resizable-e{cursor:e-resize;width:10px;top:15px;bottom:15px;right:var(--gs-item-margin-right)}.grid-stack-item>.ui-resizable-se{cursor:se-resize;width:20px;height:20px;bottom:var(--gs-item-margin-bottom);right:var(--gs-item-margin-right)}.grid-stack-item>.ui-resizable-s{cursor:s-resize;height:10px;left:25px;bottom:var(--gs-item-margin-bottom);right:25px}.grid-stack-item>.ui-resizable-sw{cursor:sw-resize;width:20px;height:20px;bottom:var(--gs-item-margin-bottom);left:var(--gs-item-margin-left)}.grid-stack-item>.ui-resizable-w{cursor:w-resize;width:10px;top:15px;bottom:15px;left:var(--gs-item-margin-left)}.grid-stack-item.ui-draggable-dragging>.ui-resizable-handle{display:none!important}.grid-stack-item.ui-draggable-dragging{will-change:left,right,top}.grid-stack-item.ui-resizable-resizing{will-change:width,height}.ui-draggable-dragging,.ui-resizable-resizing{z-index:10000}.ui-draggable-dragging>.grid-stack-item-content,.ui-resizable-resizing>.grid-stack-item-content{box-shadow:1px 4px 6px rgba(0,0,0,.2);opacity:.8}.grid-stack-animate,.grid-stack-animate .grid-stack-item{transition:left .3s,right .3s,top .3s,height .3s,width .3s}.grid-stack-animate .grid-stack-item.grid-stack-placeholder,.grid-stack-animate .grid-stack-item.ui-draggable-dragging,.grid-stack-animate .grid-stack-item.ui-resizable-resizing{transition:left 0s,right 0s,top 0s,height 0s,width 0s}.grid-stack>.grid-stack-item[gs-y="0"]{top:0}.grid-stack:not(.grid-stack-rtl)>.grid-stack-item[gs-x="0"]{left:0}.grid-stack.grid-stack-rtl>.grid-stack-item[gs-x="0"]{right:0}`);
|
|
6
|
+
//# sourceMappingURL=gridstack-css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { NileDashboardBuilder } from './nile-dashboard-builder.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const styles: import("lit").CSSResult;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
export const styles = css `
|
|
3
|
+
:host {
|
|
4
|
+
display: block;
|
|
5
|
+
width: 100%;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
:host([hidden]) {
|
|
9
|
+
display: none;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.grid-stack {
|
|
13
|
+
width: 100%;
|
|
14
|
+
min-height: var(--nile-dashboard-builder-min-height, var(--ng-spacing-20));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* Grid-line overlay: one continuous line per cell boundary, using gridstack's
|
|
18
|
+
own layout variables so lines track the actual cells at any columns /
|
|
19
|
+
cell-height / gap. Shown when the gridlines attribute is present. */
|
|
20
|
+
:host([gridlines]) .grid-stack {
|
|
21
|
+
--_gl: var(--nile-dashboard-builder-grid-line, var(--ng-color-blue-200));
|
|
22
|
+
--_bw: var(--ng-border-width-1);
|
|
23
|
+
background-image:
|
|
24
|
+
linear-gradient(to right, var(--_gl) var(--_bw), transparent var(--_bw)),
|
|
25
|
+
linear-gradient(to bottom, var(--_gl) var(--_bw), transparent var(--_bw));
|
|
26
|
+
background-size: var(--gs-column-width) 100%, 100% var(--gs-cell-height);
|
|
27
|
+
background-repeat: repeat;
|
|
28
|
+
/* Close the right/bottom edges (the repeating lines only mark cell starts). */
|
|
29
|
+
box-shadow: inset 0 0 0 var(--_bw) var(--_gl);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Resize handles: keep the full hit areas and resize cursors, but render no
|
|
33
|
+
arrow icons — resizing works by grabbing an edge/corner directly. */
|
|
34
|
+
.grid-stack-item > .ui-resizable-handle {
|
|
35
|
+
background-image: none;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* The cell wrapper hosts the widget viewer + the remove control. */
|
|
39
|
+
.nile-builder-cell {
|
|
40
|
+
position: relative;
|
|
41
|
+
width: 100%;
|
|
42
|
+
height: 100%;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* Widgets fill the cell (gridstack absolutely-positions the content box). */
|
|
46
|
+
.nile-builder-cell > nile-widget-viewer {
|
|
47
|
+
display: block;
|
|
48
|
+
width: 100%;
|
|
49
|
+
height: 100%;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.nile-builder-remove {
|
|
53
|
+
position: absolute;
|
|
54
|
+
top: var(--ng-spacing-1);
|
|
55
|
+
right: var(--ng-spacing-1);
|
|
56
|
+
z-index: 2;
|
|
57
|
+
width: var(--ng-spacing-6);
|
|
58
|
+
height: var(--ng-spacing-6);
|
|
59
|
+
padding: var(--ng-spacing-0);
|
|
60
|
+
line-height: 1;
|
|
61
|
+
border: var(--ng-border-width-1) var(--ng-border-style-solid)
|
|
62
|
+
var(--ng-color-base-transparent);
|
|
63
|
+
border-radius: var(--ng-radius-xs);
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
background: var(--ng-colors-bg-error-solid);
|
|
66
|
+
color: var(--ng-colors-text-white);
|
|
67
|
+
font-size: var(--ng-font-size-text-xs);
|
|
68
|
+
transition: background var(--ng-transition-duration-fast) ease;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.nile-builder-remove:hover {
|
|
72
|
+
background: var(--ng-colors-bg-error-solid-hover);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* Hide the remove affordance when the builder is locked. */
|
|
76
|
+
:host(:not([editable])) .nile-builder-remove {
|
|
77
|
+
display: none;
|
|
78
|
+
}
|
|
79
|
+
`;
|
|
80
|
+
//# sourceMappingURL=nile-dashboard-builder.css.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
|
|
2
|
+
import NileElement from '../internal/nile-element.js';
|
|
3
|
+
import type { NileDashboardConfig } from '../internal/types/dashboard-config.type.js';
|
|
4
|
+
import '../nile-widget-viewer/index.js';
|
|
5
|
+
export declare class NileDashboardBuilder extends NileElement {
|
|
6
|
+
static styles: CSSResultGroup;
|
|
7
|
+
/** Dashboard configuration. Widgets without an `id` are assigned one. */
|
|
8
|
+
config: NileDashboardConfig | null;
|
|
9
|
+
/** Number of grid columns. Default: 12. */
|
|
10
|
+
columns: number;
|
|
11
|
+
/** Row height in pixels. Default: 72 (matches gridster `fixedRowHeight`). */
|
|
12
|
+
cellHeight: number;
|
|
13
|
+
/** Gap between cells in pixels. Default: 8. */
|
|
14
|
+
gap: number;
|
|
15
|
+
minRows: number;
|
|
16
|
+
/** Minimum widget width in columns (gridster `minItemCols`). Default: 2. */
|
|
17
|
+
minW: number;
|
|
18
|
+
/** Minimum widget height in rows (gridster `minItemRows`). Default: 2. */
|
|
19
|
+
minH: number;
|
|
20
|
+
resizeHandles: string;
|
|
21
|
+
float: boolean;
|
|
22
|
+
editable: boolean;
|
|
23
|
+
gridLines: boolean;
|
|
24
|
+
gridLineColor: string;
|
|
25
|
+
private gridEl;
|
|
26
|
+
private grid?;
|
|
27
|
+
/** id -> the `.grid-stack-item` element hosting that widget. */
|
|
28
|
+
private itemEls;
|
|
29
|
+
/** id -> the latest widget config (used to rebuild config on layout change). */
|
|
30
|
+
private widgetById;
|
|
31
|
+
/** Guards against re-emitting while we apply config programmatically. */
|
|
32
|
+
private applying;
|
|
33
|
+
/** Signature of the last layout we applied/emitted, to suppress echoes. */
|
|
34
|
+
private lastSig;
|
|
35
|
+
private idCounter;
|
|
36
|
+
/** True when a config change came from a component method and should be emitted. */
|
|
37
|
+
private internalChange;
|
|
38
|
+
firstUpdated(): void;
|
|
39
|
+
updated(changed: PropertyValues<this>): void;
|
|
40
|
+
disconnectedCallback(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Applies the current `config` to the grid (add/remove/update items). When the
|
|
43
|
+
* change originated from a component method (`internalChange`), emits the
|
|
44
|
+
* resulting config *after* the grid is updated — this avoids a race where
|
|
45
|
+
* emitting before the grid mutation would discard the add/remove.
|
|
46
|
+
*/
|
|
47
|
+
private reconcile;
|
|
48
|
+
/** Builds a `.grid-stack-item` hosting the widget viewer plus a remove control. */
|
|
49
|
+
private createItem;
|
|
50
|
+
/** Adds a starter chart or KPI widget at the bottom of the grid. */
|
|
51
|
+
addWidget(type: 'chart' | 'kpi'): void;
|
|
52
|
+
removeWidget(id: string): void;
|
|
53
|
+
requestRemoveWidget(id: string): boolean;
|
|
54
|
+
/** Reads the true layout back from gridstack and emits the updated config. */
|
|
55
|
+
private emitFromGrid;
|
|
56
|
+
/** Ensures every widget has a stable id (assigned in place if missing). */
|
|
57
|
+
private normalizeWidgets;
|
|
58
|
+
/** Order-independent signature of the current layout + content. */
|
|
59
|
+
private signature;
|
|
60
|
+
render(): TemplateResult;
|
|
61
|
+
}
|
|
62
|
+
declare global {
|
|
63
|
+
interface HTMLElementTagNameMap {
|
|
64
|
+
'nile-dashboard-builder': NileDashboardBuilder;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { customElement, property, query } from 'lit/decorators.js';
|
|
3
|
+
import { html } from 'lit';
|
|
4
|
+
import { GridStack } from 'gridstack';
|
|
5
|
+
import NileElement from '../internal/nile-element.js';
|
|
6
|
+
import { styles } from './nile-dashboard-builder.css.js';
|
|
7
|
+
import { gridstackCss } from './gridstack-css.js';
|
|
8
|
+
import '../nile-widget-viewer/index.js';
|
|
9
|
+
let NileDashboardBuilder = class NileDashboardBuilder extends NileElement {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
/** Dashboard configuration. Widgets without an `id` are assigned one. */
|
|
13
|
+
this.config = null;
|
|
14
|
+
/** Number of grid columns. Default: 12. */
|
|
15
|
+
this.columns = 12;
|
|
16
|
+
/** Row height in pixels. Default: 72 (matches gridster `fixedRowHeight`). */
|
|
17
|
+
this.cellHeight = 72;
|
|
18
|
+
/** Gap between cells in pixels. Default: 8. */
|
|
19
|
+
this.gap = 8;
|
|
20
|
+
this.minRows = 4;
|
|
21
|
+
/** Minimum widget width in columns (gridster `minItemCols`). Default: 2. */
|
|
22
|
+
this.minW = 2;
|
|
23
|
+
/** Minimum widget height in rows (gridster `minItemRows`). Default: 2. */
|
|
24
|
+
this.minH = 2;
|
|
25
|
+
this.resizeHandles = 'n,e,s,w,se,sw,nw';
|
|
26
|
+
this.float = true;
|
|
27
|
+
this.editable = true;
|
|
28
|
+
this.gridLines = true;
|
|
29
|
+
this.gridLineColor = '';
|
|
30
|
+
/** id -> the `.grid-stack-item` element hosting that widget. */
|
|
31
|
+
this.itemEls = new Map();
|
|
32
|
+
/** id -> the latest widget config (used to rebuild config on layout change). */
|
|
33
|
+
this.widgetById = new Map();
|
|
34
|
+
/** Guards against re-emitting while we apply config programmatically. */
|
|
35
|
+
this.applying = false;
|
|
36
|
+
/** Signature of the last layout we applied/emitted, to suppress echoes. */
|
|
37
|
+
this.lastSig = '';
|
|
38
|
+
this.idCounter = 0;
|
|
39
|
+
/** True when a config change came from a component method and should be emitted. */
|
|
40
|
+
this.internalChange = false;
|
|
41
|
+
}
|
|
42
|
+
firstUpdated() {
|
|
43
|
+
this.grid = GridStack.init({
|
|
44
|
+
column: this.columns,
|
|
45
|
+
cellHeight: this.cellHeight,
|
|
46
|
+
margin: this.gap,
|
|
47
|
+
float: this.float,
|
|
48
|
+
staticGrid: !this.editable,
|
|
49
|
+
minRow: this.minRows || undefined,
|
|
50
|
+
// Resize handles (configurable via `resize-handles`); default is 8-way,
|
|
51
|
+
// matching gridster's `resizable.handles`.
|
|
52
|
+
resizable: { handles: this.resizeHandles },
|
|
53
|
+
}, this.gridEl);
|
|
54
|
+
this.grid.on('change', () => {
|
|
55
|
+
if (!this.applying)
|
|
56
|
+
this.emitFromGrid();
|
|
57
|
+
});
|
|
58
|
+
// Nudge chart libraries (Highcharts) that reflow on window resize.
|
|
59
|
+
this.grid.on('resizestop', () => window.dispatchEvent(new Event('resize')));
|
|
60
|
+
void this.reconcile();
|
|
61
|
+
}
|
|
62
|
+
updated(changed) {
|
|
63
|
+
if (this.grid) {
|
|
64
|
+
if (changed.has('columns'))
|
|
65
|
+
this.grid.column(this.columns);
|
|
66
|
+
if (changed.has('cellHeight'))
|
|
67
|
+
this.grid.cellHeight(this.cellHeight);
|
|
68
|
+
if (changed.has('gap'))
|
|
69
|
+
this.grid.margin(this.gap);
|
|
70
|
+
if (changed.has('float'))
|
|
71
|
+
this.grid.float(this.float);
|
|
72
|
+
if (changed.has('editable'))
|
|
73
|
+
this.grid.setStatic(!this.editable);
|
|
74
|
+
}
|
|
75
|
+
if (changed.has('gridLineColor')) {
|
|
76
|
+
if (this.gridLineColor) {
|
|
77
|
+
this.gridEl.style.setProperty('--nile-dashboard-builder-grid-line', this.gridLineColor);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
this.gridEl.style.removeProperty('--nile-dashboard-builder-grid-line');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (changed.has('config'))
|
|
84
|
+
void this.reconcile();
|
|
85
|
+
}
|
|
86
|
+
disconnectedCallback() {
|
|
87
|
+
super.disconnectedCallback();
|
|
88
|
+
this.grid?.destroy(false);
|
|
89
|
+
this.grid = undefined;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Applies the current `config` to the grid (add/remove/update items). When the
|
|
93
|
+
* change originated from a component method (`internalChange`), emits the
|
|
94
|
+
* resulting config *after* the grid is updated — this avoids a race where
|
|
95
|
+
* emitting before the grid mutation would discard the add/remove.
|
|
96
|
+
*/
|
|
97
|
+
async reconcile() {
|
|
98
|
+
await this.updateComplete;
|
|
99
|
+
const grid = this.grid;
|
|
100
|
+
if (!grid)
|
|
101
|
+
return;
|
|
102
|
+
const widgets = this.normalizeWidgets(this.config);
|
|
103
|
+
const sig = this.signature(widgets);
|
|
104
|
+
if (sig === this.lastSig) {
|
|
105
|
+
this.internalChange = false;
|
|
106
|
+
return; // no change / our own echo
|
|
107
|
+
}
|
|
108
|
+
this.lastSig = sig;
|
|
109
|
+
const desiredIds = new Set(widgets.map((w) => w.id));
|
|
110
|
+
this.applying = true;
|
|
111
|
+
grid.batchUpdate(true);
|
|
112
|
+
try {
|
|
113
|
+
// Remove widgets that are gone.
|
|
114
|
+
for (const [id, el] of [...this.itemEls]) {
|
|
115
|
+
if (!desiredIds.has(id)) {
|
|
116
|
+
grid.removeWidget(el);
|
|
117
|
+
this.itemEls.delete(id);
|
|
118
|
+
this.widgetById.delete(id);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Add new widgets / update existing ones in place.
|
|
122
|
+
for (const w of widgets) {
|
|
123
|
+
const id = w.id;
|
|
124
|
+
this.widgetById.set(id, w);
|
|
125
|
+
const existing = this.itemEls.get(id);
|
|
126
|
+
if (existing) {
|
|
127
|
+
grid.update(existing, {
|
|
128
|
+
x: w.layout.x,
|
|
129
|
+
y: w.layout.y,
|
|
130
|
+
w: w.layout.w,
|
|
131
|
+
h: w.layout.h,
|
|
132
|
+
minW: this.minW,
|
|
133
|
+
minH: this.minH,
|
|
134
|
+
});
|
|
135
|
+
const viewer = existing.querySelector('nile-widget-viewer');
|
|
136
|
+
if (viewer)
|
|
137
|
+
viewer.config = w;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
const el = this.createItem(w);
|
|
141
|
+
this.gridEl.appendChild(el);
|
|
142
|
+
grid.makeWidget(el, {
|
|
143
|
+
x: w.layout.x,
|
|
144
|
+
y: w.layout.y,
|
|
145
|
+
w: w.layout.w,
|
|
146
|
+
h: w.layout.h,
|
|
147
|
+
minW: this.minW,
|
|
148
|
+
minH: this.minH,
|
|
149
|
+
id,
|
|
150
|
+
});
|
|
151
|
+
this.itemEls.set(id, el);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
grid.batchUpdate(false);
|
|
157
|
+
this.applying = false;
|
|
158
|
+
}
|
|
159
|
+
if (this.internalChange) {
|
|
160
|
+
this.internalChange = false;
|
|
161
|
+
this.emitFromGrid();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/** Builds a `.grid-stack-item` hosting the widget viewer plus a remove control. */
|
|
165
|
+
createItem(widget) {
|
|
166
|
+
const item = document.createElement('div');
|
|
167
|
+
item.className = 'grid-stack-item';
|
|
168
|
+
const content = document.createElement('div');
|
|
169
|
+
content.className = 'grid-stack-item-content';
|
|
170
|
+
item.appendChild(content);
|
|
171
|
+
const wrapper = document.createElement('div');
|
|
172
|
+
wrapper.className = 'nile-builder-cell';
|
|
173
|
+
content.appendChild(wrapper);
|
|
174
|
+
const viewer = document.createElement('nile-widget-viewer');
|
|
175
|
+
viewer.config = widget;
|
|
176
|
+
wrapper.appendChild(viewer);
|
|
177
|
+
const remove = document.createElement('button');
|
|
178
|
+
remove.className = 'nile-builder-remove';
|
|
179
|
+
remove.type = 'button';
|
|
180
|
+
remove.textContent = '✕';
|
|
181
|
+
remove.title = 'Remove widget';
|
|
182
|
+
remove.addEventListener('click', (e) => {
|
|
183
|
+
e.stopPropagation();
|
|
184
|
+
this.requestRemoveWidget(widget.id);
|
|
185
|
+
});
|
|
186
|
+
wrapper.appendChild(remove);
|
|
187
|
+
return item;
|
|
188
|
+
}
|
|
189
|
+
/** Adds a starter chart or KPI widget at the bottom of the grid. */
|
|
190
|
+
addWidget(type) {
|
|
191
|
+
const widgets = this.normalizeWidgets(this.config);
|
|
192
|
+
const maxY = widgets.reduce((m, w) => Math.max(m, w.layout.y + w.layout.h), 0);
|
|
193
|
+
const id = `nile-w-${++this.idCounter}`;
|
|
194
|
+
const widget = type === 'kpi'
|
|
195
|
+
? {
|
|
196
|
+
id,
|
|
197
|
+
type: 'kpi',
|
|
198
|
+
layout: { x: 0, y: maxY, w: 3, h: 2 },
|
|
199
|
+
nileConfig: { chart: { type: 'kpi', variant: 'card', label: 'New KPI', value: '0' } },
|
|
200
|
+
}
|
|
201
|
+
: {
|
|
202
|
+
id,
|
|
203
|
+
type: 'chart',
|
|
204
|
+
layout: { x: 0, y: maxY, w: 6, h: 3 },
|
|
205
|
+
nileConfig: {
|
|
206
|
+
chart: {
|
|
207
|
+
type: 'bar',
|
|
208
|
+
data: [{ name: 'Series 1', data: [5, 3, 8, 6] }],
|
|
209
|
+
categories: ['A', 'B', 'C', 'D'],
|
|
210
|
+
},
|
|
211
|
+
aq: { chartTitle: 'New chart' },
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
this.internalChange = true;
|
|
215
|
+
this.config = { ...(this.config ?? {}), widgets: [...widgets, widget] };
|
|
216
|
+
}
|
|
217
|
+
removeWidget(id) {
|
|
218
|
+
const widgets = this.normalizeWidgets(this.config).filter((w) => w.id !== id);
|
|
219
|
+
this.internalChange = true;
|
|
220
|
+
this.config = { ...(this.config ?? {}), widgets };
|
|
221
|
+
}
|
|
222
|
+
requestRemoveWidget(id) {
|
|
223
|
+
const widget = this.widgetById.get(id) ??
|
|
224
|
+
this.normalizeWidgets(this.config).find((w) => w.id === id) ??
|
|
225
|
+
null;
|
|
226
|
+
const ev = this.emit('nile-widget-remove', { id, widget }, undefined, undefined, true);
|
|
227
|
+
if (ev.defaultPrevented)
|
|
228
|
+
return false;
|
|
229
|
+
this.removeWidget(id);
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
/** Reads the true layout back from gridstack and emits the updated config. */
|
|
233
|
+
emitFromGrid() {
|
|
234
|
+
const grid = this.grid;
|
|
235
|
+
if (!grid)
|
|
236
|
+
return;
|
|
237
|
+
const layout = grid.save(false);
|
|
238
|
+
const widgets = [];
|
|
239
|
+
for (const node of layout) {
|
|
240
|
+
const base = this.widgetById.get(String(node.id));
|
|
241
|
+
if (!base)
|
|
242
|
+
continue;
|
|
243
|
+
widgets.push({
|
|
244
|
+
...base,
|
|
245
|
+
id: String(node.id),
|
|
246
|
+
layout: { x: node.x ?? 0, y: node.y ?? 0, w: node.w ?? 1, h: node.h ?? 1 },
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
const config = { ...(this.config ?? {}), widgets };
|
|
250
|
+
this.lastSig = this.signature(widgets); // prevent this emit from re-applying
|
|
251
|
+
this.config = config;
|
|
252
|
+
this.emit('nile-dashboard-change', { config });
|
|
253
|
+
}
|
|
254
|
+
/** Ensures every widget has a stable id (assigned in place if missing). */
|
|
255
|
+
normalizeWidgets(cfg) {
|
|
256
|
+
const widgets = cfg?.widgets ?? [];
|
|
257
|
+
for (const w of widgets) {
|
|
258
|
+
if (!w.id)
|
|
259
|
+
w.id = `nile-w-${++this.idCounter}`;
|
|
260
|
+
}
|
|
261
|
+
return widgets;
|
|
262
|
+
}
|
|
263
|
+
/** Order-independent signature of the current layout + content. */
|
|
264
|
+
signature(widgets) {
|
|
265
|
+
return JSON.stringify([...widgets]
|
|
266
|
+
.sort((a, b) => a.id.localeCompare(b.id))
|
|
267
|
+
.map((w) => [w.id, w.type, w.layout.x, w.layout.y, w.layout.w, w.layout.h, w.nileConfig]));
|
|
268
|
+
}
|
|
269
|
+
render() {
|
|
270
|
+
return html `<div class="grid-stack"></div>`;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
NileDashboardBuilder.styles = [gridstackCss, styles];
|
|
274
|
+
__decorate([
|
|
275
|
+
property({ type: Object })
|
|
276
|
+
], NileDashboardBuilder.prototype, "config", void 0);
|
|
277
|
+
__decorate([
|
|
278
|
+
property({ type: Number })
|
|
279
|
+
], NileDashboardBuilder.prototype, "columns", void 0);
|
|
280
|
+
__decorate([
|
|
281
|
+
property({ type: Number, attribute: 'cell-height' })
|
|
282
|
+
], NileDashboardBuilder.prototype, "cellHeight", void 0);
|
|
283
|
+
__decorate([
|
|
284
|
+
property({ type: Number })
|
|
285
|
+
], NileDashboardBuilder.prototype, "gap", void 0);
|
|
286
|
+
__decorate([
|
|
287
|
+
property({ type: Number, attribute: 'min-rows' })
|
|
288
|
+
], NileDashboardBuilder.prototype, "minRows", void 0);
|
|
289
|
+
__decorate([
|
|
290
|
+
property({ type: Number, attribute: 'min-w' })
|
|
291
|
+
], NileDashboardBuilder.prototype, "minW", void 0);
|
|
292
|
+
__decorate([
|
|
293
|
+
property({ type: Number, attribute: 'min-h' })
|
|
294
|
+
], NileDashboardBuilder.prototype, "minH", void 0);
|
|
295
|
+
__decorate([
|
|
296
|
+
property({ attribute: 'resize-handles' })
|
|
297
|
+
], NileDashboardBuilder.prototype, "resizeHandles", void 0);
|
|
298
|
+
__decorate([
|
|
299
|
+
property({ type: Boolean })
|
|
300
|
+
], NileDashboardBuilder.prototype, "float", void 0);
|
|
301
|
+
__decorate([
|
|
302
|
+
property({ type: Boolean, reflect: true })
|
|
303
|
+
], NileDashboardBuilder.prototype, "editable", void 0);
|
|
304
|
+
__decorate([
|
|
305
|
+
property({ type: Boolean, reflect: true })
|
|
306
|
+
], NileDashboardBuilder.prototype, "gridLines", void 0);
|
|
307
|
+
__decorate([
|
|
308
|
+
property({ attribute: 'grid-line-color' })
|
|
309
|
+
], NileDashboardBuilder.prototype, "gridLineColor", void 0);
|
|
310
|
+
__decorate([
|
|
311
|
+
query('.grid-stack')
|
|
312
|
+
], NileDashboardBuilder.prototype, "gridEl", void 0);
|
|
313
|
+
NileDashboardBuilder = __decorate([
|
|
314
|
+
customElement('nile-dashboard-builder')
|
|
315
|
+
], NileDashboardBuilder);
|
|
316
|
+
export { NileDashboardBuilder };
|
|
317
|
+
//# sourceMappingURL=nile-dashboard-builder.js.map
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aquera/nile-visualization",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.28",
|
|
4
4
|
"description": "A visualization Library for the Nile Design System",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Aquera Inc",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/src/index.js",
|
|
9
9
|
"module": "dist/src/index.js",
|
|
10
|
-
|
|
11
10
|
"exports": {
|
|
12
11
|
".": "./dist/src/index.js",
|
|
13
12
|
"./nile-bar-chart": "./dist/src/nile-bar-chart/index.js",
|
|
@@ -45,6 +44,7 @@
|
|
|
45
44
|
"./nile-chart": "./dist/src/nile-chart/index.js",
|
|
46
45
|
"./nile-widget-viewer": "./dist/src/nile-widget-viewer/index.js",
|
|
47
46
|
"./nile-dashboard-viewer": "./dist/src/nile-dashboard-viewer/index.js",
|
|
47
|
+
"./nile-dashboard-builder": "./dist/src/nile-dashboard-builder/index.js",
|
|
48
48
|
"./nile-executive-summary": "./dist/src/nile-executive-summary/index.js",
|
|
49
49
|
"./nile-chart-list": "./dist/src/nile-chart-list/index.js",
|
|
50
50
|
"./nile-chart-message": "./dist/src/nile-chart-message/index.js"
|
|
@@ -60,14 +60,15 @@
|
|
|
60
60
|
"clean": "rimraf dist/*"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"lit": "^3.0.0",
|
|
64
63
|
"filtrex": "^3.0.0",
|
|
65
|
-
"
|
|
64
|
+
"gridstack": "12.6.0",
|
|
65
|
+
"jsep": "^1.3.9",
|
|
66
|
+
"lit": "^3.0.0"
|
|
66
67
|
},
|
|
67
68
|
"peerDependencies": {
|
|
68
69
|
"highcharts": "12.5.0",
|
|
69
|
-
"@aquera/nile-
|
|
70
|
-
"@aquera/nile-
|
|
70
|
+
"@aquera/nile-data-grid": ">=0.1.0",
|
|
71
|
+
"@aquera/nile-elements": ">=0.1.0"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
73
74
|
"@rollup/plugin-babel": "^6.0.3",
|