Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7bc3e75

Browse filesBrowse files
committed
make bar and histogram have distinct defaults step:
- split bar style defaults logic into own file to be reused by histogram defaults - split histogram bin defaults logic into own file to be reused by histogram2d and histogram2dcontour defaults
1 parent f4f1a93 commit 7bc3e75
Copy full SHA for 7bc3e75

File tree

4 files changed

+91
-71
lines changed
Filter options

4 files changed

+91
-71
lines changed

‎src/traces/bar/defaults.js

Copy file name to clipboardExpand all lines: src/traces/bar/defaults.js
+9-33Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,31 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../../plotly');
1312
var Lib = require('../../lib');
1413
var Color = require('../../components/color');
1514

16-
var histogramSupplyDefaults = require('../histogram/defaults');
1715
var handleXYDefaults = require('../scatter/xy_defaults');
16+
var handleStyleDefaults = require('../bar/style_defaults');
1817
var errorBarsSupplyDefaults = require('../../components/errorbars/defaults');
19-
2018
var attributes = require('./attributes');
2119

2220

23-
module.exports = function(traceIn, traceOut, defaultColor, layout) {
21+
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
2422
function coerce(attr, dflt) {
2523
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
2624
}
2725

28-
if(traceOut.type === 'histogram') {
29-
// x, y, and orientation are coerced in the histogram supplyDefaults
30-
// (along with histogram-specific attributes)
31-
histogramSupplyDefaults(traceIn, traceOut);
32-
if(!traceOut.visible) return;
33-
}
34-
else {
35-
var len = handleXYDefaults(traceIn, traceOut, coerce);
36-
if(!len) {
37-
traceOut.visible = false;
38-
return;
39-
}
40-
41-
coerce('orientation', (traceOut.x && !traceOut.y) ? 'h' : 'v');
42-
}
43-
44-
coerce('marker.color', defaultColor);
45-
if(Plotly.Colorscale.hasColorscale(traceIn, 'marker')) {
46-
Plotly.Colorscale.handleDefaults(
47-
traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'}
48-
);
49-
}
50-
51-
coerce('marker.line.color', Plotly.Color.defaultLine);
52-
if(Plotly.Colorscale.hasColorscale(traceIn, 'marker.line')) {
53-
Plotly.Colorscale.handleDefaults(
54-
traceIn, traceOut, layout, coerce, {prefix: 'marker.line.', cLetter: 'c'}
55-
);
26+
var len = handleXYDefaults(traceIn, traceOut, coerce);
27+
if(!len) {
28+
traceOut.visible = false;
29+
return;
5630
}
5731

58-
coerce('marker.line.width', 0);
32+
coerce('orientation', (traceOut.x && !traceOut.y) ? 'h' : 'v');
5933
coerce('text');
6034

35+
handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout);
36+
6137
// override defaultColor for error bars with defaultLine
6238
errorBarsSupplyDefaults(traceIn, traceOut, Color.defaultLine, {axis: 'y'});
6339
errorBarsSupplyDefaults(traceIn, traceOut, Color.defaultLine, {axis: 'x', inherit: 'y'});

‎src/traces/bar/style_defaults.js

Copy file name to clipboard
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright 2012-2015, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
10+
'use strict';
11+
12+
var Color = require('../../components/color');
13+
var Colorscale = require('../../components/colorscale');
14+
15+
16+
module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout) {
17+
coerce('marker.color', defaultColor);
18+
19+
if(Colorscale.hasColorscale(traceIn, 'marker')) {
20+
Colorscale.handleDefaults(
21+
traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'}
22+
);
23+
}
24+
25+
coerce('marker.line.color', Color.defaultLine);
26+
27+
if(Colorscale.hasColorscale(traceIn, 'marker.line')) {
28+
Colorscale.handleDefaults(
29+
traceIn, traceOut, layout, coerce, {prefix: 'marker.line.', cLetter: 'c'}
30+
);
31+
}
32+
33+
coerce('marker.line.width');
34+
};

‎src/traces/histogram/bin_defaults.js

