layerchart 2.0.0-next.37 → 2.0.0-next.39

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.
Files changed (115) hide show
  1. package/dist/components/AnnotationLine.svelte +15 -2
  2. package/dist/components/AnnotationPoint.svelte +13 -2
  3. package/dist/components/AnnotationRange.svelte +16 -2
  4. package/dist/components/Arc.svelte +3 -3
  5. package/dist/components/Area.svelte +10 -2
  6. package/dist/components/Axis.svelte +43 -26
  7. package/dist/components/Axis.svelte.d.ts +10 -3
  8. package/dist/components/Bar.svelte +6 -5
  9. package/dist/components/Bar.svelte.d.ts +2 -2
  10. package/dist/components/Bars.svelte +3 -3
  11. package/dist/components/Blur.svelte +2 -3
  12. package/dist/components/BrushContext.svelte +44 -44
  13. package/dist/components/Calendar.svelte +21 -4
  14. package/dist/components/Chart.svelte +1 -2
  15. package/dist/components/Chart.svelte.d.ts +10 -3
  16. package/dist/components/ChartClipPath.svelte +1 -1
  17. package/dist/components/Circle.svelte +44 -3
  18. package/dist/components/CircleClipPath.svelte +8 -1
  19. package/dist/components/ClipPath.svelte +1 -2
  20. package/dist/components/ColorRamp.svelte +1 -1
  21. package/dist/components/ComputedStyles.svelte +9 -2
  22. package/dist/components/Connector.svelte +1 -1
  23. package/dist/components/Ellipse.svelte +44 -3
  24. package/dist/components/ForceSimulation.svelte.d.ts +10 -3
  25. package/dist/components/Frame.svelte +1 -1
  26. package/dist/components/GeoCircle.svelte +1 -1
  27. package/dist/components/GeoEdgeFade.svelte +1 -1
  28. package/dist/components/GeoPath.svelte +18 -3
  29. package/dist/components/GeoPoint.svelte +3 -3
  30. package/dist/components/GeoSpline.svelte +1 -1
  31. package/dist/components/GeoTile.svelte +1 -1
  32. package/dist/components/Graticule.svelte +5 -5
  33. package/dist/components/Grid.svelte +57 -60
  34. package/dist/components/Group.svelte +11 -6
  35. package/dist/components/Group.svelte.d.ts +10 -3
  36. package/dist/components/Highlight.svelte +46 -22
  37. package/dist/components/Highlight.svelte.d.ts +4 -0
  38. package/dist/components/Hull.svelte +11 -4
  39. package/dist/components/Labels.svelte +21 -11
  40. package/dist/components/Labels.svelte.d.ts +10 -3
  41. package/dist/components/Legend.svelte +133 -67
  42. package/dist/components/Legend.svelte.d.ts +7 -3
  43. package/dist/components/Line.svelte +40 -3
  44. package/dist/components/LinearGradient.svelte +35 -4
  45. package/dist/components/Link.svelte +1 -1
  46. package/dist/components/Marker.svelte +37 -26
  47. package/dist/components/MonthPath.svelte +14 -3
  48. package/dist/components/MotionPath.svelte +1 -1
  49. package/dist/components/Pack.svelte.d.ts +10 -3
  50. package/dist/components/Partition.svelte.d.ts +10 -3
  51. package/dist/components/Pattern.svelte +5 -5
  52. package/dist/components/Pie.svelte +1 -2
  53. package/dist/components/Points.svelte +1 -3
  54. package/dist/components/Polygon.svelte +27 -3
  55. package/dist/components/RadialGradient.svelte +3 -3
  56. package/dist/components/Rect.svelte +55 -5
  57. package/dist/components/Rect.svelte.d.ts +2 -2
  58. package/dist/components/RectClipPath.svelte +4 -3
  59. package/dist/components/RectClipPath.svelte.d.ts +2 -2
  60. package/dist/components/Rule.svelte +30 -23
  61. package/dist/components/Spline.svelte +29 -10
  62. package/dist/components/Text.svelte +59 -13
  63. package/dist/components/TileImage.svelte +19 -4
  64. package/dist/components/TransformContext.svelte +9 -3
  65. package/dist/components/TransformControls.svelte +72 -17
  66. package/dist/components/Tree.svelte.d.ts +10 -3
  67. package/dist/components/Treemap.svelte.d.ts +10 -3
  68. package/dist/components/Voronoi.svelte +12 -13
  69. package/dist/components/charts/ArcChart.svelte +40 -69
  70. package/dist/components/charts/ArcChart.svelte.d.ts +10 -3
  71. package/dist/components/charts/AreaChart.svelte +19 -42
  72. package/dist/components/charts/AreaChart.svelte.d.ts +10 -3
  73. package/dist/components/charts/BarChart.svelte +7 -18
  74. package/dist/components/charts/BarChart.svelte.d.ts +10 -3
  75. package/dist/components/charts/DefaultTooltip.svelte +2 -2
  76. package/dist/components/charts/DefaultTooltip.svelte.d.ts +1 -1
  77. package/dist/components/charts/LineChart.svelte +61 -66
  78. package/dist/components/charts/LineChart.svelte.d.ts +21 -8
  79. package/dist/components/charts/PieChart.svelte +41 -69
  80. package/dist/components/charts/PieChart.svelte.d.ts +10 -3
  81. package/dist/components/charts/ScatterChart.svelte +8 -19
  82. package/dist/components/charts/ScatterChart.svelte.d.ts +10 -3
  83. package/dist/components/charts/utils.svelte.d.ts +1 -19
  84. package/dist/components/charts/utils.svelte.js +7 -39
  85. package/dist/components/layout/Canvas.svelte +29 -20
  86. package/dist/components/layout/Html.svelte +15 -9
  87. package/dist/components/layout/Svg.svelte +19 -11
  88. package/dist/components/layout/WebGL.svelte +26 -6
  89. package/dist/components/layout/WebGL.svelte.d.ts +5 -2
  90. package/dist/components/tooltip/Tooltip.svelte +60 -29
  91. package/dist/components/tooltip/Tooltip.svelte.d.ts +10 -3
  92. package/dist/components/tooltip/TooltipContext.svelte +73 -36
  93. package/dist/components/tooltip/TooltipContext.svelte.d.ts +17 -3
  94. package/dist/components/tooltip/TooltipHeader.svelte +27 -14
  95. package/dist/components/tooltip/TooltipItem.svelte +41 -33
  96. package/dist/components/tooltip/TooltipList.svelte +12 -10
  97. package/dist/components/tooltip/TooltipSeparator.svelte +18 -10
  98. package/dist/states/series.svelte.d.ts +30 -0
  99. package/dist/states/series.svelte.js +54 -0
  100. package/dist/styles/daisyui-5.css +6 -0
  101. package/dist/styles/shadcn-svelte.css +11 -0
  102. package/dist/styles/skeleton-3.css +15 -0
  103. package/dist/utils/attributes.d.ts +3 -13
  104. package/dist/utils/attributes.js +4 -18
  105. package/dist/utils/common.d.ts +9 -0
  106. package/dist/utils/common.js +18 -1
  107. package/dist/utils/common.test.js +26 -1
  108. package/dist/utils/graph/dagre.d.ts +4 -4
  109. package/dist/utils/graph/dagre.js +5 -7
  110. package/dist/utils/math.d.ts +17 -0
  111. package/dist/utils/math.js +17 -0
  112. package/dist/utils/scales.svelte.js +3 -3
  113. package/dist/utils/stack.js +1 -1
  114. package/dist/utils/types.d.ts +15 -2
  115. package/package.json +25 -22
