@rokkit/chart 1.0.0-next.12 → 1.0.0-next.121

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 (148) hide show
  1. package/README.md +132 -46
  2. package/dist/Plot/index.d.ts +5 -0
  3. package/dist/elements/index.d.ts +6 -0
  4. package/dist/index.d.ts +14 -0
  5. package/dist/lib/brewing/axes.svelte.d.ts +72 -0
  6. package/dist/lib/brewing/bars.svelte.d.ts +54 -0
  7. package/dist/lib/brewing/dimensions.svelte.d.ts +35 -0
  8. package/dist/lib/brewing/index.svelte.d.ts +118 -0
  9. package/dist/lib/brewing/legends.svelte.d.ts +54 -0
  10. package/dist/lib/brewing/scales.svelte.d.ts +29 -0
  11. package/dist/lib/brewing/types.d.ts +162 -0
  12. package/dist/lib/context.d.ts +13 -0
  13. package/dist/lib/scales.svelte.d.ts +35 -0
  14. package/dist/lib/utils.d.ts +58 -0
  15. package/dist/old_lib/brewer.d.ts +9 -0
  16. package/dist/old_lib/chart.d.ts +40 -0
  17. package/dist/old_lib/grid.d.ts +72 -0
  18. package/dist/old_lib/index.d.ts +4 -0
  19. package/dist/old_lib/plots.d.ts +3 -0
  20. package/dist/old_lib/swatch.d.ts +285 -0
  21. package/dist/old_lib/ticks.d.ts +36 -0
  22. package/dist/old_lib/utils.d.ts +1 -0
  23. package/dist/patterns/index.d.ts +9 -0
  24. package/dist/patterns/paths/constants.d.ts +1 -0
  25. package/dist/symbols/constants/index.d.ts +1 -0
  26. package/dist/symbols/index.d.ts +5 -0
  27. package/dist/template/constants.d.ts +43 -0
  28. package/dist/template/shapes/index.d.ts +4 -0
  29. package/package.json +28 -44
  30. package/src/Plot/Axis.svelte +103 -0
  31. package/src/Plot/Bar.svelte +95 -0
  32. package/src/Plot/Grid.svelte +68 -0
  33. package/src/Plot/Legend.svelte +129 -0
  34. package/src/Plot/Root.svelte +112 -0
  35. package/src/Plot/index.js +5 -0
  36. package/src/Symbol.svelte +21 -0
  37. package/src/{chart/Texture.svelte → Texture.svelte} +3 -3
  38. package/src/elements/Bar.svelte +2 -8
  39. package/src/elements/ColorRamp.svelte +3 -5
  40. package/src/elements/ContinuousLegend.svelte +4 -5
  41. package/src/elements/DefinePatterns.svelte +22 -0
  42. package/src/elements/DiscreteLegend.svelte +3 -5
  43. package/src/elements/Label.svelte +6 -5
  44. package/src/elements/SymbolGrid.svelte +23 -0
  45. package/src/elements/index.js +6 -0
  46. package/src/examples/BarChartExample.svelte +81 -0
  47. package/src/index.js +18 -16
  48. package/src/lib/brewing/axes.svelte.js +179 -0
  49. package/src/lib/brewing/bars.svelte.js +114 -0
  50. package/src/lib/brewing/dimensions.svelte.js +54 -0
  51. package/src/lib/brewing/index.svelte.js +214 -0
  52. package/src/lib/brewing/legends.svelte.js +95 -0
  53. package/src/lib/brewing/scales.svelte.js +94 -0
  54. package/src/lib/brewing/types.js +73 -0
  55. package/src/lib/context.js +122 -0
  56. package/src/lib/scales.svelte.js +129 -0
  57. package/src/lib/utils.js +110 -132
  58. package/src/old_lib/brewer.js +25 -0
  59. package/src/old_lib/chart.js +213 -0
  60. package/src/old_lib/grid.js +85 -0
  61. package/src/old_lib/index.js +4 -0
  62. package/src/old_lib/plots.js +27 -0
  63. package/src/old_lib/swatch.js +16 -0
  64. package/src/old_lib/ticks.js +46 -0
  65. package/src/old_lib/utils.js +8 -0
  66. package/src/patterns/Brick.svelte +17 -0
  67. package/src/patterns/Circles.svelte +18 -0
  68. package/src/patterns/CrossHatch.svelte +14 -0
  69. package/src/patterns/CurvedWave.svelte +9 -0
  70. package/src/patterns/Dots.svelte +19 -0
  71. package/src/patterns/OutlineCircles.svelte +15 -0
  72. package/src/patterns/Tile.svelte +17 -0
  73. package/src/patterns/Triangles.svelte +15 -0
  74. package/src/patterns/Waves.svelte +13 -0
  75. package/src/patterns/index.js +14 -0
  76. package/src/patterns/paths/NamedPattern.svelte +12 -0
  77. package/src/patterns/paths/constants.js +4 -0
  78. package/src/symbols/RoundedSquare.svelte +27 -0
  79. package/src/symbols/Shape.svelte +31 -0
  80. package/src/symbols/constants/index.js +4 -0
  81. package/src/symbols/index.js +9 -0
  82. package/src/symbols/outline.svelte +60 -0
  83. package/src/symbols/solid.svelte +60 -0
  84. package/src/template/Texture.svelte +16 -0
  85. package/src/template/constants.js +43 -0
  86. package/src/template/shapes/Circles.svelte +16 -0
  87. package/src/template/shapes/Lines.svelte +17 -0
  88. package/src/template/shapes/Path.svelte +12 -0
  89. package/src/template/shapes/Polygons.svelte +18 -0
  90. package/src/template/shapes/index.js +4 -0
  91. package/LICENSE +0 -21
  92. package/src/chart/FacetGrid.svelte +0 -51
  93. package/src/chart/Grid.svelte +0 -34
  94. package/src/chart/Legend.svelte +0 -16
  95. package/src/chart/PatternDefs.svelte +0 -13
  96. package/src/chart/Swatch.svelte +0 -93
  97. package/src/chart/SwatchButton.svelte +0 -29
  98. package/src/chart/SwatchGrid.svelte +0 -55
  99. package/src/chart/Symbol.svelte +0 -37
  100. package/src/chart/TexturedShape.svelte +0 -27
  101. package/src/chart/TimelapseChart.svelte +0 -97
  102. package/src/chart/Timer.svelte +0 -27
  103. package/src/chart.js +0 -9
  104. package/src/components/charts/Axis.svelte +0 -66
  105. package/src/components/charts/Chart.svelte +0 -35
  106. package/src/components/index.js +0 -23
  107. package/src/components/lib/axis.js +0 -0
  108. package/src/components/lib/chart.js +0 -187
  109. package/src/components/lib/color.js +0 -327
  110. package/src/components/lib/funnel.js +0 -204
  111. package/src/components/lib/index.js +0 -19
  112. package/src/components/lib/pattern.js +0 -190
  113. package/src/components/lib/rollup.js +0 -55
  114. package/src/components/lib/shape.js +0 -199
  115. package/src/components/lib/summary.js +0 -145
  116. package/src/components/lib/theme.js +0 -23
  117. package/src/components/lib/timer.js +0 -41
  118. package/src/components/lib/utils.js +0 -165
  119. package/src/components/plots/BarPlot.svelte +0 -36
  120. package/src/components/plots/BoxPlot.svelte +0 -54
  121. package/src/components/plots/ScatterPlot.svelte +0 -30
  122. package/src/components/store.js +0 -70
  123. package/src/constants.js +0 -66
  124. package/src/elements/PatternDefs.svelte +0 -13
  125. package/src/elements/PatternMask.svelte +0 -20
  126. package/src/elements/Symbol.svelte +0 -38
  127. package/src/elements/Tooltip.svelte +0 -23
  128. package/src/funnel.svelte +0 -35
  129. package/src/geom.js +0 -105
  130. package/src/lib/axis.js +0 -75
  131. package/src/lib/colors.js +0 -32
  132. package/src/lib/geom.js +0 -4
  133. package/src/lib/shapes.js +0 -144
  134. package/src/lib/timer.js +0 -44
  135. package/src/lookup.js +0 -29
  136. package/src/plots/BarPlot.svelte +0 -55
  137. package/src/plots/BoxPlot.svelte +0 -0
  138. package/src/plots/FunnelPlot.svelte +0 -33
  139. package/src/plots/HeatMap.svelte +0 -5
  140. package/src/plots/HeatMapCalendar.svelte +0 -129
  141. package/src/plots/LinePlot.svelte +0 -55
  142. package/src/plots/Plot.svelte +0 -25
  143. package/src/plots/RankBarPlot.svelte +0 -38
  144. package/src/plots/ScatterPlot.svelte +0 -20
  145. package/src/plots/ViolinPlot.svelte +0 -11
  146. package/src/plots/heatmap.js +0 -70
  147. package/src/plots/index.js +0 -10
  148. 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
