@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,67 @@
|
|
|
1
|
+
import { Options, Series, ChartOptionsUsingYAxis, Axes, ViewAxisLabel, RotationLabelData, InitAxisData, Categories, DefaultRadialAxisData, RadiusInfo, ScaleData } from "../../types/store/store";
|
|
2
|
+
import { AxisTitle, Rect } from "../../types/options";
|
|
3
|
+
import { Theme } from "../../types/theme";
|
|
4
|
+
import { AxisDataParams } from "../store/axes";
|
|
5
|
+
export declare function getAutoAdjustingInterval(count: number, axisWidth: number, categories?: string[]): number;
|
|
6
|
+
export declare function isLabelAxisOnYAxis({ series, options, categories, }: {
|
|
7
|
+
series: Series;
|
|
8
|
+
options?: Options;
|
|
9
|
+
categories?: Categories;
|
|
10
|
+
}): boolean;
|
|
11
|
+
export declare function hasBoxTypeSeries(series: Series): boolean;
|
|
12
|
+
export declare function isPointOnColumn(series: Series, options: Options): boolean;
|
|
13
|
+
export declare function isSeriesUsingRadialAxes(series: Series): boolean;
|
|
14
|
+
export declare function getAxisName(labelAxisOnYAxis: boolean, series: Series): {
|
|
15
|
+
valueAxisName: string;
|
|
16
|
+
labelAxisName: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function getSizeKey(labelAxisOnYAxis: boolean): {
|
|
19
|
+
valueSizeKey: string;
|
|
20
|
+
labelSizeKey: string;
|
|
21
|
+
};
|
|
22
|
+
export declare function getLimitOnAxis(labels: string[]): {
|
|
23
|
+
min: number;
|
|
24
|
+
max: number;
|
|
25
|
+
};
|
|
26
|
+
export declare function hasSecondaryYAxis(options: ChartOptionsUsingYAxis): boolean;
|
|
27
|
+
export declare function getYAxisOption(options: ChartOptionsUsingYAxis): {
|
|
28
|
+
yAxis: any;
|
|
29
|
+
secondaryYAxis: any;
|
|
30
|
+
};
|
|
31
|
+
export declare function getValueAxisName(options: ChartOptionsUsingYAxis, seriesName: string, valueAxisName: string): string;
|
|
32
|
+
export declare function getValueAxisNames(options: Options, valueAxisName: string): string[];
|
|
33
|
+
export declare function getAxisTheme(theme: Theme, name: string): any;
|
|
34
|
+
export declare function hasAxesLayoutChanged(previousAxes: Axes, currentAxes: Axes): boolean;
|
|
35
|
+
export declare function getRotatableOption(options: Options): boolean;
|
|
36
|
+
declare type ViewAxisLabelParam = {
|
|
37
|
+
labels: string[];
|
|
38
|
+
pointOnColumn?: boolean;
|
|
39
|
+
labelDistance?: number;
|
|
40
|
+
scale?: ScaleData;
|
|
41
|
+
labelInterval: number;
|
|
42
|
+
tickDistance: number;
|
|
43
|
+
tickInterval: number;
|
|
44
|
+
tickCount: number;
|
|
45
|
+
};
|
|
46
|
+
export declare function getViewAxisLabels(axisData: ViewAxisLabelParam, axisSize: number): ViewAxisLabel[];
|
|
47
|
+
export declare function makeTitleOption(title?: AxisTitle): {
|
|
48
|
+
text: string;
|
|
49
|
+
offsetX: number;
|
|
50
|
+
offsetY: number;
|
|
51
|
+
} | undefined;
|
|
52
|
+
export declare function getAxisFormatter(options: ChartOptionsUsingYAxis, axisName: string): any;
|
|
53
|
+
export declare function getLabelsAppliedFormatter(labels: string[], options: Options, dateType: boolean, axisName: string): any[];
|
|
54
|
+
export declare function makeRotationData(maxLabelWidth: number, maxLabelHeight: number, distance: number, rotatable: boolean, axisLayout: Rect): Required<RotationLabelData>;
|
|
55
|
+
export declare function getMaxLabelSize(labels: string[], xMargin: number, font?: string): {
|
|
56
|
+
maxLabelWidth: number;
|
|
57
|
+
maxLabelHeight: number;
|
|
58
|
+
};
|
|
59
|
+
export declare function getLabelXMargin(axisName: string, options: Options): number;
|
|
60
|
+
export declare function getInitAxisIntervalData(isLabelAxis: boolean, params: AxisDataParams): InitAxisData;
|
|
61
|
+
export declare function getDefaultRadialAxisData(options: Options, plot: Rect, maxLabelWidth?: number, maxLabelHeight?: number, isLabelOnVerticalAxis?: boolean): DefaultRadialAxisData;
|
|
62
|
+
export declare function getRadiusInfo(axisSize: number, radiusRange?: {
|
|
63
|
+
inner?: number | string;
|
|
64
|
+
outer?: number | string;
|
|
65
|
+
}, count?: number): RadiusInfo;
|
|
66
|
+
export declare function isDateType(options: Options, axisName: string): boolean;
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { AxisType } from "../component/axis";
|
|
2
|
+
import { divisors, makeTickPixelPositions, getTextHeight, getTextWidth, } from "./calculator";
|
|
3
|
+
import { range, isString, isUndefined, isNumber, calculateSizeWithPercentString, includes, } from "./utils";
|
|
4
|
+
import { ANGLE_CANDIDATES, calculateRotatedWidth, calculateRotatedHeight, } from "./geometric";
|
|
5
|
+
import { getDateFormat, formatDate } from "./formatDate";
|
|
6
|
+
import { calculateDegreeToRadian, DEGREE_360, DEGREE_0, initSectorOptions, getDefaultRadius, } from "./sector";
|
|
7
|
+
import { DEFAULT_LABEL_TEXT } from "../brushes/label";
|
|
8
|
+
import { getSemiCircleCenterY, getTotalAngle, isSemiCircle } from "./pieSeries";
|
|
9
|
+
import { RadialAxisType } from "../store/radialAxes";
|
|
10
|
+
function makeAdjustingIntervalInfo(blockCount, axisWidth, blockSize) {
|
|
11
|
+
let remainBlockCount;
|
|
12
|
+
let newBlockCount = Math.floor(axisWidth / blockSize);
|
|
13
|
+
let intervalInfo = null;
|
|
14
|
+
const interval = newBlockCount ? Math.floor(blockCount / newBlockCount) : blockCount;
|
|
15
|
+
if (interval > 1) {
|
|
16
|
+
// remainBlockCount : remaining block count after filling new blocks
|
|
17
|
+
// | | | | | | | | | | | | - previous block interval
|
|
18
|
+
// | | | | - new block interval
|
|
19
|
+
// |*|*| - remaining block
|
|
20
|
+
remainBlockCount = blockCount - interval * newBlockCount;
|
|
21
|
+
if (remainBlockCount >= interval) {
|
|
22
|
+
newBlockCount += Math.floor(remainBlockCount / interval);
|
|
23
|
+
remainBlockCount = remainBlockCount % interval;
|
|
24
|
+
}
|
|
25
|
+
intervalInfo = {
|
|
26
|
+
blockCount: newBlockCount,
|
|
27
|
+
remainBlockCount,
|
|
28
|
+
interval,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return intervalInfo;
|
|
32
|
+
}
|
|
33
|
+
export function getAutoAdjustingInterval(count, axisWidth, categories) {
|
|
34
|
+
var _a;
|
|
35
|
+
const autoInterval = {
|
|
36
|
+
MIN_WIDTH: 90,
|
|
37
|
+
MAX_WIDTH: 121,
|
|
38
|
+
STEP_SIZE: 5,
|
|
39
|
+
};
|
|
40
|
+
const LABEL_MARGIN = 5;
|
|
41
|
+
if ((_a = categories) === null || _a === void 0 ? void 0 : _a[0]) {
|
|
42
|
+
const categoryMinWidth = getTextWidth(categories[0]);
|
|
43
|
+
if (categoryMinWidth < axisWidth / count - LABEL_MARGIN) {
|
|
44
|
+
return 1;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
let candidates = [];
|
|
48
|
+
divisors(count).forEach((interval) => {
|
|
49
|
+
const intervalWidth = (interval / count) * axisWidth;
|
|
50
|
+
if (intervalWidth >= autoInterval.MIN_WIDTH && intervalWidth <= autoInterval.MAX_WIDTH) {
|
|
51
|
+
candidates.push({ interval, blockCount: Math.floor(count / interval), remainBlockCount: 0 });
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
if (!candidates.length) {
|
|
55
|
+
const blockSizeRange = range(autoInterval.MIN_WIDTH, autoInterval.MAX_WIDTH, autoInterval.STEP_SIZE);
|
|
56
|
+
candidates = blockSizeRange.reduce((acc, blockSize) => {
|
|
57
|
+
const candidate = makeAdjustingIntervalInfo(count, axisWidth, blockSize);
|
|
58
|
+
return candidate ? [...acc, candidate] : acc;
|
|
59
|
+
}, []);
|
|
60
|
+
}
|
|
61
|
+
let tickInterval = 1;
|
|
62
|
+
if (candidates.length) {
|
|
63
|
+
const candidate = candidates.reduce((acc, cur) => (cur.blockCount > acc.blockCount ? cur : acc), { blockCount: 0, interval: 1 });
|
|
64
|
+
tickInterval = candidate.interval;
|
|
65
|
+
}
|
|
66
|
+
return tickInterval;
|
|
67
|
+
}
|
|
68
|
+
export function isLabelAxisOnYAxis({ series, options, categories, }) {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
return (!!series.bar ||
|
|
71
|
+
!!series.radialBar ||
|
|
72
|
+
(!!series.gauge && Array.isArray(categories) && !categories.length) ||
|
|
73
|
+
(!!series.bullet && !((_b = (_a = options) === null || _a === void 0 ? void 0 : _a.series) === null || _b === void 0 ? void 0 : _b.vertical)));
|
|
74
|
+
}
|
|
75
|
+
export function hasBoxTypeSeries(series) {
|
|
76
|
+
return !!series.column || !!series.bar || !!series.boxPlot || !!series.bullet;
|
|
77
|
+
}
|
|
78
|
+
export function isPointOnColumn(series, options) {
|
|
79
|
+
var _a;
|
|
80
|
+
if (hasBoxTypeSeries(series)) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
if (series.line || series.area) {
|
|
84
|
+
return Boolean((_a = options.xAxis) === null || _a === void 0 ? void 0 : _a.pointOnColumn);
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
export function isSeriesUsingRadialAxes(series) {
|
|
89
|
+
return !!series.radar || !!series.radialBar || !!series.gauge;
|
|
90
|
+
}
|
|
91
|
+
function getAxisNameUsingRadialAxes(labelAxisOnYAxis) {
|
|
92
|
+
return {
|
|
93
|
+
valueAxisName: labelAxisOnYAxis ? 'circularAxis' : 'verticalAxis',
|
|
94
|
+
labelAxisName: labelAxisOnYAxis ? 'verticalAxis' : 'circularAxis',
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export function getAxisName(labelAxisOnYAxis, series) {
|
|
98
|
+
return isSeriesUsingRadialAxes(series)
|
|
99
|
+
? getAxisNameUsingRadialAxes(labelAxisOnYAxis)
|
|
100
|
+
: {
|
|
101
|
+
valueAxisName: labelAxisOnYAxis ? 'xAxis' : 'yAxis',
|
|
102
|
+
labelAxisName: labelAxisOnYAxis ? 'yAxis' : 'xAxis',
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export function getSizeKey(labelAxisOnYAxis) {
|
|
106
|
+
return {
|
|
107
|
+
valueSizeKey: labelAxisOnYAxis ? 'width' : 'height',
|
|
108
|
+
labelSizeKey: labelAxisOnYAxis ? 'height' : 'width',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export function getLimitOnAxis(labels) {
|
|
112
|
+
const values = labels.map((label) => Number(label));
|
|
113
|
+
return {
|
|
114
|
+
min: Math.min(...values),
|
|
115
|
+
max: Math.max(...values),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export function hasSecondaryYAxis(options) {
|
|
119
|
+
var _a;
|
|
120
|
+
return Array.isArray((_a = options) === null || _a === void 0 ? void 0 : _a.yAxis) && options.yAxis.length === 2;
|
|
121
|
+
}
|
|
122
|
+
export function getYAxisOption(options) {
|
|
123
|
+
var _a;
|
|
124
|
+
const secondaryYAxis = hasSecondaryYAxis(options);
|
|
125
|
+
return {
|
|
126
|
+
yAxis: secondaryYAxis ? options.yAxis[0] : (_a = options) === null || _a === void 0 ? void 0 : _a.yAxis,
|
|
127
|
+
secondaryYAxis: secondaryYAxis ? options.yAxis[1] : null,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
export function getValueAxisName(options, seriesName, valueAxisName) {
|
|
131
|
+
var _a;
|
|
132
|
+
const { secondaryYAxis } = getYAxisOption(options);
|
|
133
|
+
return ((_a = secondaryYAxis) === null || _a === void 0 ? void 0 : _a.chartType) === seriesName ? 'secondaryYAxis' : valueAxisName;
|
|
134
|
+
}
|
|
135
|
+
export function getValueAxisNames(options, valueAxisName) {
|
|
136
|
+
if (includes([AxisType.X, AxisType.CIRCULAR, AxisType.VERTICAL], valueAxisName)) {
|
|
137
|
+
return [valueAxisName];
|
|
138
|
+
}
|
|
139
|
+
const optionsUsingYAxis = options;
|
|
140
|
+
const { yAxis, secondaryYAxis } = getYAxisOption(optionsUsingYAxis);
|
|
141
|
+
return secondaryYAxis
|
|
142
|
+
? [yAxis.chartType, secondaryYAxis.chartType].map((seriesName, index) => seriesName
|
|
143
|
+
? getValueAxisName(optionsUsingYAxis, seriesName, valueAxisName)
|
|
144
|
+
: ['yAxis', 'secondaryYAxis'][index])
|
|
145
|
+
: [valueAxisName];
|
|
146
|
+
}
|
|
147
|
+
export function getAxisTheme(theme, name) {
|
|
148
|
+
const { xAxis, yAxis, circularAxis } = theme;
|
|
149
|
+
let axisTheme;
|
|
150
|
+
if (name === AxisType.X) {
|
|
151
|
+
axisTheme = xAxis;
|
|
152
|
+
}
|
|
153
|
+
else if (Array.isArray(yAxis)) {
|
|
154
|
+
axisTheme = name === AxisType.Y ? yAxis[0] : yAxis[1];
|
|
155
|
+
}
|
|
156
|
+
else if (name === RadialAxisType.CIRCULAR) {
|
|
157
|
+
axisTheme = circularAxis;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
axisTheme = yAxis;
|
|
161
|
+
}
|
|
162
|
+
return axisTheme;
|
|
163
|
+
}
|
|
164
|
+
function getRotationDegree(distance, labelWidth, labelHeight, axisLayout) {
|
|
165
|
+
let degree = 0;
|
|
166
|
+
ANGLE_CANDIDATES.every((angle) => {
|
|
167
|
+
const compareWidth = calculateRotatedWidth(angle, labelWidth, labelHeight);
|
|
168
|
+
degree = angle;
|
|
169
|
+
return compareWidth > distance || compareWidth / 2 > axisLayout.x;
|
|
170
|
+
});
|
|
171
|
+
return distance < labelWidth || labelWidth / 2 > axisLayout.x ? degree : 0;
|
|
172
|
+
}
|
|
173
|
+
function hasYAxisMaxLabelLengthChanged(previousAxes, currentAxes, field) {
|
|
174
|
+
var _a, _b;
|
|
175
|
+
const prevYAxis = previousAxes[field];
|
|
176
|
+
const yAxis = currentAxes[field];
|
|
177
|
+
if (!prevYAxis && !yAxis) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
return ((_a = prevYAxis) === null || _a === void 0 ? void 0 : _a.maxLabelWidth) !== ((_b = yAxis) === null || _b === void 0 ? void 0 : _b.maxLabelWidth);
|
|
181
|
+
}
|
|
182
|
+
function hasYAxisTypeMaxLabelChanged(previousAxes, currentAxes) {
|
|
183
|
+
return (hasYAxisMaxLabelLengthChanged(previousAxes, currentAxes, 'yAxis') ||
|
|
184
|
+
hasYAxisMaxLabelLengthChanged(previousAxes, currentAxes, 'secondaryYAxis'));
|
|
185
|
+
}
|
|
186
|
+
function hasXAxisSizeChanged(previousAxes, currentAxes) {
|
|
187
|
+
const { maxHeight: prevMaxHeight } = previousAxes.xAxis;
|
|
188
|
+
const { maxHeight } = currentAxes.xAxis;
|
|
189
|
+
return prevMaxHeight !== maxHeight;
|
|
190
|
+
}
|
|
191
|
+
export function hasAxesLayoutChanged(previousAxes, currentAxes) {
|
|
192
|
+
return (hasYAxisTypeMaxLabelChanged(previousAxes, currentAxes) ||
|
|
193
|
+
hasXAxisSizeChanged(previousAxes, currentAxes));
|
|
194
|
+
}
|
|
195
|
+
export function getRotatableOption(options) {
|
|
196
|
+
var _a, _b, _c, _d;
|
|
197
|
+
return _d = (_c = (_b = (_a = options) === null || _a === void 0 ? void 0 : _a.xAxis) === null || _b === void 0 ? void 0 : _b.label) === null || _c === void 0 ? void 0 : _c.rotatable, (_d !== null && _d !== void 0 ? _d : true);
|
|
198
|
+
}
|
|
199
|
+
export function getViewAxisLabels(axisData, axisSize) {
|
|
200
|
+
var _a, _b, _c, _d;
|
|
201
|
+
const { labels, pointOnColumn, labelDistance, tickDistance, labelInterval, tickInterval, tickCount, scale, } = axisData;
|
|
202
|
+
let axisSizeAppliedRatio = axisSize;
|
|
203
|
+
let additional = 0;
|
|
204
|
+
let labelAdjustment = 0;
|
|
205
|
+
if (scale) {
|
|
206
|
+
const sizeRatio = (_b = (_a = scale) === null || _a === void 0 ? void 0 : _a.sizeRatio, (_b !== null && _b !== void 0 ? _b : 1));
|
|
207
|
+
const positionRatio = (_d = (_c = scale) === null || _c === void 0 ? void 0 : _c.positionRatio, (_d !== null && _d !== void 0 ? _d : 0));
|
|
208
|
+
axisSizeAppliedRatio = axisSize * sizeRatio;
|
|
209
|
+
additional = axisSize * positionRatio;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
const interval = labelInterval === tickInterval ? labelInterval : 1;
|
|
213
|
+
labelAdjustment = pointOnColumn ? ((labelDistance !== null && labelDistance !== void 0 ? labelDistance : tickDistance * interval)) / 2 : 0;
|
|
214
|
+
}
|
|
215
|
+
const relativePositions = makeTickPixelPositions(axisSizeAppliedRatio, tickCount, additional);
|
|
216
|
+
return labels.reduce((acc, text, index) => {
|
|
217
|
+
const offsetPos = relativePositions[index] + labelAdjustment;
|
|
218
|
+
const needRender = !(index % labelInterval) && offsetPos <= axisSize;
|
|
219
|
+
return needRender ? [...acc, { offsetPos, text }] : acc;
|
|
220
|
+
}, []);
|
|
221
|
+
}
|
|
222
|
+
export function makeTitleOption(title) {
|
|
223
|
+
if (isUndefined(title)) {
|
|
224
|
+
return title;
|
|
225
|
+
}
|
|
226
|
+
const defaultOption = { text: '', offsetX: 0, offsetY: 0 };
|
|
227
|
+
return isString(title) ? Object.assign(Object.assign({}, defaultOption), { text: title }) : Object.assign(Object.assign({}, defaultOption), title);
|
|
228
|
+
}
|
|
229
|
+
export function getAxisFormatter(options, axisName) {
|
|
230
|
+
var _a, _b, _c;
|
|
231
|
+
const axisOptions = Object.assign(Object.assign({}, getYAxisOption(options)), { xAxis: options.xAxis });
|
|
232
|
+
return _c = (_b = (_a = axisOptions[axisName]) === null || _a === void 0 ? void 0 : _a.label) === null || _b === void 0 ? void 0 : _b.formatter, (_c !== null && _c !== void 0 ? _c : ((value) => value));
|
|
233
|
+
}
|
|
234
|
+
export function getLabelsAppliedFormatter(labels, options, dateType, axisName) {
|
|
235
|
+
var _a, _b;
|
|
236
|
+
const dateFormatter = getDateFormat((_b = (_a = options) === null || _a === void 0 ? void 0 : _a[axisName]) === null || _b === void 0 ? void 0 : _b.date);
|
|
237
|
+
const formattedLabels = dateType && dateFormatter
|
|
238
|
+
? labels.map((label) => formatDate(dateFormatter, new Date(label)))
|
|
239
|
+
: labels;
|
|
240
|
+
const formatter = getAxisFormatter(options, axisName);
|
|
241
|
+
return formattedLabels.map((label, index) => formatter(label, { index, labels, axisName }));
|
|
242
|
+
}
|
|
243
|
+
export function makeRotationData(maxLabelWidth, maxLabelHeight, distance, rotatable, axisLayout) {
|
|
244
|
+
const degree = getRotationDegree(distance, maxLabelWidth, maxLabelHeight, axisLayout);
|
|
245
|
+
if (!rotatable || degree === 0) {
|
|
246
|
+
return {
|
|
247
|
+
needRotateLabel: false,
|
|
248
|
+
radian: 0,
|
|
249
|
+
rotationHeight: maxLabelHeight,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
needRotateLabel: degree > 0,
|
|
254
|
+
radian: calculateDegreeToRadian(degree, 0),
|
|
255
|
+
rotationHeight: calculateRotatedHeight(degree, maxLabelWidth, maxLabelHeight),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
export function getMaxLabelSize(labels, xMargin, font = DEFAULT_LABEL_TEXT) {
|
|
259
|
+
const maxLengthLabel = labels.reduce((acc, cur) => (acc.length > cur.length ? acc : cur), '');
|
|
260
|
+
return {
|
|
261
|
+
maxLabelWidth: getTextWidth(maxLengthLabel, font) + xMargin,
|
|
262
|
+
maxLabelHeight: getTextHeight(maxLengthLabel, font),
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
export function getLabelXMargin(axisName, options) {
|
|
266
|
+
var _a, _b, _c, _d;
|
|
267
|
+
if (axisName === 'xAxis') {
|
|
268
|
+
return 0;
|
|
269
|
+
}
|
|
270
|
+
const axisOptions = getYAxisOption(options);
|
|
271
|
+
return Math.abs((_d = (_c = (_b = (_a = axisOptions) === null || _a === void 0 ? void 0 : _a[axisName]) === null || _b === void 0 ? void 0 : _b.label) === null || _c === void 0 ? void 0 : _c.margin, (_d !== null && _d !== void 0 ? _d : 0)));
|
|
272
|
+
}
|
|
273
|
+
export function getInitAxisIntervalData(isLabelAxis, params) {
|
|
274
|
+
var _a, _b, _c, _d, _e, _f;
|
|
275
|
+
const { axis, categories, layout, isCoordinateTypeChart } = params;
|
|
276
|
+
const tickInterval = (_b = (_a = axis) === null || _a === void 0 ? void 0 : _a.tick) === null || _b === void 0 ? void 0 : _b.interval;
|
|
277
|
+
const labelInterval = (_d = (_c = axis) === null || _c === void 0 ? void 0 : _c.label) === null || _d === void 0 ? void 0 : _d.interval;
|
|
278
|
+
const existIntervalOptions = isNumber(tickInterval) || isNumber(labelInterval);
|
|
279
|
+
const needAdjustInterval = isLabelAxis &&
|
|
280
|
+
!isNumber((_f = (_e = axis) === null || _e === void 0 ? void 0 : _e.scale) === null || _f === void 0 ? void 0 : _f.stepSize) &&
|
|
281
|
+
!params.shift &&
|
|
282
|
+
!existIntervalOptions &&
|
|
283
|
+
!isCoordinateTypeChart;
|
|
284
|
+
const initTickInterval = needAdjustInterval ? getInitTickInterval(categories, layout) : 1;
|
|
285
|
+
const initLabelInterval = needAdjustInterval ? initTickInterval : 1;
|
|
286
|
+
const axisData = {
|
|
287
|
+
tickInterval: (tickInterval !== null && tickInterval !== void 0 ? tickInterval : initTickInterval),
|
|
288
|
+
labelInterval: (labelInterval !== null && labelInterval !== void 0 ? labelInterval : initLabelInterval),
|
|
289
|
+
};
|
|
290
|
+
return axisData;
|
|
291
|
+
}
|
|
292
|
+
function getInitTickInterval(categories, layout) {
|
|
293
|
+
if (!categories || !layout) {
|
|
294
|
+
return 1;
|
|
295
|
+
}
|
|
296
|
+
const { width } = layout.xAxis;
|
|
297
|
+
const count = categories.length;
|
|
298
|
+
return getAutoAdjustingInterval(count, width, categories);
|
|
299
|
+
}
|
|
300
|
+
export function getDefaultRadialAxisData(options, plot, maxLabelWidth = 0, maxLabelHeight = 0, isLabelOnVerticalAxis = false) {
|
|
301
|
+
var _a;
|
|
302
|
+
const centerX = plot.width / 2;
|
|
303
|
+
if (isLabelOnVerticalAxis) {
|
|
304
|
+
const { startAngle, endAngle, clockwise } = initSectorOptions((_a = options) === null || _a === void 0 ? void 0 : _a.series);
|
|
305
|
+
const isSemiCircular = isSemiCircle(clockwise, startAngle, endAngle);
|
|
306
|
+
return {
|
|
307
|
+
isSemiCircular,
|
|
308
|
+
axisSize: getDefaultRadius(plot, isSemiCircular, maxLabelWidth, maxLabelHeight),
|
|
309
|
+
centerX,
|
|
310
|
+
centerY: isSemiCircular ? getSemiCircleCenterY(plot.height, clockwise) : plot.height / 2,
|
|
311
|
+
totalAngle: getTotalAngle(clockwise, startAngle, endAngle),
|
|
312
|
+
drawingStartAngle: startAngle,
|
|
313
|
+
clockwise,
|
|
314
|
+
startAngle,
|
|
315
|
+
endAngle,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
isSemiCircular: false,
|
|
320
|
+
axisSize: getDefaultRadius(plot, false, maxLabelWidth, maxLabelHeight),
|
|
321
|
+
centerX,
|
|
322
|
+
centerY: plot.height / 2,
|
|
323
|
+
totalAngle: DEGREE_360,
|
|
324
|
+
drawingStartAngle: DEGREE_0,
|
|
325
|
+
clockwise: true,
|
|
326
|
+
startAngle: DEGREE_0,
|
|
327
|
+
endAngle: DEGREE_360,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
export function getRadiusInfo(axisSize, radiusRange, count = 1) {
|
|
331
|
+
var _a, _b, _c, _d;
|
|
332
|
+
const innerRadius = calculateSizeWithPercentString(axisSize, (_b = (_a = radiusRange) === null || _a === void 0 ? void 0 : _a.inner, (_b !== null && _b !== void 0 ? _b : 0)));
|
|
333
|
+
const outerRadius = calculateSizeWithPercentString(axisSize, (_d = (_c = radiusRange) === null || _c === void 0 ? void 0 : _c.outer, (_d !== null && _d !== void 0 ? _d : axisSize)));
|
|
334
|
+
return {
|
|
335
|
+
radiusRanges: makeTickPixelPositions(outerRadius - innerRadius, count, innerRadius)
|
|
336
|
+
.splice(innerRadius === 0 ? 1 : 0, count)
|
|
337
|
+
.reverse(),
|
|
338
|
+
innerRadius,
|
|
339
|
+
outerRadius,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
export function isDateType(options, axisName) {
|
|
343
|
+
var _a;
|
|
344
|
+
return !!((_a = options[axisName]) === null || _a === void 0 ? void 0 : _a.date);
|
|
345
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Nullable } from "../../types/components/series";
|
|
2
|
+
export declare function calibrateDrawingValue(value: number, min: number, max: number): number;
|
|
3
|
+
export declare function sumValuesBeforeIndex(values: number[], targetIndex: number, includeTarget?: boolean): number;
|
|
4
|
+
export declare function outsideRange(values: number[], currentIndex: number, min: number, max: number): boolean;
|
|
5
|
+
export declare function calibrateBoxStackDrawingValue(values: number[], currentIndex: number, min: number, max: number): Nullable<number>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
function limitNegative(value, min, max) {
|
|
2
|
+
let result = value;
|
|
3
|
+
if (result >= max) {
|
|
4
|
+
return 0;
|
|
5
|
+
}
|
|
6
|
+
if (max < 0) {
|
|
7
|
+
result = Math.min(value - max, 0);
|
|
8
|
+
}
|
|
9
|
+
if (value < min) {
|
|
10
|
+
result -= value - min;
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
function limitPositive(value, min, max) {
|
|
15
|
+
let result = value;
|
|
16
|
+
if (min > 0) {
|
|
17
|
+
result = Math.max(value - min, 0);
|
|
18
|
+
}
|
|
19
|
+
if (value > max) {
|
|
20
|
+
result -= value - max;
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
export function calibrateDrawingValue(value, min, max) {
|
|
25
|
+
return value < 0 ? limitNegative(value, min, max) : limitPositive(value, min, max);
|
|
26
|
+
}
|
|
27
|
+
export function sumValuesBeforeIndex(values, targetIndex, includeTarget = false) {
|
|
28
|
+
const target = values[targetIndex];
|
|
29
|
+
return values.reduce((total, value, idx) => {
|
|
30
|
+
const isBefore = includeTarget ? idx <= targetIndex : idx < targetIndex;
|
|
31
|
+
const isSameSign = value * target >= 0;
|
|
32
|
+
return isBefore && isSameSign ? total + value : total;
|
|
33
|
+
}, 0);
|
|
34
|
+
}
|
|
35
|
+
export function outsideRange(values, currentIndex, min, max) {
|
|
36
|
+
const value = values[currentIndex];
|
|
37
|
+
const totalOfIndexBefore = sumValuesBeforeIndex(values, currentIndex, false);
|
|
38
|
+
const positive = value >= 0;
|
|
39
|
+
const negative = value < 0;
|
|
40
|
+
return ((positive && totalOfIndexBefore >= max) ||
|
|
41
|
+
(negative && totalOfIndexBefore <= min) ||
|
|
42
|
+
(currentIndex === 0 && positive && value < min) ||
|
|
43
|
+
(currentIndex === 0 && negative && value > max));
|
|
44
|
+
}
|
|
45
|
+
export function calibrateBoxStackDrawingValue(values, currentIndex, min, max) {
|
|
46
|
+
const totalOfIndexBefore = sumValuesBeforeIndex(values, currentIndex, false);
|
|
47
|
+
const totalOfValues = sumValuesBeforeIndex(values, currentIndex, true);
|
|
48
|
+
if (outsideRange(values, currentIndex, min, max)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
if (currentIndex === 0) {
|
|
52
|
+
return calibrateDrawingValue(values[currentIndex], min, max);
|
|
53
|
+
}
|
|
54
|
+
if (totalOfIndexBefore < min && totalOfValues > max) {
|
|
55
|
+
return max - min;
|
|
56
|
+
}
|
|
57
|
+
let result = values[currentIndex];
|
|
58
|
+
if (totalOfValues > max) {
|
|
59
|
+
result = max - totalOfIndexBefore;
|
|
60
|
+
}
|
|
61
|
+
else if (totalOfValues < min) {
|
|
62
|
+
result = min - totalOfIndexBefore;
|
|
63
|
+
}
|
|
64
|
+
else if (totalOfIndexBefore < min) {
|
|
65
|
+
result = totalOfValues - min;
|
|
66
|
+
}
|
|
67
|
+
else if (totalOfIndexBefore > max) {
|
|
68
|
+
result = totalOfValues - max;
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ValueEdge, LabelAxisData } from "../../types/store/store";
|
|
2
|
+
import { BezierPoint, Point } from "../../types/options";
|
|
3
|
+
export declare function getTextWidth(text: string, font?: string): number;
|
|
4
|
+
export declare function getTextHeight(text: string, font?: string): number;
|
|
5
|
+
export declare function getFontHeight(font?: string): number;
|
|
6
|
+
export declare function getAxisLabelAnchorPoint(labelHeight: number): number;
|
|
7
|
+
export declare function add(a: number, b: number): number;
|
|
8
|
+
export declare function multiply(a: number, b: number): number;
|
|
9
|
+
export declare function divide(a: number, b: number): number;
|
|
10
|
+
export declare function sum(values: number[]): number;
|
|
11
|
+
export declare function divisors(value: number): number[];
|
|
12
|
+
export declare function makeLabelsFromLimit(limit: ValueEdge, stepSize: number, isDateType?: boolean): string[];
|
|
13
|
+
export declare function makeTickPixelPositions(size: number, count: number, additionalPosition?: number, remainLastBlockIntervalPosition?: number): number[];
|
|
14
|
+
export declare function crispPixel(pixel: number, thickness?: number): number;
|
|
15
|
+
export declare function setSplineControlPoint(points: (BezierPoint | null)[]): void;
|
|
16
|
+
export declare function getValueRatio(value: number, { min, max }: ValueEdge): number;
|
|
17
|
+
export declare function getDistance(point1: Point, point2: Point): number;
|
|
18
|
+
export declare function getMaxLengthLabelWidth(labels: string[]): number;
|
|
19
|
+
export declare function getXPosition(axisData: LabelAxisData, offsetSize: number, value: number | string | Date, dataIndex: number): any;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { range, isInteger, isString, isNumber, isNull } from "./utils";
|
|
2
|
+
import { DEFAULT_LABEL_TEXT } from "../brushes/label";
|
|
3
|
+
import { TICK_SIZE } from "../brushes/axis";
|
|
4
|
+
const LINE_HEIGHT_NORMAL = 1.2;
|
|
5
|
+
const ctx = document.createElement('canvas').getContext('2d');
|
|
6
|
+
export function getTextWidth(text, font = DEFAULT_LABEL_TEXT) {
|
|
7
|
+
ctx.font = font;
|
|
8
|
+
return Math.ceil(ctx.measureText(text).width);
|
|
9
|
+
}
|
|
10
|
+
/*
|
|
11
|
+
* Calculate height of canvas text
|
|
12
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/TextMetrics
|
|
13
|
+
* */
|
|
14
|
+
export function getTextHeight(text, font = DEFAULT_LABEL_TEXT) {
|
|
15
|
+
ctx.font = font;
|
|
16
|
+
const { actualBoundingBoxAscent, actualBoundingBoxDescent } = ctx.measureText(text);
|
|
17
|
+
const validActualBoundingBox = isNumber(actualBoundingBoxAscent) && isNumber(actualBoundingBoxDescent);
|
|
18
|
+
return validActualBoundingBox
|
|
19
|
+
? Math.ceil(Math.abs(actualBoundingBoxAscent) + Math.abs(actualBoundingBoxDescent)) + 1
|
|
20
|
+
: getFontHeight(font);
|
|
21
|
+
}
|
|
22
|
+
export function getFontHeight(font = DEFAULT_LABEL_TEXT) {
|
|
23
|
+
const fontSize = font.match(/\d+(?=px)/);
|
|
24
|
+
return parseInt(String(Number(fontSize) * LINE_HEIGHT_NORMAL), 10);
|
|
25
|
+
}
|
|
26
|
+
export function getAxisLabelAnchorPoint(labelHeight) {
|
|
27
|
+
return crispPixel(TICK_SIZE * 2 + labelHeight / 2);
|
|
28
|
+
}
|
|
29
|
+
function getDecimalLength(value) {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
return _b = (_a = String(value).split('.')[1]) === null || _a === void 0 ? void 0 : _a.length, (_b !== null && _b !== void 0 ? _b : 0);
|
|
32
|
+
}
|
|
33
|
+
function findMultipleNum(...args) {
|
|
34
|
+
const underPointLens = args.map((value) => getDecimalLength(value));
|
|
35
|
+
const underPointLen = Math.max(...underPointLens);
|
|
36
|
+
return Math.pow(10, underPointLen);
|
|
37
|
+
}
|
|
38
|
+
export function add(a, b) {
|
|
39
|
+
const multipleNum = findMultipleNum(a, b);
|
|
40
|
+
return (a * multipleNum + b * multipleNum) / multipleNum;
|
|
41
|
+
}
|
|
42
|
+
export function multiply(a, b) {
|
|
43
|
+
const multipleNum = findMultipleNum(a, b);
|
|
44
|
+
return (a * multipleNum * (b * multipleNum)) / (multipleNum * multipleNum);
|
|
45
|
+
}
|
|
46
|
+
export function divide(a, b) {
|
|
47
|
+
const multipleNum = findMultipleNum(a, b);
|
|
48
|
+
return (a * multipleNum) / (b * multipleNum);
|
|
49
|
+
}
|
|
50
|
+
export function sum(values) {
|
|
51
|
+
const copyArr = values.slice();
|
|
52
|
+
copyArr.unshift(0);
|
|
53
|
+
return copyArr.reduce((base, value) => add(parseFloat(String(base)), parseFloat(String(value))));
|
|
54
|
+
}
|
|
55
|
+
export function divisors(value) {
|
|
56
|
+
const result = [];
|
|
57
|
+
for (let a = 2, b; a * a <= value; a += 1) {
|
|
58
|
+
if (value % a === 0) {
|
|
59
|
+
b = value / a;
|
|
60
|
+
result.push(a);
|
|
61
|
+
if (b !== a) {
|
|
62
|
+
result.push(b);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return result.sort((prev, next) => prev - next);
|
|
67
|
+
}
|
|
68
|
+
export function makeLabelsFromLimit(limit, stepSize, isDateType) {
|
|
69
|
+
const multipleNum = findMultipleNum(stepSize);
|
|
70
|
+
const min = Math.round(limit.min * multipleNum);
|
|
71
|
+
const max = Math.round(limit.max * multipleNum);
|
|
72
|
+
const labels = range(min, max + 1, stepSize * multipleNum);
|
|
73
|
+
return labels.map((label) => {
|
|
74
|
+
return String(isDateType ? new Date(label) : label / multipleNum);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export function makeTickPixelPositions(size, count, additionalPosition = 0, remainLastBlockIntervalPosition = 0) {
|
|
78
|
+
let positions = [];
|
|
79
|
+
if (count > 0) {
|
|
80
|
+
positions = range(0, count).map((index) => {
|
|
81
|
+
const ratio = index === 0 ? 0 : index / (count - 1);
|
|
82
|
+
return ratio * size + additionalPosition;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (remainLastBlockIntervalPosition) {
|
|
86
|
+
positions.push(remainLastBlockIntervalPosition);
|
|
87
|
+
}
|
|
88
|
+
return positions;
|
|
89
|
+
}
|
|
90
|
+
export function crispPixel(pixel, thickness = 1) {
|
|
91
|
+
const halfThickness = thickness / 2;
|
|
92
|
+
return thickness % 2
|
|
93
|
+
? (isInteger(pixel) ? pixel : Math.round(pixel - halfThickness)) + halfThickness
|
|
94
|
+
: Math.round(pixel);
|
|
95
|
+
}
|
|
96
|
+
function getControlPoints(prev, cur, next) {
|
|
97
|
+
// http://scaledinnovation.com/analytics/splines/aboutSplines.html
|
|
98
|
+
const TENSION = 0.333;
|
|
99
|
+
const { x: x0, y: y0 } = prev;
|
|
100
|
+
const { x: x1, y: y1 } = cur;
|
|
101
|
+
const { x: x2, y: y2 } = next;
|
|
102
|
+
const d12 = getDistance(next, cur);
|
|
103
|
+
const d01 = getDistance(cur, prev);
|
|
104
|
+
const fa = (TENSION * d01) / (d01 + d12) || 0; // scaling factor for triangle Ta
|
|
105
|
+
const fb = (TENSION * d12) / (d01 + d12) || 0; // ditto for Tb, simplifies to fb=t-fa
|
|
106
|
+
return {
|
|
107
|
+
prev: {
|
|
108
|
+
x: x1 - fa * (x2 - x0),
|
|
109
|
+
y: y1 - fa * (y2 - y0),
|
|
110
|
+
},
|
|
111
|
+
next: { x: x1 + fb * (x2 - x0), y: y1 + fb * (y2 - y0) },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export function setSplineControlPoint(points) {
|
|
115
|
+
for (let i = 0, pointsSize = points.length, prev = points[0]; i < pointsSize; i += 1) {
|
|
116
|
+
const point = points[i];
|
|
117
|
+
if (isNull(point)) {
|
|
118
|
+
prev = points[i + 1];
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const next = points[Math.min(i + 1, pointsSize - 1) % pointsSize];
|
|
122
|
+
if (prev && next) {
|
|
123
|
+
point.controlPoint = getControlPoints(prev, point, next);
|
|
124
|
+
}
|
|
125
|
+
prev = point;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export function getValueRatio(value, { min, max }) {
|
|
129
|
+
if (max === min) {
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
return (value - min) / (max - min);
|
|
133
|
+
}
|
|
134
|
+
export function getDistance(point1, point2) {
|
|
135
|
+
return Math.sqrt(Math.pow((point2.x - point1.x), 2) + Math.pow((point2.y - point1.y), 2));
|
|
136
|
+
}
|
|
137
|
+
export function getMaxLengthLabelWidth(labels) {
|
|
138
|
+
const maxLengthLabel = labels.reduce((acc, cur) => (acc.length > cur.length ? acc : cur), '');
|
|
139
|
+
return getTextWidth(maxLengthLabel);
|
|
140
|
+
}
|
|
141
|
+
export function getXPosition(axisData, offsetSize, value, dataIndex) {
|
|
142
|
+
const { pointOnColumn, tickDistance, labelRange } = axisData;
|
|
143
|
+
let x;
|
|
144
|
+
if (labelRange) {
|
|
145
|
+
const xValue = isString(value) ? Number(new Date(value)) : Number(value);
|
|
146
|
+
const xValueRatio = getValueRatio(xValue, labelRange);
|
|
147
|
+
x = xValueRatio * offsetSize;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
x = tickDistance * dataIndex + (pointOnColumn ? tickDistance / 2 : 0);
|
|
151
|
+
}
|
|
152
|
+
return x;
|
|
153
|
+
}
|