@@ -71,10 +71,17 @@ import Arc, { type ArcPropsWithoutHTML } from '../Arc.svelte';
71
71
  import Group from '../Group.svelte';
72
72
  import { type Accessor } from '../../utils/common.js';
73
73
  import type { SeriesData, SimplifiedChartProps, SimplifiedChartPropsObject, SimplifiedChartSnippet } from './types.js';
74
+ declare function $$render<TData>(): {
75
+ props: ArcChartProps<TData>;
76
+ exports: {};
77
+ bindings: "context";
78
+ slots: {};
79
+ events: {};
80
+ };
74
81
  declare class __sveltets_Render<TData> {
75
- props(): ArcChartProps<TData>;
76
- events(): {};
77
- slots(): {};
82
+ props(): ReturnType<typeof $$render<TData>>['props'];
83
+ events(): ReturnType<typeof $$render<TData>>['events'];
84
+ slots(): ReturnType<typeof $$render<TData>>['slots'];
78
85
  bindings(): "context";
79
86
  exports(): {};
80
87
  }
@@ -67,7 +67,6 @@
67
67
 
68
68
  <script lang="ts" generics="TData">
69
69
  import { onMount, type ComponentProps } from 'svelte';
70
- import { scaleLinear, scaleTime } from 'd3-scale';
71
70
  import { stack, stackOffsetDiverging, stackOffsetExpand, stackOffsetNone } from 'd3-shape';
