@hpcc-js/layout 3.5.8 → 3.5.10
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/LICENSE +43 -43
- package/README.md +83 -83
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +1 -1
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +8 -8
- package/src/AbsoluteSurface.css +8 -8
- package/src/AbsoluteSurface.ts +93 -93
- package/src/Accordion.css +101 -101
- package/src/Accordion.ts +146 -146
- package/src/Border.css +148 -148
- package/src/Border.ts +636 -636
- package/src/Border2.css +22 -22
- package/src/Border2.ts +391 -391
- package/src/Carousel.css +7 -7
- package/src/Carousel.ts +100 -100
- package/src/Cell.css +10 -10
- package/src/Cell.ts +94 -94
- package/src/ChartPanel.css +7 -7
- package/src/ChartPanel.ts +635 -635
- package/src/FlexGrid.css +8 -8
- package/src/FlexGrid.ts +140 -140
- package/src/Grid.css +89 -89
- package/src/Grid.ts +576 -576
- package/src/HorizontalList.ts +15 -15
- package/src/Layered.css +11 -11
- package/src/Layered.ts +132 -132
- package/src/Legend.ts +516 -516
- package/src/Modal.css +50 -50
- package/src/Modal.ts +289 -289
- package/src/Popup.ts +120 -120
- package/src/Surface.css +104 -104
- package/src/Surface.ts +223 -223
- package/src/Tabbed.css +23 -23
- package/src/Tabbed.ts +165 -165
- package/src/Toolbar.css +33 -33
- package/src/Toolbar.ts +127 -127
- package/src/VerticalList.ts +15 -15
- package/src/__package__.ts +3 -3
- package/src/index.ts +20 -20
package/src/ChartPanel.ts
CHANGED
|
@@ -1,635 +1,635 @@
|
|
|
1
|
-
import { IHighlight } from "@hpcc-js/api";
|
|
2
|
-
import { Button, Database, IconBar, ProgressBar, Spacer, SVGWidget, Text, TitleBar, ToggleButton, Utility, Widget } from "@hpcc-js/common";
|
|
3
|
-
import { Table } from "@hpcc-js/dgrid2";
|
|
4
|
-
import { select as d3Select } from "d3-selection";
|
|
5
|
-
import { Border2 } from "./Border2.ts";
|
|
6
|
-
import { Carousel } from "./Carousel.ts";
|
|
7
|
-
import { Legend } from "./Legend.ts";
|
|
8
|
-
import { Modal } from "./Modal.ts";
|
|
9
|
-
|
|
10
|
-
import "../src/ChartPanel.css";
|
|
11
|
-
|
|
12
|
-
export class ChartPanel<T extends Widget = Widget> extends Border2 implements IHighlight {
|
|
13
|
-
|
|
14
|
-
protected _legend = new Legend(this).enableOverflow(true);
|
|
15
|
-
protected _progressBar = new ProgressBar();
|
|
16
|
-
protected _autoScale = false;
|
|
17
|
-
protected _resolutions = {
|
|
18
|
-
tiny: { width: 100, height: 100 },
|
|
19
|
-
small: { width: 300, height: 300 }
|
|
20
|
-
};
|
|
21
|
-
private _modal = new Modal();
|
|
22
|
-
private _highlight: boolean;
|
|
23
|
-
private _scale: number;
|
|
24
|
-
private _orig_size: any;
|
|
25
|
-
|
|
26
|
-
private _toggleInfo = new ToggleButton().faChar("fa-info-circle").tooltip(".Description")
|
|
27
|
-
.selected(false)
|
|
28
|
-
.on("enabled", () => {
|
|
29
|
-
return this.description() !== "";
|
|
30
|
-
})
|
|
31
|
-
.on("click", () => {
|
|
32
|
-
if (this._toggleInfo.selected()) {
|
|
33
|
-
this._modal
|
|
34
|
-
.title(this.title())
|
|
35
|
-
.widget(new Text().text(this.description()))
|
|
36
|
-
.show(true)
|
|
37
|
-
.render()
|
|
38
|
-
;
|
|
39
|
-
|
|
40
|
-
const origCloseFunc = this._modal._close;
|
|
41
|
-
this._modal._close = () => {
|
|
42
|
-
this._toggleInfo
|
|
43
|
-
.selected(false)
|
|
44
|
-
.render()
|
|
45
|
-
;
|
|
46
|
-
this._modal._close = origCloseFunc;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
.on("mouseMove", () => {
|
|
51
|
-
/*
|
|
52
|
-
this._modal.showPreview(true).render(n => {
|
|
53
|
-
n.resize().render();
|
|
54
|
-
});
|
|
55
|
-
*/
|
|
56
|
-
})
|
|
57
|
-
.on("mouseOut", () => {
|
|
58
|
-
/*
|
|
59
|
-
if (this._modal.showPreview()) {
|
|
60
|
-
this._modal.show(false).showPreview(false).render();
|
|
61
|
-
}
|
|
62
|
-
*/
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
private _toggleData = new ToggleButton().faChar("fa-table").tooltip("Data")
|
|
66
|
-
.on("click", () => {
|
|
67
|
-
this.dataVisible(this._toggleData.selected());
|
|
68
|
-
this.render();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
private _buttonDownload = new Button().faChar("fa-download").tooltip("Download")
|
|
72
|
-
.on("click", () => {
|
|
73
|
-
this.downloadCSV();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
private _buttonDownloadImage = new Button().faChar("fa-image").tooltip("Download Image")
|
|
77
|
-
.on("click", () => {
|
|
78
|
-
this.downloadPNG();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
private _toggleLegend = new ToggleButton().faChar("fa-list-ul").tooltip("Legend")
|
|
82
|
-
.selected(false)
|
|
83
|
-
.on("click", () => {
|
|
84
|
-
const selected = this._toggleLegend.selected();
|
|
85
|
-
if (this.legendPosition() === "bottom") {
|
|
86
|
-
this.showBottom(selected);
|
|
87
|
-
} else if (this.legendPosition() === "right") {
|
|
88
|
-
this.showRight(selected);
|
|
89
|
-
}
|
|
90
|
-
this.legendVisible(selected);
|
|
91
|
-
this.render();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
protected _spacer = new Spacer();
|
|
95
|
-
|
|
96
|
-
_titleBar = new TitleBar().buttons([this._toggleData, this._buttonDownload, this._buttonDownloadImage, this._spacer, this._toggleLegend]);
|
|
97
|
-
|
|
98
|
-
protected _carousel = new Carousel();
|
|
99
|
-
protected _table = new Table();
|
|
100
|
-
protected _widget: T;
|
|
101
|
-
|
|
102
|
-
protected _hideLegendToggleList = ["dgrid_Table", "dgrid2_Table"];
|
|
103
|
-
|
|
104
|
-
constructor() {
|
|
105
|
-
super();
|
|
106
|
-
this._tag = "div";
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
fields(): Database.Field[];
|
|
110
|
-
fields(_: Database.Field[]): this;
|
|
111
|
-
fields(_?: Database.Field[]): this | Database.Field[] {
|
|
112
|
-
if (!arguments.length) return super.fields();
|
|
113
|
-
super.fields(_);
|
|
114
|
-
this._legend.fields(_);
|
|
115
|
-
this.refreshFields();
|
|
116
|
-
return this;
|
|
117
|
-
}
|
|
118
|
-
refreshFields() {
|
|
119
|
-
this._widget.fields(this._legend.filteredFields());
|
|
120
|
-
this._table.fields(this._legend.filteredFields());
|
|
121
|
-
return this;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
columns(): string[];
|
|
125
|
-
columns(_: string[], asDefault?: boolean): this;
|
|
126
|
-
columns(_?: string[], asDefault?: boolean): string[] | this {
|
|
127
|
-
if (!arguments.length) return super.columns();
|
|
128
|
-
super.columns(_, asDefault);
|
|
129
|
-
this._legend.columns(_, asDefault);
|
|
130
|
-
this.refreshColumns();
|
|
131
|
-
return this;
|
|
132
|
-
}
|
|
133
|
-
refreshColumns() {
|
|
134
|
-
this._widget.columns(this._legend.filteredColumns());
|
|
135
|
-
this._table.columns(this._legend.filteredColumns());
|
|
136
|
-
return this;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
data(_?) {
|
|
140
|
-
if (!arguments.length) return super.data();
|
|
141
|
-
super.data(_);
|
|
142
|
-
this._legend.data(_);
|
|
143
|
-
this.refreshData();
|
|
144
|
-
return this;
|
|
145
|
-
}
|
|
146
|
-
refreshData() {
|
|
147
|
-
this._widget.data(this._legend.filteredData());
|
|
148
|
-
this._table.data(this._legend.filteredData());
|
|
149
|
-
return this;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
highlight(): boolean;
|
|
153
|
-
highlight(_: boolean): this;
|
|
154
|
-
highlight(_?: boolean): boolean | this {
|
|
155
|
-
if (!arguments.length) return this._highlight;
|
|
156
|
-
this._highlight = _;
|
|
157
|
-
return this;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
startProgress() {
|
|
161
|
-
this._progressBar.start();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
finishProgress() {
|
|
165
|
-
this._progressBar.finish();
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
buttons(): Widget[];
|
|
169
|
-
buttons(_: Widget[]): this;
|
|
170
|
-
buttons(_?: Widget[]): this | Widget[] {
|
|
171
|
-
if (!arguments.length) return this._titleBar.buttons();
|
|
172
|
-
this._titleBar.buttons(_);
|
|
173
|
-
return this;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
downloadCSV() {
|
|
177
|
-
const namePrefix = this.downloadTitle() ? this.downloadTitle() : this.title() ? this.title() : "data";
|
|
178
|
-
const nameSuffix = this.downloadTimestampSuffix() ? "_" + Utility.timestamp() : "";
|
|
179
|
-
Utility.downloadString("CSV", this._widget.export("CSV"), namePrefix + nameSuffix);
|
|
180
|
-
return this;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
downloadPNG() {
|
|
184
|
-
const widget = this.widget();
|
|
185
|
-
if (widget instanceof SVGWidget) {
|
|
186
|
-
if (!this.legendVisible()) {
|
|
187
|
-
widget.downloadPNG(this.title());
|
|
188
|
-
} else {
|
|
189
|
-
widget.downloadPNG(this.title(), undefined, this._legend);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return this;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
highlightColumn(column?: string): this {
|
|
196
|
-
if (column) {
|
|
197
|
-
const cssTag = `series-${this.cssTag(column)}`;
|
|
198
|
-
this._centerWA.element().selectAll(".series")
|
|
199
|
-
.each(function () {
|
|
200
|
-
const element = d3Select(this);
|
|
201
|
-
const highlight = element.classed(cssTag);
|
|
202
|
-
element
|
|
203
|
-
.classed("highlight", highlight)
|
|
204
|
-
.classed("lowlight", !highlight)
|
|
205
|
-
;
|
|
206
|
-
})
|
|
207
|
-
;
|
|
208
|
-
} else {
|
|
209
|
-
this._centerWA.element().selectAll(".series")
|
|
210
|
-
.classed("highlight", false)
|
|
211
|
-
.classed("lowlight", false)
|
|
212
|
-
;
|
|
213
|
-
}
|
|
214
|
-
return this;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
getResponsiveMode(): "tiny" | "small" | "regular" | "none" {
|
|
218
|
-
if (!this.enableAutoscaling()) return "none";
|
|
219
|
-
if (!this._autoScale) return "regular";
|
|
220
|
-
if (this.size().width <= this._resolutions.tiny.width || this.size().height <= this._resolutions.tiny.height) {
|
|
221
|
-
return "tiny";
|
|
222
|
-
} else if (this.size().width <= this._resolutions.small.width || this.size().height <= this._resolutions.small.height) {
|
|
223
|
-
return "small";
|
|
224
|
-
}
|
|
225
|
-
return "regular";
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
setOrigSize() {
|
|
229
|
-
this._orig_size = JSON.parse(JSON.stringify(this.size()));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
enter(domNode, element) {
|
|
233
|
-
super.enter(domNode, element);
|
|
234
|
-
this._modal
|
|
235
|
-
.target(this.target())
|
|
236
|
-
.relativeTargetId(this.id())
|
|
237
|
-
;
|
|
238
|
-
|
|
239
|
-
this.top(this._titleBar);
|
|
240
|
-
this.center(this._carousel);
|
|
241
|
-
|
|
242
|
-
this._legend
|
|
243
|
-
.targetWidget(this._widget)
|
|
244
|
-
.orientation("vertical")
|
|
245
|
-
.title("")
|
|
246
|
-
.visible(false)
|
|
247
|
-
;
|
|
248
|
-
|
|
249
|
-
this._progressBar.enter(domNode, element);
|
|
250
|
-
this.setOrigSize();
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
preUpdateTiny(element) {
|
|
254
|
-
element.selectAll("div.body,div.title-text,div.icon-bar").style("display", "none");
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
preUpdateSmall(element) {
|
|
258
|
-
const scale_x = this._orig_size.width / this._resolutions.small.width;
|
|
259
|
-
const scale_y = this._orig_size.height / this._resolutions.small.height;
|
|
260
|
-
this._scale = Math.min(scale_x, scale_y);
|
|
261
|
-
const x_is_smaller = this._scale === scale_x;
|
|
262
|
-
this.size({
|
|
263
|
-
width: x_is_smaller ? this._resolutions.small.width : this._orig_size.width * (1 / this._scale),
|
|
264
|
-
height: !x_is_smaller ? this._resolutions.small.height : this._orig_size.height * (1 / this._scale)
|
|
265
|
-
});
|
|
266
|
-
element.select("div.title-icon").style("position", "static");
|
|
267
|
-
element.selectAll("lhs").style("display", "none");
|
|
268
|
-
element.selectAll("div.body,div.title-text,div.icon-bar").style("display", "");
|
|
269
|
-
element.selectAll("div.data-count").style("visibility", "hidden");
|
|
270
|
-
element.style("transform", `scale(${this._scale})`);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
preUpdateRegular(element) {
|
|
274
|
-
element.selectAll("div.body,div.title-text,div.icon-bar").style("display", "");
|
|
275
|
-
element.selectAll("div.data-count").style("visibility", "hidden");
|
|
276
|
-
element.select("div.title-icon").style("position", "static");
|
|
277
|
-
element.style("transform", "translate(0px,0px) scale(1)");
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
private _prevdataVisible;
|
|
281
|
-
private _prevlegendVisible;
|
|
282
|
-
private _prevLegendPosition;
|
|
283
|
-
private _prevChartDataFamily;
|
|
284
|
-
private _prevChart;
|
|
285
|
-
private _prevButtons;
|
|
286
|
-
update(domNode, element) {
|
|
287
|
-
super.update(domNode, element);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
preUpdate(domNode, element) {
|
|
291
|
-
|
|
292
|
-
super.preUpdate(domNode, element);
|
|
293
|
-
|
|
294
|
-
if (this._prevLegendPosition !== this.legendPosition()) {
|
|
295
|
-
if (this._legend.target() !== null) this._legend.target(null);
|
|
296
|
-
if (this._prevLegendPosition !== undefined) {
|
|
297
|
-
this.swap(this._prevLegendPosition, this.legendPosition());
|
|
298
|
-
} else {
|
|
299
|
-
this[this.legendPosition()](this._legend);
|
|
300
|
-
}
|
|
301
|
-
if (this.legendPosition() === "right") {
|
|
302
|
-
this.rightOverflowX("hidden");
|
|
303
|
-
this.rightOverflowY("auto");
|
|
304
|
-
this.bottomOverflowX("visible");
|
|
305
|
-
this.bottomOverflowY("visible");
|
|
306
|
-
} else {
|
|
307
|
-
this.rightOverflowX("visible");
|
|
308
|
-
this.rightOverflowY("visible");
|
|
309
|
-
this.bottomOverflowX("auto");
|
|
310
|
-
this.bottomOverflowY("hidden");
|
|
311
|
-
}
|
|
312
|
-
this._prevLegendPosition = this.legendPosition();
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (this._prevdataVisible !== this.dataVisible()) {
|
|
316
|
-
this._prevdataVisible = this.dataVisible();
|
|
317
|
-
this._toggleData.selected(this._prevdataVisible);
|
|
318
|
-
this._legend.visible(this._prevlegendVisible && !this._prevdataVisible);
|
|
319
|
-
this._carousel.active(this._prevdataVisible ? 1 : 0);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
if (this._prevlegendVisible !== this.legendVisible()) {
|
|
323
|
-
this._prevlegendVisible = this.legendVisible();
|
|
324
|
-
this._toggleLegend.selected(this._prevlegendVisible);
|
|
325
|
-
this._legend.visible(this._prevlegendVisible && !this._prevdataVisible);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
this._legend.orientation(this.legendPosition() === "bottom" ? "horizontal" : "vertical");
|
|
329
|
-
|
|
330
|
-
this.showLeft(!this.left());
|
|
331
|
-
|
|
332
|
-
switch (this.getResponsiveMode()) {
|
|
333
|
-
case "tiny":
|
|
334
|
-
this.preUpdateTiny(element);
|
|
335
|
-
break;
|
|
336
|
-
case "small":
|
|
337
|
-
this.preUpdateSmall(element);
|
|
338
|
-
break;
|
|
339
|
-
case "regular":
|
|
340
|
-
this.preUpdateRegular(element);
|
|
341
|
-
break;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
const chart = this._widget.classID() === "composite_MultiChart" ? this._widget["chart"]() : this._widget;
|
|
345
|
-
this._legend.dataFamily(chart._dataFamily || "any");
|
|
346
|
-
|
|
347
|
-
if (this._prevChartDataFamily !== this._legend.dataFamily()) {
|
|
348
|
-
this._prevChartDataFamily = this._legend.dataFamily();
|
|
349
|
-
switch (this._prevChartDataFamily) {
|
|
350
|
-
case "any":
|
|
351
|
-
this._toggleLegend.selected(false);
|
|
352
|
-
this._legend.visible(false);
|
|
353
|
-
break;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
element.style("box-shadow", this.highlight() ? `inset 0px 0px 0px ${this.highlightSize()}px ${this.highlightColor()}` : "none");
|
|
357
|
-
|
|
358
|
-
if (this._hideLegendToggleList.indexOf(chart.classID()) !== -1) {
|
|
359
|
-
this._spacer.visible(false);
|
|
360
|
-
this._toggleLegend.visible(false);
|
|
361
|
-
} else {
|
|
362
|
-
this._spacer.visible(true);
|
|
363
|
-
this._toggleLegend.visible(true);
|
|
364
|
-
}
|
|
365
|
-
if (this._prevChart !== chart) {
|
|
366
|
-
this._prevChart = chart;
|
|
367
|
-
const widgetIconBar = chart ? chart["_titleBar"] || chart["_iconBar"] : undefined;
|
|
368
|
-
if (widgetIconBar && widgetIconBar instanceof IconBar) {
|
|
369
|
-
this._prevButtons = this._prevButtons || [...this.buttons()];
|
|
370
|
-
const buttons: Widget[] = [
|
|
371
|
-
...widgetIconBar.buttons(),
|
|
372
|
-
new Spacer(),
|
|
373
|
-
...this._prevButtons
|
|
374
|
-
];
|
|
375
|
-
widgetIconBar.buttons([]).render();
|
|
376
|
-
this.buttons(buttons);
|
|
377
|
-
} else if (this._prevButtons) {
|
|
378
|
-
this.buttons(this._prevButtons);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
const hiddenButtons = [];
|
|
383
|
-
if (!this.dataButtonVisible()) hiddenButtons.push(this._toggleData);
|
|
384
|
-
if (!this.downloadButtonVisible()) hiddenButtons.push(this._buttonDownload);
|
|
385
|
-
if (!this.downloadImageButtonVisible()) hiddenButtons.push(this._buttonDownloadImage);
|
|
386
|
-
if (!this.legendButtonVisible()) hiddenButtons.push(this._toggleLegend);
|
|
387
|
-
this._buttonDownloadImage.enabled(this.widget() instanceof SVGWidget);
|
|
388
|
-
this._titleBar
|
|
389
|
-
.hiddenButtons(hiddenButtons)
|
|
390
|
-
.visible(this.titleVisible())
|
|
391
|
-
;
|
|
392
|
-
this.topOverlay(this.titleOverlay() || !this.titleVisible());
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
postUpdate(domNode, element) {
|
|
396
|
-
super.postUpdate(domNode, element);
|
|
397
|
-
|
|
398
|
-
switch (this.getResponsiveMode()) {
|
|
399
|
-
case "tiny":
|
|
400
|
-
this.postUpdateTiny(element);
|
|
401
|
-
break;
|
|
402
|
-
case "small":
|
|
403
|
-
this.postUpdateSmall(element);
|
|
404
|
-
break;
|
|
405
|
-
case "regular":
|
|
406
|
-
this.postUpdateRegular(element);
|
|
407
|
-
break;
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
postUpdateTiny(element) {
|
|
412
|
-
element.selectAll("div.body,div.title-text,div.icon-bar").style("display", "none");
|
|
413
|
-
element.selectAll("div.data-count")
|
|
414
|
-
.style("visibility", "visible")
|
|
415
|
-
.style("font-size", (this.titleIconFontSize() / 3) + "px")
|
|
416
|
-
.style("line-height", (this.titleIconFontSize() / 3) + "px")
|
|
417
|
-
.style("left", this.titleIconFontSize() + "px")
|
|
418
|
-
.text(this.data().length)
|
|
419
|
-
;
|
|
420
|
-
element.style("transform", "translate(0px,0px) scale(1)");
|
|
421
|
-
const iconDiv = element.selectAll("div.title-icon");
|
|
422
|
-
const _node = iconDiv.node();
|
|
423
|
-
const _container = element.node().parentElement;
|
|
424
|
-
const containerRect = _container.getBoundingClientRect();
|
|
425
|
-
if (_node) {
|
|
426
|
-
const rect = iconDiv.node().getBoundingClientRect();
|
|
427
|
-
const icon_top = containerRect.height / 2;
|
|
428
|
-
iconDiv
|
|
429
|
-
.style("position", "absolute")
|
|
430
|
-
.style("left", `calc(50% - ${rect.width / 2}px)`)
|
|
431
|
-
.style("top", `${icon_top - (rect.height / 2)}px`)
|
|
432
|
-
;
|
|
433
|
-
element.selectAll("div.data-count")
|
|
434
|
-
.style("position", "absolute")
|
|
435
|
-
.style("left", `calc(50% + ${rect.width / 2}px)`)
|
|
436
|
-
.style("top", `${icon_top - (rect.height / 2)}px`)
|
|
437
|
-
;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
postUpdateSmall(element) {
|
|
442
|
-
element.selectAll("lhs").style("display", "none"); // TODO: a bug in Border2?
|
|
443
|
-
element.selectAll("div.title-icon").style("position", "static");
|
|
444
|
-
element.selectAll("div.body,div.title-text,div.icon-bar").style("display", "");
|
|
445
|
-
element.selectAll("div.data-count").style("visibility", "hidden");
|
|
446
|
-
const rect = element.node().getBoundingClientRect();
|
|
447
|
-
const parentRect = element.node().parentElement.getBoundingClientRect();
|
|
448
|
-
element.style("transform", `translate(${parentRect.x - rect.x}px, ${parentRect.y - rect.y}px) scale(${this._scale})`);
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
postUpdateRegular(element) {
|
|
452
|
-
element.selectAll("div.title-icon").style("position", "static");
|
|
453
|
-
element.selectAll("div.body,div.title-text,div.icon-bar").style("display", "");
|
|
454
|
-
element.selectAll("div.data-count").style("visibility", "hidden");
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
exit(domNode, element) {
|
|
458
|
-
this._progressBar.exit(domNode, element);
|
|
459
|
-
|
|
460
|
-
this.right(null);
|
|
461
|
-
this._legend.target(null);
|
|
462
|
-
this.center(null);
|
|
463
|
-
this._carousel.target(null);
|
|
464
|
-
this.top(null);
|
|
465
|
-
this._titleBar.target(null);
|
|
466
|
-
|
|
467
|
-
this._modal.target(null);
|
|
468
|
-
|
|
469
|
-
delete this._prevChart;
|
|
470
|
-
delete this._prevButtons;
|
|
471
|
-
delete this._prevChartDataFamily;
|
|
472
|
-
delete this._prevPos;
|
|
473
|
-
delete this._prevdataVisible;
|
|
474
|
-
delete this._prevlegendVisible;
|
|
475
|
-
|
|
476
|
-
super.exit(domNode, element);
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
// Event Handlers ---
|
|
480
|
-
// Events ---
|
|
481
|
-
click(row, column, selected) {
|
|
482
|
-
// console.log("Click: " + JSON.stringify(row) + ", " + column + ", " + selected);
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
dblclick(row, column, selected) {
|
|
486
|
-
// console.log("Double click: " + JSON.stringify(row) + ", " + column + ", " + selected);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
vertex_click(row, col, sel, more) {
|
|
490
|
-
if (more && more.vertex) {
|
|
491
|
-
// console.log("Vertex click: " + more.vertex.id());
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
vertex_dblclick(row, col, sel, more) {
|
|
496
|
-
if (more && more.vertex) {
|
|
497
|
-
// console.log("Vertex double click: " + more.vertex.id());
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
edge_click(row, col, sel, more) {
|
|
502
|
-
if (more && more.edge) {
|
|
503
|
-
// console.log("Edge click: " + more.edge.id());
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
edge_dblclick(row, col, sel, more) {
|
|
508
|
-
if (more && more.edge) {
|
|
509
|
-
// console.log("Edge double click: " + more.edge.id());
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
ChartPanel.prototype._class += " layout_ChartPanel";
|
|
514
|
-
|
|
515
|
-
export interface ChartPanel<T extends Widget = Widget> {
|
|
516
|
-
title(): string;
|
|
517
|
-
title(_: string): this;
|
|
518
|
-
titleVisible(): boolean;
|
|
519
|
-
titleVisible(_: boolean): this;
|
|
520
|
-
titleOverlay(): boolean;
|
|
521
|
-
titleOverlay(_: boolean): this;
|
|
522
|
-
title_exists(): boolean;
|
|
523
|
-
titleFontSize(): number;
|
|
524
|
-
titleFontSize(_: number): this;
|
|
525
|
-
titleFontSize_exists(): boolean;
|
|
526
|
-
titleIconFontSize(): number;
|
|
527
|
-
titleIconFontSize(_: number): this;
|
|
528
|
-
titleIconFontSize_exists(): boolean;
|
|
529
|
-
dataVisible(): boolean;
|
|
530
|
-
dataVisible(_: boolean): this;
|
|
531
|
-
dataButtonVisible(): boolean;
|
|
532
|
-
dataButtonVisible(_: boolean): this;
|
|
533
|
-
downloadButtonVisible(): boolean;
|
|
534
|
-
downloadButtonVisible(_: boolean): this;
|
|
535
|
-
downloadImageButtonVisible(): boolean;
|
|
536
|
-
downloadImageButtonVisible(_: boolean): this;
|
|
537
|
-
downloadTitle(): string;
|
|
538
|
-
downloadTitle(_: string): this;
|
|
539
|
-
downloadTimestampSuffix(): boolean;
|
|
540
|
-
downloadTimestampSuffix(_: boolean): this;
|
|
541
|
-
legendVisible(): boolean;
|
|
542
|
-
legendVisible(_: boolean): this;
|
|
543
|
-
legendButtonVisible(): boolean;
|
|
544
|
-
legendButtonVisible(_: boolean): this;
|
|
545
|
-
legendPosition(): "right" | "bottom";
|
|
546
|
-
legendPosition(_: "right" | "bottom"): this;
|
|
547
|
-
description(): string;
|
|
548
|
-
description(_: string): this;
|
|
549
|
-
description_exists(): boolean;
|
|
550
|
-
widget(): T;
|
|
551
|
-
widget(_: T): this;
|
|
552
|
-
widget_exists(): boolean;
|
|
553
|
-
enableAutoscaling(): boolean;
|
|
554
|
-
enableAutoscaling(_: boolean): this;
|
|
555
|
-
enableAutoscaling_exists(): boolean;
|
|
556
|
-
highlightSize(): number;
|
|
557
|
-
highlightSize(_: number): this;
|
|
558
|
-
highlightSize_exists(): boolean;
|
|
559
|
-
highlightColor(): string;
|
|
560
|
-
highlightColor(_: string): this;
|
|
561
|
-
highlightColor_exists(): boolean;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
ChartPanel.prototype.publishReset();
|
|
565
|
-
ChartPanel.prototype.publishProxy("title", "_titleBar");
|
|
566
|
-
ChartPanel.prototype.publish("titleVisible", true, "boolean");
|
|
567
|
-
ChartPanel.prototype.publish("titleOverlay", false, "boolean");
|
|
568
|
-
ChartPanel.prototype.publishProxy("titleIcon", "_titleBar");
|
|
569
|
-
ChartPanel.prototype.publishProxy("titleIconFont", "_titleBar");
|
|
570
|
-
ChartPanel.prototype.publishProxy("titleFont", "_titleBar");
|
|
571
|
-
ChartPanel.prototype.publishProxy("titleIconFontSize", "_titleBar");
|
|
572
|
-
ChartPanel.prototype.publishProxy("titleFontSize", "_titleBar");
|
|
573
|
-
ChartPanel.prototype.publishProxy("description", "_titleBar");
|
|
574
|
-
ChartPanel.prototype.publishProxy("descriptionFont", "_titleBar");
|
|
575
|
-
ChartPanel.prototype.publishProxy("descriptionFontSize", "_titleBar");
|
|
576
|
-
ChartPanel.prototype.publish("dataVisible", false, "boolean", "Show data table");
|
|
577
|
-
ChartPanel.prototype.publish("dataButtonVisible", true, "boolean", "Show data table button");
|
|
578
|
-
ChartPanel.prototype.publish("downloadButtonVisible", true, "boolean", "Show data download button");
|
|
579
|
-
ChartPanel.prototype.publish("downloadImageButtonVisible", false, "boolean", "Show image download button");
|
|
580
|
-
ChartPanel.prototype.publish("downloadTitle", "", "string", "File name when downloaded");
|
|
581
|
-
ChartPanel.prototype.publish("downloadTimestampSuffix", true, "boolean", "Use timestamp as file name suffix");
|
|
582
|
-
ChartPanel.prototype.publish("legendVisible", false, "boolean", "Show legend");
|
|
583
|
-
ChartPanel.prototype.publish("legendButtonVisible", true, "boolean", "Show legend button");
|
|
584
|
-
ChartPanel.prototype.publish("legendPosition", "right", "set", "Position of legend", ["right", "bottom"]);
|
|
585
|
-
ChartPanel.prototype.publishProxy("legend_labelMaxWidth", "_legend", "labelMaxWidth");
|
|
586
|
-
ChartPanel.prototype.publishProxy("legend_showSeriesTotal", "_legend", "showSeriesTotal");
|
|
587
|
-
ChartPanel.prototype.publishProxy("legend_showLegendTotal", "_legend", "showLegendTotal");
|
|
588
|
-
ChartPanel.prototype.publishProxy("legend_itemPadding", "_legend", "itemPadding");
|
|
589
|
-
ChartPanel.prototype.publishProxy("legend_shapeRadius", "_legend", "shapeRadius");
|
|
590
|
-
ChartPanel.prototype.publishProxy("legend_symbolType", "_legend", "symbolType");
|
|
591
|
-
ChartPanel.prototype.publishProxy("legend_labelAlign", "_legend", "labelAlign");
|
|
592
|
-
ChartPanel.prototype.publish("widget", null, "widget", "Widget", undefined, { render: false });
|
|
593
|
-
ChartPanel.prototype.publish("enableAutoscaling", false, "boolean");
|
|
594
|
-
ChartPanel.prototype.publish("highlightSize", 4, "number");
|
|
595
|
-
ChartPanel.prototype.publish("highlightColor", "#e67e22", "html-color");
|
|
596
|
-
ChartPanel.prototype.publishProxy("progress_halfLife", "_progressBar", "halfLife");
|
|
597
|
-
ChartPanel.prototype.publishProxy("progress_decay", "_progressBar", "decay");
|
|
598
|
-
ChartPanel.prototype.publishProxy("progress_size", "_progressBar", "size");
|
|
599
|
-
ChartPanel.prototype.publishProxy("progress_color", "_progressBar", "color");
|
|
600
|
-
ChartPanel.prototype.publishProxy("progress_blurBar", "_progressBar", "blurBar");
|
|
601
|
-
ChartPanel.prototype.publishProxy("progress_blurSize", "_progressBar", "blurSize");
|
|
602
|
-
ChartPanel.prototype.publishProxy("progress_blurColor", "_progressBar", "blurColor");
|
|
603
|
-
ChartPanel.prototype.publishProxy("progress_blurOpacity", "_progressBar", "blurOpacity");
|
|
604
|
-
|
|
605
|
-
ChartPanel.prototype.widget = function (_?) {
|
|
606
|
-
if (!arguments.length) return this._widget;
|
|
607
|
-
this._carousel.widgets([_, this._table]);
|
|
608
|
-
this._widget = _;
|
|
609
|
-
this._widget
|
|
610
|
-
.fields(this._legend.filteredFields())
|
|
611
|
-
.data(this._legend.filteredData())
|
|
612
|
-
;
|
|
613
|
-
|
|
614
|
-
const context = this;
|
|
615
|
-
const tmpAny = this._widget as any;
|
|
616
|
-
tmpAny.click = function () {
|
|
617
|
-
context.click.apply(context, arguments);
|
|
618
|
-
};
|
|
619
|
-
tmpAny.dblclick = function () {
|
|
620
|
-
context.dblclick.apply(context, arguments);
|
|
621
|
-
};
|
|
622
|
-
tmpAny.vertex_click = function () {
|
|
623
|
-
context.vertex_click.apply(context, arguments);
|
|
624
|
-
};
|
|
625
|
-
tmpAny.vertex_dblclick = function () {
|
|
626
|
-
context.vertex_dblclick.apply(context, arguments);
|
|
627
|
-
};
|
|
628
|
-
tmpAny.edge_click = function () {
|
|
629
|
-
context.edge_click.apply(context, arguments);
|
|
630
|
-
};
|
|
631
|
-
tmpAny.edge_dblclick = function () {
|
|
632
|
-
context.edge_dblclick.apply(context, arguments);
|
|
633
|
-
};
|
|
634
|
-
return this;
|
|
635
|
-
};
|
|
1
|
+
import { IHighlight } from "@hpcc-js/api";
|
|
2
|
+
import { Button, Database, IconBar, ProgressBar, Spacer, SVGWidget, Text, TitleBar, ToggleButton, Utility, Widget } from "@hpcc-js/common";
|
|
3
|
+
import { Table } from "@hpcc-js/dgrid2";
|
|
4
|
+
import { select as d3Select } from "d3-selection";
|
|
5
|
+
import { Border2 } from "./Border2.ts";
|
|
6
|
+
import { Carousel } from "./Carousel.ts";
|
|
7
|
+
import { Legend } from "./Legend.ts";
|
|
8
|
+
import { Modal } from "./Modal.ts";
|
|
9
|
+
|
|
10
|
+
import "../src/ChartPanel.css";
|
|
11
|
+
|
|
12
|
+
export class ChartPanel<T extends Widget = Widget> extends Border2 implements IHighlight {
|
|
13
|
+
|
|
14
|
+
protected _legend = new Legend(this).enableOverflow(true);
|
|
15
|
+
protected _progressBar = new ProgressBar();
|
|
16
|
+
protected _autoScale = false;
|
|
17
|
+
protected _resolutions = {
|
|
18
|
+
tiny: { width: 100, height: 100 },
|
|
19
|
+
small: { width: 300, height: 300 }
|
|
20
|
+
};
|
|
21
|
+
private _modal = new Modal();
|
|
22
|
+
private _highlight: boolean;
|
|
23
|
+
private _scale: number;
|
|
24
|
+
private _orig_size: any;
|
|
25
|
+
|
|
26
|
+
private _toggleInfo = new ToggleButton().faChar("fa-info-circle").tooltip(".Description")
|
|
27
|
+
.selected(false)
|
|
28
|
+
.on("enabled", () => {
|
|
29
|
+
return this.description() !== "";
|
|
30
|
+
})
|
|
31
|
+
.on("click", () => {
|
|
32
|
+
if (this._toggleInfo.selected()) {
|
|
33
|
+
this._modal
|
|
34
|
+
.title(this.title())
|
|
35
|
+
.widget(new Text().text(this.description()))
|
|
36
|
+
.show(true)
|
|
37
|
+
.render()
|
|
38
|
+
;
|
|
39
|
+
|
|
40
|
+
const origCloseFunc = this._modal._close;
|
|
41
|
+
this._modal._close = () => {
|
|
42
|
+
this._toggleInfo
|
|
43
|
+
.selected(false)
|
|
44
|
+
.render()
|
|
45
|
+
;
|
|
46
|
+
this._modal._close = origCloseFunc;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
.on("mouseMove", () => {
|
|
51
|
+
/*
|
|
52
|
+
this._modal.showPreview(true).render(n => {
|
|
53
|
+
n.resize().render();
|
|
54
|
+
});
|
|
55
|
+
*/
|
|
56
|
+
})
|
|
57
|
+
.on("mouseOut", () => {
|
|
58
|
+
/*
|
|
59
|
+
if (this._modal.showPreview()) {
|
|
60
|
+
this._modal.show(false).showPreview(false).render();
|
|
61
|
+
}
|
|
62
|
+
*/
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
private _toggleData = new ToggleButton().faChar("fa-table").tooltip("Data")
|
|
66
|
+
.on("click", () => {
|
|
67
|
+
this.dataVisible(this._toggleData.selected());
|
|
68
|
+
this.render();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
private _buttonDownload = new Button().faChar("fa-download").tooltip("Download")
|
|
72
|
+
.on("click", () => {
|
|
73
|
+
this.downloadCSV();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
private _buttonDownloadImage = new Button().faChar("fa-image").tooltip("Download Image")
|
|
77
|
+
.on("click", () => {
|
|
78
|
+
this.downloadPNG();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
private _toggleLegend = new ToggleButton().faChar("fa-list-ul").tooltip("Legend")
|
|
82
|
+
.selected(false)
|
|
83
|
+
.on("click", () => {
|
|
84
|
+
const selected = this._toggleLegend.selected();
|
|
85
|
+
if (this.legendPosition() === "bottom") {
|
|
86
|
+
this.showBottom(selected);
|
|
87
|
+
} else if (this.legendPosition() === "right") {
|
|
88
|
+
this.showRight(selected);
|
|
89
|
+
}
|
|
90
|
+
this.legendVisible(selected);
|
|
91
|
+
this.render();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
protected _spacer = new Spacer();
|
|
95
|
+
|
|
96
|
+
_titleBar = new TitleBar().buttons([this._toggleData, this._buttonDownload, this._buttonDownloadImage, this._spacer, this._toggleLegend]);
|
|
97
|
+
|
|
98
|
+
protected _carousel = new Carousel();
|
|
99
|
+
protected _table = new Table();
|
|
100
|
+
protected _widget: T;
|
|
101
|
+
|
|
102
|
+
protected _hideLegendToggleList = ["dgrid_Table", "dgrid2_Table"];
|
|
103
|
+
|
|
104
|
+
constructor() {
|
|
105
|
+
super();
|
|
106
|
+
this._tag = "div";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
fields(): Database.Field[];
|
|
110
|
+
fields(_: Database.Field[]): this;
|
|
111
|
+
fields(_?: Database.Field[]): this | Database.Field[] {
|
|
112
|
+
if (!arguments.length) return super.fields();
|
|
113
|
+
super.fields(_);
|
|
114
|
+
this._legend.fields(_);
|
|
115
|
+
this.refreshFields();
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
refreshFields() {
|
|
119
|
+
this._widget.fields(this._legend.filteredFields());
|
|
120
|
+
this._table.fields(this._legend.filteredFields());
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
columns(): string[];
|
|
125
|
+
columns(_: string[], asDefault?: boolean): this;
|
|
126
|
+
columns(_?: string[], asDefault?: boolean): string[] | this {
|
|
127
|
+
if (!arguments.length) return super.columns();
|
|
128
|
+
super.columns(_, asDefault);
|
|
129
|
+
this._legend.columns(_, asDefault);
|
|
130
|
+
this.refreshColumns();
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
refreshColumns() {
|
|
134
|
+
this._widget.columns(this._legend.filteredColumns());
|
|
135
|
+
this._table.columns(this._legend.filteredColumns());
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
data(_?) {
|
|
140
|
+
if (!arguments.length) return super.data();
|
|
141
|
+
super.data(_);
|
|
142
|
+
this._legend.data(_);
|
|
143
|
+
this.refreshData();
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
refreshData() {
|
|
147
|
+
this._widget.data(this._legend.filteredData());
|
|
148
|
+
this._table.data(this._legend.filteredData());
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
highlight(): boolean;
|
|
153
|
+
highlight(_: boolean): this;
|
|
154
|
+
highlight(_?: boolean): boolean | this {
|
|
155
|
+
if (!arguments.length) return this._highlight;
|
|
156
|
+
this._highlight = _;
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
startProgress() {
|
|
161
|
+
this._progressBar.start();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
finishProgress() {
|
|
165
|
+
this._progressBar.finish();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
buttons(): Widget[];
|
|
169
|
+
buttons(_: Widget[]): this;
|
|
170
|
+
buttons(_?: Widget[]): this | Widget[] {
|
|
171
|
+
if (!arguments.length) return this._titleBar.buttons();
|
|
172
|
+
this._titleBar.buttons(_);
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
downloadCSV() {
|
|
177
|
+
const namePrefix = this.downloadTitle() ? this.downloadTitle() : this.title() ? this.title() : "data";
|
|
178
|
+
const nameSuffix = this.downloadTimestampSuffix() ? "_" + Utility.timestamp() : "";
|
|
179
|
+
Utility.downloadString("CSV", this._widget.export("CSV"), namePrefix + nameSuffix);
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
downloadPNG() {
|
|
184
|
+
const widget = this.widget();
|
|
185
|
+
if (widget instanceof SVGWidget) {
|
|
186
|
+
if (!this.legendVisible()) {
|
|
187
|
+
widget.downloadPNG(this.title());
|
|
188
|
+
} else {
|
|
189
|
+
widget.downloadPNG(this.title(), undefined, this._legend);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
highlightColumn(column?: string): this {
|
|
196
|
+
if (column) {
|
|
197
|
+
const cssTag = `series-${this.cssTag(column)}`;
|
|
198
|
+
this._centerWA.element().selectAll(".series")
|
|
199
|
+
.each(function () {
|
|
200
|
+
const element = d3Select(this);
|
|
201
|
+
const highlight = element.classed(cssTag);
|
|
202
|
+
element
|
|
203
|
+
.classed("highlight", highlight)
|
|
204
|
+
.classed("lowlight", !highlight)
|
|
205
|
+
;
|
|
206
|
+
})
|
|
207
|
+
;
|
|
208
|
+
} else {
|
|
209
|
+
this._centerWA.element().selectAll(".series")
|
|
210
|
+
.classed("highlight", false)
|
|
211
|
+
.classed("lowlight", false)
|
|
212
|
+
;
|
|
213
|
+
}
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
getResponsiveMode(): "tiny" | "small" | "regular" | "none" {
|
|
218
|
+
if (!this.enableAutoscaling()) return "none";
|
|
219
|
+
if (!this._autoScale) return "regular";
|
|
220
|
+
if (this.size().width <= this._resolutions.tiny.width || this.size().height <= this._resolutions.tiny.height) {
|
|
221
|
+
return "tiny";
|
|
222
|
+
} else if (this.size().width <= this._resolutions.small.width || this.size().height <= this._resolutions.small.height) {
|
|
223
|
+
return "small";
|
|
224
|
+
}
|
|
225
|
+
return "regular";
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
setOrigSize() {
|
|
229
|
+
this._orig_size = JSON.parse(JSON.stringify(this.size()));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
enter(domNode, element) {
|
|
233
|
+
super.enter(domNode, element);
|
|
234
|
+
this._modal
|
|
235
|
+
.target(this.target())
|
|
236
|
+
.relativeTargetId(this.id())
|
|
237
|
+
;
|
|
238
|
+
|
|
239
|
+
this.top(this._titleBar);
|
|
240
|
+
this.center(this._carousel);
|
|
241
|
+
|
|
242
|
+
this._legend
|
|
243
|
+
.targetWidget(this._widget)
|
|
244
|
+
.orientation("vertical")
|
|
245
|
+
.title("")
|
|
246
|
+
.visible(false)
|
|
247
|
+
;
|
|
248
|
+
|
|
249
|
+
this._progressBar.enter(domNode, element);
|
|
250
|
+
this.setOrigSize();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
preUpdateTiny(element) {
|
|
254
|
+
element.selectAll("div.body,div.title-text,div.icon-bar").style("display", "none");
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
preUpdateSmall(element) {
|
|
258
|
+
const scale_x = this._orig_size.width / this._resolutions.small.width;
|
|
259
|
+
const scale_y = this._orig_size.height / this._resolutions.small.height;
|
|
260
|
+
this._scale = Math.min(scale_x, scale_y);
|
|
261
|
+
const x_is_smaller = this._scale === scale_x;
|
|
262
|
+
this.size({
|
|
263
|
+
width: x_is_smaller ? this._resolutions.small.width : this._orig_size.width * (1 / this._scale),
|
|
264
|
+
height: !x_is_smaller ? this._resolutions.small.height : this._orig_size.height * (1 / this._scale)
|
|
265
|
+
});
|
|
266
|
+
element.select("div.title-icon").style("position", "static");
|
|
267
|
+
element.selectAll("lhs").style("display", "none");
|
|
268
|
+
element.selectAll("div.body,div.title-text,div.icon-bar").style("display", "");
|
|
269
|
+
element.selectAll("div.data-count").style("visibility", "hidden");
|
|
270
|
+
element.style("transform", `scale(${this._scale})`);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
preUpdateRegular(element) {
|
|
274
|
+
element.selectAll("div.body,div.title-text,div.icon-bar").style("display", "");
|
|
275
|
+
element.selectAll("div.data-count").style("visibility", "hidden");
|
|
276
|
+
element.select("div.title-icon").style("position", "static");
|
|
277
|
+
element.style("transform", "translate(0px,0px) scale(1)");
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private _prevdataVisible;
|
|
281
|
+
private _prevlegendVisible;
|
|
282
|
+
private _prevLegendPosition;
|
|
283
|
+
private _prevChartDataFamily;
|
|
284
|
+
private _prevChart;
|
|
285
|
+
private _prevButtons;
|
|
286
|
+
update(domNode, element) {
|
|
287
|
+
super.update(domNode, element);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
preUpdate(domNode, element) {
|
|
291
|
+
|
|
292
|
+
super.preUpdate(domNode, element);
|
|
293
|
+
|
|
294
|
+
if (this._prevLegendPosition !== this.legendPosition()) {
|
|
295
|
+
if (this._legend.target() !== null) this._legend.target(null);
|
|
296
|
+
if (this._prevLegendPosition !== undefined) {
|
|
297
|
+
this.swap(this._prevLegendPosition, this.legendPosition());
|
|
298
|
+
} else {
|
|
299
|
+
this[this.legendPosition()](this._legend);
|
|
300
|
+
}
|
|
301
|
+
if (this.legendPosition() === "right") {
|
|
302
|
+
this.rightOverflowX("hidden");
|
|
303
|
+
this.rightOverflowY("auto");
|
|
304
|
+
this.bottomOverflowX("visible");
|
|
305
|
+
this.bottomOverflowY("visible");
|
|
306
|
+
} else {
|
|
307
|
+
this.rightOverflowX("visible");
|
|
308
|
+
this.rightOverflowY("visible");
|
|
309
|
+
this.bottomOverflowX("auto");
|
|
310
|
+
this.bottomOverflowY("hidden");
|
|
311
|
+
}
|
|
312
|
+
this._prevLegendPosition = this.legendPosition();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (this._prevdataVisible !== this.dataVisible()) {
|
|
316
|
+
this._prevdataVisible = this.dataVisible();
|
|
317
|
+
this._toggleData.selected(this._prevdataVisible);
|
|
318
|
+
this._legend.visible(this._prevlegendVisible && !this._prevdataVisible);
|
|
319
|
+
this._carousel.active(this._prevdataVisible ? 1 : 0);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (this._prevlegendVisible !== this.legendVisible()) {
|
|
323
|
+
this._prevlegendVisible = this.legendVisible();
|
|
324
|
+
this._toggleLegend.selected(this._prevlegendVisible);
|
|
325
|
+
this._legend.visible(this._prevlegendVisible && !this._prevdataVisible);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
this._legend.orientation(this.legendPosition() === "bottom" ? "horizontal" : "vertical");
|
|
329
|
+
|
|
330
|
+
this.showLeft(!this.left());
|
|
331
|
+
|
|
332
|
+
switch (this.getResponsiveMode()) {
|
|
333
|
+
case "tiny":
|
|
334
|
+
this.preUpdateTiny(element);
|
|
335
|
+
break;
|
|
336
|
+
case "small":
|
|
337
|
+
this.preUpdateSmall(element);
|
|
338
|
+
break;
|
|
339
|
+
case "regular":
|
|
340
|
+
this.preUpdateRegular(element);
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const chart = this._widget.classID() === "composite_MultiChart" ? this._widget["chart"]() : this._widget;
|
|
345
|
+
this._legend.dataFamily(chart._dataFamily || "any");
|
|
346
|
+
|
|
347
|
+
if (this._prevChartDataFamily !== this._legend.dataFamily()) {
|
|
348
|
+
this._prevChartDataFamily = this._legend.dataFamily();
|
|
349
|
+
switch (this._prevChartDataFamily) {
|
|
350
|
+
case "any":
|
|
351
|
+
this._toggleLegend.selected(false);
|
|
352
|
+
this._legend.visible(false);
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
element.style("box-shadow", this.highlight() ? `inset 0px 0px 0px ${this.highlightSize()}px ${this.highlightColor()}` : "none");
|
|
357
|
+
|
|
358
|
+
if (this._hideLegendToggleList.indexOf(chart.classID()) !== -1) {
|
|
359
|
+
this._spacer.visible(false);
|
|
360
|
+
this._toggleLegend.visible(false);
|
|
361
|
+
} else {
|
|
362
|
+
this._spacer.visible(true);
|
|
363
|
+
this._toggleLegend.visible(true);
|
|
364
|
+
}
|
|
365
|
+
if (this._prevChart !== chart) {
|
|
366
|
+
this._prevChart = chart;
|
|
367
|
+
const widgetIconBar = chart ? chart["_titleBar"] || chart["_iconBar"] : undefined;
|
|
368
|
+
if (widgetIconBar && widgetIconBar instanceof IconBar) {
|
|
369
|
+
this._prevButtons = this._prevButtons || [...this.buttons()];
|
|
370
|
+
const buttons: Widget[] = [
|
|
371
|
+
...widgetIconBar.buttons(),
|
|
372
|
+
new Spacer(),
|
|
373
|
+
...this._prevButtons
|
|
374
|
+
];
|
|
375
|
+
widgetIconBar.buttons([]).render();
|
|
376
|
+
this.buttons(buttons);
|
|
377
|
+
} else if (this._prevButtons) {
|
|
378
|
+
this.buttons(this._prevButtons);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const hiddenButtons = [];
|
|
383
|
+
if (!this.dataButtonVisible()) hiddenButtons.push(this._toggleData);
|
|
384
|
+
if (!this.downloadButtonVisible()) hiddenButtons.push(this._buttonDownload);
|
|
385
|
+
if (!this.downloadImageButtonVisible()) hiddenButtons.push(this._buttonDownloadImage);
|
|
386
|
+
if (!this.legendButtonVisible()) hiddenButtons.push(this._toggleLegend);
|
|
387
|
+
this._buttonDownloadImage.enabled(this.widget() instanceof SVGWidget);
|
|
388
|
+
this._titleBar
|
|
389
|
+
.hiddenButtons(hiddenButtons)
|
|
390
|
+
.visible(this.titleVisible())
|
|
391
|
+
;
|
|
392
|
+
this.topOverlay(this.titleOverlay() || !this.titleVisible());
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
postUpdate(domNode, element) {
|
|
396
|
+
super.postUpdate(domNode, element);
|
|
397
|
+
|
|
398
|
+
switch (this.getResponsiveMode()) {
|
|
399
|
+
case "tiny":
|
|
400
|
+
this.postUpdateTiny(element);
|
|
401
|
+
break;
|
|
402
|
+
case "small":
|
|
403
|
+
this.postUpdateSmall(element);
|
|
404
|
+
break;
|
|
405
|
+
case "regular":
|
|
406
|
+
this.postUpdateRegular(element);
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
postUpdateTiny(element) {
|
|
412
|
+
element.selectAll("div.body,div.title-text,div.icon-bar").style("display", "none");
|
|
413
|
+
element.selectAll("div.data-count")
|
|
414
|
+
.style("visibility", "visible")
|
|
415
|
+
.style("font-size", (this.titleIconFontSize() / 3) + "px")
|
|
416
|
+
.style("line-height", (this.titleIconFontSize() / 3) + "px")
|
|
417
|
+
.style("left", this.titleIconFontSize() + "px")
|
|
418
|
+
.text(this.data().length)
|
|
419
|
+
;
|
|
420
|
+
element.style("transform", "translate(0px,0px) scale(1)");
|
|
421
|
+
const iconDiv = element.selectAll("div.title-icon");
|
|
422
|
+
const _node = iconDiv.node();
|
|
423
|
+
const _container = element.node().parentElement;
|
|
424
|
+
const containerRect = _container.getBoundingClientRect();
|
|
425
|
+
if (_node) {
|
|
426
|
+
const rect = iconDiv.node().getBoundingClientRect();
|
|
427
|
+
const icon_top = containerRect.height / 2;
|
|
428
|
+
iconDiv
|
|
429
|
+
.style("position", "absolute")
|
|
430
|
+
.style("left", `calc(50% - ${rect.width / 2}px)`)
|
|
431
|
+
.style("top", `${icon_top - (rect.height / 2)}px`)
|
|
432
|
+
;
|
|
433
|
+
element.selectAll("div.data-count")
|
|
434
|
+
.style("position", "absolute")
|
|
435
|
+
.style("left", `calc(50% + ${rect.width / 2}px)`)
|
|
436
|
+
.style("top", `${icon_top - (rect.height / 2)}px`)
|
|
437
|
+
;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
postUpdateSmall(element) {
|
|
442
|
+
element.selectAll("lhs").style("display", "none"); // TODO: a bug in Border2?
|
|
443
|
+
element.selectAll("div.title-icon").style("position", "static");
|
|
444
|
+
element.selectAll("div.body,div.title-text,div.icon-bar").style("display", "");
|
|
445
|
+
element.selectAll("div.data-count").style("visibility", "hidden");
|
|
446
|
+
const rect = element.node().getBoundingClientRect();
|
|
447
|
+
const parentRect = element.node().parentElement.getBoundingClientRect();
|
|
448
|
+
element.style("transform", `translate(${parentRect.x - rect.x}px, ${parentRect.y - rect.y}px) scale(${this._scale})`);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
postUpdateRegular(element) {
|
|
452
|
+
element.selectAll("div.title-icon").style("position", "static");
|
|
453
|
+
element.selectAll("div.body,div.title-text,div.icon-bar").style("display", "");
|
|
454
|
+
element.selectAll("div.data-count").style("visibility", "hidden");
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
exit(domNode, element) {
|
|
458
|
+
this._progressBar.exit(domNode, element);
|
|
459
|
+
|
|
460
|
+
this.right(null);
|
|
461
|
+
this._legend.target(null);
|
|
462
|
+
this.center(null);
|
|
463
|
+
this._carousel.target(null);
|
|
464
|
+
this.top(null);
|
|
465
|
+
this._titleBar.target(null);
|
|
466
|
+
|
|
467
|
+
this._modal.target(null);
|
|
468
|
+
|
|
469
|
+
delete this._prevChart;
|
|
470
|
+
delete this._prevButtons;
|
|
471
|
+
delete this._prevChartDataFamily;
|
|
472
|
+
delete this._prevPos;
|
|
473
|
+
delete this._prevdataVisible;
|
|
474
|
+
delete this._prevlegendVisible;
|
|
475
|
+
|
|
476
|
+
super.exit(domNode, element);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// Event Handlers ---
|
|
480
|
+
// Events ---
|
|
481
|
+
click(row, column, selected) {
|
|
482
|
+
// console.log("Click: " + JSON.stringify(row) + ", " + column + ", " + selected);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
dblclick(row, column, selected) {
|
|
486
|
+
// console.log("Double click: " + JSON.stringify(row) + ", " + column + ", " + selected);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
vertex_click(row, col, sel, more) {
|
|
490
|
+
if (more && more.vertex) {
|
|
491
|
+
// console.log("Vertex click: " + more.vertex.id());
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
vertex_dblclick(row, col, sel, more) {
|
|
496
|
+
if (more && more.vertex) {
|
|
497
|
+
// console.log("Vertex double click: " + more.vertex.id());
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
edge_click(row, col, sel, more) {
|
|
502
|
+
if (more && more.edge) {
|
|
503
|
+
// console.log("Edge click: " + more.edge.id());
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
edge_dblclick(row, col, sel, more) {
|
|
508
|
+
if (more && more.edge) {
|
|
509
|
+
// console.log("Edge double click: " + more.edge.id());
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
ChartPanel.prototype._class += " layout_ChartPanel";
|
|
514
|
+
|
|
515
|
+
export interface ChartPanel<T extends Widget = Widget> {
|
|
516
|
+
title(): string;
|
|
517
|
+
title(_: string): this;
|
|
518
|
+
titleVisible(): boolean;
|
|
519
|
+
titleVisible(_: boolean): this;
|
|
520
|
+
titleOverlay(): boolean;
|
|
521
|
+
titleOverlay(_: boolean): this;
|
|
522
|
+
title_exists(): boolean;
|
|
523
|
+
titleFontSize(): number;
|
|
524
|
+
titleFontSize(_: number): this;
|
|
525
|
+
titleFontSize_exists(): boolean;
|
|
526
|
+
titleIconFontSize(): number;
|
|
527
|
+
titleIconFontSize(_: number): this;
|
|
528
|
+
titleIconFontSize_exists(): boolean;
|
|
529
|
+
dataVisible(): boolean;
|
|
530
|
+
dataVisible(_: boolean): this;
|
|
531
|
+
dataButtonVisible(): boolean;
|
|
532
|
+
dataButtonVisible(_: boolean): this;
|
|
533
|
+
downloadButtonVisible(): boolean;
|
|
534
|
+
downloadButtonVisible(_: boolean): this;
|
|
535
|
+
downloadImageButtonVisible(): boolean;
|
|
536
|
+
downloadImageButtonVisible(_: boolean): this;
|
|
537
|
+
downloadTitle(): string;
|
|
538
|
+
downloadTitle(_: string): this;
|
|
539
|
+
downloadTimestampSuffix(): boolean;
|
|
540
|
+
downloadTimestampSuffix(_: boolean): this;
|
|
541
|
+
legendVisible(): boolean;
|
|
542
|
+
legendVisible(_: boolean): this;
|
|
543
|
+
legendButtonVisible(): boolean;
|
|
544
|
+
legendButtonVisible(_: boolean): this;
|
|
545
|
+
legendPosition(): "right" | "bottom";
|
|
546
|
+
legendPosition(_: "right" | "bottom"): this;
|
|
547
|
+
description(): string;
|
|
548
|
+
description(_: string): this;
|
|
549
|
+
description_exists(): boolean;
|
|
550
|
+
widget(): T;
|
|
551
|
+
widget(_: T): this;
|
|
552
|
+
widget_exists(): boolean;
|
|
553
|
+
enableAutoscaling(): boolean;
|
|
554
|
+
enableAutoscaling(_: boolean): this;
|
|
555
|
+
enableAutoscaling_exists(): boolean;
|
|
556
|
+
highlightSize(): number;
|
|
557
|
+
highlightSize(_: number): this;
|
|
558
|
+
highlightSize_exists(): boolean;
|
|
559
|
+
highlightColor(): string;
|
|
560
|
+
highlightColor(_: string): this;
|
|
561
|
+
highlightColor_exists(): boolean;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
ChartPanel.prototype.publishReset();
|
|
565
|
+
ChartPanel.prototype.publishProxy("title", "_titleBar");
|
|
566
|
+
ChartPanel.prototype.publish("titleVisible", true, "boolean");
|
|
567
|
+
ChartPanel.prototype.publish("titleOverlay", false, "boolean");
|
|
568
|
+
ChartPanel.prototype.publishProxy("titleIcon", "_titleBar");
|
|
569
|
+
ChartPanel.prototype.publishProxy("titleIconFont", "_titleBar");
|
|
570
|
+
ChartPanel.prototype.publishProxy("titleFont", "_titleBar");
|
|
571
|
+
ChartPanel.prototype.publishProxy("titleIconFontSize", "_titleBar");
|
|
572
|
+
ChartPanel.prototype.publishProxy("titleFontSize", "_titleBar");
|
|
573
|
+
ChartPanel.prototype.publishProxy("description", "_titleBar");
|
|
574
|
+
ChartPanel.prototype.publishProxy("descriptionFont", "_titleBar");
|
|
575
|
+
ChartPanel.prototype.publishProxy("descriptionFontSize", "_titleBar");
|
|
576
|
+
ChartPanel.prototype.publish("dataVisible", false, "boolean", "Show data table");
|
|
577
|
+
ChartPanel.prototype.publish("dataButtonVisible", true, "boolean", "Show data table button");
|
|
578
|
+
ChartPanel.prototype.publish("downloadButtonVisible", true, "boolean", "Show data download button");
|
|
579
|
+
ChartPanel.prototype.publish("downloadImageButtonVisible", false, "boolean", "Show image download button");
|
|
580
|
+
ChartPanel.prototype.publish("downloadTitle", "", "string", "File name when downloaded");
|
|
581
|
+
ChartPanel.prototype.publish("downloadTimestampSuffix", true, "boolean", "Use timestamp as file name suffix");
|
|
582
|
+
ChartPanel.prototype.publish("legendVisible", false, "boolean", "Show legend");
|
|
583
|
+
ChartPanel.prototype.publish("legendButtonVisible", true, "boolean", "Show legend button");
|
|
584
|
+
ChartPanel.prototype.publish("legendPosition", "right", "set", "Position of legend", ["right", "bottom"]);
|
|
585
|
+
ChartPanel.prototype.publishProxy("legend_labelMaxWidth", "_legend", "labelMaxWidth");
|
|
586
|
+
ChartPanel.prototype.publishProxy("legend_showSeriesTotal", "_legend", "showSeriesTotal");
|
|
587
|
+
ChartPanel.prototype.publishProxy("legend_showLegendTotal", "_legend", "showLegendTotal");
|
|
588
|
+
ChartPanel.prototype.publishProxy("legend_itemPadding", "_legend", "itemPadding");
|
|
589
|
+
ChartPanel.prototype.publishProxy("legend_shapeRadius", "_legend", "shapeRadius");
|
|
590
|
+
ChartPanel.prototype.publishProxy("legend_symbolType", "_legend", "symbolType");
|
|
591
|
+
ChartPanel.prototype.publishProxy("legend_labelAlign", "_legend", "labelAlign");
|
|
592
|
+
ChartPanel.prototype.publish("widget", null, "widget", "Widget", undefined, { render: false });
|
|
593
|
+
ChartPanel.prototype.publish("enableAutoscaling", false, "boolean");
|
|
594
|
+
ChartPanel.prototype.publish("highlightSize", 4, "number");
|
|
595
|
+
ChartPanel.prototype.publish("highlightColor", "#e67e22", "html-color");
|
|
596
|
+
ChartPanel.prototype.publishProxy("progress_halfLife", "_progressBar", "halfLife");
|
|
597
|
+
ChartPanel.prototype.publishProxy("progress_decay", "_progressBar", "decay");
|
|
598
|
+
ChartPanel.prototype.publishProxy("progress_size", "_progressBar", "size");
|
|
599
|
+
ChartPanel.prototype.publishProxy("progress_color", "_progressBar", "color");
|
|
600
|
+
ChartPanel.prototype.publishProxy("progress_blurBar", "_progressBar", "blurBar");
|
|
601
|
+
ChartPanel.prototype.publishProxy("progress_blurSize", "_progressBar", "blurSize");
|
|
602
|
+
ChartPanel.prototype.publishProxy("progress_blurColor", "_progressBar", "blurColor");
|
|
603
|
+
ChartPanel.prototype.publishProxy("progress_blurOpacity", "_progressBar", "blurOpacity");
|
|
604
|
+
|
|
605
|
+
ChartPanel.prototype.widget = function (_?) {
|
|
606
|
+
if (!arguments.length) return this._widget;
|
|
607
|
+
this._carousel.widgets([_, this._table]);
|
|
608
|
+
this._widget = _;
|
|
609
|
+
this._widget
|
|
610
|
+
.fields(this._legend.filteredFields())
|
|
611
|
+
.data(this._legend.filteredData())
|
|
612
|
+
;
|
|
613
|
+
|
|
614
|
+
const context = this;
|
|
615
|
+
const tmpAny = this._widget as any;
|
|
616
|
+
tmpAny.click = function () {
|
|
617
|
+
context.click.apply(context, arguments);
|
|
618
|
+
};
|
|
619
|
+
tmpAny.dblclick = function () {
|
|
620
|
+
context.dblclick.apply(context, arguments);
|
|
621
|
+
};
|
|
622
|
+
tmpAny.vertex_click = function () {
|
|
623
|
+
context.vertex_click.apply(context, arguments);
|
|
624
|
+
};
|
|
625
|
+
tmpAny.vertex_dblclick = function () {
|
|
626
|
+
context.vertex_dblclick.apply(context, arguments);
|
|
627
|
+
};
|
|
628
|
+
tmpAny.edge_click = function () {
|
|
629
|
+
context.edge_click.apply(context, arguments);
|
|
630
|
+
};
|
|
631
|
+
tmpAny.edge_dblclick = function () {
|
|
632
|
+
context.edge_dblclick.apply(context, arguments);
|
|
633
|
+
};
|
|
634
|
+
return this;
|
|
635
|
+
};
|