@rokkit/chart 1.0.0-next.35 → 1.0.0-next.37

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 (51) hide show
  1. package/package.json +14 -12
  2. package/src/chart/FacetGrid.svelte +6 -6
  3. package/src/chart/Swatch.svelte +2 -3
  4. package/src/chart/SwatchGrid.svelte +1 -2
  5. package/src/chart/TexturedShape.svelte +1 -1
  6. package/src/chart/TimelapseChart.svelte +3 -4
  7. package/src/elements/ColorRamp.svelte +1 -1
  8. package/src/elements/ContinuousLegend.svelte +1 -1
  9. package/src/index.js +1 -2
  10. package/src/{components/lib → lib}/chart.js +12 -6
  11. package/src/lib/color.js +59 -0
  12. package/src/{components/lib/color.js → lib/constants.js} +111 -56
  13. package/src/{components/lib → lib}/funnel.js +0 -2
  14. package/src/lib/geom.js +106 -0
  15. package/src/{plots → lib}/heatmap.js +2 -2
  16. package/src/lib/index.js +0 -0
  17. package/src/lib/{colors.js → palette.js} +3 -3
  18. package/src/{components/lib → lib}/rollup.js +1 -1
  19. package/src/lib/shape.js +52 -0
  20. package/src/{components → lib}/store.js +2 -2
  21. package/src/{components/lib → lib}/summary.js +0 -2
  22. package/src/{swatch.js → lib/swatch.js} +4 -4
  23. package/src/{components/lib/utils.js → lib/utils-2.js} +1 -41
  24. package/src/lib/utils.js +4 -0
  25. package/src/plots/BarPlot.svelte +2 -2
  26. package/src/{components/plots/BarPlot.svelte → plots/BarPlot2.svelte} +0 -2
  27. package/src/plots/FunnelPlot.svelte +2 -3
  28. package/src/plots/HeatMapCalendar.svelte +1 -1
  29. package/src/plots/LinePlot.svelte +1 -2
  30. package/src/plots/Plot.svelte +1 -1
  31. package/src/plots/ScatterPlot.svelte +1 -1
  32. package/src/plots/ViolinPlot.svelte +0 -1
  33. package/src/chart/PatternDefs.svelte +0 -13
  34. package/src/chart/Symbol.svelte +0 -40
  35. package/src/chart.js +0 -11
  36. package/src/components/index.js +0 -23
  37. package/src/components/lib/index.js +0 -19
  38. package/src/components/lib/shape.js +0 -199
  39. package/src/components/lib/timer.js +0 -41
  40. package/src/constants.js +0 -66
  41. package/src/elements/PatternDefs.svelte +0 -13
  42. package/src/elements/PatternMask.svelte +0 -20
  43. package/src/elements/Symbol.svelte +0 -38
  44. package/src/funnel.svelte +0 -35
  45. package/src/geom.js +0 -105
  46. package/src/lib/shapes.js +0 -144
  47. package/src/plots/old_ScatterPlot.svelte +0 -20
  48. /package/src/chart/{Grid.svelte → AxisGrid.svelte} +0 -0
  49. /package/src/{lookup.js → lib/lookup.js} +0 -0
  50. /package/src/{components/lib → lib}/pattern.js +0 -0
  51. /package/src/{components/lib → lib}/theme.js +0 -0
