vccs 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cartesian/funnel/Funnel.d.ts +2 -0
- package/dist/cartesian/funnel/index.d.ts +2 -0
- package/dist/cartesian/funnel/type.d.ts +74 -5
- package/dist/cartesian/index.d.ts +1 -0
- package/dist/chart/FunnelChart.d.ts +1 -0
- package/dist/chart/index.d.ts +1 -0
- package/dist/es/animation/Animate.mjs +48 -22
- package/dist/es/cartesian/GraphicalItemClipPath.mjs +16 -15
- package/dist/es/cartesian/area/ActivePoints.mjs +44 -40
- package/dist/es/cartesian/area/Area.mjs +42 -31
- package/dist/es/cartesian/area/ClipRect.mjs +79 -58
- package/dist/es/cartesian/area/RenderArea.mjs +142 -108
- package/dist/es/cartesian/area/hooks/useArea.mjs +71 -47
- package/dist/es/cartesian/area/type.mjs +11 -11
- package/dist/es/cartesian/area/utils.mjs +69 -49
- package/dist/es/cartesian/axis/XAxis.mjs +87 -73
- package/dist/es/cartesian/axis/YAxis.mjs +67 -56
- package/dist/es/cartesian/bar/Bar.mjs +93 -71
- package/dist/es/cartesian/bar/components/BarBackground.mjs +22 -19
- package/dist/es/cartesian/bar/components/BarRectangles.mjs +117 -80
- package/dist/es/cartesian/bar/hooks/useBar.mjs +49 -37
- package/dist/es/cartesian/bar/type.mjs +9 -9
- package/dist/es/cartesian/bar/utils.mjs +97 -70
- package/dist/es/cartesian/cartesian-axis/CartesianAxis.mjs +165 -115
- package/dist/es/cartesian/cartesian-grid/Background.mjs +19 -16
- package/dist/es/cartesian/cartesian-grid/CartesianGrid.mjs +116 -97
- package/dist/es/cartesian/cartesian-grid/HorizontalGridLines.mjs +24 -23
- package/dist/es/cartesian/cartesian-grid/HorizontalStripes.mjs +24 -24
- package/dist/es/cartesian/cartesian-grid/VerticalGridLines.mjs +23 -22
- package/dist/es/cartesian/cartesian-grid/VerticalStripes.mjs +24 -24
- package/dist/es/cartesian/cartesian-grid/const.mjs +317 -10
- package/dist/es/cartesian/cartesian-grid/utils.mjs +18 -13
- package/dist/es/cartesian/error-bar/ErrorBar.mjs +111 -83
- package/dist/es/cartesian/error-bar/ErrorBarContext.mjs +13 -12
- package/dist/es/cartesian/funnel/Funnel.mjs +177 -0
- package/dist/es/cartesian/funnel/type.mjs +80 -0
- package/dist/es/cartesian/funnel/utils.mjs +102 -0
- package/dist/es/cartesian/line/ActivePoints.mjs +45 -41
- package/dist/es/cartesian/line/Line.mjs +41 -37
- package/dist/es/cartesian/line/StaticLine.mjs +191 -122
- package/dist/es/cartesian/line/hooks/useLine.mjs +60 -44
- package/dist/es/cartesian/line/type.mjs +11 -11
- package/dist/es/cartesian/line/utils.mjs +27 -26
- package/dist/es/cartesian/reference-area/ReferenceArea.mjs +86 -69
- package/dist/es/cartesian/reference-line/ReferenceLine.mjs +99 -77
- package/dist/es/cartesian/scatter/Scatter.mjs +168 -140
- package/dist/es/cartesian/scatter/hooks/useScatter.mjs +18 -14
- package/dist/es/cartesian/useNeedsClip.mjs +18 -9
- package/dist/es/cartesian/utils/get-ticks.mjs +103 -68
- package/dist/es/cartesian/z-axis/ZAxis.mjs +30 -28
- package/dist/es/chart/AreaChart.mjs +5 -5
- package/dist/es/chart/BarChart.mjs +5 -5
- package/dist/es/chart/ComposedChart.mjs +5 -5
- package/dist/es/chart/FunnelChart.mjs +11 -0
- package/dist/es/chart/LegendPortalContext.mjs +3 -3
- package/dist/es/chart/LineChart.mjs +5 -5
- package/dist/es/chart/PieChart.mjs +5 -5
- package/dist/es/chart/RadarChart.mjs +5 -5
- package/dist/es/chart/RadialBarChart.mjs +5 -5
- package/dist/es/chart/RechartsWrapper.mjs +111 -88
- package/dist/es/chart/ScatterChart.mjs +5 -5
- package/dist/es/chart/Surface.mjs +3 -3
- package/dist/es/chart/Surface.vue_vue_type_script_setup_true_lang.mjs +51 -45
- package/dist/es/chart/TooltipPortalContext.mjs +3 -3
- package/dist/es/chart/const.mjs +2 -2
- package/dist/es/chart/generateCategoricalChart.mjs +97 -88
- package/dist/es/chart/provideClipPathId.mjs +12 -7
- package/dist/es/components/Cell.mjs +16 -4
- package/dist/es/components/Text.mjs +3 -3
- package/dist/es/components/Text.vue_vue_type_script_setup_true_lang.mjs +106 -69
- package/dist/es/components/Tooltip.mjs +274 -199
- package/dist/es/components/label/Label.mjs +30 -26
- package/dist/es/components/label/LabelList.mjs +45 -39
- package/dist/es/components/label/types.mjs +8 -5
- package/dist/es/components/label/utils.mjs +194 -162
- package/dist/es/components/legend/Legend.mjs +82 -71
- package/dist/es/components/legend/LegendSymbol.mjs +40 -38
- package/dist/es/components/legend/hooks/useLegend.mjs +66 -46
- package/dist/es/components/legend/hooks/useLegendContent.mjs +52 -31
- package/dist/es/components/legend/type.mjs +2 -2
- package/dist/es/components/legend/utils.mjs +19 -11
- package/dist/es/components/utils.mjs +35 -22
- package/dist/es/container/ClipPath.mjs +14 -14
- package/dist/es/container/Layer.mjs +9 -7
- package/dist/es/container/ResponsiveContainer.mjs +3 -3
- package/dist/es/container/ResponsiveContainer.vue_vue_type_script_setup_true_lang.mjs +109 -77
- package/dist/es/container/Surface.mjs +23 -19
- package/dist/es/container/useSizeContext.mjs +3 -3
- package/dist/es/context/ChartDataContextProvider.mjs +19 -13
- package/dist/es/context/PanoramaContextProvider.mjs +15 -10
- package/dist/es/context/accessibilityContext.mjs +3 -3
- package/dist/es/context/cartesianLabelListContext.mjs +3 -3
- package/dist/es/context/chartLayoutContext.mjs +33 -30
- package/dist/es/context/cursorLayerContext.mjs +3 -3
- package/dist/es/context/graphicalLayerContext.mjs +3 -3
- package/dist/es/context/labelLayerContext.mjs +3 -3
- package/dist/es/context/polarLabelViewBoxContext.mjs +5 -5
- package/dist/es/context/useTooltipAxis.mjs +14 -12
- package/dist/es/events/useChartSynchronisation.mjs +91 -66
- package/dist/es/hooks/useIsAnimating.mjs +28 -0
- package/dist/es/hooks/useSetupGraphicalItem.mjs +52 -43
- package/dist/es/index.mjs +46 -42
- package/dist/es/polar/pie/Pie.mjs +131 -115
- package/dist/es/polar/pie/type.mjs +6 -6
- package/dist/es/polar/radar/PolarAngleAxis.mjs +103 -84
- package/dist/es/polar/radar/PolarGrid.mjs +72 -59
- package/dist/es/polar/radar/PolarRadiusAxis.mjs +90 -65
- package/dist/es/polar/radar/Radar.mjs +181 -145
- package/dist/es/polar/radial-bar/RadialBar.mjs +161 -140
- package/dist/es/polar/radial-bar/type.mjs +9 -9
- package/dist/es/shape/Cross.mjs +11 -10
- package/dist/es/shape/Curve.mjs +69 -43
- package/dist/es/shape/Dot.mjs +12 -11
- package/dist/es/shape/Rectangle.mjs +41 -26
- package/dist/es/shape/Sector.mjs +103 -75
- package/dist/es/shape/Symbols.mjs +45 -34
- package/dist/es/shape/Trapezoid.mjs +52 -0
- package/dist/es/state/ReportChartProps.mjs +21 -20
- package/dist/es/state/ReportMainChartProps.mjs +26 -21
- package/dist/es/state/ReportPolarOptions.mjs +23 -22
- package/dist/es/state/SetGraphicalItem.mjs +42 -27
- package/dist/es/state/SetLegendPayload.mjs +17 -13
- package/dist/es/state/SetTooltipEntrySettings.mjs +14 -12
- package/dist/es/state/brushSlice.mjs +12 -8
- package/dist/es/state/cartesianAxisSlice.mjs +23 -17
- package/dist/es/state/chartDataSlice.mjs +18 -13
- package/dist/es/state/externalEventsMiddleware.mjs +25 -15
- package/dist/es/state/graphicalItemsSlice.mjs +29 -25
- package/dist/es/state/hooks.mjs +4 -3
- package/dist/es/state/keyboardEventsMiddleware.mjs +50 -42
- package/dist/es/state/layoutSlice.mjs +18 -12
- package/dist/es/state/legendSlice.mjs +19 -14
- package/dist/es/state/mouseEventsMiddleware.mjs +31 -24
- package/dist/es/state/optionsSlice.mjs +14 -11
- package/dist/es/state/polarAxisSlice.mjs +15 -13
- package/dist/es/state/polarOptionsSlice.mjs +8 -6
- package/dist/es/state/reduxDevtoolsJsonStringifyReplacer.mjs +5 -3
- package/dist/es/state/referenceElementsSlice.mjs +21 -19
- package/dist/es/state/rootPropsSlice.mjs +20 -9
- package/dist/es/state/selectors/areaSelectors.mjs +65 -55
- package/dist/es/state/selectors/axisSelectors.mjs +755 -569
- package/dist/es/state/selectors/barSelectors.mjs +225 -162
- package/dist/es/state/selectors/brushSelectors.mjs +15 -14
- package/dist/es/state/selectors/combiners/combineActiveLabel.mjs +6 -5
- package/dist/es/state/selectors/combiners/combineActiveTooltipIndex.mjs +36 -27
- package/dist/es/state/selectors/combiners/combineAxisRangeWithReverse.mjs +5 -3
- package/dist/es/state/selectors/combiners/combineCoordinateForDefaultIndex.mjs +13 -11
- package/dist/es/state/selectors/combiners/combineTooltipInteractionState.mjs +26 -21
- package/dist/es/state/selectors/combiners/combineTooltipPayloadConfigurations.mjs +10 -6
- package/dist/es/state/selectors/common.mjs +2 -2
- package/dist/es/state/selectors/containerSelectors.mjs +5 -2
- package/dist/es/state/selectors/dataSelectors.mjs +28 -9
- package/dist/es/state/selectors/funnelSelectors.mjs +38 -0
- package/dist/es/state/selectors/legendSelectors.mjs +7 -6
- package/dist/es/state/selectors/lineSelectors.mjs +54 -47
- package/dist/es/state/selectors/pickAxisId.mjs +2 -2
- package/dist/es/state/selectors/pickAxisType.mjs +2 -2
- package/dist/es/state/selectors/pieSelectors.mjs +116 -81
- package/dist/es/state/selectors/polarAxisSelectors.mjs +113 -94
- package/dist/es/state/selectors/polarGridSelectors.mjs +13 -11
- package/dist/es/state/selectors/polarScaleSelectors.mjs +49 -46
- package/dist/es/state/selectors/polarSelectors.mjs +79 -62
- package/dist/es/state/selectors/radarSelectors.mjs +111 -91
- package/dist/es/state/selectors/radialBarSelectors.mjs +230 -183
- package/dist/es/state/selectors/rootPropsSelectors.mjs +11 -5
- package/dist/es/state/selectors/scatterSelectors.mjs +111 -95
- package/dist/es/state/selectors/selectActivePropsFromChartPointer.mjs +19 -17
- package/dist/es/state/selectors/selectAllAxes.mjs +8 -3
- package/dist/es/state/selectors/selectChartOffset.mjs +59 -50
- package/dist/es/state/selectors/selectChartOffsetInternal.mjs +55 -44
- package/dist/es/state/selectors/selectTooltipEventType.mjs +15 -14
- package/dist/es/state/selectors/selectTooltipPayloadSearcher.mjs +3 -3
- package/dist/es/state/selectors/selectTooltipSettings.mjs +2 -2
- package/dist/es/state/selectors/selectTooltipState.mjs +2 -2
- package/dist/es/state/selectors/selectors.mjs +94 -75
- package/dist/es/state/selectors/tooltipSelectors.mjs +253 -204
- package/dist/es/state/selectors/touchSelectors.mjs +17 -14
- package/dist/es/state/store.mjs +46 -46
- package/dist/es/state/tooltipSlice.mjs +64 -37
- package/dist/es/state/touchEventsMiddleware.mjs +35 -29
- package/dist/es/state/utils/useReportScale.mjs +16 -13
- package/dist/es/synchronisation/syncSelectors.mjs +3 -3
- package/dist/es/synchronisation/useChartSynchronisation.mjs +33 -19
- package/dist/es/types/event.mjs +164 -2
- package/dist/es/utils/ReduceCSSCalc.mjs +81 -49
- package/dist/es/utils/VueUtils.mjs +35 -14
- package/dist/es/utils/attrs.mjs +43 -26
- package/dist/es/utils/cartesian.mjs +47 -15
- package/dist/es/utils/chart.mjs +298 -197
- package/dist/es/utils/const.mjs +30 -2
- package/dist/es/utils/createContext.mjs +28 -9
- package/dist/es/utils/data-utils.mjs +9 -8
- package/dist/es/utils/data.mjs +35 -21
- package/dist/es/utils/events.mjs +5 -3
- package/dist/es/utils/getLinearRegression.mjs +28 -11
- package/dist/es/utils/grid.mjs +20 -5
- package/dist/es/utils/isDomainSpecifiedByUser.mjs +105 -54
- package/dist/es/utils/legend.mjs +13 -12
- package/dist/es/utils/log.mjs +10 -7
- package/dist/es/utils/payload/getUniqPayload.mjs +6 -4
- package/dist/es/utils/polar.mjs +37 -30
- package/dist/es/utils/props.mjs +16 -10
- package/dist/es/utils/resolveDefaultProps.mjs +23 -4
- package/dist/es/utils/scale/getNiceTickValues.mjs +127 -49
- package/dist/es/utils/scale/utils/arithmetic.mjs +49 -19
- package/dist/es/utils/scale/utils/utils.mjs +43 -24
- package/dist/es/utils/style.mjs +24 -13
- package/dist/es/utils/tick.mjs +34 -23
- package/dist/es/utils/tooltip/translate.mjs +63 -49
- package/dist/es/utils/validate.mjs +40 -29
- package/dist/hooks/useIsAnimating.d.ts +14 -0
- package/dist/shape/Trapezoid.d.ts +31 -0
- package/dist/shape/index.d.ts +1 -0
- package/dist/state/graphicalItemsSlice.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,59 +1,137 @@
|
|
|
1
|
-
import { compose
|
|
2
|
-
import { getDigitCount
|
|
3
|
-
import
|
|
1
|
+
import { compose, map, memoize, range, reverse } from "./utils/utils.mjs";
|
|
2
|
+
import { getDigitCount, rangeStep } from "./utils/arithmetic.mjs";
|
|
3
|
+
import Decimal from "decimal.js-light";
|
|
4
4
|
//#region src/utils/scale/getNiceTickValues.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Calculate a interval of a minimum value and a maximum value
|
|
7
|
+
*
|
|
8
|
+
* @param {number} min The minimum value
|
|
9
|
+
* @param {number} max The maximum value
|
|
10
|
+
* @return {Array} An interval
|
|
11
|
+
*/
|
|
12
|
+
function getValidInterval([min, max]) {
|
|
13
|
+
let [validMin, validMax] = [min, max];
|
|
14
|
+
if (min > max) [validMin, validMax] = [max, min];
|
|
15
|
+
return [validMin, validMax];
|
|
8
16
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Calculate the step which is easy to understand between ticks, like 10, 20, 25
|
|
19
|
+
*
|
|
20
|
+
* @param {Decimal} roughStep The rough step calculated by dividing the
|
|
21
|
+
* difference by the tickCount
|
|
22
|
+
* @param {boolean} allowDecimals Allow the ticks to be decimals or not
|
|
23
|
+
* @param {Integer} correctionFactor A correction factor
|
|
24
|
+
* @return {Decimal} The step which is easy to understand between two ticks
|
|
25
|
+
*/
|
|
26
|
+
function getFormatStep(roughStep, allowDecimals, correctionFactor) {
|
|
27
|
+
if (roughStep.lte(0)) return new Decimal(0);
|
|
28
|
+
const digitCount = getDigitCount(roughStep.toNumber());
|
|
29
|
+
const digitCountValue = new Decimal(10).pow(digitCount);
|
|
30
|
+
const stepRatio = roughStep.div(digitCountValue);
|
|
31
|
+
const stepRatioScale = digitCount !== 1 ? .05 : .1;
|
|
32
|
+
const formatStep = new Decimal(Math.ceil(stepRatio.div(stepRatioScale).toNumber())).add(correctionFactor).mul(stepRatioScale).mul(digitCountValue);
|
|
33
|
+
return allowDecimals ? new Decimal(formatStep.toNumber()) : new Decimal(Math.ceil(formatStep.toNumber()));
|
|
13
34
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
35
|
+
/**
|
|
36
|
+
* calculate the ticks when the minimum value equals to the maximum value
|
|
37
|
+
*
|
|
38
|
+
* @param value The minimum value which is also the maximum value
|
|
39
|
+
* @param tickCount The count of ticks
|
|
40
|
+
* @param allowDecimals Allow the ticks to be decimals or not
|
|
41
|
+
* @return array of ticks
|
|
42
|
+
*/
|
|
43
|
+
function getTickOfSingleValue(value, tickCount, allowDecimals) {
|
|
44
|
+
let step = new Decimal(1);
|
|
45
|
+
let middle = new Decimal(value);
|
|
46
|
+
if (!middle.isint() && allowDecimals) {
|
|
47
|
+
const absVal = Math.abs(value);
|
|
48
|
+
if (absVal < 1) {
|
|
49
|
+
step = new Decimal(10).pow(getDigitCount(value) - 1);
|
|
50
|
+
middle = new Decimal(Math.floor(middle.div(step).toNumber())).mul(step);
|
|
51
|
+
} else if (absVal > 1) middle = new Decimal(Math.floor(value));
|
|
52
|
+
} else if (value === 0) middle = new Decimal(Math.floor((tickCount - 1) / 2));
|
|
53
|
+
else if (!allowDecimals) middle = new Decimal(Math.floor(value));
|
|
54
|
+
const middleIndex = Math.floor((tickCount - 1) / 2);
|
|
55
|
+
return compose(map((n) => middle.add(new Decimal(n - middleIndex).mul(step)).toNumber()), range)(0, tickCount);
|
|
22
56
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Calculate the step
|
|
59
|
+
*
|
|
60
|
+
* @param {number} min The minimum value of an interval
|
|
61
|
+
* @param {number} max The maximum value of an interval
|
|
62
|
+
* @param {Integer} tickCount The count of ticks
|
|
63
|
+
* @param {boolean} allowDecimals Allow the ticks to be decimals or not
|
|
64
|
+
* @param {number} correctionFactor A correction factor
|
|
65
|
+
* @return {object} The step, minimum value of ticks, maximum value of ticks
|
|
66
|
+
*/
|
|
67
|
+
function calculateStep(min, max, tickCount, allowDecimals, correctionFactor = 0) {
|
|
68
|
+
if (!Number.isFinite((max - min) / (tickCount - 1))) return {
|
|
69
|
+
step: new Decimal(0),
|
|
70
|
+
tickMin: new Decimal(0),
|
|
71
|
+
tickMax: new Decimal(0)
|
|
72
|
+
};
|
|
73
|
+
const step = getFormatStep(new Decimal(max).sub(min).div(tickCount - 1), allowDecimals, correctionFactor);
|
|
74
|
+
let middle;
|
|
75
|
+
if (min <= 0 && max >= 0) middle = new Decimal(0);
|
|
76
|
+
else {
|
|
77
|
+
middle = new Decimal(min).add(max).div(2);
|
|
78
|
+
middle = middle.sub(new Decimal(middle).mod(step));
|
|
79
|
+
}
|
|
80
|
+
let belowCount = Math.ceil(middle.sub(min).div(step).toNumber());
|
|
81
|
+
let upCount = Math.ceil(new Decimal(max).sub(middle).div(step).toNumber());
|
|
82
|
+
const scaleCount = belowCount + upCount + 1;
|
|
83
|
+
if (scaleCount > tickCount) return calculateStep(min, max, tickCount, allowDecimals, correctionFactor + 1);
|
|
84
|
+
if (scaleCount < tickCount) {
|
|
85
|
+
upCount = max > 0 ? upCount + (tickCount - scaleCount) : upCount;
|
|
86
|
+
belowCount = max > 0 ? belowCount : belowCount + (tickCount - scaleCount);
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
step,
|
|
90
|
+
tickMin: middle.sub(new Decimal(belowCount).mul(step)),
|
|
91
|
+
tickMax: middle.add(new Decimal(upCount).mul(step))
|
|
28
92
|
};
|
|
29
|
-
let a = l(new s(t).sub(e).div(n - 1), r, i), o;
|
|
30
|
-
e <= 0 && t >= 0 ? o = new s(0) : (o = new s(e).add(t).div(2), o = o.sub(new s(o).mod(a)));
|
|
31
|
-
let c = Math.ceil(o.sub(e).div(a).toNumber()), u = Math.ceil(new s(t).sub(o).div(a).toNumber()), f = c + u + 1;
|
|
32
|
-
return f > n ? d(e, t, n, r, i + 1) : (f < n && (u = t > 0 ? u + (n - f) : u, c = t > 0 ? c : c + (n - f)), {
|
|
33
|
-
step: a,
|
|
34
|
-
tickMin: o.sub(new s(c).mul(a)),
|
|
35
|
-
tickMax: o.add(new s(u).mul(a))
|
|
36
|
-
});
|
|
37
93
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Calculate the ticks of an interval, the count of ticks will be guaranteed
|
|
96
|
+
*
|
|
97
|
+
* @param {number} min, max min: The minimum value, max: The maximum value
|
|
98
|
+
* @param {Integer} tickCount The count of ticks
|
|
99
|
+
* @param {boolean} allowDecimals Allow the ticks to be decimals or not
|
|
100
|
+
* @return {Array} ticks
|
|
101
|
+
*/
|
|
102
|
+
function getNiceTickValuesFn([min, max], tickCount = 6, allowDecimals = true) {
|
|
103
|
+
if (!Number.isFinite(min) || !Number.isFinite(max)) return [];
|
|
104
|
+
const count = Math.max(tickCount, 2);
|
|
105
|
+
const [cormin, cormax] = getValidInterval([min, max]);
|
|
106
|
+
if (cormin === -Infinity || cormax === Infinity) {
|
|
107
|
+
const values = cormax === Infinity ? [cormin, ...range(0, tickCount - 1).map(() => Infinity)] : [...range(0, tickCount - 1).map(() => -Infinity), cormax];
|
|
108
|
+
return min > max ? reverse(values) : values;
|
|
44
109
|
}
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
110
|
+
if (cormin === cormax) return getTickOfSingleValue(cormin, tickCount, allowDecimals);
|
|
111
|
+
const { step, tickMin, tickMax } = calculateStep(cormin, cormax, count, allowDecimals, 0);
|
|
112
|
+
const values = rangeStep(tickMin, tickMax.add(new Decimal(.1).mul(step)), step);
|
|
113
|
+
return min > max ? reverse(values) : values;
|
|
48
114
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Calculate the ticks of an interval, the count of ticks won't be guraranteed,
|
|
117
|
+
* but the domain will be guaranteed
|
|
118
|
+
*
|
|
119
|
+
* @param {number} min, max min: The minimum value, max: The maximum value
|
|
120
|
+
* @param {Integer} tickCount The count of ticks
|
|
121
|
+
* @param {boolean} allowDecimals Allow the ticks to be decimals or not
|
|
122
|
+
* @return {Array} ticks
|
|
123
|
+
*/
|
|
124
|
+
function getTickValuesFixedDomainFn([min, max], tickCount, allowDecimals = true) {
|
|
125
|
+
if (!Number.isFinite(min) || !Number.isFinite(max)) return [];
|
|
126
|
+
const [cormin, cormax] = getValidInterval([min, max]);
|
|
127
|
+
if (cormin === -Infinity || cormax === Infinity) return [min, max];
|
|
128
|
+
if (cormin === cormax) return [cormin];
|
|
129
|
+
const count = Math.max(tickCount, 2);
|
|
130
|
+
const step = getFormatStep(new Decimal(cormax).sub(cormin).div(count - 1), allowDecimals, 0);
|
|
131
|
+
const values = [...rangeStep(new Decimal(cormin), new Decimal(cormax).sub(new Decimal(.99).mul(step)), step), cormax];
|
|
132
|
+
return min > max ? reverse(values) : values;
|
|
56
133
|
}
|
|
57
|
-
var
|
|
134
|
+
var getNiceTickValues = memoize(getNiceTickValuesFn);
|
|
135
|
+
var getTickValuesFixedDomain = memoize(getTickValuesFixedDomainFn);
|
|
58
136
|
//#endregion
|
|
59
|
-
export {
|
|
137
|
+
export { getNiceTickValues, getTickValuesFixedDomain };
|
|
@@ -1,24 +1,54 @@
|
|
|
1
|
-
import { curry
|
|
2
|
-
import
|
|
1
|
+
import { curry } from "./utils.mjs";
|
|
2
|
+
import Decimal from "decimal.js-light";
|
|
3
3
|
//#region src/utils/scale/utils/arithmetic.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* 获取数值的位数
|
|
6
|
+
* 其中绝对值属于区间[0.1, 1), 得到的值为0
|
|
7
|
+
* 绝对值属于区间[0.01, 0.1),得到的位数为 -1
|
|
8
|
+
* 绝对值属于区间[0.001, 0.01),得到的位数为 -2
|
|
9
|
+
*
|
|
10
|
+
* @param {number} value 数值
|
|
11
|
+
* @return {Integer} 位数
|
|
12
|
+
*/
|
|
13
|
+
function getDigitCount(value) {
|
|
14
|
+
let result;
|
|
15
|
+
if (value === 0) result = 1;
|
|
16
|
+
else result = Math.floor(new Decimal(value).abs().log(10).toNumber()) + 1;
|
|
17
|
+
return result;
|
|
7
18
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
19
|
+
/**
|
|
20
|
+
* 按照固定的步长获取[start, end)这个区间的数据
|
|
21
|
+
* 并且需要处理js计算精度的问题
|
|
22
|
+
*
|
|
23
|
+
* @param {Decimal} start 起点
|
|
24
|
+
* @param {Decimal} end 终点,不包含该值
|
|
25
|
+
* @param {Decimal} step 步长
|
|
26
|
+
* @return {Array} 若干数值
|
|
27
|
+
*/
|
|
28
|
+
function rangeStep(start, end, step) {
|
|
29
|
+
let num = new Decimal(start);
|
|
30
|
+
let i = 0;
|
|
31
|
+
const result = [];
|
|
32
|
+
while (num.lt(end) && i < 1e5) {
|
|
33
|
+
result.push(num.toNumber());
|
|
34
|
+
num = num.add(step);
|
|
35
|
+
i++;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
12
38
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
39
|
+
curry((a, b, t) => {
|
|
40
|
+
const newA = +a;
|
|
41
|
+
return newA + t * (+b - newA);
|
|
42
|
+
});
|
|
43
|
+
curry((a, b, x) => {
|
|
44
|
+
let diff = b - +a;
|
|
45
|
+
diff = diff || Infinity;
|
|
46
|
+
return (x - a) / diff;
|
|
47
|
+
});
|
|
48
|
+
curry((a, b, x) => {
|
|
49
|
+
let diff = b - +a;
|
|
50
|
+
diff = diff || Infinity;
|
|
51
|
+
return Math.max(0, Math.min(1, (x - a) / diff));
|
|
22
52
|
});
|
|
23
53
|
//#endregion
|
|
24
|
-
export {
|
|
54
|
+
export { getDigitCount, rangeStep };
|
|
@@ -1,34 +1,53 @@
|
|
|
1
1
|
//#region src/utils/scale/utils/utils.ts
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var identity = (i) => i;
|
|
3
|
+
var PLACE_HOLDER = { "@@functional/placeholder": true };
|
|
4
|
+
var isPlaceHolder = (val) => val === PLACE_HOLDER;
|
|
5
|
+
function curry0(fn) {
|
|
6
|
+
return function _curried(...args) {
|
|
7
|
+
if (args.length === 0 || args.length === 1 && isPlaceHolder(args[0])) return _curried;
|
|
8
|
+
return fn(...args);
|
|
6
9
|
};
|
|
7
10
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
function curryN(n, fn) {
|
|
12
|
+
if (n === 1) return fn;
|
|
13
|
+
return curry0((...args) => {
|
|
14
|
+
const argsLength = args.filter((arg) => arg !== PLACE_HOLDER).length;
|
|
15
|
+
if (argsLength >= n) return fn(...args);
|
|
16
|
+
return curryN(n - argsLength, curry0((...restArgs) => {
|
|
17
|
+
return fn(...args.map((arg) => isPlaceHolder(arg) ? restArgs.shift() : arg), ...restArgs);
|
|
18
|
+
}));
|
|
12
19
|
});
|
|
13
20
|
}
|
|
14
|
-
var
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
for (let
|
|
18
|
-
return
|
|
21
|
+
var curry = (fn) => curryN(fn.length, fn);
|
|
22
|
+
function range(begin, end) {
|
|
23
|
+
const arr = [];
|
|
24
|
+
for (let i = begin; i < end; ++i) arr[i - begin] = i;
|
|
25
|
+
return arr;
|
|
19
26
|
}
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
var map = curry((fn, arr) => {
|
|
28
|
+
if (Array.isArray(arr)) return arr.map(fn);
|
|
29
|
+
return Object.keys(arr).map((key) => arr[key]).map(fn);
|
|
30
|
+
});
|
|
31
|
+
function compose(...args) {
|
|
32
|
+
if (!args.length) return identity;
|
|
33
|
+
const fns = args.reverse();
|
|
34
|
+
const firstFn = fns[0];
|
|
35
|
+
const tailsFn = fns.slice(1);
|
|
36
|
+
return (...composeArgs) => tailsFn.reduce((res, fn) => fn(res), firstFn(...composeArgs));
|
|
25
37
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
38
|
+
function reverse(arr) {
|
|
39
|
+
if (Array.isArray(arr)) return arr.reverse();
|
|
40
|
+
return arr.split("").reverse().join("");
|
|
28
41
|
}
|
|
29
|
-
function
|
|
30
|
-
let
|
|
31
|
-
|
|
42
|
+
function memoize(fn) {
|
|
43
|
+
let lastArgs = null;
|
|
44
|
+
let lastResult = null;
|
|
45
|
+
return ((...args) => {
|
|
46
|
+
if (lastArgs && args.every((val, i) => val === lastArgs?.[i])) return lastResult;
|
|
47
|
+
lastArgs = args;
|
|
48
|
+
lastResult = fn(...args);
|
|
49
|
+
return lastResult;
|
|
50
|
+
});
|
|
32
51
|
}
|
|
33
52
|
//#endregion
|
|
34
|
-
export {
|
|
53
|
+
export { compose, curry, map, memoize, range, reverse };
|
package/dist/es/utils/style.mjs
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
|
-
import { isNumber
|
|
1
|
+
import { isNumber } from "./validate.mjs";
|
|
2
2
|
//#region src/utils/style.ts
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Converts a style value to a string with 'px' if it's a number
|
|
5
|
+
* @param value The style value to convert
|
|
6
|
+
* @returns The converted style value
|
|
7
|
+
*/
|
|
8
|
+
function toPx(value) {
|
|
9
|
+
if (value === void 0) return void 0;
|
|
10
|
+
return isNumber(value) ? `${value}px` : value;
|
|
5
11
|
}
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Converts style object values to use 'px' for numeric height/width values
|
|
14
|
+
* @param style The style object to convert
|
|
15
|
+
* @returns A new style object with converted values
|
|
16
|
+
*/
|
|
17
|
+
function normalizeStyle(style = {}) {
|
|
18
|
+
const { height, width, minHeight, maxHeight, minWidth, maxWidth, ...rest } = style;
|
|
8
19
|
return {
|
|
9
|
-
height:
|
|
10
|
-
width:
|
|
11
|
-
minHeight:
|
|
12
|
-
maxHeight:
|
|
13
|
-
minWidth:
|
|
14
|
-
maxWidth:
|
|
15
|
-
...
|
|
20
|
+
height: toPx(height),
|
|
21
|
+
width: toPx(width),
|
|
22
|
+
minHeight: toPx(minHeight),
|
|
23
|
+
maxHeight: toPx(maxHeight),
|
|
24
|
+
minWidth: toPx(minWidth),
|
|
25
|
+
maxWidth: toPx(maxWidth),
|
|
26
|
+
...rest
|
|
16
27
|
};
|
|
17
28
|
}
|
|
18
29
|
//#endregion
|
|
19
|
-
export {
|
|
30
|
+
export { normalizeStyle };
|
package/dist/es/utils/tick.mjs
CHANGED
|
@@ -1,31 +1,42 @@
|
|
|
1
|
-
import { getAngledRectangleWidth
|
|
1
|
+
import { getAngledRectangleWidth } from "./cartesian.mjs";
|
|
2
2
|
//#region src/utils/tick.ts
|
|
3
|
-
function
|
|
4
|
-
return
|
|
3
|
+
function getNumberIntervalTicks(ticks, interval) {
|
|
4
|
+
return getEveryNthWithCondition(ticks, interval + 1);
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Given an array and a number N, return a new array which contains every nTh
|
|
8
|
+
* element of the input array. For n below 1, an empty array is returned.
|
|
9
|
+
* If isValid is provided, all candidates must suffice the condition, else undefined is returned.
|
|
10
|
+
* @param {T[]} array An input array.
|
|
11
|
+
* @param {integer} n A number
|
|
12
|
+
* @param {Function} isValid A function to evaluate a candidate form the array
|
|
13
|
+
* @returns {T[]} The result array of the same type as the input array.
|
|
14
|
+
*/
|
|
15
|
+
function getEveryNthWithCondition(array, n, isValid) {
|
|
16
|
+
if (n < 1) return [];
|
|
17
|
+
if (n === 1 && isValid === void 0) return array;
|
|
18
|
+
const result = [];
|
|
19
|
+
for (let i = 0; i < array.length; i += n) if (isValid === void 0 || isValid(array[i]) === true) result.push(array[i]);
|
|
11
20
|
else return;
|
|
12
|
-
return
|
|
21
|
+
return result;
|
|
13
22
|
}
|
|
14
|
-
function
|
|
15
|
-
return
|
|
16
|
-
width:
|
|
17
|
-
height:
|
|
18
|
-
},
|
|
23
|
+
function getAngledTickWidth(contentSize, unitSize, angle) {
|
|
24
|
+
return getAngledRectangleWidth({
|
|
25
|
+
width: contentSize.width + unitSize.width,
|
|
26
|
+
height: contentSize.height + unitSize.height
|
|
27
|
+
}, angle);
|
|
19
28
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
function getTickBoundaries(viewBox, sign, sizeKey) {
|
|
30
|
+
const isWidth = sizeKey === "width";
|
|
31
|
+
const { x, y, width, height } = viewBox;
|
|
32
|
+
if (sign === 1) return {
|
|
33
|
+
start: isWidth ? x : y,
|
|
34
|
+
end: isWidth ? x + width : y + height
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
start: isWidth ? x + width : y + height,
|
|
38
|
+
end: isWidth ? x : y
|
|
28
39
|
};
|
|
29
40
|
}
|
|
30
41
|
//#endregion
|
|
31
|
-
export {
|
|
42
|
+
export { getAngledTickWidth, getEveryNthWithCondition, getNumberIntervalTicks, getTickBoundaries };
|
|
@@ -1,59 +1,73 @@
|
|
|
1
|
-
import { isNumber
|
|
1
|
+
import { isNumber } from "../validate.mjs";
|
|
2
2
|
//#region src/utils/tooltip/translate.ts
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[`${
|
|
8
|
-
[`${
|
|
9
|
-
[`${
|
|
3
|
+
var CSS_CLASS_PREFIX = "v-charts-tooltip-wrapper";
|
|
4
|
+
var TOOLTIP_HIDDEN = { visibility: "hidden" };
|
|
5
|
+
function getTooltipCSSClassName({ coordinate, translateX, translateY }) {
|
|
6
|
+
return [CSS_CLASS_PREFIX, {
|
|
7
|
+
[`${CSS_CLASS_PREFIX}-right`]: isNumber(translateX) && coordinate && isNumber(coordinate.x) && translateX >= coordinate.x,
|
|
8
|
+
[`${CSS_CLASS_PREFIX}-left`]: isNumber(translateX) && coordinate && isNumber(coordinate.x) && translateX < coordinate.x,
|
|
9
|
+
[`${CSS_CLASS_PREFIX}-bottom`]: isNumber(translateY) && coordinate && isNumber(coordinate.y) && translateY >= coordinate.y,
|
|
10
|
+
[`${CSS_CLASS_PREFIX}-top`]: isNumber(translateY) && coordinate && isNumber(coordinate.y) && translateY < coordinate.y
|
|
10
11
|
}];
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
function getTooltipTranslateXY({ allowEscapeViewBox, coordinate, key, offsetTopLeft, position, reverseDirection, tooltipDimension, viewBox, viewBoxDimension }) {
|
|
14
|
+
if (position && isNumber(position[key])) return position[key];
|
|
15
|
+
const negative = coordinate[key] - tooltipDimension - (offsetTopLeft > 0 ? offsetTopLeft : 0);
|
|
16
|
+
const positive = coordinate[key] + offsetTopLeft;
|
|
17
|
+
if (allowEscapeViewBox[key]) return reverseDirection[key] ? negative : positive;
|
|
18
|
+
const viewBoxKey = viewBox[key];
|
|
19
|
+
if (viewBoxKey == null) return 0;
|
|
20
|
+
if (reverseDirection[key]) {
|
|
21
|
+
if (negative < viewBoxKey) return Math.max(positive, viewBoxKey);
|
|
22
|
+
return Math.max(negative, viewBoxKey);
|
|
23
|
+
}
|
|
24
|
+
if (viewBoxDimension == null) return 0;
|
|
25
|
+
if (positive + tooltipDimension > viewBoxKey + viewBoxDimension) return Math.max(negative, viewBoxKey);
|
|
26
|
+
return Math.max(positive, viewBoxKey);
|
|
18
27
|
}
|
|
19
|
-
function
|
|
20
|
-
return { transform:
|
|
28
|
+
function getTransformStyle({ translateX, translateY, useTranslate3d }) {
|
|
29
|
+
return { transform: useTranslate3d ? `translate3d(${translateX}px, ${translateY}px, 0)` : `translate(${translateX}px, ${translateY}px)` };
|
|
21
30
|
}
|
|
22
|
-
function
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
31
|
+
function getTooltipTranslate({ allowEscapeViewBox, coordinate, offsetTopLeft, position, reverseDirection, tooltipBox, useTranslate3d, viewBox }) {
|
|
32
|
+
let cssProperties, translateX, translateY;
|
|
33
|
+
if (tooltipBox.height > 0 && tooltipBox.width > 0 && coordinate) {
|
|
34
|
+
translateX = getTooltipTranslateXY({
|
|
35
|
+
allowEscapeViewBox,
|
|
36
|
+
coordinate,
|
|
37
|
+
key: "x",
|
|
38
|
+
offsetTopLeft,
|
|
39
|
+
position,
|
|
40
|
+
reverseDirection,
|
|
41
|
+
tooltipDimension: tooltipBox.width,
|
|
42
|
+
viewBox,
|
|
43
|
+
viewBoxDimension: viewBox.width
|
|
44
|
+
});
|
|
45
|
+
translateY = getTooltipTranslateXY({
|
|
46
|
+
allowEscapeViewBox,
|
|
47
|
+
coordinate,
|
|
48
|
+
key: "y",
|
|
49
|
+
offsetTopLeft,
|
|
50
|
+
position,
|
|
51
|
+
reverseDirection,
|
|
52
|
+
tooltipDimension: tooltipBox.height,
|
|
53
|
+
viewBox,
|
|
54
|
+
viewBoxDimension: viewBox.height
|
|
55
|
+
});
|
|
56
|
+
cssProperties = {};
|
|
57
|
+
} else cssProperties = TOOLTIP_HIDDEN;
|
|
58
|
+
return {
|
|
59
|
+
cssProperties,
|
|
60
|
+
cssClasses: getTooltipCSSClassName({
|
|
61
|
+
translateX,
|
|
62
|
+
translateY,
|
|
63
|
+
coordinate
|
|
50
64
|
}),
|
|
51
|
-
transform:
|
|
52
|
-
translateX:
|
|
53
|
-
translateY:
|
|
54
|
-
useTranslate3d
|
|
65
|
+
transform: getTransformStyle({
|
|
66
|
+
translateX: translateX ?? 0,
|
|
67
|
+
translateY: translateY ?? 0,
|
|
68
|
+
useTranslate3d
|
|
55
69
|
})
|
|
56
70
|
};
|
|
57
71
|
}
|
|
58
72
|
//#endregion
|
|
59
|
-
export {
|
|
73
|
+
export { getTooltipTranslate };
|