@automattic/charts 0.1.0 → 0.2.0

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/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.2.0] - 2024-12-31
9
+ ### Added
10
+ - Charts: adds grid component to charts [#40683]
11
+
12
+ ### Fixed
13
+ - Fixing incorrect TS build. [#40761]
14
+
8
15
  ## 0.1.0 - 2024-12-20
9
16
  ### Added
10
17
  - Adding a theme provider to Automattic Charts [#40558]
@@ -25,3 +32,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
25
32
  ### Fixed
26
33
  - Fixed lints following ESLint rule changes for TS [#40584]
27
34
  - Fixing a bug in Chart storybook data. [#40640]
35
+
36
+ [0.2.0]: https://github.com/Automattic/charts/compare/v0.1.0...v0.2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/charts",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Display charts within Automattic products.",
5
5
  "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/charts/#readme",
6
6
  "bugs": {
@@ -20,33 +20,41 @@
20
20
  "storybook": "cd ../storybook && pnpm run storybook:dev",
21
21
  "compile-ts": "tsc --pretty",
22
22
  "build": "pnpm run clean-build && pnpm run compile-ts",
23
- "clean-build": "rm -rf build/"
23
+ "build:prod": "tsup src/index.ts --minify --dts",
24
+ "clean-build": "rm -rf dist/"
24
25
  },
25
26
  "dependencies": {
26
27
  "@react-spring/web": "9.7.3",
27
- "@visx/responsive": "3.12.0",
28
28
  "@visx/axis": "^3.12.0",
29
+ "@visx/event": "^3.8.0",
30
+ "@visx/grid": "^3.12.0",
29
31
  "@visx/group": "^3.12.0",
30
32
  "@visx/legend": "^3.12.0",
33
+ "@visx/responsive": "3.12.0",
31
34
  "@visx/scale": "^3.12.0",
32
35
  "@visx/shape": "^3.12.0",
33
36
  "@visx/text": "3.12.0",
34
- "@visx/xychart": "3.12.0",
35
- "clsx": "2.1.1",
36
37
  "@visx/tooltip": "^3.8.0",
37
- "@visx/event": "^3.8.0"
38
+ "@visx/xychart": "3.12.0",
39
+ "clsx": "2.1.1"
38
40
  },
39
41
  "devDependencies": {
40
42
  "@storybook/blocks": "8.4.6",
41
43
  "@storybook/react": "8.4.6",
42
44
  "@types/react": "18.3.13",
43
45
  "@types/react-dom": "18.3.1",
46
+ "esbuild": "0.24.2",
47
+ "esbuild-sass-plugin": "3.3.1",
44
48
  "jest": "29.7.0",
45
49
  "jest-environment-jsdom": "29.7.0",
46
50
  "jest-extended": "4.0.2",
51
+ "postcss": "8.4.47",
52
+ "postcss-modules": "6.0.1",
47
53
  "react": "18.3.1",
48
54
  "react-dom": "18.3.1",
55
+ "sass-embedded": "1.83.0",
49
56
  "storybook": "8.4.6",
57
+ "tsup": "8.3.5",
50
58
  "typescript": "5.7.2"
51
59
  },
52
60
  "peerDependencies": {
@@ -54,10 +62,11 @@
54
62
  "react-dom": "^17.0.0 || ^18.0.0"
55
63
  },
56
64
  "exports": {
57
- ".": "./src/index.ts",
58
- "./state": "./src/state",
59
- "./action-types": "./src/state/action-types",
60
- "./bar": "./src/components/bar-chart/index.ts",
61
- "./tooltip": "./src/components/tooltip/index.ts"
62
- }
65
+ ".": {
66
+ "types": "./dist/index.d.ts",
67
+ "default": "./dist/index.js"
68
+ }
69
+ },
70
+ "main": "./dist/index.js",
71
+ "types": "./dist/index.d.ts"
63
72
  }
@@ -7,6 +7,7 @@ import { useTooltip } from '@visx/tooltip';
7
7
  import clsx from 'clsx';
8
8
  import { FC, useCallback, type MouseEvent } from 'react';
9
9
  import { useChartTheme } from '../../providers/theme';
10
+ import { GridControl } from '../grid-control';
10
11
  import { Legend } from '../legend';
11
12
  import { BaseTooltip } from '../tooltip';
12
13
  import styles from './bar-chart.module.scss';
@@ -25,6 +26,7 @@ const BarChart: FC< BarChartProps > = ( {
25
26
  showLegend = false,
26
27
  legendOrientation = 'horizontal',
27
28
  className,
29
+ gridVisibility = 'x',
28
30
  } ) => {
29
31
  const theme = useChartTheme();
30
32
  const { tooltipOpen, tooltipLeft, tooltipTop, tooltipData, hideTooltip, showTooltip } =
@@ -97,6 +99,13 @@ const BarChart: FC< BarChartProps > = ( {
97
99
  <div className={ clsx( 'bar-chart', className, styles[ 'bar-chart' ] ) }>
98
100
  <svg width={ width } height={ height }>
99
101
  <Group left={ margins.left } top={ margins.top }>
102
+ <GridControl
103
+ width={ xMax }
104
+ height={ yMax }
105
+ xScale={ xScale }
106
+ yScale={ yScale }
107
+ gridVisibility={ gridVisibility }
108
+ />
100
109
  { data.map( ( series, seriesIndex ) => (
101
110
  <Group key={ seriesIndex }>
102
111
  { series.data.map( d => {
@@ -0,0 +1,10 @@
1
+ // Variables
2
+ $grid-line-color: #d7d6d6;
3
+
4
+ .grid-control {
5
+ :global(.visx-line) {
6
+ stroke: $grid-line-color;
7
+ stroke-width: 1px;
8
+ shape-rendering: crispEdges;
9
+ }
10
+ }
@@ -0,0 +1,22 @@
1
+ import { GridRows, GridColumns } from '@visx/grid';
2
+ import React from 'react';
3
+ import styles from './grid-control.module.scss';
4
+ import type { GridProps } from '../shared/types';
5
+
6
+ const GridControl: React.FC< GridProps > = ( {
7
+ width,
8
+ height,
9
+ xScale,
10
+ yScale,
11
+ gridVisibility = 'x',
12
+ top = 0,
13
+ } ) => {
14
+ return (
15
+ <g transform={ `translate(0, ${ top })` } className={ styles[ 'grid-control' ] }>
16
+ { gridVisibility.includes( 'x' ) && <GridRows scale={ xScale } width={ width } /> }
17
+ { gridVisibility.includes( 'y' ) && <GridColumns scale={ yScale } height={ height } /> }
18
+ </g>
19
+ );
20
+ };
21
+
22
+ export default GridControl;
@@ -0,0 +1 @@
1
+ export { default as GridControl } from './grid-control';
@@ -106,4 +106,42 @@ export type BaseChartProps< T = DataPoint | DataPointDate > = {
106
106
  * Legend orientation
107
107
  */
108
108
  legendOrientation?: 'horizontal' | 'vertical';
109
+ /**
110
+ * Grid visibility. x is default.
111
+ */
112
+ gridVisibility?: 'x' | 'y' | 'xy' | 'none';
113
+ };
114
+
115
+ /**
116
+ * Properties for grid components
117
+ */
118
+ export type GridProps = {
119
+ /**
120
+ * Width of the grid in pixels
121
+ */
122
+ width: number;
123
+ /**
124
+ * Height of the grid in pixels
125
+ */
126
+ height: number;
127
+ /**
128
+ * Grid visibility. x is default.
129
+ */
130
+ gridVisibility?: 'x' | 'y' | 'xy' | 'none';
131
+ /**
132
+ * X-axis scale for the grid
133
+ * TODO: Fix any type after resolving visx scale type issues
134
+ */
135
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
136
+ xScale: any;
137
+ /**
138
+ * Y-axis scale for the grid
139
+ * TODO: Fix any type after resolving visx scale type issues
140
+ */
141
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
+ yScale: any;
143
+ /**
144
+ * Top offset for the grid
145
+ */
146
+ top?: number;
109
147
  };
package/tsup.config.js ADDED
@@ -0,0 +1,26 @@
1
+ import path from 'path';
2
+ import { sassPlugin, postcssModules } from 'esbuild-sass-plugin';
3
+ import { defineConfig } from 'tsup';
4
+
5
+ export default defineConfig( {
6
+ entry: [ 'src/index.ts' ],
7
+ format: [ 'cjs', 'esm' ],
8
+ dts: true,
9
+ splitting: false,
10
+ sourcemap: true,
11
+ clean: true,
12
+ external: [ 'react' ],
13
+ outDir: 'dist',
14
+ esbuildPlugins: [
15
+ sassPlugin( {
16
+ filter: /\.module\.scss$/,
17
+ transform: postcssModules( {
18
+ basedir: path.resolve( __dirname ),
19
+ generateScopedName: '[name]__[local]___[hash:base64:5]',
20
+ } ),
21
+ } ),
22
+ sassPlugin( {
23
+ filter: /\.scss$/,
24
+ } ),
25
+ ],
26
+ } );