@redsift/charts 11.1.3 → 11.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/index.d.ts CHANGED
@@ -5,6 +5,7 @@ import { PieArcDatum } from 'd3-shape';
5
5
  import { MutableRefObject, ComponentProps, ReactElement, RefObject, ReactNode } from 'react';
6
6
  import * as d3_scale from 'd3-scale';
7
7
  import { ScaleLinear as ScaleLinear$2, ScaleLogarithmic, ScaleSymLog, ScalePoint as ScalePoint$1, ScaleBand as ScaleBand$1, ScaleTime as ScaleTime$1 } from 'd3-scale';
8
+ import { TooltipProps } from '@redsift/popovers';
8
9
  import * as styled_components from 'styled-components';
9
10
  import * as _react_spring_web from '@react-spring/web';
10
11
 
@@ -405,6 +406,8 @@ interface DataPointProps<T> extends Omit<ComponentProps<'g'>, 'onClick' | 'scale
405
406
  color?: string;
406
407
  /** Data. Also state to which the component should end the animation, if any. */
407
408
  data: T;
409
+ /** Entire dataset in which the data point is a part of. */
410
+ dataset: any[];
408
411
  /** Disable animations. */
409
412
  disableAnimations?: boolean;
410
413
  /** Id. Used for accessibility. */
@@ -420,7 +423,7 @@ interface DataPointProps<T> extends Omit<ComponentProps<'g'>, 'onClick' | 'scale
420
423
  color?: string;
421
424
  }) => string | ReactElement;
422
425
  /** Method called when a click or keydown occurs on the component. */
423
- onClick?: (data: T) => void;
426
+ onClick?: (data: T, dataset: any[]) => void;
424
427
  /** State from which the component should start the animation, if any. */
425
428
  previousData?: T;
426
429
  /** Role. Will be set to 'button' if onClick is provided. If 'option', then the component becomes selectable. */
@@ -435,8 +438,10 @@ interface DataPointProps<T> extends Omit<ComponentProps<'g'>, 'onClick' | 'scale
435
438
  isSelected?: boolean;
436
439
  color?: string;
437
440
  }) => string | ReactElement;
441
+ /** Default placement of the tooltip. */
442
+ tooltipProps?: Partial<Omit<TooltipProps, 'ref'>>;
438
443
  }
