Skip to content

Commit d3b6071

Browse files
Added default attributes
1 parent bc2a40a commit d3b6071

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

src/components/rangeslider/defaults.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
var Lib = require('../../lib');
1212
var attributes = require('./attributes');
13+
var rangeAttributes = require('./range_attributes');
14+
var axisIds = require('../../plots/cartesian/axis_ids');
1315

1416
module.exports = function handleDefaults(layoutIn, layoutOut, axName) {
1517
if(!layoutIn[axName].rangeslider) return;
@@ -27,6 +29,10 @@ module.exports = function handleDefaults(layoutIn, layoutOut, axName) {
2729
return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
2830
}
2931

32+
function coerceRange(yName, attr, dflt) {
33+
return Lib.coerce(containerIn[yName], containerOut[yName], rangeAttributes, attr, dflt);
34+
}
35+
3036
var visible = coerce('visible');
3137
if(!visible) return;
3238

@@ -37,7 +43,30 @@ module.exports = function handleDefaults(layoutIn, layoutOut, axName) {
3743

3844
coerce('autorange', !axOut.isValidRange(containerIn.range));
3945
coerce('range');
40-
containerOut.yaxis = containerIn.yaxis;
46+
47+
var subplots = layoutOut._subplots;
48+
var yIds = subplots.yaxis;
49+
var yNames = Lib.simpleMap(yIds, axisIds.id2name);
50+
for(var i = 0; i < yNames.length; i++) {
51+
var yName = yNames[i];
52+
if(!containerIn[yName]) {
53+
containerIn[yName] = {};
54+
}
55+
if(!containerOut[yName]) {
56+
containerOut[yName] = {};
57+
}
58+
59+
if(containerIn[yName].range && layoutOut[yName].isValidRange(containerIn[yName].range)) {
60+
coerceRange(yName, 'rangemode', 'fixed');
61+
} else {
62+
coerceRange(yName, 'rangemode', 'auto');
63+
}
64+
65+
coerceRange(yName, 'range');
66+
layoutOut[yName].cleanRange('rangeslider.' + yName + '.range');
67+
layoutOut[axName].rangeslider[yName].range = layoutOut[yName].rangeslider[yName].range.slice();
68+
delete layoutOut[yName].rangeslider;
69+
}
4170

4271
// to map back range slider (auto) range
4372
containerOut._input = containerIn;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright 2012-2018, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = {
12+
rangemode: {
13+
valType: 'enumerated',
14+
values: ['auto', 'fixed', 'match'],
15+
dflt: 'auto',
16+
role: 'style',
17+
editType: 'calc',
18+
description: [
19+
'Determines whether or not the range of this axis in',
20+
'the rangeslider use the same value than in the main plot',
21+
'when zooming in/out.',
22+
'If *auto*, the autorange will be used.',
23+
'If *fixed*, the `rangesliderrange` is used.',
24+
'If *match*, the current range is used.'
25+
].join(' ')
26+
},
27+
range: {
28+
valType: 'info_array',
29+
role: 'style',
30+
items: [
31+
{valType: 'any', editType: 'calc'},
32+
{valType: 'any', editType: 'calc'}
33+
],
34+
editType: 'calc',
35+
description: [
36+
'Sets the range of this axis for the rangeslider.'
37+
].join(' ')
38+
},
39+
editType: 'calc'
40+
};

0 commit comments

Comments
 (0)