@internetstiftelsen/charts 0.9.0 → 0.9.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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -0
  3. package/{area.d.ts → dist/area.d.ts} +1 -1
  4. package/{bar.d.ts → dist/bar.d.ts} +3 -4
  5. package/{bar.js → dist/bar.js} +3 -11
  6. package/{base-chart.d.ts → dist/base-chart.d.ts} +30 -18
  7. package/{base-chart.js → dist/base-chart.js} +170 -50
  8. package/dist/chart-interface.d.ts +19 -0
  9. package/{donut-center-content.d.ts → dist/donut-center-content.d.ts} +1 -1
  10. package/{donut-chart.d.ts → dist/donut-chart.d.ts} +19 -4
  11. package/{donut-chart.js → dist/donut-chart.js} +140 -2
  12. package/{gauge-chart.d.ts → dist/gauge-chart.d.ts} +2 -2
  13. package/{gauge-chart.js → dist/gauge-chart.js} +2 -0
  14. package/{grid.d.ts → dist/grid.d.ts} +1 -1
  15. package/{layout-manager.d.ts → dist/layout-manager.d.ts} +5 -5
  16. package/{legend.d.ts → dist/legend.d.ts} +3 -1
  17. package/{legend.js → dist/legend.js} +32 -0
  18. package/{line.d.ts → dist/line.d.ts} +1 -1
  19. package/{pie-chart.d.ts → dist/pie-chart.d.ts} +4 -11
  20. package/{pie-chart.js → dist/pie-chart.js} +23 -21
  21. package/{radial-chart-base.js → dist/radial-chart-base.js} +3 -1
  22. package/{theme.d.ts → dist/theme.d.ts} +2 -0
  23. package/{theme.js → dist/theme.js} +24 -29
  24. package/{title.d.ts → dist/title.d.ts} +1 -1
  25. package/{tooltip.d.ts → dist/tooltip.d.ts} +1 -1
  26. package/{tooltip.js → dist/tooltip.js} +239 -74
  27. package/{types.d.ts → dist/types.d.ts} +27 -10
  28. package/{utils.d.ts → dist/utils.d.ts} +0 -2
  29. package/{utils.js → dist/utils.js} +0 -5
  30. package/{word-cloud-chart.d.ts → dist/word-cloud-chart.d.ts} +1 -1
  31. package/{word-cloud-chart.js → dist/word-cloud-chart.js} +2 -0
  32. package/{x-axis.d.ts → dist/x-axis.d.ts} +2 -1
  33. package/{x-axis.js → dist/x-axis.js} +18 -14
  34. package/{xy-chart.d.ts → dist/xy-chart.d.ts} +8 -5
  35. package/{xy-chart.js → dist/xy-chart.js} +31 -5
  36. package/{y-axis.d.ts → dist/y-axis.d.ts} +1 -1
  37. package/{y-axis.js → dist/y-axis.js} +4 -4
  38. package/package.json +38 -36
  39. package/chart-interface.d.ts +0 -13
  40. /package/{area.js → dist/area.js} +0 -0
  41. /package/{chart-interface.js → dist/chart-interface.js} +0 -0
  42. /package/{donut-center-content.js → dist/donut-center-content.js} +0 -0
  43. /package/{export-image.d.ts → dist/export-image.d.ts} +0 -0
  44. /package/{export-image.js → dist/export-image.js} +0 -0
  45. /package/{export-pdf.d.ts → dist/export-pdf.d.ts} +0 -0
  46. /package/{export-pdf.js → dist/export-pdf.js} +0 -0
  47. /package/{export-tabular.d.ts → dist/export-tabular.d.ts} +0 -0
  48. /package/{export-tabular.js → dist/export-tabular.js} +0 -0
  49. /package/{export-xlsx.d.ts → dist/export-xlsx.d.ts} +0 -0
  50. /package/{export-xlsx.js → dist/export-xlsx.js} +0 -0
  51. /package/{grid.js → dist/grid.js} +0 -0
  52. /package/{grouped-data.d.ts → dist/grouped-data.d.ts} +0 -0
  53. /package/{grouped-data.js → dist/grouped-data.js} +0 -0
  54. /package/{grouped-tabular.d.ts → dist/grouped-tabular.d.ts} +0 -0
  55. /package/{grouped-tabular.js → dist/grouped-tabular.js} +0 -0
  56. /package/{layout-manager.js → dist/layout-manager.js} +0 -0
  57. /package/{line.js → dist/line.js} +0 -0
  58. /package/{radial-chart-base.d.ts → dist/radial-chart-base.d.ts} +0 -0
  59. /package/{scale-utils.d.ts → dist/scale-utils.d.ts} +0 -0
  60. /package/{scale-utils.js → dist/scale-utils.js} +0 -0
  61. /package/{title.js → dist/title.js} +0 -0
  62. /package/{types.js → dist/types.js} +0 -0
  63. /package/{validation.d.ts → dist/validation.d.ts} +0 -0
  64. /package/{validation.js → dist/validation.js} +0 -0
