@oliasoft-open-source/charts-library 4.6.0 → 4.6.2-beta-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.
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import { produce } from "immer";
12
12
  import { round as round$2, displayNumber, isCloseTo, roundByMagnitude } from "@oliasoft-open-source/units";
13
13
  import cx from "classnames";
14
14
  import { Portal, Icon, Tooltip as Tooltip$2, Button, Flex, Text, Menu, Popover, Field, InputGroup, NumberInput, InputGroupAddon, Select, ButtonGroup, Spacer } from "@oliasoft-open-source/react-ui-library";
15
- import { isEmpty, isArray as isArray$2, some, has, cloneDeep, defaultTo, findIndex, set as set$2, debounce as debounce$3, isNil, map as map$3, find, get as get$1 } from "lodash";
15
+ import { isEmpty, isArray as isArray$2, some, has, cloneDeep, defaultTo, findIndex, set as set$2, debounce as debounce$3, isNil, map as map$3, find, get as get$1, noop as noop$2 } from "lodash";
16
16
  /*!
17
17
  * @kurkle/color v0.3.2
18
18
  * https://github.com/kurkle/color#readme
@@ -26495,9 +26495,10 @@ const SvgTriangle = (props) => /* @__PURE__ */ React.createElement("svg", { heig
26495
26495
  const LEGEND_SYMBOL_SIZE$1 = 16;
26496
26496
  const LineItem = ({ dataset }) => {
26497
26497
  var _a2;
26498
- const { borderColor, borderDash, borderWidth } = dataset;
26499
- const offset = borderDash.length ? (LEGEND_SYMBOL_SIZE$1 - borderDash[0]) / 2 % (borderDash[0] + borderDash[1]) * -1 : 0;
26500
- const borderDashString = ((_a2 = dataset.borderDash) == null ? void 0 : _a2.join(" ")) || "";
26498
+ const { borderColor, borderDash, borderWidth } = dataset ?? {};
26499
+ const [dash0, dash1] = borderDash ?? [];
26500
+ const offset = dash0 && dash1 ? (LEGEND_SYMBOL_SIZE$1 - dash0) / 2 % (dash0 + dash1) * -1 : 0;
26501
+ const borderDashString = ((_a2 = dataset == null ? void 0 : dataset.borderDash) == null ? void 0 : _a2.join(" ")) || "";
26501
26502
  return /* @__PURE__ */ jsx("span", { className: styles$3.legendItemLine, children: /* @__PURE__ */ jsx(
26502
26503
  "svg",
26503
26504
  {
@@ -26522,7 +26523,7 @@ const LineItem = ({ dataset }) => {
26522
26523
  ) });
26523
26524
  };
26524
26525
  const PointItem = ({ dataset }) => {
26525
- const { pointBackgroundColor, pointRadius, pointStyle = "" } = dataset;
26526
+ const { pointBackgroundColor, pointRadius, pointStyle = "" } = dataset ?? {};
26526
26527
  if (!pointRadius)
26527
26528
  return null;
26528
26529
  const size = pointRadius * 2;
@@ -26535,19 +26536,19 @@ const PointItem = ({ dataset }) => {
26535
26536
  return /* @__PURE__ */ jsx("span", { className: styles$3.legendItemPoint, children: /* @__PURE__ */ jsx(
26536
26537
  Icon,
26537
26538
  {
26538
- icon: icons[pointStyle] ?? /* @__PURE__ */ jsx(SvgCircle, {}),
26539
+ icon: (icons == null ? void 0 : icons[pointStyle]) ?? /* @__PURE__ */ jsx(SvgCircle, {}),
26539
26540
  size,
26540
26541
  color: pointBackgroundColor
26541
26542
  }
26542
26543
  ) });
26543
26544
  };
26544
26545
  const BoxItem = ({ dataset }) => {
26545
- const { backgroundColor } = dataset;
26546
+ const { backgroundColor } = dataset ?? {};
26546
26547
  const style = { backgroundColor };
26547
26548
  return /* @__PURE__ */ jsx("span", { className: styles$3.legendItemBox, style });
26548
26549
  };
26549
26550
  const LegendItemLine = ({ dataset }) => {
26550
- const { annotationType, showLine } = dataset;
26551
+ const { annotationType, showLine } = dataset ?? {};
26551
26552
  switch (annotationType) {
26552
26553
  case AnnotationType$1.Box:
26553
26554
  case AnnotationType$1.Ellipse:
@@ -26567,15 +26568,15 @@ const renderLegendItemSymbol = (dataset, chartType, index2) => {
26567
26568
  case ChartType.LINE:
26568
26569
  return /* @__PURE__ */ jsx(LegendItemLine, { dataset });
26569
26570
  case ChartType.BAR: {
26570
- const { backgroundColor } = dataset;
26571
- const color2 = backgroundColor instanceof Array ? backgroundColor[index2] : backgroundColor;
26571
+ const { backgroundColor } = dataset ?? {};
26572
+ const color2 = backgroundColor instanceof Array ? backgroundColor == null ? void 0 : backgroundColor[index2] : backgroundColor;
26572
26573
  return /* @__PURE__ */ jsx("span", { className: styles$3.legendItemBox, children: /* @__PURE__ */ jsx(TbSquareFilled, { color: color2 }) });
26573
26574
  }
26574
26575
  case ChartType.PIE:
26575
26576
  return /* @__PURE__ */ jsx("span", { className: styles$3.legendItemPoint, children: /* @__PURE__ */ jsx(Icon, { icon: /* @__PURE__ */ jsx(SvgCircle, {}) }) });
26576
26577
  case ChartType.SCATTER: {
26577
- const { backgroundColor, borderColor } = dataset;
26578
- const color2 = backgroundColor instanceof Array ? backgroundColor[index2] : backgroundColor;
26578
+ const { backgroundColor, borderColor } = dataset ?? {};
26579
+ const color2 = backgroundColor instanceof Array ? backgroundColor == null ? void 0 : backgroundColor[index2] : backgroundColor;
26579
26580
  return /* @__PURE__ */ jsx("span", { className: styles$3.legendItemPoint, children: /* @__PURE__ */ jsx(TbCircleFilled, { color: color2 ?? borderColor }) });
26580
26581
  }
26581
26582
  default:
@@ -26592,7 +26593,7 @@ const LegendItem = ({
26592
26593
  return /* @__PURE__ */ jsxs(
26593
26594
  "div",
26594
26595
  {
26595
- className: cx(styles$3.legendItem, hidden && styles$3.isHidden),
26596
+ className: cx(styles$3 == null ? void 0 : styles$3.legendItem, hidden && (styles$3 == null ? void 0 : styles$3.isHidden)),
26596
26597
  onClick: handleClick,
26597
26598
  children: [
26598
26599
  /* @__PURE__ */ jsx(
@@ -26603,7 +26604,7 @@ const LegendItem = ({
26603
26604
  children: renderLegendItemSymbol(dataset, chartType, index2)
26604
26605
  }
26605
26606
  ),
26606
- /* @__PURE__ */ jsx("span", { className: styles$3.legendItemText, children: dataset.label })
26607
+ /* @__PURE__ */ jsx("span", { className: styles$3.legendItemText, children: dataset == null ? void 0 : dataset.label })
26607
26608
  ]
26608
26609
  }
26609
26610
  );
@@ -26645,7 +26646,7 @@ const getGeneratedLabels = (chart2) => {
26645
26646
  const useGeneratedLabels = (chartRef, generatedDatasets) => {
26646
26647
  const [items, setItems] = useState([]);
26647
26648
  useEffect(() => {
26648
- const chart2 = chartRef.current;
26649
+ const chart2 = chartRef == null ? void 0 : chartRef.current;
26649
26650
  if (!chart2)
26650
26651
  return;
26651
26652
  const newItems = getGeneratedLabels(chart2);
@@ -26658,10 +26659,10 @@ const createLegendStyle = (legendPosition, chart2) => {
26658
26659
  const { height = 0, width = 0, chartArea } = chart2 ?? {};
26659
26660
  const { top: top2 = 0, left: left2 = 0, bottom: bottom2 = 0, right: right2 = 0 } = chartArea ?? {};
26660
26661
  return {
26661
- left: legendPosition.includes("left") ? left2 : void 0,
26662
- right: legendPosition.includes("right") ? width - right2 : void 0,
26663
- top: legendPosition.includes("top") ? top2 : void 0,
26664
- bottom: legendPosition.includes("bottom") ? height - bottom2 : void 0,
26662
+ left: (legendPosition == null ? void 0 : legendPosition.includes("left")) ? left2 : void 0,
26663
+ right: (legendPosition == null ? void 0 : legendPosition.includes("right")) ? width - right2 : void 0,
26664
+ top: (legendPosition == null ? void 0 : legendPosition.includes("top")) ? top2 : void 0,
26665
+ bottom: (legendPosition == null ? void 0 : legendPosition.includes("bottom")) ? height - bottom2 : void 0,
26665
26666
  maxHeight: 0.5 * (bottom2 - top2 - LEGEND_MARGIN * 2),
26666
26667
  maxWidth: 0.9 * (right2 - left2 - LEGEND_MARGIN * 2),
26667
26668
  margin: LEGEND_MARGIN
@@ -26672,27 +26673,28 @@ const LegendItems = ({
26672
26673
  datasets,
26673
26674
  legendClick,
26674
26675
  chartType
26675
- }) => /* @__PURE__ */ jsx("div", { className: styles$3.legendItems, children: items.map((item, index2) => {
26676
- if (datasets[item.datasetIndex].hideLegend) {
26676
+ }) => /* @__PURE__ */ jsx("div", { className: styles$3.legendItems, children: items == null ? void 0 : items.map((item, index2) => {
26677
+ var _a2;
26678
+ if ((_a2 = datasets == null ? void 0 : datasets[item == null ? void 0 : item.datasetIndex]) == null ? void 0 : _a2.hideLegend) {
26677
26679
  return null;
26678
26680
  }
26679
26681
  return /* @__PURE__ */ jsx(
26680
26682
  LegendItem,
26681
26683
  {
26682
26684
  index: index2,
26683
- hidden: item.hidden,
26684
- dataset: datasets[item.datasetIndex],
26685
+ hidden: item == null ? void 0 : item.hidden,
26686
+ dataset: datasets == null ? void 0 : datasets[item == null ? void 0 : item.datasetIndex],
26685
26687
  handleClick: (_2) => legendClick(_2, item),
26686
26688
  chartType
26687
26689
  },
26688
- `${item.datasetIndex}-hidden-${item.hidden}`
26690
+ `${item == null ? void 0 : item.datasetIndex}-hidden-${item == null ? void 0 : item.hidden}`
26689
26691
  );
26690
26692
  }) });
26691
26693
  const LegendPanel = forwardRef(
26692
26694
  ({ legendPosition, chartRef, isDragging: isDragging2, legendConfig }, ref) => {
26693
26695
  var _a2;
26694
26696
  const chart2 = chartRef == null ? void 0 : chartRef.current;
26695
- const { options, generatedDatasets, chartType } = legendConfig;
26697
+ const { options, generatedDatasets, chartType } = legendConfig ?? {};
26696
26698
  const datasets = (_a2 = chart2 == null ? void 0 : chart2.data) == null ? void 0 : _a2.datasets;
26697
26699
  const { legend: legend2, legendClick } = useLegendState({
26698
26700
  chartRef,
@@ -26736,13 +26738,17 @@ const LegendPanel = forwardRef(
26736
26738
  }
26737
26739
  );
26738
26740
  const LegendDropZone = (legendDropZoneProps) => {
26739
- const { position, onDrop, placeholderSize } = legendDropZoneProps;
26741
+ const {
26742
+ position = "",
26743
+ onDrop = noop$2,
26744
+ placeholderSize = {}
26745
+ } = legendDropZoneProps ?? {};
26740
26746
  const [{ isOver, canDrop }, dropRef] = useDrop(() => ({
26741
26747
  accept: "legend",
26742
26748
  drop: onDrop,
26743
26749
  collect: (monitor) => ({
26744
- isOver: monitor.isOver(),
26745
- canDrop: monitor.canDrop()
26750
+ isOver: monitor == null ? void 0 : monitor.isOver(),
26751
+ canDrop: monitor == null ? void 0 : monitor.canDrop()
26746
26752
  })
26747
26753
  }));
26748
26754
  const isActive2 = isOver && canDrop;
@@ -26753,10 +26759,10 @@ const LegendDropZone = (legendDropZoneProps) => {
26753
26759
  className: cx(
26754
26760
  styles$3.dropzone,
26755
26761
  isActive2 && styles$3.isActive,
26756
- position.includes("left") && styles$3.left,
26757
- position.includes("right") && styles$3.right,
26758
- position.includes("top") && styles$3.top,
26759
- position.includes("bottom") && styles$3.bottom
26762
+ (position == null ? void 0 : position.includes("left")) && styles$3.left,
26763
+ (position == null ? void 0 : position.includes("right")) && styles$3.right,
26764
+ (position == null ? void 0 : position.includes("top")) && styles$3.top,
26765
+ (position == null ? void 0 : position.includes("bottom")) && styles$3.bottom
26760
26766
  ),
26761
26767
  children: /* @__PURE__ */ jsx(
26762
26768
  "div",
@@ -26789,7 +26795,7 @@ const LegendDropZones = (legendDropZonesProps) => {
26789
26795
  zIndex: isDragging2 ? 0 : -1
26790
26796
  // Position dropzones behind chart when not needed
26791
26797
  },
26792
- children: positions2.map((position) => /* @__PURE__ */ jsx(
26798
+ children: positions2 == null ? void 0 : positions2.map((position) => /* @__PURE__ */ jsx(
26793
26799
  LegendDropZone,
26794
26800
  {
26795
26801
  position,
@@ -26803,24 +26809,32 @@ const LegendDropZones = (legendDropZonesProps) => {
26803
26809
  };
26804
26810
  const Legend2 = ({ chartRef, legendConfig }) => {
26805
26811
  const chart2 = chartRef == null ? void 0 : chartRef.current;
26806
- const { chartArea } = chart2 ?? {};
26812
+ const [chartArea, setChartArea] = useState(
26813
+ chart2 == null ? void 0 : chart2.chartArea
26814
+ );
26807
26815
  const {
26808
26816
  options: { legend: legend2 }
26809
26817
  } = legendConfig ?? {};
26810
- const [measureRef] = useMeasure$1();
26818
+ const [measureRef, measureRect2] = useMeasure$1();
26811
26819
  const resizeRef = measureRef;
26812
26820
  const panelRef = useRef(null);
26813
26821
  const [legendPosition, setLegendPosition] = useState(
26814
26822
  (legend2 == null ? void 0 : legend2.position) || Position.BottomLeft
26815
26823
  );
26816
- const panelRect = panelRef.current ? panelRef.current.getBoundingClientRect() : null;
26824
+ const panelRect = (panelRef == null ? void 0 : panelRef.current) ? panelRef.current.getBoundingClientRect() : null;
26817
26825
  const panelSize = { width: panelRect == null ? void 0 : panelRect.width, height: panelRect == null ? void 0 : panelRect.height };
26818
- const [{ isDragging: isDragging2 }, dragRef] = useDrag(() => ({
26826
+ const [{ isDragging: isDragging2 = false }, dragRef = noop$2] = useDrag(() => ({
26819
26827
  type: "legend",
26820
26828
  collect: (monitor) => ({
26821
26829
  isDragging: monitor.isDragging()
26822
26830
  })
26823
26831
  }));
26832
+ useEffect(() => {
26833
+ const timeout = setTimeout(() => {
26834
+ setChartArea(chart2 == null ? void 0 : chart2.chartArea);
26835
+ }, 20);
26836
+ return () => clearTimeout(timeout);
26837
+ }, [measureRect2]);
26824
26838
  return /* @__PURE__ */ jsxs(Fragment, { children: [
26825
26839
  /* @__PURE__ */ jsx("div", { ref: resizeRef, className: styles$3.resizeContainer }),
26826
26840
  /* @__PURE__ */ jsx(
@@ -26843,7 +26857,8 @@ const Legend2 = ({ chartRef, legendConfig }) => {
26843
26857
  setLegendPosition: (position) => setLegendPosition(position),
26844
26858
  isDragging: isDragging2,
26845
26859
  placeholderSize: panelSize
26846
- }
26860
+ },
26861
+ measureRect2.width
26847
26862
  )
26848
26863
  ] });
26849
26864
  };