layerchart 0.17.0 → 0.17.2

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.
@@ -46,6 +46,12 @@ export let innerRadius = undefined;
46
46
  /**
47
47
  * Define outerRadius. Defaults to yRange max / 2 (ie. chart height / 2)
48
48
  */
49
+ /**
50
+ * Define outerRadius. Defaults to yRange max (ie. chart height / 2)
51
+ * • value >= 1: discrete value
52
+ * • value < 1: percent of chart height / 2
53
+ * • value < 0: offset of chart height / 2
54
+ */
49
55
  export let outerRadius = undefined;
50
56
  export let cornerRadius = 0;
51
57
  export let padAngle = 0;
@@ -53,15 +59,50 @@ export let padAngle = 0;
53
59
  export let track = false;
54
60
  const { yRange } = getContext('LayerCake');
55
61
  $: scale = scaleLinear().domain(domain).range(range);
56
- $: _outerRadius = outerRadius ?? max($yRange) / 2;
57
- $: _innerRadius =
58
- (innerRadius > 1
59
- ? innerRadius
60
- : innerRadius > 0
61
- ? _outerRadius * innerRadius
62
- : innerRadius < 0
63
- ? _outerRadius - innerRadius
64
- : innerRadius) ?? min($yRange);
62
+ function getOuterRadius(outerRadius, chartRadius) {
63
+ if (outerRadius == null) {
64
+ return chartRadius;
65
+ }
66
+ else if (outerRadius > 1) {
67
+ // discrete value
68
+ return outerRadius;
69
+ }
70
+ else if (outerRadius > 0) {
71
+ // percent of `chartRadius`
72
+ return chartRadius * outerRadius;
73
+ }
74
+ else if (outerRadius < 0) {
75
+ // offset of `chartRadius`
76
+ return chartRadius + outerRadius;
77
+ }
78
+ else {
79
+ // 0
80
+ return outerRadius;
81
+ }
82
+ }
83
+ $: _outerRadius = getOuterRadius(outerRadius, max($yRange) / 2);
84
+ function getInnerRadius(innerRadius, outerRadius) {
85
+ if (innerRadius == null) {
86
+ return Math.min(...$yRange);
87
+ }
88
+ else if (innerRadius > 1) {
89
+ // discrete value
90
+ return innerRadius;
91
+ }
92
+ else if (innerRadius > 0) {
93
+ // percent of `outerRadius`
94
+ return outerRadius * innerRadius;
95
+ }
96
+ else if (innerRadius < 0) {
97
+ // offset of `outerRadius`
98
+ return outerRadius + innerRadius;
99
+ }
100
+ else {
101
+ // 0
102
+ return innerRadius;
103
+ }
104
+ }
105
+ $: _innerRadius = getInnerRadius(innerRadius, _outerRadius);
65
106
  $: arc = d3arc()
66
107
  .innerRadius(_innerRadius)
67
108
  .outerRadius(_outerRadius)
