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
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { hierarchy, treemap, treemapSquarify } from "d3-hierarchy";
|
|
2
|
+
//#region src/chart/treemapUtils.ts
|
|
3
|
+
function computeTreemapLayout(options) {
|
|
4
|
+
const { data, width, height, dataKey, aspectRatio = 4 / 3, nameKey = "name", colorPanel } = options;
|
|
5
|
+
if (!data || data.length === 0 || width <= 0 || height <= 0) return [];
|
|
6
|
+
const root = hierarchy({ children: data }).sum((d) => {
|
|
7
|
+
if (d.children && d.children.length > 0) return 0;
|
|
8
|
+
const val = d[dataKey];
|
|
9
|
+
return typeof val === "number" && val > 0 ? val : 0;
|
|
10
|
+
}).sort((a, b) => (b.value ?? 0) - (a.value ?? 0));
|
|
11
|
+
treemap().size([width, height]).tile(treemapSquarify.ratio(aspectRatio)).round(true)(root);
|
|
12
|
+
return root.leaves().map((leaf) => {
|
|
13
|
+
const d = leaf.data;
|
|
14
|
+
let ancestor = leaf;
|
|
15
|
+
while (ancestor.depth > 1 && ancestor.parent) ancestor = ancestor.parent;
|
|
16
|
+
const rootIndex = ancestor.parent ? ancestor.parent.children.indexOf(ancestor) : 0;
|
|
17
|
+
return {
|
|
18
|
+
x: leaf.x0,
|
|
19
|
+
y: leaf.y0,
|
|
20
|
+
width: leaf.x1 - leaf.x0,
|
|
21
|
+
height: leaf.y1 - leaf.y0,
|
|
22
|
+
depth: leaf.depth,
|
|
23
|
+
name: d[nameKey] ?? "",
|
|
24
|
+
value: leaf.value ?? 0,
|
|
25
|
+
payload: d,
|
|
26
|
+
root: rootIndex,
|
|
27
|
+
color: colorPanel ? colorPanel[rootIndex % colorPanel.length] : void 0
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { computeTreemapLayout };
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import { defineComponent
|
|
1
|
+
import { defineComponent } from "vue";
|
|
2
2
|
//#region src/components/Cell.tsx
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Cell is a marker component used to define per-item colors and styles.
|
|
5
|
+
* It renders nothing — parent components (Bar, Pie, etc.) read Cell
|
|
6
|
+
* children from the default slot and apply their props by index.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* ```vue
|
|
10
|
+
* <Bar data-key="value">
|
|
11
|
+
* <Cell v-for="(entry, index) in data" :key="index" :fill="COLORS[index]" />
|
|
12
|
+
* </Bar>
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
var Cell = /* @__PURE__ */ defineComponent({
|
|
4
16
|
name: "Cell",
|
|
5
|
-
inheritAttrs:
|
|
17
|
+
inheritAttrs: false,
|
|
6
18
|
setup() {
|
|
7
19
|
return () => null;
|
|
8
20
|
}
|
|
9
21
|
});
|
|
10
22
|
//#endregion
|
|
11
|
-
export {
|
|
23
|
+
export { Cell };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { selectChartOffset } from "../state/selectors/selectChartOffset.mjs";
|
|
2
|
+
import { selectUnfilteredCartesianItems } from "../state/selectors/axisSelectors.mjs";
|
|
3
|
+
import { useAppSelector } from "../state/hooks.mjs";
|
|
4
|
+
import { useChartHeight, useChartWidth } from "../context/chartLayoutContext.mjs";
|
|
5
|
+
import { computed, defineComponent } from "vue";
|
|
6
|
+
//#region src/components/Customized.tsx
|
|
7
|
+
var Customized = /* @__PURE__ */ defineComponent({
|
|
8
|
+
name: "Customized",
|
|
9
|
+
inheritAttrs: false,
|
|
10
|
+
slots: Object,
|
|
11
|
+
setup(_props, { slots }) {
|
|
12
|
+
const chartWidth = useChartWidth();
|
|
13
|
+
const chartHeight = useChartHeight();
|
|
14
|
+
const offset = useAppSelector(selectChartOffset);
|
|
15
|
+
const cartesianItems = useAppSelector(selectUnfilteredCartesianItems);
|
|
16
|
+
const polarItems = useAppSelector((state) => state.graphicalItems.polarItems);
|
|
17
|
+
const formattedGraphicalItems = computed(() => {
|
|
18
|
+
const items = [];
|
|
19
|
+
for (const item of cartesianItems.value) items.push({
|
|
20
|
+
type: item.type,
|
|
21
|
+
dataKey: item.dataKey,
|
|
22
|
+
props: item
|
|
23
|
+
});
|
|
24
|
+
for (const item of polarItems.value) items.push({
|
|
25
|
+
type: item.type,
|
|
26
|
+
dataKey: item.dataKey,
|
|
27
|
+
props: item
|
|
28
|
+
});
|
|
29
|
+
return items;
|
|
30
|
+
});
|
|
31
|
+
return () => {
|
|
32
|
+
if (!slots.default) return null;
|
|
33
|
+
return slots.default({
|
|
34
|
+
formattedGraphicalItems: formattedGraphicalItems.value,
|
|
35
|
+
chartWidth: chartWidth.value,
|
|
36
|
+
chartHeight: chartHeight.value,
|
|
37
|
+
offset: offset.value
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
//#endregion
|
|
43
|
+
export { Customized };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Text_vue_vue_type_script_setup_true_lang_default from "./Text.vue_vue_type_script_setup_true_lang.mjs";
|
|
2
2
|
//#region src/components/Text.vue
|
|
3
|
-
var
|
|
3
|
+
var Text_default = Text_vue_vue_type_script_setup_true_lang_default;
|
|
4
4
|
//#endregion
|
|
5
|
-
export {
|
|
5
|
+
export { Text_default as default };
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { getStringSize
|
|
2
|
-
import { reduceCSSCalc
|
|
3
|
-
import { Fragment
|
|
1
|
+
import { getStringSize } from "../utils/attrs.mjs";
|
|
2
|
+
import { reduceCSSCalc } from "../utils/ReduceCSSCalc.mjs";
|
|
3
|
+
import { Fragment, computed, createElementBlock, defineComponent, normalizeStyle, openBlock, renderList, toDisplayString } from "vue";
|
|
4
4
|
//#region src/components/Text.vue?vue&type=script&setup=true&lang.ts
|
|
5
|
-
var
|
|
5
|
+
var _hoisted_1 = [
|
|
6
6
|
"x",
|
|
7
7
|
"y",
|
|
8
8
|
"transform",
|
|
9
9
|
"text-anchor",
|
|
10
10
|
"fill"
|
|
11
|
-
]
|
|
11
|
+
];
|
|
12
|
+
var _hoisted_2 = ["x", "dy"];
|
|
13
|
+
var Text_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
12
14
|
__name: "Text",
|
|
13
15
|
props: {
|
|
14
16
|
x: {
|
|
@@ -37,7 +39,7 @@ var u = [
|
|
|
37
39
|
},
|
|
38
40
|
scaleToFit: {
|
|
39
41
|
type: Boolean,
|
|
40
|
-
default:
|
|
42
|
+
default: false
|
|
41
43
|
},
|
|
42
44
|
textAnchor: {
|
|
43
45
|
type: String,
|
|
@@ -61,7 +63,7 @@ var u = [
|
|
|
61
63
|
},
|
|
62
64
|
breakAll: {
|
|
63
65
|
type: Boolean,
|
|
64
|
-
default:
|
|
66
|
+
default: false
|
|
65
67
|
},
|
|
66
68
|
maxLines: {
|
|
67
69
|
type: Number,
|
|
@@ -76,79 +78,114 @@ var u = [
|
|
|
76
78
|
default: ""
|
|
77
79
|
}
|
|
78
80
|
},
|
|
79
|
-
setup(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
setup(__props) {
|
|
82
|
+
const props = __props;
|
|
83
|
+
const BREAKING_SPACES = /[ \f\n\r\t\v\u2028\u2029]+/;
|
|
84
|
+
function calculateWordWidths(children, breakAll, style) {
|
|
85
|
+
let words = [];
|
|
86
|
+
if (children !== void 0 && children !== null) words = breakAll ? children.toString().split("") : children.toString().split(BREAKING_SPACES);
|
|
87
|
+
return {
|
|
88
|
+
wordsWithComputedWidth: words.map((word) => ({
|
|
89
|
+
word,
|
|
90
|
+
width: getStringSize(word, style).width
|
|
87
91
|
})),
|
|
88
|
-
spaceWidth:
|
|
92
|
+
spaceWidth: breakAll ? 0 : getStringSize("\xA0", style).width
|
|
89
93
|
};
|
|
90
94
|
}
|
|
91
|
-
function
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
95
|
+
function calculateWordsByLines(maxLines, value, style, breakAll, initialWordsWithComputedWidth, spaceWidth, lineWidth, scaleToFit) {
|
|
96
|
+
const shouldLimitLines = typeof maxLines === "number";
|
|
97
|
+
const text = value;
|
|
98
|
+
const calculate = (words = []) => {
|
|
99
|
+
return words.reduce((result, { word, width }) => {
|
|
100
|
+
const currentLine = result[result.length - 1];
|
|
101
|
+
if (currentLine && (lineWidth == null || scaleToFit || currentLine.width + width + spaceWidth < Number(lineWidth))) {
|
|
102
|
+
currentLine.words.push(word);
|
|
103
|
+
currentLine.width += width + spaceWidth;
|
|
104
|
+
} else result.push({
|
|
105
|
+
words: [word],
|
|
106
|
+
width
|
|
107
|
+
});
|
|
108
|
+
return result;
|
|
109
|
+
}, []);
|
|
110
|
+
};
|
|
111
|
+
const originalResult = calculate(initialWordsWithComputedWidth);
|
|
112
|
+
const findLongestLine = (words) => words.reduce((a, b) => a.width > b.width ? a : b);
|
|
113
|
+
if (!shouldLimitLines || scaleToFit) return originalResult;
|
|
114
|
+
if (!(originalResult.length > maxLines || findLongestLine(originalResult).width > Number(lineWidth))) return originalResult;
|
|
115
|
+
const suffix = "…";
|
|
116
|
+
const checkOverflow = (index) => {
|
|
117
|
+
const { wordsWithComputedWidth } = calculateWordWidths(text.slice(0, index) + suffix, breakAll, style);
|
|
118
|
+
const result = calculate(wordsWithComputedWidth);
|
|
119
|
+
return [result.length > maxLines || findLongestLine(result).width > Number(lineWidth), result];
|
|
120
|
+
};
|
|
121
|
+
let start = 0;
|
|
122
|
+
let end = text.length - 1;
|
|
123
|
+
let iterations = 0;
|
|
124
|
+
let trimmedResult;
|
|
125
|
+
while (start <= end && iterations <= text.length - 1) {
|
|
126
|
+
const middle = Math.floor((start + end) / 2);
|
|
127
|
+
const [doesPrevOverflow, result] = checkOverflow(middle - 1);
|
|
128
|
+
const [doesMiddleOverflow] = checkOverflow(middle);
|
|
129
|
+
if (!doesPrevOverflow && !doesMiddleOverflow) start = middle + 1;
|
|
130
|
+
if (doesPrevOverflow && doesMiddleOverflow) end = middle - 1;
|
|
131
|
+
if (!doesPrevOverflow && doesMiddleOverflow) {
|
|
132
|
+
trimmedResult = result;
|
|
108
133
|
break;
|
|
109
134
|
}
|
|
110
|
-
|
|
135
|
+
iterations++;
|
|
111
136
|
}
|
|
112
|
-
return
|
|
137
|
+
return trimmedResult || originalResult;
|
|
113
138
|
}
|
|
114
|
-
function
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
|
|
139
|
+
function getWordsByLines({ width, scaleToFit, value, style, breakAll, maxLines }) {
|
|
140
|
+
if (width || scaleToFit) {
|
|
141
|
+
const wordWidths = calculateWordWidths(value, breakAll, style);
|
|
142
|
+
const wordsWithComputedWidth = wordWidths.wordsWithComputedWidth;
|
|
143
|
+
const spaceWidth = wordWidths.spaceWidth;
|
|
144
|
+
return calculateWordsByLines(maxLines, value, style, breakAll, wordsWithComputedWidth, spaceWidth, width, scaleToFit);
|
|
118
145
|
}
|
|
119
|
-
return [{ words:
|
|
146
|
+
return [{ words: value !== void 0 && value !== null ? value.toString().split(BREAKING_SPACES) : [] }];
|
|
120
147
|
}
|
|
121
|
-
|
|
122
|
-
width:
|
|
123
|
-
scaleToFit:
|
|
124
|
-
value:
|
|
125
|
-
style:
|
|
126
|
-
breakAll:
|
|
127
|
-
maxLines:
|
|
128
|
-
}))
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
148
|
+
const wordsByLines = computed(() => getWordsByLines({
|
|
149
|
+
width: props.width,
|
|
150
|
+
scaleToFit: props.scaleToFit,
|
|
151
|
+
value: props.value,
|
|
152
|
+
style: props.style,
|
|
153
|
+
breakAll: props.breakAll,
|
|
154
|
+
maxLines: props.maxLines
|
|
155
|
+
}));
|
|
156
|
+
const x = computed(() => Number(props.x) + (typeof props.dx === "number" ? props.dx : 0));
|
|
157
|
+
const y = computed(() => Number(props.y) + (typeof props.dy === "number" ? props.dy : 0));
|
|
158
|
+
const startDy = computed(() => {
|
|
159
|
+
switch (props.verticalAnchor) {
|
|
160
|
+
case "start": return reduceCSSCalc(`calc(${props.capHeight})`);
|
|
161
|
+
case "middle": return reduceCSSCalc(`calc(${(wordsByLines.value.length - 1) / 2} * -${props.lineHeight} + (${props.capHeight} / 2))`);
|
|
162
|
+
default: return reduceCSSCalc(`calc(${wordsByLines.value.length - 1} * -${props.lineHeight})`);
|
|
133
163
|
}
|
|
134
|
-
}), x = r(() => {
|
|
135
|
-
let e = [];
|
|
136
|
-
return f.scaleToFit && _.value[0]?.width && f.width && e.push(`scale(${Number(f.width) / _.value[0].width})`), f.angle && e.push(`rotate(${f.angle}, ${v.value}, ${y.value})`), e.join(" ");
|
|
137
164
|
});
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
"
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
165
|
+
const transforms = computed(() => {
|
|
166
|
+
const arr = [];
|
|
167
|
+
if (props.scaleToFit && wordsByLines.value[0]?.width && props.width) arr.push(`scale(${Number(props.width) / wordsByLines.value[0].width})`);
|
|
168
|
+
if (props.angle) arr.push(`rotate(${props.angle}, ${x.value}, ${y.value})`);
|
|
169
|
+
return arr.join(" ");
|
|
170
|
+
});
|
|
171
|
+
return (_ctx, _cache) => {
|
|
172
|
+
return openBlock(), createElementBlock("text", {
|
|
173
|
+
x: x.value,
|
|
174
|
+
y: y.value,
|
|
175
|
+
transform: transforms.value || void 0,
|
|
176
|
+
"text-anchor": props.textAnchor,
|
|
177
|
+
fill: props.fill && props.fill.includes("url") ? "#808080" : props.fill,
|
|
178
|
+
class: "v-charts-text",
|
|
179
|
+
style: normalizeStyle(props.style)
|
|
180
|
+
}, [(openBlock(true), createElementBlock(Fragment, null, renderList(wordsByLines.value, (line, index) => {
|
|
181
|
+
return openBlock(), createElementBlock("tspan", {
|
|
182
|
+
key: index,
|
|
183
|
+
x: x.value,
|
|
184
|
+
dy: index === 0 ? startDy.value : props.lineHeight
|
|
185
|
+
}, toDisplayString(line.words.join(props.breakAll ? "" : " ")), 9, _hoisted_2);
|
|
186
|
+
}), 128))], 12, _hoisted_1);
|
|
187
|
+
};
|
|
151
188
|
}
|
|
152
189
|
});
|
|
153
190
|
//#endregion
|
|
154
|
-
export {
|
|
191
|
+
export { Text_vue_vue_type_script_setup_true_lang_default as default };
|