+ >
11
+ <style>
12
+ :where(.plot) {
13
+ --plot-background: white;
14
+ display: block;
15
+ height: auto;
16
+ height: intrinsic;
17
+ max-width: 100%;
18
+ }
19
+ :where(.plot text),
20
+ :where(.plot tspan) {
21
+ white-space: pre;
22
+ }
23
+ </style>
24
+ <g aria-label="x-axis tick" fill="none" stroke="currentColor"
25
+ ><path transform="translate(68,30)" d="M0,0L0,6"></path><path
26
+ transform="translate(160,30)"
27
+ d="M0,0L0,6"
28
+ ></path><path transform="translate(252,30)" d="M0,0L0,6"></path><path
29
+ transform="translate(344,30)"
30
+ d="M0,0L0,6"
31
+ ></path><path transform="translate(436,30)" d="M0,0L0,6"></path><path
32
+ transform="translate(528,30)"
33
+ d="M0,0L0,6"
34
+ ></path><path transform="translate(620,30)" d="M0,0L0,6"></path></g
35
+ ><g aria-label="x-axis tick label" transform="translate(0,9)"
36
+ ><text y="0.71em" transform="translate(68,30)">asterisk</text><text
37
+ y="0.71em"
38
+ transform="translate(160,30)">circle</text
39
+ ><text y="0.71em" transform="translate(252,30)">diamond2</text><text
40
+ y="0.71em"
41
+ transform="translate(344,30)">plus</text
42
+ ><text y="0.71em" transform="translate(436,30)">square2</text><text
43
+ y="0.71em"
44
+ transform="translate(528,30)">times</text
45
+ ><text y="0.71em" transform="translate(620,30)">triangle2</text></g
46
+ ><g aria-label="dot" fill="none" stroke="currentColor" stroke-width="1.5"
47
+ ><path transform="translate(160,15.25)" d="M4.5,0A4.5,4.5,0,1,1,-4.5,0A4.5,4.5,0,1,1,4.5,0"
48
+ ></path><path transform="translate(344,15.25)" d="M-6.873,0L6.873,0M0,6.873L0,-6.873"
49
+ ></path><path transform="translate(528,15.25)" d="M-4.87,-4.87L4.87,4.87M-4.87,4.87L4.87,-4.87"
50
+ ></path><path transform="translate(620,15.25)" d="M0,-5.443L4.714,2.721L-4.714,2.721Z"
51
+ ></path><path
52
+ transform="translate(68,15.25)"
53
+ d="M0,4.769L0,-4.769M-4.13,-2.384L4.13,2.384M-4.13,2.384L4.13,-2.384"
54
+ ></path><path
55
+ transform="translate(436,15.25)"
56
+ d="M3.534,3.534L3.534,-3.534L-3.534,-3.534L-3.534,3.534Z"
57
+ ></path><path transform="translate(252,15.25)" d="M0,-4.995L4.995,0L0,4.995L-4.995,0Z"
58
+ ></path></g
59
+ ></svg
60
+ >
@@ -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
+ >
@@ -0,0 +1,16 @@
1
+ <script>
2
+ import { library } from './constants'
3
+ import * as templates from './shapes'
4
+ import { pick } from 'ramda'
5
+
6
+ export let size = 10
7
+ export let fill = 'none'
8
+ export let stroke = 'none'
9
+ export let thickness = 0.5
10
+ export let name = 'Waves'
11
+
12
+ $: pattern = library[name]
13
+ $: props = pick(pattern.allowed ?? [], { fill, stroke, thickness })
14
+ </script>
15
+
16
+ <svelte:component this={templates[pattern.component]} {size} {...props} data={pattern.data} />
@@ -0,0 +1,43 @@
1
+ export const library = {
2
+ Brick: {
3
+ component: 'Lines',
4
+ allowed: ['stroke'],
5
+ data: [
6
+ { x1: 0, y1: 0.25, x2: 0.5, y2: 0.25 },
7
+ { x1: 0.5, y1: 0.75, x2: 1, y2: 0.75 },
8
+ { x1: 0, y1: 0, x2: 0, y2: 1 },
9
+ { x1: 1, y1: 0, x2: 1, y2: 1 },
10
+ { x1: 0.5, y1: 0, x2: 0.5, y2: 1 }
11
+ ]
12
+ },
13
+ Circles: {
14
+ component: 'Circles',
15
+ allowed: ['fill', 'stroke'],
16
+ data: [
17
+ { cx: 0, cy: 0, r: 0.5 },
18
+ { cx: 1, cy: 1, r: 0.5 }
19
+ ]
20
+ },
21
+ Dominoes: {
22
+ component: 'Circles',
23
+ allowed: ['fill'],
24
+ data: [
25
+ { cx: 0.2, cy: 0.2, r: 0.8 },
26
+ { cx: 0.4, cy: 0.4, r: 0.8 },
27
+ { cx: 0.6, cy: 0.6, r: 0.8 },
28
+ { cx: 0.8, cy: 0.8, r: 0.8 },
29
+ { cx: 0.8, cy: 0.2, r: 0.8 },
30
+ { cx: 0.6, cy: 0.4, r: 0.8 },
31
+ { cx: 0.4, cy: 0.6, r: 0.8 },
32
+ { cx: 0.2, cy: 0.8, r: 0.8 }
33
+ ]
34
+ },
35
+ Waves: {
36
+ component: 'Path',
37
+ stroke: true,
38
+ data: [
39
+ ['M', 0, 0.25],
40
+ ['A', 0.6, 0.5, 0, 0, 0, 1, 0.25]
41
+ ]
42
+ }
43
+ }
@@ -0,0 +1,16 @@
1
+ <script>
2
+ export let size = 10
3
+ export let fill = 'currentColor'
4
+ export let stroke = 'currentColor'
5
+ export let data
6
+
7
+ $: circles = data.map(({ cx, cy, r }) => ({
8
+ cx: cx * size,
9
+ cy: cy * size,
10
+ r: r * size
11
+ }))
12
+ </script>
13
+
14
+ {#each circles as { cx, cy, r }}
15
+ <circle {cx} {cy} {r} {fill} {stroke} />
16
+ {/each}
@@ -0,0 +1,17 @@
1
+ <script>
2
+ export let size = 10
3
+ export let thickness = 0.5
4
+ export let stroke = 'currentColor'
5
+ export let data = []
6
+
7
+ $: lines = data.map(({ x1, y1, x2, y2 }) => ({
8
+ x1: x1 * size,
9
+ y1: y1 * size,
10
+ x2: x2 * size,
11
+ y2: y2 * size
12
+ }))
13
+ </script>
14
+
15
+ {#each lines as line}
16
+ <line {...line} {stroke} stroke-width={thickness} stroke-linecap="round" />
17
+ {/each}
@@ -0,0 +1,12 @@
1
+ <script>
2
+ import { scaledPath } from '@rokkit/core'
3
+
4
+ export let size = 10
5
+ export let thickness = 0.5
6
+ export let stroke = 'currentColor'
7
+ export let data = []
8
+
9
+ $: d = scaledPath(size, data)
10
+ </script>
11
+
12
+ <path {d} {stroke} stroke-width={thickness} fill="none" />
@@ -0,0 +1,18 @@
1
+ <script>
2
+ export let size = 10
3
+ export let thickness = 0.5
4
+ export let fill = 'currentColor'
5
+ export let stroke = 'currentColor'
6
+ export let data = []
7
+
8
+ const polygons = data.map((points) => points.map((point) => point * size).join(', '))
9
+ // [
10
+ // [0, 0.5 * size, 0.5 * size, size, 0, size],
11
+ // [0.5 * size, 0, 0, 0, 0, 0.5 * size],
12
+ // [size, 0, 0.5 * size, 0.5 * size, size, size]
13
+ // ]
14
+ </script>
15
+
16
+ {#each polygons as points}
17
+ <polygon {points} {fill} {stroke} stroke-width={thickness} />
18
+ {/each}
@@ -0,0 +1,4 @@
1
+ export { default as Circles } from './Circles.svelte'
2
+ export { default as Lines } from './Lines.svelte'
3
+ export { default as Path } from './Path.svelte'
4
+ export { default as Polygons } from './Polygons.svelte'
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,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>