@oliasoft-open-source/charts-library 7.0.1 → 8.0.0-beta-2
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/README.md +15 -0
- package/dist/index.d.ts +26 -12
- package/dist/index.js +34 -40
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,20 @@ You do not need to pass these objects: omitted options receive these values auto
|
|
|
19
19
|
- The snapshots describe the initial empty configuration. Per-item defaults for supplied annotations and DS are
|
|
20
20
|
applied separately by their normalizers and renderers.
|
|
21
21
|
|
|
22
|
+
## Migrating LineChart tooltips to 8.0
|
|
23
|
+
|
|
24
|
+
Tooltip coordinate roles no longer depend on axis placement. The default title shows X and the DS row shows Y.
|
|
25
|
+
Set `options.tooltip.titleAxis` to `'y'` when the title should show Y and the DS row should show X.
|
|
26
|
+
Charts that previously relied on a top-positioned X axis must set this explicitly to preserve their tooltip order.
|
|
27
|
+
If your application swaps X/Y coordinates, update `titleAxis` to keep the intended quantity in the title.
|
|
28
|
+
This setting does not move axes, reverse scales or transpose data.
|
|
29
|
+
|
|
30
|
+
The default DS row reads units from the corresponding axis `unit` string or `unit.selectedUnit` when non-empty,
|
|
31
|
+
then falls back to units in square brackets in that axis label. The title appends its axis label.
|
|
32
|
+
Each hovered DS uses its own axis bindings, including numbered IDs such as `x10` and `y10`.
|
|
33
|
+
Time and category values retain their formatted labels. Custom `title`, `label` and `afterLabel` callbacks
|
|
34
|
+
continue to override their respective defaults independently.
|
|
35
|
+
|
|
22
36
|
## LineChart
|
|
23
37
|
|
|
24
38
|
```ts
|
|
@@ -95,6 +109,7 @@ const defaultChart = {
|
|
|
95
109
|
hideSimulationName: false,
|
|
96
110
|
scientificNotation: true,
|
|
97
111
|
callbacks: undefined,
|
|
112
|
+
titleAxis: 'x',
|
|
98
113
|
},
|
|
99
114
|
graph: {
|
|
100
115
|
lineTension: 0.01,
|
package/dist/index.d.ts
CHANGED
|
@@ -1106,13 +1106,14 @@ export declare interface ILineChartAxis<PositionType = TAxisPosition> {
|
|
|
1106
1106
|
id?: string;
|
|
1107
1107
|
/** Axis title, also appended to the default tooltip title when this is the selected title axis. */
|
|
1108
1108
|
label?: string;
|
|
1109
|
-
/**
|
|
1109
|
+
/** Visual axis placement; does not affect tooltip coordinate roles. */
|
|
1110
1110
|
position?: PositionType;
|
|
1111
1111
|
/** Canvas/CSS colour used by this element. */
|
|
1112
1112
|
color?: string | string[];
|
|
1113
1113
|
/**
|
|
1114
1114
|
* Unit metadata or a consumer-owned unit selector. Does not convert DS coordinates.
|
|
1115
|
-
*
|
|
1115
|
+
* The default DS tooltip row uses this string or `selectedUnit` when non-empty, otherwise it extracts
|
|
1116
|
+
* units from square brackets in the value-axis label. The title uses the title-axis label instead.
|
|
1116
1117
|
*/
|
|
1117
1118
|
unit?: IUnitOptions | string;
|
|
1118
1119
|
/** Requested spacing between axis ticks, in scale units. */
|
|
@@ -1340,15 +1341,28 @@ export declare interface ILineChartStyling extends ICommonStyling {
|
|
|
1340
1341
|
}
|
|
1341
1342
|
|
|
1342
1343
|
/**
|
|
1343
|
-
* LineChart tooltip formatting and callback overrides.
|
|
1344
|
-
*
|
|
1345
|
-
* Otherwise, the title uses X and the DS row uses Y. Callbacks can override this formatting.
|
|
1344
|
+
* LineChart tooltip formatting and callback overrides, independent of axis placement.
|
|
1345
|
+
* By default the title uses X and the DS row uses Y; `titleAxis` swaps these coordinate roles.
|
|
1346
1346
|
*/
|
|
1347
1347
|
export declare interface ILineChartTooltip extends ICommonTooltip {
|
|
1348
1348
|
/** Compatibility flag retained by LineChart; currently does not alter tooltip text. */
|
|
1349
1349
|
hideSimulationName?: boolean;
|
|
1350
1350
|
/** Allows scientific notation when formatting tooltip numbers. Defaults to true. */
|
|
1351
1351
|
scientificNotation?: boolean;
|
|
1352
|
+
/**
|
|
1353
|
+
* Axis whose value and axis label appear in the default tooltip title.
|
|
1354
|
+
* The other axis supplies the value beside the DS name. Does not move or reverse axes.
|
|
1355
|
+
* Axis configuration is resolved from the hovered DS axis IDs (`x`, `x2`, `y`, `y2`, ...).
|
|
1356
|
+
* Time and category values use formatted scale values rather than raw numeric coordinates.
|
|
1357
|
+
* Custom title and label callbacks override their respective defaults independently.
|
|
1358
|
+
* Update this option when swapping data coordinates if the same quantity should remain in the title.
|
|
1359
|
+
* @defaultValue 'x'
|
|
1360
|
+
* @example
|
|
1361
|
+
* ```ts
|
|
1362
|
+
* const tooltip: ILineChartTooltip = { titleAxis: 'y' };
|
|
1363
|
+
* ```
|
|
1364
|
+
*/
|
|
1365
|
+
titleAxis?: `${AxisType}`;
|
|
1352
1366
|
}
|
|
1353
1367
|
|
|
1354
1368
|
/** LineChart pointer, legend and animation lifecycle callbacks. */
|
|
@@ -2206,25 +2220,25 @@ export { }
|
|
|
2206
2220
|
|
|
2207
2221
|
declare module 'chart.js' {
|
|
2208
2222
|
interface PluginOptionsByType<TType extends ChartType> {
|
|
2209
|
-
|
|
2210
|
-
enabled?: boolean;
|
|
2211
|
-
} | TLineMarkersOptions;
|
|
2223
|
+
annotationDraggerPlugin?: AnnotationDraggerPluginOptions;
|
|
2212
2224
|
}
|
|
2213
2225
|
}
|
|
2214
2226
|
|
|
2215
2227
|
|
|
2216
2228
|
declare module 'chart.js' {
|
|
2217
2229
|
interface PluginOptionsByType<TType extends ChartType> {
|
|
2218
|
-
|
|
2230
|
+
calloutConnectorPlugin?: {
|
|
2231
|
+
enableCalloutAnnotation?: boolean;
|
|
2232
|
+
};
|
|
2219
2233
|
}
|
|
2220
2234
|
}
|
|
2221
2235
|
|
|
2222
2236
|
|
|
2223
2237
|
declare module 'chart.js' {
|
|
2224
2238
|
interface PluginOptionsByType<TType extends ChartType> {
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
};
|
|
2239
|
+
lineMarkersPlugin?: {
|
|
2240
|
+
enabled?: boolean;
|
|
2241
|
+
} | TLineMarkersOptions;
|
|
2228
2242
|
}
|
|
2229
2243
|
}
|
|
2230
2244
|
|
package/dist/index.js
CHANGED
|
@@ -20559,7 +20559,8 @@ var defaultTooltip$3 = (tooltip) => ({
|
|
|
20559
20559
|
showLabelsInTooltips: tooltip?.showLabelsInTooltips ?? false,
|
|
20560
20560
|
hideSimulationName: tooltip?.hideSimulationName ?? false,
|
|
20561
20561
|
scientificNotation: tooltip?.scientificNotation ?? true,
|
|
20562
|
-
callbacks: tooltip?.callbacks
|
|
20562
|
+
callbacks: tooltip?.callbacks,
|
|
20563
|
+
titleAxis: tooltip?.titleAxis ?? AxisType.X
|
|
20563
20564
|
});
|
|
20564
20565
|
var defaultGraph$3 = (graph) => ({
|
|
20565
20566
|
lineTension: graph?.lineTension ?? .01,
|
|
@@ -21212,45 +21213,38 @@ var getLineChartToolTips = (options) => {
|
|
|
21212
21213
|
callbacks: {}
|
|
21213
21214
|
};
|
|
21214
21215
|
}
|
|
21215
|
-
const { scientificNotation = true } = options?.tooltip ?? {};
|
|
21216
|
-
const
|
|
21217
|
-
|
|
21218
|
-
const
|
|
21219
|
-
const
|
|
21220
|
-
const
|
|
21221
|
-
|
|
21222
|
-
|
|
21223
|
-
|
|
21224
|
-
|
|
21225
|
-
|
|
21226
|
-
|
|
21227
|
-
|
|
21228
|
-
|
|
21229
|
-
|
|
21230
|
-
|
|
21231
|
-
|
|
21232
|
-
|
|
21233
|
-
|
|
21234
|
-
|
|
21235
|
-
|
|
21236
|
-
const
|
|
21237
|
-
|
|
21238
|
-
const
|
|
21239
|
-
|
|
21240
|
-
|
|
21241
|
-
|
|
21242
|
-
|
|
21243
|
-
|
|
21244
|
-
const
|
|
21245
|
-
|
|
21246
|
-
|
|
21247
|
-
const getTooltipItemValue = () => {
|
|
21248
|
-
const valueAxisId = valueLabel === TooltipLabel.X ? tooltipItem.dataset?.xAxisID ?? "x" : tooltipItem.dataset?.yAxisID ?? "y";
|
|
21249
|
-
const valueScaleType = options?.scales?.[valueAxisId]?.type;
|
|
21250
|
-
if ((isTimeScaleType(valueScaleType) || valueScaleType === "category") && tooltipItem.label) return tooltipItem.label;
|
|
21251
|
-
return customFormatNumber$1(valueLabel === TooltipLabel.X ? tooltipItem?.parsed?.x : tooltipItem?.parsed?.y, scientificNotation);
|
|
21252
|
-
};
|
|
21253
|
-
return `${label}: ${getTooltipItemValue()} ${getUnitsFromLabel(valueAxisLabel)} ${getTooltipLabel(tooltipItem, showLabelsInTooltips)}`;
|
|
21216
|
+
const { scientificNotation = true, showLabelsInTooltips = false, titleAxis = AxisType.X } = options?.tooltip ?? {};
|
|
21217
|
+
const valueAxis = titleAxis === AxisType.X ? AxisType.Y : AxisType.X;
|
|
21218
|
+
const getAxis = (item, axis) => {
|
|
21219
|
+
const axisIdKey = `${axis}AxisID`;
|
|
21220
|
+
const id = item.dataset[axisIdKey] || axis;
|
|
21221
|
+
const index = id === axis ? 0 : toNum(id.slice(1)) - 1;
|
|
21222
|
+
return {
|
|
21223
|
+
id,
|
|
21224
|
+
config: options.axes[axis][index]
|
|
21225
|
+
};
|
|
21226
|
+
};
|
|
21227
|
+
const formatValue = (item, axis) => {
|
|
21228
|
+
const { id } = getAxis(item, axis);
|
|
21229
|
+
const scale = item.chart?.scales[id];
|
|
21230
|
+
const scaleType = scale?.type ?? options.scales?.[id]?.type;
|
|
21231
|
+
const value = item.parsed[axis];
|
|
21232
|
+
if (value === null || value === void 0) return "";
|
|
21233
|
+
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);
|
|
21234
|
+
return customFormatNumber$1(value, scientificNotation);
|
|
21235
|
+
};
|
|
21236
|
+
const titleCallback = (items) => {
|
|
21237
|
+
const item = items?.[0];
|
|
21238
|
+
if (!item) return "";
|
|
21239
|
+
const { config } = getAxis(item, titleAxis);
|
|
21240
|
+
return `${formatValue(item, titleAxis)} ${config?.label || ""}`;
|
|
21241
|
+
};
|
|
21242
|
+
const labelCallback = (item) => {
|
|
21243
|
+
const { config } = getAxis(item, valueAxis);
|
|
21244
|
+
const units = (typeof config?.unit === "string" ? config.unit : config?.unit?.selectedUnit) || getUnitsFromLabel(config?.label || "");
|
|
21245
|
+
const label = item.dataset.label || "";
|
|
21246
|
+
const pointLabel = getTooltipLabel(item, showLabelsInTooltips);
|
|
21247
|
+
return `${label}: ${formatValue(item, valueAxis)} ${units} ${pointLabel}`;
|
|
21254
21248
|
};
|
|
21255
21249
|
const userCallbacks = options?.tooltip?.callbacks ?? null;
|
|
21256
21250
|
const callbacks = {
|
package/package.json
CHANGED