layerchart 0.20.2 → 0.21.1

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.
@@ -13,8 +13,6 @@ $: _x = x ? (typeof x === 'string' ? (d) => d[x] : x) : $xContext;
13
13
  */
14
14
  export let y = $yContext;
15
15
  $: _y = y ? (typeof y === 'string' ? (d) => d[y] : y) : $yContext;
16
- export let color = 'var(--color-accent-500)';
17
- export let opacity = 1;
18
16
  export let stroke = 'black';
19
17
  export let strokeWidth = 0;
20
18
  export let radius = 0;
@@ -35,28 +33,16 @@ $: getDimensions = createDimensionGetter(getContext('LayerCake'), {
35
33
  padding,
36
34
  groupPadding: {
37
35
  inner: groupPaddingInner,
38
- outer: groupPaddingOuter
39
- }
36
+ outer: groupPaddingOuter,
37
+ },
40
38
  });
41
- function getColor(item, index) {
42
- if (typeof color === 'function') {
43
- return color({ value: _y(item), item, index });
44
- }
45
- else if ($config.r) {
46
- return $rGet(item);
47
- }
48
- else {
49
- return color;
50
- }
51
- }
52
39
  </script>
53
40
 
54
41
  <g class="Bars">
55
42
  {#each $data as item, index (getKey(item, index))}
56
43
  <Rect
57
44
  data-id={index}
58
- fill={getColor(item, index)}
59
- fill-opacity={opacity}
45
+ fill={$config.r ? $rGet(item) : null}
60
46
  {stroke}
61
47
  stroke-width={strokeWidth}
62
48
  rx={radius}
@@ -5,12 +5,6 @@ declare const __propDef: {
5
5
  [x: string]: any;
6
6
  x?: any;
7
7
  y?: any;
8
- color?: string | ((obj: {
9
- value: any;
10
- item: any;
11
- index: number;
12
- }) => string) | undefined;
13
- opacity?: number | undefined;
14
8
  stroke?: string | undefined;
15
9
  strokeWidth?: number | undefined;
16
10
  radius?: number | undefined;
@@ -14,8 +14,6 @@ export let x = sankey ? (d) => d[0] : (d) => (orientation === 'horizontal' ? d.y
14
14
  export let y = sankey ? (d) => d[1] : (d) => (orientation === 'horizontal' ? d.x : d.y);
15
15
  export let curve = orientation === 'horizontal' ? curveBumpX : curveBumpY;
16
16
  export let tweened = undefined;
17
- export let color = 'black';
18
- export let width = undefined;
19
17
  $: tweenedOptions = tweened ? { interpolate: interpolatePath, ...tweened } : false;
20
18
  $: tweened_d = motionStore('', { tweened: tweenedOptions });
21
19
  $: {
@@ -30,8 +28,6 @@ $: {
30
28
  <path
31
29
  class="path-link"
32
30
  d={$tweened_d}
33
- stroke={color}
34
- stroke-width={width}
35
31
  fill="none"
36
32
  on:click
37
33
  on:mouseover
@@ -12,8 +12,6 @@ declare const __propDef: {
12
12
  y?: ((d: any) => any) | undefined;
13
13
  curve?: import("d3-shape").CurveFactory | undefined;
14
14
  tweened?: boolean | Parameters<typeof tweenedStore>[1];
15
- color?: string | undefined;
16
- width?: undefined;
17
15
  };
18
16
  events: {
19
17
  click: MouseEvent;
@@ -40,7 +40,6 @@ export let outerRadius = undefined;
40
40
  export let cornerRadius = 0;
41
41
  export let padAngle = 0;
42
42
  // export let padRadius = 0;
43
- export let color = 'black';
44
43
  export let spring = undefined;
45
44
  export let tweened = undefined;
46
45
  /**
@@ -62,17 +61,6 @@ $: pie = d3pie()
62
61
  .value($x);
63
62
  $: arcs = pie(data ?? $contextData);
64
63
  // $: console.log({ arcs, $yRange });
65
- function getColor(item, index) {
66
- if (typeof color === 'function') {
67
- return color({ value: $y(item), item, index });
68
- }
69
- else if ($config.r) {
70
- return $rGet(item);
71
- }
72
- else {
73
- return color;
74
- }
75
- }
76
64
  </script>
77
65
 
78
66
  <Group center>
@@ -86,7 +74,7 @@ function getColor(item, index) {
86
74
  {outerRadius}
87
75
  {cornerRadius}
88
76
  {offset}
89
- fill={getColor(arc.data, index)}
77
+ fill={$config.r ? $rGet(arc.data) : null}
90
78
  on:mousemove={(e) => tooltip?.show(e, arc.data)}
91
79
  on:mouseleave={(e) => tooltip?.hide()}
92
80
  />
@@ -25,11 +25,6 @@ declare const __propDef: {
25
25
  */ outerRadius?: undefined;
26
26
  cornerRadius?: number | undefined;
27
27
  padAngle?: number | undefined;
28
- color?: string | ((obj: {
29
- value: any;
30
- item: any;
31
- index: number;
32
- }) => string) | undefined;
33
28
  spring?: boolean | Parameters<typeof springStore>[1];
34
29
  tweened?: boolean | Parameters<typeof tweenedStore>[1];
35
30
  /**
@@ -7,7 +7,6 @@ const { data, xGet, y, yGet, xScale, yScale, rGet, config } = context;
7
7
  export let r = 5;
8
8
  export let offsetX = undefined;
9
9
  export let offsetY = undefined;
10
- export let color = 'var(--color-accent-500)';
11
10
  function getOffset(value, offset, scale) {
12
11
  if (typeof offset === 'function') {
13
12
  return offset(value, context);
@@ -22,18 +21,6 @@ function getOffset(value, offset, scale) {
22
21
  return 0;
23
22
  }
24
23
  }
25
- function getColor(item, index) {
26
- if (typeof color === 'function') {
27
- return color({ value: $y(item), item, index });
28
- }
29
- else if ($config.r) {
30
- // console.log({ item, value: $rGet(item), scale: $rGet.domain() });
31
- return $rGet(item);
32
- }
33
- else {
34
- return color;
35
- }
36
- }
37
24
  $: points = $data.flatMap((d) => {
38
25
  if (Array.isArray($config.x)) {
39
26
  /*
@@ -46,7 +33,7 @@ $: points = $data.flatMap((d) => {
46
33
  return {
47
34
  x: x + getOffset(x, offsetX, $xScale),
48
35
  y: $yGet(d) + getOffset($yGet(d), offsetY, $yScale),
49
- data: d
36
+ data: d,
50
37
  };
51
38
  });
52
39
  }
@@ -61,7 +48,7 @@ $: points = $data.flatMap((d) => {
61
48
  return {
62
49
  x: $xGet(d) + getOffset($xGet(d), offsetX, $xScale),
63
50
  y: y + getOffset(y, offsetY, $yScale),
64
- data: d
51
+ data: d,
65
52
  };
66
53
  });
67
54
  }
@@ -73,7 +60,7 @@ $: points = $data.flatMap((d) => {
73
60
  return {
74
61
  x: $xGet(d) + getOffset($xGet(d), offsetX, $xScale),
75
62
  y: $yGet(d) + getOffset($yGet(d), offsetY, $yScale),
76
- data: d
63
+ data: d,
77
64
  };
78
65
  }
79
66
  });
@@ -82,7 +69,13 @@ $: points = $data.flatMap((d) => {
82
69
  <slot {points}>
83
70
  <g class="point-group">
84
71
  {#each points as point, index}
85
- <Circle cx={point.x} cy={point.y} {r} fill={getColor(point.data, index)} {...$$restProps} />
72
+ <Circle
73
+ cx={point.x}
74
+ cy={point.y}
75
+ {r}
76
+ fill={$config.r ? $rGet(point.data) : null}
77
+ {...$$restProps}
78
+ />
86
79
  {/each}
87
80
  </g>
88
81
  </slot>
@@ -5,11 +5,6 @@ declare const __propDef: {
5
5
  r?: number | undefined;
6
6
  offsetX?: (number | ((value: number, context: any) => number)) | undefined;
7
7
  offsetY?: (number | ((value: number, context: any) => number)) | undefined;
8
- color?: string | ((obj: {
9
- value: any;
10
- item: any;
11
- index: number;
12
- }) => string) | undefined;
13
8
  };
14
9
  events: {
15
10
  [evt: string]: CustomEvent<any>;
@@ -5,7 +5,7 @@ const defaultContext = writable({
5
5
  left: 0,
6
6
  data: null,
7
7
  show: () => { },
8
- hide: () => { }
8
+ hide: () => { },
9
9
  });
10
10
  export function tooltipContext() {
11
11
  return getContext(tooltipContextKey) ?? defaultContext;
@@ -27,7 +27,6 @@ import { localPoint } from '../utils/event';
27
27
  import { isScaleBand, scaleInvert } from '../utils/scales';
28
28
  import { quadtreeRects } from '../utils/quadtree';
29
29
  import { createPropertySortFunc, createSortFunc } from 'svelte-ux/utils/sort';
30
- import { firstValue } from '../utils/rect';
31
30
  const dispatch = createEventDispatcher();
32
31
  const { flatData, x, xScale, xGet, xRange, y, yScale, yGet, yRange, width, height, padding } = getContext('LayerCake');
33
32
  /*
@@ -171,7 +170,7 @@ function showTooltip(event, tooltipData) {
171
170
  ...$tooltip,
172
171
  left: snapToDataX ? $xGet(tooltipData) + $padding.left : localX,
173
172
  top: snapToDataY ? $yGet(tooltipData) + $padding.top : localY,
174
- data: tooltipData
173
+ data: tooltipData,
175
174
  };
176
175
  }
177
176
  else {
@@ -204,7 +203,7 @@ $: if (mode === 'quadtree') {
204
203
  quadtree = d3Quadtree()
205
204
  .extent([
206
205
  [0, 0],
207
- [$width, $height]
206
+ [$width, $height],
208
207
  ])
209
208
  .x((d) => {
210
209
  const value = $xGet(d);
@@ -238,10 +237,10 @@ let rects = [];
238
237
  $: if (mode === 'bounds' || mode === 'band') {
239
238
  rects = $flatData
240
239
  .map((d) => {
241
- const xValue = firstValue($xGet(d));
242
- const yValue = firstValue($yGet(d));
243
- const x = Array.isArray(xValue) ? min(xValue) : xValue;
244
- const y = Array.isArray(yValue) ? max(yValue) : yValue;
240
+ const xValue = $xGet(d);
241
+ const yValue = $yGet(d);
242
+ const x = Array.isArray(xValue) ? xValue[0] : xValue;
243
+ const y = Array.isArray(yValue) ? yValue[0] : yValue;
245
244
  const xOffset = isScaleBand($xScale) ? ($xScale.padding() * $xScale.step()) / 2 : 0;
246
245
  const yOffset = isScaleBand($yScale) ? ($yScale.padding() * $yScale.step()) / 2 : 0;
247
246
  const fullWidth = max($xRange) - min($xRange);
@@ -253,7 +252,7 @@ $: if (mode === 'bounds' || mode === 'band') {
253
252
  y: isScaleBand($yScale) ? y - yOffset : min($yRange),
254
253
  width: isScaleBand($xScale) ? $xScale.step() : fullWidth,
255
254
  height: isScaleBand($yScale) ? $yScale.step() : fullHeight,
256
- data: d
255
+ data: d,
257
256
  };
258
257
  }
259
258
  else if (mode === 'bounds') {
@@ -271,7 +270,7 @@ $: if (mode === 'bounds' || mode === 'band') {
271
270
  : isScaleBand($yScale)
272
271
  ? $yScale.step()
273
272
  : max($yRange) - y,
274
- data: d
273
+ data: d,
275
274
  };
276
275
  }
277
276
  })
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Sean Lynch <techniq35@gmail.com>",
4
4
  "license": "MIT",
5
5
  "repository": "techniq/layerchart",
6
- "version": "0.20.2",
6
+ "version": "0.21.1",
7
7
  "scripts": {
8
8
  "dev": "vite dev",
9
9
  "build": "vite build",
@@ -85,7 +85,7 @@
85
85
  "lodash-es": "^4.17.21",
86
86
  "shapefile": "^0.6.6",
87
87
  "svelte": "^3.59.1",
88
- "svelte-ux": "^0.47.0",
88
+ "svelte-ux": "^0.47.1",
89
89
  "topojson-client": "^3.1.0"
90
90
  },
91
91
  "main": "./dist/index.js",