superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grace...@apache.org
Subject [incubator-superset] branch master updated: Set max width for tooltips (#5504)
Date Mon, 30 Jul 2018 18:03:45 GMT
This is an automated email from the ASF dual-hosted git repository.

graceguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new b77d6e9  Set max width for tooltips (#5504)
b77d6e9 is described below

commit b77d6e9cb1d7e8eecb3116ea74eacb0b13b64ad7
Author: Jeffrey Wang <jeffreywang93@gmail.com>
AuthorDate: Mon Jul 30 14:03:42 2018 -0400

    Set max width for tooltips (#5504)
---
 superset/assets/src/visualizations/nvd3_vis.js | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/superset/assets/src/visualizations/nvd3_vis.js b/superset/assets/src/visualizations/nvd3_vis.js
index 64a9168..199fa04 100644
--- a/superset/assets/src/visualizations/nvd3_vis.js
+++ b/superset/assets/src/visualizations/nvd3_vis.js
@@ -89,6 +89,18 @@ function hideTooltips() {
   $('.nvtooltip').css({ opacity: 0 });
 }
 
+function wrapTooltip(chart, container) {
+  const tooltipLayer = chart.useInteractiveGuideline && chart.useInteractiveGuideline()
?
+    chart.interactiveLayer : chart;
+  const tooltipGeneratorFunc = tooltipLayer.tooltip.contentGenerator();
+  tooltipLayer.tooltip.contentGenerator((d) => {
+    let tooltip = `<div style="max-width: ${container.width() * 0.5}px">`;
+    tooltip += tooltipGeneratorFunc(d);
+    tooltip += '</div>';
+    return tooltip;
+  });
+}
+
 function getMaxLabelSize(container, axisClass) {
   // axis class = .nv-y2  // second y axis on dual line chart
   // axis class = .nv-x  // x axis on time series line chart
@@ -844,6 +856,8 @@ export default function nvd3Vis(slice, payload) {
           .call(chart);
       }
     }
+
+    wrapTooltip(chart, slice.container);
     return chart;
   };
 


Mime
View raw message