Skip to content

Commit ccf64e7

Browse files
authored
Manage line label visibility when not inside chart area (#790)
1 parent 1857f42 commit ccf64e7

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/types/label.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Element} from 'chart.js';
22
import {drawBox, drawLabel, measureLabelSize, getChartPoint, toPosition, setBorderStyle, getSize, inBoxRange, isBoundToPoint, resolveBoxProperties, getRelativePosition, translate, rotated, getElementCenterPoint} from '../helpers';
3-
import {toPadding, toRadians, distanceBetweenPoints} from 'chart.js/helpers';
3+
import {toPadding, toRadians, distanceBetweenPoints, defined} from 'chart.js/helpers';
44

55
const positions = ['left', 'bottom', 'top', 'right'];
66

@@ -17,7 +17,8 @@ export default class LabelAnnotation extends Element {
1717

1818
draw(ctx) {
1919
const options = this.options;
20-
if (!options.display || !options.content) {
20+
const visible = !defined(this._visible) || this._visible;
21+
if (!options.display || !options.content || !visible) {
2122
return;
2223
}
2324
ctx.save();

src/types/line.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ export default class LineAnnotation extends Element {
8989
: {x, y, x2, y2, width: Math.abs(x2 - x), height: Math.abs(y2 - y)};
9090
properties.centerX = (x2 + x) / 2;
9191
properties.centerY = (y2 + y) / 2;
92-
if (!inside) {
93-
options.label.display = false;
94-
}
92+
const labelProperties = resolveLabelElementProperties(chart, properties, options.label);
93+
// additonal prop to manage zoom/pan
94+
labelProperties._visible = inside;
95+
9596
properties.elements = [{
9697
type: 'label',
9798
optionScope: 'label',
98-
properties: resolveLabelElementProperties(chart, properties, options.label)
99+
properties: labelProperties
99100
}];
100101
return properties;
101102
}

0 commit comments

Comments
 (0)