Skip to content

Commit eb7ce4e

Browse files
authored
Add raw data to context and rename dataPoint to parsed (#8318)
* Make the raw data point available in scriptable context * Rename variables * Update samples
1 parent 0955a25 commit eb7ce4e

File tree

15 files changed

+31
-24
lines changed

15 files changed

+31
-24
lines changed

docs/docs/configuration/tooltip.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ var chart = new Chart(ctx, {
140140
if (label) {
141141
label += ': ';
142142
}
143-
if (!isNaN(context.dataPoint.y)) {
144-
label += new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(context.dataPoint.y);
143+
if (!isNaN(context.parsed.y)) {
144+
label += new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(context.parsed.y);
145145
}
146146
return label;
147147
}
@@ -220,7 +220,10 @@ The tooltip items passed to the tooltip callbacks implement the following interf
220220
label: string,
221221

222222
// Parsed data values for the given `dataIndex` and `datasetIndex`
223-
dataPoint: object,
223+
parsed: object,
224+
225+
// Raw data values for the given `dataIndex` and `datasetIndex`
226+
raw: object,
224227

225228
// Formatted value for the tooltip
226229
formattedValue: string,

docs/docs/general/options.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ In addition to [dataset](#dataset)
7272

7373
- `active`: true if element is active (hovered)
7474
- `dataIndex`: index of the current data
75-
- `dataPoint`: the parsed data values for the given `dataIndex` and `datasetIndex`
75+
- `parsed`: the parsed data values for the given `dataIndex` and `datasetIndex`
76+
- `raw`: the raw data values for the given `dataIndex` and `datasetIndex`
7677
- `element`: the element (point, arc, bar, etc.) for this data
7778
- `index`: getter for `dataIndex`
7879
- `type`: `'data'`

samples/animations/delay.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
var delay = 0;
7777
var dsIndex = context.datasetIndex;
7878
var index = context.dataIndex;
79-
if (context.dataPoint && !context.delayed) {
79+
if (context.parsed && !context.delayed) {
8080
delay = index * 300 + dsIndex * 100;
8181
context.delayed = true;
8282
}

samples/charts/multi-series-pie.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
callbacks: {
8585
label: function(context) {
8686
var labelIndex = (context.datasetIndex * 2) + context.dataIndex;
87-
return context.chart.data.labels[labelIndex] + ': ' + context.dataset.data[context.dataIndex];
87+
return context.chart.data.labels[labelIndex] + ': ' + context.formattedValue;
8888
}
8989
}
9090
}

samples/scales/financial.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
if (label) {
193193
label += ': ';
194194
}
195-
label += context.dataPoint.y.toFixed(2);
195+
label += context.parsed.y.toFixed(2);
196196
return label;
197197
}
198198
}

samples/scriptable/bar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
utils.srand(110);
2828

2929
function colorize(opaque, ctx) {
30-
var v = ctx.dataPoint.y;
30+
var v = ctx.parsed.y;
3131
var c = v < -50 ? '#D60000'
3232
: v < 0 ? '#F46300'
3333
: v < 50 ? '#0358B6'

samples/scriptable/bubble.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
}
3434

3535
function colorize(opaque, context) {
36-
var value = context.dataset.data[context.dataIndex];
36+
var value = context.raw;
3737
var x = value.x / 100;
3838
var y = value.y / 100;
3939
var r = channelValue(x, y, [250, 150, 50, 0]);
@@ -90,14 +90,12 @@
9090
},
9191

9292
hoverBorderWidth: function(context) {
93-
var value = context.dataset.data[context.dataIndex];
94-
return Math.round(8 * value.v / 1000);
93+
return Math.round(8 * context.raw.v / 1000);
9594
},
9695

9796
radius: function(context) {
98-
var value = context.dataset.data[context.dataIndex];
9997
var size = context.chart.width;
100-
var base = Math.abs(value.v) / 1000;
98+
var base = Math.abs(context.raw.v) / 1000;
10199
return (size / 24) * base;
102100
}
103101
}

samples/scriptable/line.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
}
4141

4242
function adjustRadiusBasedOnData(ctx) {
43-
var v = ctx.dataPoint.y;
43+
var v = ctx.parsed.y;
4444
return v < 10 ? 5
4545
: v < 25 ? 7
4646
: v < 50 ? 9

samples/scriptable/pie.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
utils.srand(110);
2828

2929
function colorize(opaque, hover, ctx) {
30-
var v = ctx.dataPoint;
30+
var v = ctx.parsed;
3131
var c = v < -50 ? '#D60000'
3232
: v < 0 ? '#F46300'
3333
: v < 50 ? '#0358B6'

samples/scriptable/polar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
utils.srand(110);
2727

2828
function colorize(opaque, hover, ctx) {
29-
var v = ctx.dataset.data[ctx.dataIndex];
29+
var v = ctx.raw;
3030
var c = v < 35 ? '#D60000'
3131
: v < 55 ? '#F46300'
3232
: v < 75 ? '#0358B6'

0 commit comments

Comments
 (0)