layerchart 2.0.0-next.61 → 2.0.0-next.63
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/canvas.d.ts +6 -2
- package/dist/canvas.js +6 -2
- package/dist/components/Arc/Arc.base.svelte +49 -11
- package/dist/components/Arc/Arc.shared.svelte.d.ts +2 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-full-circle--360-degree-range--1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-full-circle--360-degree-range--2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-innerRadius-of-0--pie-slice--1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-innerRadius-of-0--pie-slice--2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-negative-domain-values-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-negative-domain-values-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-partial-arc--e-g---180-degrees--1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-partial-arc--e-g---180-degrees--2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-value-at-max-domain-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-value-at-max-domain-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-value-below-domain-min-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-value-below-domain-min-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-value-exceeding-domain-max-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-value-exceeding-domain-max-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-value-of-0-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-edge-cases-should-handle-value-of-0-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-events-should-handle-pointer-enter-events-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-events-should-handle-pointer-enter-events-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-events-should-handle-pointer-move-events-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-events-should-handle-pointer-move-events-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-events-should-handle-touch-move-events-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-events-should-handle-touch-move-events-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-custom-class-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-custom-class-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-fill-color-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-fill-color-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-fillOpacity-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-fillOpacity-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-offset-to-arc-position-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-offset-to-arc-position-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-opacity-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-opacity-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-stroke-color-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-stroke-color-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-strokeWidth-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-strokeWidth-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-zero-offset-by-default-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-apply-zero-offset-by-default-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-call-tooltip-hide-on-pointer-leave-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-call-tooltip-hide-on-pointer-leave-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-call-tooltip-show-on-pointer-enter-with-data-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-call-tooltip-show-on-pointer-enter-with-data-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-handle-custom-start-angle-in-range-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-handle-custom-start-angle-in-range-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-have-stroke--none--by-default-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-have-stroke--none--by-default-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-an-arc-path-with-value-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-an-arc-path-with-value-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-when-track-prop-is-provided-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-when-track-prop-is-provided-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-custom-class-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-custom-class-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackCornerRadius-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackCornerRadius-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackEndAngle-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackEndAngle-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackInnerRadius-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackInnerRadius-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackInnerRadius-and-trackOuterRadius-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackInnerRadius-and-trackOuterRadius-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackOuterRadius-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackOuterRadius-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackPadAngle-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackPadAngle-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackStartAngle-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackStartAngle-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackStartAngle-and-trackEndAngle-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-track-with-trackStartAngle-and-trackEndAngle-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-both-startAngle-and-endAngle-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-both-startAngle-and-endAngle-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-cornerRadius-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-cornerRadius-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-custom-domain-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-custom-domain-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-custom-domain-and-range-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-custom-domain-and-range-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-custom-range-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-custom-range-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-endAngle-in-radians-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-endAngle-in-radians-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-innerRadius-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-innerRadius-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-innerRadius-and-outerRadius-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-innerRadius-and-outerRadius-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-outerRadius-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-outerRadius-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-padAngle-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-padAngle-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-startAngle-in-radians-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-props-should-render-with-startAngle-in-radians-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-should-render-Arc-element-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-should-render-Arc-element-2.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-should-render-track-1.png +0 -0
- package/dist/components/Arc/__screenshots__/Arc.svelte.test.ts/Arc-should-render-track-2.png +0 -0
- package/dist/components/ArcLabel/ArcLabel.shared.svelte.d.ts +1 -0
- package/dist/components/{ArcLabel.svelte.test.js → ArcLabel/ArcLabel.svelte.test.js} +3 -3
- package/dist/components/ArcLabel/__screenshots__/ArcLabel.svelte.test.ts/ArcLabel-renders-a-text-element-with-the-supplied-value-at-the-centroid-1.png +0 -0
- package/dist/components/ArcLabel/__screenshots__/ArcLabel.svelte.test.ts/ArcLabel-renders-a-text-element-with-the-supplied-value-at-the-centroid-2.png +0 -0
- package/dist/components/Blur/Blur.canvas.svelte +25 -0
- package/dist/components/Blur/Blur.canvas.svelte.d.ts +4 -0
- package/dist/components/Blur/Blur.html.svelte +11 -0
- package/dist/components/Blur/Blur.html.svelte.d.ts +4 -0
- package/dist/components/{Blur.svelte.d.ts → Blur/Blur.shared.svelte.d.ts} +3 -5
- package/dist/components/Blur/Blur.svelte +23 -0
- package/dist/components/Blur/Blur.svelte.d.ts +4 -0
- package/dist/components/Blur/Blur.svg.svelte +24 -0
- package/dist/components/Blur/Blur.svg.svelte.d.ts +4 -0
- package/dist/components/Chart/Chart.base.svelte +13 -7
- package/dist/components/Chart/ChartCore.svelte.test.d.ts +1 -0
- package/dist/components/{ChartCore.svelte.test.js → Chart/ChartCore.svelte.test.js} +1 -1
- package/dist/components/Circle/Circle.shared.svelte.js +24 -5
- package/dist/components/Circle/Circle.svelte.test.js +70 -0
- package/dist/components/Dodge/Dodge.shared.svelte.d.ts +132 -0
- package/dist/components/Dodge/Dodge.shared.svelte.js +240 -0
- package/dist/components/Dodge/Dodge.svelte +88 -0
- package/dist/components/Dodge/Dodge.svelte.d.ts +27 -0
- package/dist/components/Dodge/Dodge.test.d.ts +1 -0
- package/dist/components/Dodge/Dodge.test.js +128 -0
- package/dist/components/Image/Image.html.svelte +0 -8
- package/dist/components/Image/Image.svg.svelte +1 -9
- package/dist/components/Link/Link.base.svelte +15 -9
- package/dist/components/Path/Path.canvas.svelte +5 -2
- package/dist/components/Path/Path.shared.svelte.d.ts +17 -4
- package/dist/components/Path/Path.shared.svelte.js +26 -8
- package/dist/components/Path/Path.svg.svelte +75 -60
- package/dist/components/Pattern/Pattern.canvas.svelte +4 -1
- package/dist/components/Pattern/Pattern.shared.svelte.d.ts +31 -2
- package/dist/components/Pattern/Pattern.shared.svelte.js +20 -1
- package/dist/components/Pattern/Pattern.svg.svelte +17 -1
- package/dist/components/Raster/Raster.base.svelte +2 -8
- package/dist/components/Rect/Rect.canvas.svelte +2 -4
- package/dist/components/Rect/Rect.canvas.svelte.d.ts +1 -1
- package/dist/components/Rect/Rect.html.svelte +3 -9
- package/dist/components/Rect/Rect.html.svelte.d.ts +1 -1
- package/dist/components/Rect/Rect.shared.svelte.d.ts +5 -2
- package/dist/components/Rect/Rect.shared.svelte.js +26 -13
- package/dist/components/Rect/Rect.svelte.test.js +45 -0
- package/dist/components/Rect/Rect.svg.svelte +36 -21
- package/dist/components/Rect/Rect.svg.svelte.d.ts +1 -1
- package/dist/components/RectClipPath/RectClipPath.base.svelte +25 -1
- package/dist/components/RectClipPath/RectClipPath.shared.svelte.d.ts +8 -0
- package/dist/components/Spline/Spline.base.svelte +3 -2
- package/dist/components/Text/Text.canvas.svelte +9 -0
- package/dist/components/Text/Text.html.svelte +6 -0
- package/dist/components/Text/Text.shared.svelte.d.ts +25 -2
- package/dist/components/Text/Text.shared.svelte.js +36 -5
- package/dist/components/Text/Text.svelte.test.js +40 -0
- package/dist/components/Text/Text.svg.svelte +7 -1
- package/dist/components/Trail/Trail.base.svelte +10 -7
- package/dist/components/Waffle/Waffle.shared.svelte.d.ts +182 -0
- package/dist/components/Waffle/Waffle.shared.svelte.js +300 -0
- package/dist/components/Waffle/Waffle.svelte +148 -0
- package/dist/components/Waffle/Waffle.svelte.d.ts +5 -0
- package/dist/components/charts/__screenshots__/ArcChart.svelte.test.ts/ArcChart-uses-the-chart-value-accessor-for-explicit-per-series-tooltip-values-1.png +0 -0
- package/dist/components/charts/__screenshots__/ArcChart.svelte.test.ts/ArcChart-uses-the-chart-value-accessor-for-explicit-per-series-tooltip-values-2.png +0 -0
- package/dist/components/charts/__screenshots__/BarChart.svelte.test.ts/BarChart-legend-series-toggle-adjusts-group-scale-should-adjust-grouped-bar-widths-when-series-are-toggled-via-legend-1.png +0 -0
- package/dist/components/charts/__screenshots__/PieChart.svelte.test.ts/PieChart-uses-hovered-slice-identity-for-implicit-tooltip-series-1.png +0 -0
- package/dist/components/charts/__screenshots__/PieChart.svelte.test.ts/PieChart-uses-hovered-slice-identity-for-implicit-tooltip-series-2.png +0 -0
- package/dist/components/index.d.ts +6 -2
- package/dist/components/index.js +6 -2
- package/dist/html.d.ts +6 -2
- package/dist/html.js +6 -2
- package/dist/states/chart.svelte.d.ts +4 -2
- package/dist/states/chart.svelte.js +53 -22
- package/dist/states/chart.svelte.test.js +54 -1
- package/dist/states/series.svelte.js +9 -13
- package/dist/states/series.svelte.test.js +5 -1
- package/dist/svg.d.ts +6 -2
- package/dist/svg.js +6 -2
- package/dist/utils/canvas.js +54 -13
- package/dist/utils/canvas.svelte.test.js +44 -0
- package/dist/utils/download.d.ts +5 -3
- package/dist/utils/download.js +36 -16
- package/dist/utils/stack.js +10 -2
- package/package.json +1 -1
- package/dist/components/Blur.svelte +0 -49
- /package/dist/components/{ArcLabel.svelte.test.d.ts → ArcLabel/ArcLabel.svelte.test.d.ts} +0 -0
- /package/dist/components/{ChartCore.svelte.test.d.ts → Blur/Blur.shared.svelte.js} +0 -0
|
@@ -16,11 +16,7 @@
|
|
|
16
16
|
import { max, min } from 'd3-array';
|
|
17
17
|
import { rgb } from 'd3-color';
|
|
18
18
|
|
|
19
|
-
import {
|
|
20
|
-
accessor as resolveAccessor,
|
|
21
|
-
chartDataArray,
|
|
22
|
-
type Accessor,
|
|
23
|
-
} from '../../utils/common.js';
|
|
19
|
+
import { accessor as resolveAccessor, chartDataArray, type Accessor } from '../../utils/common.js';
|
|
24
20
|
import { getChartContext } from '../../contexts/chart.js';
|
|
25
21
|
import { getGeoContext } from '../../contexts/geo.js';
|
|
26
22
|
import { gridCellCenterToBounds, resolveRasterBounds } from '../../utils/index.js';
|
|
@@ -89,9 +85,7 @@
|
|
|
89
85
|
if (!ctx.width || !ctx.height) return new Float64Array(0);
|
|
90
86
|
|
|
91
87
|
if (isGridMode) {
|
|
92
|
-
return dataProp instanceof Float64Array
|
|
93
|
-
? dataProp
|
|
94
|
-
: Float64Array.from(dataProp as number[]);
|
|
88
|
+
return dataProp instanceof Float64Array ? dataProp : Float64Array.from(dataProp as number[]);
|
|
95
89
|
}
|
|
96
90
|
|
|
97
91
|
if (typeof valueProp === 'function' && valueProp.length >= 2) {
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
export type {
|
|
3
|
-
RectProps,
|
|
4
|
-
RectPropsWithoutHTML,
|
|
5
|
-
} from './Rect.shared.svelte.js';
|
|
2
|
+
export type { RectProps, RectPropsWithoutHTML } from './Rect.shared.svelte.js';
|
|
6
3
|
</script>
|
|
7
4
|
|
|
8
5
|
<script lang="ts">
|
|
@@ -90,6 +87,7 @@
|
|
|
90
87
|
height: item.height,
|
|
91
88
|
rx: c.rx,
|
|
92
89
|
ry: c.ry,
|
|
90
|
+
corners: c.resolveCorners(item.width, item.height),
|
|
93
91
|
},
|
|
94
92
|
styleOpts
|
|
95
93
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { RectProps, RectPropsWithoutHTML
|
|
1
|
+
export type { RectProps, RectPropsWithoutHTML } from './Rect.shared.svelte.js';
|
|
2
2
|
import { type RectProps } from './Rect.shared.svelte.js';
|
|
3
3
|
declare const Rect: import("svelte").Component<RectProps, {}, "">;
|
|
4
4
|
type Rect = ReturnType<typeof Rect>;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
export type {
|
|
3
|
-
RectProps,
|
|
4
|
-
RectPropsWithoutHTML,
|
|
5
|
-
} from './Rect.shared.svelte.js';
|
|
2
|
+
export type { RectProps, RectPropsWithoutHTML } from './Rect.shared.svelte.js';
|
|
6
3
|
</script>
|
|
7
4
|
|
|
8
5
|
<script lang="ts">
|
|
@@ -11,10 +8,7 @@
|
|
|
11
8
|
import { resolveColorProp, resolveStyleProp } from '../../utils/dataProp.js';
|
|
12
9
|
import { RectState, rectMarkInfo, type RectProps } from './Rect.shared.svelte.js';
|
|
13
10
|
|
|
14
|
-
let {
|
|
15
|
-
children,
|
|
16
|
-
...rest
|
|
17
|
-
}: RectProps = $props();
|
|
11
|
+
let { children, ...rest }: RectProps = $props();
|
|
18
12
|
|
|
19
13
|
const c = new RectState(() => rest as RectProps);
|
|
20
14
|
|
|
@@ -55,7 +49,7 @@
|
|
|
55
49
|
style:border-width={resolvedBorderWidth}
|
|
56
50
|
style:border-style={c.dashArrayResolved ? 'dashed' : 'solid'}
|
|
57
51
|
style:border-color={resolvedStroke}
|
|
58
|
-
style:border-radius=
|
|
52
|
+
style:border-radius={c.borderRadius(item.width, item.height) ?? `${c.rx}px`}
|
|
59
53
|
class={cls('lc-rect', resolvedClass)}
|
|
60
54
|
></div>
|
|
61
55
|
{/each}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { RectProps, RectPropsWithoutHTML
|
|
1
|
+
export type { RectProps, RectPropsWithoutHTML } from './Rect.shared.svelte.js';
|
|
2
2
|
import { type RectProps } from './Rect.shared.svelte.js';
|
|
3
3
|
declare const Rect: import("svelte").Component<RectProps, {}, "">;
|
|
4
4
|
type Rect = ReturnType<typeof Rect>;
|
|
@@ -42,14 +42,14 @@ export type RectPropsWithoutHTML = {
|
|
|
42
42
|
*
|
|
43
43
|
* @default 0
|
|
44
44
|
*/
|
|
45
|
-
width?:
|
|
45
|
+
width?: DataProp;
|
|
46
46
|
initialWidth?: number;
|
|
47
47
|
/**
|
|
48
48
|
* The height of the rectangle (pixels).
|
|
49
49
|
*
|
|
50
50
|
* @default 0
|
|
51
51
|
*/
|
|
52
|
-
height?:
|
|
52
|
+
height?: DataProp;
|
|
53
53
|
initialHeight?: number;
|
|
54
54
|
/**
|
|
55
55
|
* Left/start x edge (data mode).
|
|
@@ -158,6 +158,9 @@ export declare class RectState {
|
|
|
158
158
|
get motionY(): any;
|
|
159
159
|
get motionWidth(): any;
|
|
160
160
|
get motionHeight(): any;
|
|
161
|
+
resolveCorners(width: number, height: number): import("../../utils/rect.svelte.js").CornerRadii | undefined;
|
|
162
|
+
roundedRectPath(x: number, y: number, width: number, height: number): string | undefined;
|
|
163
|
+
borderRadius(width: number, height: number): string | undefined;
|
|
161
164
|
resolvedCorners: import("../../utils/rect.svelte.js").CornerRadii | undefined;
|
|
162
165
|
borderRadiusStyle: string | undefined;
|
|
163
166
|
pixelPathData: string | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { untrack } from 'svelte';
|
|
2
|
-
import { hasAnyDataProp, resolveDataProp, resolveGeoDataPair
|
|
2
|
+
import { hasAnyDataProp, resolveDataProp, resolveGeoDataPair } from '../../utils/dataProp.js';
|
|
3
3
|
import { chartDataArray } from '../../utils/common.js';
|
|
4
4
|
import { resolveCorners, cornersUniform, resolveInsets, } from '../../utils/rect.svelte.js';
|
|
5
5
|
import { roundedRectPath, parseDashArray } from '../../utils/path.js';
|
|
@@ -32,7 +32,7 @@ export class RectState {
|
|
|
32
32
|
geo = getGeoContext();
|
|
33
33
|
// Data mode detection
|
|
34
34
|
hasEdgeProps = $derived(hasAnyDataProp(this.#getProps().x0, this.#getProps().y0, this.#getProps().x1, this.#getProps().y1));
|
|
35
|
-
dataMode = $derived(hasAnyDataProp(this.#getProps().x, this.#getProps().y) || this.hasEdgeProps);
|
|
35
|
+
dataMode = $derived(hasAnyDataProp(this.#getProps().x, this.#getProps().y, this.#getProps().width, this.#getProps().height) || this.hasEdgeProps);
|
|
36
36
|
// Data resolution
|
|
37
37
|
#resolvedData = $derived(this.dataMode ? (this.#getProps().data ?? chartDataArray(this.chartCtx.data)) : []);
|
|
38
38
|
resolvedItems = $derived.by(() => {
|
|
@@ -92,8 +92,10 @@ export class RectState {
|
|
|
92
92
|
return {
|
|
93
93
|
x: resolvedX + resolvedInsets.left,
|
|
94
94
|
y: resolvedY + resolvedInsets.top,
|
|
95
|
-
width: Math.max(0, (props.width
|
|
96
|
-
height: Math.max(0, (props.height
|
|
95
|
+
width: Math.max(0, resolveDataProp(props.width, d, undefined, 0) - resolvedInsets.left - resolvedInsets.right),
|
|
96
|
+
height: Math.max(0, resolveDataProp(props.height, d, undefined, 0) -
|
|
97
|
+
resolvedInsets.top -
|
|
98
|
+
resolvedInsets.bottom),
|
|
97
99
|
};
|
|
98
100
|
}
|
|
99
101
|
}
|
|
@@ -133,11 +135,24 @@ export class RectState {
|
|
|
133
135
|
return this.#motionHeight.current;
|
|
134
136
|
}
|
|
135
137
|
// Resolved per-corner radii (clamped to current bounds)
|
|
136
|
-
|
|
138
|
+
resolveCorners(width, height) {
|
|
137
139
|
const corners = this.#getProps().corners;
|
|
138
140
|
if (corners === undefined)
|
|
139
141
|
return undefined;
|
|
140
|
-
return resolveCorners(corners,
|
|
142
|
+
return resolveCorners(corners, width, height);
|
|
143
|
+
}
|
|
144
|
+
roundedRectPath(x, y, width, height) {
|
|
145
|
+
const corners = this.resolveCorners(width, height);
|
|
146
|
+
if (!corners || !this.cornersNonUniform)
|
|
147
|
+
return undefined;
|
|
148
|
+
return roundedRectPath(x, y, width, height, corners);
|
|
149
|
+
}
|
|
150
|
+
borderRadius(width, height) {
|
|
151
|
+
const corners = this.resolveCorners(width, height);
|
|
152
|
+
return corners ? corners.map((c) => `${c}px`).join(' ') : undefined;
|
|
153
|
+
}
|
|
154
|
+
resolvedCorners = $derived.by(() => {
|
|
155
|
+
return this.resolveCorners(this.motionWidth, this.motionHeight);
|
|
141
156
|
});
|
|
142
157
|
borderRadiusStyle = $derived(this.resolvedCorners ? this.resolvedCorners.map((c) => `${c}px`).join(' ') : undefined);
|
|
143
158
|
pixelPathData = $derived.by(() => {
|
|
@@ -158,9 +173,7 @@ export class RectState {
|
|
|
158
173
|
staticStrokeWidth = $derived(typeof this.#getProps().strokeWidth === 'number'
|
|
159
174
|
? this.#getProps().strokeWidth
|
|
160
175
|
: undefined);
|
|
161
|
-
staticOpacity = $derived(typeof this.#getProps().opacity === 'number'
|
|
162
|
-
? this.#getProps().opacity
|
|
163
|
-
: undefined);
|
|
176
|
+
staticOpacity = $derived(typeof this.#getProps().opacity === 'number' ? this.#getProps().opacity : undefined);
|
|
164
177
|
staticClassName = $derived(typeof this.#getProps().class === 'string' ? this.#getProps().class : undefined);
|
|
165
178
|
// Match SVG's implicit `stroke-width: 1` default
|
|
166
179
|
staticBorderWidth = $derived.by(() => {
|
|
@@ -176,13 +189,13 @@ export class RectState {
|
|
|
176
189
|
const initial = getProps();
|
|
177
190
|
const initialX = initial.initialX ?? (typeof initial.x === 'number' ? initial.x : 0);
|
|
178
191
|
const initialY = initial.initialY ?? (typeof initial.y === 'number' ? initial.y : 0);
|
|
179
|
-
const initialWidth = initial.initialWidth ?? initial.width
|
|
180
|
-
const initialHeight = initial.initialHeight ?? initial.height
|
|
192
|
+
const initialWidth = initial.initialWidth ?? (typeof initial.width === 'number' ? initial.width : 0);
|
|
193
|
+
const initialHeight = initial.initialHeight ?? (typeof initial.height === 'number' ? initial.height : 0);
|
|
181
194
|
const motion = initial.motion;
|
|
182
195
|
this.#motionX = createMotion(initialX, () => (typeof getProps().x === 'number' ? getProps().x : 0), motion === undefined ? undefined : parseMotionProp(motion, 'x'));
|
|
183
196
|
this.#motionY = createMotion(initialY, () => (typeof getProps().y === 'number' ? getProps().y : 0), motion === undefined ? undefined : parseMotionProp(motion, 'y'));
|
|
184
|
-
this.#motionWidth = createMotion(initialWidth, () => getProps().width
|
|
185
|
-
this.#motionHeight = createMotion(initialHeight, () => getProps().height
|
|
197
|
+
this.#motionWidth = createMotion(initialWidth, () => (typeof getProps().width === 'number' ? getProps().width : 0), motion === undefined ? undefined : parseMotionProp(motion, 'width'));
|
|
198
|
+
this.#motionHeight = createMotion(initialHeight, () => (typeof getProps().height === 'number' ? getProps().height : 0), motion === undefined ? undefined : parseMotionProp(motion, 'height'));
|
|
186
199
|
this.#dataMotionMap = createDataMotionMap(motion);
|
|
187
200
|
if (this.#dataMotionMap) {
|
|
188
201
|
const motionMap = this.#dataMotionMap;
|
|
@@ -47,6 +47,28 @@ describe('Rect', () => {
|
|
|
47
47
|
const rects = page.getByTestId(componentTestId).elements();
|
|
48
48
|
await expect.poll(() => rects.length).toBe(3);
|
|
49
49
|
});
|
|
50
|
+
it('should resolve width and height from data', async () => {
|
|
51
|
+
render(TestHarness, {
|
|
52
|
+
component: Rect,
|
|
53
|
+
chartProps: {
|
|
54
|
+
data: [{ x: 20, y: 30, width: 80, height: 40 }],
|
|
55
|
+
x: 'x',
|
|
56
|
+
y: 'y',
|
|
57
|
+
xDomain: [0, 100],
|
|
58
|
+
yDomain: [0, 100],
|
|
59
|
+
},
|
|
60
|
+
componentProps: {
|
|
61
|
+
x: 'x',
|
|
62
|
+
y: 'y',
|
|
63
|
+
width: 'width',
|
|
64
|
+
height: 'height',
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
const rect = page.getByTestId(componentTestId);
|
|
68
|
+
await expect.element(rect).toBeInTheDocument();
|
|
69
|
+
expect(rect.element()?.getAttribute('width')).toBe('80');
|
|
70
|
+
expect(rect.element()?.getAttribute('height')).toBe('40');
|
|
71
|
+
});
|
|
50
72
|
});
|
|
51
73
|
describe('data mode - colors', () => {
|
|
52
74
|
const data = [
|
|
@@ -153,6 +175,29 @@ describe('Rect', () => {
|
|
|
153
175
|
const width = Number(firstRect?.getAttribute('width'));
|
|
154
176
|
expect(width).toBeGreaterThan(0);
|
|
155
177
|
});
|
|
178
|
+
it('should render non-uniform corners from edge props', async () => {
|
|
179
|
+
render(TestHarness, {
|
|
180
|
+
component: Rect,
|
|
181
|
+
chartProps: {
|
|
182
|
+
data: [data[0]],
|
|
183
|
+
x: ['x0', 'x1'],
|
|
184
|
+
y: 'count',
|
|
185
|
+
xDomain: [0, 100],
|
|
186
|
+
yDomain: [0, 15],
|
|
187
|
+
},
|
|
188
|
+
componentProps: {
|
|
189
|
+
x0: 'x0',
|
|
190
|
+
x1: 'x1',
|
|
191
|
+
y0: (d) => 0,
|
|
192
|
+
y1: 'count',
|
|
193
|
+
corners: [12, 4, 10, 2],
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
const rect = page.getByTestId(componentTestId);
|
|
197
|
+
await expect.element(rect).toBeInTheDocument();
|
|
198
|
+
expect(rect.element()?.tagName.toLowerCase()).toBe('path');
|
|
199
|
+
expect(rect.element()?.getAttribute('d')).toContain('a');
|
|
200
|
+
});
|
|
156
201
|
it('should use explicit data prop over chart context data', async () => {
|
|
157
202
|
const explicitData = [{ x0: 0, x1: 50, count: 5 }];
|
|
158
203
|
render(TestHarness, {
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
export type {
|
|
3
|
-
RectProps,
|
|
4
|
-
RectPropsWithoutHTML,
|
|
5
|
-
} from './Rect.shared.svelte.js';
|
|
2
|
+
export type { RectProps, RectPropsWithoutHTML } from './Rect.shared.svelte.js';
|
|
6
3
|
</script>
|
|
7
4
|
|
|
8
5
|
<script lang="ts">
|
|
@@ -64,23 +61,41 @@
|
|
|
64
61
|
{@const resolvedStrokeWidth = resolveStyleProp(rest.strokeWidth, item.d)}
|
|
65
62
|
{@const resolvedOpacity = resolveStyleProp(rest.opacity, item.d)}
|
|
66
63
|
{@const resolvedClass = resolveStyleProp(rest.class, item.d)}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
64
|
+
{@const pathData = c.roundedRectPath(item.x, item.y, item.width, item.height)}
|
|
65
|
+
{#if pathData}
|
|
66
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
67
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
68
|
+
<path
|
|
69
|
+
{...rest as unknown as SVGAttributes<SVGPathElement>}
|
|
70
|
+
d={pathData}
|
|
71
|
+
fill={resolvedFill}
|
|
72
|
+
fill-opacity={resolvedFillOpacity}
|
|
73
|
+
stroke={resolvedStroke}
|
|
74
|
+
stroke-opacity={resolvedStrokeOpacity}
|
|
75
|
+
stroke-width={resolvedStrokeWidth}
|
|
76
|
+
opacity={resolvedOpacity}
|
|
77
|
+
stroke-dasharray={c.dashArrayAttr}
|
|
78
|
+
class={cls('lc-rect', resolvedClass)}
|
|
79
|
+
/>
|
|
80
|
+
{:else}
|
|
81
|
+
<rect
|
|
82
|
+
{...rest as any}
|
|
83
|
+
x={item.x}
|
|
84
|
+
y={item.y}
|
|
85
|
+
width={item.width}
|
|
86
|
+
height={item.height}
|
|
87
|
+
fill={resolvedFill}
|
|
88
|
+
fill-opacity={resolvedFillOpacity}
|
|
89
|
+
stroke={resolvedStroke}
|
|
90
|
+
stroke-opacity={resolvedStrokeOpacity}
|
|
91
|
+
stroke-width={resolvedStrokeWidth}
|
|
92
|
+
opacity={resolvedOpacity}
|
|
93
|
+
rx={c.rx}
|
|
94
|
+
ry={c.ry}
|
|
95
|
+
stroke-dasharray={c.dashArrayAttr}
|
|
96
|
+
class={cls('lc-rect', resolvedClass)}
|
|
97
|
+
/>
|
|
98
|
+
{/if}
|
|
84
99
|
{/each}
|
|
85
100
|
{:else if c.pixelPathData}
|
|
86
101
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { RectProps, RectPropsWithoutHTML
|
|
1
|
+
export type { RectProps, RectPropsWithoutHTML } from './Rect.shared.svelte.js';
|
|
2
2
|
import { type RectProps } from './Rect.shared.svelte.js';
|
|
3
3
|
declare const Rect: import("svelte").Component<RectProps, {}, "ref">;
|
|
4
4
|
type Rect = ReturnType<typeof Rect>;
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
<script lang="ts">
|
|
13
13
|
import { createId } from '../../utils/createId.js';
|
|
14
|
+
import { createMotion, parseMotionProp } from '../../utils/motion.svelte.js';
|
|
14
15
|
|
|
15
16
|
const uid = $props.id();
|
|
16
17
|
|
|
@@ -19,14 +20,37 @@
|
|
|
19
20
|
id = createId('clipPath-', uid),
|
|
20
21
|
x = 0,
|
|
21
22
|
y = 0,
|
|
23
|
+
initialX,
|
|
24
|
+
initialY,
|
|
22
25
|
width,
|
|
23
26
|
height,
|
|
27
|
+
initialWidth,
|
|
28
|
+
initialHeight,
|
|
24
29
|
disabled = false,
|
|
25
30
|
invert = false,
|
|
31
|
+
motion,
|
|
26
32
|
children: childrenProp,
|
|
27
33
|
}: RectClipPathBaseProps = $props();
|
|
28
34
|
|
|
29
|
-
|
|
35
|
+
// When `motion` is undefined `createMotion` returns a passthrough that just
|
|
36
|
+
// reads the getter, so we can call it unconditionally and let the fast path
|
|
37
|
+
// handle the no-motion case.
|
|
38
|
+
const motionX = createMotion(initialX ?? x, () => x, motion && parseMotionProp(motion, 'x'));
|
|
39
|
+
const motionY = createMotion(initialY ?? y, () => y, motion && parseMotionProp(motion, 'y'));
|
|
40
|
+
const motionWidth = createMotion(
|
|
41
|
+
initialWidth ?? width,
|
|
42
|
+
() => width,
|
|
43
|
+
motion && parseMotionProp(motion, 'width')
|
|
44
|
+
);
|
|
45
|
+
const motionHeight = createMotion(
|
|
46
|
+
initialHeight ?? height,
|
|
47
|
+
() => height,
|
|
48
|
+
motion && parseMotionProp(motion, 'height')
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const path = $derived(
|
|
52
|
+
`M${motionX.current},${motionY.current} h${motionWidth.current} v${motionHeight.current} h${-motionWidth.current} Z`
|
|
53
|
+
);
|
|
30
54
|
</script>
|
|
31
55
|
|
|
32
56
|
<ClipPath {id} {disabled} {invert} {path}>
|
|
@@ -8,12 +8,20 @@ export type BaseRectClipPathPropsWithoutHTML = {
|
|
|
8
8
|
id?: string;
|
|
9
9
|
/** The x position of the clipPath. @default 0 */
|
|
10
10
|
x?: number;
|
|
11
|
+
/** The initial x position (used as the animation start when `motion` is set). @default x */
|
|
12
|
+
initialX?: number;
|
|
11
13
|
/** The y position of the clipPath. @default 0 */
|
|
12
14
|
y?: number;
|
|
15
|
+
/** The initial y position (used as the animation start when `motion` is set). @default y */
|
|
16
|
+
initialY?: number;
|
|
13
17
|
/** The width of the clipPath. @required */
|
|
14
18
|
width: number;
|
|
19
|
+
/** The initial width (used as the animation start when `motion` is set). @default width */
|
|
20
|
+
initialWidth?: number;
|
|
15
21
|
/** The height of the clipPath. @required */
|
|
16
22
|
height: number;
|
|
23
|
+
/** The initial height (used as the animation start when `motion` is set). @default height */
|
|
24
|
+
initialHeight?: number;
|
|
17
25
|
/** Whether to disable clipping (show all). @default false */
|
|
18
26
|
disabled?: boolean;
|
|
19
27
|
/** Invert the clip — content renders *outside* the rect. @default false */
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
pathData={seg.d}
|
|
40
40
|
stroke={seg.stroke}
|
|
41
41
|
fill={seg.fill}
|
|
42
|
-
opacity={seg.opacity ?? c.seriesOpacity}
|
|
42
|
+
opacity={seg.opacity ?? (c.seriesOpacity === 1 ? undefined : c.seriesOpacity)}
|
|
43
43
|
{...c.series?.props}
|
|
44
44
|
{...restProps}
|
|
45
45
|
/>
|
|
@@ -49,7 +49,8 @@
|
|
|
49
49
|
pathData={c.isTweened ? c.tweenedPath : c.d}
|
|
50
50
|
stroke={(typeof stroke === 'string' ? stroke : undefined) ?? c.series?.color}
|
|
51
51
|
fill={typeof fill === 'string' ? fill : undefined}
|
|
52
|
-
opacity={(typeof opacity === 'number' ? opacity : undefined) ??
|
|
52
|
+
opacity={(typeof opacity === 'number' ? opacity : undefined) ??
|
|
53
|
+
(c.seriesOpacity === 1 ? undefined : c.seriesOpacity)}
|
|
53
54
|
{...c.series?.props}
|
|
54
55
|
{...restProps}
|
|
55
56
|
/>
|
|
@@ -50,6 +50,14 @@
|
|
|
50
50
|
strokeWidth: itemStrokeWidth ?? c.staticStrokeWidth,
|
|
51
51
|
opacity: itemOpacity ?? c.staticOpacity,
|
|
52
52
|
paintOrder: 'stroke',
|
|
53
|
+
...(rest.fontSize != null
|
|
54
|
+
? {
|
|
55
|
+
fontSize:
|
|
56
|
+
typeof rest.fontSize === 'number'
|
|
57
|
+
? `${rest.fontSize}px`
|
|
58
|
+
: rest.fontSize,
|
|
59
|
+
}
|
|
60
|
+
: {}),
|
|
53
61
|
...((rest.textAnchor ?? 'start') !== 'start'
|
|
54
62
|
? { textAnchor: rest.textAnchor }
|
|
55
63
|
: {}),
|
|
@@ -195,6 +203,7 @@
|
|
|
195
203
|
rest.class,
|
|
196
204
|
c.truncateConfig,
|
|
197
205
|
rest.rotate,
|
|
206
|
+
rest.fontSize,
|
|
198
207
|
rest.lineHeight,
|
|
199
208
|
rest.textAnchor,
|
|
200
209
|
rest.verticalAnchor,
|
|
@@ -46,6 +46,9 @@
|
|
|
46
46
|
{textAnchor === 'middle' ? 'center' : textAnchor === 'end' ? 'right' : 'left'}"
|
|
47
47
|
style:white-space="pre-wrap"
|
|
48
48
|
style:line-height={rest.lineHeight ?? '1em'}
|
|
49
|
+
style:font-size={typeof rest.fontSize === 'number'
|
|
50
|
+
? `${rest.fontSize}px`
|
|
51
|
+
: rest.fontSize}
|
|
49
52
|
style:color={resolvedFill}
|
|
50
53
|
style:opacity={resolvedOpacity ?? resolvedFillOpacity}
|
|
51
54
|
class={['lc-text', resolvedClass]}
|
|
@@ -74,6 +77,9 @@
|
|
|
74
77
|
{textAnchor === 'middle' ? 'center' : textAnchor === 'end' ? 'right' : 'left'}"
|
|
75
78
|
style:white-space="pre-wrap"
|
|
76
79
|
style:line-height={rest.lineHeight ?? '1em'}
|
|
80
|
+
style:font-size={typeof rest.fontSize === 'number'
|
|
81
|
+
? `${rest.fontSize}px`
|
|
82
|
+
: rest.fontSize}
|
|
77
83
|
style:color={c.staticFill}
|
|
78
84
|
style:opacity={c.staticOpacity ?? c.staticFillOpacity}
|
|
79
85
|
class={['lc-text', c.staticClassName]}
|
|
@@ -88,8 +88,20 @@ export type TextPropsWithoutHTML = {
|
|
|
88
88
|
*/
|
|
89
89
|
lineHeight?: string;
|
|
90
90
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
91
|
+
* Font size of the text. A number is treated as pixels; a string passes
|
|
92
|
+
* through (e.g. `'12px'`, `'1.25em'`). When set, vertical centering math
|
|
93
|
+
* derives `capHeight` from this value automatically (as `fontSize * 0.71`),
|
|
94
|
+
* so per-item scaled labels with `verticalAnchor="middle"` align correctly
|
|
95
|
+
* without an explicit `capHeight` override.
|
|
96
|
+
*/
|
|
97
|
+
fontSize?: number | string;
|
|
98
|
+
/**
|
|
99
|
+
* Cap height of the text — used by vertical anchor math to align the text
|
|
100
|
+
* to its visual center (as opposed to the font box). Defaults to `0.71em`,
|
|
101
|
+
* but if `fontSize` is set, defaults to `fontSize * 0.71` so centering
|
|
102
|
+
* stays correct as text scales.
|
|
103
|
+
*
|
|
104
|
+
* @default '0.71em' (or `fontSize * 0.71` when `fontSize` is set)
|
|
93
105
|
*/
|
|
94
106
|
capHeight?: string;
|
|
95
107
|
/**
|
|
@@ -182,6 +194,17 @@ export declare function getPathLength(pathRef: SVGPathElement | undefined): numb
|
|
|
182
194
|
* Convert css value to pixel value (ex. 0.71em => 11.36)
|
|
183
195
|
*/
|
|
184
196
|
export declare function getPixelValue(cssValue: number | string): number;
|
|
197
|
+
/**
|
|
198
|
+
* Resolve the cap-height used by vertical-anchor math.
|
|
199
|
+
*
|
|
200
|
+
* Priority:
|
|
201
|
+
* 1. Explicit `capHeight` prop
|
|
202
|
+
* 2. `fontSize * 0.71` when `fontSize` is set (keeps centering correct as
|
|
203
|
+
* labels scale per-item)
|
|
204
|
+
* 3. `'0.71em'` (legacy default — only correct for ~16px text since
|
|
205
|
+
* `getPixelValue` resolves `em` against 16, not the actual font-size)
|
|
206
|
+
*/
|
|
207
|
+
export declare function resolveCapHeight(capHeight: string | undefined, fontSize: number | string | undefined): number | string;
|
|
185
208
|
export declare function isValidXOrY(xOrY: string | number | undefined): boolean;
|
|
186
209
|
/** Build the standard `markInfo` payload used by every Text variant. */
|
|
187
210
|
export declare function textMarkInfo(props: TextProps, dataMode: boolean): {
|
|
@@ -58,6 +58,23 @@ export function getPixelValue(cssValue) {
|
|
|
58
58
|
return 0;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Resolve the cap-height used by vertical-anchor math.
|
|
63
|
+
*
|
|
64
|
+
* Priority:
|
|
65
|
+
* 1. Explicit `capHeight` prop
|
|
66
|
+
* 2. `fontSize * 0.71` when `fontSize` is set (keeps centering correct as
|
|
67
|
+
* labels scale per-item)
|
|
68
|
+
* 3. `'0.71em'` (legacy default — only correct for ~16px text since
|
|
69
|
+
* `getPixelValue` resolves `em` against 16, not the actual font-size)
|
|
70
|
+
*/
|
|
71
|
+
export function resolveCapHeight(capHeight, fontSize) {
|
|
72
|
+
if (capHeight != null)
|
|
73
|
+
return capHeight;
|
|
74
|
+
if (fontSize != null)
|
|
75
|
+
return getPixelValue(fontSize) * 0.71;
|
|
76
|
+
return '0.71em';
|
|
77
|
+
}
|
|
61
78
|
export function isValidXOrY(xOrY) {
|
|
62
79
|
return ((typeof xOrY === 'number' && Number.isFinite(xOrY)) ||
|
|
63
80
|
typeof xOrY === 'string');
|
|
@@ -89,7 +106,9 @@ export class TextState {
|
|
|
89
106
|
// Path measurement (only meaningful for SVG layer where the textPath element exists)
|
|
90
107
|
pathRef = $state();
|
|
91
108
|
// Data mode detection
|
|
92
|
-
dataMode = $derived(
|
|
109
|
+
dataMode = $derived(this.#getProps().data != null ||
|
|
110
|
+
isTextDataProp(this.#getProps().x) ||
|
|
111
|
+
isTextDataProp(this.#getProps().y));
|
|
93
112
|
// Data resolution
|
|
94
113
|
#resolvedData = $derived(this.dataMode ? (this.#getProps().data ?? chartDataArray(this.chartCtx.data)) : []);
|
|
95
114
|
resolvedItems = $derived.by(() => {
|
|
@@ -115,9 +134,21 @@ export class TextState {
|
|
|
115
134
|
const [projX, projY] = resolveGeoDataPair(props.x, props.y, d, this.geo.projection);
|
|
116
135
|
return { x: projX, y: projY };
|
|
117
136
|
}
|
|
137
|
+
// When x/y are omitted, fall back to the chart's accessors (xGet/yGet) —
|
|
138
|
+
// mirroring the Circle / Points / Dodge pattern.
|
|
139
|
+
const xDefault = typeof props.x === 'number'
|
|
140
|
+
? props.x
|
|
141
|
+
: props.x == null && this.chartCtx.config.x != null
|
|
142
|
+
? Number(this.chartCtx.xGet(d)) || 0
|
|
143
|
+
: 0;
|
|
144
|
+
const yDefault = typeof props.y === 'number'
|
|
145
|
+
? props.y
|
|
146
|
+
: props.y == null && this.chartCtx.config.y != null
|
|
147
|
+
? Number(this.chartCtx.yGet(d)) || 0
|
|
148
|
+
: 0;
|
|
118
149
|
return {
|
|
119
|
-
x: resolveDataProp(props.x, d, this.chartCtx.xScale,
|
|
120
|
-
y: resolveDataProp(props.y, d, this.chartCtx.yScale,
|
|
150
|
+
x: resolveDataProp(props.x, d, this.chartCtx.xScale, xDefault),
|
|
151
|
+
y: resolveDataProp(props.y, d, this.chartCtx.yScale, yDefault),
|
|
121
152
|
};
|
|
122
153
|
}
|
|
123
154
|
resolveTextValue(d) {
|
|
@@ -220,7 +251,7 @@ export class TextState {
|
|
|
220
251
|
const props = this.#getProps();
|
|
221
252
|
const verticalAnchor = props.verticalAnchor ?? 'end';
|
|
222
253
|
const lineHeight = props.lineHeight ?? '1em';
|
|
223
|
-
const capHeight = props.capHeight
|
|
254
|
+
const capHeight = resolveCapHeight(props.capHeight, props.fontSize);
|
|
224
255
|
if (verticalAnchor === 'start') {
|
|
225
256
|
return getPixelValue(lineHeight);
|
|
226
257
|
}
|
|
@@ -233,7 +264,7 @@ export class TextState {
|
|
|
233
264
|
const props = this.#getProps();
|
|
234
265
|
const verticalAnchor = props.verticalAnchor ?? 'end';
|
|
235
266
|
const lineHeight = props.lineHeight ?? '1em';
|
|
236
|
-
const capHeight = props.capHeight
|
|
267
|
+
const capHeight = resolveCapHeight(props.capHeight, props.fontSize);
|
|
237
268
|
if (verticalAnchor === 'start')
|
|
238
269
|
return getPixelValue(lineHeight);
|
|
239
270
|
if (verticalAnchor === 'middle')
|
|
@@ -148,5 +148,45 @@ describe('Text', () => {
|
|
|
148
148
|
const texts = page.getByTestId(componentTestId).elements();
|
|
149
149
|
await expect.poll(() => texts.length).toBe(1);
|
|
150
150
|
});
|
|
151
|
+
it('should enter data mode when only `data` prop is set, using chart accessors', async () => {
|
|
152
|
+
render(TestHarness, {
|
|
153
|
+
component: Text,
|
|
154
|
+
chartProps: {
|
|
155
|
+
data,
|
|
156
|
+
x: 'date',
|
|
157
|
+
y: 'value',
|
|
158
|
+
yDomain: [0, 100],
|
|
159
|
+
},
|
|
160
|
+
componentProps: {
|
|
161
|
+
data,
|
|
162
|
+
value: 'label',
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
const texts = page.getByTestId(componentTestId).elements();
|
|
166
|
+
await expect.poll(() => texts.length).toBe(3);
|
|
167
|
+
const ys = texts.map((t) => Number(t.getAttribute('y')));
|
|
168
|
+
expect(ys[0]).toBeGreaterThan(ys[1]);
|
|
169
|
+
expect(ys[1]).toBeGreaterThan(ys[2]);
|
|
170
|
+
});
|
|
171
|
+
it('should fall back to chart x accessor when only y is omitted', async () => {
|
|
172
|
+
render(TestHarness, {
|
|
173
|
+
component: Text,
|
|
174
|
+
chartProps: {
|
|
175
|
+
data,
|
|
176
|
+
x: 'date',
|
|
177
|
+
y: 'value',
|
|
178
|
+
yDomain: [0, 100],
|
|
179
|
+
},
|
|
180
|
+
componentProps: {
|
|
181
|
+
data,
|
|
182
|
+
x: 'date',
|
|
183
|
+
value: 'label',
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
const texts = page.getByTestId(componentTestId).elements();
|
|
187
|
+
await expect.poll(() => texts.length).toBe(3);
|
|
188
|
+
const ys = texts.map((t) => Number(t.getAttribute('y')));
|
|
189
|
+
expect(ys[0]).toBeGreaterThan(ys[2]);
|
|
190
|
+
});
|
|
151
191
|
});
|
|
152
192
|
});
|