Skip to content

Commit e78e1cf

Browse files
authored
Fix isBoundToPoint function implementation (#550)
* Fix `isBoundToPoint` function implementation * adds test cases * uses 'defined' function of CHARTJS helpers
1 parent c4039ae commit e78e1cf

File tree

5 files changed

+81
-2
lines changed

5 files changed

+81
-2
lines changed

src/helpers/helpers.options.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {isObject, valueOrDefault} from 'chart.js/helpers';
1+
import {isObject, valueOrDefault, defined} from 'chart.js/helpers';
22

33
const isEnabled = (options) => options && (options.display || options.enabled);
44
const toPercent = (s) => typeof s === 'string' && s.endsWith('%') && parseFloat(s) / 100;
@@ -52,5 +52,5 @@ export function toPosition(value) {
5252
}
5353

5454
export function isBoundToPoint(options) {
55-
return options && (options.xValue || options.yValue);
55+
return options && (defined(options.xValue) || defined(options.yValue));
5656
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module.exports = {
2+
tolerance: 0.0055,
3+
config: {
4+
type: 'scatter',
5+
options: {
6+
scales: {
7+
x: {
8+
display: true,
9+
min: -10,
10+
max: 10
11+
},
12+
y: {
13+
display: true,
14+
min: -4,
15+
max: 10
16+
}
17+
},
18+
plugins: {
19+
legend: false,
20+
annotation: {
21+
drawTime: 'afterDraw',
22+
annotations: {
23+
point: {
24+
type: 'point',
25+
xScaleID: 'x',
26+
yScaleID: 'y',
27+
xValue: 0,
28+
yValue: 0,
29+
backgroundColor: 'rgba(101, 33, 171, 0.5)',
30+
borderColor: 'rgb(101, 33, 171)',
31+
borderWidth: 15,
32+
radius: 50
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
39+
};
21.1 KB
Loading
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module.exports = {
2+
tolerance: 0.0055,
3+
config: {
4+
type: 'scatter',
5+
options: {
6+
scales: {
7+
x: {
8+
display: true,
9+
min: -10,
10+
max: 10
11+
},
12+
y: {
13+
display: true,
14+
min: -4,
15+
max: 10
16+
}
17+
},
18+
plugins: {
19+
legend: false,
20+
annotation: {
21+
drawTime: 'afterDraw',
22+
annotations: {
23+
polygon: {
24+
type: 'polygon',
25+
xScaleID: 'x',
26+
yScaleID: 'y',
27+
xValue: 0,
28+
yValue: 0,
29+
sides: 5,
30+
backgroundColor: 'rgba(101, 33, 171, 0.5)',
31+
borderColor: 'rgb(101, 33, 171)',
32+
borderWidth: 15,
33+
radius: 50
34+
}
35+
}
36+
}
37+
}
38+
}
39+
}
40+
};
20.1 KB
Loading

0 commit comments

Comments
 (0)