From ed64f141077d3acab1ccd7a534d327aaf460ba0f Mon Sep 17 00:00:00 2001 From: lepricon49 Date: Thu, 17 Dec 2015 13:24:39 -0800 Subject: [PATCH 1/3] Add the ability to use aggregate values for box plots Add a new calcdataOverride property for box plot objects which will allow calculated box plot values to be replaced. To use, pass the aggregate values as the main data along with calcdataOverride property. Plotly will calculate all of the values so it is only necessary to override some of the values. Look at the calculateStats function in Plotly.js to see the properties that can be overridden. --- src/plot_api/plot_api.js | 4 ++++ src/traces/boxes/attributes.js | 3 +++ src/traces/boxes/index.js | 1 + 3 files changed, 8 insertions(+) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 42db83daa92..3c430a166f8 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -994,6 +994,10 @@ function doCalcdata(gd) { if (!cd[0].t) cd[0].t = {}; cd[0].trace = trace; + if (trace.calcdataOverride) { + cd[0] = _.defaults(trace.calcdataOverride, cd[0]); + } + Plotly.Lib.markTime('done with calcdata for '+i); calcdata[i] = cd; } diff --git a/src/traces/boxes/attributes.js b/src/traces/boxes/attributes.js index 40c33a8e2b0..5d79849424e 100644 --- a/src/traces/boxes/attributes.js +++ b/src/traces/boxes/attributes.js @@ -171,5 +171,8 @@ module.exports = { description: 'Sets the width (in px) of line bounding the box(es).' } }, + calcdataOverride: { + valType: 'any', + }, fillcolor: scatterAttrs.fillcolor }; diff --git a/src/traces/boxes/index.js b/src/traces/boxes/index.js index f5f0f804c83..83b4843361b 100644 --- a/src/traces/boxes/index.js +++ b/src/traces/boxes/index.js @@ -65,6 +65,7 @@ boxes.supplyDefaults = function(traceIn, traceOut, defaultColor) { coerce('whiskerwidth'); coerce('boxmean'); + coerce('calcdataOverride'); var outlierColorDflt = Plotly.Lib.coerce2(traceIn, traceOut, boxes.attributes, 'marker.outliercolor'), lineoutliercolor = coerce('marker.line.outliercolor'), From 11c679a71b7ad7b8db81049074a1dbc1cde134d6 Mon Sep 17 00:00:00 2001 From: lepricon49 Date: Mon, 21 Dec 2015 14:28:16 -0800 Subject: [PATCH 2/3] Adjust tabs type to conform with standards --- src/plot_api/plot_api.js | 2 +- src/traces/box/attributes.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 3c430a166f8..13aca86c633 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -995,7 +995,7 @@ function doCalcdata(gd) { cd[0].trace = trace; if (trace.calcdataOverride) { - cd[0] = _.defaults(trace.calcdataOverride, cd[0]); + cd[0] = _.defaults(trace.calcdataOverride, cd[0]); } Plotly.Lib.markTime('done with calcdata for '+i); diff --git a/src/traces/box/attributes.js b/src/traces/box/attributes.js index 5d79849424e..2ac20d85b40 100644 --- a/src/traces/box/attributes.js +++ b/src/traces/box/attributes.js @@ -172,7 +172,7 @@ module.exports = { } }, calcdataOverride: { - valType: 'any', + valType: 'any', }, fillcolor: scatterAttrs.fillcolor }; From 2d079dc12f6074a1aae791d3fc7ac1e78df978b4 Mon Sep 17 00:00:00 2001 From: lepricon49 Date: Wed, 30 Dec 2015 14:11:13 -0800 Subject: [PATCH 3/3] Add "xtext" hoverinfo type and always show prefix/suffix for hover text "xtext" will cause the text to show in the x-axis hover box instead of the y-axis --- src/plots/attributes.js | 2 +- src/plots/cartesian/axes.js | 2 +- src/plots/cartesian/graph_interact.js | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/plots/attributes.js b/src/plots/attributes.js index 76ae50f3a93..09f09c33111 100644 --- a/src/plots/attributes.js +++ b/src/plots/attributes.js @@ -69,7 +69,7 @@ module.exports = { hoverinfo: { valType: 'flaglist', role: 'info', - flags: ['x', 'y', 'z', 'text', 'name'], + flags: ['x', 'y', 'z', 'text', 'name', 'xtext'], extras: ['all', 'none'], dflt: 'all', description: 'Determines which trace information appear on hover.' diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js index c4a3e8148bd..98bfce813e8 100644 --- a/src/plots/cartesian/axes.js +++ b/src/plots/cartesian/axes.js @@ -1594,7 +1594,7 @@ axes.tickText = function(ax, x, hover){ var first_or_last; if (showAttr===undefined) return true; - if (hover) return showAttr==='none'; + if (hover) return false; // always show tick prefix/suffix on hover, *especially* if showAttr == 'none' first_or_last = { first: ax._tmin, diff --git a/src/plots/cartesian/graph_interact.js b/src/plots/cartesian/graph_interact.js index dbd965b53c3..8b90562d69c 100644 --- a/src/plots/cartesian/graph_interact.js +++ b/src/plots/cartesian/graph_interact.js @@ -629,6 +629,10 @@ function cleanPoint(d, hovermode) { else d.xLabel = '-' + xLabelObj.text; } else d.xLabel = xLabelObj.text; + + if (d.trace.hoverinfo.indexOf("xtext") > -1 && d.text && d.text != "") { + d.xLabel += "
" + d.text + } d.xVal = d.xa.c2d(d.xLabelVal); }