Skip to content

Commit 82e616d

Browse files
authored
Merge pull request #73 from sgratzl/release/v4.3.0
Release v4.3.0
2 parents 1838ae8 + 1c94c04 commit 82e616d

File tree

6 files changed

+67
-11
lines changed

6 files changed

+67
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "chartjs-chart-error-bars",
33
"description": "Chart.js module for charting error bars",
4-
"version": "4.2.4",
4+
"version": "4.3.0",
55
"author": {
66
"name": "Samuel Gratzl",
77
"email": "samu@sgratzl.com",

src/controllers/BarWithErrorBarsController.spec.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { registry, LinearScale, CategoryScale } from 'chart.js';
1+
import { registry, LinearScale, CategoryScale, TimeScale } from 'chart.js';
22
import createChart from '../__tests__/createChart';
33
import { BarWithErrorBarsController } from './BarWithErrorBarsController';
44
import { BarWithErrorBar } from '../elements';
5+
import 'chartjs-adapter-date-fns';
56

67
describe('bar', () => {
78
beforeAll(() => {
89
registry.addControllers(BarWithErrorBarsController);
910
registry.addElements(BarWithErrorBar);
10-
registry.addScales(LinearScale, CategoryScale);
11+
registry.addScales(LinearScale, CategoryScale, TimeScale);
1112
});
1213
test('default', () => {
1314
return createChart({
@@ -43,4 +44,49 @@ describe('bar', () => {
4344
},
4445
}).toMatchImageSnapshot();
4546
});
47+
test('time scale', () => {
48+
return createChart({
49+
type: BarWithErrorBarsController.id,
50+
data: {
51+
labels: ['A', 'B'],
52+
datasets: [
53+
{
54+
data: [
55+
{
56+
x: '2017-12-25',
57+
y: 4,
58+
yMin: 1,
59+
yMax: 6,
60+
},
61+
{
62+
x: '2018-12-25',
63+
y: 2,
64+
yMin: 1,
65+
yMax: 4,
66+
},
67+
{
68+
x: '2019-12-25',
69+
y: 3,
70+
yMin: 2,
71+
yMax: 5,
72+
},
73+
],
74+
},
75+
],
76+
},
77+
options: {
78+
scales: {
79+
x: {
80+
type: 'time',
81+
display: false,
82+
min: '2017-01-01',
83+
max: '2020-01-01',
84+
},
85+
y: {
86+
display: false,
87+
},
88+
},
89+
},
90+
}).toMatchImageSnapshot();
91+
});
4692
});

src/controllers/BarWithErrorBarsController.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
CartesianScaleTypeRegistry,
1717
} from 'chart.js';
1818
import { merge } from 'chart.js/helpers';
19-
import { calculateScale } from './utils';
19+
import { calculateScale, isNumericScale } from './utils';
2020
import type { IErrorBarOptions } from '../elements/render';
2121
import { BarWithErrorBar } from '../elements';
2222
import { generateBarTooltip } from './tooltip';
@@ -67,7 +67,13 @@ export class BarWithErrorBarsController extends BarController {
6767
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
6868
parseErrorNumberData(parsed, meta.vScale!, data, start, count);
6969
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
70-
parseErrorLabelData(parsed, meta.iScale!, start, count);
70+
const iScale = meta.iScale as Scale;
71+
const hasNumberIScale = isNumericScale(iScale);
72+
if (hasNumberIScale) {
73+
parseErrorNumberData(parsed, meta.iScale!, data, start, count);
74+
} else {
75+
parseErrorLabelData(parsed, meta.iScale!, start, count);
76+
}
7177
}
7278

7379
/**

src/controllers/LineWithErrorBarsController.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
CartesianScaleTypeRegistry,
1717
} from 'chart.js';
1818
import { merge } from 'chart.js/helpers';
19-
import { calculateScale } from './utils';
19+
import { calculateScale, isNumericScale } from './utils';
2020
import type { IErrorBarOptions } from '../elements/render';
2121
import { PointWithErrorBar } from '../elements';
2222
import { generateBarTooltip } from './tooltip';
@@ -31,8 +31,6 @@ import {
3131
} from './base';
3232
import patchController from './patchController';
3333

34-
const NUMERIC_SCALE_TYPES = ['linear', 'logarithmic', 'time', 'timeseries'];
35-
3634
export class LineWithErrorBarsController extends LineController {
3735
/**
3836
* @hidden
@@ -73,7 +71,7 @@ export class LineWithErrorBarsController extends LineController {
7371
parseErrorNumberData(parsed, meta.vScale!, data, start, count);
7472
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7573
const iScale = meta.iScale as Scale;
76-
const hasNumberIScale = NUMERIC_SCALE_TYPES.includes(iScale.type);
74+
const hasNumberIScale = isNumericScale(iScale);
7775
if (hasNumberIScale) {
7876
parseErrorNumberData(parsed, meta.iScale!, data, start, count);
7977
} else {
@@ -111,7 +109,7 @@ export class LineWithErrorBarsController extends LineController {
111109
);
112110

113111
const iScale = this._cachedMeta.iScale as Scale;
114-
const hasNumberIScale = NUMERIC_SCALE_TYPES.includes(iScale.type);
112+
const hasNumberIScale = isNumericScale(iScale);
115113
if (hasNumberIScale) {
116114
calculateScale(
117115
properties,
1.5 KB
Loading

src/controllers/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { LinearScale, RadialLinearScale } from 'chart.js';
1+
import type { LinearScale, RadialLinearScale, Scale } from 'chart.js';
22
import type { IErrorBarRDataPoint, IErrorBarXYDataPoint } from './base';
33

44
export const allModelKeys = ['xMin', 'xMax', 'yMin', 'yMax'];
@@ -63,3 +63,9 @@ export function calculatePolarScale(
6363
}
6464
}
6565
}
66+
67+
const NUMERIC_SCALE_TYPES = ['linear', 'logarithmic', 'time', 'timeseries'];
68+
69+
export function isNumericScale(scale: Scale): boolean {
70+
return NUMERIC_SCALE_TYPES.includes(scale.type);
71+
}

0 commit comments

Comments
 (0)