Skip to content

Commit 0713f23

Browse files
committed
implement multiple range sliders
1 parent e97a80e commit 0713f23

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

src/components/rangeslider/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ module.exports = {
4848
handleRadius: 1,
4949
handleFill: '#fff',
5050
handleStroke: '#666',
51+
52+
extraPad: 15
5153
};

src/components/rangeslider/draw.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,16 @@ module.exports = function(gd) {
7777
// for all present range sliders
7878
rangeSliders.each(function(axisOpts) {
7979
var rangeSlider = d3.select(this),
80-
opts = axisOpts[constants.name];
80+
opts = axisOpts[constants.name],
81+
oppAxisOpts = fullLayout[Axes.id2name(axisOpts.anchor)];
8182

8283
// update range slider dimensions
8384

8485
var margin = fullLayout.margin,
8586
graphSize = fullLayout._size,
86-
domain = axisOpts.domain;
87+
domain = axisOpts.domain,
88+
oppDomain = oppAxisOpts.domain,
89+
tickHeight = (axisOpts._boundingBox || {}).height || 0;
8790

8891
opts._id = constants.name + axisOpts._id;
8992
opts._clipId = opts._id + '-' + fullLayout._uid;
@@ -92,8 +95,13 @@ module.exports = function(gd) {
9295
opts._height = (fullLayout.height - margin.b - margin.t) * opts.thickness;
9396
opts._offsetShift = Math.floor(opts.borderwidth / 2);
9497

95-
var x = margin.l + (graphSize.w * domain[0]),
96-
y = fullLayout.height - opts._height - margin.b;
98+
var x = margin.l + (graphSize.w * domain[0]);
99+
100+
var y = (
101+
margin.t + graphSize.h * (1 - oppDomain[0]) +
102+
tickHeight +
103+
opts._offsetShift + constants.extraPad
104+
);
97105

98106
rangeSlider.attr('transform', 'translate(' + x + ',' + y + ')');
99107

@@ -131,23 +139,33 @@ module.exports = function(gd) {
131139

132140
// update margins
133141

134-
var bb = axisOpts._boundingBox ? axisOpts._boundingBox.height : 0;
135-
136142
Plots.autoMargin(gd, opts._id, {
137-
x: 0, y: 0, l: 0, r: 0, t: 0,
138-
b: opts._height + fullLayout.margin.b + bb,
139-
pad: 15 + opts._offsetShift * 2
143+
x: domain[0],
144+
y: oppDomain[0],
145+
l: 0,
146+
r: 0,
147+
t: 0,
148+
b: opts._height + margin.b + tickHeight,
149+
pad: constants.extraPad + opts._offsetShift * 2
140150
});
151+
141152
});
142153
};
143154

144155
function makeRangeSliderData(fullLayout) {
145-
if(!fullLayout.xaxis) return [];
146-
if(!fullLayout.xaxis[constants.name]) return [];
147-
if(!fullLayout.xaxis[constants.name].visible) return [];
148-
if(fullLayout._has('gl2d')) return [];
156+
var axes = Axes.list({ _fullLayout: fullLayout }, 'x', true),
157+
name = constants.name,
158+
out = [];
159+
160+
if(fullLayout._has('gl2d')) return out;
149161

150-
return [fullLayout.xaxis];
162+
for(var i = 0; i < axes.length; i++) {
163+
var ax = axes[i];
164+
165+
if(ax[name] && ax[name].visible) out.push(ax);
166+
}
167+
168+
return out;
151169
}
152170

153171
function setupDragElement(rangeSlider, gd, axisOpts, opts) {
@@ -229,7 +247,7 @@ function setDataRange(rangeSlider, gd, axisOpts, opts) {
229247
dataMax = clamp(opts.p2d(opts._pixelMax));
230248

231249
window.requestAnimationFrame(function() {
232-
Plotly.relayout(gd, 'xaxis.range', [dataMin, dataMax]);
250+
Plotly.relayout(gd, axisOpts._name + '.range', [dataMin, dataMax]);
233251
});
234252
}
235253

0 commit comments

Comments
 (0)