@evergis/charts 2.0.93 → 2.0.95

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,2 +1,2 @@
1
1
  import { DrawTooltipProps } from './types';
2
- export declare const drawTooltip: ({ svg, node, data, marshalledData, xScale, yScale, renderTooltip, labelPosition, marginTop, renderLabel, barWidth, barPadding, dynamicTooltipEnable, tooltipY, tooltipBind, lineData, formatTooltipValue, formatTooltipName, tooltipYDomain, setTooltipPosition, onLabelItem, isBarTooltip, bars, tooltipRoot, tooltipClassName, }: DrawTooltipProps) => void;
2
+ export declare const drawTooltip: ({ svg, node, data, marshalledData, xScale, yScale, renderTooltip, labelPosition, marginTop, renderLabel, barWidth, barPadding, dynamicTooltipEnable, tooltipY, tooltipBind, lineData, formatTooltipValue, formatTooltipName, tooltipYDomain, setTooltipPosition, onLabelItem, isBarTooltip, bars, tooltipRoot, tooltipClassName, onBarClick, onBarHover, }: DrawTooltipProps) => void;
@@ -10,4 +10,4 @@ export declare type DrawTooltipProps = {
10
10
  marginTop: number;
11
11
  barWidth: number;
12
12
  bars: d3.Selection<SVGGElement, BarChartMarshalledGroup[], SVGGElement, unknown>;
13
- } & Pick<BarChartProps, 'renderTooltip' | 'labelPosition' | 'renderLabel' | 'dynamicTooltipEnable' | 'tooltipY' | 'tooltipBind' | 'lineData' | 'formatTooltipValue' | 'formatTooltipName' | 'tooltipYDomain' | 'data' | 'barPadding' | 'setTooltipPosition' | 'onLabelItem' | 'isBarTooltip' | 'tooltipRoot' | 'tooltipClassName'>;
13
+ } & Pick<BarChartProps, 'renderTooltip' | 'labelPosition' | 'renderLabel' | 'dynamicTooltipEnable' | 'tooltipY' | 'tooltipBind' | 'lineData' | 'formatTooltipValue' | 'formatTooltipName' | 'tooltipYDomain' | 'data' | 'barPadding' | 'setTooltipPosition' | 'onLabelItem' | 'isBarTooltip' | 'tooltipRoot' | 'tooltipClassName' | 'onBarClick' | 'onBarHover'>;
@@ -25,6 +25,7 @@ export interface BarChartMarker {
25
25
  value: number;
26
26
  color?: string;
27
27
  className?: string;
28
+ horizontal?: boolean;
28
29
  }
29
30
  export declare type BarChartProps = {
30
31
  className?: string;
@@ -112,6 +113,8 @@ export declare type BarChartProps = {
112
113
  tooltipClassName?: string;
113
114
  selectable?: boolean;
114
115
  onSelect?: (value: [number, number]) => void;
116
+ onBarClick?: (group: BarChartMarshalledGroup) => void;
117
+ onBarHover?: (group?: BarChartMarshalledGroup) => void;
115
118
  };
116
119
  export declare type BarChartMergedData = (BarChartMarshalledGroup & BarChartLineData & {
117
120
  groupName: string;
@@ -2309,7 +2309,9 @@ const drawTooltip$2 = _ref => {
2309
2309
  isBarTooltip,
2310
2310
  bars,
2311
2311
  tooltipRoot,
2312
- tooltipClassName
2312
+ tooltipClassName,
2313
+ onBarClick,
2314
+ onBarHover
2313
2315
  } = _ref;
2314
2316
  d3.select(node).select("." + barChartClassNames.barChartMouseContainer).remove();
2315
2317
  const xScaleBandDomain = xScale.domain();
@@ -2513,6 +2515,21 @@ const drawTooltip$2 = _ref => {
2513
2515
  const container = d3.select(node).append('div').attr('class', barChartClassNames.barChartMouseContainer);
2514
2516
  const labelContainer = container.append('div').attr('class', barChartClassNames.barChartLabelContainer).style('position', 'absolute').style('top', y2 + "px");
2515
2517
 
2518
+ const isMouseWithin = (e, callback) => {
2519
+ const [rectrX, rectrY] = d3.pointer(e, mouseRect);
2520
+ const [nodeX, nodeY] = d3.pointer(e, node);
2521
+ const x = rectrX - (rectrX - nodeX);
2522
+ const y = rectrY - nodeY;
2523
+ const currIndex = groups.findIndex(value => x <= value);
2524
+ const dataItem = marshalledData[currIndex][0];
2525
+
2526
+ if (dataItem.height >= y1 - y) {
2527
+ callback(dataItem);
2528
+ }
2529
+ };
2530
+
2531
+ mouseGlobal.on("click", e => isMouseWithin(e, dataItem => onBarClick && onBarClick(dataItem))).on("mousemove", e => isMouseWithin(e, dataItem => onBarHover && onBarHover(dataItem))).on("mouseleave", () => onBarHover && onBarHover(undefined));
2532
+
2516
2533
  if (labelPosition) {
2517
2534
  const concatedData = lineData ? marshalledData.map((stack, index) => stack.concat(lineData.map(_ref6 => {
2518
2535
  let {
@@ -2646,7 +2663,9 @@ const draw$4 = (node, props) => {
2646
2663
  isBarTooltip,
2647
2664
  xScaleItemWidth,
2648
2665
  tooltipRoot,
2649
- tooltipClassName
2666
+ tooltipClassName,
2667
+ onBarClick,
2668
+ onBarHover
2650
2669
  } = props;
2651
2670
 
2652
2671
  if (node !== null && data.length) {
@@ -2760,6 +2779,12 @@ const draw$4 = (node, props) => {
2760
2779
  return;
2761
2780
  }
2762
2781
 
2782
+ if (marker.horizontal) {
2783
+ svg.append('line').style("stroke", marker.color || "inherit").style("stroke-width", 1).style("stroke-dasharray", "5, 3").attr("x1", marginLeft + yAxisWidth).attr("y1", yScale(marker.value) + 1).attr("x2", width).attr("y2", yScale(marker.value) + 1);
2784
+ svg.append("text").attr("y", yScale(marker.value) + 1).attr("x", marginLeft + yAxisWidth).attr('text-anchor', 'middle').attr("class", ["marker", marker.className].filter(Boolean).join(" ")).style("fill", (marker == null ? void 0 : marker.color) || "inherit").text(marker.label);
2785
+ return;
2786
+ }
2787
+
2763
2788
  svg.append('line').style("stroke", marker.color || "inherit").style("stroke-width", 1).style("stroke-dasharray", "5, 3").attr("x1", width / data.length * marker.value + 1).attr("y1", 0).attr("x2", width / data.length * marker.value + 1).attr("y2", height - marginTop - marginBottom + marginBottom / 2);
2764
2789
  svg.append("text").attr("y", height).attr("x", width / data.length * marker.value + 1).attr('text-anchor', 'middle').attr("class", ["marker", marker.className].filter(Boolean).join(" ")).style("fill", (marker == null ? void 0 : marker.color) || "inherit").text(marker.label);
2765
2790
  });
@@ -2811,7 +2836,9 @@ const draw$4 = (node, props) => {
2811
2836
  isBarTooltip,
2812
2837
  bars: groups,
2813
2838
  tooltipRoot,
2814
- tooltipClassName
2839
+ tooltipClassName,
2840
+ onBarClick,
2841
+ onBarHover
2815
2842
  });
2816
2843
  }
2817
2844