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

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 +140 -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 +95 -0
  31. package/src/Plot/Bar.svelte +95 -0
  32. package/src/Plot/Grid.svelte +68 -0
  33. package/src/Plot/Legend.svelte +127 -0
  34. package/src/Plot/Root.svelte +114 -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 +20 -22
  40. package/src/elements/ContinuousLegend.svelte +5 -6
  41. package/src/elements/DefinePatterns.svelte +22 -0
  42. package/src/elements/DiscreteLegend.svelte +4 -6
  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 +177 -0
  49. package/src/lib/brewing/bars.svelte.js +114 -0
  50. package/src/lib/brewing/dimensions.svelte.js +56 -0
  51. package/src/lib/brewing/index.svelte.js +202 -0
  52. package/src/lib/brewing/legends.svelte.js +94 -0
  53. package/src/lib/brewing/scales.svelte.js +85 -0
  54. package/src/lib/brewing/types.js +73 -0
  55. package/src/lib/context.js +132 -0
  56. package/src/lib/scales.svelte.js +122 -0
  57. package/src/lib/utils.js +96 -120
  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 +26 -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,213 @@
1
+ import { min, max } from 'd3-array'
2
+ import { scaleBand, scaleLinear, scaleTime } from 'd3-scale'
3
+
4
+ function getOriginValue(scale) {
5
+ return scale.ticks ? scale(Math.max(0, Math.min(...scale.domain()))) : scale.range()[0]
6
+ }
7
+
8
+ function getScale(domain, range, padding = 0) {
9
+ if (domain.some(isNaN)) {
10
+ return scaleBand().domain(domain).range(range).padding(padding)
11
+ } else if (domain[0] instanceof Date) {
12
+ return scaleTime()
13
+ .domain([min(domain), max(domain)])
14
+ .range(range)
15
+ .nice()
16
+ }
17
+
18
+ return scaleLinear()
19
+ .domain([min([0, ...domain]), max([0, ...domain])])
20
+ .range(range)
21
+ .nice()
22
+ }
23
+
24
+ class Chart {
25
+ // data = []
26
+ // width = 512
27
+ // height = 512
28
+ // origin = { x: 0, y: 0 }
29
+ // range = {
30
+ // x: [0, this.width],
31
+ // y: [this.height, 0]
32
+ // }
33
+ // x
34
+ // y
35
+ // stat = 'identity'
36
+ // scale
37
+ // fill
38
+ // color
39
+ // value
40
+ // shape
41
+ // valueFormat
42
+ // valueLabel
43
+ // domain
44
+ // margin
45
+ // spacing
46
+ // padding
47
+ // flipCoords = false
48
+
49
+ constructor(data, opts) {
50
+ this.width = Number(opts.width) || 2048
51
+ this.height = Number(opts.height) || 2048
52
+ this.flipCoords = opts.flipCoords || false
53
+ this.x = opts.x
54
+ this.y = opts.y
55
+ this.value = opts.value || opts.y
56
+ this.valueLabel = opts.valueLabel || this.value
57
+ this.valueFormat = opts.valueFormat || ((d) => d)
58
+ this.fill = opts.fill || opts.x
59
+ this.color = opts.color || opts.fill
60
+ this.shape = opts.shape || opts.fill
61
+
62
+ this.padding = opts.padding !== undefined ? Number(opts.padding) : 32
63
+
64
+ this.spacing =
65
+ Number(opts.spacing) >= 0 && Number(opts.spacing) <= 0.5 ? Number(opts.spacing) : 0
66
+ this.margin = {
67
+ top: Number(opts.margin?.top) || 0,
68
+ left: Number(opts.margin?.left) || 0,
69
+ right: Number(opts.margin?.right) || 0,
70
+ bottom: Number(opts.margin?.bottom) || 0
71
+ }
72
+ this.domain = {
73
+ x: [...new Set(data.map((d) => d[this.x]))],
74
+ y: [...new Set(data.map((d) => d[this.y]))]
75
+ }
76
+ if (this.flipCoords) {
77
+ this.domain = { y: this.domain.x, x: this.domain.y }
78
+ }
79
+ this.stat = opts.stat || 'identity'
80
+
81
+ this.data = data.map((d) => ({
82
+ x: this.flipCoords ? d[this.y] : d[this.x],
83
+ y: this.flipCoords ? d[this.x] : d[this.y],
84
+ // fill: d[this.fill],
85
+ color: d[this.color]
86
+ // shape: d[this.shape]
87
+ }))
88
+
89
+ this.refresh()
90
+ }
91
+
92
+ padding(value) {
93
+ this.padding = value
94
+ return this.refresh()
95
+ }
96
+
97
+ margin(value) {
98
+ this.margin = value
99
+ return this.refresh()
100
+ }
101
+
102
+ refresh() {
103
+ this.range = {
104
+ x: [this.margin.left + this.padding, this.width - this.margin.right - this.padding],
105
+ y: [this.height - this.padding - this.margin.bottom, this.margin.top + this.padding]
106
+ }
107
+
108
+ const scale = {
109
+ x: getScale(this.domain.x, this.range.x, this.spacing),
110
+ y: getScale(this.domain.y, this.range.y, this.spacing)
111
+ }
112
+
113
+ // scale['value'] = this.value === this.x ? scale.x : scale.y
114
+
115
+ this.origin = {
116
+ x: getOriginValue(scale.x),
117
+ y: getOriginValue(scale.y)
118
+ }
119
+
120
+ this.scale = scale
121
+
122
+ return this
123
+ }
124
+
125
+ // get scale() {
126
+ // return this.scale
127
+ // }
128
+ // get origin() {
129
+ // return this.origin
130
+ // }
131
+ // get margin() {
132
+ // return this.margin
133
+ // }
134
+ // get range() {
135
+ // const [x1, x2] = this.scale.x.range()
136
+ // const [y1, y2] = this.scale.y.range()
137
+
138
+ // return { x1, y1, x2, y2 }
139
+ // }
140
+ // get data() {
141
+ // // aggregate data group by x,y,fill,shape, color
142
+ // // stat = [min, max, avg, std, q1, q3, median, sum, count, box, all]
143
+
144
+ // return this.data
145
+ // }
146
+ // get width() {
147
+ // return this.width
148
+ // }
149
+ // get height() {
150
+ // return this.height
151
+ // }
152
+ // set width(value) {
153
+ // this.width = value
154
+ // }
155
+ // set height(value) {
156
+ // this.height = value
157
+ // }
158
+ // get domain() {
159
+ // return this.domain
160
+ // }
161
+ // get flipCoords() {
162
+ // return this.flipCoords
163
+ // }
164
+ aggregate(value, stat) {
165
+ this.value = value
166
+ this.stat = stat
167
+
168
+ // this.data = nest(this.data)
169
+ }
170
+
171
+ ticks(axis, count, fontSize = 8) {
172
+ const scale = this.scale[axis]
173
+ const [minRange, maxRange] = scale.range()
174
+ let ticks = []
175
+ let offset = 0
176
+
177
+ count = count || Math.abs((maxRange - minRange) / (fontSize * (axis === 'y' ? 8 : 8)))
178
+
179
+ if (scale.ticks) {
180
+ ticks = scale.ticks(Math.round(count))
181
+ } else {
182
+ offset = scale.bandwidth() / 2
183
+ count = Math.min(Math.round(count), scale.domain().length)
184
+
185
+ ticks = scale.domain()
186
+ if (count < scale.domain().length) {
187
+ const diff = scale.domain().length - count
188
+ ticks = ticks.filter((d, i) => i % diff === 0)
189
+ }
190
+ }
191
+
192
+ ticks = ticks
193
+ .map((t) => ({
194
+ label: t,
195
+ pos: scale(t)
196
+ }))
197
+ .map(({ label, pos }) => ({
198
+ label,
199
+ offset: {
200
+ x: axis === 'x' ? offset : 0,
201
+ y: axis === 'y' ? offset : 0
202
+ },
203
+ x: axis === 'x' ? pos : this.origin.x,
204
+ y: axis === 'y' ? pos : this.origin.y
205
+ }))
206
+
207
+ return ticks
208
+ }
209
+ }
210
+
211
+ export function chart(data, aes) {
212
+ return new Chart(data, aes)
213
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @typedef GridPoint
3
+ * @property {number} x - x-coordinate of the point
4
+ * @property {number} y - y-coordinate of the point
5
+ * @property {number} r - radius of the point
6
+ */
7
+
8
+ /**
9
+ * @typedef SwatchGrid
10
+ * @property {number} width - width of the grid
11
+ * @property {number} height - height of the grid
12
+ * @property {GridPoint[]} data - data points of the grid
13
+ */
14
+
15
+ /**
16
+ * @tyoedef {Object} GridOptions
17
+ * @property {number} [pad=0] - The padding between the items
18
+ * @property {number} [columns=0] - The number of columns
19
+ * @property {number} [rows=0] - The number of rows
20
+ */
21
+
22
+ /**
23
+ * Calculates a grid of centres to fit a list of items of `size` within the number of `columns` and `rows`.
24
+ *
25
+ * - Attempts to find a best fit square if both columns and rows are not specified
26
+ * - Value in columns is prioritized over rows for recalculating the grid
27
+ * - Supports padding between the items
28
+ *
29
+ * @param {number} count - number of items
30
+ * @param {number} size - size of the items
31
+ * @param {GridOptions} options - options for the grid
32
+ * @returns {SwatchGrid}
33
+ */
34
+ export function swatchGrid(count, size, options) {
35
+ const { pad = 0 } = options || {}
36
+ let { columns = 0, rows = 0 } = options || {}
37
+ if (columns > 0) {
38
+ rows = Math.ceil(count / columns)
39
+ } else if (rows > 0) {
40
+ columns = Math.ceil(count / rows)
41
+ } else {
42
+ columns = Math.ceil(Math.sqrt(count))
43
+ rows = Math.ceil(count / columns)
44
+ }
45
+
46
+ const width = (size + pad) * columns + pad
47
+ const height = (size + pad) * rows + pad
48
+ const radius = size / 2
49
+ const data = [...Array(count).keys()].map((index) => ({
50
+ x: pad + radius + (index % columns) * (size + pad),
51
+ y: pad + radius + Math.floor(index / columns) * (size + pad),
52
+ r: radius
53
+ }))
54
+
55
+ return { width, height, data }
56
+ }
57
+
58
+ /**
59
+ * Spreads values as patterns with colors from a palette
60
+ *
61
+ * @param {number[]} values - values to spread
62
+ * @param {string[]} patterns - patterns to spread
63
+ * @param {string[]} palette - colors to spread
64
+ * @returns {Record<number, { id: string, pattern: string, color: string }>}
65
+ */
66
+ export function spreadValuesAsPatterns(values, patterns, palette) {
67
+ const result = values
68
+ .map((value, index) => ({
69
+ pattern: patterns[index % patterns.length],
70
+ color: palette[index % palette.length],
71
+ value
72
+ }))
73
+ .reduce(
74
+ (acc, { value, pattern, color }) => ({
75
+ ...acc,
76
+ [value]: {
77
+ id: `${pattern}_${color}`,
78
+ pattern,
79
+ color
80
+ }
81
+ }),
82
+ {}
83
+ )
84
+ return result
85
+ }
@@ -0,0 +1,4 @@
1
+ export { swatch } from './swatch'
2
+ export { swatchGrid } from './grid'
3
+ export * from './chart'
4
+ export * from './brewer'
@@ -0,0 +1,27 @@
1
+ // skipcq: JS-C1003 - Importing all plots from observablehq/plot
2
+ import * as Plot from '@observablehq/plot'
3
+
4
+ export function plotter(node, options) {
5
+ let { data, aes, type, opts } = options
6
+ // let chart = Plot.lineY(options.data).plot({ grid: true })
7
+
8
+ function render() {
9
+ const chart = Plot[type](data, aes).plot({
10
+ color: { scheme: 'turbo', range: [0.1, 0.9] },
11
+ ...opts
12
+ })
13
+ node.firstChild?.remove() // remove old chart, if any
14
+ node.append(chart)
15
+ }
16
+ render()
17
+
18
+ return {
19
+ update: (input) => {
20
+ data = input.data
21
+ aes = input.aes
22
+ type = input.type
23
+ opts = input.opts
24
+ render()
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,16 @@
1
+ import { writable } from 'svelte/store'
2
+ import palette from './palette.json'
3
+ // skipcq: JS-C1003 - Importing all patterns
4
+ import * as patterns from '../patterns'
5
+ import { shapes } from '../symbols'
6
+
7
+ export const swatch = writable({
8
+ palette,
9
+ patterns,
10
+ keys: {
11
+ gray: ['gray'],
12
+ color: Object.keys(palette).filter((name) => name !== 'gray'),
13
+ symbol: shapes,
14
+ pattern: Object.keys(patterns)
15
+ }
16
+ })
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @typedef {Object} TickSteps
3
+ * @property {number} major - count of major ticks
4
+ * @property {number} minor - count of minor ticks
5
+ */
6
+
7
+ /**
8
+ * Generate an array of ticks for a given axis and the tick type
9
+ *
10
+ * @param {number} lower - The lower bound of the axis
11
+ * @param {number} upper - The upper bound of the axis
12
+ * @param {TickSteps} steps - The number of steps between major and minor ticks
13
+ * @param {string} type - The type of tick to generate
14
+ *
15
+ * @returns {Array} - An array of objects representing the ticks
16
+ */
17
+ export function ticksByType(lower, upper, steps, type) {
18
+ if (steps <= 0) return []
19
+ return Array.from({ length: Math.floor((upper - lower) / steps) + 1 }, (_, i) => ({
20
+ position: i * steps,
21
+ label: i * steps,
22
+ type
23
+ })).filter((tick) => tick.position > lower && tick.position < upper)
24
+ }
25
+
26
+ /**
27
+ * Generate an array of ticks for a given axis
28
+ *
29
+ * @param {number} lower - The lower bound of the axis
30
+ * @param {number} upper - The upper bound of the axis
31
+ * @param {TickSteps} steps - The number of steps between major and minor ticks
32
+ *
33
+ * @returns {Array} - An array of objects representing the ticks
34
+ */
35
+ export function getTicks(lower, upper, steps = { major: 10, minor: 0 }) {
36
+ const majorTicks = ticksByType(lower, upper, steps.major, 'major')
37
+ const minorTicks = ticksByType(lower, upper, steps.minor, 'minor').filter(
38
+ (tick) => !majorTicks.find((major) => major.position === tick.position)
39
+ )
40
+ const end = [
41
+ { position: upper, label: upper, type: 'end' },
42
+ { position: lower, label: lower, type: 'end' }
43
+ ]
44
+
45
+ return [...minorTicks, ...majorTicks, ...end].sort((a, b) => a.position - b.position)
46
+ }
@@ -0,0 +1,8 @@
1
+ import { scaledPath } from '@rokkit/core'
2
+
3
+ export function scaledPathCollection(paths) {
4
+ return Object.entries(paths).reduce(
5
+ (acc, [key, value]) => ({ ...acc, [key]: (s) => scaledPath(s, value) }),
6
+ {}
7
+ )
8
+ }
@@ -0,0 +1,17 @@
1
+ <script>
2
+ export let size = 10
3
+ export let thickness = 0.5
4
+ export let stroke = 'currentColor'
5
+
6
+ $: lines = [
7
+ { x1: 0, y1: 0.25 * size, x2: 0.5 * size, y2: 0.25 * size },
8
+ { x1: 0.5 * size, y1: 0.75 * size, x2: size, y2: 0.75 * size },
9
+ { x1: 0, y1: 0, x2: 0, y2: size },
10
+ { x1: size, y1: 0, x2: size, y2: size },
11
+ { x1: 0.5 * size, y1: 0, x2: 0.5 * size, y2: size }
12
+ ]
13
+ </script>
14
+
15
+ {#each lines as line, index (index)}
16
+ <line {...line} {stroke} stroke-width={thickness} stroke-linecap="round" />
17
+ {/each}
@@ -0,0 +1,18 @@
1
+ <script>
2
+ export let size = 10
3
+ export let fill = 'currentColor'
4
+ export let stroke = 'currentColor'
5
+
6
+ $: data = [
7
+ { cx: 0, cy: 0, r: 0.5 },
8
+ { cx: 1, cy: 1, r: 0.5 }
9
+ ].map(({ cx, cy, r }) => ({
10
+ cx: cx * size,
11
+ cy: cy * size,
12
+ r: r * size
13
+ }))
14
+ </script>
15
+
16
+ {#each data as { cx, cy, r }, index (index)}
17
+ <circle {cx} {cy} {r} {fill} {stroke} />
18
+ {/each}
@@ -0,0 +1,14 @@
1
+ <script>
2
+ export let size = 10
3
+ export let thickness = 0.5
4
+ export let stroke = 'currentColor'
5
+
6
+ $: lines = [
7
+ { x1: 0, y1: 0, x2: size, y2: size },
8
+ { x1: 0, y1: size, x2: size, y2: 0 }
9
+ ]
10
+ </script>
11
+
12
+ {#each lines as line, index (index)}
13
+ <line {...line} {stroke} stroke-width={thickness} stroke-linecap="round" />
14
+ {/each}
@@ -0,0 +1,9 @@
1
+ <script>
2
+ import NamedPattern from './paths/NamedPattern.svelte'
3
+
4
+ export let size = 10
5
+ export let thickness = 0.5
6
+ export let stroke = 'currentColor'
7
+ </script>
8
+
9
+ <NamedPattern {size} {thickness} {stroke} name="curvedWave" />
@@ -0,0 +1,19 @@
1
+ <script>
2
+ export let size = 10
3
+ export let fill = 'currentColor'
4
+
5
+ $: data = [
6
+ { cx: 0.2 * size, cy: 0.2 * size },
7
+ { cx: 0.4 * size, cy: 0.4 * size },
8
+ { cx: 0.6 * size, cy: 0.6 * size },
9
+ { cx: 0.8 * size, cy: 0.8 * size },
10
+ { cx: 0.8 * size, cy: 0.2 * size },
11
+ { cx: 0.6 * size, cy: 0.4 * size },
12
+ { cx: 0.4 * size, cy: 0.6 * size },
13
+ { cx: 0.2 * size, cy: 0.8 * size }
14
+ ].map((x) => ({ ...x, r: 0.08 * size }))
15
+ </script>
16
+
17
+ {#each data as { cx, cy, r }, index (index)}
18
+ <circle {cx} {cy} {r} {fill} />
19
+ {/each}
@@ -0,0 +1,15 @@
1
+ <script>
2
+ export let size = 10
3
+ export let fill = 'currentColor'
4
+ export let stroke = 'currentColor'
5
+
6
+ const centres = [
7
+ { cx: 0, cy: 0 },
8
+ { cx: size, cy: size }
9
+ ]
10
+ $: r = 0.5 * size
11
+ </script>
12
+
13
+ {#each centres as { cx, cy }, index (index)}
14
+ <circle {cx} {cy} {r} {fill} {stroke} />
15
+ {/each}
@@ -0,0 +1,17 @@
1
+ <script>
2
+ const thickness = 0.5
3
+ export let size = 10
4
+ export let stroke = 'currentColor'
5
+
6
+ const lines = [
7
+ { x1: 0, y1: 0.25 * size, x2: 0.5 * size, y2: 0.25 * size },
8
+ { x1: 0.5 * size, y1: 0.75 * size, x2: size, y2: 0.75 * size },
9
+ { x1: 0, y1: 0, x2: 0, y2: size },
10
+ { x1: size, y1: 0, x2: size, y2: size },
11
+ { x1: 0.5 * size, y1: 0, x2: 0.5 * size, y2: size }
12
+ ]
13
+ </script>
14
+
15
+ {#each lines as line, index (index)}
16
+ <line {...line} {stroke} stroke-width={thickness} stroke-linecap="round" />
17
+ {/each}
@@ -0,0 +1,15 @@
1
+ <script>
2
+ export let size = 10
3
+ export let fill = 'currentColor'
4
+ export let stroke = 'currentColor'
5
+
6
+ const polygons = [
7
+ [0, 0.5 * size, 0.5 * size, size, 0, size],
8
+ [0.5 * size, 0, 0, 0, 0, 0.5 * size],
9
+ [size, 0, 0.5 * size, 0.5 * size, size, size]
10
+ ]
11
+ </script>
12
+
13
+ {#each polygons as points, index (index)}
14
+ <polygon points={points.join(', ')} {fill} {stroke} stroke-width="0" />
15
+ {/each}
@@ -0,0 +1,13 @@
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 fill = 'none'
8
+ export let data = []
9
+
10
+ $: d = scaledPath(size, data)
11
+ </script>
12
+
13
+ <path {d} {stroke} stroke-width={thickness} {fill} />
@@ -0,0 +1,14 @@
1
+ export { default as Brick } from './Brick.svelte'
2
+ export { default as Circles } from './Circles.svelte'
3
+ export { default as Dots } from './Dots.svelte'
4
+ export { default as CrossHatch } from './CrossHatch.svelte'
5
+ export { default as Waves } from './Waves.svelte'
6
+ // export { default as Squares } from './Squares.svelte'
7
+ export { default as Tile } from './Tile.svelte'
8
+ export { default as Triangles } from './Triangles.svelte'
9
+ // export { default as Waves } from './Waves.svelte'
10
+ // export { default as ZigZag } from './ZigZag.svelte'
11
+ // export { default as Flower } from './Flower.svelte'
12
+ // export { default as NamedPath } from './NamedPath.svelte'
13
+ export { default as CurvedWave } from './CurvedWave.svelte'
14
+ export { default as OutlineCircles } from './OutlineCircles.svelte'
@@ -0,0 +1,12 @@
1
+ <script>
2
+ import { patterns } from './constants'
3
+
4
+ export let size = 10
5
+ export let thickness = 0.5
6
+ export let stroke = 'currentColor'
7
+ export let name = 'cross-hatch'
8
+
9
+ $: d = patterns[name](size)
10
+ </script>
11
+
12
+ <path {d} {stroke} stroke-width={thickness} fill="none" />
@@ -0,0 +1,4 @@
1
+ import { scaledPathCollection } from '../../old_lib/utils'
2
+ import paths from './patterns.json'
3
+
4
+ export const patterns = scaledPathCollection(paths)
@@ -0,0 +1,26 @@
1
+ <script>
2
+ export let x = 0
3
+ export let y = 0
4
+ export let size = 1
5
+ export let fill = 'currentColor'
6
+ export let stroke = 'currentColor'
7
+
8
+ $: r = size * 3.534
9
+ $: props = { rx: r * 0.1, ry: r * 0.1, ...$$restProps }
10
+ </script>
11
+
12
+ <rect
13
+ x={x - r}
14
+ y={y - r}
15
+ width={r * 2}
16
+ height={r * 2}
17
+ {fill}
18
+ {stroke}
19
+ {...props}
20
+ role="button"
21
+ on:click
22
+ on:mouseover
23
+ on:mouseleave
24
+ on:focus
25
+ tabindex="0"
26
+ />
@@ -0,0 +1,31 @@
1
+ <script>
2
+ import { namedShapes } from './constants'
3
+
4
+ export let x = 0
5
+ export let y = 0
6
+ export let size = 1
7
+ export let fill = 'none'
8
+ export let stroke = 'currentColor'
9
+ export let thickness = 1
10
+
11
+ export let name = 'circle'
12
+
13
+ $: d = name in namedShapes ? namedShapes[name](size) : namedShapes['circle'](size)
14
+ </script>
15
+
16
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
17
+ <path
18
+ {d}
19
+ {fill}
20
+ {stroke}
21
+ transform="translate({x},{y})"
22
+ stroke-width={thickness}
23
+ fill-rule="evenodd"
24
+ role="button"
25
+ on:click
26
+ on:mouseover
27
+ on:mouseleave
28
+ on:focus
29
+ on:blur
30
+ tabindex="0"
31
+ />
@@ -0,0 +1,4 @@
1
+ import { scaledPathCollection } from '../../old_lib/utils'
2
+ import paths from './shapes.json' with { type: 'json' }
3
+
4
+ export const namedShapes = scaledPathCollection(paths)
@@ -0,0 +1,9 @@
1
+ import { namedShapes } from './constants'
2
+ import { default as Shape } from './Shape.svelte'
3
+ import { default as RoundedSquare } from './RoundedSquare.svelte'
4
+
5
+ export const shapes = [...Object.keys(namedShapes), 'rounded-square']
6
+ export const components = {
7
+ default: Shape,
8
+ 'rounded-square': RoundedSquare
9
+ }