vccs 0.1.0 → 0.3.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/README.md +151 -0
- package/dist/animation/Animate.d.ts +1 -1
- package/dist/cartesian/area/type.d.ts +3 -3
- package/dist/cartesian/bar/type.d.ts +1 -13
- package/dist/cartesian/brush/components/Slide.d.ts +1 -1
- package/dist/cartesian/brush/components/TravellerLayer.d.ts +1 -1
- package/dist/cartesian/brush/type.d.ts +2 -1
- package/dist/cartesian/cartesian-axis/CartesianAxis.d.ts +2 -1
- 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 -6
- package/dist/cartesian/index.d.ts +2 -0
- package/dist/cartesian/line/Line.d.ts +7 -13
- package/dist/cartesian/line/type.d.ts +4 -17
- package/dist/cartesian/reference-area/ReferenceArea.d.ts +16 -16
- package/dist/cartesian/reference-dot/ReferenceDot.d.ts +143 -0
- package/dist/cartesian/reference-dot/index.d.ts +2 -0
- package/dist/cartesian/reference-line/ReferenceLine.d.ts +8 -8
- package/dist/cartesian/scatter/Scatter.d.ts +1 -1
- package/dist/chart/FunnelChart.d.ts +1 -0
- package/dist/chart/RechartsWrapper.d.ts +7 -3
- package/dist/chart/Surface.d.ts +2 -1
- package/dist/chart/Treemap.d.ts +237 -0
- package/dist/chart/generateCategoricalChart.d.ts +2 -1
- package/dist/chart/index.d.ts +2 -0
- package/dist/chart/treemapUtils.d.ts +22 -0
- package/dist/components/Customized.d.ts +23 -0
- package/dist/components/Text.d.ts +4 -4
- package/dist/components/Tooltip.d.ts +1 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/label/Label.d.ts +3 -3
- package/dist/components/label/types.d.ts +1 -1
- package/dist/container/Surface.d.ts +3 -2
- 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 +13 -15
- 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 +78 -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 +11 -25
- 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 +162 -0
- package/dist/es/cartesian/funnel/type.mjs +78 -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 +13 -18
- package/dist/es/cartesian/line/utils.mjs +27 -26
- package/dist/es/cartesian/reference-area/ReferenceArea.mjs +79 -78
- package/dist/es/cartesian/reference-dot/ReferenceDot.mjs +134 -0
- package/dist/es/cartesian/reference-line/ReferenceLine.mjs +93 -84
- 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 +113 -89
- 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/Treemap.mjs +379 -0
- package/dist/es/chart/const.mjs +2 -2
- package/dist/es/chart/generateCategoricalChart.mjs +99 -89
- package/dist/es/chart/provideClipPathId.mjs +12 -7
- package/dist/es/chart/treemapUtils.mjs +32 -0
- package/dist/es/components/Cell.mjs +16 -4
- package/dist/es/components/Customized.mjs +43 -0
- 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 +10 -6
- 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 +71 -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 +25 -23
- 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/publicHooks.mjs +207 -0
- package/dist/es/hooks/useIsAnimating.mjs +28 -0
- package/dist/es/hooks/useSetupGraphicalItem.mjs +52 -43
- package/dist/es/index.mjs +54 -42
- package/dist/es/polar/pie/Pie.mjs +131 -115
- package/dist/es/polar/pie/type.mjs +8 -10
- 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 +71 -44
- package/dist/es/shape/Dot.mjs +12 -11
- package/dist/es/shape/Polygon.mjs +19 -0
- package/dist/es/shape/Rectangle.mjs +41 -30
- package/dist/es/shape/Sector.mjs +105 -79
- package/dist/es/shape/Symbols.mjs +45 -34
- package/dist/es/shape/Trapezoid.mjs +50 -0
- package/dist/es/state/ReportChartProps.mjs +23 -24
- 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 +24 -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 +784 -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/common.mjs +12 -0
- 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/cell.mjs +28 -0
- package/dist/es/utils/chart.mjs +298 -197
- package/dist/es/utils/const.mjs +30 -2
- package/dist/es/utils/createCategoricalInverse.mjs +46 -0
- 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/scale.mjs +46 -0
- 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/publicHooks.d.ts +143 -0
- package/dist/hooks/useIsAnimating.d.ts +14 -0
- package/dist/index.d.ts +1 -0
- package/dist/polar/pie/type.d.ts +2 -2
- package/dist/polar/radar/Radar.d.ts +4 -4
- package/dist/shape/Curve.d.ts +2 -1
- package/dist/shape/Polygon.d.ts +9 -0
- package/dist/shape/Rectangle.d.ts +0 -4
- package/dist/shape/Sector.d.ts +2 -2
- package/dist/shape/Symbols.d.ts +2 -1
- package/dist/shape/Trapezoid.d.ts +30 -0
- package/dist/shape/index.d.ts +2 -0
- package/dist/shape/types.d.ts +4 -5
- package/dist/state/ReportChartProps.d.ts +3 -3
- package/dist/state/graphicalItemsSlice.d.ts +1 -1
- package/dist/state/rootPropsSlice.d.ts +2 -2
- package/dist/state/selectors/axisSelectors.d.ts +5 -0
- package/dist/types/axis.d.ts +2 -2
- package/dist/types/bar.d.ts +2 -6
- package/dist/types/categorical.d.ts +2 -2
- package/dist/types/common.d.ts +7 -1
- package/dist/types/tooltip.d.ts +2 -2
- package/dist/utils/cell.d.ts +11 -0
- package/dist/utils/createCategoricalInverse.d.ts +16 -0
- package/dist/utils/scale.d.ts +23 -0
- package/package.json +2 -1
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
//#region src/utils/resolveDefaultProps.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
/**
|
|
3
|
+
* This function mimics the behavior of the `defaultProps` static property in React.
|
|
4
|
+
* Functional components do not have a defaultProps property, so this function is useful to resolve default props.
|
|
5
|
+
*
|
|
6
|
+
* The common recommendation is to use ES6 destructuring with default values in the function signature,
|
|
7
|
+
* but you need to be careful there and make sure you destructure all the individual properties
|
|
8
|
+
* and not the whole object. See the test file for example.
|
|
9
|
+
*
|
|
10
|
+
* And because destructuring all properties one by one is a faff, and it's easy to miss one property,
|
|
11
|
+
* this function exists.
|
|
12
|
+
*
|
|
13
|
+
* @param realProps - the props object passed to the component by the user
|
|
14
|
+
* @param defaultProps - the default props object defined in the component by Recharts
|
|
15
|
+
* @returns - the props object with all the default props resolved. All `undefined` values are replaced with the default value.
|
|
16
|
+
*/
|
|
17
|
+
function resolveDefaultProps(realProps, defaultProps) {
|
|
18
|
+
const resolvedProps = { ...realProps };
|
|
19
|
+
const dp = defaultProps;
|
|
20
|
+
return Object.keys(defaultProps).reduce((acc, key) => {
|
|
21
|
+
if (acc[key] === void 0 && dp[key] !== void 0) acc[key] = dp[key];
|
|
22
|
+
return acc;
|
|
23
|
+
}, resolvedProps);
|
|
5
24
|
}
|
|
6
25
|
//#endregion
|
|
7
|
-
export {
|
|
26
|
+
export { resolveDefaultProps };
|
|
@@ -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 };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isWellBehavedNumber } from "./validate.mjs";
|
|
2
|
+
//#region src/utils/scale.ts
|
|
3
|
+
/**
|
|
4
|
+
* Convert a data value to pixel coordinate using a D3 scale.
|
|
5
|
+
* Automatically centers on band-scale categories by adding half the bandwidth.
|
|
6
|
+
*/
|
|
7
|
+
function scaleCoord(scale, value) {
|
|
8
|
+
const coord = scale(value);
|
|
9
|
+
if (!isWellBehavedNumber(coord)) return void 0;
|
|
10
|
+
return coord + (scale.bandwidth?.() ?? 0) / 2;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Convert a data value to pixel coordinate for range boundaries.
|
|
14
|
+
* `start` returns the left/top edge; `end` returns the right/bottom edge (adding full bandwidth).
|
|
15
|
+
*/
|
|
16
|
+
function scaleValue(scale, value, position) {
|
|
17
|
+
const coord = scale(value);
|
|
18
|
+
if (!isWellBehavedNumber(coord)) return void 0;
|
|
19
|
+
const bandwidth = scale.bandwidth?.() ?? 0;
|
|
20
|
+
return position === "start" ? coord : coord + bandwidth;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Check whether a pixel coordinate falls within the scale's output range.
|
|
24
|
+
*/
|
|
25
|
+
function isInRange(scale, coord) {
|
|
26
|
+
const r = scale.range();
|
|
27
|
+
const min = Math.min(r[0], r[1]);
|
|
28
|
+
const max = Math.max(r[0], r[1]);
|
|
29
|
+
return coord >= min && coord <= max;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the minimum value of a scale's range.
|
|
33
|
+
*/
|
|
34
|
+
function rangeMin(scale) {
|
|
35
|
+
const r = scale.range();
|
|
36
|
+
return Math.min(r[0], r[1]);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the maximum value of a scale's range.
|
|
40
|
+
*/
|
|
41
|
+
function rangeMax(scale) {
|
|
42
|
+
const r = scale.range();
|
|
43
|
+
return Math.max(r[0], r[1]);
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { isInRange, rangeMax, rangeMin, scaleCoord, scaleValue };
|
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 };
|