439
- type StyledDataPointProps = Omit<DataPointProps<any>, 'data'> & {
444
+ type StyledDataPointProps = Omit<DataPointProps<any>, 'data' | 'dataset'> & {
440
445
  $clickable: boolean;
441
446
  };
442
447
 
@@ -445,7 +450,7 @@ declare const DataPoint: Comp<DataPointProps<any>, SVGGElement>;
445
450
  /**
446
451
  * Component style.
447
452
  */
448
- declare const StyledDataPoint: styled_components.StyledComponent<_react_spring_web.AnimatedComponent<"g">, any, Omit<DataPointProps<any>, "data"> & {
453
+ declare const StyledDataPoint: styled_components.StyledComponent<_react_spring_web.AnimatedComponent<"g">, any, Omit<DataPointProps<any>, "data" | "dataset"> & {
449
454
  $clickable: boolean;
450
455
  }, never>;
451
456
 
@@ -468,7 +473,7 @@ declare const Arc: Comp<ArcProps, SVGGElement>;
468
473
  /**
469
474
  * Component style.
470
475
  */
471
- declare const StyledArc: styled_components.StyledComponent<_redsift_design_system.Comp<DataPointProps<any>, SVGGElement>, any, Omit<DataPointProps<any>, "data"> & {
476
+ declare const StyledArc: styled_components.StyledComponent<_redsift_design_system.Comp<DataPointProps<any>, SVGGElement>, any, Omit<DataPointProps<any>, "data" | "dataset"> & {
472
477
  $clickable: boolean;
473
478
  } & Omit<ArcProps, "createArc"> & {
474
479
  $hasStroke: boolean | undefined;
@@ -533,7 +538,7 @@ declare const Bar: Comp<BarProps, SVGGElement>;
533
538
  /**
534
539
  * Component style.
535
540
  */
536
- declare const StyledBar: styled_components.StyledComponent<_redsift_design_system.Comp<DataPointProps<any>, SVGGElement>, any, Omit<DataPointProps<any>, "data"> & {
541
+ declare const StyledBar: styled_components.StyledComponent<_redsift_design_system.Comp<DataPointProps<any>, SVGGElement>, any, Omit<DataPointProps<any>, "data" | "dataset"> & {
537
542
  $clickable: boolean;
538
543
  } & Omit<BarProps, "scale" | "scalePosition"> & {
539
544
  $theme: Theme;
@@ -599,7 +604,7 @@ declare const StyledChartContainerCaption: styled_components.StyledComponent<"p"
599
604
  /**
600
605
  * Component props.
601
606
  */
602
- interface LegendItemProps extends Pick<DataPointProps<LegendItemDatum>, 'color' | 'data' | 'id' | 'index' | 'isSelected' | 'labelDecorator' | 'onClick' | 'previousData' | 'role' | 'tooltipVariant'>, Omit<ComponentProps<'li'>, 'onClick' | 'role'> {
607
+ interface LegendItemProps extends Pick<DataPointProps<LegendItemDatum>, 'color' | 'data' | 'dataset' | 'id' | 'index' | 'isSelected' | 'labelDecorator' | 'onClick' | 'previousData' | 'role' | 'tooltipVariant'>, Omit<ComponentProps<'li'>, 'onClick' | 'role'> {
603
608
  /** Method modifying what's displayed within the legend when the variant is "custom". */
604
609
  legendDecorator?: (datum: LegendItemDatum, props?: {
605
610
  index?: number;
@@ -633,7 +638,7 @@ interface LegendProps extends Omit<ComponentProps<'ul'>, 'onClick'>, ContainerPr
633
638
  color?: string;
634
639
  }) => string | ReactElement;
635
640
  /** Method to be called on a click on a legend item. */
636
- onLegendItemClick?: (datum: LegendItemDatum) => void;
641
+ onLegendItemClick?: (datum: LegendItemDatum, data: LegendItemDatum[]) => void;
637
642
  /** LegendItem role. Used to indicate that legend items are to be considered buttons or links. If an onClick is provided, the legend items will have the role `button` unless specifically set to `link` with this prop. */
638
643
  legendItemRole?: LegendItemProps['role'];
639
644
  /** Variant. */
@@ -719,7 +724,7 @@ interface BarChartProps extends ChartContainerProps, ChartAxesProps {
719
724
  /** Custom margins, used to give more space for axes labels and legend for instance. */
720
725
  margins?: MarginProps;
721
726
  /** Method to be called on a click on a bar. For a navigation link, please use `getBarAnchorProps` instead. */
722
- onBarClick?: (datum: BarDatum) => void;
727
+ onBarClick?: (datum: BarDatum, data: BarDatum[]) => void;
723
728
  /** Orientation of the bar. */
724
729
  orientation?: BarOrientation;
725
730
  /** Whether a category should be displayed for categories that has been removed by the caping option. Optionaly, this prop can be used to change the label of this category. */
@@ -798,7 +803,7 @@ declare const Dot: Comp<DotProps, SVGGElement>;
798
803
  /**
799
804
  * Component style.
800
805
  */
801
- declare const StyledDot: styled_components.StyledComponent<_redsift_design_system.Comp<DataPointProps<any>, SVGGElement>, any, Omit<DataPointProps<any>, "data"> & {
806
+ declare const StyledDot: styled_components.StyledComponent<_redsift_design_system.Comp<DataPointProps<any>, SVGGElement>, any, Omit<DataPointProps<any>, "data" | "dataset"> & {
802
807
  $clickable: boolean;
803
808
  } & Omit<DotProps, "scaleX" | "scaleY"> & {
804
809
  $variant: DotVariant | undefined;
package/index.js CHANGED
@@ -376,7 +376,7 @@ var k=/^--/;function I(t,e){return e==null||typeof e=="boolean"||e===""?"":typeo
376
376
  const StyledDataPoint = styled(it.g)``;
377
377
 
378
378
  const _excluded$q = ["as", "href"],
379
- _excluded2$5 = ["anchorProps", "children", "className", "data", "id", "index", "isSelected", "labelDecorator", "onClick", "role", "tooltipDecorator", "tooltipVariant", "theme"];
379
+ _excluded2$5 = ["anchorProps", "children", "className", "data", "id", "index", "isSelected", "labelDecorator", "onClick", "role", "tooltipDecorator", "tooltipVariant", "theme", "tooltipProps", "dataset"];
380
380
  const DataPoint = /*#__PURE__*/forwardRef((props, ref) => {
381
381
  const {
382
382
  anchorProps: {
@@ -394,7 +394,9 @@ const DataPoint = /*#__PURE__*/forwardRef((props, ref) => {
394
394
  role,
395
395
  tooltipDecorator,
396
396
  tooltipVariant,
397
- theme: propsTheme
397
+ theme: propsTheme,
398
+ tooltipProps,
399
+ dataset
398
400
  } = props,
399
401
  anchorProps = _objectWithoutProperties(props.anchorProps, _excluded$q),
400
402
  forwardedProps = _objectWithoutProperties(props, _excluded2$5);
@@ -420,7 +422,7 @@ const DataPoint = /*#__PURE__*/forwardRef((props, ref) => {
420
422
  event.stopPropagation();
421
423
  if (event.code === 'Enter' || event.code === 'Space') {
422
424
  event.preventDefault();
423
- onClick(data);
425
+ onClick(data, dataset);
424
426
  }
425
427
  }
426
428
  };
@@ -432,7 +434,7 @@ const DataPoint = /*#__PURE__*/forwardRef((props, ref) => {
432
434
  "aria-label": showTooltip && !isEmpty ? labelDecorator ? text : `${data.data.key}, ${data.data.value}` : undefined,
433
435
  "aria-labelledby": !showTooltip && !isEmpty ? `${id}-title` : undefined,
434
436
  "aria-selected": isSelected ? true : isDeselected ? false : undefined,
435
- onClick: onClick ? () => onClick(data) : undefined,
437
+ onClick: onClick ? () => onClick(data, dataset) : undefined,
436
438
  onKeyDown: onClick ? e => onKeyDown(e) : undefined,
437
439
  role: role ? role : onClick ? 'button' : href ? undefined : 'img'
438
440
  }, forwardedProps, {
@@ -447,11 +449,11 @@ const DataPoint = /*#__PURE__*/forwardRef((props, ref) => {
447
449
  id: `${id}-title`
448
450
  }, `${text}: ${data.data.value}`) : null);
449
451
  if (showTooltip) {
450
- return /*#__PURE__*/React__default.createElement(Tooltip, {
452
+ return /*#__PURE__*/React__default.createElement(Tooltip, _extends({
451
453
  placement: "right",
452
454
  theme: theme,
453
455
  delay: 50
454
- }, /*#__PURE__*/React__default.createElement(Tooltip.Trigger, null, href !== undefined ? /*#__PURE__*/React__default.createElement(as || 'a', _objectSpread2({
456
+ }, tooltipProps), /*#__PURE__*/React__default.createElement(Tooltip.Trigger, null, href !== undefined ? /*#__PURE__*/React__default.createElement(as || 'a', _objectSpread2({
455
457
  href
456
458
  }, anchorProps), DataPointComponent) : DataPointComponent), /*#__PURE__*/React__default.createElement(Tooltip.Content, null, isTooltipCustom ? tooltipDecorator(data, {
457
459
  index,
@@ -569,7 +571,11 @@ const Arc = /*#__PURE__*/forwardRef((props, ref) => {
569
571
  className: classNames(Arc.className, className),
570
572
  $clickable: Boolean(onClick),
571
573
  $hasStroke: Boolean(hasStroke),
572
- $theme: theme
574
+ $theme: theme,
575
+ tooltipProps: {
576
+ placement: 'client-point',
577
+ offset: 12
578
+ }
573
579
  }), /*#__PURE__*/React__default.createElement(it.path, {
574
580
  d: config.immediate || disableAnimations ? createArc(data) : animatedProps.t.to(t => createArc(interpolator(t))),
575
581
  fill: isDeselected ? 'var(--redsift-color-neutral-light-grey)' : color
@@ -1768,6 +1774,7 @@ const RenderedOrdinalBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1768
1774
  return /*#__PURE__*/React__default.createElement(Bar, _extends({
1769
1775
  color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(to.data.key),
1770
1776
  data: to,
1777
+ dataset: bars,
1771
1778
  disableAnimations: disableAnimations,
1772
1779
  gap: gap,
1773
1780
  id: `id${id}__bar-${index}`,
@@ -1858,7 +1865,7 @@ const StyledLegendItem = styled.li`
1858
1865
  }}}
1859
1866
  `;
1860
1867
 
1861
- const _excluded$h = ["className", "color", "data", "id", "variant"];
1868
+ const _excluded$h = ["className", "color", "data", "dataset", "id", "variant"];
1862
1869
  const COMPONENT_NAME$7 = 'LegendItem';
1863
1870
  const CLASSNAME$7 = 'redsift-legend-item';
1864
1871
  const LegendItem = /*#__PURE__*/forwardRef((props, ref) => {
@@ -1874,6 +1881,7 @@ const LegendItem = /*#__PURE__*/forwardRef((props, ref) => {
1874
1881
  className,
1875
1882
  color = monochrome,
1876
1883
  data,
1884
+ dataset,
1877
1885
  id: propsId,
1878
1886
  variant
1879
1887
  } = props,
@@ -1896,7 +1904,7 @@ const LegendItem = /*#__PURE__*/forwardRef((props, ref) => {
1896
1904
  event.stopPropagation();
1897
1905
  if (event.code === 'Enter' || event.code === 'Space') {
1898
1906
  event.preventDefault();
1899
- onClick(data);
1907
+ onClick(data, dataset);
1900
1908
  }
1901
1909
  }
1902
1910
  };
@@ -1910,7 +1918,7 @@ const LegendItem = /*#__PURE__*/forwardRef((props, ref) => {
1910
1918
  "aria-labelledby": !isEmpty ? `${id}-title` : undefined,
1911
1919
  "aria-selected": isSelected ? true : isDeselected ? false : undefined,
1912
1920
  id: id,
1913
- onClick: onClick ? () => onClick(data) : undefined,
1921
+ onClick: onClick ? () => onClick(data, dataset) : undefined,
1914
1922
  onKeyDown: onClick ? e => onKeyDown(e) : undefined,
1915
1923
  role: role ? role : onClick ? 'button' : undefined,
1916
1924
  tabIndex: onClick ? 0 : undefined,
@@ -1977,6 +1985,7 @@ const Legend = /*#__PURE__*/forwardRef((props, ref) => {
1977
1985
  percent: (_datum$percent = datum.percent) !== null && _datum$percent !== void 0 ? _datum$percent : datum.value / total
1978
1986
  })
1979
1987
  },
1988
+ dataset: data,
1980
1989
  color: color,
1981
1990
  variant: variant,
1982
1991
  index: index,
@@ -2283,6 +2292,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
2283
2292
  return /*#__PURE__*/React__default.createElement(Bar, _extends({
2284
2293
  color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(to.data.category),
2285
2294
  data: to,
2295
+ dataset: bars,
2286
2296
  disableAnimations: disableAnimations,
2287
2297
  gap: gap,
2288
2298
  id: `id${id}__bar-${categoryIndex}.${index}`,
@@ -3119,6 +3129,7 @@ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
3119
3129
  id: `id${id}__circle-${categoryIndex}.${index}`,
3120
3130
  color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(circle.category),
3121
3131
  data: to,
3132
+ dataset: circles,
3122
3133
  isSelected: Boolean(isDotSelected === null || isDotSelected === void 0 ? void 0 : isDotSelected(to)),
3123
3134
  anchorProps: getDotAnchorProps ? getDotAnchorProps(to) : undefined,
3124
3135
  key: `circle _${categoryIndex}.${index}`,
@@ -3568,6 +3579,17 @@ const EmptyPieChart = /*#__PURE__*/forwardRef((props, ref) => {
3568
3579
  endAngle: 2 * Math.PI,
3569
3580
  padAngle: 0
3570
3581
  },
3582
+ dataset: [{
3583
+ data: {
3584
+ key: 'No Data',
3585
+ value: 0
3586
+ },
3587
+ index: 0,
3588
+ value: 0,
3589
+ startAngle: 0,
3590
+ endAngle: 2 * Math.PI,
3591
+ padAngle: 0
3592
+ }],
3571
3593
  color: empty
3572
3594
  }],
3573
3595
  transform: `translate(${width / 2} ${height / 2})`
@@ -3750,6 +3772,7 @@ const RenderedPieChart = /*#__PURE__*/forwardRef((props, ref) => {
3750
3772
  isSelected: isSliceSelected(to),
3751
3773
  key: `id${id}__arc-${index}`,
3752
3774
  data: to,
3775
+ dataset: pieData,
3753
3776
  anchorProps: getSliceAnchorProps ? getSliceAnchorProps(to) : undefined
3754
3777
  };
3755
3778
  }),
@@ -4342,6 +4365,7 @@ const RenderedScatterPlot = /*#__PURE__*/forwardRef((props, ref) => {
4342
4365
  return /*#__PURE__*/React__default.createElement(Dot, {
4343
4366
  color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(circle.category),
4344
4367
  data: to,
4368
+ dataset: circles,
4345
4369
  isSelected: Boolean(isDotSelected === null || isDotSelected === void 0 ? void 0 : isDotSelected(to)),
4346
4370
  key: `circle _${index}`,
4347
4371
  labelDecorator: labelDecorator,