layerchart 0.58.3 → 0.59.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.
@@ -6,9 +6,11 @@
6
6
  import Spline from './Spline.svelte';
7
7
 
8
8
  import { createDimensionGetter } from '../utils/rect.js';
9
- import type { Accessor } from '../utils/common.js';
9
+ import { isScaleBand } from '../utils/scales.js';
10
+ import { accessor, type Accessor } from '../utils/common.js';
11
+ import { greatestAbs } from '@layerstack/utils/array';
10
12
 
11
- const { x: xContext, y: yContext } = chartContext();
13
+ const { x: xContext, y: yContext, xScale } = chartContext();
12
14
 
13
15
  export let bar: Object;
14
16
 
@@ -40,6 +42,8 @@
40
42
  /** Control which corners are rounded with radius. Uses <path> instead of <rect> when not set to `all` */
41
43
  export let rounded:
42
44
  | 'all'
45
+ | 'none'
46
+ | 'edge'
43
47
  | 'top'
44
48
  | 'bottom'
45
49
  | 'left'
@@ -65,10 +69,27 @@
65
69
  });
66
70
  $: dimensions = $getDimensions(bar) ?? { x: 0, y: 0, width: 0, height: 0 };
67
71
 
68
- $: topLeft = ['all', 'top', 'left', 'top-left'].includes(rounded);
69
- $: topRight = ['all', 'top', 'right', 'top-right'].includes(rounded);
70
- $: bottomLeft = ['all', 'bottom', 'left', 'bottom-left'].includes(rounded);
71
- $: bottomRight = ['all', 'bottom', 'right', 'bottom-right'].includes(rounded);
72
+ $: isVertical = isScaleBand($xScale);
73
+ $: valueAccessor = accessor(isVertical ? y : x);
74
+ $: value = valueAccessor(bar);
75
+ $: resolvedValue = Array.isArray(value) ? greatestAbs(value) : value;
76
+
77
+ // Resolved `rounded="edge"` based on orientation and value
78
+ $: _rounded =
79
+ rounded === 'edge'
80
+ ? isVertical
81
+ ? resolvedValue >= 0
82
+ ? 'top'
83
+ : 'bottom'
84
+ : resolvedValue >= 0
85
+ ? 'right'
86
+ : 'left'
87
+ : rounded;
88
+
89
+ $: topLeft = ['all', 'top', 'left', 'top-left'].includes(_rounded);
90
+ $: topRight = ['all', 'top', 'right', 'top-right'].includes(_rounded);
91
+ $: bottomLeft = ['all', 'bottom', 'left', 'bottom-left'].includes(_rounded);
92
+ $: bottomRight = ['all', 'bottom', 'right', 'bottom-right'].includes(_rounded);
72
93
 
73
94
  $: width = dimensions.width;
74
95
  $: height = dimensions.height;
@@ -87,7 +108,7 @@
87
108
  .join('');
88
109
  </script>
89
110
 
90
- {#if rounded === 'all'}
111
+ {#if _rounded === 'all' || radius === 0}
91
112
  <Rect
92
113
  {fill}
93
114
  {spring}
@@ -1,7 +1,7 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import { type ComponentProps } from 'svelte';
3
3
  import Rect from './Rect.svelte';
4
- import type { Accessor } from '../utils/common.js';
4
+ import { type Accessor } from '../utils/common.js';
5
5
  declare const __propDef: {
6
6
  props: {
7
7
  [x: string]: any;
@@ -14,7 +14,7 @@ declare const __propDef: {
14
14
  stroke?: string | undefined;
15
15
  strokeWidth?: number | undefined;
16
16
  radius?: number | undefined;
17
- rounded?: ("all" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
17
+ rounded?: ("all" | "none" | "edge" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
18
18
  inset?: number | undefined;
19
19
  spring?: ComponentProps<Rect>["spring"];
20
20
  tweened?: ComponentProps<Rect>["tweened"];
@@ -43,18 +43,20 @@
43
43
 
44
44
  export let spring: ComponentProps<Rect>['spring'] = undefined;
45
45
  export let tweened: ComponentProps<Rect>['tweened'] = undefined;
46
+
47
+ $: _data = chartDataArray(data ?? $contextData);
46
48
  </script>
47
49
 
48
50
  <g class="Bars">
49
51
  <slot>
50
- {#each chartDataArray(data ?? $contextData) as item}
52
+ {#each _data as d, i}
51
53
  <Bar
52
- bar={item}
54
+ bar={d}
53
55
  {x}
54
56
  {y}
55
57
  {x1}
56
58
  {y1}
57
- fill={fill ?? ($config.c ? $cGet(item) : null)}
59
+ fill={fill ?? ($config.c ? $cGet(d) : null)}
58
60
  {stroke}
59
61
  {strokeWidth}
60
62
  {radius}
@@ -47,7 +47,7 @@ declare const __propDef: {
47
47
  stroke?: string | undefined;
48
48
  strokeWidth?: number | undefined;
49
49
  radius?: number | undefined;
50
- rounded?: ("all" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
50
+ rounded?: ("all" | "none" | "edge" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
51
51
  inset?: number | undefined;
52
52
  spring?: ComponentProps<Rect>["spring"];
53
53
  tweened?: ComponentProps<Rect>["tweened"];
@@ -150,20 +150,16 @@
150
150
  }
151
151
 
152
152
  function getBarsProps(s: (typeof series)[number], i: number) {
153
+ const valueAccesor = stackSeries
154
+ ? (d: any) => d.stackData[i]
155
+ : (s.value ?? (s.data ? undefined : s.key));
153
156
  const barsProps: ComponentProps<Bars> = {
154
157
  data: s.data,
155
- x: !isVertical
156
- ? stackSeries
157
- ? (d) => d.stackData[i]
158
- : (s.value ?? (s.data ? undefined : s.key))
159
- : undefined,
160
- y: isVertical
161
- ? stackSeries
162
- ? (d) => d.stackData[i]
163
- : (s.value ?? (s.data ? undefined : s.key))
164
- : undefined,
158
+ x: !isVertical ? valueAccesor : undefined,
159
+ y: isVertical ? valueAccesor : undefined,
165
160
  x1: isVertical && groupSeries ? (d) => s.value ?? s.key : undefined,
166
161
  y1: !isVertical && groupSeries ? (d) => s.value ?? s.key : undefined,
162
+ rounded: seriesLayout.startsWith('stack') && i !== series.length - 1 ? 'none' : 'edge',
167
163
  radius: 4,
168
164
  strokeWidth: 1,
169
165
  fill: s.color,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "author": "Sean Lynch <techniq35@gmail.com>",
5
5
  "license": "MIT",
6
6
  "repository": "techniq/layerchart",
7
- "version": "0.58.3",
7
+ "version": "0.59.0",
8
8
  "devDependencies": {
9
9
  "@changesets/cli": "^2.27.9",
10
10
  "@mdi/js": "^7.4.47",