72
71
  import { cls } from '@layerstack/tailwind';
73
72
 
@@ -93,7 +92,8 @@
93
92
  import { asAny } from '../../utils/types.js';
94
93
  import Spline from '../Spline.svelte';
95
94
  import type { SeriesData, SimplifiedChartProps, SimplifiedChartPropsObject } from './types.js';
96
- import { createLegendProps, SeriesState } from './utils.svelte.js';
95
+ import { SeriesState } from '../../states/series.svelte.js';
96
+ import { createLegendProps } from './utils.svelte.js';
97
97
  import { setTooltipMetaContext } from '../tooltip/tooltipMetaContext.js';
98
98
  import DefaultTooltip from './DefaultTooltip.svelte';
99
99
  import ChartAnnotations from './ChartAnnotations.svelte';
@@ -139,7 +139,7 @@
139
139
  key: 'default',
140
140
  label: typeof y === 'string' ? y : 'value',
141
141
  value: y,
142
- color: 'var(--color-primary)',
142
+ color: 'var(--color-primary, currentColor)',
143
143
  },
144
144
  ]
145
145
  : seriesProp
@@ -221,13 +221,6 @@
221
221
  ...(typeof s.props?.line === 'object' ? s.props.line : null),
222
222
  };
223
223
 
224
- const highlightClass =
225
- seriesState.visibleSeries.length > 1 &&
226
- seriesState.highlightKey.current &&
227
- seriesState.highlightKey.current !== s.key
228
- ? 'opacity-10'
229
- : '';
230
-
231
224
  return {
232
225
  data: s.data,
233
226
  y0: stackSeries
@@ -242,19 +235,18 @@
242
235
  : (s.value ?? (s.data ? undefined : s.key)),
243
236
  fill: s.color,
244
237
  fillOpacity: 0.3,
238
+ opacity:
239
+ // Checking `visibleSeries.length <= 1` fixes re-animated tweened areas on hover
240
+ seriesState.visibleSeries.length <= 1 || seriesState.isHighlighted(s.key, true) ? 1 : 0.1,
245
241
  ...props.area,
246
242
  ...s.props,
247
- class: cls(
248
- 'transition-opacity',
249
- // Checking `visibleSeries.length > 1` fixes re-animated tweened areas on hover
250
- highlightClass,
251
- props.area?.class,
252
- s.props?.class
253
- ),
243
+ class: cls(props.area?.class, s.props?.class),
254
244
  line: {
255
245
  stroke: s.color,
246
+ opacity:
247
+ // Checking `visibleSeries.length <= 1` fixes re-animated tweened areas on hover
248
+ seriesState.visibleSeries.length <= 1 || seriesState.isHighlighted(s.key, true) ? 1 : 0.1,
256
249
  ...lineProps,
257
- class: cls('transition-opacity', highlightClass, lineProps.class),
258
250
  },
259
251
  };
260
252
  }
@@ -271,16 +263,11 @@
271
263
  ? s.value[1]
272
264
  : (s.value ?? (s.data ? undefined : s.key)),
273
265
  fill: s.color,
266
+ stroke: 'var(--color-surface-100, light-dark(white, black))',
267
+ opacity: seriesState.isHighlighted(s.key, true) ? 1 : 0.1,
274
268
  ...props.points,
275
269
  ...(typeof points === 'object' ? points : null),
276
- class: cls(
277
- 'stroke-surface-200 transition-opacity',
278
- seriesState.highlightKey.current &&
279
- seriesState.highlightKey.current !== s.key &&
280
- 'opacity-10',
281
- props.points?.class,
282
- typeof points === 'object' && points.class
283
- ),
270
+ class: cls(props.points?.class, typeof points === 'object' && points.class),
284
271
  };
285
272
  }
286
273
 
@@ -295,16 +282,11 @@
295
282
  : Array.isArray(s.value)
296
283
  ? s.value[1]
297
284
  : (s.value ?? (s.data ? undefined : s.key)),
285
+ stroke: 'var(--color-surface-100, light-dark(white, black))',
286
+ opacity: seriesState.isHighlighted(s.key, true) ? 1 : 0.1,
298
287
  ...props.labels,
