@rokkit/chart 1.0.0-next.16 → 1.0.0-next.160

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 (173) hide show
  1. package/README.md +150 -46
  2. package/package.json +42 -45
  3. package/src/AnimatedPlot.svelte +383 -0
  4. package/src/Chart.svelte +95 -0
  5. package/src/ChartProvider.svelte +10 -0
  6. package/src/FacetPlot/Panel.svelte +37 -0
  7. package/src/FacetPlot.svelte +114 -0
  8. package/src/Plot/Arc.svelte +29 -0
  9. package/src/Plot/Area.svelte +32 -0
  10. package/src/Plot/Axis.svelte +95 -0
  11. package/src/Plot/Bar.svelte +54 -0
  12. package/src/Plot/Grid.svelte +34 -0
  13. package/src/Plot/Legend.svelte +233 -0
  14. package/src/Plot/Line.svelte +37 -0
  15. package/src/Plot/Point.svelte +40 -0
  16. package/src/Plot/Root.svelte +62 -0
  17. package/src/Plot/Timeline.svelte +95 -0
  18. package/src/Plot/Tooltip.svelte +87 -0
  19. package/src/Plot/index.js +9 -0
  20. package/src/Plot.svelte +297 -0
  21. package/src/PlotState.svelte.js +350 -0
  22. package/src/Sparkline.svelte +108 -0
  23. package/src/Symbol.svelte +21 -0
  24. package/src/Texture.svelte +18 -0
  25. package/src/charts/AreaChart.svelte +27 -0
  26. package/src/charts/BarChart.svelte +28 -0
  27. package/src/charts/BoxPlot.svelte +21 -0
  28. package/src/charts/BubbleChart.svelte +23 -0
  29. package/src/charts/LineChart.svelte +26 -0
  30. package/src/charts/PieChart.svelte +35 -0
  31. package/src/charts/ScatterPlot.svelte +26 -0
  32. package/src/charts/ViolinPlot.svelte +21 -0
  33. package/src/crossfilter/CrossFilter.svelte +42 -0
  34. package/src/crossfilter/FilterBar.svelte +24 -0
  35. package/src/crossfilter/FilterHistogram.svelte +290 -0
  36. package/src/crossfilter/FilterSlider.svelte +83 -0
  37. package/src/crossfilter/createCrossFilter.svelte.js +124 -0
  38. package/src/elements/Bar.svelte +22 -24
  39. package/src/elements/ColorRamp.svelte +20 -22
  40. package/src/elements/ContinuousLegend.svelte +20 -17
  41. package/src/elements/DefinePatterns.svelte +24 -0
  42. package/src/elements/DiscreteLegend.svelte +15 -15
  43. package/src/elements/Label.svelte +4 -8
  44. package/src/elements/SymbolGrid.svelte +22 -0
  45. package/src/elements/index.js +6 -0
  46. package/src/examples/BarChartExample.svelte +81 -0
  47. package/src/geoms/Arc.svelte +126 -0
  48. package/src/geoms/Area.svelte +78 -0
  49. package/src/geoms/Bar.svelte +200 -0
  50. package/src/geoms/Box.svelte +113 -0
  51. package/src/geoms/LabelPill.svelte +17 -0
  52. package/src/geoms/Line.svelte +123 -0
  53. package/src/geoms/Point.svelte +145 -0
  54. package/src/geoms/Violin.svelte +56 -0
  55. package/src/geoms/lib/areas.js +154 -0
  56. package/src/geoms/lib/bars.js +223 -0
  57. package/src/index.js +74 -16
  58. package/src/lib/brewer.js +25 -0
  59. package/src/lib/brewing/BoxBrewer.svelte.js +14 -0
  60. package/src/lib/brewing/CartesianBrewer.svelte.js +21 -0
  61. package/src/lib/brewing/PieBrewer.svelte.js +14 -0
  62. package/src/lib/brewing/QuartileBrewer.svelte.js +51 -0
  63. package/src/lib/brewing/ViolinBrewer.svelte.js +14 -0
  64. package/src/lib/brewing/axes.svelte.js +270 -0
  65. package/src/lib/brewing/bars.svelte.js +201 -0
  66. package/src/lib/brewing/brewer.svelte.js +277 -0
  67. package/src/lib/brewing/colors.js +51 -0
  68. package/src/lib/brewing/dimensions.svelte.js +56 -0
  69. package/src/lib/brewing/index.svelte.js +205 -0
  70. package/src/lib/brewing/legends.svelte.js +137 -0
  71. package/src/lib/brewing/marks/arcs.js +43 -0
  72. package/src/lib/brewing/marks/areas.js +72 -0
  73. package/src/lib/brewing/marks/bars.js +49 -0
  74. package/src/lib/brewing/marks/boxes.js +75 -0
  75. package/src/lib/brewing/marks/lines.js +55 -0
  76. package/src/lib/brewing/marks/points.js +105 -0
  77. package/src/lib/brewing/marks/violins.js +90 -0
  78. package/src/lib/brewing/patterns.js +45 -0
  79. package/src/lib/brewing/scales.js +51 -0
  80. package/src/lib/brewing/scales.svelte.js +82 -0
  81. package/src/lib/brewing/stats.js +74 -0
  82. package/src/lib/brewing/symbols.js +10 -0
  83. package/src/lib/brewing/types.js +73 -0
  84. package/src/lib/chart.js +221 -0
  85. package/src/lib/context.js +131 -0
  86. package/src/lib/grid.js +85 -0
  87. package/src/lib/keyboard-nav.js +37 -0
  88. package/src/lib/plot/chartProps.js +76 -0
  89. package/src/lib/plot/crossfilter.js +16 -0
  90. package/src/lib/plot/facet.js +58 -0
  91. package/src/lib/plot/frames.js +81 -0
  92. package/src/lib/plot/helpers.js +14 -0
  93. package/src/lib/plot/preset.js +67 -0
  94. package/src/lib/plot/scales.js +81 -0
  95. package/src/lib/plot/stat.js +92 -0
  96. package/src/lib/plot/types.js +65 -0
  97. package/src/lib/preset.js +41 -0
  98. package/src/lib/scales.svelte.js +151 -0
  99. package/src/lib/swatch.js +13 -0
  100. package/src/lib/ticks.js +46 -0
  101. package/src/lib/utils.js +111 -118
  102. package/src/lib/xscale.js +31 -0
  103. package/src/patterns/DefinePatterns.svelte +32 -0
  104. package/src/patterns/PatternDef.svelte +27 -0
  105. package/src/patterns/index.js +4 -0
  106. package/src/patterns/patterns.js +360 -0
  107. package/src/patterns/scale.js +116 -0
  108. package/src/spec/chart-spec.js +72 -0
  109. package/src/symbols/RoundedSquare.svelte +33 -0
  110. package/src/symbols/Shape.svelte +37 -0
  111. package/src/symbols/constants/index.js +4 -0
  112. package/src/symbols/index.js +9 -0
  113. package/src/symbols/outline.svelte +60 -0
  114. package/src/symbols/solid.svelte +60 -0
  115. package/LICENSE +0 -21
  116. package/src/chart/FacetGrid.svelte +0 -51
  117. package/src/chart/Grid.svelte +0 -34
  118. package/src/chart/Legend.svelte +0 -16
  119. package/src/chart/PatternDefs.svelte +0 -13
  120. package/src/chart/Swatch.svelte +0 -93
  121. package/src/chart/SwatchButton.svelte +0 -29
  122. package/src/chart/SwatchGrid.svelte +0 -55
  123. package/src/chart/Symbol.svelte +0 -37
  124. package/src/chart/Texture.svelte +0 -16
  125. package/src/chart/TexturedShape.svelte +0 -27
  126. package/src/chart/TimelapseChart.svelte +0 -97
  127. package/src/chart/Timer.svelte +0 -27
  128. package/src/chart.js +0 -9
  129. package/src/components/charts/Axis.svelte +0 -66
  130. package/src/components/charts/Chart.svelte +0 -35
  131. package/src/components/index.js +0 -23
  132. package/src/components/lib/axis.js +0 -0
  133. package/src/components/lib/chart.js +0 -187
  134. package/src/components/lib/color.js +0 -327
  135. package/src/components/lib/funnel.js +0 -204
  136. package/src/components/lib/index.js +0 -19
  137. package/src/components/lib/pattern.js +0 -190
  138. package/src/components/lib/rollup.js +0 -55
  139. package/src/components/lib/shape.js +0 -199
  140. package/src/components/lib/summary.js +0 -145
  141. package/src/components/lib/theme.js +0 -23
  142. package/src/components/lib/timer.js +0 -41
  143. package/src/components/lib/utils.js +0 -165
  144. package/src/components/plots/BarPlot.svelte +0 -36
  145. package/src/components/plots/BoxPlot.svelte +0 -54
  146. package/src/components/plots/ScatterPlot.svelte +0 -30
  147. package/src/components/store.js +0 -70
  148. package/src/constants.js +0 -66
  149. package/src/elements/PatternDefs.svelte +0 -13
  150. package/src/elements/PatternMask.svelte +0 -20
  151. package/src/elements/Symbol.svelte +0 -38
  152. package/src/elements/Tooltip.svelte +0 -23
  153. package/src/funnel.svelte +0 -35
  154. package/src/geom.js +0 -105
  155. package/src/lib/axis.js +0 -75
  156. package/src/lib/colors.js +0 -32
  157. package/src/lib/geom.js +0 -4
  158. package/src/lib/shapes.js +0 -144
  159. package/src/lib/timer.js +0 -44
  160. package/src/lookup.js +0 -29
  161. package/src/plots/BarPlot.svelte +0 -55
  162. package/src/plots/BoxPlot.svelte +0 -0
  163. package/src/plots/FunnelPlot.svelte +0 -33
  164. package/src/plots/HeatMap.svelte +0 -5
  165. package/src/plots/HeatMapCalendar.svelte +0 -129
  166. package/src/plots/LinePlot.svelte +0 -55
  167. package/src/plots/Plot.svelte +0 -25
  168. package/src/plots/RankBarPlot.svelte +0 -38
  169. package/src/plots/ScatterPlot.svelte +0 -20
  170. package/src/plots/ViolinPlot.svelte +0 -11
  171. package/src/plots/heatmap.js +0 -70
  172. package/src/plots/index.js +0 -10
  173. package/src/swatch.js +0 -11
