Skip to content

Rangeslider data conversion #441

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

Merged
merged 2 commits into from
Apr 19, 2016
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
18 changes: 0 additions & 18 deletions src/components/rangeslider/data_processors.js

This file was deleted.

26 changes: 16 additions & 10 deletions src/components/rangeslider/range_plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var Symbols = require('../drawing/symbol_defs');
var Drawing = require('../drawing');

var helpers = require('./helpers');
var dataProcessors = require('./data_processors');
var svgNS = require('../../constants/xmlns_namespaces').svg;

module.exports = function rangePlot(gd, w, h) {
Expand Down Expand Up @@ -42,10 +41,6 @@ module.exports = function rangePlot(gd, w, h) {
rangePlot.appendChild(clipDefs);


var processX = dataProcessors[gd._fullLayout.xaxis.type || 'category'],
processY = dataProcessors[gd._fullLayout.yaxis.type || 'category'];


// for now, only scatter traces are supported
var allowedTypes = ['scatter'];

Expand All @@ -59,12 +54,13 @@ module.exports = function rangePlot(gd, w, h) {
continue;
}

for(var k = 0; k < trace.x.length; k++) {
var x = processX(trace.x[k], k),
y = processY(trace.y[k], k);
var x = makeLinearData(trace, xaxis),
y = makeLinearData(trace, yaxis);

var posX = w * (x - minX) / (maxX - minX),
posY = h * (1 - (y - minY) / (maxY - minY));
for(var k = 0; k < x.length; k++) {

var posX = w * (x[k] - minX) / (maxX - minX),
posY = h * (1 - (y[k] - minY) / (maxY - minY));

pointPairs.push([posX, posY]);
}
Expand All @@ -77,6 +73,16 @@ module.exports = function rangePlot(gd, w, h) {
return rangePlot;
};

function makeLinearData(trace, axis) {
var data = axis.makeCalcdata(trace || [], axis._id[0]);

for(var i = 0; i < data.length; i++) {
data[i] = axis.c2l(data[i]);
}

return data;
}


function makeScatter(trace, pointPairs, w, h) {

Expand Down
29 changes: 29 additions & 0 deletions test/jasmine/tests/range_slider_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,35 @@ describe('the range slider', function() {
expect(layoutOut).toEqual(expected);
});
});

describe('in general', function() {

beforeEach(function() {
gd = createGraphDiv();
});

afterEach(destroyGraphDiv);

it('should plot when only x data is provided', function(done) {
Plotly.plot(gd, [{ x: [1,2,3] }], { xaxis: { rangeslider: {} }})
.then(function() {
var rangeslider = document.getElementsByClassName('range-slider');

expect(rangeslider.length).toBe(1);
})
.then(done);
});

it('should plot when only y data is provided', function(done) {
Plotly.plot(gd, [{ y: [1,2,3] }], { xaxis: { rangeslider: {} }})
.then(function() {
var rangeslider = document.getElementsByClassName('range-slider');

expect(rangeslider.length).toBe(1);
})
.then(done);
});
});
});


Expand Down