Skip to content

parcoords - bug fix handling undefined ranges and dticks for tickText #4011

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
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions src/traces/parcoords/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ function dimensionDefaults(dimensionIn, dimensionOut, parentOut, opts) {
coerce('ticktext');
coerce('tickformat');
var range = coerce('range');
if(!range) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I would move this down to the plot step. That way we don't have to loop over the data during the defaults.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.
Done in bf02101.

var max = -Infinity;
var min = Infinity;
for(var i = 0; i < values.length; i++) {
var v = values[i];
if(isFinite(v)) {
if(max < v) max = v;
if(min > v) min = v;
}
}

range = [min, max];
}

dimensionOut._ax = {
_id: 'y',
Expand Down
55 changes: 27 additions & 28 deletions src/traces/parcoords/parcoords.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function viewModel(state, callbacks, model) {
var unitPad = c.verticalPadding / height;
var _unitToPaddedPx = unitToPaddedPx(height, c.verticalPadding);

var viewModel = {
var vm = {
key: model.key,
xScale: xScale,
model: model,
Expand All @@ -215,7 +215,7 @@ function viewModel(state, callbacks, model) {

var uniqueKeys = {};

viewModel.dimensions = dimensions.filter(helpers.isVisible).map(function(dimension, i) {
vm.dimensions = dimensions.filter(helpers.isVisible).map(function(dimension, i) {
var domainToPaddedUnit = domainToPaddedUnitScale(dimension, unitPad);
var foundKey = uniqueKeys[dimension.label];
uniqueKeys[dimension.label] = (foundKey || 0) + 1;
Expand All @@ -229,7 +229,7 @@ function viewModel(state, callbacks, model) {
specifiedConstraint.map(function(d) { return d.map(domainToPaddedUnit); }) :
[[-Infinity, Infinity]];
var brushMove = function() {
var p = viewModel;
var p = vm;
p.focusLayer && p.focusLayer.render(p.panels, true);
var filtersActive = someFiltersActive(p);
if(!state.contextShown() && filtersActive) {
Expand Down Expand Up @@ -299,7 +299,7 @@ function viewModel(state, callbacks, model) {
unitToPaddedPx: _unitToPaddedPx,
domainScale: domainScale(height, c.verticalPadding, dimension, tickvals, ticktext),
ordinalScale: ordinalScale(dimension),
parent: viewModel,
parent: vm,
model: model,
brush: brush.makeBrush(
state,
Expand All @@ -310,9 +310,8 @@ function viewModel(state, callbacks, model) {
},
brushMove,
function(f) {
var p = viewModel;
p.focusLayer.render(p.panels, true);
p.pickLayer && p.pickLayer.render(p.panels, true);
vm.focusLayer.render(vm.panels, true);
vm.pickLayer && vm.pickLayer.render(vm.panels, true);
state.linePickActive(true);
if(callbacks && callbacks.filterChanged) {
var invScale = domainToPaddedUnit.invert;
Expand All @@ -321,14 +320,14 @@ function viewModel(state, callbacks, model) {
var newRanges = f.map(function(r) {
return r.map(invScale).sort(Lib.sorterAsc);
}).sort(function(a, b) { return a[0] - b[0]; });
callbacks.filterChanged(p.key, dimension._index, newRanges);
callbacks.filterChanged(vm.key, dimension._index, newRanges);
}
}
)
};
});

return viewModel;
return vm;
}

function styleExtentTexts(selection) {
Expand Down Expand Up @@ -386,8 +385,7 @@ function calcAllTicks(cd) {
var dim = dimensions[k]._ax;

if(dim) {
if(!dim.range) dim.range = [0, 1];
if(!dim.dtick) dim.dtick = 0.1;
if(!dim.dtick) dim.dtick = 0.01 * Math.abs(dim.range[1] - dim.range[0]);
dim.tickformat = dimensions[k].tickformat;

Axes.calcTicks(dim);
Expand All @@ -399,27 +397,28 @@ function calcAllTicks(cd) {
}
}

module.exports = function parcoords(gd, cdModule, layout, callbacks) {
var state = parcoordsInteractionState();
function linearFormat(dim, v) {
return Axes.tickText(dim._ax, v, false).text;
}

var fullLayout = gd._fullLayout;
var svg = fullLayout._toppaper;
var glContainer = fullLayout._glcontainer;
function extremeText(d, isTop) {
if(d.ordinal) return '';
var domain = d.domainScale.domain();
var v = (domain[isTop ? domain.length - 1 : 0]);

function linearFormat(dim, v) {
return Axes.tickText(dim._ax, v, false).text;
}
return linearFormat(d.model.dimensions[d.visibleIndex], v);
}

function extremeText(d, isTop) {
if(d.ordinal) return '';
var domain = d.domainScale.domain();
var v = (domain[isTop ? domain.length - 1 : 0]);

return linearFormat(d.model.dimensions[d.visibleIndex], v);
}
module.exports = function parcoords(gd, cdModule, layout, callbacks) {
var fullLayout = gd._fullLayout;
var svg = fullLayout._toppaper;
var glContainer = fullLayout._glcontainer;

calcAllTicks(cdModule);

var state = parcoordsInteractionState();

var vm = cdModule
.filter(function(d) { return unwrap(d).trace.visible; })
.map(model.bind(0, layout))
Expand Down Expand Up @@ -509,14 +508,14 @@ module.exports = function parcoords(gd, cdModule, layout, callbacks) {
});

var yAxis = parcoordsControlView.selectAll('.' + c.cn.yAxis)
.data(function(vm) { return vm.dimensions; }, keyFun);
.data(function(p) { return p.dimensions; }, keyFun);

yAxis.enter()
.append('g')
.classed(c.cn.yAxis, true);

parcoordsControlView.each(function(vm) {
updatePanelLayout(yAxis, vm);
parcoordsControlView.each(function(p) {
updatePanelLayout(yAxis, p);
});

glLayers
Expand Down
Binary file modified test/image/baselines/gl2d_parcoords.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/gl2d_parcoords_large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.