datasetIndex: number,
// Index of this data item in the dataset
- dataIndex: number
+ dataIndex: number,
+
+ // The chart element (point, arc, bar, etc.) for this tooltip item
+ element: Element,
}
```
tableRoot.innerHTML = innerHtml;
}
- // `this` will be the overall tooltip
- var position = this._chart.canvas.getBoundingClientRect();
+ var position = context.chart.canvas.getBoundingClientRect();
// Display, position, and set styles for font
tooltipEl.style.opacity = 1;
* Legend `onClick`, `onHover`, and `onLeave` options now receive the legend as the 3rd argument in addition to implicitly via `this`
* Legend `onClick`, `onHover`, and `onLeave` options now receive a wrapped `event` as the first parameter. The previous first parameter value is accessible via `event.native`.
* `Title.margins` is now private
-* The tooltip item's `x` and `y` attributes were removed. Use `datasetIndex` and `dataIndex` to get the element and any corresponding data from it
+* The tooltip item's `x` and `y` attributes were replaced by `element`. You can use `element.x` and `element.y` or `element.tooltipPosition()` instead.
#### Removal of private APIs
}]
},
options: {
- animation: (context) => {
- if (context.active) {
- return {
- radius: {
- duration: 400,
- loop: true
- }
- };
+ animation: (context) => Object.assign({},
+ Chart.defaults.animation,
+ {
+ radius: {
+ duration: 400,
+ easing: 'linear',
+ loop: context.active
+ }
}
- return Chart.defaults.animation;
- },
+ ),
elements: {
point: {
hoverRadius: 6
tooltips: {
enabled: false,
mode: 'index',
+ intersect: false,
position: 'nearest',
custom: customTooltips
}
if (tooltip.dataPoints.length > 0) {
tooltip.dataPoints.forEach(function(dataPoint) {
- var content = [dataPoint.label, dataPoint.value].join(': ');
+ var content = [dataPoint.label, dataPoint.formattedValue].join(': ');
var $tooltip = $('#tooltip-' + dataPoint.datasetIndex);
+ var pos = dataPoint.element.tooltipPosition();
$tooltip.html(content);
$tooltip.css({
opacity: 1,
- top: positionY + dataPoint.y + 'px',
- left: positionX + dataPoint.x + 'px',
+ top: positionY + pos.y + 'px',
+ left: positionX + pos.x + 'px',
});
});
}
const remain = me._duration - elapsed;
me._start = date;
me._duration = Math.floor(Math.max(remain, cfg.duration));
+ me._loop = !!cfg.loop;
me._to = resolve([cfg.to, to, currentValue, cfg.from]);
me._from = resolve([cfg.from, currentValue, to]);
}
/**
* Private helper to create a tooltip item model
- * @param item - the chart element (point, arc, bar) to create the tooltip item for
+ * @param item - {element, index, datasetIndex} to create the tooltip item for
* @return new tooltip item
*/
function createTooltipItem(chart, item) {
- const {datasetIndex, index} = item;
+ const {element, datasetIndex, index} = item;
const controller = chart.getDatasetMeta(datasetIndex).controller;
- const dataset = controller.getDataset();
const {label, value} = controller.getLabelAndValue(index);
return {
label,
dataPoint: controller.getParsed(index),
formattedValue: value,
- dataset,
+ dataset: controller.getDataset(),
dataIndex: index,
- datasetIndex
+ datasetIndex,
+ element
};
}
}
const chart = me._chart;
- const opts = chart.options.animation && me.options.animation;
+ const options = me.options;
+ const opts = options.enabled && chart.options.animation && options.animation;
const animations = new Animations(me._chart, opts);
me._cachedAnimations = Object.freeze(animations);