Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 2 additions & 5 deletions src/components/rangeslider/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ module.exports = {
grabAreaFill: 'transparent',
grabAreaCursor: 'col-resize',
grabAreaWidth: 10,
grabAreaMinOffset: -6,
grabAreaMaxOffset: -2,

handleWidth: 2,
handleWidth: 4,
handleRadius: 1,
handleFill: '#fff',
handleStroke: '#666',
handleStrokeWidth: 1,

extraPad: 15
};
51 changes: 31 additions & 20 deletions src/components/rangeslider/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ module.exports = function(gd) {
opts._height = (fullLayout.height - margin.b - margin.t) * opts.thickness;
opts._offsetShift = Math.floor(opts.borderwidth / 2);

var x = margin.l + (graphSize.w * domain[0]);
var x = Math.round(margin.l + (graphSize.w * domain[0]));

var y = (
var y = Math.round(
margin.t + graphSize.h * (1 - oppDomain[0]) +
tickHeight +
opts._offsetShift + constants.extraPad
Expand Down Expand Up @@ -252,11 +252,16 @@ function setDataRange(rangeSlider, gd, axisOpts, opts) {
}

function setPixelRange(rangeSlider, gd, axisOpts, opts) {
var hw2 = constants.handleWidth / 2;

function clamp(v) {
return Lib.constrain(v, 0, opts._width);
}

function clampHandle(v) {
return Lib.constrain(v, -hw2, opts._width + hw2);
}

var pixelMin = clamp(opts.d2p(axisOpts._rl[0])),
pixelMax = clamp(opts.d2p(axisOpts._rl[1]));

Expand All @@ -271,11 +276,17 @@ function setPixelRange(rangeSlider, gd, axisOpts, opts) {
.attr('x', pixelMax)
.attr('width', opts._width - pixelMax);

// ..
var offset = 0.5;

var xMin = Math.round(clampHandle(pixelMin - hw2)) - offset,
xMax = Math.round(clampHandle(pixelMax - hw2)) + offset;

rangeSlider.select('g.' + constants.grabberMinClassName)
.attr('transform', 'translate(' + (pixelMin - constants.handleWidth - 1) + ',0)');
.attr('transform', 'translate(' + xMin + ',' + offset + ')');

rangeSlider.select('g.' + constants.grabberMaxClassName)
.attr('transform', 'translate(' + pixelMax + ',0)');
.attr('transform', 'translate(' + xMax + ',' + offset + ')');
}

function drawBg(rangeSlider, gd, axisOpts, opts) {
Expand All @@ -295,14 +306,15 @@ function drawBg(rangeSlider, gd, axisOpts, opts) {
opts.borderwidth - 1;

var offsetShift = -opts._offsetShift;
var lw = Drawing.crispRound(gd, opts.borderwidth);

bg.attr({
width: opts._width + borderCorrect,
height: opts._height + borderCorrect,
transform: 'translate(' + offsetShift + ',' + offsetShift + ')',
fill: opts.bgcolor,
stroke: opts.bordercolor,
'stroke-width': opts.borderwidth,
'stroke-width': lw
});
}

Expand Down Expand Up @@ -415,7 +427,8 @@ function drawMasks(rangeSlider, gd, axisOpts, opts) {

maskMin.enter().append('rect')
.classed(constants.maskMinClassName, true)
.attr({ x: 0, y: 0 });
.attr({ x: 0, y: 0 })
.attr('shape-rendering', 'crispEdges');

maskMin
.attr('height', opts._height)
Expand All @@ -426,7 +439,8 @@ function drawMasks(rangeSlider, gd, axisOpts, opts) {

maskMax.enter().append('rect')
.classed(constants.maskMaxClassName, true)
.attr('y', 0);
.attr('y', 0)
.attr('shape-rendering', 'crispEdges');

maskMax
.attr('height', opts._height)
Expand All @@ -442,7 +456,8 @@ function drawSlideBox(rangeSlider, gd, axisOpts, opts) {
slideBox.enter().append('rect')
.classed(constants.slideBoxClassName, true)
.attr('y', 0)
.attr('cursor', constants.slideBoxCursor);
.attr('cursor', constants.slideBoxCursor)
.attr('shape-rendering', 'crispEdges');

slideBox.attr({
height: opts._height,
Expand Down Expand Up @@ -470,14 +485,15 @@ function drawGrabbers(rangeSlider, gd, axisOpts, opts) {
x: 0,
width: constants.handleWidth,
rx: constants.handleRadius,
fill: constants.handleFill,
stroke: constants.handleStroke,
fill: Color.background,
stroke: Color.defaultLine,
'stroke-width': constants.handleStrokeWidth,
'shape-rendering': 'crispEdges'
};

var handleDynamicAttrs = {
y: opts._height / 4,
height: opts._height / 2,
y: Math.round(opts._height / 4),
height: Math.round(opts._height / 2),
};

var handleMin = grabberMin.selectAll('rect.' + constants.handleMinClassName)
Expand All @@ -500,6 +516,7 @@ function drawGrabbers(rangeSlider, gd, axisOpts, opts) {

var grabAreaFixAttrs = {
width: constants.grabAreaWidth,
x: 0,
y: 0,
fill: constants.grabAreaFill,
cursor: constants.grabAreaCursor
Expand All @@ -510,20 +527,14 @@ function drawGrabbers(rangeSlider, gd, axisOpts, opts) {
grabAreaMin.enter().append('rect')
.classed(constants.grabAreaMinClassName, true)
.attr(grabAreaFixAttrs);
grabAreaMin.attr({
x: constants.grabAreaMinOffset,
height: opts._height
});
grabAreaMin.attr('height', opts._height);

var grabAreaMax = grabberMax.selectAll('rect.' + constants.grabAreaMaxClassName)
.data([0]);
grabAreaMax.enter().append('rect')
.classed(constants.grabAreaMaxClassName, true)
.attr(grabAreaFixAttrs);
grabAreaMax.attr({
x: constants.grabAreaMaxOffset,
height: opts._height
});
grabAreaMax.attr('height', opts._height);
}

function clearPushMargins(gd) {
Expand Down
Binary file modified test/image/baselines/candlestick_double-y-axis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/candlestick_rangeslider_thai.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/ohlc_first.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/range_slider.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/range_slider_axes_double.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/range_slider_box.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/range_slider_initial_expanded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/range_slider_initial_valid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/range_slider_multiple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions test/jasmine/tests/range_slider_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('the range slider', function() {
var transformParts = node.getAttribute('transform').split('(');

expect(transformParts[0]).toEqual('translate');
expect(+transformParts[1].split(',0)')[0]).toBeWithin(val, TOL);
expect(+transformParts[1].split(',0.5)')[0]).toBeWithin(val, TOL);
}

describe('when specified as visible', function() {
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('the range slider', function() {

expect(gd.layout.xaxis.range).toBeCloseToArray([4, 49], -0.5);
expect(maskMin.getAttribute('width')).toEqual(String(diff));
expect(handleMin.getAttribute('transform')).toBe('translate(' + (diff - 3) + ',0)');
expect(handleMin.getAttribute('transform')).toBe('translate(' + (diff - 2.5) + ',0.5)');
}).then(done);
});

Expand Down Expand Up @@ -204,7 +204,7 @@ describe('the range slider', function() {
expect(+maskMin.getAttribute('width')).toBeWithin(126, TOL);
expect(+maskMax.getAttribute('width')).toEqual(0);
testTranslate1D(handleMin, 123.32);
testTranslate1D(handleMax, 619);
testTranslate1D(handleMax, 617);
})
.then(done);
});
Expand Down