-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Rangeslider allow zoom on oppaxis #2364
Changes from 39 commits
519e1a7
044e633
f335258
707f432
6a7f652
fc4f082
92c6550
b30167c
91caff1
3dd91b5
00fd1d7
5e0486a
32488f1
bc2a40a
d3b6071
b496641
149ef70
54d8b58
dd48914
a8a3ee5
0ae2831
8764e4d
a17d3a8
e85e3d0
0dd8562
3929be6
e2ad33d
df85f35
fe83e07
3b6b81a
9de4e3e
f2819c8
df96a13
9c66f81
f092c44
041ce3d
23c8401
73560f6
c556f8c
43f15a7
ccb6091
6a88b24
95b8c10
4f54f62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
|
||
var Lib = require('../../lib'); | ||
var attributes = require('./attributes'); | ||
var oppAxisAttrs = require('./oppaxis_attributes'); | ||
var axisIds = require('../../plots/cartesian/axis_ids'); | ||
|
||
module.exports = function handleDefaults(layoutIn, layoutOut, axName) { | ||
if(!layoutIn[axName].rangeslider) return; | ||
|
@@ -27,6 +29,10 @@ module.exports = function handleDefaults(layoutIn, layoutOut, axName) { | |
return Lib.coerce(containerIn, containerOut, attributes, attr, dflt); | ||
} | ||
|
||
function coerceRange(rangeContainerIn, rangeContainerOut, attr, dflt) { | ||
return Lib.coerce(rangeContainerIn, rangeContainerOut, oppAxisAttrs, attr, dflt); | ||
} | ||
|
||
var visible = coerce('visible'); | ||
if(!visible) return; | ||
|
||
|
@@ -38,6 +44,34 @@ module.exports = function handleDefaults(layoutIn, layoutOut, axName) { | |
coerce('autorange', !axOut.isValidRange(containerIn.range)); | ||
coerce('range'); | ||
|
||
var subplots = layoutOut._subplots; | ||
if(subplots) { | ||
var yIds = subplots.cartesian | ||
.filter(function(subplotId) { | ||
return subplotId.substr(0, subplotId.indexOf('y')) === axisIds.name2id(axName); | ||
}) | ||
.map(function(subplotId) { | ||
return subplotId.substr(subplotId.indexOf('y'), subplotId.length); | ||
}); | ||
var yNames = Lib.simpleMap(yIds, axisIds.id2name); | ||
for(var i = 0; i < yNames.length; i++) { | ||
var yName = yNames[i]; | ||
|
||
var rangeContainerIn = containerIn[yName] || {}; | ||
var rangeContainerOut = containerOut[yName] = {}; | ||
|
||
var rangemodeDflt; | ||
if(rangeContainerIn.range && layoutOut[yName].isValidRange(rangeContainerIn.range)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. The default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
rangemodeDflt = 'fixed'; | ||
} | ||
|
||
var rangeMode = coerceRange(rangeContainerIn, rangeContainerOut, 'rangemode', rangemodeDflt); | ||
if(rangeMode !== 'match') { | ||
coerceRange(rangeContainerIn, rangeContainerOut, 'range', layoutOut[yName].range.slice()); | ||
} | ||
} | ||
} | ||
|
||
// to map back range slider (auto) range | ||
containerOut._input = containerIn; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright 2012-2018, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
// not really a 'subplot' attribute container, | ||
// but this is the flag we use to denote attributes that | ||
// support yaxis, yaxis2, yaxis3, ... counters | ||
_isSubplotObj: true, | ||
|
||
rangemode: { | ||
valType: 'enumerated', | ||
values: ['auto', 'fixed', 'match'], | ||
dflt: 'match', | ||
role: 'style', | ||
editType: 'calc', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alexcjohnson we should be able to change these to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh hmm... actually I don't think we can, it's like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. I tried switching them to |
||
description: [ | ||
'Determines whether or not the range of this axis in', | ||
'the rangeslider use the same value than in the main plot', | ||
'when zooming in/out.', | ||
'If *auto*, the autorange will be used.', | ||
'If *fixed*, the `range` is used.', | ||
'If *match*, the current range of the corresponding y-axis on the main subplot is used.' | ||
].join(' ') | ||
}, | ||
range: { | ||
valType: 'info_array', | ||
role: 'style', | ||
items: [ | ||
{valType: 'any', editType: 'plot'}, | ||
{valType: 'any', editType: 'plot'} | ||
], | ||
editType: 'calc', | ||
description: [ | ||
'Sets the range of this axis for the rangeslider.' | ||
].join(' ') | ||
}, | ||
editType: 'calc' | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit tricky actually - we don't want all y axes, we only want the ones that apply to this x axis. It might be sufficient to look at
subplots.cartesian
, filtering on the x axis ID and taking the y axis IDs (note that you can't do this withsubplotId.indexOf(xId) !== -1
becausex
is a valid ID - you have to do something likesubplotId.substr(0, subplotId.indexOf('y')) === xId
, like here)I say might because I'm not sure what happens with rangesliders now if we have overlaying x axes... that would be very weird and confusing, so I think I'd be OK ignoring the y data for these axes, but we should confirm that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we just use :
layoutOut[yName].anchor === axisIds.name2id(axName)
in thefor
loop ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle you can have a y axis shared across several x axes, or positioned as a free axis, and not anchored to the one with the range slider, so unfortunately I don't think that will work.