Add type to context objects (#8007)

This commit is contained in:
Jukka Kurkela
2020-11-08 15:43:55 +02:00
committed by GitHub
parent 17f6edb650
commit d74a5d7552
4 changed files with 20 additions and 0 deletions

View File

@@ -54,6 +54,7 @@ The context object contains the following properties:
### chart
- `chart`: the associated chart
- `type`: `'chart'`
### dataset
@@ -63,6 +64,7 @@ In addition to [chart](#chart)
- `dataset`: dataset at index `datasetIndex`
- `datasetIndex`: index of the current dataset
- `index`: getter for `datasetIndex`
- `type`: `'dataset'`
### data
@@ -73,12 +75,14 @@ In addition to [dataset](#dataset)
- `dataPoint`: the parsed data values for the given `dataIndex` and `datasetIndex`
- `element`: the element (point, arc, bar, etc.) for this data
- `index`: getter for `dataIndex`
- `type`: `'data'`
### scale
In addition to [chart](#chart)
- `scale`: the associated scale
- `type`: `'scale'`
### tick
@@ -86,3 +90,4 @@ In addition to [scale](#scale)
- `tick`: the associated tick object
- `index`: tick index
- `type`: `'tick'`

View File

@@ -735,6 +735,9 @@ class Chart {
return this.$context || (this.$context = Object.create(null, {
chart: {
value: this
},
type: {
value: 'chart'
}
}));
}

View File

@@ -164,6 +164,9 @@ function createDatasetContext(parent, index, dataset) {
get() {
return this.datasetIndex;
}
},
type: {
value: 'dataset'
}
});
}
@@ -187,6 +190,9 @@ function createDataContext(parent, index, point, element) {
get() {
return this.dataIndex;
}
},
type: {
value: 'data',
}
});
}

View File

@@ -274,6 +274,9 @@ function createScaleContext(parent, scale) {
scale: {
value: scale
},
type: {
value: 'scale'
}
});
}
@@ -284,6 +287,9 @@ function createTickContext(parent, index, tick) {
},
index: {
value: index
},
type: {
value: 'tick'
}
});
}