@automattic/charts 1.12.0 → 2.0.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.
@@ -1,6 +1,6 @@
1
1
  import { DataContext } from '@visx/xychart';
2
2
  import { __ } from '@wordpress/i18n';
3
- import { Button } from '@wordpress/ui';
3
+ import { IconButton } from '@wordpress/ui';
4
4
  import { useCallback, useContext, useMemo, useState } from 'react';
5
5
  import styles from './x-zoom.module.scss';
6
6
  import type { SingleChartRef } from '../single-chart-context';
@@ -172,14 +172,8 @@ export function ZoomClip( {
172
172
 
173
173
  /**
174
174
  * Visible icon-only reset control rendered as an HTML overlay on top of the
175
- * chart container, using the WPDS `Button`. The host should wrap its SVG in a
176
- * `position: relative` container so the button anchors correctly.
177
- *
178
- * `IconButton` would be the natural fit, but it renders a Base UI tooltip whose
179
- * CommonJS `use-sync-external-store` dependency makes Rolldown emit a dynamic
180
- * `require()` into `dist`, which throws on evaluation in WordPress Script
181
- * Module consumers. `Button` gives the same treatment without that dependency;
182
- * the tooltip is replaced by `aria-label` + `title`.
175
+ * chart container, using the WPDS `IconButton`. The host should wrap its SVG in
176
+ * a `position: relative` container so the button anchors correctly.
183
177
  *
184
178
  * @param props - Props.
185
179
  * @param props.onClick - Click handler. Typically the `reset` from `useXZoom`.
@@ -194,44 +188,39 @@ export function ZoomResetButton( { onClick }: { onClick: () => void } ) {
194
188
  event.stopPropagation();
195
189
  }
196
190
  }, [] );
197
- const label = __( 'Reset zoom', 'jetpack-charts' );
198
191
  return (
199
- <Button
192
+ <IconButton
200
193
  className={ styles[ 'x-zoom__reset' ] }
201
194
  onKeyDown={ stopActivationKeys }
202
- aria-label={ label }
203
- title={ label }
195
+ label={ __( 'Reset zoom', 'jetpack-charts' ) }
204
196
  variant="outline"
205
197
  tone="neutral"
206
198
  size="small"
207
199
  onClick={ onClick }
208
200
  data-testid="chart-zoom-reset"
209
- >
210
- <Button.Icon
211
- icon={
212
- <svg
213
- viewBox="0 0 24 24"
214
- fill="none"
215
- stroke="currentColor"
216
- strokeWidth="2"
217
- strokeLinecap="round"
218
- strokeLinejoin="round"
219
- aria-hidden="true"
220
- focusable="false"
221
- >
222
- { /*
223
- Icons render edge-to-edge at 24px, so inset the glyph the
224
- way @wordpress/icons glyphs do (drawn within roughly 4-20
225
- of the viewBox, ~1.5px effective stroke).
226
- */ }
227
- <g transform="translate(2.4 2.4) scale(0.8)">
228
- <circle cx="10" cy="10" r="6" />
229
- <line x1="15" y1="15" x2="20" y2="20" />
230
- <line x1="7" y1="10" x2="13" y2="10" />
231
- </g>
232
- </svg>
233
- }
234
- />
235
- </Button>
201
+ icon={
202
+ <svg
203
+ viewBox="0 0 24 24"
204
+ fill="none"
205
+ stroke="currentColor"
206
+ strokeWidth="2"
207
+ strokeLinecap="round"
208
+ strokeLinejoin="round"
209
+ aria-hidden="true"
210
+ focusable="false"
211
+ >
212
+ { /*
213
+ Icons render edge-to-edge at 24px, so inset the glyph the
214
+ way @wordpress/icons glyphs do (drawn within roughly 4-20
215
+ of the viewBox, ~1.5px effective stroke).
216
+ */ }
217
+ <g transform="translate(2.4 2.4) scale(0.8)">
218
+ <circle cx="10" cy="10" r="6" />
219
+ <line x1="15" y1="15" x2="20" y2="20" />
220
+ <line x1="7" y1="10" x2="13" y2="10" />
221
+ </g>
222
+ </svg>
223
+ }
224
+ />
236
225
  );
237
226
  }
@@ -54,6 +54,6 @@
54
54
  }
55
55
 
56
56
  .legend-item-value {
57
- font-weight: var(--wpds-typography-font-weight-medium, 499);
57
+ font-weight: var(--wpds-typography-font-weight-emphasis, 499);
58
58
  flex-shrink: 0; // Prevent value from shrinking when text is ellipsized
59
59
  }
@@ -8,7 +8,7 @@
8
8
  color: #fff;
9
9
  border-radius: var(--wpds-border-radius-md, 4px);
10
10
  font-size: var(--wpds-typography-font-size-md, 13px);
11
- box-shadow: var(--wpds-elevation-sm, 0 1px 2px 0 #0000000d, 0 2px 3px 0 #0000000a, 0 6px 6px 0 #00000008, 0 8px 8px 0 #00000005);
11
+ box-shadow: var(--a8c-charts-elevation-sm, 0 1px 2px 0 #0000000d, 0 2px 3px 0 #0000000a, 0 6px 6px 0 #00000008, 0 8px 8px 0 #00000005);
12
12
  position: absolute;
13
13
  pointer-events: none;
14
14
  transform: translate(-50%, -100%);
@@ -3,7 +3,7 @@
3
3
  align-items: center;
4
4
  gap: 0.125em;
5
5
  font-size: var(--wpds-typography-font-size-md, 13px);
6
- font-weight: var(--wpds-typography-font-weight-medium, 499);
6
+ font-weight: var(--wpds-typography-font-weight-emphasis, 499);
7
7
  line-height: 1;
8
8
 
9
9
  // Trend colours use the --a8c-charts-color-trend-* catalog roles, falling back
package/src/index.ts CHANGED
@@ -51,6 +51,7 @@ export type {
51
51
  ChartTheme,
52
52
  CompleteChartTheme,
53
53
  AxisOptions,
54
+ TickResolution,
54
55
  ScaleOptions,
55
56
  LegendItemStyles,
56
57
  LegendLabelStyles,
package/src/types.ts CHANGED
@@ -462,6 +462,12 @@ export type CompleteChartTheme = Required< ChartTheme > & {
462
462
  Pick< NonNullable< ChartTheme[ 'heatmapChart' ] >, 'primaryColor' >;
463
463
  };
464
464
 
465
+ /**
466
+ * Bucket resolution of time-series data, as known by the caller (e.g. a
467
+ * granularity selector), for consumers that don't need to infer it.
468
+ */
469
+ export type TickResolution = 'hour' | 'day' | 'week' | 'month' | 'year';
470
+
465
471
  export type AxisOptions = {
466
472
  orientation?: OrientationType;
467
473
  numTicks?: number;
@@ -475,6 +481,15 @@ export type AxisOptions = {
475
481
  labelClassName?: string;
476
482
  tickClassName?: string;
477
483
  tickFormat?: TickFormatter< ScaleInput< AxisScale > >;
484
+ /**
485
+ * Bucket resolution of the data on a time x-axis. When set, the automatic
486
+ * tick formatter derives tick formats from it directly instead of
487
+ * inferring the resolution from point spacing. The overall time span still
488
+ * constrains the choice — e.g. hourly buckets spanning more than a week
489
+ * get date ticks, since hour ticks would be unreadable at that span.
490
+ * Ignored when `tickFormat` is set.
491
+ */
492
+ tickResolution?: TickResolution;
478
493
  /**
479
494
  * Whether to display this axis. Defaults to true.
480
495
  */