Skip to content

Commit

Permalink
[CORESDK-3299] Charts: tooltip customization for boxes in boxplots an…
Browse files Browse the repository at this point in the history
…d candles in candlestick
  • Loading branch information
michelezanda committed Mar 19, 2018
1 parent fe063f5 commit ef9a259
Show file tree
Hide file tree
Showing 20 changed files with 152 additions and 55 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG_ION.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# plotly.js ION changelog

## [1.33.1-ion5] -- 2018-03-19

### [CORESDK-3299] Charts: tooltip customization for boxes in boxplots and candles in candlestick


## [1.33.1-ion4] -- 2018-02-14

### [IONWEBQA-1381] Charts: donut raises exception on click
Expand Down
75 changes: 58 additions & 17 deletions dist_ion/plotly-ion.js
Original file line number Diff line number Diff line change
Expand Up @@ -22559,6 +22559,7 @@ exports.loneHover = function loneHover(hoverItem, opts) {
yLabel: hoverItem.yLabel,
zLabel: hoverItem.zLabel,
text: hoverItem.text,
//textbox: hoverItem.textbox,
name: hoverItem.name,
idealAlign: hoverItem.idealAlign,

Expand Down Expand Up @@ -22803,6 +22804,7 @@ function _hover(gd, evt, subplot, noHoverEvent) {
yLabelVal: undefined,
zLabelVal: undefined,
text: undefined
//textbox: undefined
};

// add ref to subplot object (non-cartesian case)
Expand Down Expand Up @@ -23092,8 +23094,8 @@ function createHoverText(hoverData, opts, gd, evt, hoverFollowsMouse) {
// show the common label, if any, on the axis
// never show a common label in array mode,
// even if sometimes there could be one
var showCommonLabel = c0.distance <= opts.hoverdistance &&
(hovermode === 'x' || hovermode === 'y');
var showCommonLabel = c0.distance <= opts.hoverdistance &&
(hovermode === 'x' || hovermode === 'y');

// all hover traces hoverinfo must contain the hovermode
// to have common labels
Expand Down Expand Up @@ -23263,15 +23265,15 @@ function createHoverText(hoverData, opts, gd, evt, hoverFollowsMouse) {

if(d.text && !Array.isArray(d.text)) {
text += (text ? '<br>' : '') + d.text;
}
}

// if 'text' is empty at this point,
// put 'name' in main label and don't show secondary label
if(text === '') {
// if 'name' is also empty, remove entire label
if(name === '') g.remove();
text = name;
}
}

// main label
var tx = g.select('text.nums')
Expand Down Expand Up @@ -23661,7 +23663,7 @@ function cleanPoint(d, hovermode) {
else d.yLabel += ' ± ' + yeText;

if(hovermode === 'y') d.distance += 1;
}
}

var infomode = d.hoverinfo || d.trace.hoverinfo;

