Skip to content

Commit 2c14168

Browse files
committed
Cleanup supplyDefaults and add visible dimension property
(property isn't wired up properly yet)
1 parent 6797a83 commit 2c14168

File tree

2 files changed

+46
-60
lines changed

2 files changed

+46
-60
lines changed

src/traces/parcats/attributes.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,14 @@ module.exports = {
133133
].join(' ')
134134
},
135135
editType: 'calc',
136-
description: 'The dimensions (variables) of the parallel categories diagram.'
136+
description: 'The dimensions (variables) of the parallel categories diagram.',
137+
visible: {
138+
valType: 'boolean',
139+
dflt: true,
140+
role: 'info',
141+
editType: 'calc',
142+
description: 'Shows the dimension when set to `true` (the default). Hides the dimension for `false`.'
143+
},
137144
},
138145

139146
line: line,

src/traces/parcats/defaults.js

Lines changed: 38 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,85 +9,55 @@
99
'use strict';
1010

1111
var Lib = require('../../lib');
12-
var attributes = require('./attributes');
13-
var parcatConstants = require('./constants');
14-
var colorbarDefaults = require('../../components/colorbar/defaults');
12+
var hasColorscale = require('../../components/colorscale/has_colorscale');
13+
var colorscaleDefaults = require('../../components/colorscale/defaults');
1514
var handleDomainDefaults = require('../../plots/domain').defaults;
15+
var handleArrayContainerDefaults = require('../../plots/array_container_defaults');
1616

17-
function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
17+
var attributes = require('./attributes');
18+
var mergeLength = require('../parcoords/merge_length');
1819

19-
coerce('line.color', defaultColor);
20+
function handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
2021

2122
if(traceIn.line) {
22-
coerce('line.cmin');
23-
coerce('line.cmax');
24-
coerce('line.cauto');
25-
coerce('line.colorscale');
26-
coerce('line.showscale');
2723
coerce('line.shape');
28-
colorbarDefaults(traceIn.line, traceOut.line, layout);
2924
}
30-
}
31-
32-
function dimensionsDefaults(traceIn, traceOut) {
33-
var dimensionsIn = traceIn.dimensions || [],
34-
dimensionsOut = traceOut.dimensions = [];
3525

36-
var dimensionIn, dimensionOut, i;
37-
var commonLength = Infinity;
26+
var lineColor = coerce('line.color', defaultColor);
27+
if(hasColorscale(traceIn, 'line') && Lib.isArrayOrTypedArray(lineColor)) {
28+
if(lineColor.length) {
29+
coerce('line.colorscale');
30+
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'});
31+
return lineColor.length;
32+
}
33+
else {
34+
traceOut.line.color = defaultColor;
35+
}
36+
}
37+
return Infinity;
38+
}
3839

40+
function dimensionDefaults(dimensionIn, dimensionOut) {
3941
function coerce(attr, dflt) {
4042
return Lib.coerce(dimensionIn, dimensionOut, attributes.dimensions, attr, dflt);
4143
}
4244

43-
for(i = 0; i < dimensionsIn.length; i++) {
44-
dimensionIn = dimensionsIn[i];
45-
dimensionOut = {};
46-
47-
if(!Lib.isPlainObject(dimensionIn)) {
48-
continue;
49-
}
45+
var values = coerce('values');
46+
var visible = coerce('visible');
47+
if(!(values && values.length)) {
48+
visible = dimensionOut.visible = false;
49+
}
5050

51+
if(visible) {
5152
// Dimension level
52-
coerce('values');
5353
coerce('label');
54-
coerce('displayindex', i);
54+
coerce('displayindex', dimensionOut._index);
5555

5656
// Category level
5757
coerce('catDisplayInds');
5858
coerce('catValues');
5959
coerce('catLabels');
60-
61-
// Pass through catValues, catorder, and catlabels (validated in calc since this is where unique info is available)
62-
63-
// pass through line (color)
64-
// Pass through font
65-
66-
commonLength = Math.min(commonLength, dimensionOut.values.length);
67-
68-
// dimensionOut._index = i;
69-
dimensionsOut.push(dimensionOut);
70-
}
71-
72-
if(isFinite(commonLength)) {
73-
for(i = 0; i < dimensionsOut.length; i++) {
74-
dimensionOut = dimensionsOut[i];
75-
if(dimensionOut.values.length > commonLength) {
76-
dimensionOut.values = dimensionOut.values.slice(0, commonLength);
77-
}
78-
}
7960
}
80-
81-
// handle dimension order
82-
// If specified for all dimensions and no collisions or holes keep, otherwise discard
83-
84-
// Pass through value colors
85-
// Pass through opacity
86-
87-
// Pass through dimension font
88-
// Pass through category font
89-
90-
return dimensionsOut;
9161
}
9262

9363
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
@@ -96,11 +66,20 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
9666
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
9767
}
9868

99-
dimensionsDefaults(traceIn, traceOut);
69+
var dimensions = handleArrayContainerDefaults(traceIn, traceOut, {
70+
name: 'dimensions',
71+
handleItemDefaults: dimensionDefaults
72+
});
73+
74+
var len = handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);
10075

10176
handleDomainDefaults(traceOut, layout, coerce);
10277

103-
markerDefaults(traceIn, traceOut, defaultColor, layout, coerce);
78+
if(!Array.isArray(dimensions) || !dimensions.length) {
79+
traceOut.visible = false;
80+
}
81+
82+
mergeLength(traceOut, dimensions, 'values', len);
10483

10584
coerce('hovermode');
10685
coerce('tooltip');

0 commit comments

Comments
 (0)