From a86c47cf480e8d86ea03a121e9b6552a17aae41d Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Fri, 14 Oct 2016 16:36:49 -0500 Subject: [PATCH] Configurable Tooltip Position Modes (#3453) Adds new tooltip position option that allows configuring where a tooltip is displayed on the graph in relation to the elements that appear in it --- docs/01-Chart-Configuration.md | 1 + src/core/core.controller.js | 87 +++++++++---------- src/core/core.legend.js | 12 ++- src/core/core.tooltip.js | 150 +++++++++++++++++++++++++-------- 4 files changed, 166 insertions(+), 84 deletions(-) diff --git a/docs/01-Chart-Configuration.md b/docs/01-Chart-Configuration.md index ef0a5b57f..c08e23d44 100644 --- a/docs/01-Chart-Configuration.md +++ b/docs/01-Chart-Configuration.md @@ -214,6 +214,7 @@ enabled | Boolean | true | Are tooltips enabled custom | Function | null | See [section](#advanced-usage-external-tooltips) below mode | String | 'nearest' | Sets which elements appear in the tooltip. See [Interaction Modes](#interaction-modes) for details intersect | Boolean | true | if true, the tooltip mode applies only when the mouse position intersects with an element. If false, the mode will be applied at all times. +position | String | 'average' | The mode for positioning the tooltip. 'average' mode will place the tooltip at the average position of the items displayed in the tooltip. 'nearest' will place the tooltip at the position of the element closest to the event position. New modes can be defined by adding functions to the Chart.Tooltip.positioners map. itemSort | Function | undefined | Allows sorting of [tooltip items](#chart-configuration-tooltip-item-interface). Must implement at minimum a function that can be passed to [Array.prototype.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort). This function can also accept a third parameter that is the data object passed to the chart. backgroundColor | Color | 'rgba(0,0,0,0.8)' | Background color of the tooltip titleFontFamily | String | "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif" | Font family for tooltip title inherited from global font family diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 6302dd11c..5e3632e4f 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -156,6 +156,7 @@ module.exports = function(Chart) { me.chart = instance; me.config = config; me.options = config.options; + me._bufferedRender = false; // Add the chart instance to the global namespace Chart.instances[me.id] = me; @@ -403,7 +404,9 @@ module.exports = function(Chart) { // Do this before render so that any plugins that need final scale updates can use it Chart.plugins.notify('afterUpdate', [me]); - me.render(animationDuration, lazy); + if (!me._bufferedRender) { + me.render(animationDuration, lazy); + } }, /** @@ -644,20 +647,6 @@ module.exports = function(Chart) { var method = enabled? 'setHoverStyle' : 'removeHoverStyle'; var element, i, ilen; - switch (mode) { - case 'single': - elements = [elements[0]]; - break; - case 'label': - case 'dataset': - case 'x-axis': - // elements = elements; - break; - default: - // unsupported mode - return; - } - for (i=0, ilen=elements.length; i