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,29 +1,29 @@
|
|
|
1
|
-
import { isNumOrStr
|
|
2
|
-
import { useIsPanorama
|
|
3
|
-
import { selectAxisScale
|
|
4
|
-
import { useAppDispatch
|
|
5
|
-
import { Layer
|
|
6
|
-
import { Label
|
|
7
|
-
import { Rectangle
|
|
8
|
-
import { addArea
|
|
9
|
-
import { useClipPathId
|
|
10
|
-
import { computed
|
|
1
|
+
import { isNumOrStr, isWellBehavedNumber } from "../../utils/validate.mjs";
|
|
2
|
+
import { useIsPanorama } from "../../context/PanoramaContextProvider.mjs";
|
|
3
|
+
import { selectAxisScale } from "../../state/selectors/axisSelectors.mjs";
|
|
4
|
+
import { useAppDispatch, useAppSelector } from "../../state/hooks.mjs";
|
|
5
|
+
import { Layer } from "../../container/Layer.mjs";
|
|
6
|
+
import { Label } from "../../components/label/Label.mjs";
|
|
7
|
+
import { Rectangle } from "../../shape/Rectangle.mjs";
|
|
8
|
+
import { addArea, removeArea } from "../../state/referenceElementsSlice.mjs";
|
|
9
|
+
import { useClipPathId } from "../../chart/provideClipPathId.mjs";
|
|
10
|
+
import { computed, createVNode, defineComponent, mergeProps, onMounted, onUnmounted, reactive } from "vue";
|
|
11
11
|
//#region src/cartesian/reference-area/ReferenceArea.tsx
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
if (!
|
|
15
|
-
|
|
16
|
-
return
|
|
12
|
+
function scaleValue(scale, value, position) {
|
|
13
|
+
const coord = scale(value);
|
|
14
|
+
if (!isWellBehavedNumber(coord)) return void 0;
|
|
15
|
+
const bandwidth = scale.bandwidth?.() ?? 0;
|
|
16
|
+
return position === "start" ? coord : coord + bandwidth;
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
return Math.min(
|
|
18
|
+
function rangeMin(scale) {
|
|
19
|
+
const r = scale.range();
|
|
20
|
+
return Math.min(r[0], r[1]);
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
return Math.max(
|
|
22
|
+
function rangeMax(scale) {
|
|
23
|
+
const r = scale.range();
|
|
24
|
+
return Math.max(r[0], r[1]);
|
|
25
25
|
}
|
|
26
|
-
var
|
|
26
|
+
var ReferenceArea = /* @__PURE__ */ defineComponent({
|
|
27
27
|
name: "ReferenceArea",
|
|
28
28
|
props: {
|
|
29
29
|
x1: {
|
|
@@ -88,59 +88,76 @@ var S = /* @__PURE__ */ m({
|
|
|
88
88
|
default: 0
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
|
-
inheritAttrs:
|
|
92
|
-
setup(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
91
|
+
inheritAttrs: false,
|
|
92
|
+
setup(props, { attrs }) {
|
|
93
|
+
const dispatch = useAppDispatch();
|
|
94
|
+
const isPanorama = useIsPanorama();
|
|
95
|
+
const clipPathId = useClipPathId();
|
|
96
|
+
const settings = reactive({
|
|
97
|
+
xAxisId: props.xAxisId,
|
|
98
|
+
yAxisId: props.yAxisId,
|
|
99
|
+
ifOverflow: props.ifOverflow,
|
|
100
|
+
x1: props.x1,
|
|
101
|
+
x2: props.x2,
|
|
102
|
+
y1: props.y1,
|
|
103
|
+
y2: props.y2
|
|
101
104
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}), _(() => {
|
|
105
|
-
S(u(T));
|
|
105
|
+
onMounted(() => {
|
|
106
|
+
dispatch(addArea(settings));
|
|
106
107
|
});
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
onUnmounted(() => {
|
|
109
|
+
dispatch(removeArea(settings));
|
|
110
|
+
});
|
|
111
|
+
const xAxisScale = useAppSelector((state) => selectAxisScale(state, "xAxis", props.xAxisId, isPanorama));
|
|
112
|
+
const yAxisScale = useAppSelector((state) => selectAxisScale(state, "yAxis", props.yAxisId, isPanorama));
|
|
113
|
+
const rect = computed(() => {
|
|
114
|
+
const xScale = xAxisScale.value;
|
|
115
|
+
const yScale = yAxisScale.value;
|
|
116
|
+
if (!xScale || !yScale) return null;
|
|
117
|
+
const hasX1 = isNumOrStr(props.x1);
|
|
118
|
+
const hasX2 = isNumOrStr(props.x2);
|
|
119
|
+
const hasY1 = isNumOrStr(props.y1);
|
|
120
|
+
const hasY2 = isNumOrStr(props.y2);
|
|
121
|
+
if (!hasX1 && !hasX2 && !hasY1 && !hasY2) return null;
|
|
122
|
+
const px1 = hasX1 ? scaleValue(xScale, props.x1, "start") : rangeMin(xScale);
|
|
123
|
+
const px2 = hasX2 ? scaleValue(xScale, props.x2, "end") : rangeMax(xScale);
|
|
124
|
+
const py1 = hasY1 ? scaleValue(yScale, props.y1, "start") : rangeMin(yScale);
|
|
125
|
+
const py2 = hasY2 ? scaleValue(yScale, props.y2, "end") : rangeMax(yScale);
|
|
126
|
+
if (px1 == null || px2 == null || py1 == null || py2 == null) return null;
|
|
127
|
+
return {
|
|
128
|
+
x: Math.min(px1, px2),
|
|
129
|
+
y: Math.min(py1, py2),
|
|
130
|
+
width: Math.abs(px2 - px1),
|
|
131
|
+
height: Math.abs(py2 - py1)
|
|
118
132
|
};
|
|
119
133
|
});
|
|
120
134
|
return () => {
|
|
121
|
-
|
|
122
|
-
if (!
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
"stroke
|
|
127
|
-
|
|
128
|
-
"fill
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
},
|
|
135
|
+
const r = rect.value;
|
|
136
|
+
if (!r) return null;
|
|
137
|
+
const clipPath = props.ifOverflow === "hidden" ? `url(#${clipPathId})` : void 0;
|
|
138
|
+
const svgAttrs = {
|
|
139
|
+
...attrs,
|
|
140
|
+
"stroke": props.stroke,
|
|
141
|
+
"stroke-width": props.strokeWidth,
|
|
142
|
+
"fill": props.fill,
|
|
143
|
+
"fill-opacity": props.fillOpacity
|
|
144
|
+
};
|
|
145
|
+
const labelValue = props.label;
|
|
146
|
+
const labelProps = typeof labelValue === "object" && labelValue !== null ? labelValue : {};
|
|
147
|
+
return createVNode(Layer, { "class": ["v-charts-reference-area", props.className] }, { default: () => [createVNode(Rectangle, mergeProps(svgAttrs, {
|
|
148
|
+
"clip-path": clipPath,
|
|
149
|
+
"x": r.x,
|
|
150
|
+
"y": r.y,
|
|
151
|
+
"width": r.width,
|
|
152
|
+
"height": r.height,
|
|
153
|
+
"radius": props.radius,
|
|
154
|
+
"class": "v-charts-reference-area-rect"
|
|
155
|
+
}), null), labelValue != null && labelValue !== false && createVNode(Label, mergeProps({
|
|
156
|
+
"viewBox": r,
|
|
157
|
+
"value": typeof labelValue === "string" || typeof labelValue === "number" ? labelValue : void 0
|
|
158
|
+
}, labelProps), null)] });
|
|
142
159
|
};
|
|
143
160
|
}
|
|
144
161
|
});
|
|
145
162
|
//#endregion
|
|
146
|
-
export {
|
|
163
|
+
export { ReferenceArea };
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
import { isNumOrStr
|
|
2
|
-
import { useIsPanorama
|
|
3
|
-
import { selectAxisScale
|
|
4
|
-
import { useAppDispatch
|
|
5
|
-
import { useViewBox
|
|
6
|
-
import { Layer
|
|
7
|
-
import { Label
|
|
8
|
-
import { addLine
|
|
9
|
-
import { useClipPathId
|
|
10
|
-
import { computed
|
|
1
|
+
import { isNumOrStr, isWellBehavedNumber } from "../../utils/validate.mjs";
|
|
2
|
+
import { useIsPanorama } from "../../context/PanoramaContextProvider.mjs";
|
|
3
|
+
import { selectAxisScale, selectXAxisSettings, selectYAxisSettings } from "../../state/selectors/axisSelectors.mjs";
|
|
4
|
+
import { useAppDispatch, useAppSelector } from "../../state/hooks.mjs";
|
|
5
|
+
import { useViewBox } from "../../context/chartLayoutContext.mjs";
|
|
6
|
+
import { Layer } from "../../container/Layer.mjs";
|
|
7
|
+
import { Label } from "../../components/label/Label.mjs";
|
|
8
|
+
import { addLine, removeLine } from "../../state/referenceElementsSlice.mjs";
|
|
9
|
+
import { useClipPathId } from "../../chart/provideClipPathId.mjs";
|
|
10
|
+
import { computed, createVNode, defineComponent, mergeProps, onMounted, onUnmounted, reactive } from "vue";
|
|
11
11
|
//#region src/cartesian/reference-line/ReferenceLine.tsx
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
if (
|
|
12
|
+
function scaleCoord(scale, value) {
|
|
13
|
+
const coord = scale(value);
|
|
14
|
+
if (!isWellBehavedNumber(coord)) return;
|
|
15
|
+
return coord + (scale.bandwidth?.() ?? 0) / 2;
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
function isInRange(scale, coord) {
|
|
18
|
+
const r = scale.range();
|
|
19
|
+
const min = Math.min(r[0], r[1]);
|
|
20
|
+
const max = Math.max(r[0], r[1]);
|
|
21
|
+
return coord >= min && coord <= max;
|
|
19
22
|
}
|
|
20
|
-
var
|
|
23
|
+
var ReferenceLine = /* @__PURE__ */ defineComponent({
|
|
21
24
|
name: "ReferenceLine",
|
|
22
25
|
props: {
|
|
23
26
|
x: {
|
|
@@ -66,78 +69,97 @@ var C = /* @__PURE__ */ g({
|
|
|
66
69
|
default: void 0
|
|
67
70
|
}
|
|
68
71
|
},
|
|
69
|
-
inheritAttrs:
|
|
70
|
-
setup(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
inheritAttrs: false,
|
|
73
|
+
setup(props, { attrs }) {
|
|
74
|
+
const dispatch = useAppDispatch();
|
|
75
|
+
const isPanorama = useIsPanorama();
|
|
76
|
+
const clipPathId = useClipPathId();
|
|
77
|
+
const viewBox = useViewBox();
|
|
78
|
+
const settings = reactive({
|
|
79
|
+
xAxisId: props.xAxisId,
|
|
80
|
+
yAxisId: props.yAxisId,
|
|
81
|
+
ifOverflow: props.ifOverflow,
|
|
82
|
+
x: props.x,
|
|
83
|
+
y: props.y
|
|
77
84
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}), y(() => {
|
|
81
|
-
w(f(O));
|
|
85
|
+
onMounted(() => {
|
|
86
|
+
dispatch(addLine(settings));
|
|
82
87
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
onUnmounted(() => {
|
|
89
|
+
dispatch(removeLine(settings));
|
|
90
|
+
});
|
|
91
|
+
const xAxisSettings = useAppSelector((state) => selectXAxisSettings(state, props.xAxisId));
|
|
92
|
+
const yAxisSettings = useAppSelector((state) => selectYAxisSettings(state, props.yAxisId));
|
|
93
|
+
const xAxisScale = useAppSelector((state) => selectAxisScale(state, "xAxis", props.xAxisId, isPanorama));
|
|
94
|
+
const yAxisScale = useAppSelector((state) => selectAxisScale(state, "yAxis", props.yAxisId, isPanorama));
|
|
95
|
+
const endPoints = computed(() => {
|
|
96
|
+
const vb = viewBox.value;
|
|
97
|
+
const xScale = xAxisScale.value;
|
|
98
|
+
const yScale = yAxisScale.value;
|
|
99
|
+
if (!vb || !xScale || !yScale) return null;
|
|
100
|
+
if (isNumOrStr(props.y)) {
|
|
101
|
+
const coord = scaleCoord(yScale, props.y);
|
|
102
|
+
if (coord == null) return null;
|
|
103
|
+
if (props.ifOverflow === "discard" && !isInRange(yScale, coord)) return null;
|
|
104
|
+
const yOrientation = yAxisSettings.value?.orientation;
|
|
105
|
+
const points = [{
|
|
106
|
+
x: vb.x + vb.width,
|
|
107
|
+
y: coord
|
|
92
108
|
}, {
|
|
93
|
-
x:
|
|
94
|
-
y:
|
|
109
|
+
x: vb.x,
|
|
110
|
+
y: coord
|
|
95
111
|
}];
|
|
96
|
-
return
|
|
112
|
+
return yOrientation === "left" ? points.reverse() : points;
|
|
97
113
|
}
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
114
|
+
if (isNumOrStr(props.x)) {
|
|
115
|
+
const coord = scaleCoord(xScale, props.x);
|
|
116
|
+
if (coord == null) return null;
|
|
117
|
+
if (props.ifOverflow === "discard" && !isInRange(xScale, coord)) return null;
|
|
118
|
+
const xOrientation = xAxisSettings.value?.orientation;
|
|
119
|
+
const points = [{
|
|
120
|
+
x: coord,
|
|
121
|
+
y: vb.y + vb.height
|
|
104
122
|
}, {
|
|
105
|
-
x:
|
|
106
|
-
y:
|
|
123
|
+
x: coord,
|
|
124
|
+
y: vb.y
|
|
107
125
|
}];
|
|
108
|
-
return
|
|
126
|
+
return xOrientation === "top" ? points.reverse() : points;
|
|
109
127
|
}
|
|
110
128
|
return null;
|
|
111
129
|
});
|
|
112
130
|
return () => {
|
|
113
|
-
|
|
114
|
-
if (!
|
|
115
|
-
|
|
116
|
-
if (!
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
131
|
+
const pts = endPoints.value;
|
|
132
|
+
if (!pts || pts.length < 2) return null;
|
|
133
|
+
const [p1, p2] = pts;
|
|
134
|
+
if (!isWellBehavedNumber(p1.x) || !isWellBehavedNumber(p1.y) || !isWellBehavedNumber(p2.x) || !isWellBehavedNumber(p2.y)) return null;
|
|
135
|
+
const clipPath = props.ifOverflow === "hidden" ? `url(#${clipPathId})` : void 0;
|
|
136
|
+
const svgAttrs = {
|
|
137
|
+
...attrs,
|
|
138
|
+
stroke: props.stroke,
|
|
139
|
+
"stroke-width": props.strokeWidth,
|
|
140
|
+
fill: props.fill
|
|
141
|
+
};
|
|
142
|
+
const labelViewBox = {
|
|
143
|
+
x: Math.min(p1.x, p2.x),
|
|
144
|
+
y: Math.min(p1.y, p2.y),
|
|
145
|
+
width: Math.abs(p2.x - p1.x),
|
|
146
|
+
height: Math.abs(p2.y - p1.y)
|
|
147
|
+
};
|
|
148
|
+
const labelValue = props.label;
|
|
149
|
+
const labelProps = typeof labelValue === "object" && labelValue !== null ? labelValue : {};
|
|
150
|
+
return createVNode(Layer, { "class": ["v-charts-reference-line", props.className] }, { default: () => [createVNode("line", mergeProps(svgAttrs, {
|
|
151
|
+
"clip-path": clipPath,
|
|
152
|
+
"x1": p1.x,
|
|
153
|
+
"y1": p1.y,
|
|
154
|
+
"x2": p2.x,
|
|
155
|
+
"y2": p2.y,
|
|
156
|
+
"class": "v-charts-reference-line-line"
|
|
157
|
+
}), null), labelValue != null && labelValue !== false && createVNode(Label, mergeProps({
|
|
158
|
+
"viewBox": labelViewBox,
|
|
159
|
+
"value": typeof labelValue === "string" || typeof labelValue === "number" ? labelValue : void 0
|
|
160
|
+
}, labelProps), null)] });
|
|
139
161
|
};
|
|
140
162
|
}
|
|
141
163
|
});
|
|
142
164
|
//#endregion
|
|
143
|
-
export {
|
|
165
|
+
export { ReferenceLine };
|