Skip to content

Box points hover & select #2094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/fx/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exports.p2c = function p2c(axArray, v) {
};

exports.getDistanceFunction = function getDistanceFunction(mode, dx, dy, dxy) {
if(mode === 'closest') return dxy || quadrature(dx, dy);
if(mode === 'closest') return dxy || exports.quadrature(dx, dy);
return mode === 'x' ? dx : dy;
};

Expand Down Expand Up @@ -77,13 +77,13 @@ exports.inbox = function inbox(v0, v1) {
return Infinity;
};

function quadrature(dx, dy) {
exports.quadrature = function quadrature(dx, dy) {
return function(di) {
var x = dx(di),
y = dy(di);
return Math.sqrt(x * x + y * y);
};
}
};

/** Appends values inside array attributes corresponding to given point number
*
Expand Down
26 changes: 2 additions & 24 deletions src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,36 +1065,14 @@ function cleanPoint(d, hovermode) {

// and convert the x and y label values into objects
// formatted as text, with font info
var logOffScale;
if(d.xLabelVal !== undefined) {
logOffScale = (d.xa.type === 'log' && d.xLabelVal <= 0);
var xLabelObj = Axes.tickText(d.xa,
d.xa.c2l(logOffScale ? -d.xLabelVal : d.xLabelVal), 'hover');
if(logOffScale) {
if(d.xLabelVal === 0) d.xLabel = '0';
else d.xLabel = '-' + xLabelObj.text;
}
// TODO: should we do something special if the axis calendar and
// the data calendar are different? Somehow display both dates with
// their system names? Right now it will just display in the axis calendar
// but users could add the other one as text.
else d.xLabel = xLabelObj.text;
d.xLabel = ('xLabel' in d) ? d.xLabel : Axes.hoverLabelText(d.xa, d.xLabelVal);
d.xVal = d.xa.c2d(d.xLabelVal);
}

if(d.yLabelVal !== undefined) {
logOffScale = (d.ya.type === 'log' && d.yLabelVal <= 0);
var yLabelObj = Axes.tickText(d.ya,
d.ya.c2l(logOffScale ? -d.yLabelVal : d.yLabelVal), 'hover');
if(logOffScale) {
if(d.yLabelVal === 0) d.yLabel = '0';
else d.yLabel = '-' + yLabelObj.text;
}
// TODO: see above TODO
else d.yLabel = yLabelObj.text;
d.yLabel = ('yLabel' in d) ? d.yLabel : Axes.hoverLabelText(d.ya, d.yLabelVal);
d.yVal = d.ya.c2d(d.yLabelVal);
}

if(d.zLabelVal !== undefined) d.zLabel = String(d.zLabelVal);

// for box means and error bars, add the range to the label
Expand Down
1 change: 1 addition & 0 deletions src/components/fx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = {
getDistanceFunction: helpers.getDistanceFunction,
getClosest: helpers.getClosest,
inbox: helpers.inbox,
quadrature: helpers.quadrature,
appendArrayPointValue: helpers.appendArrayPointValue,

castHoverOption: castHoverOption,
Expand Down
4 changes: 4 additions & 0 deletions src/components/modebar/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ function isSelectable(fullData) {
if(scatterSubTypes.hasMarkers(trace) || scatterSubTypes.hasText(trace)) {
selectable = true;
}
} else if(Registry.traceIs(trace, 'box')) {
if(trace.boxpoints === 'all') {
selectable = true;
}
}
// assume that in general if the trace module has selectPoints,
// then it's selectable. Scatter is an exception to this because it must
Expand Down
15 changes: 15 additions & 0 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,21 @@ axes.tickText = function(ax, x, hover) {
return out;
};

axes.hoverLabelText = function(ax, val) {
var logOffScale = (ax.type === 'log' && val <= 0);
var tx = axes.tickText(ax, ax.c2l(logOffScale ? -val : val), 'hover').text;

if(logOffScale) {
return val === 0 ? '0' : '-' + tx;
}

// TODO: should we do something special if the axis calendar and
// the data calendar are different? Somehow display both dates with
// their system names? Right now it will just display in the axis calendar
// but users could add the other one as text.
return tx;
};

function tickTextObj(ax, x, text) {
var tf = ax.tickfont || {};

Expand Down
6 changes: 4 additions & 2 deletions src/traces/bar/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var DESELECTDIM = require('../../constants/interactions').DESELECTDIM;

module.exports = function selectPoints(searchInfo, polygon) {
var cd = searchInfo.cd;
var xa = searchInfo.xaxis;
var ya = searchInfo.yaxis;
var selection = [];
var trace = cd[0].trace;
var node3 = cd[0].node3;
Expand All @@ -31,8 +33,8 @@ module.exports = function selectPoints(searchInfo, polygon) {
if(polygon.contains(di.ct)) {
selection.push({
pointNumber: i,
x: di.x,
y: di.y
x: xa.c2d(di.x),
y: ya.c2d(di.y)
});
di.dim = 0;
} else {
Expand Down
34 changes: 28 additions & 6 deletions src/traces/box/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ var scatterAttrs = require('../scatter/attributes');
var colorAttrs = require('../../components/color/attributes');
var extendFlat = require('../../lib/extend').extendFlat;

var scatterMarkerAttrs = scatterAttrs.marker,
scatterMarkerLineAttrs = scatterMarkerAttrs.line;

var scatterMarkerAttrs = scatterAttrs.marker;
var scatterMarkerLineAttrs = scatterMarkerAttrs.line;

module.exports = {
y: {
Expand Down Expand Up @@ -63,6 +62,16 @@ module.exports = {
'missing and the position axis is categorical'
].join(' ')
},
text: extendFlat({}, scatterAttrs.text, {
Copy link
Contributor Author

@etpinard etpinard Oct 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

text is expected to be an array as long as the sample array y (x) for vertical (horizontal) box plots, matching each sample pt one-to-one.

description: [
'Sets the text elements associated with each sample value.',
'If a single string, the same string appears over',
'all the data points.',
'If an array of string, the items are mapped in order to the',
'this trace\'s (x,y) coordinates.',
'To be seen, trace `hoverinfo` must contain a *text* flag.'
].join(' ')
}),
whiskerwidth: {
valType: 'number',
min: 0,
Expand Down Expand Up @@ -159,9 +168,11 @@ module.exports = {
{arrayOk: false, editType: 'style'}),
line: {
color: extendFlat({}, scatterMarkerLineAttrs.color,
{arrayOk: false, dflt: colorAttrs.defaultLine, editType: 'style'}),
{arrayOk: false, dflt: colorAttrs.defaultLine, editType: 'style'}
),
width: extendFlat({}, scatterMarkerLineAttrs.width,
{arrayOk: false, dflt: 0, editType: 'style'}),
{arrayOk: false, dflt: 0, editType: 'style'}
),
outliercolor: {
valType: 'color',
role: 'style',
Expand Down Expand Up @@ -202,5 +213,16 @@ module.exports = {
},
editType: 'plot'
},
fillcolor: scatterAttrs.fillcolor
fillcolor: scatterAttrs.fillcolor,
hoveron: {
valType: 'flaglist',
flags: ['boxes', 'points'],
dflt: 'boxes+points',
role: 'info',
editType: 'style',
description: [
'Do the hover effects highlight individual boxes ',
'or sample points or both?'
].join(' ')
}
};
Loading