Skip to content

Commit e3d92fa

Browse files
authored
Add adjustScaleRange options (#419)
* add adjustScaleRange options * clean up Co-authored-by: 6y <[email protected]>
1 parent 9ecc800 commit e3d92fa

File tree

9 files changed

+14
-2
lines changed

9 files changed

+14
-2
lines changed

docs/guide/types/box.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ The following options are available for box annotations.
5252
| Name | Type | [Scriptable](../options#scriptable-options) | Default
5353
| ---- | ---- | :----: | ----
5454
| [`display`](#general) | `boolean` | Yes | `true`
55+
| [`adjustScaleRange`](#general) | `boolean` | Yes | `true`
5556
| [`drawTime`](#general) | `string` | Yes | `'afterDatasetsDraw'`
5657
| [`xScaleID`](#general) | `string` | Yes | `'x'`
5758
| [`yScaleID`](#general) | `string` | Yes | `'y'`
@@ -73,6 +74,7 @@ If one of the axes does not match an axis in the chart, the box will take the en
7374
| Name | Description |
7475
| ---- | ---- |
7576
| `display` | Whether or not this annotation is visible
77+
| `adjustScaleRange` | Should the scale range be adjusted if this annotation is out of range
7678
| `drawTime` | See [drawTime](../options#draw-time)
7779
| `xScaleID` | ID of the X scale to bind onto, default is 'x'.
7880
| `yScaleID` | ID of the Y scale to bind onto, default is 'y'.

docs/guide/types/ellipse.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ The following options are available for ellipse annotations.
5252
| Name | Type | [Scriptable](../options#scriptable-options) | Default
5353
| ---- | ---- | :----: | ----
5454
| [`display`](#general) | `boolean` | Yes | `true`
55+
| [`adjustScaleRange`](#general) | `boolean` | Yes | `true`
5556
| [`drawTime`](#general) | `string` | Yes | `'afterDatasetsDraw'`
5657
| [`xScaleID`](#general) | `string` | Yes | `'x'`
5758
| [`yScaleID`](#general) | `string` | Yes | `'y'`
@@ -72,6 +73,7 @@ If one of the axes does not match an axis in the chart, the ellipse will take th
7273
| Name | Description |
7374
| ---- | ---- |
7475
| `display` | Whether or not this annotation is visible
76+
| `adjustScaleRange` | Should the scale range be adjusted if this annotation is out of range
7577
| `drawTime` | See [drawTime](../options#draw-time)
7678
| `xScaleID` | ID of the X scale to bind onto, default is 'x'.
7779
| `yScaleID` | ID of the Y scale to bind onto, default is 'y'.

docs/guide/types/line.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ The following options are available for line annotations. All of these options c
5151
| Name | Type | [Scriptable](../options#scriptable-options) | Default
5252
| ---- | ---- | ---- | :----: | ----
5353
| [`display`](#general) | `boolean` | Yes | `true`
54+
| [`adjustScaleRange`](#general) | `boolean` | Yes | `true`
5455
| [`drawTime`](#general) | `string` | Yes | `'afterDatasetsDraw'`
5556
| [`scaleID`](#positioning) | `string` | Yes | `undefined`
5657
| [`value`](#positioning) | `number` | Yes | `undefined`
@@ -74,6 +75,7 @@ If one of the axes does not match an axis in the chart, the box will take the en
7475
| Name | Description |
7576
| ---- | ---- |
7677
| `display` | Whether or not this annotation is visible
78+
| `adjustScaleRange` | Should the scale range be adjusted if this annotation is out of range
7779
| `drawTime` | See [drawTime](../options#draw-time)
7880

7981
### Positioning

docs/guide/types/point.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ The following options are available for ellipse annotations.
5050
| Name | Type | [Scriptable](../options#scriptable-options) | Default
5151
| ---- | ---- | :----: | ----
5252
| [`display`](#general) | `boolean` | Yes | `true`
53+
| [`adjustScaleRange`](#general) | `boolean` | Yes | `true`
5354
| [`drawTime`](#general) | `string` | Yes | `'afterDatasetsDraw'`
5455
| [`xScaleID`](#general) | `string` | Yes | `'x'`
5556
| [`yScaleID`](#general) | `string` | Yes | `'y'`
@@ -69,6 +70,7 @@ If one of the axes does not match an axis in the chart, the ellipse will take th
6970
| Name | Description |
7071
| ---- | ---- |
7172
| `display` | Whether or not this annotation is visible
73+
| `adjustScaleRange` | Should the scale range be adjusted if this annotation is out of range
7274
| `drawTime` | See [drawTime](../options#draw-time)
7375
| `xScaleID` | ID of the X scale to bind onto, default is 'x'.
7476
| `yScaleID` | ID of the Y scale to bind onto, default is 'y'.

src/annotation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default {
6565

6666
afterDataLimits(chart, args) {
6767
const state = chartStates.get(chart);
68-
adjustScaleRange(chart, args.scale, state.annotations.filter(a => a.display));
68+
adjustScaleRange(chart, args.scale, state.annotations.filter(a => a.display && a.adjustScaleRange));
6969
},
7070

7171
afterUpdate(chart, args, options) {
@@ -253,7 +253,7 @@ function getScaleLimits(scale, annotations) {
253253
let max = valueOrDefault(scale.max, Number.POSITIVE_INFINITY);
254254
for (const annotation of annotations) {
255255
if (annotation.scaleID === scaleID) {
256-
for (const prop of ['value', 'endValue']) { //
256+
for (const prop of ['value', 'endValue']) {
257257
const raw = annotation[prop];
258258
if (raw) {
259259
const value = scale.parse(raw);

src/types/box.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ BoxAnnotation.id = 'boxAnnotation';
8181

8282
BoxAnnotation.defaults = {
8383
display: true,
84+
adjustScaleRange: true,
8485
borderDash: [],
8586
borderDashOffset: 0,
8687
borderWidth: 1,

src/types/ellipse.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ EllipseAnnotation.id = 'ellipseAnnotation';
3434

3535
EllipseAnnotation.defaults = {
3636
display: true,
37+
adjustScaleRange: true,
3738
borderDash: [],
3839
borderDashOffset: 0,
3940
borderWidth: 1,

src/types/line.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export default class LineAnnotation extends Element {
145145
LineAnnotation.id = 'lineAnnotation';
146146
LineAnnotation.defaults = {
147147
display: true,
148+
adjustScaleRange: true,
148149
borderWidth: 2,
149150
borderDash: [],
150151
borderDashOffset: 0,

src/types/point.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ PointAnnotation.id = 'pointAnnotation';
6868

6969
PointAnnotation.defaults = {
7070
display: true,
71+
adjustScaleRange: true,
7172
borderDash: [],
7273
borderDashOffset: 0,
7374
borderWidth: 1,

0 commit comments

Comments
 (0)