Skip to content

Commit 39b71bb

Browse files
committed
add dimensions[i].axis.type
.. to more easily set axis type on splom-generated axes
1 parent ab7d9c6 commit 39b71bb

File tree

6 files changed

+55
-18
lines changed

6 files changed

+55
-18
lines changed

src/plots/cartesian/axis_defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ var setConvert = require('./set_convert');
3333
*/
3434
module.exports = function handleAxisDefaults(containerIn, containerOut, coerce, options, layoutOut) {
3535
var letter = options.letter;
36-
var id = containerOut._id;
3736
var font = options.font || {};
37+
var splomStash = options.splomStash || {};
3838

3939
var visible = coerce('visible', !options.cheateronly);
4040

@@ -66,7 +66,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
6666
// template too.
6767
var dfltFontColor = (dfltColor !== layoutAttributes.color.dflt) ? dfltColor : font.color;
6868
// try to get default title from splom trace, fallback to graph-wide value
69-
var dfltTitle = ((layoutOut._splomAxes || {})[letter] || {})[id] || layoutOut._dfltTitle[letter];
69+
var dfltTitle = splomStash.label || layoutOut._dfltTitle[letter];
7070

7171
coerce('title', dfltTitle);
7272
Lib.coerceFont(coerce, 'titlefont', {

src/plots/cartesian/layout_defaults.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
172172
bgColor: bgColor,
173173
calendar: layoutOut.calendar,
174174
automargin: true,
175-
cheateronly: axLetter === 'x' && xaCheater[axName] && !xaNonCheater[axName]
175+
cheateronly: axLetter === 'x' && xaCheater[axName] && !xaNonCheater[axName],
176+
splomStash: ((layoutOut._splomAxes || {})[axLetter] || {})[id]
176177
};
177178

178179
handleTypeDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions);

src/plots/cartesian/type_defaults.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var Registry = require('../../registry');
@@ -17,8 +16,8 @@ var autoType = require('./axis_autotype');
1716
* name: axis object name (ie 'xaxis') if one should be stored
1817
*/
1918
module.exports = function handleTypeDefaults(containerIn, containerOut, coerce, options) {
19+
var axType = coerce('type', (options.splomStash || {}).type);
2020

21-
var axType = coerce('type');
2221
if(axType === '-') {
2322
setAutoType(containerOut, options.data);
2423

src/traces/splom/defaults.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ function dimensionDefaults(dimIn, dimOut) {
6161

6262
if(!(values && values.length)) dimOut.visible = false;
6363
else coerce('visible');
64+
65+
coerce('axis.type');
6466
}
6567

6668
function handleAxisDefaults(traceIn, traceOut, layout, coerce) {
@@ -148,7 +150,13 @@ function fillAxisStash(layout, axId, dim) {
148150
var stash = layout._splomAxes[axLetter];
149151

150152
if(!(axId in stash)) {
151-
stash[axId] = (dim || {}).label || '';
153+
var s = stash[axId] = {};
154+
if(dim) {
155+
s.label = dim.label || '';
156+
if(dim.visible && dim.axis) {
157+
s.type = dim.axis.type;
158+
}
159+
}
152160
}
153161
}
154162

test/image/mocks/splom_multi-axis-type.json

+5-12
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
},
1717
{
1818
"label": "bool",
19-
"values": [false, true, true, true, false, true, false, false, false, true]
19+
"values": [false, true, true, true, false, true, false, false, false, true],
20+
"axis": {"type": "category"}
2021
},
2122
{
2223
"label": "0/1",
23-
"values": [0, 1, 1, 1, 1, 1, 0, 0, 0, 0]
24+
"values": [0, 1, 1, 1, 1, 1, 0, 0, 0, 0],
25+
"axis": {"type": "category"}
2426
},
2527
{
2628
"label": "string",
@@ -31,15 +33,6 @@
3133
],
3234
"layout": {
3335
"hovermode": "closest",
34-
"margin": {
35-
"b": 80,
36-
"l": 80,
37-
"r": 30,
38-
"t": 30
39-
},
40-
"yaxis2": {"type": "category"},
41-
"yaxis3": {"type": "category"},
42-
"xaxis3": {"type": "category"},
43-
"xaxis4": {"type": "category"}
36+
"margin": {"b": 80, "l": 80, "r": 30, "t": 30}
4437
}
4538
}

test/jasmine/tests/splom_test.js

+36
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,42 @@ describe('Test splom trace defaults:', function() {
357357
expect(fullLayout.xaxis2.type).toBe('date');
358358
expect(fullLayout.yaxis2.type).toBe('date');
359359
});
360+
361+
it('axis type in layout takes precedence over dimensions setting', function() {
362+
_supply({
363+
dimensions: [
364+
{values: [1, 2, 1], axis: {type: 'category'}},
365+
{values: [2, 1, 3]}
366+
]
367+
}, {
368+
xaxis: {type: 'linear'},
369+
yaxis: {type: 'linear'},
370+
xaxis2: {type: 'category'},
371+
yaxis2: {type: 'category'}
372+
});
373+
374+
var fullLayout = gd._fullLayout;
375+
expect(fullLayout.xaxis.type).toBe('linear');
376+
expect(fullLayout.yaxis.type).toBe('linear');
377+
expect(fullLayout.xaxis2.type).toBe('category');
378+
expect(fullLayout.yaxis2.type).toBe('category');
379+
});
380+
381+
it('axis type setting should be skipped when dimension is not visible', function() {
382+
_supply({
383+
dimensions: [
384+
{visible: false, values: [1, 2, 1], axis: {type: 'category'}},
385+
{values: [-1, 2, 3], axis: {type: 'category'}},
386+
]
387+
}, {
388+
});
389+
390+
var fullLayout = gd._fullLayout;
391+
expect(fullLayout.xaxis.type).toBe('linear');
392+
expect(fullLayout.yaxis.type).toBe('linear');
393+
expect(fullLayout.xaxis2.type).toBe('category');
394+
expect(fullLayout.yaxis2.type).toBe('category');
395+
});
360396
});
361397

362398
describe('Test splom trace calc step:', function() {

0 commit comments

Comments
 (0)