@rokkit/chart 1.0.0-next.95 → 1.0.0-next.97

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/chart",
3
- "version": "1.0.0-next.95",
3
+ "version": "1.0.0-next.97",
4
4
  "description": "Components for making interactive charts.",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
@@ -12,17 +12,17 @@
12
12
  "access": "public"
13
13
  },
14
14
  "devDependencies": {
15
- "@sveltejs/vite-plugin-svelte": "^3.0.2",
16
- "@testing-library/svelte": "^4.1.0",
17
- "@vitest/coverage-v8": "^1.4.0",
18
- "@vitest/ui": "~1.4.0",
15
+ "@sveltejs/vite-plugin-svelte": "^3.1.1",
16
+ "@testing-library/svelte": "^5.1.0",
17
+ "@vitest/coverage-v8": "^1.6.0",
18
+ "@vitest/ui": "~1.6.0",
19
19
  "js-yaml": "^4.1.0",
20
- "jsdom": "^24.0.0",
21
- "svelte": "^4.2.12",
22
- "typescript": "^5.4.4",
23
- "vite": "^5.2.8",
24
- "vitest": "~1.4.0",
25
- "shared-config": "1.0.0-next.95"
20
+ "jsdom": "^24.1.0",
21
+ "svelte": "^4.2.17",
22
+ "typescript": "^5.4.5",
23
+ "vite": "^5.2.12",
24
+ "vitest": "~1.6.0",
25
+ "shared-config": "1.0.0-next.97"
26
26
  },
27
27
  "dependencies": {
28
28
  "@observablehq/plot": "^0.6.14",
@@ -33,12 +33,12 @@
33
33
  "d3-scale": "^4.0.2",
34
34
  "d3-shape": "^3.2.0",
35
35
  "date-fns": "^3.6.0",
36
- "ramda": "^0.29.1",
36
+ "ramda": "^0.30.1",
37
37
  "yootils": "^0.3.1",
38
- "@rokkit/atoms": "1.0.0-next.95",
39
- "@rokkit/core": "1.0.0-next.95",
40
- "@rokkit/molecules": "1.0.0-next.95",
41
- "@rokkit/stores": "1.0.0-next.95"
38
+ "@rokkit/atoms": "1.0.0-next.97",
39
+ "@rokkit/core": "1.0.0-next.97",
40
+ "@rokkit/stores": "1.0.0-next.97",
41
+ "@rokkit/molecules": "1.0.0-next.97"
42
42
  },
