resolveDataElementOptions(index, mode) {
const me = this;
const chart = me.chart;
- const dataset = me.getDataset();
const parsed = me.getParsed(index);
let values = super.resolveDataElementOptions(index, mode);
// Scriptable options
- const context = {
- chart,
- dataPoint: parsed,
- dataIndex: index,
- dataset,
- datasetIndex: me.index
- };
+ const context = me.getContext(index, mode === 'active');
// In case values were cached (and thus frozen), we need to clone the values
if (values.$shared) {
me._cachedMeta.count = me.countVisibleElements();
for (i = 0; i < start; ++i) {
- angle += me._computeAngle(i);
+ angle += me._computeAngle(i, mode);
}
for (i = start; i < start + count; i++) {
const arc = arcs[i];
let startAngle = angle;
- let endAngle = angle + me._computeAngle(i);
+ let endAngle = angle + me._computeAngle(i, mode);
let outerRadius = this.chart.getDataVisibility(i) ? scale.getDistanceFromCenterForValue(dataset.data[i]) : 0;
angle = endAngle;
/**
* @private
*/
- _computeAngle(index) {
+ _computeAngle(index, mode) {
const me = this;
const meta = me._cachedMeta;
const count = meta.count;
}
// Scriptable options
- const context = {
- chart: me.chart,
- dataPoint: this.getParsed(index),
- dataIndex: index,
- dataset,
- datasetIndex: me.index
- };
+ const context = me.getContext(index, mode === 'active');
return resolve([
me.chart.options.elements.arc.angle,
}
/**
- * @private
+ * @protected
*/
- _getContext(index, active) {
+ getContext(index, active) {
return {
chart: this.chart,
dataPoint: this.getParsed(index),
const datasetOpts = me._config;
const options = me.chart.options.elements[type] || {};
const values = {};
- const context = me._getContext(index, active);
+ const context = me.getContext(index, active);
const keys = optionKeys(optionNames);
for (let i = 0, ilen = keys.length; i < ilen; ++i) {
}
const info = {cacheable: true};
- const context = me._getContext(index, active);
+ const context = me.getContext(index, active);
const chartAnim = resolve([chart.options.animation], context, index, info);
const datasetAnim = resolve([me._config.animation], context, index, info);
let config = chartAnim && mergeIf({}, [datasetAnim, chartAnim]);
0;
}
+ /**
+ * @protected
+ */
+ getContext(index) {
+ const ticks = this.ticks || [];
+ return {
+ chart: this.chart,
+ scale: this,
+ tick: ticks[index],
+ index
+ };
+ }
+
/**
* Returns a subset of ticks to be plotted to avoid overlapping labels.
* @param {Tick[]} ticks
const tl = getTickMarkLength(gridLines);
const items = [];
- let context = {
- chart,
- scale: me,
- tick: ticks[0],
- index: 0,
- };
+ let context = this.getContext(0);
const axisWidth = gridLines.drawBorder ? resolve([gridLines.borderWidth, gridLines.lineWidth, 0], context, 0) : 0;
const axisHalfWidth = axisWidth / 2;
const alignBorderValue = function(pixel) {
}
for (i = 0; i < ticksLength; ++i) {
- /** @type {Tick|object} */
- const tick = ticks[i] || {};
-
- context = {
- chart,
- scale: me,
- tick,
- index: i,
- };
+ context = this.getContext(i);
const lineWidth = resolve([gridLines.lineWidth], context, i);
const lineColor = resolve([gridLines.color], context, i);
const gridLines = me.options.gridLines;
const ctx = me.ctx;
const chart = me.chart;
- let context = {
- chart,
- scale: me,
- tick: me.ticks[0],
- index: 0,
- };
+ let context = me.getContext(0);
const axisWidth = gridLines.drawBorder ? resolve([gridLines.borderWidth, gridLines.lineWidth, 0], context, 0) : 0;
const items = me._gridLineItems || (me._gridLineItems = me._computeGridLineItems(chartArea));
let i, ilen;
if (axisWidth) {
// Draw the line at the edge of the axis
const firstLineWidth = axisWidth;
- context = {
- chart,
- scale: me,
- tick: me.ticks[me._ticksLength - 1],
- index: me._ticksLength - 1,
- };
+ context = me.getContext(me._ticksLength - 1);
const lastLineWidth = resolve([gridLines.lineWidth, 1], context, me._ticksLength - 1);
const borderValue = me._borderValue;
let x1, x2, y1, y2;
const me = this;
const chart = me.chart;
const options = me.options.ticks;
- const ticks = me.ticks || [];
- const context = {
- chart,
- scale: me,
- tick: ticks[index],
- index
- };
+ const context = me.getContext(index);
return toFont(resolve([options.font], context), chart.options.font);
}
}
for (i = 0; i < valueCount; i++) {
pointPosition = scale.getPointPosition(i, scale.drawingArea + 5);
- const context = {
- chart: scale.chart,
- scale,
- index: i,
- label: scale.pointLabels[i]
- };
+ const context = scale.getContext(i);
const plFont = toFont(resolve([scale.options.pointLabels.font], context, i), scale.chart.options.font);
scale.ctx.font = plFont.string;
textSize = measureLabelSize(scale.ctx, plFont.lineHeight, scale.pointLabels[i]);
const extra = (i === 0 ? tickBackdropHeight / 2 : 0);
const pointLabelPosition = scale.getPointPosition(i, outerDistance + extra + 5);
- const context = {
- chart: scale.chart,
- scale,
- index: i,
- label: scale.pointLabels[i],
- };
+ const context = scale.getContext(i);
const plFont = toFont(resolve([pointLabelOpts.font], context, i), scale.chart.options.font);
ctx.font = plFont.string;
ctx.fillStyle = plFont.color;
const circular = gridLineOpts.circular;
const valueCount = scale.chart.data.labels.length;
- const context = {
- chart: scale.chart,
- scale,
- index,
- tick: scale.ticks[index],
- };
+ const context = scale.getContext(index);
const lineColor = resolve([gridLineOpts.color], context, index - 1);
const lineWidth = resolve([gridLineOpts.lineWidth], context, index - 1);
let pointPosition;
ctx.save();
for (i = me.chart.data.labels.length - 1; i >= 0; i--) {
- const context = {
- chart: me.chart,
- scale: me,
- index: i,
- label: me.pointLabels[i],
- };
+ const context = me.getContext(i);
const lineWidth = resolve([angleLineOpts.lineWidth, gridLineOpts.lineWidth], context, i);
const color = resolve([angleLineOpts.color, gridLineOpts.color], context, i);
ctx.textBaseline = 'middle';
me.ticks.forEach((tick, index) => {
- const context = {
- chart: me.chart,
- scale: me,
- index,
- tick,
- };
-
if (index === 0 && !opts.reverse) {
return;
}
+ const context = me.getContext(index);
const tickFont = me._resolveTickFontOptions(index);
ctx.font = tickFont.string;
offset = me.getDistanceFromCenterForValue(me.ticks[index].value);