-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Feature range slider #336
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
Feature range slider #336
Changes from 3 commits
4c28de7
866d1d2
d2973f3
eb619ef
854442d
b0c16cd
2666162
c8d87d0
598d69f
3ecdcdc
fb863f6
5857574
028b46e
4143a65
8cfd258
fe51426
09af762
f381299
149348c
0ebc894
80571f3
c4d19ad
242458d
4f4ffeb
665c061
c008328
0a63f2a
771546c
47a6829
ab9ba72
25071ae
37e93d5
00c0732
4d238e9
21d6bdc
0e9bc90
7fd37ae
0b32a36
88e855b
df58e62
358243d
6bb10c0
0fd5c37
288c4a3
767a821
67674b6
2deed2e
7ead461
5214897
771b113
fb91908
2dd5e8e
83375d2
cb50997
6736bbb
c613c6c
c55bf02
cbe2c26
271589c
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 |
---|---|---|
|
@@ -28,7 +28,12 @@ function draw(gd, minStart, maxStart) { | |
var fullLayout = gd._fullLayout, | ||
options = fullLayout.xaxis.rangeslider; | ||
|
||
if(!options.visible) return; | ||
// don't draw if being exported | ||
if(!options.visible || gd._context.staticPlot) { | ||
options.visible = false; | ||
return; | ||
} | ||
|
||
|
||
var width = fullLayout._size.w, | ||
height = (fullLayout.height - fullLayout.margin.b - fullLayout.margin.t) * options.height, | ||
|
@@ -41,6 +46,7 @@ function draw(gd, minStart, maxStart) { | |
var x = fullLayout.margin.l, | ||
y = fullLayout.height - height - fullLayout.margin.b; | ||
|
||
|
||
var slider = document.createElementNS(svgNS, 'g'); | ||
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. 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. My favourite library: http://vanilla-js.com/ |
||
helpers.setAttributes(slider, { | ||
'class': 'range-slider', | ||
|
@@ -274,12 +280,13 @@ function supplyLayoutDefaults(layoutIn, layoutOut) { | |
attributes, attr, dflt); | ||
} | ||
|
||
var yaxis = layoutOut.yaxis || {}; | ||
yaxis.fixedrange = true; | ||
|
||
coerce('visible'); | ||
coerce('height'); | ||
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. we should return early (and not coerce the other attributes) if |
||
coerce('backgroundcolor'); | ||
coerce('bordercolor'); | ||
coerce('borderwidth'); | ||
|
||
if(containerOut.visible) { | ||
layoutOut.yaxis.fixedrange = true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2407,7 +2407,7 @@ Plotly.relayout = function relayout(gd, astr, val) { | |
newMin = changes['xaxis.range[0]'], | ||
newMax = changes['xaxis.range[1]']; | ||
|
||
if(fullLayout.xaxis.rangeslider.visible) { | ||
if(fullLayout.xaxis && fullLayout.xaxis.rangeslider.visible) { | ||
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. kinda hacky here. But, yeah, I can't think of a better way at the moment. 👍 |
||
if(newMin && newMax) { | ||
fullLayout.xaxis.rangeslider.setRange(newMin, newMax); | ||
} else if(changes['xaxis.autorange']) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ describe('the range slider', function() { | |
}); | ||
|
||
it('should react to resizing the minimum handle', function() { | ||
var start = 86, | ||
var start = 85, | ||
end = 140, | ||
dataMinStart = rangeSlider.getAttribute('data-min'), | ||
diff = end - start; | ||
|
@@ -62,7 +62,7 @@ describe('the range slider', function() { | |
}); | ||
|
||
it('should react to resizing the maximum handle', function() { | ||
var start = 706, | ||
var start = 705, | ||
end = 500, | ||
dataMaxStart = rangeSlider.getAttribute('data-max'), | ||
diff = end - start; | ||
|
@@ -117,7 +117,7 @@ describe('the range slider', function() { | |
|
||
var rangeDiff = gd._fullLayout.xaxis.range[1] - gd._fullLayout.xaxis.range[0]; | ||
|
||
expect(rangeDiff).toBeCloseTo(21.009, 2); | ||
expect(rangeDiff).toBeCloseTo(21, 1); | ||
}); | ||
}); | ||
|
||
|
@@ -142,9 +142,9 @@ describe('the range slider', function() { | |
describe('supplyLayoutDefaults function', function() { | ||
|
||
it('should not mutate layoutIn', function() { | ||
var layoutIn = { xaxis: { rangeslider: { visible: true }}}, | ||
layoutOut = { xaxis: { rangeslider: {}}}, | ||
expected = { xaxis: { rangeslider: { visible: true }}}; | ||
var layoutIn = { xaxis: { rangeslider: { visible: true }}, yaxis: {}}, | ||
layoutOut = { xaxis: { rangeslider: {}}, yaxis: {}}, | ||
expected = { xaxis: { rangeslider: { visible: true }}, yaxis: {}}; | ||
|
||
RangeSlider.supplyLayoutDefaults(layoutIn, layoutOut); | ||
|
||
|
@@ -161,15 +161,22 @@ describe('the range slider', function() { | |
}); | ||
|
||
it('should set defaults if rangeslider.visible is true', function() { | ||
var layoutIn = { xaxis: { rangeslider: { visible: true }}}, | ||
layoutOut = { xaxis: { rangeslider: {}}}, | ||
expected = { xaxis: { rangeslider: { | ||
visible: true, | ||
height: 0.15, | ||
backgroundcolor: '#ffffff', | ||
borderwidth: 1, | ||
bordercolor: 'transparent' | ||
}}}; | ||
var layoutIn = { xaxis: { rangeslider: { visible: true }}, yaxis: {}}, | ||
layoutOut = { xaxis: { rangeslider: {}}, yaxis: {}}, | ||
expected = { | ||
xaxis: { | ||
rangeslider: { | ||
visible: true, | ||
height: 0.15, | ||
backgroundcolor: '#ffffff', | ||
borderwidth: 1, | ||
bordercolor: 'transparent' | ||
} | ||
}, | ||
yaxis: { | ||
fixedrange: true | ||
} | ||
}; | ||
|
||
RangeSlider.supplyLayoutDefaults(layoutIn, layoutOut); | ||
|
||
|
@@ -183,15 +190,15 @@ describe('the range slider', function() { | |
backgroundcolor: 42, | ||
bordercolor: 42, | ||
borderwidth: 'superfat' | ||
}}}, | ||
layoutOut = { xaxis: { rangeslider: {}}}, | ||
}}, yaxis: {}}, | ||
layoutOut = { xaxis: { rangeslider: {}}, yaxis: {}}, | ||
expected = { xaxis: { rangeslider: { | ||
visible: false, | ||
height: 0.15, | ||
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. ICYMI ⏫ , the attributes shouldn't be coerced when |
||
backgroundcolor: '#ffffff', | ||
borderwidth: 1, | ||
bordercolor: 'transparent' | ||
}}}; | ||
}}, yaxis: {}}; | ||
|
||
RangeSlider.supplyLayoutDefaults(layoutIn, layoutOut); | ||
|
||
|
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.
I'm ok with this for the first iteration. But, I'm curious. What happens when you try to export a graph with a range slider?
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.
It happily exports it :)
We could maybe add the option to have it displayed on export or not as an attribute too.
excludeonexport: false
or something a bit less verbose.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.
Highchart exports their range sliders by default ; I'd vote for exporting them by default.