@rokkit/chart 1.0.0-next.28 → 1.0.0-next.32

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.28",
3
+ "version": "1.0.0-next.32",
4
4
  "description": "Components for making interactive charts.",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
@@ -13,18 +13,16 @@
13
13
  "access": "public"
14
14
  },
15
15
  "devDependencies": {
16
- "@sveltejs/vite-plugin-svelte": "^2.2.0",
16
+ "@sveltejs/vite-plugin-svelte": "^2.4.1",
17
17
  "@testing-library/svelte": "^3.2.2",
18
- "@vitest/ui": "~0.31.0",
19
- "eslint": "^8.40.0",
18
+ "@vitest/ui": "~0.31.1",
20
19
  "js-yaml": "^4.1.0",
21
- "jsdom": "^22.0.0",
20
+ "jsdom": "^22.1.0",
22
21
  "svelte": "^3.59.1",
23
22
  "typescript": "^5.0.4",
24
- "vite": "^4.3.5",
25
- "vitest": "~0.31.0",
26
- "eslint-config-shared": "1.0.0-next.27",
27
- "shared-config": "1.0.0-next.27"
23
+ "vite": "^4.3.9",
24
+ "vitest": "~0.31.1",
25
+ "shared-config": "1.0.0-next.32"
28
26
  },
29
27
  "dependencies": {
30
28
  "d3-array": "^3.2.3",
@@ -34,7 +32,7 @@
34
32
  "date-fns": "^2.30.0",
35
33
  "ramda": "^0.29.0",
36
34
  "yootils": "^0.3.1",
37
- "@rokkit/core": "1.0.0-next.28"
35
+ "@rokkit/core": "1.0.0-next.32"
38
36
  },
39
37
  "files": [
40
38
  "src/**/*.js",
@@ -52,12 +50,13 @@
52
50
  }
53
51
  },
54
52
  "scripts": {
55
- "lint": "prettier --check --plugin-search-dir=. . && eslint .",
56
- "format": "prettier --write --plugin-search-dir=. .",
53
+ "format": "prettier --write .",
54
+ "lint": "eslint --fix .",
57
55
  "test:ci": "vitest run",
58
56
  "test:ui": "vitest --ui",
59
57
  "test": "vitest",
60
58
  "coverage": "vitest run --coverage",
61
- "upgrade": "pnpm upgrade"
59
+ "latest": "pnpm upgrade --latest && pnpm test:ci",
60
+ "release": "tsc && pnpm publish --access public"
62
61
  }
63
62
  }
@@ -26,7 +26,7 @@
26
26
  height,
27
27
  data,
28
28
  theme,
29
- aes,
29
+ aes
30
30
  })
31
31
  </script>
32
32
 
@@ -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>
@@ -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" />
@@ -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'
@@ -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
@@ -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
9
  {#each data as { x, curve }, i}
10
- <path d={curve} transform="translate({x},0)" fill="gray" stroke="none" />
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']
@@ -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>