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,6 +1,10 @@
|
|
|
1
|
-
import { isNan
|
|
1
|
+
import { isNan } from "./validate.mjs";
|
|
2
2
|
//#region src/utils/ReduceCSSCalc.ts
|
|
3
|
-
var
|
|
3
|
+
var MULTIPLY_OR_DIVIDE_REGEX = /(-?\d+(?:\.\d+)?[a-z%]*)([*/])(-?\d+(?:\.\d+)?[a-z%]*)/i;
|
|
4
|
+
var ADD_OR_SUBTRACT_REGEX = /(-?\d+(?:\.\d+)?[a-z%]*)([+-])(-?\d+(?:\.\d+)?[a-z%]*)/i;
|
|
5
|
+
var CSS_LENGTH_UNIT_REGEX = /^px|cm|vh|vw|em|rem|%|mm|in|pt|pc|ex|ch|vmin|vmax|Q$/;
|
|
6
|
+
var NUM_SPLIT_REGEX = /(-?\d+(?:\.\d+)?)([a-z%]+)?/i;
|
|
7
|
+
var CONVERSION_RATES = {
|
|
4
8
|
cm: 96 / 2.54,
|
|
5
9
|
mm: 96 / 25.4,
|
|
6
10
|
pt: 96 / 72,
|
|
@@ -8,75 +12,103 @@ var t = /(-?\d+(?:\.\d+)?[a-z%]*)([*/])(-?\d+(?:\.\d+)?[a-z%]*)/i, n = /(-?\d+(?
|
|
|
8
12
|
in: 96,
|
|
9
13
|
Q: 96 / (2.54 * 40),
|
|
10
14
|
px: 1
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
};
|
|
16
|
+
var FIXED_CSS_LENGTH_UNITS = Object.keys(CONVERSION_RATES);
|
|
17
|
+
var STR_NAN = "NaN";
|
|
18
|
+
function convertToPx(value, unit) {
|
|
19
|
+
return value * CONVERSION_RATES[unit];
|
|
14
20
|
}
|
|
15
|
-
var
|
|
16
|
-
static parse(
|
|
17
|
-
|
|
18
|
-
return new
|
|
21
|
+
var DecimalCSS = class DecimalCSS {
|
|
22
|
+
static parse(str) {
|
|
23
|
+
const [, numStr, unit] = NUM_SPLIT_REGEX.exec(str) ?? [];
|
|
24
|
+
return new DecimalCSS(parseFloat(numStr), unit ?? "");
|
|
19
25
|
}
|
|
20
|
-
constructor(
|
|
21
|
-
this.num =
|
|
26
|
+
constructor(num, unit) {
|
|
27
|
+
this.num = num;
|
|
28
|
+
this.unit = unit;
|
|
29
|
+
this.num = num;
|
|
30
|
+
this.unit = unit;
|
|
31
|
+
if (isNan(num)) this.unit = "";
|
|
32
|
+
if (unit !== "" && !CSS_LENGTH_UNIT_REGEX.test(unit)) {
|
|
33
|
+
this.num = NaN;
|
|
34
|
+
this.unit = "";
|
|
35
|
+
}
|
|
36
|
+
if (FIXED_CSS_LENGTH_UNITS.includes(unit)) {
|
|
37
|
+
this.num = convertToPx(num, unit);
|
|
38
|
+
this.unit = "px";
|
|
39
|
+
}
|
|
22
40
|
}
|
|
23
|
-
add(
|
|
24
|
-
|
|
41
|
+
add(other) {
|
|
42
|
+
if (this.unit !== other.unit) return new DecimalCSS(NaN, "");
|
|
43
|
+
return new DecimalCSS(this.num + other.num, this.unit);
|
|
25
44
|
}
|
|
26
|
-
subtract(
|
|
27
|
-
|
|
45
|
+
subtract(other) {
|
|
46
|
+
if (this.unit !== other.unit) return new DecimalCSS(NaN, "");
|
|
47
|
+
return new DecimalCSS(this.num - other.num, this.unit);
|
|
28
48
|
}
|
|
29
|
-
multiply(
|
|
30
|
-
|
|
49
|
+
multiply(other) {
|
|
50
|
+
if (this.unit !== "" && other.unit !== "" && this.unit !== other.unit) return new DecimalCSS(NaN, "");
|
|
51
|
+
return new DecimalCSS(this.num * other.num, this.unit || other.unit);
|
|
31
52
|
}
|
|
32
|
-
divide(
|
|
33
|
-
|
|
53
|
+
divide(other) {
|
|
54
|
+
if (this.unit !== "" && other.unit !== "" && this.unit !== other.unit) return new DecimalCSS(NaN, "");
|
|
55
|
+
return new DecimalCSS(this.num / other.num, this.unit || other.unit);
|
|
34
56
|
}
|
|
35
57
|
toString() {
|
|
36
58
|
return `${this.num}${this.unit}`;
|
|
37
59
|
}
|
|
38
60
|
isNaN() {
|
|
39
|
-
return
|
|
61
|
+
return isNan(this.num);
|
|
40
62
|
}
|
|
41
63
|
};
|
|
42
|
-
function
|
|
43
|
-
if (
|
|
44
|
-
let
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
64
|
+
function calculateArithmetic(expr) {
|
|
65
|
+
if (expr.includes(STR_NAN)) return STR_NAN;
|
|
66
|
+
let newExpr = expr;
|
|
67
|
+
while (newExpr.includes("*") || newExpr.includes("/")) {
|
|
68
|
+
const [, leftOperand, operator, rightOperand] = MULTIPLY_OR_DIVIDE_REGEX.exec(newExpr) ?? [];
|
|
69
|
+
const lTs = DecimalCSS.parse(leftOperand ?? "");
|
|
70
|
+
const rTs = DecimalCSS.parse(rightOperand ?? "");
|
|
71
|
+
const result = operator === "*" ? lTs.multiply(rTs) : lTs.divide(rTs);
|
|
72
|
+
if (result.isNaN()) return STR_NAN;
|
|
73
|
+
newExpr = newExpr.replace(MULTIPLY_OR_DIVIDE_REGEX, result.toString());
|
|
49
74
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
75
|
+
while (newExpr.includes("+") || /.-\d+(?:\.\d+)?/.test(newExpr)) {
|
|
76
|
+
const [, leftOperand, operator, rightOperand] = ADD_OR_SUBTRACT_REGEX.exec(newExpr) ?? [];
|
|
77
|
+
const lTs = DecimalCSS.parse(leftOperand ?? "");
|
|
78
|
+
const rTs = DecimalCSS.parse(rightOperand ?? "");
|
|
79
|
+
const result = operator === "+" ? lTs.add(rTs) : lTs.subtract(rTs);
|
|
80
|
+
if (result.isNaN()) return STR_NAN;
|
|
81
|
+
newExpr = newExpr.replace(ADD_OR_SUBTRACT_REGEX, result.toString());
|
|
54
82
|
}
|
|
55
|
-
return
|
|
83
|
+
return newExpr;
|
|
56
84
|
}
|
|
57
|
-
var
|
|
58
|
-
function
|
|
59
|
-
let
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
85
|
+
var PARENTHESES_REGEX = /\(([^()]*)\)/;
|
|
86
|
+
function calculateParentheses(expr) {
|
|
87
|
+
let newExpr = expr;
|
|
88
|
+
let match;
|
|
89
|
+
while ((match = PARENTHESES_REGEX.exec(newExpr)) != null) {
|
|
90
|
+
const [, parentheticalExpression] = match;
|
|
91
|
+
newExpr = newExpr.replace(PARENTHESES_REGEX, calculateArithmetic(parentheticalExpression));
|
|
63
92
|
}
|
|
64
|
-
return
|
|
93
|
+
return newExpr;
|
|
65
94
|
}
|
|
66
|
-
function
|
|
67
|
-
let
|
|
68
|
-
|
|
95
|
+
function evaluateExpression(expression) {
|
|
96
|
+
let newExpr = expression.replace(/\s+/g, "");
|
|
97
|
+
newExpr = calculateParentheses(newExpr);
|
|
98
|
+
newExpr = calculateArithmetic(newExpr);
|
|
99
|
+
return newExpr;
|
|
69
100
|
}
|
|
70
|
-
function
|
|
101
|
+
function safeEvaluateExpression(expression) {
|
|
71
102
|
try {
|
|
72
|
-
return
|
|
103
|
+
return evaluateExpression(expression);
|
|
73
104
|
} catch {
|
|
74
|
-
return
|
|
105
|
+
return STR_NAN;
|
|
75
106
|
}
|
|
76
107
|
}
|
|
77
|
-
function
|
|
78
|
-
|
|
79
|
-
|
|
108
|
+
function reduceCSSCalc(expression) {
|
|
109
|
+
const result = safeEvaluateExpression(expression.slice(5, -1));
|
|
110
|
+
if (result === STR_NAN) return "";
|
|
111
|
+
return result;
|
|
80
112
|
}
|
|
81
113
|
//#endregion
|
|
82
|
-
export {
|
|
114
|
+
export { reduceCSSCalc };
|
|
@@ -1,18 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { EventKeys } from "../types/event.mjs";
|
|
2
|
+
import { FilteredElementKeyMap, SVGElementPropKeys } from "../cartesian/cartesian-grid/const.mjs";
|
|
3
3
|
//#region src/utils/VueUtils.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the property is valid to spread onto an SVG element or onto a specific component
|
|
6
|
+
* @param {unknown} property property value currently being compared
|
|
7
|
+
* @param {string} key property key currently being compared
|
|
8
|
+
* @param {boolean} includeEvents if events are included in spreadable props
|
|
9
|
+
* @param {boolean} svgElementType checks against map of SVG element types to attributes
|
|
10
|
+
* @returns {boolean} is prop valid
|
|
11
|
+
*/
|
|
12
|
+
function isValidSpreadableProp(property, key, includeEvents, svgElementType) {
|
|
13
|
+
/**
|
|
14
|
+
* If the svg element type is explicitly included, check against the filtered element key map
|
|
15
|
+
* to determine if there are attributes that should only exist on that element type.
|
|
16
|
+
* @todo Add an internal cjs version of https://github.com/wooorm/svg-element-attributes for full coverage.
|
|
17
|
+
*/
|
|
18
|
+
const matchingElementTypeKeys = (svgElementType && FilteredElementKeyMap?.[svgElementType]) ?? [];
|
|
19
|
+
return key.startsWith("data-") || typeof property !== "function" && (svgElementType && matchingElementTypeKeys.includes(key) || SVGElementPropKeys.includes(key)) || includeEvents && EventKeys.includes(key);
|
|
7
20
|
}
|
|
8
|
-
function
|
|
9
|
-
if (!
|
|
10
|
-
|
|
11
|
-
if (typeof
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
function filterProps(props, includeEvents, svgElementType) {
|
|
22
|
+
if (!props || typeof props === "function" || typeof props === "boolean") return null;
|
|
23
|
+
const inputProps = props;
|
|
24
|
+
if (typeof inputProps !== "object" && typeof inputProps !== "function") return null;
|
|
25
|
+
const out = {};
|
|
26
|
+
/**
|
|
27
|
+
* Props are blindly spread onto SVG elements. This loop filters out properties that we don't want to spread.
|
|
28
|
+
* Items filtered out are as follows:
|
|
29
|
+
* - functions in properties that are SVG attributes (functions are included when includeEvents is true)
|
|
30
|
+
* - props that are SVG attributes but don't matched the passed svgElementType
|
|
31
|
+
* - any prop that is not in SVGElementPropKeys (or in EventKeys if includeEvents is true)
|
|
32
|
+
*/
|
|
33
|
+
Object.keys(inputProps).forEach((key) => {
|
|
34
|
+
if (isValidSpreadableProp(inputProps?.[key], key, includeEvents, svgElementType)) out[key] = inputProps[key];
|
|
35
|
+
});
|
|
36
|
+
return out;
|
|
16
37
|
}
|
|
17
38
|
//#endregion
|
|
18
|
-
export {
|
|
39
|
+
export { filterProps };
|
package/dist/es/utils/attrs.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { isSsr
|
|
1
|
+
import { isSsr } from "./validate.mjs";
|
|
2
2
|
//#region src/utils/attrs.ts
|
|
3
|
-
var
|
|
3
|
+
var stringCache = {
|
|
4
4
|
widthCache: {},
|
|
5
5
|
cacheCount: 0
|
|
6
|
-
}
|
|
6
|
+
};
|
|
7
|
+
var MAX_CACHE_NUM = 2e3;
|
|
8
|
+
var SPAN_STYLE = {
|
|
7
9
|
position: "absolute",
|
|
8
10
|
top: "-20000px",
|
|
9
11
|
left: 0,
|
|
@@ -11,36 +13,51 @@ var t = {
|
|
|
11
13
|
margin: 0,
|
|
12
14
|
border: "none",
|
|
13
15
|
whiteSpace: "pre"
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
};
|
|
17
|
+
var MEASUREMENT_SPAN_ID = "v-charts_measurement_span";
|
|
18
|
+
function removeInvalidKeys(obj) {
|
|
19
|
+
const copyObj = { ...obj };
|
|
20
|
+
Object.keys(copyObj).forEach((key) => {
|
|
21
|
+
if (!copyObj[key]) delete copyObj[key];
|
|
22
|
+
});
|
|
23
|
+
return copyObj;
|
|
20
24
|
}
|
|
21
|
-
function
|
|
22
|
-
if (
|
|
25
|
+
function getStringSize(text, style = {}) {
|
|
26
|
+
if (text === void 0 || text === null || isSsr) return {
|
|
23
27
|
width: 0,
|
|
24
28
|
height: 0
|
|
25
29
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
const copyStyle = removeInvalidKeys(style);
|
|
31
|
+
const cacheKey = JSON.stringify({
|
|
32
|
+
text,
|
|
33
|
+
copyStyle
|
|
29
34
|
});
|
|
30
|
-
if (
|
|
35
|
+
if (stringCache.widthCache[cacheKey]) return stringCache.widthCache[cacheKey];
|
|
31
36
|
try {
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
let measurementSpan = document.getElementById(MEASUREMENT_SPAN_ID);
|
|
38
|
+
if (!measurementSpan) {
|
|
39
|
+
measurementSpan = document.createElement("span");
|
|
40
|
+
measurementSpan.setAttribute("id", MEASUREMENT_SPAN_ID);
|
|
41
|
+
measurementSpan.setAttribute("aria-hidden", "true");
|
|
42
|
+
document.body.appendChild(measurementSpan);
|
|
43
|
+
}
|
|
44
|
+
const measurementSpanStyle = {
|
|
45
|
+
...SPAN_STYLE,
|
|
46
|
+
...copyStyle
|
|
37
47
|
};
|
|
38
|
-
Object.assign(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
Object.assign(measurementSpan.style, measurementSpanStyle);
|
|
49
|
+
measurementSpan.textContent = `${text}`;
|
|
50
|
+
const rect = measurementSpan.getBoundingClientRect();
|
|
51
|
+
const result = {
|
|
52
|
+
width: rect.width,
|
|
53
|
+
height: rect.height
|
|
42
54
|
};
|
|
43
|
-
|
|
55
|
+
stringCache.widthCache[cacheKey] = result;
|
|
56
|
+
if (++stringCache.cacheCount > MAX_CACHE_NUM) {
|
|
57
|
+
stringCache.cacheCount = 0;
|
|
58
|
+
stringCache.widthCache = {};
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
44
61
|
} catch {
|
|
45
62
|
return {
|
|
46
63
|
width: 0,
|
|
@@ -49,4 +66,4 @@ function o(o, s = {}) {
|
|
|
49
66
|
}
|
|
50
67
|
}
|
|
51
68
|
//#endregion
|
|
52
|
-
export {
|
|
69
|
+
export { getStringSize };
|
|
@@ -1,22 +1,54 @@
|
|
|
1
|
-
import { isVisible
|
|
2
|
-
import { getEveryNthWithCondition
|
|
1
|
+
import { isVisible } from "./validate.mjs";
|
|
2
|
+
import { getEveryNthWithCondition } from "./tick.mjs";
|
|
3
3
|
//#region src/utils/cartesian.ts
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes the angle so that 0 <= angle < 180.
|
|
6
|
+
* @param {number} angle Angle in degrees.
|
|
7
|
+
* @return {number} the normalized angle with a value of at least 0 and never greater or equal to 180.
|
|
8
|
+
*/
|
|
9
|
+
function normalizeAngle(angle) {
|
|
10
|
+
return (angle % 180 + 180) % 180;
|
|
6
11
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Calculates the width of the largest horizontal line that fits inside a rectangle that is displayed at an angle.
|
|
14
|
+
* @param {object} size Width and height of the text in a horizontal position.
|
|
15
|
+
* @param {number} angle Angle in degrees in which the text is displayed.
|
|
16
|
+
* @return {number} The width of the largest horizontal line that fits inside a rectangle that is displayed at an angle.
|
|
17
|
+
*/
|
|
18
|
+
function getAngledRectangleWidth({ width, height }, angle = 0) {
|
|
19
|
+
const angleRadians = normalizeAngle(angle) * Math.PI / 180;
|
|
20
|
+
const angleThreshold = Math.atan(height / width);
|
|
21
|
+
const angledWidth = angleRadians > angleThreshold && angleRadians < Math.PI - angleThreshold ? height / Math.sin(angleRadians) : width / Math.cos(angleRadians);
|
|
22
|
+
return Math.abs(angledWidth);
|
|
10
23
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
function getEquidistantTicks(sign, boundaries, getTickSize, ticks, minTickGap) {
|
|
25
|
+
const result = (ticks || []).slice();
|
|
26
|
+
const { start: initialStart, end } = boundaries;
|
|
27
|
+
let index = 0;
|
|
28
|
+
let stepsize = 1;
|
|
29
|
+
let start = initialStart;
|
|
30
|
+
while (stepsize <= result.length) {
|
|
31
|
+
const entry = ticks?.[index];
|
|
32
|
+
if (entry === void 0) return getEveryNthWithCondition(ticks, stepsize) ?? [];
|
|
33
|
+
const i = index;
|
|
34
|
+
let size;
|
|
35
|
+
const getSize = () => {
|
|
36
|
+
if (size === void 0) size = getTickSize(entry, i);
|
|
37
|
+
return size;
|
|
38
|
+
};
|
|
39
|
+
const tickCoord = entry.coordinate;
|
|
40
|
+
const isShow = index === 0 || isVisible(sign, tickCoord, getSize, start, end);
|
|
41
|
+
if (!isShow) {
|
|
42
|
+
index = 0;
|
|
43
|
+
start = initialStart;
|
|
44
|
+
stepsize += 1;
|
|
45
|
+
}
|
|
46
|
+
if (isShow) {
|
|
47
|
+
start = tickCoord + sign * (getSize() / 2 + minTickGap);
|
|
48
|
+
index += stepsize;
|
|
49
|
+
}
|
|
18
50
|
}
|
|
19
51
|
return [];
|
|
20
52
|
}
|
|
21
53
|
//#endregion
|
|
22
|
-
export {
|
|
54
|
+
export { getAngledRectangleWidth, getEquidistantTicks };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Cell } from "../components/Cell.mjs";
|
|
2
|
+
import { Fragment } from "vue";
|
|
3
|
+
//#region src/utils/cell.ts
|
|
4
|
+
/**
|
|
5
|
+
* Extract Cell VNode props from a VNode tree.
|
|
6
|
+
* Handles Fragment wrapping from v-for.
|
|
7
|
+
*/
|
|
8
|
+
function extractCellProps(vnodes) {
|
|
9
|
+
const result = [];
|
|
10
|
+
for (const vnode of vnodes) if (vnode.type === Cell) result.push(vnode.props ?? {});
|
|
11
|
+
else if (vnode.type === Fragment && Array.isArray(vnode.children)) result.push(...extractCellProps(vnode.children));
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Filter out Cell VNodes from a VNode tree, preserving non-Cell siblings.
|
|
16
|
+
* Recursively descends Fragment children to preserve co-located content (e.g. LabelList).
|
|
17
|
+
*/
|
|
18
|
+
function filterOutCells(vnodes) {
|
|
19
|
+
const result = [];
|
|
20
|
+
for (const vnode of vnodes) {
|
|
21
|
+
if (vnode.type === Cell) continue;
|
|
22
|
+
if (vnode.type === Fragment && Array.isArray(vnode.children)) result.push(...filterOutCells(vnode.children));
|
|
23
|
+
else result.push(vnode);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { extractCellProps, filterOutCells };
|