@rokkit/chart 1.0.0-next.11

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.
Files changed (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +55 -0
  3. package/package.json +63 -0
  4. package/src/chart/FacetGrid.svelte +51 -0
  5. package/src/chart/Grid.svelte +34 -0
  6. package/src/chart/Legend.svelte +16 -0
  7. package/src/chart/PatternDefs.svelte +13 -0
  8. package/src/chart/Swatch.svelte +93 -0
  9. package/src/chart/SwatchButton.svelte +29 -0
  10. package/src/chart/SwatchGrid.svelte +55 -0
  11. package/src/chart/Symbol.svelte +37 -0
  12. package/src/chart/Texture.svelte +16 -0
  13. package/src/chart/TexturedShape.svelte +27 -0
  14. package/src/chart/TimelapseChart.svelte +97 -0
  15. package/src/chart/Timer.svelte +27 -0
  16. package/src/chart.js +9 -0
  17. package/src/components/charts/Axis.svelte +66 -0
  18. package/src/components/charts/Chart.svelte +35 -0
  19. package/src/components/index.js +23 -0
  20. package/src/components/lib/axis.js +0 -0
  21. package/src/components/lib/chart.js +187 -0
  22. package/src/components/lib/color.js +327 -0
  23. package/src/components/lib/funnel.js +204 -0
  24. package/src/components/lib/index.js +19 -0
  25. package/src/components/lib/pattern.js +190 -0
  26. package/src/components/lib/rollup.js +55 -0
  27. package/src/components/lib/shape.js +199 -0
  28. package/src/components/lib/summary.js +145 -0
  29. package/src/components/lib/theme.js +23 -0
  30. package/src/components/lib/timer.js +41 -0
  31. package/src/components/lib/utils.js +165 -0
  32. package/src/components/plots/BarPlot.svelte +36 -0
  33. package/src/components/plots/BoxPlot.svelte +54 -0
  34. package/src/components/plots/ScatterPlot.svelte +30 -0
  35. package/src/components/store.js +70 -0
  36. package/src/constants.js +66 -0
  37. package/src/elements/Bar.svelte +35 -0
  38. package/src/elements/ColorRamp.svelte +51 -0
  39. package/src/elements/ContinuousLegend.svelte +46 -0
  40. package/src/elements/DiscreteLegend.svelte +41 -0
  41. package/src/elements/Label.svelte +12 -0
  42. package/src/elements/PatternDefs.svelte +13 -0
  43. package/src/elements/PatternMask.svelte +20 -0
  44. package/src/elements/Symbol.svelte +38 -0
  45. package/src/elements/Tooltip.svelte +23 -0
  46. package/src/funnel.svelte +35 -0
  47. package/src/geom.js +105 -0
  48. package/src/index.js +16 -0
  49. package/src/lib/axis.js +75 -0
  50. package/src/lib/colors.js +32 -0
  51. package/src/lib/geom.js +4 -0
  52. package/src/lib/shapes.js +144 -0
  53. package/src/lib/timer.js +44 -0
  54. package/src/lib/utils.js +157 -0
  55. package/src/lookup.js +29 -0
  56. package/src/plots/BarPlot.svelte +55 -0
  57. package/src/plots/BoxPlot.svelte +0 -0
  58. package/src/plots/FunnelPlot.svelte +33 -0
  59. package/src/plots/HeatMap.svelte +5 -0
  60. package/src/plots/HeatMapCalendar.svelte +129 -0
  61. package/src/plots/LinePlot.svelte +55 -0
  62. package/src/plots/Plot.svelte +25 -0
  63. package/src/plots/RankBarPlot.svelte +38 -0
  64. package/src/plots/ScatterPlot.svelte +20 -0
  65. package/src/plots/ViolinPlot.svelte +11 -0
  66. package/src/plots/heatmap.js +70 -0
  67. package/src/plots/index.js +10 -0
  68. package/src/swatch.js +11 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Jerry Thomas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Charts for Svelte
2
+
3
+ The core idea behind the implementation is to use the respective strengths of both D3 and Svelte to build Themable, Composable, Animated, Responsive, Accessible, and Reactive Data Visualization components.
4
+
5
+ - [D3](https://d3js.org/) makes working with SVG a breeze. It provides a large set of utility functions for graph visualization that includes the computation of scales, interpolation, shapes, and more.
6
+ - [Svelte](https://svelte.dev/) makes UI development fun again. It provides modularization, interactivity, reactivity, and responsiveness.
7
+
8
+ This component library borrows concepts from the following articles, products, and repositories.
9
+
10
+ - [Introduction to Accessible Contrast and Color for Data Visualization](https://observablehq.com/@frankelavsky/chartability-contrast-series) by [Frank Elavsky](https://observablehq.com/@frankelavsky)
11
+ - [Animated, Responsive, and Reactive Data Visualization with Svelte](https://www.infoq.com/news/2020/10/svelte-d3-animation-data-vis/)
12
+ - [Barchart Race using Svelte & D3](https://t.co/iIoJw4f7Jc?amp=1) by [Amelia Wattenberger](https://mobile.twitter.com/Wattenberger) & [Russell Goldenberg](https://mobile.twitter.com/codenberg)
13
+ - [The D3.js Graph Gallery](https://www.d3-graph-gallery.com/index.html)
14
+ - [DC.js](https://dc-js.github.io/dc.js/) is an awesome implementation of interactive animated charts using D3.
15
+
16
+ ## Getting Started
17
+
18
+ Get started quickly using [degit](https://github.com/Rich-Harris/degit).
19
+
20
+ ```bash
21
+ degit jerrythomas/sparsh-ui/sites/playground my-app
22
+ ```
23
+
24
+ ## Features
25
+
26
+ - [x] Fill patterns
27
+ - [x] Symbols
28
+ - [x] Colors
29
+ - [ ] Themes
30
+
31
+ ### Plots
32
+
33
+ - [x] Box
34
+ - [ ] Violin
35
+ - [x] Scatter
36
+ - [ ] Line
37
+ - [ ] Histogram
38
+ - [ ] StackedBar
39
+ - [ ] Funnel
40
+
41
+ ### Chart
42
+
43
+ - [x] Axis
44
+ - [x] Labels
45
+ - [x] Grid
46
+ - [x] Ticks
47
+ - [ ] Margins
48
+ - [ ] Legend
49
+ - [ ] Composable
50
+ - [ ] Facet Grid
51
+ - [ ] Combine multiple plots
52
+ - [ ] Animation
53
+ - [ ] Time lapse
54
+ - [ ] Sliding window
55
+ - [ ] Rolling window
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@rokkit/chart",
3
+ "version": "1.0.0-next.11",
4
+ "description": "Components for making interactive charts.",
5
+ "author": "Jerry Thomas <me@jerrythomas.name>",
6
+ "license": "MIT",
7
+ "main": "index.js",
8
+ "svelte": "src/index.js",
9
+ "module": "src/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "type": "module",
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "devDependencies": {
16
+ "@sveltejs/vite-plugin-svelte": "^2.0.2",
17
+ "@testing-library/svelte": "^3.2.2",
18
+ "@vitest/ui": "~0.12.10",
19
+ "eslint": "^8.33.0",
20
+ "js-yaml": "^4.1.0",
21
+ "jsdom": "^19.0.0",
22
+ "svelte": "^3.55.1",
23
+ "typescript": "^4.9.5",
24
+ "vite": "^4.1.1",
25
+ "vitest": "~0.19.1",
26
+ "shared-config": "1.0.0",
27
+ "eslint-config-shared": "1.0.0"
28
+ },
29
+ "dependencies": {
30
+ "d3-array": "^3.2.2",
31
+ "d3-collection": "^1.0.7",
32
+ "d3-scale": "^4.0.2",
33
+ "d3-shape": "^3.2.0",
34
+ "date-fns": "^2.29.3",
35
+ "ramda": "^0.28.0",
36
+ "yootils": "^0.3.1",
37
+ "@rokkit/core": "1.0.0-next.11"
38
+ },
39
+ "files": [
40
+ "src/**/*.js",
41
+ "src/**/*.svelte",
42
+ "!src/fixtures",
43
+ "!src/mocks",
44
+ "!src/**/*.spec.js"
45
+ ],
46
+ "exports": {
47
+ "./src": "./src",
48
+ "./package.json": "./package.json",
49
+ ".": {
50
+ "types": "./dist/index.d.ts",
51
+ "import": "./src/index.js"
52
+ }
53
+ },
54
+ "scripts": {
55
+ "lint": "prettier --check --plugin-search-dir=. . && eslint .",
56
+ "format": "prettier --write --plugin-search-dir=. .",
57
+ "test:ci": "vitest run",
58
+ "test:ui": "vitest --ui",
59
+ "test": "vitest",
60
+ "coverage": "vitest run --coverage",
61
+ "upgrade": "pnpm upgrade"
62
+ }
63
+ }
@@ -0,0 +1,51 @@
1
+ <script>
2
+ import Chart from './Chart.svelte'
3
+ import AxisGrid from './AxisGrid.svelte'
4
+ import Axis from './Axis.svelte'
5
+ import AxisTicks from './AxisTicks.svelte'
6
+ import AxisLabels from './AxisLabels.svelte'
7
+
8
+ export let data
9
+ export let row
10
+ export let col
11
+ export let plot
12
+ export let x
13
+ export let y
14
+ export let labels = { x: true, y: true }
15
+
16
+ $: rowValues = [...new Set(data.map((d) => d[row]))]
17
+ $: colValues = [...new Set(data.map((d) => d[col]))]
18
+ </script>
19
+
20
+ <div class="flex flex-col">
21
+ {#each rowValues as rowItem}
22
+ {@const dataFilteredByRow = data.filter((d) => d[row] === rowItem)}
23
+
24
+ <div class="flex flex-row">
25
+ {#each colValues as colItem}
26
+ {@const dataFilteredByCol = dataFilteredByRow.filter(
27
+ (d) => d[col] === colItem
28
+ )}
29
+
30
+ <Chart data={dataFilteredByCol} {x} {y}>
31
+ <Axis name="x" count={7} gap={10}>
32
+ <AxisTicks side="bottom">
33
+ {#if labels.x}
34
+ <AxisLabels angle={-60} />
35
+ {/if}
36
+ </AxisTicks>
37
+ </Axis>
38
+ <Axis name="y" gap={10}>
39
+ <AxisTicks side="left">
40
+ {#if labels.y}
41
+ <AxisLabels />
42
+ {/if}
43
+ </AxisTicks>
44
+ <AxisGrid />
45
+ </Axis>
46
+ <svelte:component this={plot} />
47
+ </Chart>
48
+ {/each}
49
+ </div>
50
+ {/each}
51
+ </div>
@@ -0,0 +1,34 @@
1
+ <script>
2
+ import { getContext } from 'svelte'
3
+
4
+ export let opacity = 1
5
+ export let hideVertical = false
6
+ export let hideHorizontal = false
7
+ let chart = getContext('chart')
8
+
9
+ $: opacityV = hideVertical ? 0 : opacity
10
+ $: opacityH = hideHorizontal ? 0 : opacity
11
+ $: xRange = $chart.axis.x.scale.range()
12
+ $: yRange = $chart.axis.y.scale.range()
13
+ </script>
14
+
15
+ <g class="grid">
16
+ {#each $chart.axis.x.ticks as tick}
17
+ <line
18
+ x1={tick.position}
19
+ x2={tick.position}
20
+ y1={yRange[0]}
21
+ y2={yRange[1]}
22
+ opacity={opacityV}
23
+ />
24
+ {/each}
25
+ {#each $chart.axis.y.ticks as tick}
26
+ <line
27
+ y1={tick.position}
28
+ y2={tick.position}
29
+ x1={xRange[0]}
30
+ x2={xRange[1]}
31
+ opacity={opacityH}
32
+ />
33
+ {/each}
34
+ </g>
@@ -0,0 +1,16 @@
1
+ <script>
2
+ export let title
3
+ export let items = []
4
+ </script>
5
+
6
+ <ul class="flex flex-col">
7
+ <p>{title}</p>
8
+ {#each items as item}
9
+ <li class="flex flex-row gap-5">
10
+ <svg width="42" height="42" viewBox="0 0 42 42">
11
+ <rect width="42" height="42" fill={item.fillUrl || item.fill} />
12
+ </svg>
13
+ <p class="flex flex-grow">{item.label}</p>
14
+ </li>
15
+ {/each}
16
+ </ul>
@@ -0,0 +1,13 @@
1
+ <script>
2
+ import Texture from './Texture.svelte'
3
+ const size = 10
4
+
5
+ export let thickness = 0.5
6
+ export let patterns
7
+ </script>
8
+
9
+ <defs>
10
+ {#each patterns as pattern}
11
+ <Texture {...pattern} {thickness} {size} />
12
+ {/each}
13
+ </defs>
@@ -0,0 +1,93 @@
1
+ <script>
2
+ import { createEventDispatcher } from 'svelte'
3
+
4
+ import { swatch } from '../lib/utils'
5
+ import { clamp } from 'yootils'
6
+ import Symbol from './Symbol.svelte'
7
+ import PatternDefs from './PatternDefs.svelte'
8
+
9
+ const dispatch = createEventDispatcher()
10
+
11
+ export let label
12
+ export let size = 30
13
+ export let items = []
14
+ export let type = 'square'
15
+ export let pad = 10
16
+ export let columns
17
+ export let rows
18
+ export let limit
19
+ export let start = 0
20
+ export let autoscale = false
21
+ export let interactive = false
22
+ export let activeIndex = -1
23
+
24
+ function fill(item) {
25
+ return item.fillUrl || item.fill || item
26
+ }
27
+
28
+ function stroke(item) {
29
+ return item.stroke || item
30
+ }
31
+
32
+ function swapType(inputType) {
33
+ return inputType === 'square'
34
+ ? 'circle'
35
+ : inputType === 'circle'
36
+ ? 'square'
37
+ : type
38
+ }
39
+
40
+ function click(index) {
41
+ if (interactive) {
42
+ activeIndex = start + index
43
+ dispatch('click', { index: activeIndex, item: items[activeIndex] })
44
+ }
45
+ }
46
+
47
+ function forwardEvent(event, index) {
48
+ if (interactive)
49
+ dispatch(event, {
50
+ index: start + index,
51
+ item: items[start + index]
52
+ })
53
+ }
54
+
55
+ $: grid = swatch(limit || items.length, size, pad, columns, rows)
56
+ $: data = grid.data.map((item, i) => ({
57
+ ...item,
58
+ type: i == activeIndex ? swapType(type) : type
59
+ }))
60
+ $: start = clamp(start, 0, items.length - (limit || 0))
61
+ </script>
62
+
63
+ <div class="flex flex-col leading-loose">
64
+ {#if label}
65
+ <span class="py-2">{label}</span>
66
+ {/if}
67
+ <svg
68
+ viewBox="0 0 {grid.width} {grid.height}"
69
+ width="100%"
70
+ class="cursor-pointer"
71
+ >
72
+ {#if label}
73
+ <title>A swatch with label {label}</title>
74
+ {/if}
75
+
76
+ {#each data as { cx, cy, r, type }, i}
77
+ <Symbol
78
+ x={cx}
79
+ y={cy}
80
+ {size}
81
+ fill={fill(items[i + start])}
82
+ stroke={stroke(items[i + start])}
83
+ shape={items[i + start].shape || type}
84
+ thickness={i + start == activeIndex ? 2 : 0.5}
85
+ on:click={click(i + start)}
86
+ on:mouseover={forwardEvent('mouseover', i + start)}
87
+ on:mouseleave={forwardEvent('mouseleave', i + start)}
88
+ on:focus={forwardEvent('focus', i + start)}
89
+ />
90
+ {/each}
91
+ <PatternDefs patterns={items} />
92
+ </svg>
93
+ </div>
@@ -0,0 +1,29 @@
1
+ <script>
2
+ import TexturedShape from './TexturedShape.svelte'
3
+
4
+ export let pattern
5
+ export let shape = 'circle'
6
+ // export let type
7
+ export let fill
8
+ export let stroke
9
+ export let isCurrent = false
10
+
11
+ const size = 40
12
+ </script>
13
+
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"
16
+ class:isCurrent
17
+ on:click
18
+ on:mouseover
19
+ on:mouseleave
20
+ on:focus
21
+ >
22
+ <TexturedShape {pattern} {fill} {stroke} {shape} {size} />
23
+ </button>
24
+
25
+ <style>
26
+ .isCurrent {
27
+ @apply bg-primary-200;
28
+ }
29
+ </style>
@@ -0,0 +1,55 @@
1
+ <script>
2
+ import SwatchButton from './SwatchButton.svelte'
3
+
4
+ export let columns
5
+ export let rows
6
+ export let items
7
+ let grid
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)
40
+ </script>
41
+
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}
55
+ </row>
@@ -0,0 +1,37 @@
1
+ <script>
2
+ import { namedShapes } from '../components/lib/shape'
3
+
4
+ export let x = 0
5
+ export let y = 0
6
+ export let size = 10
7
+ export let fill = 'none'
8
+ export let stroke = 'currentColor'
9
+ export let thickness = 0.5
10
+
11
+ export let name = null
12
+ export let shape = null
13
+
14
+ $: x = x - size / 2
15
+ $: y = y - size / 2
16
+
17
+ $: d =
18
+ typeof shape === 'function'
19
+ ? shape(size)
20
+ : (shape || name) in namedShapes
21
+ ? namedShapes[shape || name](size)
22
+ : namedShapes.circle(size)
23
+ </script>
24
+
25
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
26
+ <path
27
+ {d}
28
+ {fill}
29
+ {stroke}
30
+ transform="translate({x},{y})"
31
+ stroke-width={thickness}
32
+ fill-rule="evenodd"
33
+ on:click
34
+ on:mouseover
35
+ on:mouseleave
36
+ on:focus
37
+ />
@@ -0,0 +1,16 @@
1
+ <script>
2
+ export let id
3
+ export let fill
4
+ export let path
5
+ export let contrast
6
+ export let thickness = 0.5
7
+ export let patternUnits = 'userSpaceOnUse'
8
+ export let size = 10
9
+ </script>
10
+
11
+ <pattern {id} {patternUnits} width={size} height={size}>
12
+ <rect width={size} height={size} {fill} />
13
+ {#if path}
14
+ <path d={path} fill="none" stroke={contrast} stroke-width={thickness} />
15
+ {/if}
16
+ </pattern>
@@ -0,0 +1,27 @@
1
+ <script>
2
+ import Symbol from './Symbol.svelte'
3
+ import Texture from './Texture.svelte'
4
+
5
+ export let pattern
6
+ export let shape = 'circle'
7
+ export let fill
8
+ export let stroke
9
+
10
+ const size = 40
11
+ </script>
12
+
13
+ <svg viewBox="0 0 {size} {size}">
14
+ <Symbol
15
+ x={size / 2}
16
+ y={size / 2}
17
+ {size}
18
+ fill={pattern.fillUrl || fill}
19
+ {stroke}
20
+ {shape}
21
+ />
22
+ {#if pattern}
23
+ <defs>
24
+ <Texture {...pattern} />
25
+ </defs>
26
+ {/if}
27
+ </svg>
@@ -0,0 +1,97 @@
1
+ <script>
2
+ import { setContext } from 'svelte'
3
+ import { writable } from 'svelte/store'
4
+ import { slidingWindow, uniques, brewer } from '../lib'
5
+
6
+ import Grid from './Grid.svelte'
7
+ import Axis from './Axis.svelte'
8
+ import BoxPlot from '../plots/BoxPlot.svelte'
9
+ import ViolinPlot from '../plots/ViolinPlot.svelte'
10
+ import ScatterPlot from '../plots/ScatterPlot.svelte'
11
+
12
+ let chart = writable({})
13
+ let axis
14
+ setContext('chart', chart)
15
+
16
+ export let data
17
+ export let x
18
+ export let y
19
+ export let time
20
+ export let theme
21
+
22
+ export let current
23
+ export let stages
24
+
25
+ function base(data, x, y) {
26
+ return {
27
+ data,
28
+ x,
29
+ y,
30
+ width: 800,
31
+ height: 350,
32
+ values: {
33
+ x: uniques(data, x),
34
+ y: uniques(data, y),
35
+ },
36
+ }
37
+ }
38
+
39
+ function sliceBy(data, attr, size, step, offset) {
40
+ const values = uniques(data, attr)
41
+ const groups = slidingWindow(values, size, step, offset).map((x) => ({
42
+ ...x,
43
+ data: data.filter(
44
+ (y) => y.Petal_Length >= x.lowerBound && y.Petal_Length < x.upperBound
45
+ ),
46
+ }))
47
+
48
+ return groups
49
+ }
50
+
51
+ function timed(data, x, y, time) {
52
+ let chart = base(data, x, y)
53
+ let temp = brewer().chart(data, x, y).use(theme).computeAxis()
54
+ axis = temp.axis
55
+ console.log(temp)
56
+ chart.data = sliceBy(chart.data, time, 3, 1)
57
+ stages = chart.data.length - 1
58
+ return chart
59
+ }
60
+
61
+ function switchChart(index) {
62
+ let chart = {}
63
+ if (index != null) {
64
+ chart = brewer()
65
+ .chart(phased.data[index].data, x, y)
66
+ .use(theme)
67
+ .computeAxis()
68
+ chart.axis = axis
69
+ // chart.margin = { left: 40, right: 10, top: 10, bottom: 30 }
70
+ }
71
+ return chart
72
+ }
73
+ let phased
74
+
75
+ $: phased = timed(data, x, y, time)
76
+ $: $chart = switchChart(current)
77
+ // $: console.log(current, phased, chart)
78
+
79
+ // setup chart attributes that do not change over time
80
+ // get scales for x & y
81
+ // set margins
82
+
83
+ // nest data by time attribute
84
+ // set up sequence based on ascending values of time
85
+ // set up the timer to switch between data values
86
+ // On change set the context with new data set
87
+ // Old data set needs exit animation, new data set needs entry animation
88
+ </script>
89
+
90
+ <svg viewBox="0 0 {phased.width} {phased.height}" class="flex chart">
91
+ <Grid />
92
+ <Axis orient="bottom" />
93
+ <Axis orient="left" />
94
+ <BoxPlot />
95
+ <ViolinPlot />
96
+ <ScatterPlot jitterWidth={50} offset={50} />
97
+ </svg>
@@ -0,0 +1,27 @@
1
+ <script>
2
+ import { createEventDispatcher } from 'svelte'
3
+ import { elapsed, timer } from '../lib/timer.js'
4
+
5
+ const dispatch = createEventDispatcher()
6
+
7
+ export let isEnabled = false
8
+ export let currentKeyframe = 0
9
+ export let keyframeCount = 0
10
+ export let duration = 1000
11
+
12
+ $: if (isEnabled) currentKeyframe = Math.floor($elapsed / duration)
13
+ $: if (currentKeyframe === keyframeCount) dispatch('end')
14
+ $: isEnabled && currentKeyframe < keyframeCount ? timer.start() : timer.stop()
15
+
16
+ function onReset() {
17
+ timer.reset()
18
+ isEnabled = false
19
+ currentKeyframe = 0
20
+ }
21
+ </script>
22
+
23
+ <div class="flex flex-row gap-2 timer">
24
+ <button on:click|preventDefault={() => (isEnabled = true)}>play</button>
25
+ <button on:click|preventDefault={() => (isEnabled = false)}>pause</button>
26
+ <button on:click|preventDefault={onReset}>reset</button>
27
+ </div>
package/src/chart.js ADDED
@@ -0,0 +1,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
+ }