@rokkit/chart 1.0.2 → 1.0.4

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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/dist/Plot/index.d.ts +9 -0
  3. package/dist/PlotState.svelte.d.ts +84 -0
  4. package/dist/crossfilter/createCrossFilter.svelte.d.ts +13 -0
  5. package/dist/elements/index.d.ts +6 -0
  6. package/dist/geoms/lib/areas.d.ts +52 -0
  7. package/dist/geoms/lib/bars.d.ts +3 -0
  8. package/dist/index.d.ts +64 -0
  9. package/dist/lib/brewer.d.ts +9 -0
  10. package/dist/lib/brewing/BoxBrewer.svelte.d.ts +8 -0
  11. package/dist/lib/brewing/CartesianBrewer.svelte.d.ts +8 -0
  12. package/dist/lib/brewing/PieBrewer.svelte.d.ts +8 -0
  13. package/dist/lib/brewing/QuartileBrewer.svelte.d.ts +9 -0
  14. package/dist/lib/brewing/ViolinBrewer.svelte.d.ts +8 -0
  15. package/dist/lib/brewing/axes.svelte.d.ts +66 -0
  16. package/dist/lib/brewing/bars.svelte.d.ts +56 -0
  17. package/dist/lib/brewing/brewer.svelte.d.ts +114 -0
  18. package/dist/lib/brewing/colors.d.ts +66 -0
  19. package/dist/lib/brewing/dimensions.svelte.d.ts +35 -0
  20. package/dist/lib/brewing/index.svelte.d.ts +118 -0
  21. package/dist/lib/brewing/legends.svelte.d.ts +48 -0
  22. package/dist/lib/brewing/marks/arcs.d.ts +17 -0
  23. package/dist/lib/brewing/marks/areas.d.ts +31 -0
  24. package/dist/lib/brewing/marks/bars.d.ts +1 -0
  25. package/dist/lib/brewing/marks/boxes.d.ts +24 -0
  26. package/dist/lib/brewing/marks/lines.d.ts +24 -0
  27. package/dist/lib/brewing/marks/points.d.ts +55 -0
  28. package/dist/lib/brewing/marks/violins.d.ts +20 -0
  29. package/dist/lib/brewing/patterns.d.ts +14 -0
  30. package/dist/lib/brewing/scales.d.ts +28 -0
  31. package/dist/lib/brewing/scales.svelte.d.ts +24 -0
  32. package/dist/lib/brewing/stats.d.ts +23 -0
  33. package/dist/lib/brewing/symbols.d.ts +7 -0
  34. package/dist/lib/brewing/types.d.ts +162 -0
  35. package/dist/lib/chart.d.ts +38 -0
  36. package/dist/lib/context.d.ts +13 -0
  37. package/dist/lib/grid.d.ts +72 -0
  38. package/dist/lib/keyboard-nav.d.ts +15 -0
  39. package/dist/lib/plot/chartProps.d.ts +177 -0
  40. package/dist/lib/plot/crossfilter.d.ts +13 -0
  41. package/dist/lib/plot/facet.d.ts +24 -0
  42. package/dist/lib/plot/frames.d.ts +47 -0
  43. package/dist/lib/plot/helpers.d.ts +3 -0
  44. package/dist/lib/plot/preset.d.ts +29 -0
  45. package/dist/lib/plot/scales.d.ts +5 -0
  46. package/dist/lib/plot/stat.d.ts +32 -0
  47. package/dist/lib/plot/types.d.ts +89 -0
  48. package/dist/lib/preset.d.ts +30 -0
  49. package/dist/lib/scales.svelte.d.ts +35 -0
  50. package/dist/lib/swatch.d.ts +12 -0
  51. package/dist/lib/ticks.d.ts +36 -0
  52. package/dist/lib/utils.d.ts +61 -0
  53. package/dist/lib/xscale.d.ts +11 -0
  54. package/dist/patterns/index.d.ts +4 -0
  55. package/dist/patterns/patterns.d.ts +72 -0
  56. package/dist/patterns/scale.d.ts +30 -0
  57. package/dist/symbols/constants/index.d.ts +1 -0
  58. package/dist/symbols/index.d.ts +5 -0
  59. package/package.json +1 -1
  60. package/src/ChartExporter.svelte +1 -0
  61. package/src/PlotState.svelte.js +1 -0
  62. package/src/crossfilter/FilterHistogram.svelte +3 -3
  63. package/src/geoms/Hexbin.svelte +2 -0
  64. package/src/geoms/Ribbon.svelte +6 -0
  65. package/src/geoms/Waterfall.svelte +1 -0
  66. package/src/lib/keyboard-nav.js +1 -0
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Creates appropriate scales based on data and dimensions
3
+ *
4
+ * @param {Array} data The dataset
5
+ * @param {Object} dimensions Chart dimensions
6
+ * @param {Object} [options] Additional options
7
+ * @param {string} options.xKey Field to use for x-axis
8
+ * @param {string} options.yKey Field to use for y-axis
9
+ * @param {string} [options.colorKey] Field to use for color mapping
10
+ * @returns {Object} Object containing xScale, yScale, and colorScale
11
+ */
12
+ export function createScales(data: any[], dimensions: Object, options?: {
13
+ xKey: string;
14
+ yKey: string;
15
+ colorKey?: string | undefined;
16
+ }): Object;
17
+ /**
18
+ * Calculates the actual chart dimensions after applying margins
19
+ *
20
+ * @param {Object} dimensions Original dimensions
21
+ * @returns {Object} Dimensions with calculated inner width and height
22
+ */
23
+ export function calculateChartDimensions(dimensions: Object): Object;
24
+ /**
25
+ * Normalizes data for use with D3 charts
26
+ *
27
+ * @param {Array|Object} inputData Raw data or dataset object
28
+ * @returns {Array} Normalized data array
29
+ */
30
+ export function normalizeData(inputData: any[] | Object): any[];
31
+ /**
32
+ * Generates a unique ID for SVG elements
33
+ *
34
+ * @param {string} prefix Prefix for the ID
35
+ * @returns {string} A unique ID
36
+ */
37
+ export function uniqueId(prefix?: string): string;
38
+ /**
39
+ * Formats tooltip content for a data point
40
+ *
41
+ * @param {Object} d Data point
42
+ * @param {Object} options Tooltip format options
43
+ * @returns {string} Formatted tooltip HTML content
44
+ */
45
+ export function formatTooltipContent(d: Object, options?: Object): string;
46
+ /**
47
+ * Generates a tooltip formatter function
48
+ *
49
+ * @param {Object} options Tooltip format options
50
+ * @returns {Function} A function that formats tooltip content
51
+ */
52
+ export function createTooltipFormatter(options?: Object): Function;
53
+ /**
54
+ * Calculates the transform attribute for SVG elements
55
+ *
56
+ * @param {number} x X position
57
+ * @param {number} y Y position
58
+ * @returns {string} Transform attribute value
59
+ */
60
+ export function transform(x: number, y: number): string;
61
+ export function scaledPathCollection(paths: any): {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Builds an appropriate D3 x-axis scale based on value types.
3
+ * Returns scaleTime for Date values, scaleLinear for numeric values,
4
+ * or scaleBand for categorical values.
5
+ *
6
+ * @param {Array} xValues
7
+ * @param {Object} dimensions
8
+ * @param {number} padding
9
+ * @returns {import('d3-scale').ScaleContinuousNumeric|import('d3-scale').ScaleBand}
10
+ */
11
+ export function buildXScale(xValues: any[], dimensions: Object, padding: number): any | any;
@@ -0,0 +1,4 @@
1
+ export { default as PatternDef } from "./PatternDef.svelte";
2
+ export { default as DefinePatterns } from "./DefinePatterns.svelte";
3
+ export { PATTERNS } from "./patterns.js";
4
+ export { scaleMark, resolveMarkAttrs } from "./scale.js";
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Unified pattern library.
3
+ *
4
+ * Each entry is an array of mark descriptors. All geometry is in normalized
5
+ * 0–1 coordinates; the renderer scales by `size` at paint time.
6
+ *
7
+ * Mark types
8
+ * ----------
9
+ * circle { cx, cy, r }
10
+ * line { x1, y1, x2, y2 } coordinates may exceed 0–1 for seamless tiling
11
+ * polygon { points: [x,y][] }
12
+ * rect { x, y, w, h }
13
+ * path { d: [cmd, ...args][] } SVG path commands as nested arrays (H/V take one arg)
14
+ *
15
+ * Appearance
16
+ * ----------
17
+ * fill: true → element uses fill color (stroke: none)
18
+ * fill: false → element uses stroke color (fill: none) ← default
19
+ * fillOpacity: n → applied as fill-opacity on filled marks
20
+ * opacity: n → applied as opacity on any mark
21
+ */
22
+ /** @typedef {{ type: 'circle', cx: number, cy: number, r: number, fill?: boolean, fillOpacity?: number, opacity?: number }} CircleMark */
23
+ /** @typedef {{ type: 'line', x1: number, y1: number, x2: number, y2: number, fill?: false, strokeWidth?: number }} LineMark */
24
+ /** @typedef {{ type: 'polygon', points: [number,number][], fill?: boolean, fillOpacity?: number, opacity?: number }} PolygonMark */
25
+ /** @typedef {{ type: 'rect', x: number, y: number, w: number, h: number, fill?: boolean, fillOpacity?: number, opacity?: number }} RectMark */
26
+ /** @typedef {{ type: 'path', d: (string|number)[][], fill?: boolean, fillOpacity?: number, opacity?: number }} PathMark */
27
+ /** @typedef {CircleMark | LineMark | PolygonMark | RectMark | PathMark} PatternMark */
28
+ /** @type {Record<string, PatternMark[]>} */
29
+ export const PATTERNS: Record<string, PatternMark[]>;
30
+ export type CircleMark = {
31
+ type: "circle";
32
+ cx: number;
33
+ cy: number;
34
+ r: number;
35
+ fill?: boolean;
36
+ fillOpacity?: number;
37
+ opacity?: number;
38
+ };
39
+ export type LineMark = {
40
+ type: "line";
41
+ x1: number;
42
+ y1: number;
43
+ x2: number;
44
+ y2: number;
45
+ fill?: false;
46
+ strokeWidth?: number;
47
+ };
48
+ export type PolygonMark = {
49
+ type: "polygon";
50
+ points: [number, number][];
51
+ fill?: boolean;
52
+ fillOpacity?: number;
53
+ opacity?: number;
54
+ };
55
+ export type RectMark = {
56
+ type: "rect";
57
+ x: number;
58
+ y: number;
59
+ w: number;
60
+ h: number;
61
+ fill?: boolean;
62
+ fillOpacity?: number;
63
+ opacity?: number;
64
+ };
65
+ export type PathMark = {
66
+ type: "path";
67
+ d: (string | number)[][];
68
+ fill?: boolean;
69
+ fillOpacity?: number;
70
+ opacity?: number;
71
+ };
72
+ export type PatternMark = CircleMark | LineMark | PolygonMark | RectMark | PathMark;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Scale all geometric coordinates in a mark by `size`.
3
+ * Renames rect `w`/`h` to `width`/`height` and converts polygon/path to strings.
4
+ * @param {PatternMark} mark
5
+ * @param {number} size
6
+ * @returns {object}
7
+ */
8
+ export function scaleMark(mark: PatternMark, size: number): object;
9
+ /**
10
+ * Resolve a scaled mark into SVG-ready `{ type, attrs }`.
11
+ * `attrs` can be spread directly onto the SVG element.
12
+ *
13
+ * Per-mark overrides respected:
14
+ * mark.strokeWidth → `stroke-width` (takes precedence over `thickness`)
15
+ * mark.fillOpacity → `fill-opacity`
16
+ * mark.opacity → `opacity`
17
+ *
18
+ * @param {object} scaledMark Output of scaleMark
19
+ * @param {{ fill: string, stroke: string, thickness: number }} appearance
20
+ * @returns {{ type: string, attrs: object }}
21
+ */
22
+ export function resolveMarkAttrs(scaledMark: object, { fill, stroke, thickness }: {
23
+ fill: string;
24
+ stroke: string;
25
+ thickness: number;
26
+ }): {
27
+ type: string;
28
+ attrs: object;
29
+ };
30
+ import type { PatternMark } from './patterns.js';
@@ -0,0 +1 @@
1
+ export const namedShapes: {};
@@ -0,0 +1,5 @@
1
+ export const shapes: string[];
2
+ export const components: {
3
+ default: import("svelte/legacy").LegacyComponentType;
4
+ 'rounded-square': import("svelte/legacy").LegacyComponentType;
5
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/chart",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "description": "Data-driven chart components",
6
6
  "repository": {
@@ -26,6 +26,7 @@
26
26
  * @param {SVGSVGElement} svg
27
27
  * @returns {SVGSVGElement}
28
28
  */
29
+ // eslint-disable-next-line complexity
29
30
  function inlineStyles(svg) {
30
31
  const clone = /** @type {SVGSVGElement} */ (svg.cloneNode(true))
31
32
  const computed = getComputedStyle(svg)
@@ -191,6 +191,7 @@ export class PlotState {
191
191
  // use it instead of deriving distinct values from the local panel data.
192
192
  colors = $derived.by(() => {
193
193
  const field = this.#effectiveChannels.color
194
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
194
195
  if (isLiteralColor(field)) return new Map([[null, { fill: field, stroke: field }]])
195
196
  const values = this.#colorDomain ?? distinct(this.#data, field)
196
197
  // No color channel but data exists → use first preset color for single-series rendering.
@@ -149,7 +149,7 @@
149
149
  >
150
150
  <g transform="translate({margin.left},{margin.top})">
151
151
  <!-- Y axis ticks -->
152
- {#each yTicks as tick}
152
+ {#each yTicks as tick (tick)}
153
153
  <line
154
154
  x1={0}
155
155
  x2={innerWidth}
@@ -181,7 +181,7 @@
181
181
  />
182
182
 
183
183
  <!-- X axis ticks -->
184
- {#each xTicks as tick}
184
+ {#each xTicks as tick (tick)}
185
185
  <text
186
186
  x={xScale(tick)}
187
187
  y={innerHeight + 12}
@@ -193,7 +193,7 @@
193
193
  {/each}
194
194
 
195
195
  <!-- Bars -->
196
- {#each binned as b}
196
+ {#each binned as b (b.x0)}
197
197
  {@const bx = xScale(b.x0) + 1}
198
198
  {@const bw = Math.max(0, xScale(b.x1) - xScale(b.x0) - 1)}
199
199
  {@const by = yScale(b.length)}
@@ -40,9 +40,11 @@
40
40
  const continuousColor = $derived(plotState.continuousColorScale)
41
41
 
42
42
  // Hex binning: group data points into hexagonal cells
43
+ // eslint-disable-next-line max-params, complexity
43
44
  function hexBin(data, xField, yField, xScale, yScale, r) {
44
45
  const dx = r * 2 * Math.sin(Math.PI / 3) // horizontal spacing
45
46
  const dy = r * 1.5 // vertical spacing
47
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
46
48
  const bins = new Map()
47
49
 
48
50
  for (const d of data) {
@@ -43,6 +43,7 @@
43
43
  const innerWidth = $derived(plotState.innerWidth)
44
44
 
45
45
  // Compute Sankey-style layout
46
+ // eslint-disable-next-line max-lines-per-function, complexity
46
47
  const ribbons = $derived.by(() => {
47
48
  if (!data?.length) return { links: [], sourceNodes: [], targetNodes: [] }
48
49
 
@@ -55,7 +56,9 @@
55
56
  }))
56
57
 
57
58
  // Compute node positions
59
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
58
60
  const sourceMap = new Map()
61
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
59
62
  const targetMap = new Map()
60
63
  for (const f of flows) {
61
64
  sourceMap.set(f.source, (sourceMap.get(f.source) ?? 0) + f.value)
@@ -86,11 +89,14 @@
86
89
  }
87
90
 
88
91
  // Build ribbon paths
92
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
89
93
  const sourceOffsets = new Map(sourceNodes.map((n) => [n.name, n.y]))
94
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
90
95
  const targetOffsets = new Map(targetNodes.map((n) => [n.name, n.y]))
91
96
  const x0 = 0
92
97
  const x1 = innerWidth
93
98
 
99
+ // eslint-disable-next-line complexity
94
100
  const links = flows.map((f, i) => {
95
101
  const sy0 = sourceOffsets.get(f.source) ?? 0
96
102
  const ty0 = targetOffsets.get(f.target) ?? 0
@@ -42,6 +42,7 @@
42
42
  const xScale = $derived(plotState.xScale)
43
43
  const yScale = $derived(plotState.yScale)
44
44
 
45
+ // eslint-disable-next-line max-lines-per-function
45
46
  const bars = $derived.by(() => {
46
47
  if (!data?.length || !xScale || !yScale) return []
47
48
  const bw = typeof xScale.bandwidth === 'function' ? xScale.bandwidth() : 10
@@ -10,6 +10,7 @@
10
10
  * @param {boolean} enabled
11
11
  */
12
12
  export function keyboardNav(node, enabled) {
13
+ // eslint-disable-next-line complexity
13
14
  function handleKeydown(e) {
14
15
  if (!enabled) return
15
16
  if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return