@limetech/lime-elements 40.19.0 → 40.20.0
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/CHANGELOG.md +16 -0
- package/dist/cjs/keyboard-navigation-VyqkMDKy.js +152 -0
- package/dist/cjs/lime-elements.cjs.js +1 -1
- package/dist/cjs/{limel-breadcrumbs_6.cjs.entry.js → limel-badge_7.cjs.entry.js} +33 -0
- package/dist/cjs/limel-chart.cjs.entry.js +51361 -269
- package/dist/cjs/limel-tab-bar.cjs.entry.js +6 -149
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/components/chart/chart.css +63 -927
- package/dist/collection/components/chart/chart.js +330 -288
- package/dist/collection/components/chart/options.js +572 -0
- package/dist/collection/components/chart/scale.js +193 -0
- package/dist/collection/components/chart/theme.js +133 -0
- package/dist/collection/components/scroller/scroller.js +1 -1
- package/dist/esm/keyboard-navigation-BF7IKmnG.js +147 -0
- package/dist/esm/{keycodes-Bu6-QXrA.js → keycodes-DQ5DmW_Y.js} +1 -1
- package/dist/esm/lime-elements.js +1 -1
- package/dist/esm/{limel-breadcrumbs_6.entry.js → limel-badge_7.entry.js} +36 -4
- package/dist/esm/limel-chart.entry.js +51362 -270
- package/dist/esm/limel-chip-set.entry.js +1 -1
- package/dist/esm/limel-chip_2.entry.js +1 -1
- package/dist/esm/limel-pagination-jump.entry.js +1 -1
- package/dist/esm/limel-picker.entry.js +2 -2
- package/dist/esm/limel-popover_2.entry.js +1 -1
- package/dist/esm/limel-resize-handle.entry.js +1 -1
- package/dist/esm/limel-select.entry.js +2 -2
- package/dist/esm/limel-side-panel.entry.js +1 -1
- package/dist/esm/limel-tab-bar.entry.js +2 -145
- package/dist/esm/limel-text-editor-link-menu.entry.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{typeahead-DOlnT3wh.js → typeahead-B4PwrlM3.js} +1 -1
- package/dist/lime-elements/lime-elements.esm.js +1 -1
- package/dist/lime-elements/{p-d4702653.entry.js → p-07f3565b.entry.js} +1 -1
- package/dist/lime-elements/{p-0910aefc.entry.js → p-22e9e327.entry.js} +1 -1
- package/dist/lime-elements/{p-7bf3bf8a.entry.js → p-23067836.entry.js} +1 -1
- package/dist/lime-elements/{p-7f0743d6.entry.js → p-56e2fa48.entry.js} +1 -1
- package/dist/lime-elements/{p-af7d07fd.entry.js → p-5e408c27.entry.js} +1 -1
- package/dist/lime-elements/{p-843886fe.entry.js → p-7fcd48c6.entry.js} +1 -1
- package/dist/lime-elements/p-8514480b.entry.js +56 -0
- package/dist/lime-elements/{p-fYs7n6yY.js → p-DNYOwOWu.js} +1 -1
- package/dist/lime-elements/{p-Bu6-QXrA.js → p-DQ5DmW_Y.js} +1 -1
- package/dist/lime-elements/p-_1yBt1pG.js +1 -0
- package/dist/lime-elements/p-a807a45f.entry.js +159 -0
- package/dist/lime-elements/{p-45572e9d.entry.js → p-c8a34cef.entry.js} +1 -1
- package/dist/lime-elements/{p-4834e7c1.entry.js → p-cd479c23.entry.js} +1 -1
- package/dist/lime-elements/p-cf2d43c7.entry.js +1 -0
- package/dist/lime-elements/{p-94ae27e2.entry.js → p-f3b93ce8.entry.js} +2 -2
- package/dist/types/components/chart/chart.d.ts +51 -52
- package/dist/types/components/chart/chart.types.d.ts +5 -0
- package/dist/types/components/chart/options.d.ts +88 -0
- package/dist/types/components/chart/scale.d.ts +101 -0
- package/dist/types/components/chart/theme.d.ts +52 -0
- package/dist/types/components.d.ts +7 -38
- package/package.json +2 -1
- package/dist/cjs/limel-badge.cjs.entry.js +0 -37
- package/dist/esm/limel-badge.entry.js +0 -35
- package/dist/lime-elements/p-02aac2c0.entry.js +0 -1
- package/dist/lime-elements/p-38ab193f.entry.js +0 -1
- package/dist/lime-elements/p-3ca188f6.entry.js +0 -159
- package/dist/lime-elements/p-f7a90228.entry.js +0 -1
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
import { h } from "@stencil/core";
|
|
1
|
+
import { h, Host, } from "@stencil/core";
|
|
2
|
+
import { BarChart, GaugeChart, LineChart, PieChart, ScatterChart, } from "echarts/charts";
|
|
3
|
+
import { GridComponent, PolarComponent, TooltipComponent, } from "echarts/components";
|
|
4
|
+
import { init, use } from "echarts/core";
|
|
5
|
+
import { SVGRenderer } from "echarts/renderers";
|
|
2
6
|
import translate from "../../global/translations";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
import { findNavigationTarget, findTabStop, isNavigationKey, NO_NAVIGATION_TARGET, } from "../../util/keyboard-navigation";
|
|
8
|
+
import { drawChart, fitItemTexts, getItemIndex, getItemLabel, locateItem, } from "./options";
|
|
9
|
+
import { formatValue, getAxisRange, MAX_AXIS_STEPS, usesAxisIncrement, } from "./scale";
|
|
10
|
+
import { createThemeReader, watchTheme, } from "./theme";
|
|
11
|
+
const orientations = ['horizontal', 'vertical'];
|
|
12
|
+
const extensions = [
|
|
13
|
+
BarChart,
|
|
14
|
+
GaugeChart,
|
|
15
|
+
LineChart,
|
|
16
|
+
PieChart,
|
|
17
|
+
ScatterChart,
|
|
18
|
+
GridComponent,
|
|
19
|
+
PolarComponent,
|
|
20
|
+
TooltipComponent,
|
|
21
|
+
SVGRenderer,
|
|
22
|
+
];
|
|
16
23
|
/**
|
|
17
24
|
* A chart is a graphical representation of data, in which
|
|
18
25
|
* visual symbols such as such bars, dots, lines, or slices, represent
|
|
@@ -41,7 +48,6 @@ const WHOLE_TYPES = new Set([
|
|
|
41
48
|
* @exampleComponent limel-example-chart-accessibility
|
|
42
49
|
* @exampleComponent limel-example-chart-axis-labels
|
|
43
50
|
* @exampleComponent limel-example-chart-styling
|
|
44
|
-
* @exampleComponent limel-example-chart-creative-styling
|
|
45
51
|
* @beta
|
|
46
52
|
*/
|
|
47
53
|
export class Chart {
|
|
@@ -90,8 +96,42 @@ export class Chart {
|
|
|
90
96
|
* Indicates whether the chart is in a loading state.
|
|
91
97
|
*/
|
|
92
98
|
this.loading = false;
|
|
99
|
+
/**
|
|
100
|
+
* The item that last had focus, which is the one that Tab returns to.
|
|
101
|
+
*/
|
|
102
|
+
this.focusedIndex = 0;
|
|
103
|
+
this.themeMayHaveChanged = false;
|
|
104
|
+
this.invalidColors = new Set();
|
|
105
|
+
this.setPlot = (element) => {
|
|
106
|
+
this.plot = element;
|
|
107
|
+
};
|
|
108
|
+
this.handleResize = () => {
|
|
109
|
+
this.draw();
|
|
110
|
+
};
|
|
111
|
+
this.handleThemeChange = () => {
|
|
112
|
+
this.themeMayHaveChanged = true;
|
|
113
|
+
this.draw();
|
|
114
|
+
};
|
|
115
|
+
this.handleChartClick = (event) => {
|
|
116
|
+
var _a, _b;
|
|
117
|
+
if (!this.drawing) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const item = this.getClickableItem(getItemIndex(this.drawing, event));
|
|
121
|
+
if (!item) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
(_b = (_a = event.event) === null || _a === void 0 ? void 0 : _a.event) === null || _b === void 0 ? void 0 : _b.stopPropagation();
|
|
125
|
+
this.interact.emit(item);
|
|
126
|
+
};
|
|
127
|
+
this.handleChartOver = (event) => {
|
|
128
|
+
this.highlightItemAt(event, true);
|
|
129
|
+
};
|
|
130
|
+
this.handleChartOut = (event) => {
|
|
131
|
+
this.highlightItemAt(event, false);
|
|
132
|
+
};
|
|
93
133
|
this.handleClick = (event) => {
|
|
94
|
-
const item = this.getClickableItem(event
|
|
134
|
+
const item = this.getClickableItem(this.getRowIndex(event));
|
|
95
135
|
if (!item) {
|
|
96
136
|
return;
|
|
97
137
|
}
|
|
@@ -99,27 +139,79 @@ export class Chart {
|
|
|
99
139
|
this.interact.emit(item);
|
|
100
140
|
};
|
|
101
141
|
this.handleKeyDown = (event) => {
|
|
142
|
+
const orientation = orientations.find((option) => isNavigationKey(event, { orientation: option }));
|
|
143
|
+
if (orientation) {
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
this.focusItem(findNavigationTarget(this.items, event.key, this.getRowIndex(event), { orientation: orientation }));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
102
148
|
if (event.key !== 'Enter' && event.key !== ' ') {
|
|
103
149
|
return;
|
|
104
150
|
}
|
|
105
|
-
const item = this.getClickableItem(event
|
|
151
|
+
const item = this.getClickableItem(this.getRowIndex(event));
|
|
106
152
|
if (!item) {
|
|
107
153
|
return;
|
|
108
154
|
}
|
|
109
155
|
event.preventDefault();
|
|
110
156
|
this.interact.emit(item);
|
|
111
157
|
};
|
|
158
|
+
this.handleFocus = (event) => {
|
|
159
|
+
const row = event.currentTarget;
|
|
160
|
+
this.focusedIndex = Number(row.dataset.index);
|
|
161
|
+
this.showItem(row, true);
|
|
162
|
+
};
|
|
163
|
+
this.handleBlur = (event) => {
|
|
164
|
+
this.showItem(event.currentTarget, false);
|
|
165
|
+
};
|
|
112
166
|
}
|
|
113
167
|
componentWillLoad() {
|
|
114
|
-
this.
|
|
168
|
+
this.warnAboutAxisIncrement();
|
|
169
|
+
}
|
|
170
|
+
connectedCallback() {
|
|
171
|
+
this.draw();
|
|
172
|
+
}
|
|
173
|
+
componentDidRender() {
|
|
174
|
+
this.draw();
|
|
175
|
+
}
|
|
176
|
+
disconnectedCallback() {
|
|
177
|
+
var _a, _b, _c;
|
|
178
|
+
this.disposeChart();
|
|
179
|
+
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
180
|
+
this.resizeObserver = undefined;
|
|
181
|
+
(_b = this.stopWatchingTheme) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
182
|
+
this.stopWatchingTheme = undefined;
|
|
183
|
+
(_c = this.themeReader) === null || _c === void 0 ? void 0 : _c.dispose();
|
|
184
|
+
this.themeReader = undefined;
|
|
185
|
+
}
|
|
186
|
+
warnAboutAxisIncrement() {
|
|
187
|
+
const warning = this.getAxisIncrementWarning();
|
|
188
|
+
if (warning && warning !== this.axisIncrementWarning) {
|
|
189
|
+
console.warn(warning);
|
|
190
|
+
}
|
|
191
|
+
this.axisIncrementWarning = warning;
|
|
192
|
+
}
|
|
193
|
+
getAxisIncrementWarning() {
|
|
194
|
+
var _a;
|
|
195
|
+
const increment = this.axisIncrement;
|
|
196
|
+
if (increment === undefined || increment === null) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (increment <= 0 || Number.isNaN(increment)) {
|
|
200
|
+
return `limel-chart: \`axisIncrement\` must be above 0, but was ${increment}. Working out a step from the values instead.`;
|
|
201
|
+
}
|
|
202
|
+
if (!usesAxisIncrement(this.type)) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const range = getAxisRange((_a = this.items) !== null && _a !== void 0 ? _a : [], this.maxValue, increment);
|
|
206
|
+
if (range.increment !== increment) {
|
|
207
|
+
return `limel-chart: \`axisIncrement\` ${increment} would divide the axis into more than ${MAX_AXIS_STEPS} steps. Working out a step from the values instead.`;
|
|
208
|
+
}
|
|
115
209
|
}
|
|
116
210
|
render() {
|
|
117
211
|
if (this.loading) {
|
|
118
212
|
return h("limel-spinner", { limeBranded: false });
|
|
119
213
|
}
|
|
120
|
-
return (h("
|
|
121
|
-
'--limel-chart-number-of-items': this.items.length.toString(),
|
|
122
|
-
} }, this.renderCaption(), this.renderTableHeader(), this.renderAxises(), h("tbody", { class: "chart" }, this.renderItems())));
|
|
214
|
+
return (h(Host, null, h("div", { class: "plot", "aria-hidden": "true", ref: this.setPlot }), h("table", { "aria-live": "polite" }, this.renderCaption(), this.renderTableHeader(), h("tbody", null, this.renderItems()))));
|
|
123
215
|
}
|
|
124
216
|
renderCaption() {
|
|
125
217
|
if (!this.accessibleLabel) {
|
|
@@ -128,300 +220,237 @@ export class Chart {
|
|
|
128
220
|
return h("caption", null, this.accessibleLabel);
|
|
129
221
|
}
|
|
130
222
|
renderTableHeader() {
|
|
131
|
-
|
|
132
|
-
return (h("thead", null, h("tr", null, h("th", { scope: "col" }, (_a = this.accessibleItemsLabel) !== null && _a !== void 0 ? _a : translate.get('items', this.language)), h("th", { scope: "col" }, (_b = this.accessibleValuesLabel) !== null && _b !== void 0 ? _b : translate.get('value', this.language)))));
|
|
223
|
+
return (h("thead", null, h("tr", null, h("th", { scope: "col" }, this.itemsLabel), h("th", { scope: "col" }, this.valuesLabel))));
|
|
133
224
|
}
|
|
134
|
-
|
|
135
|
-
|
|
225
|
+
get itemsLabel() {
|
|
226
|
+
var _a;
|
|
227
|
+
return ((_a = this.accessibleItemsLabel) !== null && _a !== void 0 ? _a : translate.get('items', this.language));
|
|
228
|
+
}
|
|
229
|
+
get valuesLabel() {
|
|
230
|
+
var _a;
|
|
231
|
+
return ((_a = this.accessibleValuesLabel) !== null && _a !== void 0 ? _a : translate.get('value', this.language));
|
|
232
|
+
}
|
|
233
|
+
renderItems() {
|
|
234
|
+
var _a, _b;
|
|
235
|
+
const tabStop = findTabStop((_a = this.items) !== null && _a !== void 0 ? _a : [], this.focusedIndex);
|
|
236
|
+
return (_b = this.items) === null || _b === void 0 ? void 0 : _b.map((item, index) => (h("tr", { "data-index": index, "aria-description": this.getRowDescription(index), tabIndex: index === tabStop ? 0 : -1, role: item.clickable ? 'button' : null, onClick: this.handleClick, onKeyDown: this.handleKeyDown, onFocus: this.handleFocus, onBlur: this.handleBlur }, h("td", null, item.text), h("td", null, formatValue(item, this.type)))));
|
|
237
|
+
}
|
|
238
|
+
getRowDescription(index) {
|
|
239
|
+
const label = getItemLabel({
|
|
240
|
+
items: this.items,
|
|
241
|
+
type: this.type,
|
|
242
|
+
maxValue: this.maxValue,
|
|
243
|
+
displayItemPercentage: this.displayItemPercentage,
|
|
244
|
+
}, index);
|
|
245
|
+
return label === this.items[index].text ? undefined : label;
|
|
246
|
+
}
|
|
247
|
+
draw() {
|
|
248
|
+
var _a;
|
|
249
|
+
if (!((_a = this.plot) === null || _a === void 0 ? void 0 : _a.isConnected)) {
|
|
250
|
+
this.disposeChart();
|
|
136
251
|
return;
|
|
137
252
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
// Two value axes, so a full grid: horizontal lines for the vertical axis,
|
|
144
|
-
// vertical lines for the horizontal one. Which range maps to which flips
|
|
145
|
-
// with `orientation`, like the points.
|
|
146
|
-
renderScatterAxises() {
|
|
147
|
-
const portrait = this.orientation === 'portrait';
|
|
148
|
-
const horizontalLines = portrait ? this.secondaryAxisRange : this.range;
|
|
149
|
-
const verticalLines = portrait ? this.range : this.secondaryAxisRange;
|
|
150
|
-
return [
|
|
151
|
-
this.renderAxisLines(horizontalLines, 'horizontal-lines'),
|
|
152
|
-
this.renderAxisLines(verticalLines, 'vertical-lines'),
|
|
153
|
-
];
|
|
154
|
-
}
|
|
155
|
-
renderAxisLines(range, direction) {
|
|
156
|
-
const { minValue, maxValue, increment } = range;
|
|
157
|
-
const lines = [];
|
|
158
|
-
for (let value = minValue; value <= maxValue; value += increment) {
|
|
159
|
-
lines.push(h("div", { class: {
|
|
160
|
-
'axis-line': true,
|
|
161
|
-
'zero-line': value === 0,
|
|
162
|
-
}, role: "presentation" }, h("limel-badge", { label: value })));
|
|
253
|
+
this.observeSize();
|
|
254
|
+
const { clientWidth: width, clientHeight: height } = this.plot;
|
|
255
|
+
if (!width || !height) {
|
|
256
|
+
return;
|
|
163
257
|
}
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
|
|
258
|
+
this.createChart();
|
|
259
|
+
if (width !== this.chart.getWidth() ||
|
|
260
|
+
height !== this.chart.getHeight()) {
|
|
261
|
+
this.chart.resize();
|
|
167
262
|
}
|
|
168
|
-
|
|
263
|
+
this.updateChart();
|
|
264
|
+
this.fitItemTextsToSize();
|
|
169
265
|
}
|
|
170
|
-
|
|
266
|
+
createChart() {
|
|
171
267
|
var _a;
|
|
172
|
-
if (
|
|
268
|
+
if (((_a = this.chart) === null || _a === void 0 ? void 0 : _a.getDom()) === this.plot) {
|
|
173
269
|
return;
|
|
174
270
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
271
|
+
this.disposeChart();
|
|
272
|
+
/*!
|
|
273
|
+
* Apache ECharts
|
|
274
|
+
* Copyright 2017-2026 The Apache Software Foundation
|
|
275
|
+
*
|
|
276
|
+
* This product includes software developed at
|
|
277
|
+
* The Apache Software Foundation (https://www.apache.org/).
|
|
278
|
+
*
|
|
279
|
+
* Licensed under the Apache License, Version 2.0
|
|
280
|
+
* (https://www.apache.org/licenses/LICENSE-2.0).
|
|
281
|
+
*
|
|
282
|
+
*
|
|
283
|
+
* ZRender
|
|
284
|
+
* Copyright (c) 2017, Baidu Inc.
|
|
285
|
+
* All rights reserved.
|
|
286
|
+
*
|
|
287
|
+
* Redistribution and use in source and binary forms, with or without
|
|
288
|
+
* modification, are permitted provided that the following conditions are met:
|
|
289
|
+
*
|
|
290
|
+
* * Redistributions of source code must retain the above copyright notice, this
|
|
291
|
+
* list of conditions and the following disclaimer.
|
|
292
|
+
*
|
|
293
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
294
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
295
|
+
* and/or other materials provided with the distribution.
|
|
296
|
+
*
|
|
297
|
+
* * Neither the name of the copyright holder nor the names of its
|
|
298
|
+
* contributors may be used to endorse or promote products derived from
|
|
299
|
+
* this software without specific prior written permission.
|
|
300
|
+
*
|
|
301
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
302
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
303
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
304
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
305
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
306
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
307
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
308
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
309
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
310
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
311
|
+
*/
|
|
312
|
+
use(extensions);
|
|
313
|
+
this.chart = init(this.plot, null, { renderer: 'svg' });
|
|
314
|
+
this.chart.on('click', this.handleChartClick);
|
|
315
|
+
this.chart.on('mouseover', this.handleChartOver);
|
|
316
|
+
this.chart.on('mouseout', this.handleChartOut);
|
|
187
317
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
318
|
+
updateChart() {
|
|
319
|
+
var _a, _b;
|
|
320
|
+
const settings = this.getSettings();
|
|
321
|
+
const drawnSettings = JSON.stringify(settings);
|
|
322
|
+
if (drawnSettings === this.drawnSettings && !this.themeMayHaveChanged) {
|
|
323
|
+
return;
|
|
191
324
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
325
|
+
this.themeMayHaveChanged = false;
|
|
326
|
+
(_a = this.themeReader) !== null && _a !== void 0 ? _a : (this.themeReader = createThemeReader(this.host.shadowRoot));
|
|
327
|
+
(_b = this.stopWatchingTheme) !== null && _b !== void 0 ? _b : (this.stopWatchingTheme = watchTheme(this.host, this.handleThemeChange));
|
|
328
|
+
const theme = this.themeReader.theme();
|
|
329
|
+
const coloredSettings = this.withItemColors(settings, theme);
|
|
330
|
+
const drawnTheme = JSON.stringify({
|
|
331
|
+
theme: theme,
|
|
332
|
+
itemColors: coloredSettings.items.map((item) => item.color),
|
|
333
|
+
});
|
|
334
|
+
if (drawnSettings === this.drawnSettings &&
|
|
335
|
+
drawnTheme === this.drawnTheme) {
|
|
336
|
+
return;
|
|
200
337
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
338
|
+
this.drawnSettings = drawnSettings;
|
|
339
|
+
this.drawnTheme = drawnTheme;
|
|
340
|
+
this.drawing = drawChart(coloredSettings, theme, this.itemSpace);
|
|
341
|
+
this.chart.setOption(this.drawing.option, { notMerge: true });
|
|
342
|
+
const focusedRow = this.host.shadowRoot.activeElement;
|
|
343
|
+
if (focusedRow instanceof HTMLElement && focusedRow.dataset.index) {
|
|
344
|
+
this.showItem(focusedRow, true);
|
|
205
345
|
}
|
|
206
|
-
return style;
|
|
207
346
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
};
|
|
214
|
-
if (item.color) {
|
|
215
|
-
style['--limel-chart-item-color'] = item.color;
|
|
347
|
+
fitItemTextsToSize() {
|
|
348
|
+
var _a;
|
|
349
|
+
const axis = (_a = this.drawing) === null || _a === void 0 ? void 0 : _a.itemTextAxis;
|
|
350
|
+
if (!axis) {
|
|
351
|
+
return;
|
|
216
352
|
}
|
|
217
|
-
|
|
353
|
+
const finder = { [`${axis}Index`]: 0 };
|
|
354
|
+
const itemSpace = Math.floor(Math.abs(this.chart.convertToPixel(finder, 1) -
|
|
355
|
+
this.chart.convertToPixel(finder, 0)));
|
|
356
|
+
if (itemSpace === this.itemSpace) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
this.itemSpace = itemSpace;
|
|
360
|
+
this.chart.setOption(fitItemTexts(this.drawing, itemSpace));
|
|
218
361
|
}
|
|
219
|
-
|
|
362
|
+
getSettings() {
|
|
363
|
+
var _a;
|
|
220
364
|
return {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
365
|
+
items: ((_a = this.items) !== null && _a !== void 0 ? _a : []).map((item) => ({
|
|
366
|
+
text: item.text,
|
|
367
|
+
value: item.value,
|
|
368
|
+
formattedValue: item.formattedValue,
|
|
369
|
+
color: item.color,
|
|
370
|
+
clickable: item.clickable,
|
|
371
|
+
})),
|
|
372
|
+
type: this.type,
|
|
373
|
+
orientation: this.orientation,
|
|
374
|
+
maxValue: this.maxValue,
|
|
375
|
+
axisIncrement: this.axisIncrement,
|
|
376
|
+
displayAxisLabels: this.displayAxisLabels,
|
|
377
|
+
itemsLabel: this.itemsLabel,
|
|
378
|
+
valuesLabel: this.valuesLabel,
|
|
379
|
+
displayItemText: this.displayItemText,
|
|
380
|
+
displayItemValue: this.displayItemValue,
|
|
381
|
+
displayItemPercentage: this.displayItemPercentage,
|
|
227
382
|
};
|
|
228
383
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (!item) {
|
|
232
|
-
return {
|
|
233
|
-
size: 0,
|
|
234
|
-
offset: 0,
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
if (this.isPartOfWhole()) {
|
|
238
|
-
return {
|
|
239
|
-
size: (this.getValueSpan(item) / totalRange) * PERCENT,
|
|
240
|
-
offset: 0,
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
let startValue = 0;
|
|
244
|
-
if (this.isRangeItem(item)) {
|
|
245
|
-
startValue = this.getMinimumValue(item);
|
|
246
|
-
}
|
|
247
|
-
const normalizedStart = ((startValue - minValue) / totalRange) * PERCENT;
|
|
248
|
-
const normalizedEnd = ((this.getMaximumValue(item) - minValue) / totalRange) * PERCENT;
|
|
249
|
-
return {
|
|
250
|
-
size: normalizedEnd - normalizedStart,
|
|
251
|
-
offset: normalizedStart,
|
|
252
|
-
};
|
|
384
|
+
withItemColors(settings, theme) {
|
|
385
|
+
return Object.assign(Object.assign({}, settings), { items: settings.items.map((item) => (Object.assign(Object.assign({}, item), { color: this.getItemColor(item, theme) }))) });
|
|
253
386
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return formattedValue;
|
|
387
|
+
getItemColor(item, theme) {
|
|
388
|
+
if (!item.color) {
|
|
389
|
+
return theme.itemColor;
|
|
258
390
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
return `${value[0]} — ${value[1]}`;
|
|
391
|
+
const color = this.themeReader.color(item.color);
|
|
392
|
+
if (color) {
|
|
393
|
+
return color;
|
|
264
394
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const text = this.getItemText(item);
|
|
272
|
-
const PERCENT_DECIMAL = 2;
|
|
273
|
-
const formattedValue = this.getFormattedValue(item);
|
|
274
|
-
const tooltipProps = {
|
|
275
|
-
label: text,
|
|
276
|
-
helperLabel: formattedValue,
|
|
277
|
-
elementId: itemId,
|
|
278
|
-
};
|
|
279
|
-
if (this.displayItemPercentage && this.isPartOfWhole()) {
|
|
280
|
-
tooltipProps.label = `${text} (${size.toFixed(PERCENT_DECIMAL)}%)`;
|
|
395
|
+
if (!this.invalidColors.has(item.color)) {
|
|
396
|
+
this.invalidColors.add(item.color);
|
|
397
|
+
const hint = item.color.includes('var(')
|
|
398
|
+
? ' Check that its variables are set, and that they make a color.'
|
|
399
|
+
: '';
|
|
400
|
+
console.warn(`limel-chart: the color of an item must be a CSS color, but was \`${item.color}\`.${hint} Using the default item color instead.`);
|
|
281
401
|
}
|
|
282
|
-
return
|
|
402
|
+
return theme.itemColor;
|
|
283
403
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return this.range;
|
|
288
|
-
}
|
|
289
|
-
if (this.isPartOfWhole()) {
|
|
290
|
-
return this.calculateWholeRange();
|
|
291
|
-
}
|
|
292
|
-
const minRange = Math.min(0, ...this.items.map(this.getMinimumValue));
|
|
293
|
-
const maxRange = Math.max(...this.items.map(this.getMaximumValue));
|
|
294
|
-
const finalMaxRange = (_a = this.maxValue) !== null && _a !== void 0 ? _a : maxRange;
|
|
295
|
-
if (!this.axisIncrement) {
|
|
296
|
-
this.axisIncrement = this.calculateAxisIncrement(this.items.map(this.getMaximumValue));
|
|
404
|
+
observeSize() {
|
|
405
|
+
if (this.resizeObserver || typeof ResizeObserver === 'undefined') {
|
|
406
|
+
return;
|
|
297
407
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const totalRange = visualMaxValue - visualMinValue;
|
|
301
|
-
return {
|
|
302
|
-
minValue: visualMinValue,
|
|
303
|
-
maxValue: visualMaxValue,
|
|
304
|
-
totalRange: totalRange,
|
|
305
|
-
increment: this.axisIncrement,
|
|
306
|
-
};
|
|
408
|
+
this.resizeObserver = new ResizeObserver(this.handleResize);
|
|
409
|
+
this.resizeObserver.observe(this.host);
|
|
307
410
|
}
|
|
308
|
-
|
|
309
|
-
* The range of a chart whose items are parts of one whole: `maxValue`
|
|
310
|
-
* when set, otherwise the combined item values or range extents. The value
|
|
311
|
-
* is a scale, not a cap, so the combined size can exceed it. The whole is
|
|
312
|
-
* not rounded to an axis step, since these types draw no axis and an item's
|
|
313
|
-
* size has to be its exact share.
|
|
314
|
-
*/
|
|
315
|
-
calculateWholeRange() {
|
|
411
|
+
disposeChart() {
|
|
316
412
|
var _a;
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
328
|
-
isPartOfWhole() {
|
|
329
|
-
return WHOLE_TYPES.has(this.type);
|
|
330
|
-
}
|
|
331
|
-
calculateAxisIncrement(values, steps = DEFAULT_INCREMENT_SIZE) {
|
|
332
|
-
return this.calculateNiceStep(Math.max(...values), steps);
|
|
333
|
-
}
|
|
334
|
-
// A "nice" step (…× 10ⁿ) dividing `span` into ~`steps` intervals. Takes the
|
|
335
|
-
// axis length, not a raw max, so it's sign-safe (a negative max would make
|
|
336
|
-
// `Math.log10` return `NaN`).
|
|
337
|
-
calculateNiceStep(span, steps = DEFAULT_INCREMENT_SIZE) {
|
|
338
|
-
if (span <= 0) {
|
|
339
|
-
// Every value is identical (e.g. all zero); any positive step works.
|
|
340
|
-
return 1;
|
|
413
|
+
(_a = this.chart) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
414
|
+
this.chart = undefined;
|
|
415
|
+
this.drawing = undefined;
|
|
416
|
+
this.drawnSettings = undefined;
|
|
417
|
+
this.drawnTheme = undefined;
|
|
418
|
+
this.itemSpace = undefined;
|
|
419
|
+
}
|
|
420
|
+
highlightItemAt(event, highlight) {
|
|
421
|
+
if (!this.drawing) {
|
|
422
|
+
return;
|
|
341
423
|
}
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}
|
|
346
|
-
// Axis length measured through zero, so the origin is always included.
|
|
347
|
-
axisSpan(values) {
|
|
348
|
-
return Math.max(0, ...values) - Math.min(0, ...values);
|
|
349
|
-
}
|
|
350
|
-
// A "nice" rounded range for one scatter axis. Both bounds include zero, so
|
|
351
|
-
// a fully-negative axis still shows its origin (and zero line).
|
|
352
|
-
calculateAxisRange(values, increment) {
|
|
353
|
-
const minValue = Math.floor(Math.min(0, ...values) / increment) * increment;
|
|
354
|
-
const maxValue = Math.ceil(Math.max(0, ...values) / increment) * increment;
|
|
355
|
-
return {
|
|
356
|
-
minValue: minValue,
|
|
357
|
-
maxValue: maxValue,
|
|
358
|
-
totalRange: maxValue - minValue,
|
|
359
|
-
increment: increment,
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
normalize(value, range) {
|
|
363
|
-
if (range.totalRange === 0) {
|
|
364
|
-
// Degenerate axis (every value is zero): center the point so it
|
|
365
|
-
// stays visible instead of dividing by zero.
|
|
366
|
-
return PERCENT / 2;
|
|
424
|
+
const location = locateItem(this.drawing, getItemIndex(this.drawing, event));
|
|
425
|
+
if (location.seriesIndex === event.seriesIndex) {
|
|
426
|
+
return;
|
|
367
427
|
}
|
|
368
|
-
|
|
428
|
+
this.chart.dispatchAction(Object.assign({ type: highlight ? 'highlight' : 'downplay' }, location));
|
|
369
429
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
getYValue(item) {
|
|
374
|
-
return Array.isArray(item.value) ? item.value[1] : item.value;
|
|
375
|
-
}
|
|
376
|
-
getMinimumValue(item) {
|
|
377
|
-
const value = item.value;
|
|
378
|
-
return Array.isArray(value) ? Math.min(...value) : value;
|
|
379
|
-
}
|
|
380
|
-
getMaximumValue(item) {
|
|
381
|
-
const value = item.value;
|
|
382
|
-
return Array.isArray(value) ? Math.max(...value) : value;
|
|
383
|
-
}
|
|
384
|
-
getValueSpan(item) {
|
|
385
|
-
const startValue = this.isRangeItem(item)
|
|
386
|
-
? this.getMinimumValue(item)
|
|
387
|
-
: 0;
|
|
388
|
-
return this.getMaximumValue(item) - startValue;
|
|
389
|
-
}
|
|
390
|
-
isRangeItem(item) {
|
|
391
|
-
return Array.isArray(item.value);
|
|
392
|
-
}
|
|
393
|
-
handleChange() {
|
|
394
|
-
this.range = null;
|
|
395
|
-
this.secondaryAxisRange = null;
|
|
396
|
-
this.recalculateRangeData();
|
|
397
|
-
}
|
|
398
|
-
recalculateRangeData() {
|
|
399
|
-
if (this.type === 'scatter') {
|
|
400
|
-
this.recalculateScatterRanges();
|
|
430
|
+
getClickableItem(index) {
|
|
431
|
+
const item = this.items[index];
|
|
432
|
+
if (!(item === null || item === void 0 ? void 0 : item.clickable)) {
|
|
401
433
|
return;
|
|
402
434
|
}
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
const xValues = this.items.map((item) => this.getXValue(item));
|
|
411
|
-
const yValues = this.items.map((item) => this.getYValue(item));
|
|
412
|
-
this.range = this.calculateAxisRange(yValues, this.calculateNiceStep(this.axisSpan(yValues)));
|
|
413
|
-
this.secondaryAxisRange = this.calculateAxisRange(xValues, this.calculateNiceStep(this.axisSpan(xValues)));
|
|
414
|
-
}
|
|
415
|
-
getClickableItem(target) {
|
|
416
|
-
const index = target.dataset.index;
|
|
417
|
-
if (index === undefined) {
|
|
435
|
+
return item;
|
|
436
|
+
}
|
|
437
|
+
getRowIndex(event) {
|
|
438
|
+
return Number(event.currentTarget.dataset.index);
|
|
439
|
+
}
|
|
440
|
+
focusItem(index) {
|
|
441
|
+
if (index === NO_NAVIGATION_TARGET) {
|
|
418
442
|
return;
|
|
419
443
|
}
|
|
420
|
-
const
|
|
421
|
-
|
|
444
|
+
const rows = this.host.shadowRoot.querySelectorAll('tbody tr');
|
|
445
|
+
rows[index].focus();
|
|
446
|
+
}
|
|
447
|
+
showItem(row, show) {
|
|
448
|
+
if (!this.chart || !this.drawing) {
|
|
422
449
|
return;
|
|
423
450
|
}
|
|
424
|
-
|
|
451
|
+
const location = locateItem(this.drawing, Number(row.dataset.index));
|
|
452
|
+
this.chart.dispatchAction(Object.assign({ type: show ? 'highlight' : 'downplay' }, location));
|
|
453
|
+
this.chart.dispatchAction(Object.assign({ type: show ? 'showTip' : 'hideTip' }, location));
|
|
425
454
|
}
|
|
426
455
|
static get is() { return "limel-chart"; }
|
|
427
456
|
static get encapsulation() { return "shadow"; }
|
|
@@ -629,9 +658,16 @@ export class Chart {
|
|
|
629
658
|
"type": "string",
|
|
630
659
|
"mutable": false,
|
|
631
660
|
"complexType": {
|
|
632
|
-
"original": "
|
|
661
|
+
"original": "ChartType",
|
|
633
662
|
"resolved": "\"area\" | \"bar\" | \"dot\" | \"doughnut\" | \"line\" | \"nps\" | \"pie\" | \"ring\" | \"scatter\" | \"stacked-bar\"",
|
|
634
|
-
"references": {
|
|
663
|
+
"references": {
|
|
664
|
+
"ChartType": {
|
|
665
|
+
"location": "import",
|
|
666
|
+
"path": "./chart.types",
|
|
667
|
+
"id": "src/components/chart/chart.types.ts::ChartType",
|
|
668
|
+
"referenceLocation": "ChartType"
|
|
669
|
+
}
|
|
670
|
+
}
|
|
635
671
|
},
|
|
636
672
|
"required": false,
|
|
637
673
|
"optional": true,
|
|
@@ -696,7 +732,7 @@ export class Chart {
|
|
|
696
732
|
"optional": true,
|
|
697
733
|
"docs": {
|
|
698
734
|
"tags": [],
|
|
699
|
-
"text": "Sets the axis increment for `bar`, `dot`, `area`, and `line` charts.\nHas no effect on other chart types."
|
|
735
|
+
"text": "Sets the axis increment for `bar`, `dot`, `area`, and `line` charts.\nWhen it is not set, or not above zero, the chart works out a step\nfrom the values. It also does that when the step would divide the\naxis into more than 100 parts, so that it does not draw too many lines.\nHas no effect on other chart types."
|
|
700
736
|
},
|
|
701
737
|
"getter": false,
|
|
702
738
|
"setter": false,
|
|
@@ -725,6 +761,11 @@ export class Chart {
|
|
|
725
761
|
}
|
|
726
762
|
};
|
|
727
763
|
}
|
|
764
|
+
static get states() {
|
|
765
|
+
return {
|
|
766
|
+
"focusedIndex": {}
|
|
767
|
+
};
|
|
768
|
+
}
|
|
728
769
|
static get events() {
|
|
729
770
|
return [{
|
|
730
771
|
"method": "interact",
|
|
@@ -750,19 +791,20 @@ export class Chart {
|
|
|
750
791
|
}
|
|
751
792
|
}];
|
|
752
793
|
}
|
|
794
|
+
static get elementRef() { return "host"; }
|
|
753
795
|
static get watchers() {
|
|
754
796
|
return [{
|
|
755
|
-
"propName": "items",
|
|
756
|
-
"methodName": "handleChange"
|
|
757
|
-
}, {
|
|
758
797
|
"propName": "axisIncrement",
|
|
759
|
-
"methodName": "
|
|
798
|
+
"methodName": "warnAboutAxisIncrement"
|
|
799
|
+
}, {
|
|
800
|
+
"propName": "items",
|
|
801
|
+
"methodName": "warnAboutAxisIncrement"
|
|
760
802
|
}, {
|
|
761
803
|
"propName": "maxValue",
|
|
762
|
-
"methodName": "
|
|
804
|
+
"methodName": "warnAboutAxisIncrement"
|
|
763
805
|
}, {
|
|
764
806
|
"propName": "type",
|
|
765
|
-
"methodName": "
|
|
807
|
+
"methodName": "warnAboutAxisIncrement"
|
|
766
808
|
}];
|
|
767
809
|
}
|
|
768
810
|
}
|