43
43
  "files": [
44
44
  "src/**/*.js",
package/src/lib/brewer.js CHANGED
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Get fill patterns for a set of values
3
+ *
4
+ * @param {Array} values - Array of values
5
+ * @param {Object} swatch - Object with keys for color, gray, and pattern
6
+ * @param {Boolean} gray - Boolean to determine if gray or color
7
+ * @returns {Object} - Object with keys for pattern and color
8
+ */
1
9
  export function getFillPatterns(values, swatch, gray = false) {
2
10
  const colors = gray ? swatch.keys.gray : swatch.keys.color
3
11
  const max_colors = colors.length
package/src/lib/grid.js CHANGED
@@ -1,15 +1,22 @@
1
1
  /**
2
2
  * @typedef GridPoint
3
- * @property {number} x
4
- * @property {number} y
5
- * @property {number} r
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
6
  */
7
7
 
8
8
  /**
9
9
  * @typedef SwatchGrid
10
- * @property {number} width
11
- * @property {number} height
12
- * @property {GridPoint[]} data
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
13
20
  */
14
21
 
15
22
  /**
@@ -19,14 +26,14 @@
19
26
  * - Value in columns is prioritized over rows for recalculating the grid
20
27
  * - Supports padding between the items
21
28
  *
22
- * @param {number} count
23
- * @param {number} size
24
- * @param {number} pad
25
- * @param {number} columns
26
- * @param {number} rows
29
+ * @param {number} count - number of items
30
+ * @param {number} size - size of the items
31
+ * @param {GridOptions} options - options for the grid
27
32
  * @returns {SwatchGrid}
28
33
  */
29
- export function swatchGrid(count, size, pad = 0, columns = 0, rows = 0) {
34
+ export function swatchGrid(count, size, options) {
35
+ const { pad = 0 } = options || {}
36
+ let { columns = 0, rows = 0 } = options || {}
30
37
  if (columns > 0) {
31
38
  rows = Math.ceil(count / columns)
32
39
  } else if (rows > 0) {
@@ -51,9 +58,9 @@ export function swatchGrid(count, size, pad = 0, columns = 0, rows = 0) {
51
58
  /**
52
59
  * Spreads values as patterns with colors from a palette
53
60
  *
54
- * @param {number[]} values
55
- * @param {string[]} patterns
56
- * @param {string[]} palette
61
+ * @param {number[]} values - values to spread
62
+ * @param {string[]} patterns - patterns to spread
63
+ * @param {string[]} palette - colors to spread
57
64
  * @returns {Record<number, { id: string, pattern: string, color: string }>}
58
65
  */
59
66
  export function spreadValuesAsPatterns(values, patterns, palette) {
package/src/lib/ticks.js CHANGED
@@ -1,15 +1,42 @@
1
- function ticksByType(lower, upper, steps, type) {
2
- return Array.from({ length: Math.floor((upper - lower) / steps[type]) + 1 }, (_, i) => ({
3
- position: i * steps[type],
4
- label: i * steps[type],
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,
5
22
  type
6
- }))
23
+ })).filter((tick) => tick.position > lower && tick.position < upper)
7
24
  }
8
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
+ */
9
35
  export function getTicks(lower, upper, steps = { major: 10, minor: 0 }) {
10
- if (steps.major === 0 && steps.minor === 0) return []
11
- const minorTicks = ticksByType(lower, upper, steps.major, 'major')
12
- const majorTicks = ticksByType(lower, upper, steps.minor, 'minor')
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
+ )
13
40
  const end = [
14
41
  { position: upper, label: upper, type: 'end' },
15
42
  { position: lower, label: lower, type: 'end' }
@@ -11,3 +11,4 @@ export { default as Triangles } from './Triangles.svelte'
11
11
  // export { default as Flower } from './Flower.svelte'
12
12
  // export { default as NamedPath } from './NamedPath.svelte'
13
13
  export { default as CurvedWave } from './CurvedWave.svelte'
14
+ export { default as OutlineCircles } from './OutlineCircles.svelte'
@@ -10,7 +10,7 @@
10
10
 
11
11
  export let name = 'circle'
12
12
 
13
- $: d = name in namedShapes ? namedShapes[name](size) : namedShapes['star'](size)
13
+ $: d = name in namedShapes ? namedShapes[name](size) : namedShapes['circle'](size)
14
14
  </script>
15
15
 
16
16
  <!-- svelte-ignore a11y-click-events-have-key-events -->
@@ -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} />
@@ -1,3 +1,4 @@
1
1
  export { default as Circles } from './Circles.svelte'
2
2
  export { default as Lines } from './Lines.svelte'
3
3
  export { default as Path } from './Path.svelte'
4
+ export { default as Polygons } from './Polygons.svelte'
@@ -1,20 +0,0 @@
1
- <script>
2
- import { library } from './constants'
3
- import templates from './templates'
4
- import { pick } from 'ramda'
5
-
6
- export let size = 10
7
- export let fill = 'none'
8
- export let stroke = 'none'
9
- export let name = 'Waves'
10
-
11
- $: pattern = library[name]
12
- $: props = { fill, stroke }
13
- </script>
14
-
15
- <svelte:component
16
- this={templates[pattern.component]}
17
- {size}
18
- {...pick(pattern.allowed, props)}
19
- data={pattern.data}
20
- />
File without changes