@oliasoft-open-source/charts-library 3.6.2 → 3.6.4

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
@@ -11,7 +11,7 @@ import { round as round$2, displayNumber, isCloseTo, roundByMagnitude, toNum } f
11
11
  import cx from "classnames";
12
12
  import { produce } from "immer";
13
13
  import { Icon, Tooltip as Tooltip$2, Button, Flex, Text, Menu, Popover, Field, InputGroup, NumberInput, InputGroupAddon, Select, ButtonGroup, Spacer, Portal } from "@oliasoft-open-source/react-ui-library";
14
- import { debounce as debounce$3, isEqual } from "lodash";
14
+ import { isEmpty, isArray as isArray$2, some, has, debounce as debounce$3, isEqual } from "lodash";
15
15
  import { roundNumberToPrecision } from "@oliasoft-open-source/units/dist/rounding/rounding";
16
16
  /*!
17
17
  * @kurkle/color v0.3.2
@@ -22877,7 +22877,8 @@ const LineOptions = ({
22877
22877
  onToggleLine,
22878
22878
  onTogglePoints,
22879
22879
  pointsEnabled,
22880
- translations
22880
+ translations,
22881
+ hasCustomOpt
22881
22882
  }) => {
22882
22883
  const options = [
22883
22884
  {
@@ -22907,17 +22908,26 @@ const LineOptions = ({
22907
22908
  }
22908
22909
  ];
22909
22910
  const selectedOption = options.find((option) => option.selected);
22910
- return /* @__PURE__ */ jsx(Tooltip$2, { text: selectedOption == null ? void 0 : selectedOption.label, placement: "bottom", children: /* @__PURE__ */ jsx(
22911
- Button,
22911
+ return /* @__PURE__ */ jsx(
22912
+ Tooltip$2,
22912
22913
  {
22913
- small: true,
22914
- basic: true,
22915
- colored: "muted",
22916
- round: true,
22917
- icon: selectedOption == null ? void 0 : selectedOption.icon,
22918
- onClick: selectedOption == null ? void 0 : selectedOption.onClick
22914
+ text: selectedOption == null ? void 0 : selectedOption.label,
22915
+ placement: "bottom",
22916
+ enabled: !hasCustomOpt,
22917
+ children: /* @__PURE__ */ jsx(
22918
+ Button,
22919
+ {
22920
+ small: true,
22921
+ basic: true,
22922
+ colored: "muted",
22923
+ round: true,
22924
+ icon: selectedOption == null ? void 0 : selectedOption.icon,
22925
+ onClick: selectedOption == null ? void 0 : selectedOption.onClick,
22926
+ disabled: hasCustomOpt
22927
+ }
22928
+ )
22919
22929
  }
22920
- ) });
22930
+ );
22921
22931
  };