@@ -2,6 +2,7 @@ import { max, min, scaleBand, scaleLinear, scaleLog, scaleTime, } from 'd3';
2
2
  import { BaseChart, } from './base-chart.js';
3
3
  import { ChartValidator } from './validation.js';
4
4
  import { GROUPED_GAP_TICK_PREFIX, GROUPED_GROUP_LABEL_KEY, } from './grouped-data.js';
5
+ import { resolveScaleValue } from './scale-utils.js';
5
6
  const DEFAULT_SERIES_COLOR = '#8884d8';
6
7
  function isXYSeries(component) {
7
8
  return (component.type === 'line' ||
@@ -41,6 +42,13 @@ export class XYChart extends BaseChart {
41
42
  writable: true,
42
43
  value: void 0
43
44
  });
45
+ Object.defineProperty(this, "orientation", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: void 0
50
+ });
51
+ this.orientation = config.orientation ?? 'vertical';
44
52
  this.barStackMode = config.barStack?.mode ?? 'normal';
45
53
  this.barStackGap = config.barStack?.gap ?? 0.1;
46
54
  this.barStackReverseSeries = config.barStack?.reverseSeries ?? false;
@@ -71,9 +79,12 @@ export class XYChart extends BaseChart {
71
79
  createExportChart() {
72
80
  return new XYChart({
73
81
  data: this.data,
82
+ width: this.configuredWidth,
83
+ height: this.configuredHeight,
74
84
  theme: this.theme,
75
85
  scales: this.scaleConfig,
76
86
  responsive: this.responsiveConfig,
87
+ orientation: this.orientation,
77
88
  barStack: {
78
89
  mode: this.barStackMode,
79
90
  gap: this.barStackGap,
@@ -108,6 +119,7 @@ export class XYChart extends BaseChart {
108
119
  }
109
120
  }
110
121
  renderChart({ svg, plotGroup, plotArea, }) {
122
+ this.validateSeriesOrientation();
111
123
  this.series.forEach((series) => {
112
124
  const typeName = series.type === 'line'
113
125
  ? 'Line'
@@ -241,7 +253,7 @@ export class XYChart extends BaseChart {
241
253
  }
242
254
  setupScales() {
243
255
  const xKey = this.getXKey();
244
- const isHorizontal = this.isHorizontalOrientation();
256
+ const isHorizontal = this.orientation === 'horizontal';
245
257
  let xConfig;
246
258
  let yConfig;
247
259
  if (isHorizontal) {
@@ -256,7 +268,21 @@ export class XYChart extends BaseChart {
256
268
  this.y = this.createScale(yConfig, isHorizontal ? xKey : null, 'y');
257
269
  }
258
270
  isHorizontalOrientation() {
259
- return this.series.some((s) => s.type === 'bar' && s.orientation === 'horizontal');
271
+ return this.orientation === 'horizontal';
272
+ }
273
+ validateSeriesOrientation() {
274
+ if (this.orientation !== 'horizontal') {
275
+ return;
276
+ }
277
+ const hasLineSeries = this.series.some((series) => {
278
+ return series.type === 'line';
279
+ });
280
+ const hasAreaSeries = this.series.some((series) => {
281
+ return series.type === 'area';
282
+ });
283
+ if (hasLineSeries || hasAreaSeries) {
284
+ throw new Error('XYChart: horizontal orientation currently supports Bar series only');
285
+ }
260
286
  }
261
287
  collectSeriesValues(series) {
262
288
  const values = [];
@@ -340,8 +366,8 @@ export class XYChart extends BaseChart {
340
366
  }
341
367
  else if (scaleType === 'time' && dataKey) {
342
368
  domain = [
343
- min(this.data, (d) => new Date(d[dataKey])),
344
- max(this.data, (d) => new Date(d[dataKey])),
369
+ min(this.data, (d) => resolveScaleValue(d[dataKey], 'time')),
370
+ max(this.data, (d) => resolveScaleValue(d[dataKey], 'time')),
345
371
  ];
346
372
  }
347
373
  else if ((scaleType === 'linear' || scaleType === 'log') && dataKey) {
@@ -506,7 +532,7 @@ export class XYChart extends BaseChart {
506
532
  gap: this.barStackGap,
507
533
  nextLayerData,
508
534
  };
509
- series.render(this.plotGroup, this.data, xKey, this.x, this.y, this.parseValue, categoryScaleType, this.renderTheme, stackingContext);
535
+ series.render(this.plotGroup, this.data, xKey, this.x, this.y, this.parseValue, categoryScaleType, this.renderTheme, stackingContext, this.orientation);
510
536
  });
511
537
  areaSeries.forEach((series) => {
512
538
  series.render(this.plotGroup, this.data, xKey, this.x, this.y, this.parseValue, categoryScaleType, this.renderTheme, areaStackingContextBySeries.get(series), areaValueLabelLayer ?? undefined);
@@ -13,7 +13,7 @@ export declare class YAxis implements LayoutAwareComponent<YAxisConfigBase> {
13
13
  readonly exportHooks?: ExportHooks<YAxisConfigBase>;
14
14
  constructor(config?: YAxisConfig);
15
15
  getExportConfig(): YAxisConfigBase;
16
- createExportComponent(override?: Partial<YAxisConfigBase>): LayoutAwareComponent;
16
+ createExportComponent(override?: Partial<YAxisConfigBase>): LayoutAwareComponent<YAxisConfigBase>;
17
17
  /**
18
18
  * Returns the space required by the y-axis
19
19
  */
@@ -32,7 +32,6 @@ export class YAxis {
32
32
  writable: true,
33
33
  value: void 0
34
34
  });
35
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
35
  Object.defineProperty(this, "tickFormat", {
37
36
  enumerable: true,
38
37
  configurable: true,
@@ -108,11 +107,12 @@ export class YAxis {
108
107
  const axis = axisLeft(y).tickSize(0).tickPadding(this.tickPadding);
109
108
  // Apply tick formatting if specified
110
109
  if (this.tickFormat) {
111
- if (typeof this.tickFormat === 'function') {
112
- axis.ticks(5).tickFormat(this.tickFormat);
110
+ const tickFormat = this.tickFormat;
111
+ if (typeof tickFormat === 'function') {
112
+ axis.ticks(5).tickFormat((value) => tickFormat(value));
113
113
  }
114
114
  else {
115
- axis.ticks(5, this.tickFormat);
115
+ axis.ticks(5, tickFormat);
116
116
  }
117
117
  }
118
118
  else {
package/package.json CHANGED
@@ -1,23 +1,24 @@
1
1
  {
2
- "version": "0.9.0",
2
+ "version": "0.9.1",
3
3
  "name": "@internetstiftelsen/charts",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": {
7
7
  "./*": {
8
- "types": "./*.d.ts",
9
- "import": "./*.js"
10
- }
8
+ "types": "./dist/*.d.ts",
9
+ "import": "./dist/*.js"
10
+ },
11
+ "./package.json": "./package.json"
11
12
  },
12
13
  "files": [
13
- "*.js",
14
- "*.d.ts",
15
- "README.md"
14
+ "dist",
15
+ "README.md",
16
+ "LICENSE"
16
17
  ],
17
18
  "scripts": {
18
19
  "dev": "vite",
19
20
  "dev:docs": "vite --config vite.docs.config.ts --open",
20
- "build": "tsc --project tsconfig.lib.json && tsc-alias --project tsconfig.lib.json",
21
+ "build": "rm -rf dist && tsc --project tsconfig.lib.json && tsc-alias --project tsconfig.lib.json",
21
22
  "build:demo": "tsc -b && vite build",
22
23
  "build:docs": "vite build --config vite.docs.config.ts && cp -R docs dist-docs/docs",
23
24
  "lint": "eslint .",
@@ -26,57 +27,58 @@
26
27
  "preview:docs": "vite preview --config vite.docs.config.ts",
27
28
  "test": "vitest",
28
29
  "test:run": "vitest run",
30
+ "verify": "pnpm lint && pnpm test:run && pnpm build",
29
31
  "build:lib": "npm run build",
30
- "prepub": "rm -rf dist && npm run build:lib && cp package.json dist && cp README.md dist",
31
- "pub": "npm run prepub && cd dist && npm publish --access public"
32
+ "prepublishOnly": "pnpm verify",
33
+ "pub": "npm publish --access public"
32
34
  },
33
35
  "dependencies": {
34
- "@handsontable/react-wrapper": "^16.2.0",
35
- "@radix-ui/react-label": "^2.1.8",
36
- "@radix-ui/react-select": "^2.2.6",
37
- "@radix-ui/react-switch": "^1.2.6",
38
- "@radix-ui/react-tabs": "^1.1.13",
39
- "@types/d3": "^7.4.3",
40
- "class-variance-authority": "^0.7.1",
41
- "clsx": "^2.1.1",
42
36
  "d3": "^7.9.0",
43
- "d3-cloud": "^1.2.9",
44
- "handsontable": "^16.2.0",
45
- "lucide-react": "^0.548.0",
46
- "react": "^19.2.4",
47
- "react-dom": "^19.2.4",
48
- "tailwind-merge": "^3.4.0",
49
- "tailwindcss": "^4.1.18"
37
+ "d3-cloud": "^1.2.9"
50
38
  },
51
39
  "optionalDependencies": {
52
- "jspdf": "^4.1.0",
40
+ "jspdf": "^4.2.1",
53
41
  "xlsx": "^0.18.5"
54
42
  },
55
43
  "devDependencies": {
56
- "@eslint/js": "^9.39.2",
57
- "@internetstiftelsen/styleguide": "^5.1.23",
58
- "@speed-highlight/core": "^1.2.14",
59
- "@tailwindcss/vite": "^4.1.18",
44
+ "@eslint/js": "^9.39.4",
45
+ "@handsontable/react-wrapper": "^16.2.0",
46
+ "@internetstiftelsen/styleguide": "^5.1.24",
47
+ "@radix-ui/react-label": "^2.1.8",
48
+ "@radix-ui/react-select": "^2.2.6",
49
+ "@radix-ui/react-switch": "^1.2.6",
50
+ "@radix-ui/react-tabs": "^1.1.13",
51
+ "@speed-highlight/core": "^1.2.15",
52
+ "@tailwindcss/vite": "^4.2.2",
60
53
  "@testing-library/dom": "^10.4.1",
61
54
  "@testing-library/jest-dom": "^6.9.1",
62
55
  "@testing-library/react": "^16.3.2",
56
+ "@types/d3": "^7.4.3",
63
57
  "@types/d3-cloud": "^1.2.9",
64
- "@types/node": "^24.10.13",
58
+ "@types/node": "^24.12.0",
65
59
  "@types/react": "^19.2.14",
66
60
  "@types/react-dom": "^19.2.3",
67
- "@vitejs/plugin-react-swc": "^4.2.3",
68
- "eslint": "^9.39.2",
61
+ "@vitejs/plugin-react-swc": "^4.3.0",
62
+ "class-variance-authority": "^0.7.1",
63
+ "clsx": "^2.1.1",
64
+ "eslint": "^9.39.4",
69
65
  "eslint-plugin-react-hooks": "^7.0.1",
70
66
  "eslint-plugin-react-refresh": "^0.4.26",
71
67
  "globals": "^16.5.0",
68
+ "handsontable": "^16.2.0",
72
69
  "jsdom": "^27.4.0",
70
+ "lucide-react": "^0.548.0",
73
71
  "prettier": "3.6.2",
74
- "sass": "^1.97.3",
72
+ "react": "^19.2.4",
73
+ "react-dom": "^19.2.4",
74
+ "sass": "^1.98.0",
75
+ "tailwind-merge": "^3.5.0",
76
+ "tailwindcss": "^4.2.2",
75
77
  "tsc-alias": "^1.8.16",
76
78
  "tw-animate-css": "^1.4.0",
77
79
  "typescript": "~5.9.3",
78
- "typescript-eslint": "^8.55.0",
80
+ "typescript-eslint": "^8.57.1",
79
81
  "vite": "^7.3.1",
80
- "vitest": "^4.0.18"
82
+ "vitest": "^4.1.0"
81
83
  }
82
84
  }
@@ -1,13 +0,0 @@
1
- import type { ExportHooks } from './types.js';
2
- export interface ChartComponent<TConfig = any> {
3
- type: 'line' | 'area' | 'bar' | 'xAxis' | 'yAxis' | 'grid' | 'tooltip' | 'legend' | 'title' | 'donutCenterContent';
4
- exportHooks?: ExportHooks<TConfig>;
5
- }
6
- export type ComponentSpace = {
7
- width: number;
8
- height: number;
9
- position: 'top' | 'bottom' | 'left' | 'right';
10
- };
11
- export interface LayoutAwareComponent<TConfig = any> extends ChartComponent<TConfig> {
12
- getRequiredSpace(): ComponentSpace;
13
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes