Skip to content

Commit

Permalink
moving gd[].dimensions out of parcoords.js #2
Browse files Browse the repository at this point in the history
  • Loading branch information
monfera committed Feb 6, 2017
1 parent 133f3ab commit e256929
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
23 changes: 1 addition & 22 deletions src/traces/parcoords/parcoords.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ function model(layout, d, i, a) {
return {
key: i,
colCount: d.dimensions.filter(visible).length,
_gdDimensions: d._gdDimensions,
_gdDimensionsOriginalOrder: d._gdDimensions.slice(),
dimensions: d.dimensions,
tickDistance: c.tickDistance,
unitToColor: unitToColorScale(d.line.colorscale, d.line.cmin, d.line.cmax, d.line.color),
Expand Down Expand Up @@ -510,27 +508,8 @@ module.exports = function(root, svg, styledData, layout, callbacks) {
p.pickLineLayer && p.pickLineLayer.render(p.panels, true);
linePickActive = true;

// Have updated order data on `gd.data` and raise `Plotly.restyle` event
// without having to incur heavy UI blocking due to an actual `Plotly.restyle` call

var orig = p.model._gdDimensionsOriginalOrder
.filter(function(d) {return d.visible === void(0) || d.visible;});
function newIdx(dim) {
var origIndex = orig.indexOf(dim);
var currentIndex = p.dimensions.map(function(dd) {return dd.crossfilterDimensionIndex;}).indexOf(origIndex);
if(currentIndex === -1) {
// invisible dimensions go to the end, retaining their original order
currentIndex += orig.length;
}
return currentIndex;
}
d.model._gdDimensions.sort(function(d1, d2) {
var i1 = newIdx(d1);
var i2 = newIdx(d2);
return i1 - i2;
});
if(callbacks && callbacks.axesMoved) {
callbacks.axesMoved();
callbacks.axesMoved(p.key, p.dimensions.map(function(dd) {return dd.crossfilterDimensionIndex;}));
}
})
);
Expand Down
33 changes: 31 additions & 2 deletions src/traces/parcoords/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ var Lib = require('../../lib');

module.exports = function plot(gd, cdparcoords) {

var gdDimensions = {};
var gdDimensionsOriginalOrder = {};

var fullLayout = gd._fullLayout;
var svg = fullLayout._paper;
var root = fullLayout._paperdiv;
var data = cdparcoords.map(function(d, i) {
var item = Lib.extendDeep(d[0]);
item._gdDimensions = gd.data[i].dimensions;
gdDimensions[i] = gd.data[i].dimensions;
gdDimensionsOriginalOrder[i] = gd.data[i].dimensions.slice();
return item;
});

var filterChanged = function(i, originalDimensionIndex, newRange) {

// Have updated `constraintrange` data on `gd.data` and raise `Plotly.restyle` event
// without having to incur heavy UI blocking due to an actual `Plotly.restyle` call

var gdDimension = gdDimensionsOriginalOrder[i][originalDimensionIndex];
var gdConstraintRange = gdDimension.constraintrange;
if(!gdConstraintRange || gdConstraintRange.length !== 2) {
Expand All @@ -46,7 +50,32 @@ module.exports = function plot(gd, cdparcoords) {
gd.emit('plotly_unhover', eventData);
};

var axesMoved = function() {
var axesMoved = function(i, visibleIndices) {

// Have updated order data on `gd.data` and raise `Plotly.restyle` event
// without having to incur heavy UI blocking due to an actual `Plotly.restyle` call

function newIdx(visibleIndices, orig, dim) {
var origIndex = orig.indexOf(dim);
var currentIndex = visibleIndices.indexOf(origIndex);
if(currentIndex === -1) {
// invisible dimensions go to the end, retaining their original order
currentIndex += orig.length;
}
return currentIndex;
}

function sorter(orig) {
return function sorter(d1, d2) {
var i1 = newIdx(visibleIndices, orig, d1);
var i2 = newIdx(visibleIndices, orig, d2);
return i1 - i2;
};
}

var orig = sorter(gdDimensionsOriginalOrder[i].filter(function(d) {return d.visible === void(0) || d.visible;}));
gdDimensions[i].sort(orig);

gd.emit('plotly_restyle');
};

Expand Down

0 comments on commit e256929

Please sign in to comment.