@rokkit/chart 1.2.0 → 1.3.1

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.2.0",
3
+ "version": "1.3.1",
4
4
  "type": "module",
5
5
  "description": "Data-driven chart components",
6
6
  "repository": {
@@ -169,7 +169,7 @@
169
169
  {#each patternItems as item (item.key)}
170
170
  <div class="legend-item" data-plot-legend-item>
171
171
  <svg width="14" height="14" data-plot-legend-swatch>
172
- <rect width="14" height="14" fill="var(--color-surface-z2, #ccc)" />
172
+ <rect width="14" height="14" fill="var(--paper-mute, #ccc)" />
173
173
  <rect width="14" height="14" fill="url(#{item.patternId})" />
174
174
  </svg>
175
175
  <span class="label" data-plot-legend-label>{item.label}</span>
@@ -242,7 +242,7 @@
242
242
  font-size: 12px;
243
243
  }
244
244
  .legend-section {
245
- border-top: 1px solid var(--color-surface-z3, #e0e0e0);
245
+ border-top: 1px solid var(--paper-mute, #e0e0e0);
246
246
  padding-top: 6px;
247
247
  }
248
248
  .legend-item {
@@ -32,7 +32,7 @@
32
32
  width = 280,
33
33
  height = 120,
34
34
  color = 'rgb(var(--color-primary, 249 115 22))',
35
- dimColor = 'rgb(var(--color-surface-z3, 203 213 225))'
35
+ dimColor = 'rgb(var(--paper-mute, 203 213 225))'
36
36
  }: Props = $props()
37
37
 
38
38
  const cf = getContext<CrossFilter | undefined>('crossfilter')
@@ -285,7 +285,7 @@
285
285
  flex-direction: column;
286
286
  gap: 4px;
287
287
  font-size: 12px;
288
- color: rgb(var(--color-surface-z6, 100 116 139));
288
+ color: rgb(var(--ink-soft, 100 116 139));
289
289
  }
290
290
  [data-filter-histogram-label] {
291
291
  font-weight: 600;
package/src/lib/chart.js CHANGED
@@ -97,11 +97,13 @@ class Chart {
97
97
  this.refresh()
98
98
  }
99
99
 
100
+ /* v8 ignore next 4 -- this.padding (number) set in #initFields shadows this prototype method */
100
101
  padding(value) {
101
102
  this.padding = value
102
103
  return this.refresh()
103
104
  }
104
105
 
106
+ /* v8 ignore next 4 -- this.margin (object) set in #initFields shadows this prototype method */
105
107
  margin(value) {
106
108
  this.margin = value
107
109
  return this.refresh()
@@ -1,6 +1,8 @@
1
1
  import { getContext, setContext } from 'svelte'
2
2
  import { writable, derived } from 'svelte/store'
3
- import * as d3 from 'd3'
3
+ import { scaleBand, scaleLinear, scaleOrdinal } from 'd3-scale'
4
+ import { schemeCategory10 } from 'd3-scale-chromatic'
5
+ import { max } from 'd3-array'
4
6
 
5
7
  const CHART_CONTEXT = 'chart-context'
6
8
 
@@ -61,22 +63,20 @@ function makeUpdateScales(data, innerDimensions) {
61
63
  return derived([data, innerDimensions], ([$data, $innerDimensions]) => {
62
64
  if (!$data || $data.length === 0) return null
63
65
 
64
- const xScale = d3
65
- .scaleBand()
66
+ const xScale = scaleBand()
66
67
  .domain($data.map((d) => d[xKey]))
67
68
  .range([0, $innerDimensions.width])
68
69
  .padding(0.2)
69
70
 
70
- const yScale = d3
71
- .scaleLinear()
72
- .domain([0, d3.max($data, (d) => d[yKey])])
71
+ const yScale = scaleLinear()
72
+ .domain([0, max($data, (d) => d[yKey])])
73
73
  .nice()
74
74
  .range([$innerDimensions.height, 0])
75
75
 
76
76
  let colorScale = null
77
77
  if (colorKey) {
78
78
  const uniqueCategories = [...new Set($data.map((d) => d[colorKey]))]
79
- colorScale = d3.scaleOrdinal().domain(uniqueCategories).range(d3.schemeCategory10)
79
+ colorScale = scaleOrdinal().domain(uniqueCategories).range(schemeCategory10)
80
80
  }
81
81
 
82
82
  return { xScale, yScale, colorScale }
@@ -17,7 +17,7 @@ export function keyboardNav(node, enabled) {
17
17
  const container = node.closest('[data-plot-geom]')
18
18
  if (!container) return
19
19
  const elements = [...container.querySelectorAll('[data-plot-element]')].filter(
20
- (el) => /** @type {HTMLElement|SVGElement} */ (el).tabIndex >= 0
20
+ (el) => el.tabIndex >= 0
21
21
  )
22
22
  const idx = elements.indexOf(node)
23
23
  if (idx === -1) return
@@ -25,7 +25,7 @@ export function keyboardNav(node, enabled) {
25
25
  e.key === 'ArrowRight' ? Math.min(idx + 1, elements.length - 1) : Math.max(idx - 1, 0)
26
26
  if (nextIdx !== idx) {
27
27
  e.preventDefault()
28
- /** @type {HTMLElement|SVGElement} */ (elements[nextIdx]).focus()
28
+ elements[nextIdx].focus()
29
29
  }
30
30
  }
31
31
  node.addEventListener('keydown', handleKeydown)