@rokkit/chart 1.0.0-next.29 → 1.0.0-next.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/chart",
3
- "version": "1.0.0-next.29",
3
+ "version": "1.0.0-next.34",
4
4
  "description": "Components for making interactive charts.",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
@@ -13,28 +13,27 @@
13
13
  "access": "public"
14
14
  },
15
15
  "devDependencies": {
16
- "@sveltejs/vite-plugin-svelte": "^2.2.0",
17
- "@testing-library/svelte": "^3.2.2",
18
- "@vitest/ui": "~0.31.0",
19
- "eslint": "^8.40.0",
16
+ "@sveltejs/vite-plugin-svelte": "^2.4.2",
17
+ "@testing-library/svelte": "^4.0.3",
18
+ "@vitest/ui": "~0.32.3",
20
19
  "js-yaml": "^4.1.0",
21
- "jsdom": "^22.0.0",
22
- "svelte": "^3.59.1",
23
- "typescript": "^5.0.4",
24
- "vite": "^4.3.5",
25
- "vitest": "~0.31.0",
26
- "eslint-config-shared": "1.0.0-next.28",
27
- "shared-config": "1.0.0-next.28"
20
+ "jsdom": "^22.1.0",
21
+ "svelte": "^4.0.1",
22
+ "typescript": "^5.1.6",
23
+ "vite": "^4.3.9",
24
+ "vitest": "~0.32.3",
25
+ "shared-config": "1.0.0-next.34"
28
26
  },
29
27
  "dependencies": {
30
- "d3-array": "^3.2.3",
28
+ "d3-array": "^3.2.4",
31
29
  "d3-collection": "^1.0.7",
32
30
  "d3-scale": "^4.0.2",
33
31
  "d3-shape": "^3.2.0",
34
32
  "date-fns": "^2.30.0",
35
33
  "ramda": "^0.29.0",
34
+ "rokkit": "1.0.0-next.33",
36
35
  "yootils": "^0.3.1",
37
- "@rokkit/core": "1.0.0-next.29"
36
+ "@rokkit/core": "1.0.0-next.34"
38
37
  },
39
38
  "files": [
40
39
  "src/**/*.js",
@@ -52,12 +51,13 @@
52
51
  }
53
52
  },
54
53
  "scripts": {
55
- "lint": "prettier --check --plugin-search-dir=. . && eslint .",
56
- "format": "prettier --write --plugin-search-dir=. .",
54
+ "format": "prettier --write .",
55
+ "lint": "eslint --fix .",
57
56
  "test:ci": "vitest run",
58
57
  "test:ui": "vitest --ui",
59
58
  "test": "vitest",
60
59
  "coverage": "vitest run --coverage",
61
- "upgrade": "pnpm upgrade"
60
+ "latest": "pnpm upgrade --latest && pnpm test:ci",
61
+ "release": "tsc && pnpm publish --access public"
62
62
  }
63
63
  }
@@ -26,7 +26,7 @@
26
26
  height,
27
27
  data,
28
28
  theme,
29
- aes,
29
+ aes
30
30
  })
31
31
  </script>
32
32
 
@@ -73,7 +73,7 @@
73
73
  <title>A swatch with label {label}</title>
74
74
  {/if}
75
75
 
