Skip to content

Commit

Permalink
implement cartesian axis for parcoords and change parcoords tickforma…
Browse files Browse the repository at this point in the history
…t default to be on par with cartesian axes
  • Loading branch information
archmoj committed Jun 19, 2019
1 parent 9e73c27 commit a80bf49
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 27 deletions.
15 changes: 3 additions & 12 deletions src/traces/parcoords/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,9 @@ module.exports = {
'Sets the text displayed at the ticks position via `tickvals`.'
].join(' ')
}),
tickformat: {
valType: 'string',
dflt: '3s',
noBlank: true,
role: 'style',
editType: 'plot',
description: [
'Sets the tick label formatting rule using d3 formatting mini-language',
'which is similar to those of Python. See',
'https://github.com/d3/d3-format/blob/master/README.md#locale_format'
].join(' ')
},
tickformat: extendFlat({}, axesAttrs.tickformat, {
editType: 'plot'
}),
visible: {
valType: 'boolean',
dflt: true,
Expand Down
22 changes: 20 additions & 2 deletions src/traces/parcoords/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var hasColorscale = require('../../components/colorscale/helpers').hasColorscale
var colorscaleDefaults = require('../../components/colorscale/defaults');
var handleDomainDefaults = require('../../plots/domain').defaults;
var handleArrayContainerDefaults = require('../../plots/array_container_defaults');
var Axes = require('../../plots/cartesian/axes');
var axesAttrs = require('../../plots/cartesian/layout_attributes');

var attributes = require('./attributes');
var axisBrush = require('./axisbrush');
Expand All @@ -37,11 +39,15 @@ function handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
return Infinity;
}

function dimensionDefaults(dimensionIn, dimensionOut) {
function dimensionDefaults(dimensionIn, dimensionOut, parentOut, opts) {
function coerce(attr, dflt) {
return Lib.coerce(dimensionIn, dimensionOut, attributes.dimensions, attr, dflt);
}

function axCoerce(attr, dflt) {
return Lib.coerce(dimensionIn, dimensionOut._ax, axesAttrs, attr, dflt);
}

var values = coerce('values');
var visible = coerce('visible');
if(!(values && values.length)) {
Expand All @@ -53,7 +59,18 @@ function dimensionDefaults(dimensionIn, dimensionOut) {
coerce('tickvals');
coerce('ticktext');
coerce('tickformat');
coerce('range');

dimensionOut._ax = {
_id: 'y',
type: 'linear',
showexponent: 'all',
exponentformat: 'B'
};

Axes.setConvert(dimensionOut._ax, opts.layout);

axCoerce('range');
dimensionOut.range = dimensionOut._ax.range;

coerce('multiselect');
var constraintRange = coerce('constraintrange');
Expand All @@ -76,6 +93,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

var dimensions = handleArrayContainerDefaults(traceIn, traceOut, {
name: 'dimensions',
layout: layout,
handleItemDefaults: dimensionDefaults
});

Expand Down
24 changes: 12 additions & 12 deletions src/traces/parcoords/parcoords.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,22 +378,22 @@ function updatePanelLayout(yAxis, vm) {
}
}

function attachAxesToCd(cd, fullLayout) {
function calcAllTicks(cd) {
for(var i = 0; i < cd.length; i++) {
for(var j = 0; j < cd[i].length; j++) {
var dimensions = cd[i][j].trace.dimensions;

for(var k = 0; k < dimensions.length; k++) {
var dim = dimensions[k];
var dim = dimensions[k]._ax;

dim._ax = {
type: 'linear',
showexponent: 'all',
exponentformat: 'B',
tickformat: dim.tickformat
};
if(dim) {
if(!dim.range) dim.range = [0, 1];
if(!dim.dtick) dim.dtick = 0.1;
dim.tickformat = dimensions[k].tickformat;

Axes.calcTicks(dim);

Axes.setConvert(dim._ax, fullLayout);
dim.cleanRange();
}
}
}
}
Expand All @@ -406,8 +406,6 @@ module.exports = function parcoords(gd, cdModule, layout, callbacks) {
var svg = fullLayout._toppaper;
var glContainer = fullLayout._glcontainer;

attachAxesToCd(cdModule, fullLayout);

function linearFormat(dim, v) {
return Axes.tickText(dim._ax, v, false).text;
}
Expand All @@ -420,6 +418,8 @@ module.exports = function parcoords(gd, cdModule, layout, callbacks) {
return linearFormat(d.model.dimensions[d.visibleIndex], v);
}

calcAllTicks(cdModule);

var vm = cdModule
.filter(function(d) { return unwrap(d).trace.visible; })
.map(model.bind(0, layout))
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_256_colors.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_60_dims.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_coloraxis.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.
Binary file modified test/image/baselines/gl2d_parcoords_rgba_colorscale.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_style_labels.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_tick_format.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/jasmine/tests/parcoords_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ describe('parcoords initialization tests', function() {
expect(fullTrace.dimensions).toEqual([jasmine.objectContaining({
values: [1],
visible: true,
tickformat: '3s',
tickformat: '',
multiselect: true,
_index: 0,
_length: 1
Expand Down

0 comments on commit a80bf49

Please sign in to comment.