@@ -0,0 +1,52 @@
1
+ import { ColorBrewer } from './color'
2
+ import { scaledPath } from './utils'
3
+ import { shapePaths } from './constants'
4
+
5
+ export class ShapeBrewer {
6
+ constructor() {
7
+ this.shapes = Object.entries(shapePaths).reduce(
8
+ (acc, [name, path]) => ({ ...acc, [name]: (s) => scaledPath(s, path) }),
9
+ {}
10
+ )
11
+ this.repeat = false
12
+ this.keys = Object.keys(this.shapes)
13
+ this.gray = new ColorBrewer().gray()
14
+ this.shades = []
15
+ this.repeat = false
16
+ }
17
+
18
+ clear() {
19
+ this.shapes = {}
20
+ return this
21
+ }
22
+
23
+ add(shape) {
24
+ const shapes = typeof shape === 'object' ? shape : { shape }
25
+ this.shapes = { ...this.shapes, ...shapes }
26
+
27
+ return this
28
+ }
29
+
30
+ filter(keys) {
31
+ keys = Array.isArray(keys) ? keys : [keys]
32
+ this.keys = keys.filter((key) => key in this.shapes)
33
+
34
+ return this
35
+ }
36
+
37
+ colors(shades, repeat = false) {
38
+ this.shades = Array.isArray(shades) ? shades : [shades]
39
+ this.repeat = repeat
40
+ return this
41
+ }
42
+
43
+ brew() {
44
+ return this.keys
45
+ .map((i) => this.shapes[i])
46
+ .map((shape, i) => {
47
+ return i < this.shades.length || this.repeat
48
+ ? { shape, ...this.shades[i % this.shades.length] }
49
+ : { shape, ...this.gray }
50
+ })
51
+ }
52
+ }
@@ -18,7 +18,7 @@ export function animatedChart(input, key, valueFields = [], previous = []) {
18
18
  const toRemove = new Set(
19
19
  [...previousKeys].filter((key) => !currentKeys.has(key))
20
20
  )
21
- console.log(toAdd, toRemove)
21
+
22
22
  let data = input
23
23
  .filter((item) => toAdd.has(item[key]))
24
24
  .map((item) => {
@@ -46,7 +46,7 @@ export function animatedChart(input, key, valueFields = [], previous = []) {
46
46
  return el
47
47
  })
48
48
  data = [...prev, ...data]
49
- console.log(data)
49
+
50
50
  return tweened(data, { duration: 500, easing: cubicOut })
51
51
  }
52
52
  // function createAxis() {
@@ -131,11 +131,9 @@
131
131
  // export function funnel(input, aes) {
132
132
  // let data = convertToPhases(input, aes)
133
133
  // data = mirror(data, aes)
134
- // // console.log(data)
135
134
 
136
135
  // if ('fill' in aes) {
137
136
  // let stats = flatten(data.stats.map((phase) => phase.value))
138
- // // console.log(stats)
139
137
  // data.stats = nest()
140
138
  // .key((d) => d[aes.fill])
141
139
  // .rollup((rows) => [...rows, { ...rows[rows.length - 1], x: rows.length }])
@@ -5,7 +5,7 @@ import { writable } from 'svelte/store'
5
5
  export const swatchStore = writable({})
6
6
 
7
7
  // A set of 7 should be sufficient
8
- // array of names and patterns
9
- // array of names and shapes
10
- // array of colors
11
- // array of shades of one color.
8
+ // set of patterns
9
+ // set of shapes
10
+ // set of colors
11
+ // fill, stroke, text
@@ -2,47 +2,7 @@ import { scaleBand, scaleLinear } from 'd3-scale'
2
2
  import { min, max } from 'd3-array'
3
3
  import { ascending, quantile } from 'd3-array'
4
4
  import { nest } from 'd3-collection'
5
- import { omit, filter } from 'ramda'
6
-
7
- /**
8
- * Generates a unique id from current timestamp
9
- *
10
- * @returns {String} timestamp based unique id
11
- */
12
- export function uniqueId(prefix = '') {
13
- return prefix + Date.now().toString(36)
14
- }
15
-
16
- /**
17
- * Capitalizes the first letter of input string
18
- *
19
- * @param {String} str
20
- * @returns {String}
21
- */
22
- export function initCap(str) {
23
- return str.charAt(0).toUpperCase() + str.slice(1)
24
- }
25
-
26
- /**
27
- * Removes undefined and null values from the input object.
28
- *
29
- * @param {Object} obj
30
- * @returns {Object}
31
- */
32
- export function compact(obj) {
33
- return filter((x) => x !== undefined && x !== null, obj)
34
- }
35
-
36
- /**
37
- * Converts an input number into it's hexadecimal representation, with optional left padded zeroes based on the `size`
38
- *
39
- * @param {number} value
40
- * @param {number} size
41
- * @returns
42
- */
43
- export function toHexString(value, size = 2) {
44
- return value.toString(16).padStart(size, '0')
45
- }
5
+ import { omit } from 'ramda'
46
6
 
47
7
  /**
48
8
  * Calculates a grid of centres to fit a list of items of `size` within the number of `columns` and `rows`.
package/src/lib/utils.js CHANGED
@@ -4,6 +4,10 @@ import { ascending, quantile } from 'd3-array'
4
4
  import { nest } from 'd3-collection'
5
5
  import { omit } from 'ramda'
6
6
 
7
+ export function scaledPath(size, x) {
8
+ if (Array.isArray(x)) return x.map((x) => scaledPath(size, x)).join(' ')
9
+ return typeof size === 'number' ? x * size : x
10
+ }
7
11
  /**
8
12
  * Calculates a grid of centres to fit a list of items of `size` within the number of `columns` and `rows`.
9
13
  *
@@ -1,6 +1,6 @@
1
1
  <script>
2
2
  import { getContext } from 'svelte'
3
- import { colorBrewer } from '../lib/colors'
3
+ import { colorBrewer } from '../lib/palette'
4
4
 
5
5
  let chart = getContext('chart')
6
6
 
@@ -32,7 +32,7 @@
32
32
  }
33
33
  }))
34
34
 
35
- // $: console.log(data)
35
+
36
36
  </script>
37
37
 
38
38
  {#each data as { x, y, width, height, fill, label }}
@@ -12,11 +12,9 @@
12
12
  export let h = 10
13
13
 
14
14
  function size(value) {
15
- // console.log($chart.axis.x.scale, value)
16
15
  return $chart.axis.x.scale(value)
17
16
  }
18
17
  function top(value) {
19
- // console.log('Y', value)
20
18
  return $chart.axis.y.scale(value)
21
19
  }
22
20
 
@@ -1,7 +1,7 @@
1
1
  <script>
2
2
  import { getContext } from 'svelte'
3
- import { compact } from '../components/lib/utils'
4
- import { funnel } from '../components/lib/funnel'
3
+ import { compact } from '../lib/utils-2'
4
+ import { funnel } from '../lib/funnel'
5
5
 
6
6
  const chart = getContext('chart')
7
7
 
@@ -13,7 +13,6 @@
13
13
 
14
14
  $: aes = { ...$chart.aes, ...compact({ x, y, fill, stat, curve }) }
15
15
  $: data = funnel($chart.data, aes, $chart.width, $chart.height)
16
- // $: console.log(data)
17
16
  </script>
18
17
 
19
18
  {#each data.stats as stat, i}
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { summarize, heatmap } from './heatmap'
2
+ import { summarize, heatmap } from '../lib/heatmap'
3
3
  import { interpolateHsl } from 'd3-interpolate'
4
4
  import { scaleLinear } from 'd3-scale'
5
5
  // import ContinuousLegend from '../elements/ContinuousLegend.svelte'
@@ -1,6 +1,6 @@
1
1
  <script>
2
2
  import { getContext } from 'svelte'
3
- import { colorBrewer } from '../lib/colors'
3
+ import { colorBrewer } from '../lib/palette'
4
4
 
5
5
  let chart = getContext('chart')
6
6
 
@@ -32,7 +32,6 @@
32
32
  }
33
33
  }))
34
34
 
35
- // $: console.log(data)
36
35
  </script>
37
36
 
38
37
  {#each data as { x1, y1, x2, y2, color, label }}
@@ -2,7 +2,7 @@
2
2
  import { aggregate, getScales } from '../lib/utils'
3
3
 
4
4
  import BoxPlot from './BoxPlot.svelte'
5
- import ScatterPlot from './old_ScatterPlot.svelte'
5
+ import ScatterPlot from './ScatterPlot.svelte'
6
6
 
7
7
  export let data
8
8
  export let width
@@ -1,6 +1,6 @@
1
1
  <script>
2
2
  import { clamp } from 'yootils'
3
- import Symbol from '../chart/Symbol.svelte'
3
+ import {Symbol} from '@rokkit/molecules'
4
4
  import { getContext } from 'svelte'
5
5
 
6
6
  const chart = getContext('chart')
@@ -3,7 +3,6 @@
3
3
 
4
4
  let chart = getContext('chart')
5
5
  $: data = $chart.violin()
6
- // $: console.log(data)
7
6
  </script>
8
7
 
9
8
  {#each data as { x, curve }}
@@ -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,40 +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
- role="option"
38
- aria-selected={false}
39
- tabindex="0"
40
- />
package/src/chart.js DELETED
@@ -1,11 +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
-
10
- // return { x, y, width, height, flipCoords }
11
- // }
@@ -1,23 +0,0 @@
1
- export { default as ColorRamp } from './elements/ColorRamp.svelte'
2
-
3
- export { default as Symbol } from './chart/Symbol.svelte'
4
- export { default as PatternDefs } from './chart/PatternDefs.svelte'
5
- export { default as Swatch } from './chart/Swatch.svelte'
6
- export { default as SwatchButton } from './chart/SwatchButton.svelte'
7
- export { default as SwatchGrid } from './chart/SwatchGrid.svelte'
8
-
9
- export { default as Axis } from './chart/Axis.svelte'
10
- export { default as Grid } from './chart/Grid.svelte'
11
-
12
- export { default as BoxPlot } from '../plots/BoxPlot.svelte'
13
- export { default as ViolinPlot } from '../plots/ViolinPlot.svelte'
14
- export { default as ScatterPlot } from '../plots/ScatterPlot.svelte'
15
- export { default as FunnelPlot } from '../plots/FunnelPlot.svelte'
16
-
17
- export { default as Chart } from './chart/Chart.svelte'
18
- export { default as TimelapseChart } from './chart/TimelapseChart.svelte'
19
- export { default as Timer } from './chart/Timer.svelte'
20
- export { default as BarPlot } from './plots/BarPlot.svelte'
21
- export { default as HeatMapCalendar } from '../plots/HeatMapCalendar.svelte'
22
- export { toHexString, initCap, uniqueId, toNested } from './lib/utils'
23
- export { brewer, uniques, slidingWindow, colors } from './lib/index'
@@ -1,19 +0,0 @@
1
- import { ChartBrewer } from './chart'
2
- import { ColorBrewer } from './color'
3
- import { ShapeBrewer } from './shape'
4
- import { ThemeBrewer } from './theme'
5
- import { PatternBrewer } from './pattern'
6
-
7
- export { toHexString, swatch } from './utils'
8
- export { uniques, slidingWindow } from './rollup'
9
- export { colors } from './color'
10
-
11
- export function brewer() {
12
- return {
13
- pattern: () => new PatternBrewer(),
14
- color: () => new ColorBrewer(),
15
- theme: () => new ThemeBrewer(),
16
- shape: () => new ShapeBrewer(),
17
- chart: (data, x, y) => new ChartBrewer(data, x, y)
18
- }
19
- }
@@ -1,199 +0,0 @@
1
- import { ColorBrewer } from './color'
2
-
3
- export const namedShapes = {
4
- square: (s) =>
5
- `M${0.1 * s} 0` +
6
- `A${0.1 * s} ${0.1 * s} 0 0 0 0 ${0.1 * s}V${0.9 * s}` +
7
- `A${0.1 * s} ${0.1 * s} 0 0 0 ${0.1 * s} ${s}H${0.9 * s}` +
8
- `A${0.1 * s} ${0.1 * s} 0 0 0 ${s} ${0.9 * s}V${0.1 * s}` +
9
- `A${0.1 * s} ${0.1 * s} 0 0 0 ${0.9 * s} 0Z`,
10
- circle: (s) =>
11
- `M0 ${0.5 * s}` +
12
- `A${0.5 * s} ${0.5 * s} 0 0 0 ${s} ${0.5 * s}` +
13
- `A${0.5 * s} ${0.5 * s} 0 0 0 0 ${0.5 * s}`,
14
- diamond: (s) =>
15
- `M${0.5 * s} 0` +
16
- `A${0.6 * s} ${0.6 * s} 0 0 0 ${s} ${0.5 * s}` +
17
- `A${0.6 * s} ${0.6 * s} 0 0 0 ${0.5 * s} ${s}` +
18
- `A${0.6 * s} ${0.6 * s} 0 0 0 0 ${0.5 * s}` +
19
- `A${0.6 * s} ${0.6 * s} 0 0 0 ${0.5 * s} 0`,
20
- triangle: (s) =>
21
- `M${0.5 * s} ${0.0866 * s}L0 ${0.9234 * s}L${s} ${0.9234 * s}Z`,
22
- rhombus: (s) =>
23
- `M${0.5 * s} 0` +
24
- `L${s} ${0.5 * s}` +
25
- `L${0.5 * s} ${s}` +
26
- `L0 ${0.5 * s}Z`,
27
- star: (s) =>
28
- `M${0.5 * s} ${0.05 * s}` +
29
- `L${0.606 * s} ${0.36 * s}` +
30
- `L${s} ${0.36 * s}` +
31
- `L${0.685 * s} ${0.59 * s}` +
32
- `L${0.81 * s} ${0.95 * s}` +
33
- `L${0.5 * s} ${0.725 * s}` +
34
- `L${0.19 * s} ${0.95 * s}` +
35
- `L${0.315 * s} ${0.59 * s}` +
36
- `L0 ${0.36 * s}` +
37
- `L${0.394 * s} ${0.36 * s}Z`,
38
- heart: (s) =>
39
- `M${0.9 * s} ${0.5 * s}` +
40
- `A${0.08 * s} ${0.08 * s} 0 0 0 ${0.5 * s} ${0.2 * s}` +
41
- `A${0.08 * s} ${0.08 * s} 0 0 0 ${0.1 * s} ${0.5 * s}` +
42
- `L${0.5 * s} ${0.9 * s}` +
43
- `L${0.9 * s} ${0.5 * s}`,
44
- shurikan: (s) =>
45
- `M${0.3 * s} ${0.1 * s}L${0.5 * s} 0L${0.7 * s} ${0.1 * s}` +
46
- `A ${0.05 * s} ${0.05 * s} 0 0 0 ${0.9 * s} ${0.35 * s}` +
47
- `L${s} ${0.5 * s}L${0.9 * s} ${0.7 * s}` +
48
- `A ${0.05 * s} ${0.05 * s} 0 0 0 ${0.7 * s} ${0.9 * s}` +
49
- `L${0.5 * s} ${s}L${0.3 * s} ${0.9 * s}` +
50
- `A${0.05 * s} ${0.05 * s} 0 0 0 ${0.1 * s} ${0.7 * s}` +
51
- `L0 ${0.5 * s}L${0.1 * s} ${0.3 * s}` +
52
- `A${0.05 * s} ${0.05 * s} 0 0 0 ${0.3 * s} ${0.1 * s}` +
53
- `M${0.4 * s} ${0.5 * s}` +
54
- `A${0.1 * s} ${0.1 * s} 0 0 0 ${0.6 * s} ${0.5 * s}` +
55
- `A${0.1 * s} ${0.1 * s} 0 0 0 ${0.4 * s} ${0.5 * s}`,
56
- target: (s) =>
57
- `M${0.2 * s} ${0.5 * s}` +
58
- `A${0.3 * s} ${0.3 * s} 0 0 0 ${0.8 * s} ${0.5 * s}` +
59
- `A${0.3 * s} ${0.3 * s} 0 0 0 ${0.2 * s} ${0.5 * s}` +
60
- `M0 ${0.5 * s}` +
61
- `L${s} ${0.5 * s}` +
62
- `M${0.5 * s} 0` +
63
- `L${0.5 * s} ${s}`
64
- }
65
-
66
- export const builtIn = [
67
- ...Object.keys(namedShapes).map((key) => ({ shape: namedShapes[key] })),
68
- {
69
- shape: (s) =>
70
- `M${0.1 * s} ${0.1 * s}` +
71
- `A${0.5 * s} ${0.5 * s} 0 0 0 ${0.9 * s} ${0.1 * s}` +
72
- `A${0.5 * s} ${0.5 * s} 0 0 0 ${0.9 * s} ${0.9 * s}` +
73
- `A${0.5 * s} ${0.5 * s} 0 0 0 ${0.1 * s} ${0.9 * s}` +
74
- `A${0.5 * s} ${0.5 * s} 0 0 0 ${0.1 * s} ${0.1 * s}`
75
- },
76
- {
77
- shape: (s) =>
78
- `M${0.5 * s} ${0.3 * s}` +
79
- `A${0.2 * s} ${0.1 * s} 0 0 0 ${0.5 * s} ${0.1 * s}` +
80
- `L${0.5 * s} ${0.9 * s}` +
81
- `M${0.5 * s} ${0.7 * s}` +
82
- `A${0.2 * s} ${0.1 * s} 0 0 0 ${0.5 * s} ${0.9 * s}` +
83
- `M${0.3 * s} ${0.5 * s}` +
84
- `A${0.1 * s} ${0.2 * s} 0 0 0 ${0.1 * s} ${0.5 * s}` +
85
- `L${0.9 * s} ${0.5 * s}` +
86
- `M${0.7 * s} ${0.5 * s}` +
87
- `A${0.1 * s} ${0.2 * s} 0 0 0 ${0.9 * s} ${0.5 * s}`
88
- },
89
- {
90
- shape: (s) =>
91
- `M${0.1 * s} ${0.3 * s}` +
92
- `L${0.7 * s} ${0.9 * s}` +
93
- `L${0.9 * s} ${0.7 * s}` +
94
- `L${0.3 * s} ${0.1 * s}Z` +
95
- `M${0.1 * s} ${0.7 * s}` +
96
- `L${0.7 * s} ${0.1 * s}` +
97
- `L${0.9 * s} ${0.3 * s}` +
98
- `L${0.3 * s} ${0.9 * s}Z`
99
- },
100
- {
101
- shape: (s) =>
102
- `M${0.1 * s} ${0.4 * s}` +
103
- `L${0.9 * s} ${0.4 * s}` +
104
- `L${0.9 * s} ${0.6 * s}` +
105
- `L${0.1 * s} ${0.6 * s}Z` +
106
- `M${0.4 * s} ${0.1 * s}` +
107
- `L${0.4 * s} ${0.9 * s}` +
108
- `L${0.6 * s} ${0.9 * s}` +
109
- `L${0.6 * s} ${0.1 * s}Z`
110
- },
111
- {
112
- shape: (s) =>
113
- `M${0.5 * s} ${0.05 * s}` +
114
- `L${0.19 * s} ${0.95 * s}` +
115
- `L${s} ${0.36 * s}` +
116
- `L0 ${0.36 * s}` +
117
- `L${0.81 * s} ${0.95 * s}Z`
118
- },
119
- {
120
- shape: (s) =>
121
- `M${0.1 * s} ${0.1 * s}` +
122
- `L${0.1 * s} ${0.9 * s}` +
123
- `L${0.9 * s} ${0.9 * s}` +
124
- `L${0.9 * s} ${0.1 * s}Z` +
125
- `M${0.1 * s} ${0.1 * s}` +
126
- `L${0.1 * s} ${0.5 * s}` +
127
- `L${0.5 * s} ${0.5 * s}` +
128
- `L${0.5 * s} ${0.1 * s}Z` +
129
- `M${0.5 * s} ${0.5 * s}` +
130
- `L${0.5 * s} ${0.9 * s}` +
131
- `L${0.9 * s} ${0.9 * s}` +
132
- `L${0.9 * s} ${0.5 * s}Z`
133
- },
134
- {
135
- shape: (s) =>
136
- `M${0.5 * s} 0` +
137
- `L${s} ${0.5 * s}` +
138
- `L${0.5 * s} ${s}` +
139
- `L0 ${0.5 * s}Z` +
140
- `M${0.5 * s} 0` +
141
- `L${s} ${0.5 * s}` +
142
- `L${0.5 * s} ${s}Z`
143
- },
144
- {
145
- shape: (s) =>
146
- `M0 ${0.5 * s}` +
147
- `A${0.6 * s} ${0.4 * s} 0 0 0 ${s} ${0.5 * s}` +
148
- `A${0.6 * s} ${0.4 * s} 0 0 0 0 ${0.5 * s}` +
149
- `M${0.5 * s} 0` +
150
- `A${0.4 * s} ${0.6 * s} 0 0 0 ${0.5 * s} ${s}` +
151
- `A${0.4 * s} ${0.6 * s} 0 0 0 ${0.5 * s} 0`
152
- }
153
- ]
154
-
155
- export class ShapeBrewer {
156
- constructor() {
157
- this.shapes = builtIn
158
- this.repeat = false
159
- this.indices = [...this.shapes.keys()]
160
- this.gray = new ColorBrewer().gray()
161
- this.shades = []
162
- this.repeat = false
163
- }
164
-
165
- clear() {
166
- this.shapes = []
167
- return this
168
- }
169
-
170
- add(shape) {
171
- const shapes = Array.isArray(shape) ? shape : [shape]
172
- this.shapes = [...shapes]
173
-
174
- return this
175
- }
176
-
177
- filter(indices) {
178
- indices = Array.isArray(indices) ? indices : [indices]
179
- this.indices = indices.filter((i) => i > 0 && i < this.shapes.length)
180
-
181
- return this
182
- }
183
-
184
- colors(shades, repeat = false) {
185
- this.shades = Array.isArray(shades) ? shades : [shades]
186
- this.repeat = repeat
187
- return this
188
- }
189
-
190
- brew() {
191
- return this.indices
192
- .map((i) => this.shapes[i])
193
- .map((shape, i) => {
194
- return i < this.shades.length || this.repeat
195
- ? { ...shape, ...this.shades[i % this.shades.length] }
196
- : { ...shape, ...this.gray }
197
- })
198
- }
199
- }
@@ -1,41 +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
- prev = timestamp
11
- elapsed.update((e) => e + diff)
12
- req = window.requestAnimationFrame(tick)
13
- }
14
-
15
- const timer = {
16
- start() {
17
- if (typeof window === 'undefined') return
18
- else if (!req) {
19
- prev = null
20
- req = window.requestAnimationFrame(tick)
21
- }
22
- },
23
- stop() {
24
- if (typeof window === 'undefined') return
25
- else if (req) {
26
- window.cancelAnimationFrame(req)
27
- req = null
28
- }
29
- },
30
- toggle() {
31
- req ? timer.stop() : timer.start()
32
- },
33
- set(val) {
34
- if (typeof val === 'number') elapsed.set(val)
35
- },
36
- reset() {
37
- timer.set(0)
38
- }
39
- }
40
-
41
- export { timer, elapsed }
package/src/constants.js DELETED
@@ -1,66 +0,0 @@
1
- export const __muted__ = {
2
- color: '#eeeeee',
3
- fill: 'empty',
4
- shape: 'circle'
5
- }
6
- export const __colors__ = [
7
- '#FFDE6B',
8
- '#EF89EE',
9
- '#F79F1E',
10
- '#02B8FF',
11
- '#9F84EC',
12
- '#15CBC4',
13
- '#0092FD',
14
- '#F63A57',
15
- '#A2CB39',
16
- '#FF6E2F',
17
- '#FEB8B9',
18
- '#af7aa1',
19
- '#7EFFF5'
20
- ]
21
-
22
- export const __patterns__ = {
23
- A: 'M0 5A6 6 0 0 0 10 5',
24
- B: 'M0 10L10 0',
25
- C: 'M0 0A10 10 0 0 0 10 10',
26
- D: 'M0 0L10 10',
27
- E: 'M10 5A6 6 0 0 0 0 5',
28
- F: 'M10 10A10 10 0 0 0 0 0',
29
- G: 'M0 0L10 10ZM10 0L0 10Z',
30
- H: 'M1 1L9 1L9 9L1 9Z',
31
- I: 'M4 0L4 10M6 10L6 0M0 4L10 4M10 6L0 6',
32
- J: 'M0 2L8 10M2 0L10 8M0 8L8 0M2 10L10 2',
33
- K: 'M5 1A 4 4 0 0 0 9 5A4 4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