299
288
  ...(typeof labels === 'object' ? labels : null),
300
- class: cls(
301
- 'stroke-surface-200 transition-opacity',
302
- seriesState.highlightKey.current &&
303
- seriesState.highlightKey.current !== s.key &&
304
- 'opacity-10',
305
- props.labels?.class,
306
- typeof labels === 'object' && labels.class
307
- ),
289
+ class: cls(props.labels?.class, typeof labels === 'object' && labels.class),
308
290
  };
309
291
  }
310
292
 
@@ -317,7 +299,7 @@
317
299
  if (!context) return {};
318
300
  const seriesTooltipData =
319
301
  s.data && context.tooltip.data
320
- ? findRelatedData(s.data, context.tooltip.data, context.x)
302
+ ? (findRelatedData(s.data, context.tooltip.data, context.x) ?? {})
321
303
  : null;
322
304
  const highlightPointsProps =
323
305
  typeof props.highlight?.points === 'object' ? props.highlight.points : null;
@@ -332,19 +314,14 @@
332
314
  onPointEnter: () => (seriesState.highlightKey.current = s.key),
333
315
  onPointLeave: () => (seriesState.highlightKey.current = null),
334
316
  ...props.highlight,
317
+ opacity:
318
+ seriesState.highlightKey.current && seriesState.highlightKey.current !== s.key ? 0.1 : 1,
335
319
  points:
336
320
  props.highlight?.points == false
337
321
  ? false
338
322
  : {
339
323
  ...highlightPointsProps,
340
324
  fill: s.color,
341
- class: cls(
342
- 'transition-opacity',
343
- seriesState.highlightKey.current &&
344
- seriesState.highlightKey.current !== s.key &&
345
- 'opacity-10',
346
- highlightPointsProps?.class
347
- ),
348
325
  },
349
326
  };
350
327
  }
@@ -42,10 +42,17 @@ import Labels from '../Labels.svelte';
42
42
  import Points from '../Points.svelte';
43
43
  import Rule from '../Rule.svelte';
44
44
  import type { SeriesData, SimplifiedChartProps, SimplifiedChartPropsObject } from './types.js';
45
+ declare function $$render<TData>(): {
46
+ props: AreaChartProps<TData>;
47
+ exports: {};
48
+ bindings: "context";
49
+ slots: {};
50
+ events: {};
51
+ };
45
52
  declare class __sveltets_Render<TData> {
46
- props(): AreaChartProps<TData>;
47
- events(): {};
48
- slots(): {};
53
+ props(): ReturnType<typeof $$render<TData>>['props'];
54
+ events(): ReturnType<typeof $$render<TData>>['events'];
55
+ slots(): ReturnType<typeof $$render<TData>>['slots'];
49
56
  bindings(): "context";
50
57
  exports(): {};
51
58
  }
@@ -109,7 +109,8 @@
109
109
  import type { Insets } from '../../utils/rect.svelte.js';
110
110
  import type { SeriesData, SimplifiedChartProps, SimplifiedChartPropsObject } from './types.js';
111
111
  import { isScaleTime, type AnyScale } from '../../utils/scales.svelte.js';
112
- import { createLegendProps, SeriesState } from './utils.svelte.js';
112
+ import { SeriesState } from '../../states/series.svelte.js';
113
+ import { createLegendProps } from './utils.svelte.js';
113
114
  import { setTooltipMetaContext } from '../tooltip/tooltipMetaContext.js';
114
115
  import DefaultTooltip from './DefaultTooltip.svelte';
115
116
  import ChartAnnotations from './ChartAnnotations.svelte';
@@ -311,17 +312,11 @@
311
312
  strokeWidth: 1,
312
313
  insets: stackInsets,
313
314
  fill: s.color,
315
+ opacity: seriesState.isHighlighted(s.key, true) ? 1 : 0.1,
314
316
  onBarClick: (e, detail) => onBarClick(e, { ...detail, series: s }),
315
317
  ...props.bars,
316
318
  ...s.props,
317
- class: cls(
318
- 'transition-opacity',
319
- seriesState.highlightKey.current &&
320
- seriesState.highlightKey.current !== s.key &&
321
- 'opacity-10',
322
- props.bars?.class,
323
- s.props?.class
324
- ),
319
+ class: cls(props.bars?.class, s.props?.class),
325
320
  };
326
321
  }
327
322
 
@@ -333,16 +328,10 @@
333
328
  // TODO: Improve placement when using `seriesLayout="group"`
