@trismegisto/charts 3.4.0 → 4.0.1
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/MIGRATION.md +831 -0
- package/NOTICE +1 -6
- package/README.md +24 -14
- package/dist/core/bar-chart.d.ts +23 -3
- package/dist/core/bar-chart.js +98 -20
- package/dist/core/bar-chart.js.map +1 -1
- package/dist/core/boxplot-chart.js +12 -13
- package/dist/core/boxplot-chart.js.map +1 -1
- package/dist/core/bullet-chart.js +30 -32
- package/dist/core/bullet-chart.js.map +1 -1
- package/dist/core/calendar-heatmap.d.ts +2 -0
- package/dist/core/calendar-heatmap.js +22 -23
- package/dist/core/calendar-heatmap.js.map +1 -1
- package/dist/core/category-range.d.ts +15 -0
- package/dist/core/category-range.js +35 -0
- package/dist/core/category-range.js.map +1 -0
- package/dist/core/chart-host.d.ts +25 -8
- package/dist/core/chart-host.js +124 -24
- package/dist/core/chart-host.js.map +1 -1
- package/dist/core/charts-messages.d.ts +71 -16
- package/dist/core/charts-messages.en.js +50 -13
- package/dist/core/charts-messages.en.js.map +1 -1
- package/dist/core/charts-messages.es.js +50 -13
- package/dist/core/charts-messages.es.js.map +1 -1
- package/dist/core/charts-messages.js +50 -13
- package/dist/core/charts-messages.js.map +1 -1
- package/dist/core/colors.d.ts +27 -0
- package/dist/core/colors.js +76 -0
- package/dist/core/colors.js.map +1 -0
- package/dist/core/context.d.ts +22 -2
- package/dist/core/context.js +25 -2
- package/dist/core/context.js.map +1 -1
- package/dist/core/engine-locale.d.ts +3 -2
- package/dist/core/engine-locale.js +23 -44
- package/dist/core/engine-locale.js.map +1 -1
- package/dist/core/frame.d.ts +13 -1
- package/dist/core/frame.js +37 -1
- package/dist/core/frame.js.map +1 -1
- package/dist/core/funnel-chart.js +9 -12
- package/dist/core/funnel-chart.js.map +1 -1
- package/dist/core/gauge-chart.js +31 -63
- package/dist/core/gauge-chart.js.map +1 -1
- package/dist/core/heatmap-chart.d.ts +5 -0
- package/dist/core/heatmap-chart.js +28 -21
- package/dist/core/heatmap-chart.js.map +1 -1
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.js +14 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/line-chart.d.ts +34 -3
- package/dist/core/line-chart.js +90 -20
- package/dist/core/line-chart.js.map +1 -1
- package/dist/core/line-extras.d.ts +20 -0
- package/dist/core/line-extras.js +49 -0
- package/dist/core/line-extras.js.map +1 -0
- package/dist/core/linear-gauge.d.ts +64 -0
- package/dist/core/linear-gauge.js +78 -0
- package/dist/core/linear-gauge.js.map +1 -0
- package/dist/core/live-session.d.ts +58 -0
- package/dist/core/live-session.js +200 -0
- package/dist/core/live-session.js.map +1 -0
- package/dist/core/live.d.ts +78 -0
- package/dist/core/live.js +245 -0
- package/dist/core/live.js.map +1 -0
- package/dist/core/navigation.d.ts +3 -8
- package/dist/core/navigation.js +12 -7
- package/dist/core/navigation.js.map +1 -1
- package/dist/core/normalize.d.ts +19 -0
- package/dist/core/normalize.js +51 -0
- package/dist/core/normalize.js.map +1 -0
- package/dist/core/observe.js +51 -15
- package/dist/core/observe.js.map +1 -1
- package/dist/core/options.d.ts +9 -7
- package/dist/core/options.js +16 -11
- package/dist/core/options.js.map +1 -1
- package/dist/core/pie-chart.d.ts +18 -2
- package/dist/core/pie-chart.js +83 -18
- package/dist/core/pie-chart.js.map +1 -1
- package/dist/core/radar-chart.js +10 -10
- package/dist/core/radar-chart.js.map +1 -1
- package/dist/core/range-interaction.d.ts +62 -0
- package/dist/core/range-interaction.js +196 -0
- package/dist/core/range-interaction.js.map +1 -0
- package/dist/core/range.d.ts +83 -0
- package/dist/core/range.js +200 -0
- package/dist/core/range.js.map +1 -0
- package/dist/core/references.d.ts +25 -0
- package/dist/core/references.js +71 -0
- package/dist/core/references.js.map +1 -0
- package/dist/core/sankey-chart.js +8 -12
- package/dist/core/sankey-chart.js.map +1 -1
- package/dist/core/scale-legend.d.ts +10 -0
- package/dist/core/scale-legend.js +16 -0
- package/dist/core/scale-legend.js.map +1 -0
- package/dist/core/scatter-chart.d.ts +5 -0
- package/dist/core/scatter-chart.js +34 -22
- package/dist/core/scatter-chart.js.map +1 -1
- package/dist/core/scope-cache.d.ts +6 -0
- package/dist/core/scope-cache.js +49 -0
- package/dist/core/scope-cache.js.map +1 -0
- package/dist/core/series-extras.d.ts +46 -0
- package/dist/core/series-extras.js +125 -0
- package/dist/core/series-extras.js.map +1 -0
- package/dist/core/sparkline-chart.d.ts +11 -0
- package/dist/core/sparkline-chart.js +27 -18
- package/dist/core/sparkline-chart.js.map +1 -1
- package/dist/core/theme.d.ts +3 -2
- package/dist/core/theme.js +36 -69
- package/dist/core/theme.js.map +1 -1
- package/dist/core/time-series-chart.d.ts +91 -0
- package/dist/core/time-series-chart.js +390 -0
- package/dist/core/time-series-chart.js.map +1 -0
- package/dist/core/treemap-chart.js +12 -16
- package/dist/core/treemap-chart.js.map +1 -1
- package/dist/core/types.d.ts +57 -0
- package/dist/core/view.d.ts +73 -2
- package/dist/core/warn.d.ts +5 -0
- package/dist/core/warn.js +22 -0
- package/dist/core/warn.js.map +1 -0
- package/dist/core/waterfall-chart.js +17 -18
- package/dist/core/waterfall-chart.js.map +1 -1
- package/dist/engine/aria.d.ts +1 -6
- package/dist/engine/aria.js +1 -53
- package/dist/engine/aria.js.map +1 -1
- package/dist/engine/component/legend.js +11 -12
- package/dist/engine/component/legend.js.map +1 -1
- package/dist/engine/component/reference-marks.d.ts +46 -0
- package/dist/engine/component/reference-marks.js +197 -0
- package/dist/engine/component/reference-marks.js.map +1 -0
- package/dist/engine/component/text-style.d.ts +1 -1
- package/dist/engine/component/text-style.js +2 -2
- package/dist/engine/component/text-style.js.map +1 -1
- package/dist/engine/component/tooltip.js +8 -32
- package/dist/engine/component/tooltip.js.map +1 -1
- package/dist/engine/component/view-window.d.ts +29 -0
- package/dist/engine/component/view-window.js +39 -0
- package/dist/engine/component/view-window.js.map +1 -0
- package/dist/engine/component/visual-map.js +2 -2
- package/dist/engine/component/visual-map.js.map +1 -1
- package/dist/engine/contract.d.ts +29 -64
- package/dist/engine/contract.js +4 -5
- package/dist/engine/contract.js.map +1 -1
- package/dist/engine/coord/axis.js +12 -3
- package/dist/engine/coord/axis.js.map +1 -1
- package/dist/engine/coord/calendar.js +1 -1
- package/dist/engine/coord/calendar.js.map +1 -1
- package/dist/engine/coord/cartesian.js +37 -5
- package/dist/engine/coord/cartesian.js.map +1 -1
- package/dist/engine/coord/radar.d.ts +1 -1
- package/dist/engine/index.d.ts +3 -27
- package/dist/engine/index.js +4 -15
- package/dist/engine/index.js.map +1 -1
- package/dist/engine/instance.d.ts +54 -32
- package/dist/engine/instance.js +399 -179
- package/dist/engine/instance.js.map +1 -1
- package/dist/engine/locale.d.ts +3 -6
- package/dist/engine/locale.js +26 -80
- package/dist/engine/locale.js.map +1 -1
- package/dist/engine/model.d.ts +3 -8
- package/dist/engine/model.js +13 -160
- package/dist/engine/model.js.map +1 -1
- package/dist/engine/option/components.d.ts +29 -19
- package/dist/engine/registry.d.ts +0 -2
- package/dist/engine/registry.js +3 -5
- package/dist/engine/registry.js.map +1 -1
- package/dist/engine/render/path.d.ts +2 -3
- package/dist/engine/render/path.js +8 -17
- package/dist/engine/render/path.js.map +1 -1
- package/dist/engine/render/svg.js +32 -5
- package/dist/engine/render/svg.js.map +1 -1
- package/dist/engine/scale.d.ts +12 -2
- package/dist/engine/scale.js +86 -18
- package/dist/engine/scale.js.map +1 -1
- package/dist/engine/series/bar.d.ts +3 -1
- package/dist/engine/series/bar.js +15 -4
- package/dist/engine/series/bar.js.map +1 -1
- package/dist/engine/series/boxplot.js +2 -2
- package/dist/engine/series/boxplot.js.map +1 -1
- package/dist/engine/series/cartesian-data.d.ts +1 -1
- package/dist/engine/series/cartesian-data.js +1 -1
- package/dist/engine/series/circular-common.d.ts +6 -7
- package/dist/engine/series/circular-common.js +8 -26
- package/dist/engine/series/circular-common.js.map +1 -1
- package/dist/engine/series/common.d.ts +2 -5
- package/dist/engine/series/common.js +6 -18
- package/dist/engine/series/common.js.map +1 -1
- package/dist/engine/series/funnel.js +1 -1
- package/dist/engine/series/funnel.js.map +1 -1
- package/dist/engine/series/gauge.js +2 -2
- package/dist/engine/series/gauge.js.map +1 -1
- package/dist/engine/series/heatmap.js +2 -2
- package/dist/engine/series/heatmap.js.map +1 -1
- package/dist/engine/series/label-fit.d.ts +1 -1
- package/dist/engine/series/label-fit.js +4 -12
- package/dist/engine/series/label-fit.js.map +1 -1
- package/dist/engine/series/line.d.ts +3 -1
- package/dist/engine/series/line.js +14 -7
- package/dist/engine/series/line.js.map +1 -1
- package/dist/engine/series/mark-point.d.ts +4 -0
- package/dist/engine/series/mark-point.js +196 -0
- package/dist/engine/series/mark-point.js.map +1 -0
- package/dist/engine/series/pie.d.ts +5 -0
- package/dist/engine/series/pie.js +8 -2
- package/dist/engine/series/pie.js.map +1 -1
- package/dist/engine/series/radar.js +7 -7
- package/dist/engine/series/radar.js.map +1 -1
- package/dist/engine/series/sankey.js +4 -4
- package/dist/engine/series/sankey.js.map +1 -1
- package/dist/engine/series/scatter.d.ts +3 -1
- package/dist/engine/series/scatter.js.map +1 -1
- package/dist/engine/series/treemap.js +6 -6
- package/dist/engine/series/treemap.js.map +1 -1
- package/dist/engine/spec/compile.d.ts +9 -0
- package/dist/engine/spec/compile.js +593 -0
- package/dist/engine/spec/compile.js.map +1 -0
- package/dist/engine/spec/theme.d.ts +5 -0
- package/dist/engine/spec/theme.js +83 -0
- package/dist/engine/spec/theme.js.map +1 -0
- package/dist/engine/spec/types.d.ts +564 -0
- package/dist/engine/spec/types.js +3 -0
- package/dist/engine/spec/types.js.map +1 -0
- package/dist/engine/theme.d.ts +2 -3
- package/dist/engine/theme.js +10 -9
- package/dist/engine/theme.js.map +1 -1
- package/dist/engine/util.d.ts +12 -7
- package/dist/engine/util.js +26 -10
- package/dist/engine/util.js.map +1 -1
- package/package.json +4 -3
- package/dist/engine/option.d.ts +0 -59
- package/dist/engine/option.js +0 -2
- package/dist/engine/option.js.map +0 -1
package/dist/engine/instance.js
CHANGED
|
@@ -1,18 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { compileSpec } from './spec/compile';
|
|
2
|
+
import { themePlan } from './spec/theme';
|
|
3
|
+
import { decalFor } from './aria';
|
|
2
4
|
import { nextLegendSelection, scrollLegend } from './component/legend';
|
|
3
5
|
import { TooltipController } from './component/tooltip';
|
|
4
6
|
import { createVisualResolver, toggleVisualPiece } from './component/visual-map';
|
|
5
7
|
import { layoutLabels } from './label-layout';
|
|
8
|
+
import { markPointNodes } from './series/mark-point';
|
|
9
|
+
import { referenceMarkNodes } from './component/reference-marks';
|
|
10
|
+
import { sweepNodes, viewWindowOf } from './component/view-window';
|
|
6
11
|
import { createLocale, languageOf } from './locale';
|
|
7
|
-
import { dataCount,
|
|
12
|
+
import { dataCount, normalizeOption } from './model';
|
|
8
13
|
import { COMPONENT_TYPES, COORDINATE_TYPES, SERIES_TYPES } from './registry';
|
|
9
14
|
import { SvgRenderer } from './render/svg';
|
|
10
15
|
import { measureText } from './render/text';
|
|
11
16
|
import { buildTheme } from './theme';
|
|
12
|
-
import {
|
|
17
|
+
import { isPlainObject, isUnnamed, toArray } from './util';
|
|
13
18
|
const EASINGS = ['linear', 'cubicOut', 'cubicInOut', 'quadraticOut', 'elasticOut', 'backOut', 'exponentialOut'];
|
|
14
19
|
const FALLBACK_WIDTH = 600;
|
|
15
20
|
const FALLBACK_HEIGHT = 400;
|
|
21
|
+
/** De onde o evento veio, no vocabulário do contrato. */
|
|
22
|
+
function partOf(componentType) {
|
|
23
|
+
switch (componentType) {
|
|
24
|
+
case 'series':
|
|
25
|
+
return 'series';
|
|
26
|
+
case 'legend':
|
|
27
|
+
return 'legend';
|
|
28
|
+
case 'blank':
|
|
29
|
+
return 'plane';
|
|
30
|
+
case 'sweepSelect':
|
|
31
|
+
return 'sweep';
|
|
32
|
+
default:
|
|
33
|
+
return 'chart';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
16
36
|
const coordKey = (type, index) => `${type}:${index}`;
|
|
17
37
|
function easingOf(value, fallback) {
|
|
18
38
|
return EASINGS.includes(value) ? value : fallback;
|
|
@@ -25,15 +45,15 @@ function prefersReducedMotion() {
|
|
|
25
45
|
return false;
|
|
26
46
|
}
|
|
27
47
|
}
|
|
28
|
-
export class
|
|
48
|
+
export class Chart {
|
|
29
49
|
dom;
|
|
30
50
|
raw = {};
|
|
31
51
|
theme;
|
|
32
52
|
locale;
|
|
33
53
|
renderer;
|
|
34
54
|
tooltip;
|
|
35
|
-
|
|
36
|
-
|
|
55
|
+
plotWidth;
|
|
56
|
+
plotHeight;
|
|
37
57
|
fixedWidth;
|
|
38
58
|
fixedHeight;
|
|
39
59
|
legendSelected = {};
|
|
@@ -46,24 +66,31 @@ export class ChartInstanceImpl {
|
|
|
46
66
|
frame = null;
|
|
47
67
|
renderTicket = 0;
|
|
48
68
|
animateNext = true;
|
|
49
|
-
|
|
50
|
-
|
|
69
|
+
gone = false;
|
|
70
|
+
current = null;
|
|
71
|
+
/** A opção nova ainda não desenhou: a translação de `slide` vale nesse quadro só. */
|
|
72
|
+
slidePending = false;
|
|
73
|
+
/** Faixa temporária da seleção por arrasto (`sweepSelect`), enquanto o botão está apertado. */
|
|
74
|
+
sweep = null;
|
|
75
|
+
domListeners = [];
|
|
76
|
+
constructor(dom, opts = {}) {
|
|
51
77
|
this.dom = dom;
|
|
52
|
-
this.theme = buildTheme(theme);
|
|
78
|
+
this.theme = buildTheme(themePlan(opts.theme));
|
|
53
79
|
this.locale = createLocale(opts.locale ?? null, languageOf(dom));
|
|
54
80
|
this.fixedWidth = opts.width;
|
|
55
81
|
this.fixedHeight = opts.height;
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
58
|
-
if (getComputedStyleSafe(dom, 'position') === 'static')
|
|
82
|
+
this.plotWidth = this.measureWidth();
|
|
83
|
+
this.plotHeight = this.measureHeight();
|
|
84
|
+
if (!opts.positioned && getComputedStyleSafe(dom, 'position') === 'static')
|
|
59
85
|
dom.style.position = 'relative';
|
|
60
86
|
this.renderer = new SvgRenderer(dom, {
|
|
61
87
|
onPointer: (item, x, y, e) => this.onPointer(item, x, y, e),
|
|
62
88
|
onClick: (item, x, y, e) => this.onClick(item, x, y, e),
|
|
63
89
|
onLeave: (e) => this.onLeave(e),
|
|
64
90
|
});
|
|
65
|
-
this.renderer.onFinished = () => this.emit('
|
|
66
|
-
this.
|
|
91
|
+
this.renderer.onFinished = () => this.emit('settled', { componentType: 'chart' });
|
|
92
|
+
this.listenSweep();
|
|
93
|
+
this.renderer.setSize(this.plotWidth, this.plotHeight);
|
|
67
94
|
this.tooltip = new TooltipController(dom, () => this.currentCtx(), {
|
|
68
95
|
paramsOf: (model, dataIndex) => SERIES_TYPES.get(model.type)?.tooltipParams(model, dataIndex, this.currentCtx()) ?? null,
|
|
69
96
|
itemsAtAxisValue: (model, axisDim, value) => SERIES_TYPES.get(model.type)?.itemsAtAxisValue?.(model, axisDim, value, this.currentCtx()) ?? [],
|
|
@@ -76,73 +103,76 @@ export class ChartInstanceImpl {
|
|
|
76
103
|
measureHeight() {
|
|
77
104
|
return this.fixedHeight ?? (this.dom.clientHeight || FALLBACK_HEIGHT);
|
|
78
105
|
}
|
|
79
|
-
|
|
80
|
-
return this.
|
|
106
|
+
get width() {
|
|
107
|
+
return this.plotWidth;
|
|
81
108
|
}
|
|
82
|
-
|
|
83
|
-
return this.
|
|
109
|
+
get height() {
|
|
110
|
+
return this.plotHeight;
|
|
84
111
|
}
|
|
85
|
-
|
|
112
|
+
get element() {
|
|
86
113
|
return this.dom;
|
|
87
114
|
}
|
|
88
|
-
|
|
89
|
-
|
|
115
|
+
get disposed() {
|
|
116
|
+
return this.gone;
|
|
117
|
+
}
|
|
118
|
+
get spec() {
|
|
119
|
+
return this.current;
|
|
120
|
+
}
|
|
121
|
+
resize(size = {}) {
|
|
122
|
+
if (this.gone)
|
|
90
123
|
return;
|
|
91
|
-
this.
|
|
92
|
-
this.
|
|
93
|
-
this.renderer.setSize(this.
|
|
94
|
-
this.animateNext = !!
|
|
95
|
-
this.
|
|
96
|
-
this.emit('resize', { componentType: '
|
|
124
|
+
this.plotWidth = typeof size.width === 'number' ? size.width : this.dom.clientWidth || this.fixedWidth || this.plotWidth;
|
|
125
|
+
this.plotHeight = typeof size.height === 'number' ? size.height : this.dom.clientHeight || this.fixedHeight || this.plotHeight;
|
|
126
|
+
this.renderer.setSize(this.plotWidth, this.plotHeight);
|
|
127
|
+
this.animateNext = !!size.animate;
|
|
128
|
+
this.draw();
|
|
129
|
+
this.emit('resize', { componentType: 'chart' });
|
|
97
130
|
}
|
|
98
131
|
// ---------------------------------------------------------------- opção
|
|
99
|
-
|
|
100
|
-
if (this.
|
|
132
|
+
render(spec) {
|
|
133
|
+
if (this.gone || !spec || !Array.isArray(spec.series))
|
|
101
134
|
return;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (isPlainObject(legendSel))
|
|
112
|
-
this.legendSelected = { ...legendSel };
|
|
113
|
-
else if (!this.legendInit)
|
|
135
|
+
this.current = spec;
|
|
136
|
+
this.apply(compileSpec(spec));
|
|
137
|
+
}
|
|
138
|
+
/** Troca o plano interno inteiro (sem mesclar com o anterior). */
|
|
139
|
+
apply(plan) {
|
|
140
|
+
this.raw = plan;
|
|
141
|
+
this.highlights.clear();
|
|
142
|
+
this.pointer = null;
|
|
143
|
+
if (!this.legendInit)
|
|
114
144
|
this.legendSelected = {};
|
|
115
145
|
this.legendInit = true;
|
|
116
146
|
this.animateNext = true;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
else
|
|
120
|
-
this.render();
|
|
147
|
+
this.slidePending = true;
|
|
148
|
+
this.draw();
|
|
121
149
|
}
|
|
122
|
-
|
|
150
|
+
/** Plano interno normalizado (padrões aplicados) do quadro atual: só para os testes do motor. */
|
|
151
|
+
normalizedPlan() {
|
|
123
152
|
const frame = this.frame ?? this.build();
|
|
124
|
-
return
|
|
153
|
+
return frame.normalized.option;
|
|
125
154
|
}
|
|
126
155
|
setTheme(theme) {
|
|
127
|
-
this.theme = buildTheme(theme);
|
|
156
|
+
this.theme = buildTheme(themePlan(theme));
|
|
128
157
|
this.animateNext = false;
|
|
129
|
-
this.
|
|
158
|
+
this.draw();
|
|
130
159
|
}
|
|
131
160
|
clear() {
|
|
132
161
|
this.raw = {};
|
|
162
|
+
this.current = null;
|
|
133
163
|
this.highlights.clear();
|
|
134
164
|
this.hover = null;
|
|
135
165
|
this.pointer = null;
|
|
136
166
|
this.tooltip.hide();
|
|
137
|
-
this.
|
|
138
|
-
}
|
|
139
|
-
isDisposed() {
|
|
140
|
-
return this.disposed;
|
|
167
|
+
this.draw();
|
|
141
168
|
}
|
|
142
169
|
dispose() {
|
|
143
|
-
if (this.
|
|
170
|
+
if (this.gone)
|
|
144
171
|
return;
|
|
145
|
-
this.
|
|
172
|
+
this.gone = true;
|
|
173
|
+
for (const [type, fn, opts] of this.domListeners)
|
|
174
|
+
this.dom.removeEventListener(type, fn, opts);
|
|
175
|
+
this.domListeners.length = 0;
|
|
146
176
|
this.tooltip.dispose();
|
|
147
177
|
this.renderer.dispose();
|
|
148
178
|
this.listeners.length = 0;
|
|
@@ -152,8 +182,8 @@ export class ChartInstanceImpl {
|
|
|
152
182
|
requestRender() {
|
|
153
183
|
const ticket = ++this.renderTicket;
|
|
154
184
|
const run = () => {
|
|
155
|
-
if (ticket === this.renderTicket && !this.
|
|
156
|
-
this.
|
|
185
|
+
if (ticket === this.renderTicket && !this.gone)
|
|
186
|
+
this.draw();
|
|
157
187
|
};
|
|
158
188
|
if (typeof requestAnimationFrame === 'function')
|
|
159
189
|
requestAnimationFrame(run);
|
|
@@ -180,8 +210,8 @@ export class ChartInstanceImpl {
|
|
|
180
210
|
return type?.legendEntries ? true : legendSelected(m.name);
|
|
181
211
|
});
|
|
182
212
|
const ctx = {
|
|
183
|
-
width: this.
|
|
184
|
-
height: this.
|
|
213
|
+
width: this.plotWidth,
|
|
214
|
+
height: this.plotHeight,
|
|
185
215
|
theme: this.theme,
|
|
186
216
|
locale: this.locale,
|
|
187
217
|
option,
|
|
@@ -223,8 +253,8 @@ export class ChartInstanceImpl {
|
|
|
223
253
|
}
|
|
224
254
|
return frame;
|
|
225
255
|
}
|
|
226
|
-
|
|
227
|
-
if (this.
|
|
256
|
+
draw() {
|
|
257
|
+
if (this.gone)
|
|
228
258
|
return;
|
|
229
259
|
++this.renderTicket;
|
|
230
260
|
const frame = this.build();
|
|
@@ -232,6 +262,10 @@ export class ChartInstanceImpl {
|
|
|
232
262
|
const option = normalized.option;
|
|
233
263
|
const nodes = [];
|
|
234
264
|
const labels = [];
|
|
265
|
+
// Tempo real: as séries vão num grupo interno que desliza pelo intervalo novo (o recorte do grupo de fora fica parado).
|
|
266
|
+
const slideOption = isPlainObject(option['slide']) ? option['slide'] : null;
|
|
267
|
+
const slide = slideOption && this.slidePending ? { dx: Number(slideOption.dx) || 0, duration: Number(slideOption.duration) || 0 } : null;
|
|
268
|
+
this.slidePending = false;
|
|
235
269
|
for (const [key, coord] of coords) {
|
|
236
270
|
try {
|
|
237
271
|
nodes.push({ kind: 'group', key: `coord/${key}`, z: 0, children: coord.render(ctx) });
|
|
@@ -249,13 +283,34 @@ export class ChartInstanceImpl {
|
|
|
249
283
|
nodes.push({ kind: 'group', key: 'axis-pointer', z: kind === 'shadow' ? 1 : 5, silent: true, children: coord.renderAxisPointer(axis, this.pointer.value, kind, ctx) });
|
|
250
284
|
}
|
|
251
285
|
}
|
|
286
|
+
// Marcas de referência: faixas atrás das séries, linhas na frente delas e atrás dos rótulos.
|
|
287
|
+
if (option['referenceMarks']?.length) {
|
|
288
|
+
try {
|
|
289
|
+
const refs = referenceMarkNodes(ctx);
|
|
290
|
+
if (refs.bands.length)
|
|
291
|
+
nodes.push({ kind: 'group', key: 'reference-bands', z: 1.5, silent: true, children: refs.bands });
|
|
292
|
+
if (refs.lines.length)
|
|
293
|
+
nodes.push({ kind: 'group', key: 'reference-lines', z: 2.9, silent: true, children: refs.lines });
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
logError('marcas de referência', error);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
252
299
|
for (const model of visible) {
|
|
253
300
|
const type = SERIES_TYPES.get(model.type);
|
|
254
301
|
if (!type)
|
|
255
302
|
continue;
|
|
256
303
|
try {
|
|
257
304
|
const result = type.render(model, ctx);
|
|
258
|
-
|
|
305
|
+
// Com janela de dados no grid, a série é recortada na largura do plano (o ponto logo fora leva a linha à borda).
|
|
306
|
+
let clip;
|
|
307
|
+
if (model.coordinateSystem === 'cartesian2d' && viewWindowOf(option, model.coordinateIndex)) {
|
|
308
|
+
const rect = coords.get(coordKey('cartesian2d', model.coordinateIndex))?.rect;
|
|
309
|
+
if (rect)
|
|
310
|
+
clip = { x: rect.x, y: 0, width: rect.width, height: this.plotHeight };
|
|
311
|
+
}
|
|
312
|
+
const children = slideOption ? [{ kind: 'group', key: `series/${model.index}/slide`, children: result.nodes, ...(slide ? { slide } : {}) }] : result.nodes;
|
|
313
|
+
nodes.push({ kind: 'group', key: `series/${model.index}`, z: 2 + Number(model.option['z'] ?? 0) / 100, children, ...(clip ? { clip } : {}) });
|
|
259
314
|
if (result.labels)
|
|
260
315
|
labels.push(...result.labels);
|
|
261
316
|
}
|
|
@@ -265,6 +320,26 @@ export class ChartInstanceImpl {
|
|
|
265
320
|
}
|
|
266
321
|
if (labels.length)
|
|
267
322
|
nodes.push({ kind: 'group', key: 'labels', z: 3, children: layoutLabels(labels, measureText) });
|
|
323
|
+
// markPoint: acima das séries e dos rótulos delas, fora da disposição (o selo não some por sobreposição).
|
|
324
|
+
const marks = [];
|
|
325
|
+
for (const model of visible) {
|
|
326
|
+
if (!model.option['markPoint'] || !ctx.legendSelected(model.name))
|
|
327
|
+
continue;
|
|
328
|
+
try {
|
|
329
|
+
const children = markPointNodes(model, ctx);
|
|
330
|
+
if (children.length) {
|
|
331
|
+
const group = { kind: 'group', key: `markPoint/${model.index}`, z: 3.5, silent: true, children };
|
|
332
|
+
nodes.push(group);
|
|
333
|
+
marks.push(group);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
logError(`markPoint da série ${model.index}`, error);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
stackOverlappingBadges(marks);
|
|
341
|
+
if (this.sweep)
|
|
342
|
+
nodes.push({ kind: 'group', key: 'sweep', z: 4.5, silent: true, children: sweepNodes(this.sweep, ctx) });
|
|
268
343
|
// Componentes: a legenda recebe as entradas das séries.
|
|
269
344
|
const entries = this.legendEntries(normalized.models, ctx);
|
|
270
345
|
for (const [key, type] of COMPONENT_TYPES) {
|
|
@@ -280,9 +355,9 @@ export class ChartInstanceImpl {
|
|
|
280
355
|
}
|
|
281
356
|
});
|
|
282
357
|
}
|
|
283
|
-
this.renderer.setSize(this.
|
|
358
|
+
this.renderer.setSize(this.plotWidth, this.plotHeight);
|
|
284
359
|
this.renderer.setBackground(typeof option['backgroundColor'] === 'string' ? option['backgroundColor'] : undefined);
|
|
285
|
-
this.renderer.setLabel(
|
|
360
|
+
this.renderer.setLabel(null);
|
|
286
361
|
this.renderer.render(nodes, {
|
|
287
362
|
animate: ctx.animation.enabled && this.animateNext,
|
|
288
363
|
duration: ctx.animation.duration,
|
|
@@ -291,7 +366,7 @@ export class ChartInstanceImpl {
|
|
|
291
366
|
easingUpdate: easingOf(option['animationEasingUpdate'], 'cubicInOut'),
|
|
292
367
|
});
|
|
293
368
|
this.animateNext = true;
|
|
294
|
-
this.emit('rendered', { componentType: '
|
|
369
|
+
this.emit('rendered', { componentType: 'chart' });
|
|
295
370
|
}
|
|
296
371
|
/** Entradas da legenda: as que cada série dá (pizza por item) ou uma por série com nome. */
|
|
297
372
|
legendEntries(models, ctx) {
|
|
@@ -301,9 +376,9 @@ export class ChartInstanceImpl {
|
|
|
301
376
|
const type = SERIES_TYPES.get(model.type);
|
|
302
377
|
const list = type?.legendEntries
|
|
303
378
|
? type.legendEntries(model, ctx)
|
|
304
|
-
: model.name
|
|
379
|
+
: isUnnamed(model.name)
|
|
305
380
|
? []
|
|
306
|
-
: [{ name: model.name, color: model.color, icon: model.type === 'line' ? 'line' : '
|
|
381
|
+
: [{ name: model.name, color: model.color, icon: model.type === 'line' ? 'line' : 'rounded-square', seriesIndex: model.index, decal: model.decal, lineStyle: undefined }];
|
|
307
382
|
for (const entry of list) {
|
|
308
383
|
if (seen.has(entry.name))
|
|
309
384
|
continue;
|
|
@@ -351,6 +426,9 @@ export class ChartInstanceImpl {
|
|
|
351
426
|
return frame.normalized.option['tooltip'][0] ?? { show: false };
|
|
352
427
|
}
|
|
353
428
|
onPointer(item, x, y, event) {
|
|
429
|
+
// Arrastando a seleção: sem tooltip nem destaque.
|
|
430
|
+
if (this.sweep)
|
|
431
|
+
return;
|
|
354
432
|
const frame = this.frame ?? this.build();
|
|
355
433
|
const tip = this.tooltipOption();
|
|
356
434
|
const tipOn = !!frame.normalized.option['tooltip'].length && tip['show'] !== false && tip['showContent'] !== false && String(tip['triggerOn'] ?? 'mousemove').includes('mousemove');
|
|
@@ -358,10 +436,10 @@ export class ChartInstanceImpl {
|
|
|
358
436
|
const seriesItem = item?.componentType === 'series' ? item : null;
|
|
359
437
|
if (!this.sameItem(this.hover, seriesItem)) {
|
|
360
438
|
if (this.hover)
|
|
361
|
-
this.emit('
|
|
439
|
+
this.emit('pointerleave', { ...this.hover, event });
|
|
362
440
|
this.hover = seriesItem;
|
|
363
441
|
if (seriesItem)
|
|
364
|
-
this.emit('
|
|
442
|
+
this.emit('pointerenter', { ...this.fillItem(seriesItem, frame), event });
|
|
365
443
|
needsRender = true;
|
|
366
444
|
}
|
|
367
445
|
if (tipOn && tip['trigger'] === 'axis') {
|
|
@@ -385,7 +463,7 @@ export class ChartInstanceImpl {
|
|
|
385
463
|
}
|
|
386
464
|
if (needsRender) {
|
|
387
465
|
this.animateNext = true;
|
|
388
|
-
this.
|
|
466
|
+
this.draw();
|
|
389
467
|
}
|
|
390
468
|
}
|
|
391
469
|
axisAt(x, y, frame) {
|
|
@@ -404,16 +482,16 @@ export class ChartInstanceImpl {
|
|
|
404
482
|
this.tooltip.hide();
|
|
405
483
|
const changed = !!this.hover || !!this.pointer;
|
|
406
484
|
if (this.hover)
|
|
407
|
-
this.emit('
|
|
485
|
+
this.emit('pointerleave', { ...this.hover, event });
|
|
408
486
|
this.hover = null;
|
|
409
487
|
this.pointer = null;
|
|
410
488
|
if (changed)
|
|
411
|
-
this.
|
|
489
|
+
this.draw();
|
|
412
490
|
}
|
|
413
491
|
onClick(item, x, y, event) {
|
|
414
492
|
const frame = this.frame ?? this.build();
|
|
415
493
|
if (!item) {
|
|
416
|
-
this.emit('click', { componentType: 'blank',
|
|
494
|
+
this.emit('click', { componentType: 'blank', event });
|
|
417
495
|
return;
|
|
418
496
|
}
|
|
419
497
|
if (item.componentType === 'legend' && item.name !== undefined) {
|
|
@@ -432,12 +510,12 @@ export class ChartInstanceImpl {
|
|
|
432
510
|
return;
|
|
433
511
|
}
|
|
434
512
|
const full = this.fillItem(item, frame);
|
|
435
|
-
this.emit('click', { ...full,
|
|
513
|
+
this.emit('click', { ...full, event });
|
|
436
514
|
if (item.componentType === 'series' && item.seriesIndex !== undefined) {
|
|
437
515
|
const model = frame.normalized.models[item.seriesIndex];
|
|
438
516
|
const type = model ? SERIES_TYPES.get(model.type) : undefined;
|
|
439
517
|
if (model && type?.onClick?.(model, item, frame.ctx))
|
|
440
|
-
this.
|
|
518
|
+
this.draw();
|
|
441
519
|
const tip = this.tooltipOption();
|
|
442
520
|
if (String(tip['triggerOn'] ?? '').includes('click') && tip['trigger'] !== 'axis' && model && item.dataIndex !== undefined)
|
|
443
521
|
this.tooltip.showItem(model, item.dataIndex, x, y);
|
|
@@ -452,7 +530,7 @@ export class ChartInstanceImpl {
|
|
|
452
530
|
return item;
|
|
453
531
|
const data = item.dataIndex !== undefined ? model.data[item.dataIndex] : undefined;
|
|
454
532
|
let name = item.name || data?.name || '';
|
|
455
|
-
// Sem nome no item: a categoria do eixo
|
|
533
|
+
// Sem nome no item: a categoria do eixo.
|
|
456
534
|
if (!name && item.dataIndex !== undefined && model.coordinateSystem !== 'none') {
|
|
457
535
|
const coord = frame.coords.get(coordKey(model.coordinateSystem, model.coordinateIndex));
|
|
458
536
|
const base = coord && Object.values(coord.axes).find((a) => a.type === 'category');
|
|
@@ -475,7 +553,7 @@ export class ChartInstanceImpl {
|
|
|
475
553
|
const frame = this.frame ?? this.build();
|
|
476
554
|
const legendOpt = (frame.normalized.option['legend'] ?? [])[index] ?? {};
|
|
477
555
|
this.legendSelected = nextLegendSelection(legendOpt, this.legendSelected, name, this.legendNames(frame));
|
|
478
|
-
this.afterLegendChange(name, '
|
|
556
|
+
this.afterLegendChange(name, 'legendtoggle');
|
|
479
557
|
}
|
|
480
558
|
afterLegendChange(name, type) {
|
|
481
559
|
const frame = this.frame ?? this.build();
|
|
@@ -483,12 +561,25 @@ export class ChartInstanceImpl {
|
|
|
483
561
|
for (const n of this.legendNames(frame))
|
|
484
562
|
selected[n] = this.legendSelected[n] !== false;
|
|
485
563
|
this.animateNext = true;
|
|
486
|
-
this.
|
|
487
|
-
this.emit(type, { componentType: 'legend',
|
|
564
|
+
this.draw();
|
|
565
|
+
this.emit(type, { componentType: 'legend', name, selected });
|
|
566
|
+
}
|
|
567
|
+
// ---------------------------------------------------------------- destaque e tooltip (contrato)
|
|
568
|
+
highlight(target) {
|
|
569
|
+
this.act({ type: 'highlight', seriesIndex: target.series, dataIndex: target.point });
|
|
488
570
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
571
|
+
clearHighlight(target) {
|
|
572
|
+
this.act(target ? { type: 'downplay', seriesIndex: target.series, dataIndex: target.point } : { type: 'downplay' });
|
|
573
|
+
}
|
|
574
|
+
showTooltip(target) {
|
|
575
|
+
this.act({ type: 'showTip', seriesIndex: target.series, dataIndex: target.point, axisValue: target.axisValue });
|
|
576
|
+
}
|
|
577
|
+
hideTooltip() {
|
|
578
|
+
this.act({ type: 'hideTip' });
|
|
579
|
+
}
|
|
580
|
+
// ---------------------------------------------------------------- ações internas
|
|
581
|
+
act(action) {
|
|
582
|
+
if (this.gone || !isPlainObject(action))
|
|
492
583
|
return;
|
|
493
584
|
const frame = this.frame ?? this.build();
|
|
494
585
|
const models = frame.normalized.models;
|
|
@@ -547,15 +638,30 @@ export class ChartInstanceImpl {
|
|
|
547
638
|
}
|
|
548
639
|
}
|
|
549
640
|
this.animateNext = true;
|
|
550
|
-
this.
|
|
551
|
-
this.emit(type, { componentType: 'series',
|
|
641
|
+
this.draw();
|
|
642
|
+
this.emit(type === 'highlight' ? 'highlight' : 'clearhighlight', { componentType: 'series', seriesIndex: action['seriesIndex'], dataIndex: action['dataIndex'], name: action['name'] });
|
|
552
643
|
return;
|
|
553
644
|
}
|
|
554
645
|
case 'showTip': {
|
|
555
646
|
const pos = Array.isArray(action['position']) ? action['position'] : undefined;
|
|
556
|
-
const x = pos?.[0] ?? (typeof action['x'] === 'number' ? action['x'] : this.
|
|
557
|
-
const y = pos?.[1] ?? (typeof action['y'] === 'number' ? action['y'] : this.
|
|
647
|
+
const x = pos?.[0] ?? (typeof action['x'] === 'number' ? action['x'] : this.plotWidth / 2);
|
|
648
|
+
const y = pos?.[1] ?? (typeof action['y'] === 'number' ? action['y'] : this.plotHeight / 2);
|
|
558
649
|
const model = seriesOf()[0];
|
|
650
|
+
// Valor no eixo-base (instante): o tooltip de eixo nesse valor, com o ponteiro de eixo.
|
|
651
|
+
if (action['axisValue'] !== undefined) {
|
|
652
|
+
const target = model ?? models.find((m) => m.coordinateSystem === 'cartesian2d');
|
|
653
|
+
const coord = target ? frame.coords.get(coordKey(target.coordinateSystem, target.coordinateIndex)) : undefined;
|
|
654
|
+
const base = coord && (Object.values(coord.axes).find((a) => a.type === 'category') ?? coord.axes['x']);
|
|
655
|
+
if (coord && base) {
|
|
656
|
+
const value = Number(action['axisValue']);
|
|
657
|
+
this.pointer = { coordKey: coordKey(target.coordinateSystem, target.coordinateIndex), axisDim: base.dim, value };
|
|
658
|
+
const px = base.toPixel(value);
|
|
659
|
+
const pos = base.dim === 'x' ? [px, coord.rect.y + coord.rect.height / 2] : [coord.rect.x + coord.rect.width / 2, px];
|
|
660
|
+
this.tooltip.showAxis(coord, base, value, pos[0], pos[1]);
|
|
661
|
+
this.draw();
|
|
662
|
+
}
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
559
665
|
if (model) {
|
|
560
666
|
const idx = indicesOf(model);
|
|
561
667
|
const dataIndex = idx === 'all' ? 0 : idx[0];
|
|
@@ -570,7 +676,7 @@ export class ChartInstanceImpl {
|
|
|
570
676
|
this.pointer = { coordKey: coordKey(model.coordinateSystem, model.coordinateIndex), axisDim: base.dim, value: dataIndex };
|
|
571
677
|
this.tooltip.showAxis(coord, base, dataIndex, x, y);
|
|
572
678
|
void value;
|
|
573
|
-
this.
|
|
679
|
+
this.draw();
|
|
574
680
|
return;
|
|
575
681
|
}
|
|
576
682
|
}
|
|
@@ -582,7 +688,7 @@ export class ChartInstanceImpl {
|
|
|
582
688
|
if (found) {
|
|
583
689
|
this.pointer = { coordKey: found.key, axisDim: found.axis.dim, value: found.value };
|
|
584
690
|
this.tooltip.showAxis(found.coord, found.axis, found.value, action['x'], action['y']);
|
|
585
|
-
this.
|
|
691
|
+
this.draw();
|
|
586
692
|
}
|
|
587
693
|
}
|
|
588
694
|
return;
|
|
@@ -591,56 +697,150 @@ export class ChartInstanceImpl {
|
|
|
591
697
|
this.tooltip.hide();
|
|
592
698
|
if (this.pointer) {
|
|
593
699
|
this.pointer = null;
|
|
594
|
-
this.
|
|
700
|
+
this.draw();
|
|
595
701
|
}
|
|
596
702
|
return;
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
// ---------------------------------------------------------------- seleção por arrasto, Ctrl + roda, duplo clique
|
|
706
|
+
sweepOption() {
|
|
707
|
+
const frame = this.frame ?? this.build();
|
|
708
|
+
return toArray(frame.normalized.option['sweepSelect'])[0] ?? null;
|
|
709
|
+
}
|
|
710
|
+
/** Grid, eixo X e posição local do ponteiro, quando ele está dentro do plano do grid do componente. */
|
|
711
|
+
sweepTarget(e) {
|
|
712
|
+
const option = this.sweepOption();
|
|
713
|
+
if (!option)
|
|
714
|
+
return null;
|
|
715
|
+
const grid = option.gridIndex ?? 0;
|
|
716
|
+
const coord = (this.frame ?? this.build()).coords.get(coordKey('cartesian2d', grid));
|
|
717
|
+
const axis = coord?.xAxes[0];
|
|
718
|
+
if (!coord || !axis)
|
|
719
|
+
return null;
|
|
720
|
+
const box = this.renderer.svg.getBoundingClientRect();
|
|
721
|
+
const x = e.clientX - box.left;
|
|
722
|
+
const y = e.clientY - box.top;
|
|
723
|
+
const r = coord.rect;
|
|
724
|
+
if (x < r.x || x > r.x + r.width || y < r.y || y > r.y + r.height)
|
|
725
|
+
return null;
|
|
726
|
+
return { grid, axis, x };
|
|
727
|
+
}
|
|
728
|
+
listenSweep() {
|
|
729
|
+
const on = (type, fn, opts) => {
|
|
730
|
+
this.dom.addEventListener(type, fn, opts);
|
|
731
|
+
this.domListeners.push([type, fn, opts]);
|
|
732
|
+
};
|
|
733
|
+
const valueAt = (axis, px) => (axis.type === 'category' ? Math.round(axis.fromPixel(px)) : axis.fromPixel(px));
|
|
734
|
+
on('pointerdown', (e) => {
|
|
735
|
+
// Um dedo continua rolando a página: arrasto de seleção só com mouse ou caneta.
|
|
736
|
+
if (e.button !== 0 || e.pointerType === 'touch' || !this.sweepOption() || this.sweepOption()?.drag === false)
|
|
737
|
+
return;
|
|
738
|
+
const target = this.sweepTarget(e);
|
|
739
|
+
if (!target)
|
|
606
740
|
return;
|
|
741
|
+
this.sweep = { gridIndex: target.grid, from: target.x, to: target.x };
|
|
742
|
+
try {
|
|
743
|
+
this.dom.setPointerCapture?.(e.pointerId);
|
|
744
|
+
}
|
|
745
|
+
catch {
|
|
746
|
+
// ponteiro sintético (testes): sem captura
|
|
607
747
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
748
|
+
});
|
|
749
|
+
on('pointermove', (e) => {
|
|
750
|
+
if (!this.sweep)
|
|
751
|
+
return;
|
|
752
|
+
const coord = (this.frame ?? this.build()).coords.get(coordKey('cartesian2d', this.sweep.gridIndex));
|
|
753
|
+
if (!coord)
|
|
754
|
+
return;
|
|
755
|
+
const box = this.renderer.svg.getBoundingClientRect();
|
|
756
|
+
const x = Math.max(coord.rect.x, Math.min(coord.rect.x + coord.rect.width, e.clientX - box.left));
|
|
757
|
+
if (x === this.sweep.to)
|
|
758
|
+
return;
|
|
759
|
+
this.sweep = { ...this.sweep, to: x };
|
|
760
|
+
this.tooltip.hide();
|
|
761
|
+
this.pointer = null;
|
|
762
|
+
this.animateNext = false;
|
|
763
|
+
this.draw();
|
|
764
|
+
this.emit('sweepmove', { componentType: 'sweepSelect' });
|
|
765
|
+
});
|
|
766
|
+
const finish = (e, cancel) => {
|
|
767
|
+
const sweep = this.sweep;
|
|
768
|
+
if (!sweep)
|
|
615
769
|
return;
|
|
770
|
+
this.sweep = null;
|
|
771
|
+
try {
|
|
772
|
+
this.dom.releasePointerCapture?.(e.pointerId);
|
|
773
|
+
}
|
|
774
|
+
catch {
|
|
775
|
+
// idem
|
|
616
776
|
}
|
|
617
|
-
|
|
618
|
-
|
|
777
|
+
this.animateNext = false;
|
|
778
|
+
this.draw();
|
|
779
|
+
const coord = (this.frame ?? this.build()).coords.get(coordKey('cartesian2d', sweep.gridIndex));
|
|
780
|
+
const axis = coord?.xAxes[0];
|
|
781
|
+
if (cancel || !axis || Math.abs(sweep.to - sweep.from) < 4)
|
|
619
782
|
return;
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
783
|
+
const a = valueAt(axis, Math.min(sweep.from, sweep.to));
|
|
784
|
+
const b = valueAt(axis, Math.max(sweep.from, sweep.to));
|
|
785
|
+
this.emit('sweepselect', { componentType: 'sweepSelect', data: { start: Math.min(a, b), end: Math.max(a, b) } });
|
|
786
|
+
};
|
|
787
|
+
on('pointerup', (e) => finish(e, false));
|
|
788
|
+
on('pointercancel', (e) => finish(e, true));
|
|
789
|
+
on('keydown', (e) => {
|
|
790
|
+
if (e.key !== 'Escape' || !this.sweep)
|
|
791
|
+
return;
|
|
792
|
+
this.sweep = null;
|
|
793
|
+
this.animateNext = false;
|
|
794
|
+
this.draw();
|
|
795
|
+
this.emit('sweepcancel', { componentType: 'sweepSelect' });
|
|
796
|
+
});
|
|
797
|
+
// Roda só com Ctrl (ou a pinça do touchpad): a roda sozinha rola a página, nunca é presa.
|
|
798
|
+
on('wheel', (e) => {
|
|
799
|
+
if (!e.ctrlKey)
|
|
800
|
+
return;
|
|
801
|
+
const target = this.sweepTarget(e);
|
|
802
|
+
if (!target)
|
|
803
|
+
return;
|
|
804
|
+
e.preventDefault();
|
|
805
|
+
this.emit('sweepzoom', { componentType: 'sweepSelect', data: { center: target.axis.fromPixel(target.x), factor: e.deltaY < 0 ? 0.8 : 1.25 } });
|
|
806
|
+
}, { passive: false });
|
|
807
|
+
on('dblclick', (e) => {
|
|
808
|
+
if (this.sweepTarget(e))
|
|
809
|
+
this.emit('sweepreset', { componentType: 'sweepSelect' });
|
|
810
|
+
});
|
|
623
811
|
}
|
|
624
812
|
// ---------------------------------------------------------------- eventos
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
this.listeners.
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
const l = this.listeners[i];
|
|
634
|
-
if (l.event === event && (!handler || l.handler === handler))
|
|
635
|
-
this.listeners.splice(i, 1);
|
|
636
|
-
}
|
|
813
|
+
listen(type, handler) {
|
|
814
|
+
const entry = { event: type.toLowerCase(), handler };
|
|
815
|
+
this.listeners.push(entry);
|
|
816
|
+
return () => {
|
|
817
|
+
const at = this.listeners.indexOf(entry);
|
|
818
|
+
if (at >= 0)
|
|
819
|
+
this.listeners.splice(at, 1);
|
|
820
|
+
};
|
|
637
821
|
}
|
|
638
822
|
emit(type, params) {
|
|
639
|
-
|
|
823
|
+
if (!this.listeners.length)
|
|
824
|
+
return;
|
|
825
|
+
const model = params.seriesIndex !== undefined ? this.frame?.normalized.models[params.seriesIndex] : undefined;
|
|
826
|
+
const event = {
|
|
827
|
+
type,
|
|
828
|
+
part: partOf(params.componentType),
|
|
829
|
+
seriesIndex: params.seriesIndex,
|
|
830
|
+
seriesId: model?.option['id'],
|
|
831
|
+
seriesName: params.seriesName ?? (model && !isUnnamed(model.name) ? model.name : undefined),
|
|
832
|
+
pointIndex: params.dataIndex,
|
|
833
|
+
name: params.name,
|
|
834
|
+
value: params.value,
|
|
835
|
+
detail: params.data,
|
|
836
|
+
selected: params.selected,
|
|
837
|
+
native: params.event,
|
|
838
|
+
};
|
|
839
|
+
for (const key of Object.keys(event))
|
|
840
|
+
if (event[key] === undefined)
|
|
841
|
+
delete event[key];
|
|
640
842
|
for (const l of [...this.listeners]) {
|
|
641
|
-
if (l.event
|
|
642
|
-
continue;
|
|
643
|
-
if (l.query && !matchesQuery(l.query, event))
|
|
843
|
+
if (l.event !== type)
|
|
644
844
|
continue;
|
|
645
845
|
try {
|
|
646
846
|
l.handler(event);
|
|
@@ -651,9 +851,9 @@ export class ChartInstanceImpl {
|
|
|
651
851
|
}
|
|
652
852
|
}
|
|
653
853
|
// ---------------------------------------------------------------- conversão de coordenadas
|
|
654
|
-
coordFor(
|
|
854
|
+
coordFor(target) {
|
|
655
855
|
const frame = this.frame ?? this.build();
|
|
656
|
-
const f =
|
|
856
|
+
const f = 'series' in target ? { seriesIndex: target.series } : { gridIndex: target.plane };
|
|
657
857
|
const get = (type, index) => frame.coords.get(coordKey(type, index));
|
|
658
858
|
if (f['seriesIndex'] !== undefined) {
|
|
659
859
|
const model = frame.normalized.models[f['seriesIndex']];
|
|
@@ -666,33 +866,20 @@ export class ChartInstanceImpl {
|
|
|
666
866
|
const coord = get('cartesian2d', f['gridIndex']);
|
|
667
867
|
return coord ? { coord } : undefined;
|
|
668
868
|
}
|
|
669
|
-
for (const [key, dim] of [['xAxisIndex', 'x'], ['yAxisIndex', 'y']]) {
|
|
670
|
-
if (f[key] === undefined)
|
|
671
|
-
continue;
|
|
672
|
-
const axis = (frame.normalized.option[key === 'xAxisIndex' ? 'xAxis' : 'yAxis'] ?? [])[f[key]];
|
|
673
|
-
const coord = get('cartesian2d', Number(axis?.['gridIndex'] ?? 0));
|
|
674
|
-
return coord ? { coord, axisDim: dim } : undefined;
|
|
675
|
-
}
|
|
676
|
-
for (const [key, type] of [['polarIndex', 'polar'], ['radarIndex', 'radar'], ['calendarIndex', 'calendar']]) {
|
|
677
|
-
if (f[key] === undefined)
|
|
678
|
-
continue;
|
|
679
|
-
const coord = get(type, f[key]);
|
|
680
|
-
return coord ? { coord } : undefined;
|
|
681
|
-
}
|
|
682
869
|
return undefined;
|
|
683
870
|
}
|
|
684
|
-
|
|
685
|
-
const found = this.coordFor(
|
|
871
|
+
toPixel(target, value) {
|
|
872
|
+
const found = this.coordFor(target);
|
|
686
873
|
if (!found)
|
|
687
874
|
return undefined;
|
|
688
875
|
if (found.axisDim) {
|
|
689
876
|
const axis = found.coord.axes[found.axisDim];
|
|
690
877
|
return axis ? axis.toPixel(Array.isArray(value) ? value[0] : value) : undefined;
|
|
691
878
|
}
|
|
692
|
-
return found.coord.dataToPoint(Array.isArray(value) ? value : [value]);
|
|
879
|
+
return found.coord.dataToPoint(Array.isArray(value) ? [...value] : [value]);
|
|
693
880
|
}
|
|
694
|
-
|
|
695
|
-
const found = this.coordFor(
|
|
881
|
+
fromPixel(target, value) {
|
|
882
|
+
const found = this.coordFor(target);
|
|
696
883
|
if (!found)
|
|
697
884
|
return undefined;
|
|
698
885
|
if (found.axisDim) {
|
|
@@ -706,8 +893,8 @@ export class ChartInstanceImpl {
|
|
|
706
893
|
return [x.fromPixel(value[0]), y.fromPixel(value[1])];
|
|
707
894
|
return undefined;
|
|
708
895
|
}
|
|
709
|
-
|
|
710
|
-
const found = this.coordFor(
|
|
896
|
+
containsPixel(target, value) {
|
|
897
|
+
const found = this.coordFor(target);
|
|
711
898
|
if (!found)
|
|
712
899
|
return false;
|
|
713
900
|
if (found.coord.contains)
|
|
@@ -716,33 +903,64 @@ export class ChartInstanceImpl {
|
|
|
716
903
|
return value[0] >= r.x && value[0] <= r.x + r.width && value[1] >= r.y && value[1] <= r.y + r.height;
|
|
717
904
|
}
|
|
718
905
|
// ---------------------------------------------------------------- exportar
|
|
719
|
-
|
|
906
|
+
toSVG() {
|
|
720
907
|
return this.renderer.toString();
|
|
721
908
|
}
|
|
722
|
-
|
|
723
|
-
let svg = this.
|
|
724
|
-
if (
|
|
725
|
-
svg = svg.replace(/<svg([^>]*?)style="/, `<svg$1style="background-color:${
|
|
909
|
+
toDataURL(options = {}) {
|
|
910
|
+
let svg = this.toSVG();
|
|
911
|
+
if (options.background)
|
|
912
|
+
svg = svg.replace(/<svg([^>]*?)style="/, `<svg$1style="background-color:${options.background};`);
|
|
726
913
|
return `data:image/svg+xml;charset=UTF-8,${encodeURIComponent(svg)}`;
|
|
727
914
|
}
|
|
728
915
|
}
|
|
729
916
|
// ---------------------------------------------------------------- auxiliares
|
|
730
|
-
/**
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
return
|
|
745
|
-
|
|
917
|
+
/**
|
|
918
|
+
* Selos com `stackOverlap` (último valor de cada série) que colidem sobem acima do anterior, na ordem em que vieram:
|
|
919
|
+
* nenhum some e nenhum esconde o outro.
|
|
920
|
+
*/
|
|
921
|
+
export function stackOverlappingBadges(groups) {
|
|
922
|
+
const badges = [];
|
|
923
|
+
const collect = (node) => {
|
|
924
|
+
if (node.kind === 'group')
|
|
925
|
+
node.children.forEach(collect);
|
|
926
|
+
else if (node.kind === 'text' && node.stackOverlap)
|
|
927
|
+
badges.push(node);
|
|
928
|
+
};
|
|
929
|
+
groups.forEach(collect);
|
|
930
|
+
if (badges.length < 2)
|
|
931
|
+
return;
|
|
932
|
+
const placed = [];
|
|
933
|
+
const boxOf = (n) => {
|
|
934
|
+
const m = measureText(n.text, n.style);
|
|
935
|
+
const [pt, pr, pb, pl] = paddingOf(n.style.padding);
|
|
936
|
+
const w = m.width + pl + pr;
|
|
937
|
+
const h = m.height + pt + pb;
|
|
938
|
+
const align = n.style.align ?? 'left';
|
|
939
|
+
const valign = n.style.verticalAlign ?? 'top';
|
|
940
|
+
const x = align === 'center' ? n.x - w / 2 : align === 'right' ? n.x - w : n.x;
|
|
941
|
+
const y = valign === 'middle' ? n.y - h / 2 : valign === 'bottom' ? n.y - h : n.y;
|
|
942
|
+
return { x, y, w, h };
|
|
943
|
+
};
|
|
944
|
+
for (const badge of badges) {
|
|
945
|
+
let box = boxOf(badge);
|
|
946
|
+
for (let guard = 0; guard < badges.length; guard++) {
|
|
947
|
+
const hit = placed.find((p) => box.x < p.x + p.w && p.x < box.x + box.w && box.y < p.y + p.h && p.y < box.y + box.h);
|
|
948
|
+
if (!hit)
|
|
949
|
+
break;
|
|
950
|
+
const shift = box.y + box.h - hit.y + 2;
|
|
951
|
+
badge.y -= shift;
|
|
952
|
+
box = { ...box, y: box.y - shift };
|
|
953
|
+
}
|
|
954
|
+
placed.push(box);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
function paddingOf(padding) {
|
|
958
|
+
if (padding === undefined)
|
|
959
|
+
return [0, 0, 0, 0];
|
|
960
|
+
if (typeof padding === 'number')
|
|
961
|
+
return [padding, padding, padding, padding];
|
|
962
|
+
const [a = 0, b = a, c = a, d = b] = padding;
|
|
963
|
+
return [a, b, c, d];
|
|
746
964
|
}
|
|
747
965
|
function getComputedStyleSafe(el, prop) {
|
|
748
966
|
try {
|
|
@@ -753,21 +971,23 @@ function getComputedStyleSafe(el, prop) {
|
|
|
753
971
|
}
|
|
754
972
|
}
|
|
755
973
|
function logError(where, error) {
|
|
756
|
-
// Um pedaço que falha não derruba o gráfico inteiro; o erro vai para o console
|
|
974
|
+
// Um pedaço que falha não derruba o gráfico inteiro; o erro vai para o console.
|
|
757
975
|
console.error(`[hermes-charts] ${where}:`, error);
|
|
758
976
|
}
|
|
759
977
|
// ---------------------------------------------------------------- registro por elemento
|
|
760
978
|
const instances = new WeakMap();
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
979
|
+
/** Cria o gráfico no elemento (um por elemento: criar de novo descarta o anterior). Desenho sempre em SVG. */
|
|
980
|
+
export function createChart(element, options) {
|
|
981
|
+
const existing = instances.get(element);
|
|
982
|
+
if (existing && !existing.disposed)
|
|
764
983
|
existing.dispose();
|
|
765
|
-
const
|
|
766
|
-
instances.set(
|
|
767
|
-
return
|
|
984
|
+
const chart = new Chart(element, options);
|
|
985
|
+
instances.set(element, chart);
|
|
986
|
+
return chart;
|
|
768
987
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
988
|
+
/** O gráfico vivo no elemento, se houver. */
|
|
989
|
+
export function chartOf(element) {
|
|
990
|
+
const chart = instances.get(element);
|
|
991
|
+
return chart && !chart.disposed ? chart : undefined;
|
|
772
992
|
}
|
|
773
993
|
//# sourceMappingURL=instance.js.map
|