76
- {#each data as { cx, cy, r, type }, i}
76
+ {#each data as { cx, cy, type }, i}
77
77
  <Symbol
78
78
  x={cx}
79
79
  y={cy}
@@ -12,7 +12,7 @@
12
12
  </script>
13
13
 
14
14
  <button
15
- class="bg-gray-100 rounded shadow-md w-10 h-10 p-1 flex items-center justify-center hover:bg-primary-300"
15
+ class="h-10 w-10 flex items-center justify-center rounded bg-gray-100 p-1 shadow-md hover:bg-primary-300"
16
16
  class:isCurrent
17
17
  on:click
18
18
  on:mouseover
@@ -1,55 +1,55 @@
1
1
  <script>
2
- import SwatchButton from './SwatchButton.svelte'
2
+ import SwatchButton from './SwatchButton.svelte'
3
3
 
4
- export let columns
5
- export let rows
6
- export let items
7
- let grid
4
+ export let columns
5
+ export let rows
6
+ export let items
7
+ let grid
8
8
 
9
- function toGrid(columns, rows, patterns) {
10
- const count = patterns.length
11
- if (columns > 0) {
12
- rows = Math.ceil(count / columns)
13
- } else if (rows > 0) {
14
- columns = Math.ceil(count / rows)
15
- } else {
16
- columns = Math.ceil(Math.sqrt(count))
17
- rows = Math.ceil(count / columns)
18
- }
19
- const grid = [...Array(rows).keys()].map((row) =>
20
- [...Array(columns).keys()]
21
- .filter((column) => row * columns + column < count)
22
- .map((column) => ({
23
- item: patterns[row * columns + column],
24
- isCurrent: false,
25
- }))
26
- )
27
- return grid
28
- }
29
- let previous
30
- function handleClick(row, column) {
31
- console.log(row, column, grid)
32
- if (previous) {
33
- grid[previous.row][previous.column].isCurrent = false
34
- }
35
- grid[row][column].isCurrent = true
36
- previous = { row, column }
37
- }
38
- $: grid = toGrid(columns, rows, items)
39
- $: console.log(grid)
9
+ function toGrid(columns, rows, patterns) {
10
+ const count = patterns.length
11
+ if (columns > 0) {
12
+ rows = Math.ceil(count / columns)
13
+ } else if (rows > 0) {
14
+ columns = Math.ceil(count / rows)
15
+ } else {
16
+ columns = Math.ceil(Math.sqrt(count))
17
+ rows = Math.ceil(count / columns)
18
+ }
19
+ const grid = [...Array(rows).keys()].map((row) =>
20
+ [...Array(columns).keys()]
21
+ .filter((column) => row * columns + column < count)
22
+ .map((column) => ({
23
+ item: patterns[row * columns + column],
24
+ isCurrent: false
25
+ }))
26
+ )
27
+ return grid
28
+ }
29
+ let previous
30
+ function handleClick(row, column) {
31
+ console.log(row, column, grid)
32
+ if (previous) {
33
+ grid[previous.row][previous.column].isCurrent = false
34
+ }
35
+ grid[row][column].isCurrent = true
36
+ previous = { row, column }
37
+ }
38
+ $: grid = toGrid(columns, rows, items)
39
+ $: console.log(grid)
40
40
  </script>
41
41
 
42
42
  <row class="flex flex-col gap-2">
43
- {#each grid as items, row}
44
- <div class="flex flex-row gap-2">
45
- {#each items as { item, isCurrent }, column}
46
- <SwatchButton
47
- shape="shurikan"
48
- pattern={item}
49
- on:click={() => handleClick(row, column)}
50
- {isCurrent}
51
- />
52
- {/each}
53
- </div>
54
- {/each}
43
+ {#each grid as items, row}
44
+ <div class="flex flex-row gap-2">
45
+ {#each items as { item, isCurrent }, column}
46
+ <SwatchButton
47
+ shape="shurikan"
48
+ pattern={item}
49
+ on:click={() => handleClick(row, column)}
50
+ {isCurrent}
51
+ />
52
+ {/each}
53
+ </div>
54
+ {/each}
55
55
  </row>
@@ -34,4 +34,7 @@
34
34
  on:mouseover
35
35
  on:mouseleave
36
36
  on:focus
37
+ role="option"
38
+ aria-selected={false}
39
+ tabindex="0"
37
40
  />
@@ -87,7 +87,7 @@
87
87
  // Old data set needs exit animation, new data set needs entry animation
88
88
  </script>
89
89
 
90
- <svg viewBox="0 0 {phased.width} {phased.height}" class="flex chart">
90
+ <svg viewBox="0 0 {phased.width} {phased.height}" class="chart flex">
91
91
  <Grid />
92
92
  <Axis orient="bottom" />
93
93
  <Axis orient="left" />
@@ -1,6 +1,6 @@
1
1
  <script>
2
2
  import { createEventDispatcher } from 'svelte'
3
- import { elapsed, timer } from '../lib/timer.js'
3
+ import { elapsed, timer } from 'rokkit/stores'
4
4
 
5
5
  const dispatch = createEventDispatcher()
6
6
 
@@ -20,7 +20,7 @@
20
20
  }
21
21
  </script>
22
22
 
23
- <div class="flex flex-row gap-2 timer">
23
+ <div class="timer flex flex-row gap-2">
24
24
  <button on:click|preventDefault={() => (isEnabled = true)}>play</button>
25
25
  <button on:click|preventDefault={() => (isEnabled = false)}>pause</button>
26
26
  <button on:click|preventDefault={onReset}>reset</button>
package/src/chart.js CHANGED
@@ -1,9 +1,11 @@
1
- export function scales(data, aes, opts) {
2
- const { x, y } = aes
3
- const { width, height, flipCoords } = {
4
- width: 800,
5
- height: 600,
6
- flipCoords: false,
7
- ...opts
8
- }
9
- }
1
+ // export function scales(data, aes, opts) {
2
+ // const { x, y } = aes
3
+ // const { width, height, flipCoords } = {
4
+ // width: 800,
5
+ // height: 600,
6
+ // flipCoords: false,
7
+ // ...opts
8
+ // }
9
+
10
+ // return { x, y, width, height, flipCoords }
11
+ // }
@@ -1,5 +1,5 @@
1
1
  import { nest } from 'd3-collection'
2
- import { max, quantile, ascending } from 'd3-array'
2
+ import { max, quantile, ascending, bin } from 'd3-array'
3
3
  import { scaleLinear } from 'd3-scale'
4
4
  import { area, curveCatmullRom } from 'd3-shape'
5
5
  import { getScale } from './utils'
@@ -1,13 +1,13 @@
1
- import { writable } from 'svelte/store'
2
-
3
- function createChart() {
4
- const { subscribe, set } = writable({
5
- data: [],
6
- x: '',
7
- y: ''
8
- })
9
- return { subscribe, set }
10
- }
1
+ // import { writable } from 'svelte/store'
2
+ import { tweened, cubicOut } from 'svelte/motion'
3
+ // function createChart() {
4
+ // const { subscribe, set } = writable({
5
+ // data: [],
6
+ // x: '',
7
+ // y: ''
8
+ // })
9
+ // return { subscribe, set }
10
+ // }
11
11
 
12
12
  export function animatedChart(input, key, valueFields = [], previous = []) {
13
13
  const previousKeys = new Set(previous.map((item) => item[key]))
@@ -20,7 +20,7 @@
20
20
 
21
21
  $: colors = ticks.map(({ value }) => ({
22
22
  color: scale(value),
23
- offset: `${scalePercent(value)}%`,
23
+ offset: `${scalePercent(value)}%`
24
24
  }))
25
25
  $: id = uniqueId('legend-')
26
26
  </script>
@@ -15,7 +15,7 @@
15
15
  $: x = x - size / 2
16
16
  $: y = y - size / 2
17
17
 
18
- $: d = $swatchStore[shapes][name](size)
18
+ $: d = $swatchStore['shapes'][name](size)
19
19
  // typeof shape === 'function'
20
20
  // ? shape(size)
21
21
  // : (shape || name) in namedShapes
package/src/funnel.svelte CHANGED
@@ -1,4 +1,4 @@
1
- <script context="module">
1
+ <!-- <script context="module">
2
2
  /**
3
3
  * @type {import('@sveltejs/kit').Load}
4
4
  */
@@ -19,7 +19,7 @@
19
19
  error: new Error(`Could not load ${url}`)
20
20
  }
21
21
  }
22
- </script>
22
+ </script> -->
23
23
 
24
24
  <script>
25
25
  import { FunnelPlot, Chart } from '@rokkit/chart'
package/src/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // export { aes } from './lib/aes'
2
2
  // export { timelapse } from './lib/timelapse'
3
3
  // export { axisTicks } from './lib/axis'
4
- export { timer, elapsed } from './lib/timer'
4
+ // export { timer, elapsed } from './lib/timer'
5
5
  // export { default as Chart } from './chart/Chart.svelte'
6
6
  // export { default as Axis } from './chart/Axis.svelte'
7
7
  export { default as Swatch } from './chart/Swatch.svelte'
@@ -1,54 +1,54 @@
1
1
  <script>
2
- import { getContext } from 'svelte'
2
+ import { getContext } from 'svelte'
3
3
 
4
- let chart = getContext('chart')
4
+ let chart = getContext('chart')
5
5
 
6
- export let whisker = true
7
- export let boxWidth = 150
8
- export let stroke = 'green'
9
- export let fill = '#69b3a2' // fixed color or attribute to be used for color
10
- export let scaleFill = () => fill // defaults to fill color
6
+ export let whisker = true
7
+ export let boxWidth = 150
8
+ export let stroke = 'green'
9
+ export let fill = '#69b3a2' // fixed color or attribute to be used for color
10
+ export let scaleFill = () => fill // defaults to fill color
11
11
 
12
- $: data = $chart.summary()
12
+ $: data = $chart.summary()
13
13
  </script>
14
14
 
15
15
  {#each data as { key, value }}
16
- <rect
17
- width={boxWidth}
18
- height={$chart.axis.y.scale(value.q1) - $chart.axis.y.scale(value.q3)}
19
- x={$chart.axis.x.scale(key) - boxWidth / 2}
20
- y={$chart.axis.y.scale(value.q3)}
21
- fill={scaleFill(value[fill])}
22
- {stroke}
23
- />
24
- <line
25
- x1={$chart.axis.x.scale(key) - boxWidth / 2}
26
- x2={$chart.axis.x.scale(key) + boxWidth / 2}
27
- y1={$chart.axis.y.scale(value.median)}
28
- y2={$chart.axis.y.scale(value.median)}
29
- {stroke}
30
- />
31
- <line
32
- x1={$chart.axis.x.scale(key)}
33
- x2={$chart.axis.x.scale(key)}
34
- y1={$chart.axis.y.scale(value.min)}
35
- y2={$chart.axis.y.scale(value.max)}
36
- {stroke}
37
- />
38
- {#if whisker}
39
- <line
40
- x1={$chart.axis.x.scale(key) - boxWidth / 8}
41
- x2={$chart.axis.x.scale(key) + boxWidth / 8}
42
- y1={$chart.axis.y.scale(value.min)}
43
- y2={$chart.axis.y.scale(value.min)}
44
- {stroke}
45
- />
46
- <line
47
- x1={$chart.axis.x.scale(key) - boxWidth / 8}
48
- x2={$chart.axis.x.scale(key) + boxWidth / 8}
49
- y1={$chart.axis.y.scale(value.max)}
50
- y2={$chart.axis.y.scale(value.max)}
51
- {stroke}
52
- />
53
- {/if}
16
+ <rect
17
+ width={boxWidth}
18
+ height={$chart.axis.y.scale(value.q1) - $chart.axis.y.scale(value.q3)}
19
+ x={$chart.axis.x.scale(key) - boxWidth / 2}
20
+ y={$chart.axis.y.scale(value.q3)}
21
+ fill={scaleFill(value[fill])}
22
+ {stroke}
23
+ />
24
+ <line
25
+ x1={$chart.axis.x.scale(key) - boxWidth / 2}
26
+ x2={$chart.axis.x.scale(key) + boxWidth / 2}
27
+ y1={$chart.axis.y.scale(value.median)}
28
+ y2={$chart.axis.y.scale(value.median)}
29
+ {stroke}
30
+ />
31
+ <line
32
+ x1={$chart.axis.x.scale(key)}
33
+ x2={$chart.axis.x.scale(key)}
34
+ y1={$chart.axis.y.scale(value.min)}
35
+ y2={$chart.axis.y.scale(value.max)}
36
+ {stroke}
37
+ />
38
+ {#if whisker}
39
+ <line
40
+ x1={$chart.axis.x.scale(key) - boxWidth / 8}
41
+ x2={$chart.axis.x.scale(key) + boxWidth / 8}
42
+ y1={$chart.axis.y.scale(value.min)}
43
+ y2={$chart.axis.y.scale(value.min)}
44
+ {stroke}
45
+ />
46
+ <line
47
+ x1={$chart.axis.x.scale(key) - boxWidth / 8}
48
+ x2={$chart.axis.x.scale(key) + boxWidth / 8}
49
+ y1={$chart.axis.y.scale(value.max)}
50
+ y2={$chart.axis.y.scale(value.max)}
51
+ {stroke}
52
+ />
53
+ {/if}
54
54
  {/each}
@@ -2,7 +2,7 @@
2
2
  import { summarize, heatmap } from './heatmap'
3
3
  import { interpolateHsl } from 'd3-interpolate'
4
4
  import { scaleLinear } from 'd3-scale'
5
- import ContinuousLegend from '../elements/ContinuousLegend.svelte'
5
+ // import ContinuousLegend from '../elements/ContinuousLegend.svelte'
6
6
  import DiscreteLegend from '../elements/DiscreteLegend.svelte'
7
7
  import ColorRamp from '../elements/ColorRamp.svelte'
8
8
 
@@ -13,7 +13,7 @@
13
13
  export let dateField = 'date'
14
14
  export let valueField = null
15
15
  export let months = 12
16
- export let colors = [transparent, '#FB8C00']
16
+ export let colors = ['transparent', '#FB8C00']
17
17
  export let padding = 8
18
18
  export let space = 2
19
19
  export let size = 10
@@ -29,7 +29,7 @@
29
29
 
30
30
  <svg viewBox="0 0 {width} {height}">
31
31
  {#if Array.isArray(data)}
32
- {#each data as item, i}
32
+ {#each data as item}
33
33
  {#if item.rank < limit}
34
34
  <Bar {...item} fill={colors[item.name]} {scales} />
35
35
  {/if}
@@ -1,30 +1,30 @@
1
1
  <script>
2
- import { clamp } from 'yootils'
3
- import Symbol from '../chart/Symbol.svelte'
4
- import { getContext } from 'svelte'
2
+ import { clamp } from 'yootils'
3
+ import Symbol from '../chart/Symbol.svelte'
4
+ import { getContext } from 'svelte'
5
5
 
6
- const chart = getContext('chart')
6
+ const chart = getContext('chart')
7
7
 
8
- export let size = 8
9
- export let fill = '#c0c0c0'
10
- export let stroke = '#3c3c3c'
11
- export let jitterWidth = 50
12
- export let offset
8
+ export let size = 8
9
+ export let fill = '#c0c0c0'
10
+ export let stroke = '#3c3c3c'
11
+ export let jitterWidth = 50
12
+ export let offset
13
13
 
14
- $: jitterWidth = clamp(jitterWidth, 0, 100 / 2)
15
- $: offset = clamp(offset | (jitterWidth / 2), 0, 100)
14
+ $: jitterWidth = clamp(jitterWidth, 0, 100 / 2)
15
+ $: offset = clamp(offset | (jitterWidth / 2), 0, 100)
16
16
  </script>
17
17
 
18
18
  {#if $chart.data}
19
- {#each $chart.data as d}
20
- <Symbol
21
- x={$chart.axis.x.scale(d[$chart.x]) -
22
- offset +
23
- Math.random() * jitterWidth}
24
- y={$chart.axis.y.scale(d[$chart.y])}
25
- {fill}
26
- {stroke}
27
- {size}
28
- />
29
- {/each}
19
+ {#each $chart.data as d}
20
+ <Symbol
21
+ x={$chart.axis.x.scale(d[$chart.x]) -
22
+ offset +
23
+ Math.random() * jitterWidth}
24
+ y={$chart.axis.y.scale(d[$chart.y])}
25
+ {fill}
26
+ {stroke}
27
+ {size}
28
+ />
29
+ {/each}
30
30
  {/if}
@@ -1,11 +1,11 @@
1
1
  <script>
2
- import { getContext } from 'svelte'
2
+ import { getContext } from 'svelte'
3
3
 
4
- let chart = getContext('chart')
5
- $: data = $chart.violin()
6
- // $: console.log(data)
4
+ let chart = getContext('chart')
5
+ $: data = $chart.violin()
6
+ // $: console.log(data)
7
7
  </script>
8
8
 
9
- {#each data as { x, curve }, i}
10
- <path d={curve} transform="translate({x},0)" fill="gray" stroke="none" />
9
+ {#each data as { x, curve }}
10
+ <path d={curve} transform="translate({x},0)" fill="gray" stroke="none" />
11
11
  {/each}
@@ -10,7 +10,7 @@ import {
10
10
  endOfWeek
11
11
  } from 'date-fns'
12
12
  import { nest } from 'd3-collection'
13
- import { group } from 'd3-array'
13
+ // import { group } from 'd3-array'
14
14
 
15
15
  const DATE_FORMAT = 'yyyy-MM-dd'
16
16
  const weekdays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
package/src/lib/timer.js DELETED
@@ -1,44 +0,0 @@
1
- import { writable } from 'svelte/store'
2
-
3
- let req
4
- let prev
5
- const elapsed = writable(0)
6
-
7
- const tick = (timestamp) => {
8
- if (!prev) prev = timestamp
9
- const diff = Math.round(timestamp - prev)
10
-
11
- if (diff > 0) {
12
- prev = timestamp
13
- }
14
- elapsed.update((e) => e + diff)
15
- req = window.requestAnimationFrame(tick)
16
- }
17
-
18
- const timer = {
19
- start() {
20
- if (typeof window === 'undefined') return
21
- else if (!req) {
22
- prev = null
23
- req = window.requestAnimationFrame(tick)
24
- }
25
- },
26
- stop() {
27
- if (typeof window === 'undefined') return
28
- else if (req) {
29
- window.cancelAnimationFrame(req)
30
- req = null
31
- }
32
- },
33
- toggle() {
34
- req ? timer.stop() : timer.start()
35
- },
36
- set(val) {
37
- if (typeof val === 'number') elapsed.set(val)
38
- },
39
- reset() {
40
- timer.set(0)
41
- }
42
- }
43
-
44
- export { timer, elapsed }
@@ -1,5 +0,0 @@
1
- <script>
2
- let y // axis (day of week)
3
- let x // week Number (week starts sunday)
4
- let weeks //weeks
5
- </script>