8000 Cartesian dropline support by rpaskowitz · Pull Request #1461 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Cartesian dropline support #1461

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 30 commits into from
Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d9fab15
Cartesian dropline support
rpaskowitz Mar 10, 2017
5d39b53
Removed chart config for showDroplines
rpaskowitz Mar 11, 2017
be47533
Add spikecolor, spikethickness, spikedash and spikemode
rpaskowitz Apr 7, 2017
17d815c
Add cartesian spikeline modebar support
rpaskowitz Apr 7, 2017
162068e
Merge branch 'master' into dropline
rpaskowitz Apr 7, 2017
762b54a
Move dashStyle to Drawing
rpaskowitz Apr 7, 2017
d680bd4
Name back to showspikes
rpaskowitz Apr 7, 2017
2433d4c
Lint, test and implementation fixes
rpaskowitz Apr 7, 2017
75da2fe
add spikeline icon
etpinard Apr 7, 2017
7953488
Fix cartesian check and fine-tune marker placement
rpaskowitz Apr 7, 2017
55b17b2
Merge branch 'master' into dropline
etpinard Apr 10, 2017
b9f6ab1
Refactor dropline to spikeline
rpaskowitz Apr 10, 2017
7fe4363
Merge branch 'dropline' of github.com:rpaskowitz/plotly.js into dropline
rpaskowitz Apr 10, 2017
34a1562
Switch from getBoundingClientRect to offsetLeft and offsetTop.
rpaskowitz Apr 10, 2017
8c7ac76
Move spike setup from axis to layout.
rpaskowitz Apr 10, 2017
6e243de
Fix marker positioning and across rendering for top-side x-axes.
rpaskowitz Apr 11, 2017
c036bf7
Merge branch 'master' into dropline
alexcjohnson Apr 13, 2017
08371c2
short-circuit redraw for spike attribute relayouts
alexcjohnson Apr 14, 2017
69dc781
fix manual-hover logic for event emitting
alexcjohnson Apr 14, 2017
37b77fe
don't make spike markers crisp
alexcjohnson Apr 14, 2017
710d2d6
alter logic for where spikes start and end
alexcjohnson Apr 14, 2017
e509fa7
lint
alexcjohnson Apr 14, 2017
75121d2
:hocho: spikemode: 'none'
alexcjohnson Apr 17, 2017
bd11567
make drawing/attributes.dash - and clean up some dashes that don't fi…
alexcjohnson Apr 17, 2017
3a9aa58
short-circuit spike properties when spikes are off
alexcjohnson Apr 17, 2017
052417b
test hover event response to manual and "real" events
alexcjohnson Apr 17, 2017
a3a0a4f
:hocho: fit
alexcjohnson Apr 17, 2017
f7b467e
fix scattermapbox defaults for omitted options
alexcjohnson Apr 18, 2017
7aa4359
lint
alexcjohnson Apr 18, 2017
5925049
:hocho: :hocho:
alexcjohnson Apr 18, 2017
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
Prev Previous commit
Next Next commit
Add cartesian spikeline modebar support
  • Loading branch information
rpaskowitz committed Apr 7, 2017
commit 17d815c71e57c19157b9730faa38e7665e0edf61
49 changes: 48 additions & 1 deletion src/components/modebar/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ function handleCartesian(gd, ev) {
var mag = (val === 'in') ? 0.5 : 2,
r0 = (1 + mag) / 2,
r1 = (1 - mag) / 2,
axList = Axes.list(gd, null, true);
axList = Axes.list(gd, null, true),
allEnabled = 'on';
Copy link
Collaborator

Choose a reason for hiding this comment

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

this (and fullLayout._cartesianSpikesEnabled) reads to me like a boolean, and it seems like that would simplify some of the logic too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, this would be better as a boolean, and is how I had it originally. I wound up changing it to take advantage of the modebar logic which sets the active class. Because the val on the button is passed through a data-val attr on the dom, and the is a strict equality check at https://github.com/plotly/plotly.js/blob/master/src/components/modebar/modebar.js#L211 I found I couldn't use a boolean. Open to suggestions that let me keep this as a boolean, but get to use the state display on the modebar.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, makes sense. Sure, lets leave it as a string then. Thanks for pointing me back to this.


var ax, axName;

Expand All @@ -202,6 +203,12 @@ function handleCartesian(gd, ev) {
aobj[axName + '.range[0]'] = rangeInitial[0];
aobj[axName + '.range[1]'] = rangeInitial[1];
}
if(ax._showSpikeInitial !== undefined) {
aobj[axName + '.showspike'] = ax._showSpikeInitial;
if(allEnabled === 'on' && !ax._showSpikeInitial) {
allEnabled = 'off';
}
}
}
else {
var rangeNow = [
Expand All @@ -219,12 +226,17 @@ function handleCartesian(gd, ev) {
}
}
}
fullLayout._cartesianSpikesEnabled = allEnabled;
}
else {
// if ALL traces have orientation 'h', 'hovermode': 'x' otherwise: 'y'
if(astr === 'hovermode' && (val === 'x' || val === 'y')) {
val = fullLayout._isHoriz ? 'y' : 'x';
button.setAttribute('data-val', val);
if(val !== 'closest') {
fullLayout._cartesianSpikesEnabled = 'off';
aobj = setSpikelineVisibility(gd);
}
}

aobj[astr] = val;
Expand Down Expand Up @@ -518,3 +530,38 @@ modeBarButtons.resetViews = {
// geo subplots.
}
};