334
329
  // data: s.data,
335
330
  // y: s.value ?? (s.data ? undefined : s.key),
331
+ opacity: seriesState.isHighlighted(s.key, true) ? 1 : 0.1,
336
332
  ...props.labels,
337
333
  ...(typeof labels === 'object' ? labels : null),
338
- class: cls(
339
- 'stroke-surface-200 transition-opacity',
340
- seriesState.highlightKey.current &&
341
- seriesState.highlightKey.current !== s.key &&
342
- 'opacity-10',
343
- props.labels?.class,
344
- typeof labels === 'object' && labels.class
345
- ),
334
+ class: cls(props.labels?.class, typeof labels === 'object' && labels.class),
346
335
  };
347
336
  }
348
337
 
@@ -452,7 +441,7 @@
452
441
  {y1Range}
453
442
  {yInterval}
454
443
  c={isVertical ? yProp : xProp}
455
- cRange={['var(--color-primary)']}
444
+ cRange={['var(--color-primary, currentColor)']}
456
445
  {radial}
457
446
  padding={radial ? undefined : defaultChartPadding(axis, legend)}
458
447
  {...restProps}
@@ -57,10 +57,17 @@ import Highlight from '../Highlight.svelte';
57
57
  import Labels from '../Labels.svelte';
58
58
  import Rule from '../Rule.svelte';
59
59
  import type { SeriesData, SimplifiedChartProps, SimplifiedChartPropsObject } from './types.js';
60
+ declare function $$render<TData>(): {
61
+ props: BarChartProps<TData>;
62
+ exports: {};
63
+ bindings: "context";
64
+ slots: {};
65
+ events: {};
66
+ };
60
67
  declare class __sveltets_Render<TData> {
61
- props(): BarChartProps<TData>;
62
- events(): {};
63
- slots(): {};
68
+ props(): ReturnType<typeof $$render<TData>>['props'];
69
+ events(): ReturnType<typeof $$render<TData>>['events'];
70
+ slots(): ReturnType<typeof $$render<TData>>['slots'];
64
71
  bindings(): "context";
65
72
  exports(): {};
66
73
  }
@@ -4,7 +4,7 @@
4
4
  import { getChartContext } from '../Chart.svelte';
5
5
  import * as Tooltip from '../tooltip/index.js';
6
6
  import type { SimplifiedChartPropsObject } from './types.js';
7
- import type { SeriesState } from './utils.svelte.js';
7
+ import type { SeriesState } from '../../states/series.svelte.js';
8
8
  import { format } from '@layerstack/utils';
9
9
  import { accessor, findRelatedData } from '../../utils/common.js';
10
10
 
@@ -48,7 +48,7 @@
48
48
  value={sum(seriesState.visibleSeries, (s) => {
49
49
  const seriesTooltipData = s.data ? findRelatedData(s.data, data, context.x) : data;
50
50
  const valueAccessor = accessor(s.value ?? (s.data ? context.y : s.key));
51
- return valueAccessor(seriesTooltipData);
51
+ return seriesTooltipData ? valueAccessor(seriesTooltipData) : 0;
52
52
  })}
53
53
  format="integer"
54
54
  valueAlign="right"
@@ -1,5 +1,5 @@
1
1
  import type { SimplifiedChartPropsObject } from './types.js';
2
- import type { SeriesState } from './utils.svelte.js';
2
+ import type { SeriesState } from '../../states/series.svelte.js';
3
3
  type $$ComponentProps = {
4
4
  tooltipProps?: SimplifiedChartPropsObject['tooltip'];
5
5
  seriesState: SeriesState<any, any>;
@@ -44,12 +44,11 @@
44
44
  LineChartExtraSnippetProps<TData>
45
45
  > & {
46
46
  /**
47
- * The event to be dispatched when the point is clicked.
47
+ * The orientation of the line chart.
48
+ *
49
+ * @default 'horizontal'
48
50
  */
49
- onPointClick?: (
50
- e: MouseEvent,
51
- details: { data: HighlightPointData; series: SeriesData<TData, typeof Spline> }
52
- ) => void;
51
+ orientation?: 'vertical' | 'horizontal';
53
52
 
54
53
  props?: LineChartPropsObjProp;
55
54
 
@@ -64,6 +63,14 @@
64
63
  seriesIndex: number;
65
64
  }
66
65
  >;
66
+
67
+ /**
68
+ * The event to be dispatched when the point is clicked.
69
+ */
70
+ onPointClick?: (
71
+ e: MouseEvent,
72
+ details: { data: HighlightPointData; series: SeriesData<TData, typeof Spline> }
73
+ ) => void;
67
74
  };