@@ -0,0 +1,60 @@
1
+ <svg
2
+ class="plot"
3
+ fill="currentColor"
4
+ font-family="system-ui, sans-serif"
5
+ font-size="10"
6
+ text-anchor="middle"
7
+ width="688"
8
+ height="60"
9
+ viewBox="0 0 688 60"
10
+ ><style>
11
+ :where(.plot) {
12
+ --plot-background: white;
13
+ display: block;
14
+ height: auto;
15
+ height: intrinsic;
16
+ max-width: 100%;
17
+ }
18
+ :where(.plot text),
19
+ :where(.plot tspan) {
20
+ white-space: pre;
21
+ }
22
+ </style><g aria-label="x-axis tick" fill="none" stroke="currentColor"
23
+ ><path transform="translate(68,30)" d="M0,0L0,6"></path><path
24
+ transform="translate(160,30)"
25
+ d="M0,0L0,6"
26
+ ></path><path transform="translate(252,30)" d="M0,0L0,6"></path><path
27
+ transform="translate(344,30)"
28
+ d="M0,0L0,6"
29
+ ></path><path transform="translate(436,30)" d="M0,0L0,6"></path><path
30
+ transform="translate(528,30)"
31
+ d="M0,0L0,6"
32
+ ></path><path transform="translate(620,30)" d="M0,0L0,6"></path></g
33
+ ><g aria-label="x-axis tick label" transform="translate(0,9)"
34
+ ><text y="0.71em" transform="translate(68,30)">circle</text><text
35
+ y="0.71em"
36
+ transform="translate(160,30)">cross</text
37
+ ><text y="0.71em" transform="translate(252,30)">diamond</text><text
38
+ y="0.71em"
39
+ transform="translate(344,30)">square</text
40
+ ><text y="0.71em" transform="translate(436,30)">star</text><text
41
+ y="0.71em"
42
+ transform="translate(528,30)">triangle</text
43
+ ><text y="0.71em" transform="translate(620,30)">wye</text></g
44
+ ><g aria-label="dot"
45
+ ><path transform="translate(68,15.25)" d="M4.5,0A4.5,4.5,0,1,1,-4.5,0A4.5,4.5,0,1,1,4.5,0"
46
+ ></path><path
47
+ transform="translate(160,15.25)"
48
+ d="M-5.35,-1.783L-1.783,-1.783L-1.783,-5.35L1.783,-5.35L1.783,-1.783L5.35,-1.783L5.35,1.783L1.783,1.783L1.783,5.35L-1.783,5.35L-1.783,1.783L-5.35,1.783Z"
49
+ ></path><path transform="translate(252,15.25)" d="M0,-7.423L4.285,0L0,7.423L-4.285,0Z"
50
+ ></path><path transform="translate(344,15.25)" d="M-3.988,-3.988h7.976v7.976h-7.976Z"
51
+ ></path><path
52
+ transform="translate(436,15.25)"
53
+ d="M0,-7.528L1.69,-2.326L7.16,-2.326L2.735,0.889L4.425,6.09L0,2.875L-4.425,6.09L-2.735,0.889L-7.16,-2.326L-1.69,-2.326Z"
54
+ ></path><path transform="translate(528,15.25)" d="M0,-6.998L6.06,3.499L-6.06,3.499Z"
55
+ ></path><path
56
+ transform="translate(620,15.25)"
57
+ d="M2.152,1.243L2.152,5.547L-2.152,5.547L-2.152,1.243L-5.88,-0.91L-3.728,-4.638L0,-2.485L3.728,-4.638L5.88,-0.91Z"
58
+ ></path></g
59
+ ></svg
60
+ >
package/LICENSE DELETED
@@ -1,21 +0,0 @@
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.
@@ -1,51 +0,0 @@
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>
@@ -1,34 +0,0 @@
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>
@@ -1,16 +0,0 @@
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>
@@ -1,13 +0,0 @@
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>
@@ -1,93 +0,0 @@
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>
@@ -1,29 +0,0 @@
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>
@@ -1,55 +0,0 @@
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>
@@ -1,37 +0,0 @@
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
- />
@@ -1,16 +0,0 @@
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>
@@ -1,27 +0,0 @@
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>
@@ -1,97 +0,0 @@
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>
@@ -1,27 +0,0 @@
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 DELETED
@@ -1,9 +0,0 @@
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,66 +0,0 @@
1
- <script>
2
- import { getContext } from 'svelte'
3
- export let orient = 'bottom'
4
-
5
- let chart = getContext('chart')
6
-
7
- let top =
8
- orient === 'bottom'
9
- ? $chart.height - $chart.margin.bottom
10
- : $chart.margin.top
11
- let left =
12
- orient === 'right' ? $chart.width - $chart.margin.right : $chart.margin.left
13
- let tickSizeInner = $chart.theme.tick.size.inner || 6
14
- let tickSizeOuter = $chart.theme.tick.size.outer || 6
15
- let tickPadding = $chart.theme.tick.size.padding || 3
16
-
17
- function axisPath(vertical, scale) {
18
- const range = scale.range()
19
- return vertical
20
- ? `M${k * tickSizeOuter},${range[0]}H0V${range[1]}H${k * tickSizeOuter}`
21
- : `M${range[0]},${k * tickSizeOuter}V0H${range[1]}V${k * tickSizeOuter}`
22
- }
23
-
24
- $: anchor =
25
- orient === 'right' ? 'start' : orient === 'left' ? 'end' : 'middle'
26
- $: k = orient === 'top' || orient === 'left' ? -1 : 1
27
- $: dy = orient === 'top' ? '0em' : orient === 'bottom' ? '0.71em' : '0.32em'
28
- $: vertical = orient === 'left' || orient === 'right'
29
- // $: range = axis.scale.range()
30
- $: axis = vertical ? $chart.axis.y : $chart.axis.x
31
- </script>
32
-
33
- <g
34
- transform="translate({vertical ? left : 0},{vertical ? 0 : top})"
35
- fill="none"
36
- font-size="10"
37
- font-family="sans-serif"
38
- text-anchor={anchor}
39
- class="axis"
40
- >
41
- <path
42
- class="domain"
43
- stroke="currentColor"
44
- d="{axisPath(vertical, axis.scale)}}"
45
- />
46
- {#each axis.ticks as tick}
47
- <g
48
- class="tick"
49
- transform="translate({vertical ? 0 : tick.position},{vertical
50
- ? tick.position
51
- : 0})"
52
- >
53
- <line
54
- stroke="currentColor"
55
- y2={vertical ? 0 : k * tickSizeInner}
56
- x2={vertical ? k * tickSizeInner : 0}
57
- />
58
- <text
59
- fill="currentColor"
60
- y={vertical ? 0 : k * (tickSizeInner + tickPadding)}
61
- x={vertical ? k * (tickSizeInner + tickPadding) : 0}
62
- {dy}>{tick.label}</text
63
- >
64
- </g>
65
- {/each}
66
- </g>