22922
22932
  function TbHandStop(props) {
22923
22933
  return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24", "strokeWidth": "2", "stroke": "currentColor", "fill": "none", "strokeLinecap": "round", "strokeLinejoin": "round" }, "child": [{ "tag": "path", "attr": { "stroke": "none", "d": "M0 0h24v24H0z", "fill": "none" } }, { "tag": "path", "attr": { "d": "M8 13v-7.5a1.5 1.5 0 0 1 3 0v6.5" } }, { "tag": "path", "attr": { "d": "M11 5.5v-2a1.5 1.5 0 1 1 3 0v8.5" } }, { "tag": "path", "attr": { "d": "M14 5.5a1.5 1.5 0 0 1 3 0v6.5" } }, { "tag": "path", "attr": { "d": "M17 7.5a1.5 1.5 0 0 1 3 0v8.5a6 6 0 0 1 -6 6h-2h.208a6 6 0 0 1 -5.012 -2.7a69.74 69.74 0 0 1 -.196 -.3c-.312 -.479 -1.407 -2.388 -3.286 -5.728a1.5 1.5 0 0 1 .536 -2.022a1.867 1.867 0 0 1 2.28 .28l1.47 1.47" } }] })(props);
@@ -24489,6 +24499,27 @@ const ControlsPortal = ({
24489
24499
  }
24490
24500
  return children;
24491
24501
  };
24502
+ const checkCustomOption = (data, customOptions) => {
24503
+ if (isEmpty(data) || isEmpty(customOptions))
24504
+ return false;
24505
+ const checkOption = (dataset) => {
24506
+ if (typeof customOptions === "string") {
24507
+ return has(dataset, customOptions);
24508
+ } else if (isArray$2(customOptions)) {
24509
+ return some(customOptions, (option) => has(dataset, option));
24510
+ } else {
24511
+ return some(
24512
+ Object.values(customOptions),
24513
+ (option) => has(dataset, option)
24514
+ );
24515
+ }
24516
+ };
24517
+ if (isArray$2(data)) {
24518
+ return some(data, (dataset) => checkOption(dataset));
24519
+ } else {
24520
+ return checkOption(data);
24521
+ }
24522
+ };
24492
24523
  const Controls = ({
24493
24524
  headerComponent,
24494
24525
  subheaderComponent,
@@ -24533,6 +24564,7 @@ const Controls = ({
24533
24564
  dispatch,
24534
24565
  generatedDatasets
24535
24566
  });
24567
+ const hasCustomOpt = checkCustomOption(generatedDatasets, "hasCustomOpt");
24536
24568
  return /* @__PURE__ */ jsxs(Fragment, { children: [
24537
24569
  /* @__PURE__ */ jsxs("div", { className: styles$3.controls, children: [
24538
24570
  !!options.title && /* @__PURE__ */ jsx(Text, { bold: true, children: options.title }),
@@ -24558,7 +24590,8 @@ const Controls = ({
24558
24590
  pointsEnabled,
24559
24591
  onToggleLine,
24560
24592
  onTogglePoints,
24561
- translations
24593
+ translations,
24594
+ hasCustomOpt
24562
24595
  }
24563
24596
  ),
24564
24597
  /* @__PURE__ */ jsx(
@@ -25135,6 +25168,11 @@ const INIT_KEYS = {
25135
25168
  };
25136
25169
  const LOWER_BOUND = 1e-4;
25137
25170
  const UPPER_BOUND = 1e7;
25171
+ var CUSTOM_OPTION = /* @__PURE__ */ ((CUSTOM_OPTION2) => {
25172
+ CUSTOM_OPTION2["showLine"] = "showLine";
25173
+ CUSTOM_OPTION2["showPoints"] = "showPoints";
25174
+ return CUSTOM_OPTION2;
25175
+ })(CUSTOM_OPTION || {});
25138
25176
  const generateLineChartDatasets = (datasets, state, options, { label }) => {
25139
25177
  const copyDataset = [...datasets];
25140
25178
  const { annotations, graph } = options;
@@ -25176,7 +25214,9 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
25176
25214
  borderColor,
25177
25215
  backgroundColor,
25178
25216
  pointBackgroundColor,
25179
- borderDash
25217
+ borderDash,
25218
+ showPoints = true,
25219
+ showLine
25180
25220
  } = line ?? {};
25181
25221
  const { lineEnabled, pointsEnabled, axes = [] } = state ?? {};
25182
25222
  const { lineTension, spanGaps } = graph ?? {};
@@ -25194,14 +25234,15 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
25194
25234
  const filteredData = data.filter(Boolean) || [];
25195
25235
  const isSinglePoint = (filteredData == null ? void 0 : filteredData.length) === 1;
25196
25236
  const linePointRadius = parseFloat(pointRadiusProp) || DEFAULT_POINT_RADIUS;
25197
- const pointRadius = pointsEnabled || isSinglePoint ? linePointRadius : 0;
25237
+ const pointRadius = (pointsEnabled || isSinglePoint) && showPoints ? linePointRadius : 0;
25198
25238
  const hoverRadius = parseFloat(pointHoverRadius) || DEFAULT_HOVER_RADIUS;
25199
25239
  const indexedColor = COLORS[i2];
25240
+ const hasCustomOpt = checkCustomOption(line, CUSTOM_OPTION);
25200
25241
  return {
25201
25242
  ...line,
25202
25243
  label: line.label || `${label} ${i2 + 1}`,
25203
25244
  data: filteredData,
25204
- showLine: lineEnabled,
25245
+ showLine: showLine ?? lineEnabled,
25205
25246
  lineTension,
25206
25247
  spanGaps,
25207
25248
  borderWidth: parseFloat(borderWidth) || DEFAULT_BORDER_WIDTH,
@@ -25212,7 +25253,8 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
25212
25253
  pointBackgroundColor: pointBackgroundColor ?? indexedColor ?? generateRandomColor(COLORS),
25213
25254
  pointRadius,
25214
25255
  pointHoverRadius: hoverRadius,
25215
- pointHitRadius: line.pointHitRadius ?? hoverRadius
25256
+ pointHitRadius: line.pointHitRadius ?? hoverRadius,
25257
+ ...hasCustomOpt ? { hasCustomOpt } : {}
25216
25258
  };
25217
25259
  });
25218
25260
  };
@@ -25502,23 +25544,29 @@ const getLineChartDataLabels = (options) => {
25502
25544
  formatter: (_value, context) => context.dataset.data[context.dataIndex].label || ""
25503
25545
  } : { display: false };
25504
25546
  };
25505
- const annotationEnter = ({ element }, { chart: chart2 }) => {
25547
+ const annotationEnter = (element, chart2) => {
25506
25548
  var _a2;
25507
25549
  if ((_a2 = element.options.scaleID) == null ? void 0 : _a2.includes(AxisType.X)) {
25508
25550
  element.options.label.xAdjust = chart2.chartArea.left;
25509
25551
  }
25510
25552
  element.options.borderWidth = BORDER_WIDTH.HOVERED;
25511
- if (element.options.label)
25553
+ if (element.options.label) {
25554
+ element.label.options.display = true;
25512
25555
  element.options.label.enabled = true;
25556
+ }
25513
25557
  chart2.draw();
25514
25558
  chart2.canvas.style.cursor = CursorStyle.Pointer;
25559
+ return true;
25515
25560
  };
25516
- const annotationLeave = ({ element }, { chart: chart2 }) => {
25561
+ const annotationLeave = (element, chart2) => {
25517
25562
  element.options.borderWidth = BORDER_WIDTH.INITIAL;
25518
- if (element.options.label)
25563
+ if (element.options.label) {
25564
+ element.label.options.display = false;
25519
25565
  element.options.label.enabled = false;
25566
+ }
25520
25567
  chart2.draw();
25521
25568
  chart2.canvas.style.cursor = CursorStyle.Initial;
25569
+ return true;
25522
25570
  };
25523
25571
  const generateAnnotations = (options, state) => {
25524
25572
  const { annotationsData } = (options == null ? void 0 : options.annotations) || {};
@@ -25537,22 +25585,22 @@ const generateAnnotations = (options, state) => {
25537
25585
  const label = type === "line" ? {
25538
25586
  backgroundColor: color2,
25539
25587
  content: curr == null ? void 0 : curr.label,
25540
- enabled: false,
25588
+ display: false,
25541
25589
  position: Position.Top
25542
25590
  } : {
25543
25591
  content: curr == null ? void 0 : curr.label,
25544
- enabled: true,
25592
+ display: true,
25545
25593
  font: { weight: "normal" }
25546
25594
  };
25547
- const enter = (context, event) => {
25595
+ const enter = ({ element }, { chart: chart2 }) => {
25548
25596
  if (type !== "line")
25549
25597
  return;
25550
- annotationEnter(context, event);
25598
+ annotationEnter(element, chart2);
25551
25599
  };
25552
- const leave = (context, event) => {
25600
+ const leave = ({ element }, { chart: chart2 }) => {
25553
25601
  if (type !== "line")
25554
25602
  return;
25555
- annotationLeave(context, event);
25603
+ annotationLeave(element, chart2);
25556
25604
  };
25557
25605
  const annotation2 = {
25558
25606
  ...curr,