68
75
  </script>
69
76
 
@@ -83,12 +90,7 @@
83
90
  import Rule from '../Rule.svelte';
84
91
  import Spline from '../Spline.svelte';
85
92
 
86
- import {
87
- accessor,
88
- chartDataArray,
89
- defaultChartPadding,
90
- findRelatedData,
91
- } from '../../utils/common.js';
93
+ import { chartDataArray, defaultChartPadding, findRelatedData } from '../../utils/common.js';
92
94
  import { asAny } from '../../utils/types.js';
93
95
  import type {
94
96
  SeriesData,
@@ -96,18 +98,22 @@
96
98
  SimplifiedChartPropsObject,
97
99
  SimplifiedChartSnippet,
98
100
  } from './types.js';
99
- import { createLegendProps, SeriesState } from './utils.svelte.js';
101
+ import { SeriesState } from '../../states/series.svelte.js';
102
+ import { createLegendProps } from './utils.svelte.js';
100
103
  import { setTooltipMetaContext } from '../tooltip/tooltipMetaContext.js';
101
- import { layerClass } from '../../utils/attributes.js';
102
104
  import DefaultTooltip from './DefaultTooltip.svelte';
103
105
  import ChartAnnotations from './ChartAnnotations.svelte';
106
+ import { isScaleTime } from '../../utils/scales.svelte.js';
104
107
 
105
108
  let {
106
109
  data = [],
107
110
  x: xProp,
108
- y: yProp,
111
+ xScale,
109
112
  xDomain,
113
+ y: yProp,
114
+ yScale,
110
115
  radial = false,
116
+ orientation = 'horizontal',
111
117
  series: seriesProp,
112
118
  seriesLayout = 'overlap',
113
119
  axis = true,
@@ -137,14 +143,23 @@
137
143
  ...restProps
138
144
  }: LineChartProps<TData> = $props();
139
145
 
