@oliasoft-open-source/charts-library 9.1.0-beta-2 → 9.1.0-beta-3
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
|
@@ -33200,7 +33200,17 @@ var getMinorTickPositions = (majorTickPositions, scale) => {
|
|
|
33200
33200
|
return parseFloat(minorTickPosition?.toFixed(1));
|
|
33201
33201
|
})?.filter((position) => isValidPosition(position, sortedMajorTickPositions, scale));
|
|
33202
33202
|
};
|
|
33203
|
-
var
|
|
33203
|
+
var getEqualScaleMinorTicks = (scale, majorPositions, step) => {
|
|
33204
|
+
const positions = [];
|
|
33205
|
+
const first = Math.ceil(scale.min / step);
|
|
33206
|
+
const last = Math.floor(scale.max / step);
|
|
33207
|
+
for (let index = first; index <= last; index++) {
|
|
33208
|
+
const position = scale.getPixelForValue(index * step);
|
|
33209
|
+
if (isValidPosition(position, majorPositions, scale) && !majorPositions.some((major) => Math.abs(major - position) < .1)) positions.push(position);
|
|
33210
|
+
}
|
|
33211
|
+
return positions;
|
|
33212
|
+
};
|
|
33213
|
+
var drawMinorTicksForScale = (scale, sharedStep) => {
|
|
33204
33214
|
const { chart, ctx } = scale ?? {};
|
|
33205
33215
|
if (!ctx || ctx?.canvas === null) return;
|
|
33206
33216
|
const config = chart?.config;
|
|
@@ -33208,7 +33218,7 @@ var drawMinorTicksForScale = (scale) => {
|
|
|
33208
33218
|
if (config?.options?.indexAxis === scale?.axis) return;
|
|
33209
33219
|
const isHorizontal = scale?.axis === AxisType.X;
|
|
33210
33220
|
const majorTickPositions = scale?.ticks?.map((_, index) => scale?.getPixelForTick(index))?.sort((a, b) => a - b);
|
|
33211
|
-
const minorTickPositions = getMinorTickPositions(majorTickPositions, scale);
|
|
33221
|
+
const minorTickPositions = sharedStep ? getEqualScaleMinorTicks(scale, majorTickPositions, sharedStep) : getMinorTickPositions(majorTickPositions, scale);
|
|
33212
33222
|
ctx?.save?.();
|
|
33213
33223
|
ctx.strokeStyle = config?._config?.options?.scales?.[scale.id]?.grid?.color || "rgba(0,0,0,0.06)";
|
|
33214
33224
|
ctx.lineWidth = .5;
|
|
@@ -33229,9 +33239,16 @@ var drawMinorTicksForScale = (scale) => {
|
|
|
33229
33239
|
};
|
|
33230
33240
|
var chartMinorGridlinesPlugin = {
|
|
33231
33241
|
id: "minorGridlines",
|
|
33232
|
-
beforeDatasetsDraw: (chart) => {
|
|
33233
|
-
const { scales } = chart
|
|
33234
|
-
|
|
33242
|
+
beforeDatasetsDraw: (chart, _args, { equalScale }) => {
|
|
33243
|
+
const { scales } = chart;
|
|
33244
|
+
const { x, y } = scales;
|
|
33245
|
+
let sharedStep;
|
|
33246
|
+
if (equalScale && Object.keys(scales).length === 2 && x?.type === "linear" && y?.type === "linear") {
|
|
33247
|
+
const majorSteps = [x, y].map((scale) => getLargestMajorTickWidth(scale.ticks.map(({ value }) => value)));
|
|
33248
|
+
const step = Math.min(...majorSteps) / MINOR_TICKS_PER_MAJOR;
|
|
33249
|
+
if (Number.isFinite(step) && step > 0) sharedStep = step;
|
|
33250
|
+
}
|
|
33251
|
+
Object.values(scales).forEach((scale) => drawMinorTicksForScale(scale, sharedStep));
|
|
33235
33252
|
}
|
|
33236
33253
|
};
|
|
33237
33254
|
// src/components/common/helpers/chart-consts.ts
|
|
@@ -36544,6 +36561,7 @@ var useChartOptions = ({ chartRef, state, options, dispatch, generatedDatasets,
|
|
|
36544
36561
|
const lineMarkersAnnotation = options?.annotations?.lineMarkersAnnotation ?? {};
|
|
36545
36562
|
const lineMarkersPluginEnabled = Boolean(options?.plugins?.lineMarkersPlugin?.enabled ?? lineMarkersAnnotation?.enabled);
|
|
36546
36563
|
const plugins = useMemo(() => ({
|
|
36564
|
+
minorGridlines: { equalScale: !!options.additionalAxesOptions.allowEqualScale && !!state.equalScaleEnabled },
|
|
36547
36565
|
equalAxisScale: { enabled: !!options.additionalAxesOptions.allowEqualScale && !!state.equalScaleEnabled },
|
|
36548
36566
|
datalabels,
|
|
36549
36567
|
annotationDraggerPlugin: { enabled: state?.enableDragAnnotation },
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Scale, Plugin, ChartType } from 'chart.js';
|
|
2
2
|
export declare const getLargestMajorTickWidth: (majorTickPositions: number[]) => number;
|
|
3
3
|
export declare const isValidPosition: (minorTickPosition: number, majorTickPositions: number[], scale: Scale) => boolean;
|
|
4
4
|
export declare const getMinorTickPositions: (majorTickPositions: number[], scale: Scale) => number[];
|
|
5
|
-
export declare const chartMinorGridlinesPlugin: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
5
|
+
export declare const chartMinorGridlinesPlugin: Plugin<ChartType, {
|
|
6
|
+
equalScale?: boolean;
|
|
7
|
+
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oliasoft-open-source/charts-library",
|
|
3
|
-
"version": "9.1.0-beta-
|
|
3
|
+
"version": "9.1.0-beta-3",
|
|
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": {
|