Copy file name to clipboard
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright 2012-2015, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
10+
'use strict';
11+
12+
13+
module.exports = function handleBinDefaults(traceIn, traceOut, coerce, binDirections) {
14+
coerce('histnorm');
15+
16+
binDirections.forEach(function(binDirection) {
17+
// data being binned - note that even though it's a little weird,
18+
// it's possible to have bins without data, if there's inferred data
19+
var binstrt = coerce(binDirection + 'bins.start'),
20+
binend = coerce(binDirection + 'bins.end'),
21+
autobin = coerce('autobin' + binDirection, !(binstrt && binend));
22+
23+
if(autobin) coerce('nbins' + binDirection);
24+
else coerce(binDirection + 'bins.size');
25+
});
26+
27+
return traceOut;
28+
};

‎src/traces/histogram/defaults.js

Copy file name to clipboardExpand all lines: src/traces/histogram/defaults.js
+20-38Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,42 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../../plotly');
1312
var Lib = require('../../lib');
13+
var Color = require('../../components/color');
1414

15+
var handleBinDefaults = require('./bin_defaults');
16+
var handleStyleDefaults = require('../bar/style_defaults');
17+
var errorBarsSupplyDefaults = require('../../components/errorbars/defaults');
1518
var attributes = require('./attributes');
1619

1720

18-
module.exports = function(traceIn, traceOut) {
21+
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
1922
function coerce(attr, dflt) {
2023
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
2124
}
2225

23-
var binDirections = ['x'],
24-
hasAggregationData,
25-
x = coerce('x'),
26+
var x = coerce('x'),
2627
y = coerce('y');
2728

28-
if(Plotly.Plots.traceIs(traceOut, '2dMap')) {
29-
// we could try to accept x0 and dx, etc...
30-
// but that's a pretty weird use case.
31-
// for now require both x and y explicitly specified.
32-
if(!(x && x.length && y && y.length)) {
33-
traceOut.visible = false;
34-
return;
35-
}
29+
coerce('text');
3630

37-
// if marker.color is an array, we can use it in aggregation instead of z
38-
hasAggregationData = coerce('z') || coerce('marker.color');
31+
var orientation = coerce('orientation', (y && !x) ? 'h' : 'v'),
32+
sample = traceOut[orientation==='v' ? 'x' : 'y'];
3933

40-
binDirections = ['x','y'];
41-
} else {
42-
var orientation = coerce('orientation', (y && !x) ? 'h' : 'v'),
43-
sample = traceOut[orientation==='v' ? 'x' : 'y'];
44-
45-
if(!(sample && sample.length)) {
46-
traceOut.visible = false;
47-
return;
48-
}
49-
50-
if(orientation==='h') binDirections = ['y'];
51-
52-
hasAggregationData = traceOut[orientation==='h' ? 'x' : 'y'];
34+
if(!(sample && sample.length)) {
35+
traceOut.visible = false;
36+
return;
5337
}
5438

39+
var hasAggregationData = traceOut[orientation==='h' ? 'x' : 'y'];
5540
if(hasAggregationData) coerce('histfunc');
56-
coerce('histnorm');
5741

58-
binDirections.forEach(function(binDirection) {
59-
// data being binned - note that even though it's a little weird,
60-
// it's possible to have bins without data, if there's inferred data
61-
var binstrt = coerce(binDirection + 'bins.start'),
62-
binend = coerce(binDirection + 'bins.end'),
63-
autobin = coerce('autobin' + binDirection, !(binstrt && binend));
42+
var binDirections = (orientation==='h') ? ['y'] : ['x'];
43+
handleBinDefaults(traceIn, traceOut, coerce, binDirections);
44+
45+
handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout);
6446

65-
if(autobin) coerce('nbins' + binDirection);
66-
else coerce(binDirection + 'bins.size');
67-
});
47+
// override defaultColor for error bars with defaultLine
48+
errorBarsSupplyDefaults(traceIn, traceOut, Color.defaultLine, {axis: 'y'});
49+
errorBarsSupplyDefaults(traceIn, traceOut, Color.defaultLine, {axis: 'x', inherit: 'y'});
6850
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.