@techie_doubts/tui.chart.2026 4.6.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/README.md +165 -0
- package/dist/esm/animator.d.ts +32 -0
- package/dist/esm/animator.js +102 -0
- package/dist/esm/brushes/axis.d.ts +3 -0
- package/dist/esm/brushes/axis.js +21 -0
- package/dist/esm/brushes/basic.d.ts +9 -0
- package/dist/esm/brushes/basic.js +95 -0
- package/dist/esm/brushes/boxPlot.d.ts +2 -0
- package/dist/esm/brushes/boxPlot.js +22 -0
- package/dist/esm/brushes/circleLegend.d.ts +2 -0
- package/dist/esm/brushes/circleLegend.js +26 -0
- package/dist/esm/brushes/dataLabel.d.ts +6 -0
- package/dist/esm/brushes/dataLabel.js +176 -0
- package/dist/esm/brushes/exportMenu.d.ts +2 -0
- package/dist/esm/brushes/exportMenu.js +55 -0
- package/dist/esm/brushes/gauge.d.ts +2 -0
- package/dist/esm/brushes/gauge.js +39 -0
- package/dist/esm/brushes/label.d.ts +34 -0
- package/dist/esm/brushes/label.js +165 -0
- package/dist/esm/brushes/legend.d.ts +7 -0
- package/dist/esm/brushes/legend.js +162 -0
- package/dist/esm/brushes/lineSeries.d.ts +5 -0
- package/dist/esm/brushes/lineSeries.js +41 -0
- package/dist/esm/brushes/polygon.d.ts +2 -0
- package/dist/esm/brushes/polygon.js +24 -0
- package/dist/esm/brushes/resetButton.d.ts +3 -0
- package/dist/esm/brushes/resetButton.js +112 -0
- package/dist/esm/brushes/scatterSeries.d.ts +2 -0
- package/dist/esm/brushes/scatterSeries.js +125 -0
- package/dist/esm/brushes/sector.d.ts +2 -0
- package/dist/esm/brushes/sector.js +54 -0
- package/dist/esm/brushes/spectrumLegend.d.ts +14 -0
- package/dist/esm/brushes/spectrumLegend.js +199 -0
- package/dist/esm/charts/areaChart.d.ts +254 -0
- package/dist/esm/charts/areaChart.js +358 -0
- package/dist/esm/charts/barChart.d.ts +203 -0
- package/dist/esm/charts/barChart.js +300 -0
- package/dist/esm/charts/boxPlotChart.d.ts +209 -0
- package/dist/esm/charts/boxPlotChart.js +288 -0
- package/dist/esm/charts/bubbleChart.d.ts +188 -0
- package/dist/esm/charts/bubbleChart.js +263 -0
- package/dist/esm/charts/bulletChart.d.ts +199 -0
- package/dist/esm/charts/bulletChart.js +278 -0
- package/dist/esm/charts/chart.d.ts +133 -0
- package/dist/esm/charts/chart.js +484 -0
- package/dist/esm/charts/columnChart.d.ts +205 -0
- package/dist/esm/charts/columnChart.js +299 -0
- package/dist/esm/charts/columnLineChart.d.ts +271 -0
- package/dist/esm/charts/columnLineChart.js +386 -0
- package/dist/esm/charts/gaugeChart.d.ts +191 -0
- package/dist/esm/charts/gaugeChart.js +279 -0
- package/dist/esm/charts/heatmapChart.d.ts +199 -0
- package/dist/esm/charts/heatmapChart.js +292 -0
- package/dist/esm/charts/lineAreaChart.d.ts +271 -0
- package/dist/esm/charts/lineAreaChart.js +374 -0
- package/dist/esm/charts/lineChart.d.ts +253 -0
- package/dist/esm/charts/lineChart.js +360 -0
- package/dist/esm/charts/lineScatterChart.d.ts +200 -0
- package/dist/esm/charts/lineScatterChart.js +285 -0
- package/dist/esm/charts/nestedPieChart.d.ts +192 -0
- package/dist/esm/charts/nestedPieChart.js +268 -0
- package/dist/esm/charts/pieChart.d.ts +156 -0
- package/dist/esm/charts/pieChart.js +224 -0
- package/dist/esm/charts/radarChart.d.ts +169 -0
- package/dist/esm/charts/radarChart.js +240 -0
- package/dist/esm/charts/radialBarChart.d.ts +172 -0
- package/dist/esm/charts/radialBarChart.js +251 -0
- package/dist/esm/charts/scatterChart.d.ts +184 -0
- package/dist/esm/charts/scatterChart.js +279 -0
- package/dist/esm/charts/treemapChart.d.ts +166 -0
- package/dist/esm/charts/treemapChart.js +239 -0
- package/dist/esm/component/areaSeries.d.ts +96 -0
- package/dist/esm/component/areaSeries.js +474 -0
- package/dist/esm/component/axis.d.ts +40 -0
- package/dist/esm/component/axis.js +176 -0
- package/dist/esm/component/axisTitle.d.ts +25 -0
- package/dist/esm/component/axisTitle.js +67 -0
- package/dist/esm/component/axisUsingCenterY.d.ts +32 -0
- package/dist/esm/component/axisUsingCenterY.js +175 -0
- package/dist/esm/component/backButton.d.ts +13 -0
- package/dist/esm/component/backButton.js +26 -0
- package/dist/esm/component/background.d.ts +10 -0
- package/dist/esm/component/background.js +15 -0
- package/dist/esm/component/boxPlotSeries.d.ts +126 -0
- package/dist/esm/component/boxPlotSeries.js +410 -0
- package/dist/esm/component/boxSeries.d.ts +211 -0
- package/dist/esm/component/boxSeries.js +603 -0
- package/dist/esm/component/boxStackSeries.d.ts +62 -0
- package/dist/esm/component/boxStackSeries.js +447 -0
- package/dist/esm/component/bubbleSeries.d.ts +35 -0
- package/dist/esm/component/bubbleSeries.js +174 -0
- package/dist/esm/component/bulletSeries.d.ts +89 -0
- package/dist/esm/component/bulletSeries.js +392 -0
- package/dist/esm/component/circleLegend.d.ts +10 -0
- package/dist/esm/component/circleLegend.js +37 -0
- package/dist/esm/component/component.d.ts +64 -0
- package/dist/esm/component/component.js +170 -0
- package/dist/esm/component/componentManager.d.ts +23 -0
- package/dist/esm/component/componentManager.js +45 -0
- package/dist/esm/component/dataLabels.d.ts +23 -0
- package/dist/esm/component/dataLabels.js +134 -0
- package/dist/esm/component/exportMenu.d.ts +38 -0
- package/dist/esm/component/exportMenu.js +147 -0
- package/dist/esm/component/gaugeSeries.d.ts +160 -0
- package/dist/esm/component/gaugeSeries.js +447 -0
- package/dist/esm/component/heatmapSeries.d.ts +64 -0
- package/dist/esm/component/heatmapSeries.js +152 -0
- package/dist/esm/component/hoveredSeries.d.ts +27 -0
- package/dist/esm/component/hoveredSeries.js +95 -0
- package/dist/esm/component/legend.d.ts +26 -0
- package/dist/esm/component/legend.js +149 -0
- package/dist/esm/component/lineSeries.d.ts +69 -0
- package/dist/esm/component/lineSeries.js +319 -0
- package/dist/esm/component/noDataText.d.ts +9 -0
- package/dist/esm/component/noDataText.js +31 -0
- package/dist/esm/component/pieSeries.d.ts +137 -0
- package/dist/esm/component/pieSeries.js +390 -0
- package/dist/esm/component/plot.d.ts +37 -0
- package/dist/esm/component/plot.js +163 -0
- package/dist/esm/component/radarSeries.d.ts +85 -0
- package/dist/esm/component/radarSeries.js +222 -0
- package/dist/esm/component/radialAxis.d.ts +26 -0
- package/dist/esm/component/radialAxis.js +210 -0
- package/dist/esm/component/radialBarSeries.d.ts +111 -0
- package/dist/esm/component/radialBarSeries.js +349 -0
- package/dist/esm/component/radialPlot.d.ts +55 -0
- package/dist/esm/component/radialPlot.js +188 -0
- package/dist/esm/component/rangeSelection.d.ts +61 -0
- package/dist/esm/component/rangeSelection.js +150 -0
- package/dist/esm/component/resetButton.d.ts +13 -0
- package/dist/esm/component/resetButton.js +26 -0
- package/dist/esm/component/scatterSeries.d.ts +34 -0
- package/dist/esm/component/scatterSeries.js +159 -0
- package/dist/esm/component/selectedSeries.d.ts +26 -0
- package/dist/esm/component/selectedSeries.js +109 -0
- package/dist/esm/component/spectrumLegend.d.ts +15 -0
- package/dist/esm/component/spectrumLegend.js +76 -0
- package/dist/esm/component/title.d.ts +12 -0
- package/dist/esm/component/title.js +53 -0
- package/dist/esm/component/tooltip.d.ts +41 -0
- package/dist/esm/component/tooltip.js +131 -0
- package/dist/esm/component/treemapSeries.d.ts +57 -0
- package/dist/esm/component/treemapSeries.js +191 -0
- package/dist/esm/component/zeroAxis.d.ts +9 -0
- package/dist/esm/component/zeroAxis.js +49 -0
- package/dist/esm/eventEmitter.d.ts +8 -0
- package/dist/esm/eventEmitter.js +15 -0
- package/dist/esm/helpers/arrayUtil.d.ts +10 -0
- package/dist/esm/helpers/arrayUtil.js +54 -0
- package/dist/esm/helpers/axes.d.ts +67 -0
- package/dist/esm/helpers/axes.js +345 -0
- package/dist/esm/helpers/boxSeries.d.ts +5 -0
- package/dist/esm/helpers/boxSeries.js +71 -0
- package/dist/esm/helpers/calculator.d.ts +19 -0
- package/dist/esm/helpers/calculator.js +153 -0
- package/dist/esm/helpers/color.d.ts +153 -0
- package/dist/esm/helpers/color.js +218 -0
- package/dist/esm/helpers/colorSpectrum.d.ts +5 -0
- package/dist/esm/helpers/colorSpectrum.js +17 -0
- package/dist/esm/helpers/coordinate.d.ts +9 -0
- package/dist/esm/helpers/coordinate.js +51 -0
- package/dist/esm/helpers/dataLabels.d.ts +36 -0
- package/dist/esm/helpers/dataLabels.js +405 -0
- package/dist/esm/helpers/dom.d.ts +2 -0
- package/dist/esm/helpers/dom.js +8 -0
- package/dist/esm/helpers/downloader.d.ts +7 -0
- package/dist/esm/helpers/downloader.js +287 -0
- package/dist/esm/helpers/formatDate.d.ts +16 -0
- package/dist/esm/helpers/formatDate.js +140 -0
- package/dist/esm/helpers/geometric.d.ts +3 -0
- package/dist/esm/helpers/geometric.js +35 -0
- package/dist/esm/helpers/googleAnalytics.d.ts +1 -0
- package/dist/esm/helpers/googleAnalytics.js +39 -0
- package/dist/esm/helpers/htmlSanitizer.d.ts +1 -0
- package/dist/esm/helpers/htmlSanitizer.js +86 -0
- package/dist/esm/helpers/legend.d.ts +9 -0
- package/dist/esm/helpers/legend.js +47 -0
- package/dist/esm/helpers/pieSeries.d.ts +15 -0
- package/dist/esm/helpers/pieSeries.js +72 -0
- package/dist/esm/helpers/plot.d.ts +2 -0
- package/dist/esm/helpers/plot.js +4 -0
- package/dist/esm/helpers/radarSeries.d.ts +1 -0
- package/dist/esm/helpers/radarSeries.js +7 -0
- package/dist/esm/helpers/range.d.ts +6 -0
- package/dist/esm/helpers/range.js +16 -0
- package/dist/esm/helpers/responders.d.ts +37 -0
- package/dist/esm/helpers/responders.js +197 -0
- package/dist/esm/helpers/sector.d.ts +55 -0
- package/dist/esm/helpers/sector.js +117 -0
- package/dist/esm/helpers/squarifier.d.ts +8 -0
- package/dist/esm/helpers/squarifier.js +110 -0
- package/dist/esm/helpers/style.d.ts +14 -0
- package/dist/esm/helpers/style.js +48 -0
- package/dist/esm/helpers/theme.d.ts +58 -0
- package/dist/esm/helpers/theme.js +557 -0
- package/dist/esm/helpers/tooltip.d.ts +2 -0
- package/dist/esm/helpers/tooltip.js +18 -0
- package/dist/esm/helpers/tooltipTemplate.d.ts +21 -0
- package/dist/esm/helpers/tooltipTemplate.js +147 -0
- package/dist/esm/helpers/utils.d.ts +42 -0
- package/dist/esm/helpers/utils.js +268 -0
- package/dist/esm/helpers/validation.d.ts +6 -0
- package/dist/esm/helpers/validation.js +16 -0
- package/dist/esm/index.d.ts +40 -0
- package/dist/esm/index.js +75 -0
- package/dist/esm/message.d.ts +11 -0
- package/dist/esm/message.js +11 -0
- package/dist/esm/painter.d.ts +27 -0
- package/dist/esm/painter.js +88 -0
- package/dist/esm/responderDetectors.d.ts +6 -0
- package/dist/esm/responderDetectors.js +124 -0
- package/dist/esm/scale/coordinateScaleCalculator.d.ts +24 -0
- package/dist/esm/scale/coordinateScaleCalculator.js +174 -0
- package/dist/esm/scale/datetimeScaleCalculator.d.ts +20 -0
- package/dist/esm/scale/datetimeScaleCalculator.js +59 -0
- package/dist/esm/store/axes.d.ts +30 -0
- package/dist/esm/store/axes.js +282 -0
- package/dist/esm/store/category.d.ts +4 -0
- package/dist/esm/store/category.js +73 -0
- package/dist/esm/store/colorValueScale.d.ts +3 -0
- package/dist/esm/store/colorValueScale.js +56 -0
- package/dist/esm/store/dataRange.d.ts +4 -0
- package/dist/esm/store/dataRange.js +170 -0
- package/dist/esm/store/gaugeAxes.d.ts +4 -0
- package/dist/esm/store/gaugeAxes.js +175 -0
- package/dist/esm/store/heatmapAxes.d.ts +3 -0
- package/dist/esm/store/heatmapAxes.js +98 -0
- package/dist/esm/store/heatmapSeriesData.d.ts +3 -0
- package/dist/esm/store/heatmapSeriesData.js +34 -0
- package/dist/esm/store/layout.d.ts +12 -0
- package/dist/esm/store/layout.js +487 -0
- package/dist/esm/store/legend.d.ts +3 -0
- package/dist/esm/store/legend.js +435 -0
- package/dist/esm/store/nestedPieSeriesData.d.ts +3 -0
- package/dist/esm/store/nestedPieSeriesData.js +49 -0
- package/dist/esm/store/options.d.ts +3 -0
- package/dist/esm/store/options.js +62 -0
- package/dist/esm/store/plot.d.ts +3 -0
- package/dist/esm/store/plot.js +102 -0
- package/dist/esm/store/radialAxes.d.ts +8 -0
- package/dist/esm/store/radialAxes.js +199 -0
- package/dist/esm/store/reactive.d.ts +11 -0
- package/dist/esm/store/reactive.js +196 -0
- package/dist/esm/store/root.d.ts +3 -0
- package/dist/esm/store/root.js +46 -0
- package/dist/esm/store/scale.d.ts +3 -0
- package/dist/esm/store/scale.js +102 -0
- package/dist/esm/store/seriesData.d.ts +3 -0
- package/dist/esm/store/seriesData.js +299 -0
- package/dist/esm/store/stackSeriesData.d.ts +8 -0
- package/dist/esm/store/stackSeriesData.js +192 -0
- package/dist/esm/store/store.d.ts +20 -0
- package/dist/esm/store/store.js +112 -0
- package/dist/esm/store/theme.d.ts +3 -0
- package/dist/esm/store/theme.js +139 -0
- package/dist/esm/store/treemapSeriesData.d.ts +4 -0
- package/dist/esm/store/treemapSeriesData.js +93 -0
- package/dist/td-chart.css +127 -0
- package/dist/td-chart.js +41463 -0
- package/dist/td-chart.min.css +6 -0
- package/dist/td-chart.min.js +9 -0
- package/package.json +112 -0
- package/types/brushes.d.ts +30 -0
- package/types/charts.d.ts +152 -0
- package/types/components/axis.d.ts +71 -0
- package/types/components/circleLegend.d.ts +9 -0
- package/types/components/dataLabels.d.ts +119 -0
- package/types/components/exportMenu.d.ts +14 -0
- package/types/components/legend.d.ts +27 -0
- package/types/components/plot.d.ts +8 -0
- package/types/components/radialAxis.d.ts +22 -0
- package/types/components/radialPlot.d.ts +11 -0
- package/types/components/rangeSelection.d.ts +3 -0
- package/types/components/resetButton.d.ts +13 -0
- package/types/components/series.d.ts +386 -0
- package/types/components/spectrumLegend.d.ts +25 -0
- package/types/components/tooltip.d.ts +58 -0
- package/types/components/zoom.d.ts +3 -0
- package/types/eventEmitter.d.ts +12 -0
- package/types/index.d.ts +615 -0
- package/types/options.d.ts +833 -0
- package/types/resizeObserver.d.ts +54 -0
- package/types/store/store.d.ts +564 -0
- package/types/theme.d.ts +670 -0
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { isUndefined, sum, deepMergedCopy, range, isNumber } from "../helpers/utils";
|
|
2
|
+
import { getLegendItemHeight, LEGEND_CHECKBOX_SIZE, LEGEND_ICON_SIZE, LEGEND_ITEM_MARGIN_X, LEGEND_MARGIN_X, } from "../brushes/legend";
|
|
3
|
+
import { getTextWidth } from "../helpers/calculator";
|
|
4
|
+
import { isVerticalAlign, padding } from "./layout";
|
|
5
|
+
import { SPECTRUM_LEGEND_LABEL_HEIGHT, spectrumLegendBar, spectrumLegendTooltip, } from "../brushes/spectrumLegend";
|
|
6
|
+
import { hasNestedPieSeries } from "../helpers/pieSeries";
|
|
7
|
+
import { extend } from "./store";
|
|
8
|
+
import { getTitleFontString } from "../helpers/style";
|
|
9
|
+
import { makeDefaultTheme } from "../helpers/theme";
|
|
10
|
+
import { isNoData } from "../helpers/validation";
|
|
11
|
+
import { getIconType, getLegendAlign, showCheckbox, showCircleLegend, showLegend, } from "../helpers/legend";
|
|
12
|
+
const INITIAL_LEGEND_WIDTH = 100;
|
|
13
|
+
const INITIAL_CIRCLE_LEGEND_WIDTH = 150;
|
|
14
|
+
const COMPONENT_HEIGHT_EXCEPT_Y_AXIS = 100;
|
|
15
|
+
const ELLIPSIS_DOT_TEXT = '...';
|
|
16
|
+
const WIDEST_TEXT = 'W'; // The widest text width in Arial font.
|
|
17
|
+
const NUMBER_OF_BOTH_SIDES = 2;
|
|
18
|
+
function recalculateLegendWhenHeightOverflows(params, legendHeight) {
|
|
19
|
+
const { legendWidths, itemHeight } = params;
|
|
20
|
+
const totalHeight = legendWidths.length * itemHeight;
|
|
21
|
+
const columnCount = Math.ceil(totalHeight / legendHeight);
|
|
22
|
+
const rowCount = legendWidths.length / columnCount;
|
|
23
|
+
let legendWidth = 0;
|
|
24
|
+
range(0, columnCount).forEach((count) => {
|
|
25
|
+
legendWidth += Math.max(...legendWidths.slice(count * rowCount, (count + 1) * rowCount));
|
|
26
|
+
});
|
|
27
|
+
legendWidth += LEGEND_ITEM_MARGIN_X * (columnCount - 1);
|
|
28
|
+
return { legendWidth, legendHeight: rowCount * itemHeight + padding.Y, columnCount, rowCount };
|
|
29
|
+
}
|
|
30
|
+
function recalculateLegendWhenWidthOverflows(params, prevLegendWidth) {
|
|
31
|
+
const { legendWidths, itemHeight } = params;
|
|
32
|
+
let columnCount = 0;
|
|
33
|
+
let legendWidth = 0;
|
|
34
|
+
const { rowCount } = legendWidths.reduce((acc, width) => {
|
|
35
|
+
const widthWithMargin = LEGEND_ITEM_MARGIN_X + width;
|
|
36
|
+
if (acc.totalWidth + width > prevLegendWidth) {
|
|
37
|
+
acc.totalWidth = widthWithMargin;
|
|
38
|
+
acc.rowCount += 1;
|
|
39
|
+
acc.columnCount = 1;
|
|
40
|
+
columnCount = Math.max(columnCount, acc.columnCount);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
acc.totalWidth += widthWithMargin;
|
|
44
|
+
acc.columnCount += 1;
|
|
45
|
+
}
|
|
46
|
+
legendWidth = Math.max(legendWidth, acc.totalWidth);
|
|
47
|
+
return acc;
|
|
48
|
+
}, { totalWidth: 0, rowCount: 1, columnCount: 0 });
|
|
49
|
+
return { legendHeight: itemHeight * rowCount, rowCount, columnCount, legendWidth };
|
|
50
|
+
}
|
|
51
|
+
function calculateLegendSize(params) {
|
|
52
|
+
if (!params.visible) {
|
|
53
|
+
return { legendWidth: 0, legendHeight: 0, rowCount: 0, columnCount: 0 };
|
|
54
|
+
}
|
|
55
|
+
const { chart, verticalAlign, legendWidths } = params;
|
|
56
|
+
const { legendWidth, isOverflow: widthOverflow } = calculateLegendWidth(params);
|
|
57
|
+
const { legendHeight, isOverflow: heightOverflow } = calculateLegendHeight(params);
|
|
58
|
+
const columnCount = verticalAlign ? legendWidths.length : 1;
|
|
59
|
+
const rowCount = verticalAlign ? Math.ceil(legendWidth / chart.width) : legendWidths.length;
|
|
60
|
+
if (widthOverflow) {
|
|
61
|
+
return recalculateLegendWhenWidthOverflows(params, legendWidth / rowCount);
|
|
62
|
+
}
|
|
63
|
+
if (heightOverflow) {
|
|
64
|
+
return recalculateLegendWhenHeightOverflows(params, legendHeight);
|
|
65
|
+
}
|
|
66
|
+
return { legendWidth, legendHeight, columnCount, rowCount };
|
|
67
|
+
}
|
|
68
|
+
function calculateLegendHeight(params) {
|
|
69
|
+
const { verticalAlign, itemHeight, legendWidths } = params;
|
|
70
|
+
const { height: chartHeight } = getDefaultLegendSize(params);
|
|
71
|
+
let legendHeight;
|
|
72
|
+
let isOverflow = false;
|
|
73
|
+
if (verticalAlign) {
|
|
74
|
+
legendHeight = chartHeight;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const totalHeight = legendWidths.length * itemHeight;
|
|
78
|
+
isOverflow = chartHeight < totalHeight;
|
|
79
|
+
legendHeight = isOverflow ? chartHeight : totalHeight;
|
|
80
|
+
}
|
|
81
|
+
return { legendHeight, isOverflow };
|
|
82
|
+
}
|
|
83
|
+
function getSpectrumLegendWidth(legendWidths, chartWidth, verticalAlign) {
|
|
84
|
+
if (verticalAlign) {
|
|
85
|
+
const labelAreaWidth = sum(legendWidths);
|
|
86
|
+
return Math.max(chartWidth / 4, labelAreaWidth);
|
|
87
|
+
}
|
|
88
|
+
const spectrumAreaWidth = (spectrumLegendTooltip.PADDING + spectrumLegendBar.PADDING + padding.X) * NUMBER_OF_BOTH_SIDES +
|
|
89
|
+
spectrumLegendTooltip.POINT_HEIGHT +
|
|
90
|
+
spectrumLegendBar.HEIGHT;
|
|
91
|
+
return Math.max(...legendWidths) + spectrumAreaWidth;
|
|
92
|
+
}
|
|
93
|
+
function getSpectrumLegendHeight(itemHeight, chartHeight, verticalAlign) {
|
|
94
|
+
return verticalAlign
|
|
95
|
+
? SPECTRUM_LEGEND_LABEL_HEIGHT +
|
|
96
|
+
spectrumLegendBar.PADDING * NUMBER_OF_BOTH_SIDES +
|
|
97
|
+
spectrumLegendTooltip.POINT_HEIGHT +
|
|
98
|
+
spectrumLegendTooltip.HEIGHT +
|
|
99
|
+
padding.Y
|
|
100
|
+
: (chartHeight * 3) / 4;
|
|
101
|
+
}
|
|
102
|
+
function getNormalLegendWidth(params) {
|
|
103
|
+
const { initialWidth, legendWidths, checkbox, verticalAlign } = params;
|
|
104
|
+
let isOverflow = false;
|
|
105
|
+
let legendWidth;
|
|
106
|
+
if (verticalAlign) {
|
|
107
|
+
const { width: chartWidth } = getDefaultLegendSize(params);
|
|
108
|
+
const totalWidth = sum(legendWidths) + LEGEND_ITEM_MARGIN_X * (legendWidths.length - 1);
|
|
109
|
+
isOverflow = totalWidth > chartWidth;
|
|
110
|
+
legendWidth = totalWidth;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const labelAreaWidth = Math.max(...legendWidths);
|
|
114
|
+
legendWidth =
|
|
115
|
+
(checkbox ? LEGEND_CHECKBOX_SIZE + LEGEND_MARGIN_X : 0) +
|
|
116
|
+
LEGEND_ICON_SIZE +
|
|
117
|
+
LEGEND_MARGIN_X +
|
|
118
|
+
Math.max(labelAreaWidth, initialWidth);
|
|
119
|
+
}
|
|
120
|
+
return { legendWidth, isOverflow };
|
|
121
|
+
}
|
|
122
|
+
function calculateLegendWidth(params) {
|
|
123
|
+
var _a, _b;
|
|
124
|
+
const { options, visible } = params;
|
|
125
|
+
const legendOptions = (_a = options) === null || _a === void 0 ? void 0 : _a.legend;
|
|
126
|
+
if (!visible) {
|
|
127
|
+
return { legendWidth: 0, isOverflow: false };
|
|
128
|
+
}
|
|
129
|
+
if ((_b = legendOptions) === null || _b === void 0 ? void 0 : _b.width) {
|
|
130
|
+
return { legendWidth: legendOptions.width, isOverflow: false };
|
|
131
|
+
}
|
|
132
|
+
return getNormalLegendWidth(params);
|
|
133
|
+
}
|
|
134
|
+
function getDefaultLegendSize(params) {
|
|
135
|
+
const { verticalAlign, chart, itemHeight, initialWidth, circleLegendVisible } = params;
|
|
136
|
+
const restAreaHeight = COMPONENT_HEIGHT_EXCEPT_Y_AXIS + (circleLegendVisible ? INITIAL_CIRCLE_LEGEND_WIDTH : 0); // rest area temporary value (yAxisTitle.height + xAxis.height + circleLegend.height)
|
|
137
|
+
return verticalAlign
|
|
138
|
+
? { width: chart.width - padding.X * NUMBER_OF_BOTH_SIDES, height: itemHeight }
|
|
139
|
+
: {
|
|
140
|
+
width: initialWidth,
|
|
141
|
+
height: chart.height - restAreaHeight,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function getNestedPieLegendLabelsInfo(series, legendInfo) {
|
|
145
|
+
const result = [];
|
|
146
|
+
const maxTextLengthWithEllipsis = getMaxTextLengthWithEllipsis(legendInfo);
|
|
147
|
+
series.pie.forEach(({ data }) => {
|
|
148
|
+
data.forEach(({ name, parentName, visible }) => {
|
|
149
|
+
if (!parentName) {
|
|
150
|
+
const { width, viewLabel } = getViewLabelInfo(legendInfo, name, maxTextLengthWithEllipsis);
|
|
151
|
+
result.push({
|
|
152
|
+
label: name,
|
|
153
|
+
type: 'pie',
|
|
154
|
+
checked: (visible !== null && visible !== void 0 ? visible : true),
|
|
155
|
+
viewLabel,
|
|
156
|
+
width,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
function getMaxTextLengthWithEllipsis(legendInfo) {
|
|
164
|
+
var _a, _b;
|
|
165
|
+
const { legendOptions, font, checkboxVisible } = legendInfo;
|
|
166
|
+
const width = (_b = (_a = legendOptions) === null || _a === void 0 ? void 0 : _a.item) === null || _b === void 0 ? void 0 : _b.width;
|
|
167
|
+
if (isUndefined(width)) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const checkboxWidth = checkboxVisible ? LEGEND_CHECKBOX_SIZE + LEGEND_MARGIN_X : 0;
|
|
171
|
+
const iconWidth = LEGEND_ICON_SIZE + LEGEND_MARGIN_X;
|
|
172
|
+
const ellipsisDotWidth = getTextWidth(ELLIPSIS_DOT_TEXT, font);
|
|
173
|
+
const widestTextWidth = getTextWidth(WIDEST_TEXT, font);
|
|
174
|
+
const maxTextCount = Math.floor((width - ellipsisDotWidth - checkboxWidth - iconWidth) / widestTextWidth);
|
|
175
|
+
return maxTextCount > 0 ? maxTextCount : 0;
|
|
176
|
+
}
|
|
177
|
+
function getViewLabelInfo(legendInfo, label, maxTextLength) {
|
|
178
|
+
var _a, _b;
|
|
179
|
+
const { checkboxVisible, useSpectrumLegend, font, legendOptions } = legendInfo;
|
|
180
|
+
let viewLabel = label;
|
|
181
|
+
const itemWidth = (_b = (_a = legendOptions) === null || _a === void 0 ? void 0 : _a.item) === null || _b === void 0 ? void 0 : _b.width;
|
|
182
|
+
const itemWidthWithFullText = getItemWidth(viewLabel, checkboxVisible, useSpectrumLegend, font);
|
|
183
|
+
if (isNumber(itemWidth) && isNumber(maxTextLength) && itemWidth < itemWidthWithFullText) {
|
|
184
|
+
viewLabel = `${label.slice(0, maxTextLength)}${ELLIPSIS_DOT_TEXT}`;
|
|
185
|
+
}
|
|
186
|
+
return { viewLabel, width: (itemWidth !== null && itemWidth !== void 0 ? itemWidth : itemWidthWithFullText) };
|
|
187
|
+
}
|
|
188
|
+
function getLegendLabelsInfo(series, legendInfo, categories) {
|
|
189
|
+
const maxTextLengthWithEllipsis = getMaxTextLengthWithEllipsis(legendInfo);
|
|
190
|
+
let colorIndex = 0;
|
|
191
|
+
return Object.keys(series).flatMap((type) => {
|
|
192
|
+
const labelInfo = series[type].map(({ name, colorValue, visible, colorByCategories }) => {
|
|
193
|
+
const label = colorValue ? colorValue : name;
|
|
194
|
+
const currentColorIndex = colorIndex;
|
|
195
|
+
const { width, viewLabel } = getViewLabelInfo(legendInfo, label, maxTextLengthWithEllipsis);
|
|
196
|
+
colorIndex += colorByCategories ? categories.length : 1;
|
|
197
|
+
return {
|
|
198
|
+
label,
|
|
199
|
+
type,
|
|
200
|
+
colorByCategories: !!colorByCategories,
|
|
201
|
+
colorIndex: currentColorIndex,
|
|
202
|
+
checked: (visible !== null && visible !== void 0 ? visible : true),
|
|
203
|
+
viewLabel,
|
|
204
|
+
width,
|
|
205
|
+
};
|
|
206
|
+
});
|
|
207
|
+
colorIndex += series[type].length - 1;
|
|
208
|
+
return labelInfo;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function getItemWidth(label, checkboxVisible, useSpectrumLegend, font) {
|
|
212
|
+
return ((useSpectrumLegend
|
|
213
|
+
? 0
|
|
214
|
+
: (checkboxVisible ? LEGEND_CHECKBOX_SIZE + LEGEND_MARGIN_X : 0) +
|
|
215
|
+
LEGEND_ICON_SIZE +
|
|
216
|
+
LEGEND_MARGIN_X) + getTextWidth(label, font));
|
|
217
|
+
}
|
|
218
|
+
function getLegendDataAppliedTheme(data, series) {
|
|
219
|
+
const colors = Object.values(series).reduce((acc, cur) => (cur && cur.colors ? [...acc, ...cur.colors] : acc), []);
|
|
220
|
+
const hasColorByCategories = data.some((legend) => legend.colorByCategories);
|
|
221
|
+
return data.map((datum, idx) => {
|
|
222
|
+
const { colorByCategories, colorIndex } = datum;
|
|
223
|
+
const index = hasColorByCategories ? colorIndex || idx : idx;
|
|
224
|
+
return Object.assign(Object.assign({}, datum), { color: colorByCategories ? '#aaa' : colors[index % colors.length] });
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
function getLegendState(options, series, categories) {
|
|
228
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
229
|
+
const useSpectrumLegend = (_c = (_b = (_a = options) === null || _a === void 0 ? void 0 : _a.series) === null || _b === void 0 ? void 0 : _b.useColorValue, (_c !== null && _c !== void 0 ? _c : !!series.heatmap));
|
|
230
|
+
const useScatterChartIcon = !!((_d = series) === null || _d === void 0 ? void 0 : _d.scatter);
|
|
231
|
+
const checkboxVisible = useSpectrumLegend
|
|
232
|
+
? false
|
|
233
|
+
: showCheckbox(options);
|
|
234
|
+
const defaultTheme = makeDefaultTheme(series, (_g = (_f = (_e = options) === null || _e === void 0 ? void 0 : _e.theme) === null || _f === void 0 ? void 0 : _f.chart) === null || _g === void 0 ? void 0 : _g.fontFamily);
|
|
235
|
+
const font = getTitleFontString(deepMergedCopy(defaultTheme.legend.label, Object.assign({}, (_j = (_h = options.theme) === null || _h === void 0 ? void 0 : _h.legend) === null || _j === void 0 ? void 0 : _j.label)));
|
|
236
|
+
const legendInfo = {
|
|
237
|
+
checkboxVisible,
|
|
238
|
+
font,
|
|
239
|
+
useSpectrumLegend,
|
|
240
|
+
legendOptions: options.legend,
|
|
241
|
+
};
|
|
242
|
+
const legendLabelsInfo = hasNestedPieSeries(series)
|
|
243
|
+
? getNestedPieLegendLabelsInfo(series, legendInfo)
|
|
244
|
+
: getLegendLabelsInfo(series, legendInfo, categories);
|
|
245
|
+
const data = legendLabelsInfo.map(({ label, type, checked, width, viewLabel, colorByCategories, colorIndex }) => ({
|
|
246
|
+
label,
|
|
247
|
+
active: true,
|
|
248
|
+
checked,
|
|
249
|
+
width,
|
|
250
|
+
iconType: getIconType(type),
|
|
251
|
+
chartType: type,
|
|
252
|
+
rowIndex: 0,
|
|
253
|
+
columnIndex: 0,
|
|
254
|
+
viewLabel,
|
|
255
|
+
colorByCategories,
|
|
256
|
+
colorIndex,
|
|
257
|
+
}));
|
|
258
|
+
return {
|
|
259
|
+
useSpectrumLegend,
|
|
260
|
+
useScatterChartIcon,
|
|
261
|
+
data,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
function getNextColumnRowIndex(params) {
|
|
265
|
+
const { verticalAlign, columnCount, rowCount, legendCount } = params;
|
|
266
|
+
let { rowIndex, columnIndex } = params;
|
|
267
|
+
if (verticalAlign) {
|
|
268
|
+
const maxLen = legendCount / rowCount;
|
|
269
|
+
if (maxLen - 1 > columnIndex) {
|
|
270
|
+
columnIndex += 1;
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
rowIndex += 1;
|
|
274
|
+
columnIndex = 0;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
const maxLen = legendCount / columnCount;
|
|
279
|
+
if (maxLen - 1 > rowIndex) {
|
|
280
|
+
rowIndex += 1;
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
columnIndex += 1;
|
|
284
|
+
rowIndex = 0;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return [rowIndex, columnIndex];
|
|
288
|
+
}
|
|
289
|
+
function setIndexToLegendData(legendData, rowCount, columnCount, legendCount, verticalAlign) {
|
|
290
|
+
let columnIndex = 0;
|
|
291
|
+
let rowIndex = 0;
|
|
292
|
+
legendData.forEach((datum) => {
|
|
293
|
+
datum.rowIndex = rowIndex;
|
|
294
|
+
datum.columnIndex = columnIndex;
|
|
295
|
+
[rowIndex, columnIndex] = getNextColumnRowIndex({
|
|
296
|
+
rowCount,
|
|
297
|
+
columnCount,
|
|
298
|
+
verticalAlign,
|
|
299
|
+
legendCount,
|
|
300
|
+
rowIndex,
|
|
301
|
+
columnIndex,
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
const legend = {
|
|
306
|
+
name: 'legend',
|
|
307
|
+
state: ({ options, series, categories }) => {
|
|
308
|
+
return {
|
|
309
|
+
legend: getLegendState(options, series, categories),
|
|
310
|
+
circleLegend: {},
|
|
311
|
+
};
|
|
312
|
+
},
|
|
313
|
+
action: {
|
|
314
|
+
initLegendState({ state, initStoreState }) {
|
|
315
|
+
extend(state.legend, getLegendState(initStoreState.options, initStoreState.series, initStoreState.categories));
|
|
316
|
+
},
|
|
317
|
+
setLegendLayout({ state }) {
|
|
318
|
+
if (state.legend.useSpectrumLegend) {
|
|
319
|
+
this.dispatch('setSpectrumLegendLayout');
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
this.dispatch('setNormalLegendLayout');
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
setSpectrumLegendLayout({ state }) {
|
|
326
|
+
const { legend: { data: legendData }, series, options, chart, theme, } = state;
|
|
327
|
+
const align = getLegendAlign(options);
|
|
328
|
+
const visible = showLegend(options, series);
|
|
329
|
+
const verticalAlign = isVerticalAlign(align);
|
|
330
|
+
const legendWidths = legendData.map(({ width }) => width);
|
|
331
|
+
const itemHeight = getLegendItemHeight(theme.legend.label.fontSize);
|
|
332
|
+
const width = getSpectrumLegendWidth(legendWidths, chart.width, verticalAlign);
|
|
333
|
+
const height = getSpectrumLegendHeight(itemHeight, chart.height, verticalAlign);
|
|
334
|
+
extend(state.legend, { visible, align, width, height });
|
|
335
|
+
},
|
|
336
|
+
setNormalLegendLayout({ state, initStoreState }) {
|
|
337
|
+
const { legend: { data: legendData }, series, options, chart, theme, } = state;
|
|
338
|
+
const align = getLegendAlign(options);
|
|
339
|
+
const visible = showLegend(options, series);
|
|
340
|
+
const checkbox = showCheckbox(options);
|
|
341
|
+
const initialWidth = Math.min(chart.width / 5, INITIAL_LEGEND_WIDTH);
|
|
342
|
+
const verticalAlign = isVerticalAlign(align);
|
|
343
|
+
const isNestedPieChart = hasNestedPieSeries(initStoreState.series);
|
|
344
|
+
const isScatterChart = !!series.scatter;
|
|
345
|
+
const isBubbleChart = !!series.bubble;
|
|
346
|
+
const circleLegendVisible = isBubbleChart
|
|
347
|
+
? showCircleLegend(options)
|
|
348
|
+
: false;
|
|
349
|
+
const legendWidths = legendData.map(({ width }) => width);
|
|
350
|
+
const itemHeight = getLegendItemHeight(theme.legend.label.fontSize);
|
|
351
|
+
const { legendWidth, legendHeight, rowCount, columnCount } = calculateLegendSize({
|
|
352
|
+
initialWidth,
|
|
353
|
+
legendWidths,
|
|
354
|
+
options,
|
|
355
|
+
verticalAlign,
|
|
356
|
+
visible,
|
|
357
|
+
checkbox,
|
|
358
|
+
chart,
|
|
359
|
+
itemHeight,
|
|
360
|
+
circleLegendVisible,
|
|
361
|
+
});
|
|
362
|
+
setIndexToLegendData(legendData, rowCount, columnCount, legendWidths.length, verticalAlign);
|
|
363
|
+
extend(state.legend, {
|
|
364
|
+
visible,
|
|
365
|
+
align,
|
|
366
|
+
showCheckbox: checkbox,
|
|
367
|
+
width: legendWidth,
|
|
368
|
+
height: legendHeight,
|
|
369
|
+
});
|
|
370
|
+
if (isBubbleChart && circleLegendVisible) {
|
|
371
|
+
this.dispatch('updateCircleLegendLayout', { legendWidth });
|
|
372
|
+
}
|
|
373
|
+
if (!isNestedPieChart && !isNoData(series)) {
|
|
374
|
+
this.dispatch('updateLegendColor');
|
|
375
|
+
}
|
|
376
|
+
if (isScatterChart) {
|
|
377
|
+
this.dispatch('updateLegendIcon');
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
updateCircleLegendLayout({ state }, { legendWidth }) {
|
|
381
|
+
const width = legendWidth === 0
|
|
382
|
+
? INITIAL_CIRCLE_LEGEND_WIDTH
|
|
383
|
+
: Math.min(legendWidth, INITIAL_CIRCLE_LEGEND_WIDTH);
|
|
384
|
+
const radius = Math.max((width - LEGEND_MARGIN_X) / 2, 0);
|
|
385
|
+
extend(state.circleLegend, { visible: true, width, radius });
|
|
386
|
+
},
|
|
387
|
+
setLegendActiveState({ state }, { name, active }) {
|
|
388
|
+
const { data } = state.legend;
|
|
389
|
+
const model = data.find(({ label }) => label === name);
|
|
390
|
+
model.active = active;
|
|
391
|
+
this.notify(state, 'legend');
|
|
392
|
+
},
|
|
393
|
+
setAllLegendActiveState({ state }, active) {
|
|
394
|
+
state.legend.data.forEach((datum) => {
|
|
395
|
+
datum.active = active;
|
|
396
|
+
});
|
|
397
|
+
this.notify(state, 'legend');
|
|
398
|
+
},
|
|
399
|
+
setLegendCheckedState({ state }, { name, checked }) {
|
|
400
|
+
const model = state.legend.data.find(({ label }) => label === name);
|
|
401
|
+
model.checked = checked;
|
|
402
|
+
this.notify(state, 'legend');
|
|
403
|
+
},
|
|
404
|
+
updateLegendColor({ state }) {
|
|
405
|
+
const { legend: legendData, series } = state;
|
|
406
|
+
const data = getLegendDataAppliedTheme(legendData.data, series);
|
|
407
|
+
extend(state.legend, { data });
|
|
408
|
+
},
|
|
409
|
+
updateLegendIcon({ state }) {
|
|
410
|
+
const { legend: legendData, series } = state;
|
|
411
|
+
const data = legendData.data.reduce((acc, cur) => {
|
|
412
|
+
var _a;
|
|
413
|
+
if (cur.chartType === 'scatter' && ((_a = series.scatter) === null || _a === void 0 ? void 0 : _a.data)) {
|
|
414
|
+
const model = series.scatter.data.find(({ name }) => name === cur.label);
|
|
415
|
+
const iconType = model ? model.iconType : cur.iconType;
|
|
416
|
+
return [...acc, Object.assign(Object.assign({}, cur), { iconType })];
|
|
417
|
+
}
|
|
418
|
+
return [...acc, cur];
|
|
419
|
+
}, []);
|
|
420
|
+
extend(state.legend, { data });
|
|
421
|
+
},
|
|
422
|
+
updateNestedPieChartLegend({ state }) {
|
|
423
|
+
const { legend: legendData, nestedPieSeries } = state;
|
|
424
|
+
extend(state.legend, {
|
|
425
|
+
data: getLegendDataAppliedTheme(legendData.data, nestedPieSeries),
|
|
426
|
+
});
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
observe: {
|
|
430
|
+
updateLegendLayout() {
|
|
431
|
+
this.dispatch('setLegendLayout');
|
|
432
|
+
},
|
|
433
|
+
},
|
|
434
|
+
};
|
|
435
|
+
export default legend;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
function findRootName(rawSeries, seriesIndex, parentName) {
|
|
2
|
+
var _a, _b;
|
|
3
|
+
const item = (_a = rawSeries.pie) === null || _a === void 0 ? void 0 : _a[seriesIndex].data.find(({ name }) => name === parentName);
|
|
4
|
+
return ((_b = item) === null || _b === void 0 ? void 0 : _b.parentName) ? findRootName(rawSeries, seriesIndex - 1, item.parentName) : parentName;
|
|
5
|
+
}
|
|
6
|
+
const nestedPieSeriesData = {
|
|
7
|
+
name: 'seriesData',
|
|
8
|
+
state: () => ({
|
|
9
|
+
nestedPieSeries: {},
|
|
10
|
+
}),
|
|
11
|
+
action: {
|
|
12
|
+
setNestedPieSeriesData({ state, initStoreState }) {
|
|
13
|
+
const { theme, disabledSeries } = state;
|
|
14
|
+
const rawSeries = initStoreState.series;
|
|
15
|
+
const newSeriesData = {};
|
|
16
|
+
const colorMap = {};
|
|
17
|
+
rawSeries.pie.forEach(({ name: alias, data }, seriesIndex) => {
|
|
18
|
+
const { colors } = theme.series.pie[alias];
|
|
19
|
+
const colorList = [];
|
|
20
|
+
const originSeriesData = data.map((m, index) => {
|
|
21
|
+
var _a;
|
|
22
|
+
const { parentName, name: dataName } = m;
|
|
23
|
+
const color = parentName && seriesIndex ? colorMap[parentName] : (_a = colors) === null || _a === void 0 ? void 0 : _a[index];
|
|
24
|
+
colorList.push(color);
|
|
25
|
+
colorMap[dataName] = color;
|
|
26
|
+
const rootParentName = parentName && seriesIndex
|
|
27
|
+
? findRootName(rawSeries, seriesIndex - 1, parentName)
|
|
28
|
+
: dataName;
|
|
29
|
+
return Object.assign(Object.assign({}, m), { data: m.data, rootParentName,
|
|
30
|
+
color });
|
|
31
|
+
});
|
|
32
|
+
newSeriesData[alias] = {
|
|
33
|
+
data: originSeriesData.filter(({ rootParentName }) => {
|
|
34
|
+
return !disabledSeries.includes(rootParentName);
|
|
35
|
+
}),
|
|
36
|
+
colors: colorList,
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
state.nestedPieSeries = newSeriesData;
|
|
40
|
+
this.dispatch('updateNestedPieChartLegend');
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
observe: {
|
|
44
|
+
updateNestedPieSeriesData() {
|
|
45
|
+
this.dispatch('setNestedPieSeriesData');
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
export default nestedPieSeriesData;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { deepCopy, deepMergedCopy } from "../helpers/utils";
|
|
2
|
+
function getOptionsBySize(size, options) {
|
|
3
|
+
var _a;
|
|
4
|
+
const rules = (_a = options.responsive) === null || _a === void 0 ? void 0 : _a.rules;
|
|
5
|
+
return Array.isArray(rules)
|
|
6
|
+
? rules.reduce((acc, cur) => {
|
|
7
|
+
return cur.condition(size) ? deepMergedCopy(acc, cur.options) : acc;
|
|
8
|
+
}, options)
|
|
9
|
+
: options;
|
|
10
|
+
}
|
|
11
|
+
function getSize(usingContainerSize, containerSize, chartSize) {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
const { width: usingContainerWidth, height: usingContainerHeight } = usingContainerSize;
|
|
14
|
+
return {
|
|
15
|
+
width: usingContainerWidth ? containerSize.width : (_a = chartSize) === null || _a === void 0 ? void 0 : _a.width,
|
|
16
|
+
height: usingContainerHeight ? containerSize.height : (_b = chartSize) === null || _b === void 0 ? void 0 : _b.height,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const optionsData = {
|
|
20
|
+
name: 'options',
|
|
21
|
+
state: ({ options }) => ({
|
|
22
|
+
originalOptions: deepCopy(options),
|
|
23
|
+
options,
|
|
24
|
+
}),
|
|
25
|
+
action: {
|
|
26
|
+
setOptions({ state }) {
|
|
27
|
+
const { width, height } = state.chart;
|
|
28
|
+
if (width < 0 || height < 0) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
state.options = getOptionsBySize({ width, height }, state.originalOptions);
|
|
32
|
+
},
|
|
33
|
+
initOptions({ initStoreState, state }, { options, containerSize }) {
|
|
34
|
+
initStoreState.options = options;
|
|
35
|
+
state.originalOptions = deepCopy(options);
|
|
36
|
+
const { usingContainerSize, originalOptions } = state;
|
|
37
|
+
const size = getSize(usingContainerSize, containerSize, {
|
|
38
|
+
width: originalOptions.chart.width,
|
|
39
|
+
height: originalOptions.chart.height,
|
|
40
|
+
});
|
|
41
|
+
this.dispatch('setChartSize', size);
|
|
42
|
+
},
|
|
43
|
+
updateOptions({ state, initStoreState }, { options, containerSize }) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
initStoreState.options = deepMergedCopy(initStoreState.options, options);
|
|
46
|
+
state.originalOptions = deepMergedCopy(state.originalOptions, options);
|
|
47
|
+
const { usingContainerSize, originalOptions } = state;
|
|
48
|
+
const size = getSize(usingContainerSize, containerSize, {
|
|
49
|
+
width: (_a = originalOptions.chart) === null || _a === void 0 ? void 0 : _a.width,
|
|
50
|
+
height: (_b = originalOptions.chart) === null || _b === void 0 ? void 0 : _b.height,
|
|
51
|
+
});
|
|
52
|
+
this.dispatch('setChartSize', size);
|
|
53
|
+
this.dispatch('initThemeState');
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
observe: {
|
|
57
|
+
updateOptions() {
|
|
58
|
+
this.dispatch('setOptions');
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
export default optionsData;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { extend } from "./store";
|
|
2
|
+
import { rgba } from "../helpers/color";
|
|
3
|
+
import { isRangeValue } from "../helpers/range";
|
|
4
|
+
import { isString } from "../helpers/utils";
|
|
5
|
+
import { isExistPlotId } from "../helpers/plot";
|
|
6
|
+
function getOverlappingRange(ranges) {
|
|
7
|
+
const overlappingRanges = ranges.reduce((acc, { range }) => {
|
|
8
|
+
const [accStart, accEnd] = acc;
|
|
9
|
+
const [start, end] = range;
|
|
10
|
+
return [Math.min(accStart, start), Math.max(accEnd, end)];
|
|
11
|
+
}, [Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER]);
|
|
12
|
+
return {
|
|
13
|
+
range: overlappingRanges,
|
|
14
|
+
color: ranges[0].color,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function getCategoryIndex(value, categories) {
|
|
18
|
+
return categories.findIndex((category) => category === String(value));
|
|
19
|
+
}
|
|
20
|
+
function getValidValue(value, categories, isDateType = false) {
|
|
21
|
+
if (isDateType) {
|
|
22
|
+
return Number(new Date(value));
|
|
23
|
+
}
|
|
24
|
+
if (isString(value)) {
|
|
25
|
+
return getCategoryIndex(value, categories);
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
function makePlotLines(categories, isDateType, plotLines = []) {
|
|
30
|
+
return plotLines.map(({ value, color, opacity }) => ({
|
|
31
|
+
value: getValidValue(value, categories, isDateType),
|
|
32
|
+
color: rgba(color, opacity),
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
function makePlotBands(categories, isDateType, plotBands = []) {
|
|
36
|
+
return plotBands.flatMap(({ range, mergeOverlappingRanges = false, color: bgColor, opacity }) => {
|
|
37
|
+
const color = rgba(bgColor, opacity);
|
|
38
|
+
const rangeArray = (isRangeValue(range[0]) ? range : [range]);
|
|
39
|
+
const ranges = rangeArray.map((rangeData) => ({
|
|
40
|
+
range: rangeData.map((value) => getValidValue(value, categories, isDateType)),
|
|
41
|
+
color,
|
|
42
|
+
}));
|
|
43
|
+
return mergeOverlappingRanges ? getOverlappingRange(ranges) : ranges;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const plot = {
|
|
47
|
+
name: 'plot',
|
|
48
|
+
state: ({ options }) => {
|
|
49
|
+
var _a, _b, _c;
|
|
50
|
+
return ({
|
|
51
|
+
plot: {
|
|
52
|
+
visible: (_c = (_b = (_a = options) === null || _a === void 0 ? void 0 : _a.plot) === null || _b === void 0 ? void 0 : _b.visible, (_c !== null && _c !== void 0 ? _c : true)),
|
|
53
|
+
lines: [],
|
|
54
|
+
bands: [],
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
action: {
|
|
59
|
+
setPlot({ state }) {
|
|
60
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
61
|
+
const { series, options } = state;
|
|
62
|
+
if (!(series.area || series.line)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const rawCategories = state.rawCategories;
|
|
66
|
+
const lineAreaOptions = options;
|
|
67
|
+
const lines = makePlotLines(rawCategories, !!((_b = (_a = options) === null || _a === void 0 ? void 0 : _a.xAxis) === null || _b === void 0 ? void 0 : _b.date), (_d = (_c = lineAreaOptions) === null || _c === void 0 ? void 0 : _c.plot) === null || _d === void 0 ? void 0 : _d.lines);
|
|
68
|
+
const bands = makePlotBands(rawCategories, !!((_f = (_e = options) === null || _e === void 0 ? void 0 : _e.xAxis) === null || _f === void 0 ? void 0 : _f.date), (_h = (_g = lineAreaOptions) === null || _g === void 0 ? void 0 : _g.plot) === null || _h === void 0 ? void 0 : _h.bands);
|
|
69
|
+
extend(state.plot, { lines, bands });
|
|
70
|
+
},
|
|
71
|
+
addPlotLine({ state }, { data }) {
|
|
72
|
+
var _a, _b, _c;
|
|
73
|
+
const lines = (_c = (_b = (_a = state.options) === null || _a === void 0 ? void 0 : _a.plot) === null || _b === void 0 ? void 0 : _b.lines, (_c !== null && _c !== void 0 ? _c : []));
|
|
74
|
+
if (!isExistPlotId(lines, data)) {
|
|
75
|
+
this.dispatch('updateOptions', { options: { plot: { lines: [...lines, data] } } });
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
addPlotBand({ state }, { data }) {
|
|
79
|
+
var _a, _b, _c;
|
|
80
|
+
const bands = (_c = (_b = (_a = state.options) === null || _a === void 0 ? void 0 : _a.plot) === null || _b === void 0 ? void 0 : _b.bands, (_c !== null && _c !== void 0 ? _c : []));
|
|
81
|
+
if (!isExistPlotId(bands, data)) {
|
|
82
|
+
this.dispatch('updateOptions', { options: { plot: { bands: [...bands, data] } } });
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
removePlotLine({ state }, { id }) {
|
|
86
|
+
var _a, _b, _c;
|
|
87
|
+
const lines = (_c = (_b = (_a = state.options) === null || _a === void 0 ? void 0 : _a.plot) === null || _b === void 0 ? void 0 : _b.lines, (_c !== null && _c !== void 0 ? _c : [])).filter(({ id: lineId }) => lineId !== id);
|
|
88
|
+
this.dispatch('updateOptions', { options: { plot: { lines } } });
|
|
89
|
+
},
|
|
90
|
+
removePlotBand({ state }, { id }) {
|
|
91
|
+
var _a, _b, _c;
|
|
92
|
+
const bands = (_c = (_b = (_a = state.options) === null || _a === void 0 ? void 0 : _a.plot) === null || _b === void 0 ? void 0 : _b.bands, (_c !== null && _c !== void 0 ? _c : [])).filter(({ id: bandId }) => bandId !== id);
|
|
93
|
+
this.dispatch('updateOptions', { options: { plot: { bands } } });
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
observe: {
|
|
97
|
+
updatePlot() {
|
|
98
|
+
this.dispatch('setPlot');
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
export default plot;
|