Expand Down Expand Up @@ -32814,7 +32816,7 @@ exports.svgAttrs = {
var Plotly = require('./plotly');

// package version injected by `npm run preprocess`
exports.version = '1.33.1-ion4';
exports.version = '1.33.1-ion5';

// inject promise polyfill
require('es6-promise').polyfill();
Expand Down Expand Up @@ -63602,6 +63604,9 @@ module.exports = {
},
text: extendFlat({}, scatterAttrs.text, {

}),
textbox: extendFlat({}, scatterAttrs.textbox, {

}),
whiskerwidth: {
valType: 'number',
Expand Down Expand Up @@ -64055,6 +64060,7 @@ function handlePointsDefaults(traceIn, traceOut, coerce, opts) {
coerce('unselected.marker.size');

coerce('text');
coerce('textbox');
} else {
delete traceOut.marker;
}
Expand Down Expand Up @@ -64217,8 +64223,8 @@ function hoverOnBoxes(pointData, xval, yval, hovermode) {
}
if(trace.boxpoints || trace.points) {
attrs.push('lf', 'uf');
}

}
for(var i = 0; i < attrs.length; i++) {
var attr = attrs[i];

Expand All @@ -64231,12 +64237,15 @@ function hoverOnBoxes(pointData, xval, yval, hovermode) {
var pointData2 = Lib.extendFlat({}, pointData);

pointData2[vLetter + '0'] = pointData2[vLetter + '1'] = valPx;
pointData2[vLetter + 'LabelVal'] = val;
pointData2[vLetter + 'Label'] = (t.labels ? t.labels[attr] + ' ' : '') + Axes.hoverLabelText(vAxis, val);

if(attr === 'mean' && ('sd' in di) && trace.boxmean === 'sd') {
pointData2[vLetter + 'err'] = di.sd;
}

// ION to support custom tooltips on boxes and candlesticks
if (trace.textbox && trace.textbox[pointData.index] && trace.textbox[pointData.index][i]) {
pointData2['text'] = trace.textbox[pointData.index][i];
} else {
pointData2[vLetter + 'LabelVal'] = val;
pointData2[vLetter + 'Label'] = (t.labels ? t.labels[attr] + ' ' : '') + Axes.hoverLabelText(vAxis, val);
}

// only keep name on the first item (median)
pointData.name = '';

Expand Down Expand Up @@ -65003,6 +65012,7 @@ module.exports = {
decreasing: directionAttrs(OHLCattrs.decreasing.line.color.dflt),

text: OHLCattrs.text,
textbox: OHLCattrs.textbox,
whiskerwidth: extendFlat({}, boxAttrs.whiskerwidth, { dflt: 0 })
};

Expand Down Expand Up @@ -65043,6 +65053,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
handleDirection(traceIn, traceOut, coerce, 'decreasing');

coerce('text');
coerce('textbox');
coerce('whiskerwidth');
};

Expand Down Expand Up @@ -65964,6 +65975,15 @@ module.exports = {

},

textbox: {
valType: 'string',

dflt: '',
arrayOk: true,
editType: 'calc',

},

tickwidth: {
valType: 'number',
min: 0,
Expand Down Expand Up @@ -66013,6 +66033,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
handleDirection(traceIn, traceOut, coerce, 'decreasing');

coerce('text');
coerce('textbox');
coerce('tickwidth');
};

Expand Down Expand Up @@ -66122,6 +66143,8 @@ exports.copyOHLC = function(container, traceOut) {
if(container.high) traceOut.high = container.high;
if(container.low) traceOut.low = container.low;
if(container.close) traceOut.close = container.close;
if(container.text) traceOut.text = container.text;
if(container.textbox) traceOut.textbox = container.textbox;
};

// This routine gets called during the applyTransform step.
Expand All @@ -66143,7 +66166,10 @@ exports.makeTransform = function(traceIn, state, direction) {
open: traceIn.open,
high: traceIn.high,
low: traceIn.low,
close: traceIn.close
close: traceIn.close,

text: traceIn.text,
textbox: traceIn.textbox
};

return out;
Expand Down Expand Up @@ -66251,7 +66277,9 @@ module.exports = function handleOHLC(traceIn, traceOut, coerce, layout) {
open = coerce('open'),
high = coerce('high'),
low = coerce('low'),
close = coerce('close');
close = coerce('close'),
text = coerce('text'),
textbox = coerce('textbox');

var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
handleCalendarDefaults(traceIn, traceOut, ['x'], layout);
Expand All @@ -66267,6 +66295,8 @@ module.exports = function handleOHLC(traceIn, traceOut, coerce, layout) {
if(len < high.length) traceOut.high = high.slice(0, len);
if(len < low.length) traceOut.low = low.slice(0, len);
if(len < close.length) traceOut.close = close.slice(0, len);
if(len < text.length) traceOut.text = text.slice(0, len);
if(len < textbox.length) traceOut.textbox = textbox.slice(0, len);

return len;
};
Expand Down Expand Up @@ -66382,12 +66412,15 @@ function makeHoverInfo(traceIn) {

var parts = hoverinfo.split('+'),
indexOfY = parts.indexOf('y'),
indexOfText = parts.indexOf('text');
indexOfText = parts.indexOf('text'),
indexOfTextbox = parts.indexOf('textbox');

if(indexOfY !== -1) {
parts.splice(indexOfY, 1);

if(indexOfText === -1) parts.push('text');

if(indexOfTextbox === -1) parts.push('textbox');
}

return parts.join('+');
Expand Down Expand Up @@ -68050,6 +68083,14 @@ module.exports = {
arrayOk: true,
editType: 'calc',

},
textbox: {
valType: 'string',

dflt: '',
arrayOk: true,
editType: 'calc',

},
hovertext: {
valType: 'string',
Expand Down
2 changes: 1 addition & 1 deletion dist_ion/plotly-ion.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plotly.js",
"version": "1.33.1-ion4",
"version": "1.33.1-ion5",
"description": "The open source javascript graphing library that powers plotly",
"license": "MIT",
"main": "./lib/index.js",
Expand Down
32 changes: 14 additions & 18 deletions samples/chart_perf.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
var trace1 = {
y: [2, 3, 4, 6,7, 8, 9, 10, 11, 12, 13],
//y: [-40, 50, 60],
// x: ['2017-01-04', '2017-01-05', '2017-01-06'],
//y: [2, 3, 4, 6,7, 8, 9, 10, 11, 12, 13],
y: [-40, 50, 60],
x: ['2017-01-04', '2017-01-05', '2017-01-06'],
// y: [-40, 50, 60],
// close: [116.019997, 116.610001, 117.910004],
close: [116.019997, 116.610001, 117.910004],

// decreasing: {line: {color: '#7F7F7F'}},
decreasing: {line: {color: '#7F7F7F'}},

// high: [116.510002, 116.860001, 118.160004],
high: [116.510002, 116.860001, 118.160004],

// increasing: {line: {color: '#17BECF'}},
increasing: {line: {color: '#17BECF'}},

// line: {color: 'rgba(31,119,180,1)'},
line: {color: 'rgba(31,119,180,1)'},

// low: [115.75, 115.809998, 116.470001],
low: [115.75, 115.809998, 116.470001],

// open: [115.849998, 115.919998, 116.779999],
open: [115.849998, 115.919998, 116.779999],
text: ['ciao1', 'ciao2', 'ciao3', 'ciao3', 'ciao3', 'ciao3', 'ciao3'],
textbox: {
q0: 'goofy0',
q1: 'goofy1',
q2: 'goofy2',
q3: 'goofy3'
},
textbox: [['goofy0', 'goofy1', 'goofy2', 'goofy3', 'goofy4'], ['goofy5', 'goofy6', 'goofy7']],

hoverinfo: 'text',

boxpoints: 'all',
type: 'box',
name: 'prova MZ',
type: 'candlestick',
name: 'MZ',
opacity: 0.5
};

Expand Down
2 changes: 1 addition & 1 deletion src/assets/geo_assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ var saneTopojson = require('sane-topojson');


// package version injected by `npm run preprocess`
exports.version = '1.33.1-ion4';exports.topojson = saneTopojson;
exports.version = '1.33.1-ion5';exports.topojson = saneTopojson;
12 changes: 7 additions & 5 deletions src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ exports.loneHover = function loneHover(hoverItem, opts) {
yLabel: hoverItem.yLabel,
zLabel: hoverItem.zLabel,
text: hoverItem.text,
//textbox: hoverItem.textbox,
name: hoverItem.name,
idealAlign: hoverItem.idealAlign,

Expand Down Expand Up @@ -360,6 +361,7 @@ function _hover(gd, evt, subplot, noHoverEvent) {
yLabelVal: undefined,
zLabelVal: undefined,
text: undefined
//textbox: undefined
};

// add ref to subplot object (non-cartesian case)
Expand Down Expand Up @@ -649,8 +651,8 @@ function createHoverText(hoverData, opts, gd, evt, hoverFollowsMouse) {
// show the common label, if any, on the axis
// never show a common label in array mode,
// even if sometimes there could be one
var showCommonLabel = c0.distance <= opts.hoverdistance &&
(hovermode === 'x' || hovermode === 'y');
var showCommonLabel = c0.distance <= opts.hoverdistance &&
(hovermode === 'x' || hovermode === 'y');

// all hover traces hoverinfo must contain the hovermode
// to have common labels
Expand Down Expand Up @@ -820,15 +822,15 @@ function createHoverText(hoverData, opts, gd, evt, hoverFollowsMouse) {

if(d.text && !Array.isArray(d.text)) {
text += (text ? '<br>' : '') + d.text;
}
}

// if 'text' is empty at this point,
// put 'name' in main label and don't show secondary label
if(text === '') {
// if 'name' is also empty, remove entire label
if(name === '') g.remove();
text = name;
}
}

// main label
var tx = g.select('text.nums')
Expand Down Expand Up @@ -1218,7 +1220,7 @@ function cleanPoint(d, hovermode) {
else d.yLabel += ' ± ' + yeText;

if(hovermode === 'y') d.distance += 1;
}
}

var infomode = d.hoverinfo || d.trace.hoverinfo;

Expand Down
2 changes: 1 addition & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
var Plotly = require('./plotly');

// package version injected by `npm run preprocess`
exports.version = '1.33.1-ion4';
exports.version = '1.33.1-ion5';

// inject promise polyfill
require('es6-promise').polyfill();
Expand Down
8 changes: 8 additions & 0 deletions src/plots/mapbox/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ module.exports = overrideAll({
'Sets the symbol text.'
].join(' ')
},
// textbox: {
// valType: 'string',
// dflt: '',
// role: 'info',
// description: [
// 'Sets the box hover text.'
// ].join(' ')
// },
textfont: fontAttr,
textposition: Lib.extendFlat({}, textposition, { arrayOk: false })
}
Expand Down
5 changes: 5 additions & 0 deletions src/traces/box/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ module.exports = {
'To be seen, trace `hoverinfo` must contain a *text* flag.'
].join(' ')
}),
textbox: extendFlat({}, scatterAttrs.textbox, {
description: [
''
].join(' ')
}),
whiskerwidth: {
valType: 'number',
min: 0,
Expand Down
1 change: 1 addition & 0 deletions src/traces/box/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function handlePointsDefaults(traceIn, traceOut, coerce, opts) {
coerce('unselected.marker.size');

coerce('text');
coerce('textbox');
} else {
delete traceOut.marker;
}
Expand Down
Loading

0 comments on commit ef9a259

Please sign in to comment.