@@ -11,8 +11,8 @@ declare const __propDef: {
11
11
  range?: number[] | undefined;
12
12
  startAngle?: number | undefined;
13
13
  endAngle?: number | undefined;
14
- innerRadius?: undefined;
15
- outerRadius?: undefined;
14
+ innerRadius?: number | undefined;
15
+ outerRadius?: number | undefined;
16
16
  cornerRadius?: number | undefined;
17
17
  padAngle?: number | undefined;
18
18
  track?: boolean | SVGAttributes<SVGPathElement> | undefined;
@@ -1,5 +1,5 @@
1
1
  <script>import { getContext } from 'svelte';
2
- import { format as formatValue } from 'svelte-ux';
2
+ import { format as formatValue, cls } from 'svelte-ux';
3
3
  import { max, min } from 'd3-array';
4
4
  import Text from './Text.svelte';
5
5
  import { isScaleBand } from '../utils/scales';
@@ -79,14 +79,15 @@ function getDefaultLabelProps() {
79
79
  {@const tickCoords = getCoords(tick)}
80
80
  <g>
81
81
  {#if gridlines !== false}
82
+ {@const lineProps = typeof gridlines === 'object' ? gridlines : null}
82
83
  {#if orientation === 'horizontal'}
83
84
  <line
84
85
  x1={tickCoords.x}
85
86
  y1={min($yRange)}
86
87
  x2={tickCoords.x}
87
88
  y2={max($yRange)}
88
- class="gridline stroke-gray-200"
89
- {...gridlines}
89
+ {...lineProps}
90
+ class={cls('gridline stroke-gray-200', lineProps?.class)}
90
91
  />
91
92
  {:else if orientation === 'vertical'}
92
93
  <line
@@ -94,8 +95,8 @@ function getDefaultLabelProps() {
94
95
  y1={tickCoords.y}
95
96
  x2={$width}
96
97
  y2={tickCoords.y}
97
- class="gridline stroke-gray-200"
98
- {...gridlines}
98
+ {...lineProps}
99
+ class={cls('gridline stroke-gray-200', lineProps?.class)}
99
100
  />
100
101
  {/if}
101
102
  {/if}
@@ -16,7 +16,7 @@ declare const __propDef: {
16
16
  yScale?: Function | undefined;
17
17
  xBaseline?: number | null | undefined;
18
18
  yBaseline?: number | null | undefined;
19
- tooltip?: ComponentProps<TooltipContext> | undefined;
19
+ tooltip?: ComponentProps<TooltipContext> | boolean | undefined;
20
20
  geo?: ComponentProps<GeoContext> | undefined;
21
21
  };
22
22
  events: {
@@ -1,6 +1,6 @@
1
1
  <script>import { getContext } from 'svelte';
2
- import { get } from 'svelte/store';
3
2
  import { max } from 'd3-array';
3
+ import { notNull } from 'svelte-ux';
4
4
  import { isScaleBand } from '../utils/scales';
5
5
  import Circle from './Circle.svelte';
6
6
  import Line from './Line.svelte';
@@ -10,7 +10,7 @@ const tooltip = tooltipContext();
10
10
  export let color = undefined;
11
11
  export let axis = 'x';
12
12
  // TODO: Fix circle points being backwards for stack (see AreaStack)
13
- function getColor(item, index = undefined) {
13
+ function getColor(item, index = -1) {
14
14
  if (color) {
15
15
  if (typeof color === 'function') {
16
16
  return color({ value: $y(item), item, index });
@@ -40,7 +40,7 @@ $: if ($tooltip.data) {
40
40
  // `x` accessor with multiple properties (ex. `x={['start', 'end']})`)
41
41
  lines = [
42
42
  ...lines,
43
- ...x.map((xItem, i) => ({
43
+ ...x.filter(notNull).map((xItem, i) => ({
44
44
  x1: xItem + xOffset,
45
45
  y1: 0,
46
46
  x2: xItem + xOffset,
@@ -65,7 +65,7 @@ $: if ($tooltip.data) {
65
65
  // `y` accessor with multiple properties (ex. `y={['start', 'end']})`)
66
66
  lines = [
67
67
  ...lines,
68
- ...y.map((yItem, i) => ({
68
+ ...y.filter(notNull).map((yItem, i) => ({
69
69
  x1: 0,
70
70
  y1: yItem + yOffset,
71
71
  x2: max($xRange),
@@ -87,7 +87,7 @@ $: if ($tooltip.data) {
87
87
  }
88
88
  if (Array.isArray(x)) {
89
89
  // `x` accessor with multiple properties (ex. `x={['start', 'end']})`)
90
- points = x.map((xItem, i) => ({
90
+ points = x.filter(notNull).map((xItem, i) => ({
91
91
  x: xItem + xOffset,
92
92
  y: $yGet($tooltip.data) + yOffset,
93
93
  color: getColor($tooltip.data) // TODO: improve
@@ -1,6 +1,6 @@
1
1
  <script>export let id;
2
2
  export let from;
3
- export let via; // TODO: Currently --tw-gradient-via is not the color but the full stops
3
+ export let via = undefined; // TODO: Currently --tw-gradient-via is not the color but the full stops
4
4
  export let to;
5
5
  export let vertical = false;
6
6
  export let x1 = '0%';
@@ -4,7 +4,7 @@ declare const __propDef: {
4
4
  [x: string]: any;
5
5
  id: string;
6
6
  from: string | boolean;
7
- via: string;
7
+ via?: string | undefined;
8
8
  to: string | boolean;
9
9
  vertical?: boolean | undefined;
10
10
  x1?: string | undefined;
@@ -35,6 +35,8 @@ $: {
35
35
  fill="none"
36
36
  on:click
37
37
  on:mouseover
38
+ on:mousemove
38
39
  on:mouseout
40
+ on:mouseleave
39
41
  {...$$restProps}
40
42
  />
@@ -18,7 +18,9 @@ declare const __propDef: {
18
18
  events: {
19
19
  click: MouseEvent;
20
20
  mouseover: MouseEvent;
21
+ mousemove: MouseEvent;
21
22
  mouseout: MouseEvent;
23
+ mouseleave: MouseEvent;
22
24
  } & {
23
25
  [evt: string]: CustomEvent<any>;
24
26
  };
@@ -1,6 +1,7 @@
1
1
  <script>import { getContext } from 'svelte';
2
2
  import Circle from './Circle.svelte';
3
3
  import { isScaleBand } from '../utils/scales';
4
+ import { notNull } from 'svelte-ux';
4
5
  const context = getContext('LayerCake');
5
6
  const { data, xGet, y, yGet, xScale, yScale, rGet, config } = context;
6
7
  export let r = 5;
@@ -39,7 +40,9 @@ $: points = $data.flatMap((d) => {
39
40
  x={["prop1" ,"prop2"]}
40
41
  y="prop3"
41
42
  */
42
- return $xGet(d).map((x) => {
43
+ return $xGet(d)
44
+ .filter(notNull)
45
+ .map((x) => {
43
46
  return {
44
47
  x: x + getOffset(x, offsetX, $xScale),
45
48
  y: $yGet(d) + getOffset($yGet(d), offsetY, $yScale),
@@ -52,7 +55,9 @@ $: points = $data.flatMap((d) => {
52
55
  x="prop1"
53
56
  y={["prop2" ,"prop3"]}
54
57
  */
55
- return $yGet(d).map((y) => {
58
+ return $yGet(d)
59
+ .filter(notNull)
60
+ .map((y) => {
56
61
  return {
57
62
  x: $xGet(d) + getOffset($xGet(d), offsetX, $xScale),
58
63
  y: y + getOffset(y, offsetY, $yScale),
@@ -24,5 +24,7 @@ $: tweened_height.set(height);
24
24
  {...$$restProps}
25
25
  on:click
26
26
  on:mouseover
27
+ on:mousemove
27
28
  on:mouseout
29
+ on:mouseleave
28
30
  />
@@ -16,6 +16,7 @@ export let tweened = undefined;
16
16
  </ClipPath>
17
17
 
18
18
  {#if $$slots.default}
19
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
19
20
  <g style="clip-path: url(#{id})" on:click on:mousemove on:mouseleave>
20
21
  <slot {id} />
21
22
  </g>
@@ -2,6 +2,7 @@
2
2
  import { spring } from 'svelte/motion';
3
3
  import { fade } from 'svelte/transition';
4
4
  import { writable } from 'svelte/store';
5
+ import { cls } from 'svelte-ux';
5
6
  import { tooltipContext } from './TooltipContext.svelte';
6
7
  export let topOffset = 10;
7
8
  export let leftOffset = 10;
@@ -15,8 +16,8 @@ let tooltipHeight = 0;
15
16
  let top = animate ? spring($tooltip.top) : writable($tooltip.top);
16
17
  $: if ($tooltip) {
17
18
  if (contained === 'container' && $tooltip.top + topOffset + tooltipHeight > $containerHeight) {
18
- // change side
19
- $top = $tooltip.top - (topOffset + tooltipHeight);
19
+ // Change side. Do not allow tooltip to go above the top
20
+ $top = Math.max($tooltip.top - (topOffset + tooltipHeight), 0);
20
21
  }
21
22
  else {
22
23
  $top = $tooltip.top + topOffset;
@@ -25,8 +26,8 @@ $: if ($tooltip) {
25
26
  let left = animate ? spring($tooltip.left) : writable($tooltip.left);
26
27
  $: if ($tooltip) {
27
28
  if (contained === 'container' && $tooltip.left + leftOffset + tooltipWidth > $containerWidth) {
28
- // change side
29
- $left = $tooltip.left - (leftOffset + tooltipWidth);
29
+ // Change side
30
+ $left = Math.max($tooltip.left - (leftOffset + tooltipWidth), 0);
30
31
  }
31
32
  else {
32
33
  $left = $tooltip.left + leftOffset;
@@ -36,7 +37,7 @@ $: if ($tooltip) {
36
37
 
37
38
  {#if $tooltip.data}
38
39
  <div
39
- class="absolute pointer-events-none z-50"
40
+ class={cls('absolute pointer-events-none z-50', $$props.class)}
40
41
  style:top="{$top}px"
41
42
  style:left="{$left}px"
42
43
  transition:fade={{ duration: 100 }}
@@ -44,11 +45,11 @@ $: if ($tooltip) {
44
45
  bind:clientHeight={tooltipHeight}
45
46
  >
46
47
  <div
47
- class="bg-gray-900/90 backdrop-filter backdrop-blur-[2px] text-white rounded elevation-1 px-2 py-1"
48
+ class="bg-gray-900/90 backdrop-filter backdrop-blur-[2px] text-white rounded elevation-1 px-2 py-1 h-full"
48
49
  >
49
50
  {#if header || $$slots.header}
50
51
  <div class="text-center font-semibold whitespace-nowrap">
51
- <slot name="header">
52
+ <slot name="header" data={$tooltip.data}>
52
53
  {header($tooltip.data)}
53
54
  </slot>
54
55
  </div>
@@ -1,6 +1,7 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
+ [x: string]: any;
4
5
  topOffset?: number | undefined;
5
6
  leftOffset?: number | undefined;
6
7
  contained?: false | "container" | undefined;
@@ -11,7 +12,9 @@ declare const __propDef: {
11
12
  [evt: string]: CustomEvent<any>;
12
13
  };
13
14
  slots: {
14
- header: {};
15
+ header: {
16
+ data: any;
17
+ };
15
18
  default: {
16
19
  data: any;
17
20
  };
@@ -6,7 +6,7 @@ export let max = 100;
6
6
  export let step = 1;
7
7
  </script>
8
8
 
9
- <Field let:id {...$$restProps}>
9
+ <Field let:id classes={{ input: 'mt-[6px] mb-1' }} {...$$restProps}>
10
10
  <Button
11
11
  icon={mdiChevronLeft}
12
12
  on:click={() => (value -= value > min ? step : 0)}
@@ -11,10 +11,10 @@ export let icon;
11
11
  <Toggle let:on={open} let:toggle>
12
12
  <Button {icon} on:click={toggle} variant="fill-light" color="blue" size="sm">{label}</Button>
13
13
  <Dialog {open} on:close={toggle}>
14
- <div class="grid grid-cols-[1fr,auto] gap-1 items-center p-4">
15
- <div>
14
+ <div class="grid grid-cols-[1fr,auto] gap-3 items-center p-4">
15
+ <div class="overflow-auto">
16
16
  <div class="text-lg font-semibold">{label}</div>
17
- <div class="text-xs text-black/50">{href}</div>
17
+ <div class="text-xs text-black/50 truncate">{href}</div>
18
18
  </div>
19
19
 
20
20
  {#if href}
@@ -24,7 +24,7 @@ export let icon;
24
24
  {/if}
25
25
  </div>
26
26
 
27
- <div class="max-h-[80vh] w-[70vw] overflow-auto">
27
+ <div class="max-h-[80vh] overflow-auto">
28
28
  <Code {source} language={source.startsWith('<script') ? 'svelte' : 'js'} />
29
29
  </div>
30
30
 
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.17.0",
6
+ "version": "0.17.2",
7
7
  "scripts": {
8
8
  "dev": "vite dev",
9
9
  "build": "vite build",
@@ -18,8 +18,8 @@
18
18
  "devDependencies": {
19
19
  "@rollup/plugin-dsv": "^3.0.2",
20
20
  "@sveltejs/adapter-vercel": "^3.0.1",
21
- "@sveltejs/kit": "^1.20.4",
22
- "@sveltejs/package": "^2.0.2",
21
+ "@sveltejs/kit": "^1.20.5",
22
+ "@sveltejs/package": "^2.1.0",
23
23
  "@tailwindcss/typography": "^0.5.9",
24
24
  "@types/d3-array": "^3.0.5",
25
25
  "@types/d3-delaunay": "^6.0.1",
@@ -36,7 +36,7 @@
36
36
  "@types/shapefile": "^0.6.1",
37
37
  "@types/topojson-client": "^3.1.1",
38
38
  "autoprefixer": "^10.4.14",
39
- "mdsvex": "^0.10.6",
39
+ "mdsvex": "^0.11.0",
40
40
  "prettier": "^2.8.8",
41
41
  "prettier-plugin-svelte": "^2.10.1",
42
42
  "prism-themes": "^1.9.0",
@@ -71,11 +71,11 @@
71
71
  "d3-shape": "^3.2.0",
72
72
  "d3-tile": "^1.0.0",
73
73
  "date-fns": "^2.30.0",
74
- "layercake": "^7.4.0",
74
+ "layercake": "^7.6.0",
75
75
  "lodash-es": "^4.17.21",
76
76
  "shapefile": "^0.6.6",
77
77
  "svelte": "^3.59.1",
78
- "svelte-ux": "^0.42.0",
78
+ "svelte-ux": "^0.43.3",
79
79
  "topojson-client": "^3.1.0"
80
80
  },
81
81
  "main": "./dist/index.js",