@oliasoft-open-source/charts-library 7.0.0 → 8.0.0-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.d.ts CHANGED
@@ -769,6 +769,7 @@ export declare interface ILineChartStyling extends ICommonStyling {
769
769
  export declare interface ILineChartTooltip extends ICommonTooltip {
770
770
  hideSimulationName?: boolean;
771
771
  scientificNotation?: boolean;
772
+ titleAxis?: `${AxisType}`;
772
773
  }
773
774
 
774
775
  export declare interface ILineInteractions extends ICommonInteractions {
@@ -1235,13 +1236,6 @@ export declare type UnusedParameter = unknown;
1235
1236
  export { }
1236
1237
 
1237
1238
 
1238
- declare module 'chart.js' {
1239
- interface PluginOptionsByType<TType extends ChartType> {
1240
- annotationDraggerPlugin?: AnnotationDraggerPluginOptions;
1241
- }
1242
- }
1243
-
1244
-
1245
1239
  declare module 'chart.js' {
1246
1240
  interface PluginOptionsByType<TType extends ChartType> {
1247
1241
  calloutConnectorPlugin?: {
@@ -1260,6 +1254,13 @@ declare module 'chart.js' {
1260
1254
  }
1261
1255
 
1262
1256
 
1257
+ declare module 'chart.js' {
1258
+ interface PluginOptionsByType<TType extends ChartType> {
1259
+ annotationDraggerPlugin?: AnnotationDraggerPluginOptions;
1260
+ }
1261
+ }
1262
+
1263
+
1263
1264
 
1264
1265
  declare module 'react-base64-downloader' {
1265
1266
  export function triggerBase64Download(base64: string, filename: string): void;
package/dist/index.js CHANGED
@@ -20540,7 +20540,8 @@ var defaultTooltip$3 = (tooltip) => ({
20540
20540
  showLabelsInTooltips: tooltip?.showLabelsInTooltips ?? false,
20541
20541
  hideSimulationName: tooltip?.hideSimulationName ?? false,
20542
20542
  scientificNotation: tooltip?.scientificNotation ?? true,
20543
- callbacks: tooltip?.callbacks
20543
+ callbacks: tooltip?.callbacks,
20544
+ titleAxis: tooltip?.titleAxis ?? AxisType.X
20544
20545
  });
20545
20546
  var defaultGraph$3 = (graph) => ({
20546
20547
  lineTension: graph?.lineTension ?? .01,
@@ -21193,45 +21194,38 @@ var getLineChartToolTips = (options) => {
21193
21194
  callbacks: {}
21194
21195
  };
21195
21196
  }
21196
- const { scientificNotation = true } = options?.tooltip ?? {};
21197
- const getTooltipLabels = ({ xAxisID = "", yAxisID = "" }) => {
21198
- const xIndex = xAxisID?.length > 1 ? Number(xAxisID?.[1]) - 1 : 0;
21199
- const yIndex = yAxisID?.length > 1 ? Number(yAxisID?.[1]) - 1 : 0;
21200
- const xAxis = options?.axes?.x?.[xIndex];
21201
- const yAxis = options?.axes?.y?.[yIndex];
21202
- if (options?.axes?.x?.[0]?.position === Position.Top) return {
21203
- titleAxisLabel: yAxis?.label || "",
21204
- valueAxisLabel: xAxis?.label || "",
21205
- titleLabel: TooltipLabel.Y,
21206
- valueLabel: TooltipLabel.X
21207
- };
21208
- else return {
21209
- titleAxisLabel: xAxis?.label || "",
21210
- valueAxisLabel: yAxis?.label || "",
21211
- titleLabel: TooltipLabel.X,
21212
- valueLabel: TooltipLabel.Y
21213
- };
21214
- };
21215
- const titleCallback = (tooltipItem) => {
21216
- if (!tooltipItem?.[0]) return "";
21217
- const { titleLabel = "", titleAxisLabel = "" } = getTooltipLabels(tooltipItem[0].dataset) ?? {};
21218
- const titleAxisId = titleLabel === TooltipLabel.Y ? tooltipItem[0].dataset?.yAxisID ?? "y" : tooltipItem[0].dataset?.xAxisID ?? "x";
21219
- const titleScaleType = options?.scales?.[titleAxisId]?.type;
21220
- const titleValue = isTimeScaleType(titleScaleType) || titleScaleType === "category" ? tooltipItem[0].label : void 0;
21221
- const formattedValue = titleLabel === TooltipLabel.Y ? tooltipItem?.[0]?.parsed?.y : tooltipItem?.[0]?.parsed?.x;
21222
- return `${titleValue ?? customFormatNumber$1(formattedValue, scientificNotation)} ${titleAxisLabel}`;
21223
- };
21224
- const labelCallback = (tooltipItem) => {
21225
- const { showLabelsInTooltips = false } = options?.tooltip ?? {};
21226
- let label = tooltipItem?.dataset?.label || "";
21227
- const { valueLabel = "", valueAxisLabel = "" } = getTooltipLabels(tooltipItem?.dataset) ?? {};
21228
- const getTooltipItemValue = () => {
21229
- const valueAxisId = valueLabel === TooltipLabel.X ? tooltipItem.dataset?.xAxisID ?? "x" : tooltipItem.dataset?.yAxisID ?? "y";
21230
- const valueScaleType = options?.scales?.[valueAxisId]?.type;
21231
- if ((isTimeScaleType(valueScaleType) || valueScaleType === "category") && tooltipItem.label) return tooltipItem.label;
21232
- return customFormatNumber$1(valueLabel === TooltipLabel.X ? tooltipItem?.parsed?.x : tooltipItem?.parsed?.y, scientificNotation);
21233
- };
21234
- return `${label}: ${getTooltipItemValue()} ${getUnitsFromLabel(valueAxisLabel)} ${getTooltipLabel(tooltipItem, showLabelsInTooltips)}`;
21197
+ const { scientificNotation = true, showLabelsInTooltips = false, titleAxis = AxisType.X } = options?.tooltip ?? {};
21198
+ const valueAxis = titleAxis === AxisType.X ? AxisType.Y : AxisType.X;
21199
+ const getAxis = (item, axis) => {
21200
+ const axisIdKey = `${axis}AxisID`;
21201
+ const id = item.dataset[axisIdKey] || axis;
21202
+ const index = id === axis ? 0 : toNum(id.slice(1)) - 1;
21203
+ return {
21204
+ id,
21205
+ config: options.axes[axis][index]
21206
+ };
21207
+ };
21208
+ const formatValue = (item, axis) => {
21209
+ const { id } = getAxis(item, axis);
21210
+ const scale = item.chart?.scales[id];
21211
+ const scaleType = scale?.type ?? options.scales?.[id]?.type;
21212
+ const value = item.parsed[axis];
21213
+ if (value === null || value === void 0) return "";
21214
+ if (scaleType === ScaleType.Time || scaleType === ScaleType.TimeSeries || scaleType === ScaleType.Category) return (axis === (item.chart?.getDatasetMeta(item.datasetIndex).iScale?.axis ?? AxisType.X) ? item.label : item.formattedValue) || scale?.getLabelForValue(value) || String(value);
21215
+ return customFormatNumber$1(value, scientificNotation);
21216
+ };
21217
+ const titleCallback = (items) => {
21218
+ const item = items?.[0];
21219
+ if (!item) return "";
21220
+ const { config } = getAxis(item, titleAxis);
21221
+ return `${formatValue(item, titleAxis)} ${config?.label || ""}`;
21222
+ };
21223
+ const labelCallback = (item) => {
21224
+ const { config } = getAxis(item, valueAxis);
21225
+ const units = (typeof config?.unit === "string" ? config.unit : config?.unit?.selectedUnit) || getUnitsFromLabel(config?.label || "");
21226
+ const label = item.dataset.label || "";
21227
+ const pointLabel = getTooltipLabel(item, showLabelsInTooltips);
21228
+ return `${label}: ${formatValue(item, valueAxis)} ${units} ${pointLabel}`;
21235
21229
  };
21236
21230
  const userCallbacks = options?.tooltip?.callbacks ?? null;
21237
21231
  const callbacks = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/charts-library",
3
- "version": "7.0.0",
3
+ "version": "8.0.0-beta-1",
4
4
  "description": "React Chart Library (based on Chart.js and react-chart-js-2)",
5
5
  "homepage": "https://gitlab.com/oliasoft-open-source/charts-library",
6
6
  "bugs": {