modeBarButtons.toggleSpikelines = {
name: 'toggleSpikelines',
title: 'Toggle Spike Lines',
icon: Icons.home,
attr: '_cartesianSpikesEnabled',
val: 'on',
click: function(gd) {
var fullLayout = gd._fullLayout;

fullLayout._cartesianSpikesEnabled = fullLayout.hovermode === 'closest' ?
(fullLayout._cartesianSpikesEnabled === 'on' ? 'off' : 'on') : 'on';

var aobj = setSpikelineVisibility(gd);

aobj.hovermode = 'closest';
Plotly.relayout(gd, aobj);
}
};

function setSpikelineVisibility(gd) {
var fullLayout = gd._fullLayout,
axList = Axes.list(gd, null, true),
ax,
axName,
aobj = {};

for(var i = 0; i < axList.length; i++) {
ax = axList[i];
axName = ax._name;
aobj[axName + '.showspike'] = fullLayout._cartesianSpikesEnabled === 'on' ? true : false;
}

return aobj;
}
2 changes: 1 addition & 1 deletion src/components/modebar/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
addGroup(['hoverClosestGl2d']);
}
else if(hasCartesian) {
addGroup(['hoverClosestCartesian', 'hoverCompareCartesian']);
addGroup(['toggleSpikelines', 'hoverClosestCartesian', 'hoverCompareCartesian']);
Copy link
Contributor

Choose a reason for hiding this comment

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

peek 2017-04-07 17-09

Personally, I think I'd prefer placing this new icon first from the right. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My reasoning was to put it beside hovermode: closest because of how spikeline functionality is tied to that mode. (Needed for any spikelines, and using the toggle will force you into that mode)

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point. I'm ok leaving it there.

}
else if(hasPie) {
addGroup(['hoverClosestPie']);
Expand Down
9 changes: 6 additions & 3 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,12 @@ Plotly.plot = function(gd, data, layout, config) {
makePlotFramework(gd);
}

// save initial axis range once per graph
if(graphWasEmpty) Plotly.Axes.saveRangeInitial(gd);

if(graphWasEmpty) {
// save initial axis range once per graph
Plotly.Axes.saveRangeInitial(gd);
// save initial show spikes once per graph
Plotly.Axes.saveShowSpikeInitial(gd);
}
Copy link
Collaborator
@alexcjohnson alexcjohnson Apr 7, 2017

Choose a reason for hiding this comment

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


// prepare the data and find the autorange

Expand Down
29 changes: 29 additions & 0 deletions src/plots/cartesian/axes.js
F438
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,35 @@ axes.saveRangeInitial = function(gd, overwrite) {
return hasOneAxisChanged;
};

// save a copy of the initial spike visibility
axes.saveShowSpikeInitial = function(gd, overwrite) {
var axList = axes.list(gd, '', true),
hasOneAxisChanged = false,
allEnabled = 'on';

for(var i = 0; i < axList.length; i++) {
var ax = axList[i];

var isNew = (ax._showSpikeInitial === undefined);
var hasChanged = (
isNew || !(
ax.showspike === ax._showspike
)
);

if((isNew) || (overwrite && hasChanged)) {
ax._showSpikeInitial = ax.showspike;
hasOneAxisChanged = true;
}

if(allEnabled === 'on' && !ax.showspike) {
allEnabled = 'off';
}
}
gd._fullLayout._cartesianSpikesEnabled = allEnabled;
return hasOneAxisChanged;
};

// axes.expand: if autoranging, include new data in the outer limits
// for this axis
// data is an array of numbers (ie already run through ax.d2c)
Expand Down
2 changes: 1 addition & 1 deletion src/plots/cartesian/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
coerce('range');
containerOut.cleanRange();

coerce('showspikes');
coerce('showspike');
coerce('spikecolor');
coerce('spikethickness');
coerce('spikedash');
Expand Down
4 changes: 2 additions & 2 deletions src/plots/cartesian/graph_interact.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ function createDroplines(hoverData, opts) {
container.selectAll('circle.dropline').remove();


if(c0.ya.showspikes) {
if(c0.ya.showspike) {
if(ySpikeLine) {
// Background horizontal Line (to y-axis)
container.append('line')
Expand Down Expand Up @@ -913,7 +913,7 @@ function createDroplines(hoverData, opts) {
}
}

if(c0.xa.showspikes) {
if(c0.xa.showspike) {
if(xSpikeLine) {
// Background vertical line (to x-axis)
container.append('line')
Expand Down
4 changes: 2 additions & 2 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ module.exports = {
role: 'style',
description: 'Determines whether or not the tick labels are drawn.'
},
showspikes: {
showspike: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

in gl2d it's already showspikes - which I think makes sense, as even if at any given time you only show one, there are many spikes you could show, ie one for each data point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I can change this back. I was thinking of the plural in terms of the axes, not the data points.

valType: 'boolean',
dflt: true,
dflt: false,
role: 'style',
description: [
'Determines whether or not spikes (aka droplines) are drawn for this axis.',
Expand Down
0