146
+ const isVertical = $derived(orientation === 'vertical');
147
+
140
148
  const series = $derived(
141
149
  seriesProp === undefined
142
150
  ? [
143
151
  {
144
152
  key: 'default',
145
- label: typeof yProp === 'string' ? yProp : 'value',
146
- value: yProp,
147
- color: 'var(--color-primary)',
153
+
154
+ label: isVertical
155
+ ? typeof xProp === 'string'
156
+ ? xProp
157
+ : 'value'
158
+ : typeof yProp === 'string'
159
+ ? yProp
160
+ : 'value',
161
+ value: isVertical ? xProp : yProp,
162
+ color: 'var(--color-primary, currentColor)',
148
163
  },
149
164
  ]
150
165
  : seriesProp
@@ -160,21 +175,15 @@
160
175
  function getSplineProps(s: SeriesData<TData, typeof Spline>, i: number) {
161
176
  const splineProps: ComponentProps<typeof Spline> = {
162
177
  data: s.data,
163
- y: s.value ?? (s.data ? undefined : s.key),
178
+ x: isVertical ? (s.value ?? (s.data ? undefined : s.key)) : undefined,
179
+ y: !isVertical ? (s.value ?? (s.data ? undefined : s.key)) : undefined,
164
180
  stroke: s.color,
181
+ opacity:
182
+ // Checking `visibleSeries.length <= 1` fixes re-animated tweened areas on hover
183
+ seriesState.visibleSeries.length <= 1 || seriesState.isHighlighted(s.key, true) ? 1 : 0.1,
165
184
  ...props.spline,
166
185
  ...s.props,
167
- class: cls(
168
- layerClass('line-chart-line'),
169
- 'transition-opacity',
170
- // Checking `visibleSeries.length > 1` fixes re-animated tweened areas on hover
171
- seriesState.visibleSeries.length > 1 &&
172
- seriesState.highlightKey.current &&
173
- seriesState.highlightKey.current !== s.key &&
174
- 'opacity-10',
175
- props.spline?.class,
176
- s.props?.class
177
- ),
186
+ class: cls(props.spline?.class, s.props?.class),
178
187
  };
179
188
 
180
189
  return splineProps;
@@ -183,18 +192,14 @@
183
192
  function getPointsProps(s: SeriesData<TData, typeof Spline>, i: number) {
184
193
  const pointsProps: ComponentProps<typeof Points> = {
185
194
  data: s.data,
186
- y: s.value ?? (s.data ? undefined : s.key),
195
+ x: isVertical ? (s.value ?? (s.data ? undefined : s.key)) : undefined,
196
+ y: !isVertical ? (s.value ?? (s.data ? undefined : s.key)) : undefined,
187
197
  fill: s.color,
198
+ stroke: 'var(--color-surface-100, light-dark(white, black))',
199
+ opacity: seriesState.isHighlighted(s.key, true) ? 1 : 0.1,
188
200
  ...props.points,
189
201
  ...(typeof points === 'object' ? points : null),
190
- class: cls(
191
- 'stroke-surface-200 transition-opacity',
192
- seriesState.highlightKey.current &&
193
- seriesState.highlightKey.current !== s.key &&
194
- 'opacity-10',
195
- props.points?.class,
196
- typeof points === 'object' && points.class
197
- ),
202
+ class: cls(props.points?.class, typeof points === 'object' && points.class),
198
203
  };
199
204
 
200
205
  return pointsProps;
@@ -203,26 +208,17 @@
203
208
  function getLabelsProps(s: SeriesData<TData, typeof Spline>, i: number) {
204
209
  const labelsProps: ComponentProps<typeof Labels<TData>> = {
205
210
  data: s.data,
206
- y: s.value ?? (s.data ? undefined : s.key),
211
+ x: isVertical ? (s.value ?? (s.data ? undefined : s.key)) : undefined,
212
+ y: !isVertical ? (s.value ?? (s.data ? undefined : s.key)) : undefined,
213
+ opacity: seriesState.isHighlighted(s.key, true) ? 1 : 0.1,
207
214
  ...props.labels,
208
215
  ...(typeof labels === 'object' ? labels : null),
209
- class: cls(
210
- 'stroke-surface-200 transition-opacity',
211
- seriesState.highlightKey.current &&
212
- seriesState.highlightKey.current !== s.key &&
213
- 'opacity-10',
214
- props.labels?.class,
215
- typeof labels === 'object' && labels.class
216
- ),
216
+ class: cls(props.labels?.class, typeof labels === 'object' && labels.class),
217
217
  };
218
218
 
219
219
  return labelsProps;
220
220
  }
221
221
 
222
- const highlightPointsProps = $derived(
223
- typeof props.highlight?.points === 'object' ? props.highlight.points : null
224
- );
225
-
226
222
  function getHighlightProps(
227
223
  s: SeriesData<TData, typeof Spline>,
228
224
  i: number
@@ -230,18 +226,22 @@
230
226
  if (!context || !context.tooltip.data) return {};
231
227
  const seriesTooltipData =
232
228
  s.data && context.tooltip.data
233
- ? findRelatedData(s.data, context.tooltip.data, context.x)
229
+ ? (findRelatedData(s.data, context.tooltip.data, context.x) ?? {})
234
230
  : null;
231
+ const highlightPointsProps =
232
+ typeof props.highlight?.points === 'object' ? props.highlight.points : null;
235
233
 
236
234
  return {
237
235
  data: seriesTooltipData,
238
- y: s.value ?? (s.data ? undefined : s.key),
236
+ x: isVertical ? (s.value ?? (s.data ? undefined : s.key)) : undefined,
237
+ y: !isVertical ? (s.value ?? (s.data ? undefined : s.key)) : undefined,
239
238
  lines: i === 0,
240
239
  onPointClick: onPointClick
241
240
  ? (e, detail) => onPointClick(e, { ...detail, series: s })
242
241
  : undefined,
243
242
  onPointEnter: () => (seriesState.highlightKey.current = s.key),
244
243
  onPointLeave: () => (seriesState.highlightKey.current = null),
244
+ opacity: seriesState.isHighlighted(s.key, true) ? 1 : 0.1,
245
245
  ...props.highlight,
246
246
  points:
247
247
  props.highlight?.points == false
@@ -249,13 +249,6 @@
249
249
  : {
250
250
  ...highlightPointsProps,
251
251
  fill: s.color,
252
- class: cls(
253
- 'transition-opacity',
254
- seriesState.highlightKey.current &&
255
- seriesState.highlightKey.current !== s.key &&
256
- 'opacity-10',
257
- highlightPointsProps?.class
258
- ),
259
252
  },
260
253
  };
261
254
  }
@@ -264,8 +257,8 @@
264
257
  return createLegendProps({
265
258
  seriesState,
266
259
  props: {
267
- ...props.legend,
268
260
  ...(typeof legend === 'object' ? legend : null),
261
+ ...props.legend,
269
262
  },
270
263
  });
271
264
  }
@@ -324,18 +317,20 @@
324
317
  <Chart
325
318
  bind:context
326
319
  data={chartData}
327
- x={xProp}
320
+ x={xProp ?? (isVertical ? series.map((s) => s.value ?? s.key) : undefined)}
328
321
  {xDomain}
329
- y={yProp ?? series.map((s) => s.value ?? s.key)}
330
- yBaseline={0}
331
- yNice
322
+ xBaseline={!isVertical || (xScale && isScaleTime(xScale)) ? undefined : 0}
323
+ xNice={orientation === 'vertical'}
324
+ y={yProp ?? (isVertical ? undefined : series.map((s) => s.value ?? s.key))}
325
+ yBaseline={isVertical || (yScale && isScaleTime(yScale)) ? undefined : 0}
326
+ yNice={orientation === 'horizontal'}
332
327
  {radial}
333
328
  padding={radial ? undefined : defaultChartPadding(axis, legend)}
334
329
  {...restProps}
335
330
  tooltip={tooltip === false
336
331
  ? false
337
332
  : {
338
- mode: 'quadtree-x',
333
+ mode: isVertical ? 'quadtree-y' : 'quadtree-x',
339
334
  onclick: onTooltipClick,
340
335
  debug,
341
336
  ...props.tooltip?.context,
@@ -10,12 +10,11 @@ export type LineChartExtraSnippetProps<TData> = {
10
10
  export type LineChartPropsObjProp = Pick<SimplifiedChartPropsObject, 'brush' | 'canvas' | 'grid' | 'highlight' | 'labels' | 'legend' | 'points' | 'rule' | 'spline' | 'svg' | 'tooltip' | 'xAxis' | 'yAxis'>;
11
11
  export type LineChartProps<TData> = SimplifiedChartProps<TData, typeof Spline, LineChartExtraSnippetProps<TData>> & {
12
12
  /**
13
- * The event to be dispatched when the point is clicked.
13
+ * The orientation of the line chart.
14
+ *
15
+ * @default 'horizontal'
14
16
  */
15
- onPointClick?: (e: MouseEvent, details: {
16
- data: HighlightPointData;
17
- series: SeriesData<TData, typeof Spline>;
18
- }) => void;
17
+ orientation?: 'vertical' | 'horizontal';
19
18
  props?: LineChartPropsObjProp;
20
19
  spline?: SimplifiedChartSnippet<TData, typeof Spline, LineChartExtraSnippetProps<TData> & {
21
20
  props: ComponentProps<typeof Spline>;
@@ -24,6 +23,13 @@ export type LineChartProps<TData> = SimplifiedChartProps<TData, typeof Spline, L
24
23
  */
25
24
  seriesIndex: number;
26
25
  }>;
26
+ /**
27
+ * The event to be dispatched when the point is clicked.
28
+ */
29
+ onPointClick?: (e: MouseEvent, details: {
30
+ data: HighlightPointData;
31
+ series: SeriesData<TData, typeof Spline>;
32
+ }) => void;
27
33
  };
28
34
  import { type ComponentProps } from 'svelte';
29
35
  import Axis from '../Axis.svelte';
@@ -34,10 +40,17 @@ import Points from '../Points.svelte';
34
40
  import Rule from '../Rule.svelte';
35
41
  import Spline from '../Spline.svelte';
36
42
  import type { SeriesData, SimplifiedChartProps, SimplifiedChartPropsObject, SimplifiedChartSnippet } from './types.js';
43
+ declare function $$render<TData>(): {
44
+ props: LineChartProps<TData>;
45
+ exports: {};
46
+ bindings: "context";
47
+ slots: {};
48
+ events: {};
49
+ };
37
50
  declare class __sveltets_Render<TData> {
38
- props(): LineChartProps<TData>;
39
- events(): {};
40
- slots(): {};
51
+ props(): ReturnType<typeof $$render<TData>>['props'];
52
+ events(): ReturnType<typeof $$render<TData>>['events'];
53
+ slots(): ReturnType<typeof $$render<TData>>['slots'];
41
54
  bindings(): "context";
42
55
  exports(): {};
43
56
  }