Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94b2098

Browse files
committed
split up scatter defaults in separate files:
- require individual steps in scatter3d, scattergeo, scattergl defaults.
1 parent 2ff7f38 commit 94b2098

File tree

9 files changed

+251
-162
lines changed

9 files changed

+251
-162
lines changed

src/traces/scatter/defaults.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Copyright 2012-2016, 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 Lib = require('../../lib');
13+
14+
var attributes = require('./attributes');
15+
var constants = require('./constants');
16+
var subTypes = require('./subtypes');
17+
var handleXYDefaults = require('./xy_defaults');
18+
var handleMarkerDefaults = require('./marker_defaults');
19+
var handleLineDefaults = require('./line_defaults');
20+
var handleTextDefaults = require('./text_defaults');
21+
var handleFillColorDefaults = require('./fillcolor_defaults');
22+
var errorBarsSupplyDefaults = require('../../components/errorbars/defaults');
23+
24+
25+
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
26+
function coerce(attr, dflt) {
27+
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
28+
}
29+
30+
var len = handleXYDefaults(traceIn, traceOut, coerce),
31+
// TODO: default mode by orphan points...
32+
defaultMode = len < constants.PTS_LINESONLY ? 'lines+markers' : 'lines';
33+
if(!len) {
34+
traceOut.visible = false;
35+
return;
36+
}
37+
38+
coerce('text');
39+
coerce('mode', defaultMode);
40+
41+
if(subTypes.hasLines(traceOut)) {
42+
handleLineDefaults(traceIn, traceOut, defaultColor, coerce);
43+
lineShapeDefaults(traceIn, traceOut, coerce);
44+
coerce('connectgaps');
45+
}
46+
47+
if(subTypes.hasMarkers(traceOut)) {
48+
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce);
49+
}
50+
51+
if(subTypes.hasText(traceOut)) {
52+
handleTextDefaults(traceIn, traceOut, layout, coerce);
53+
}
54+
55+
if(subTypes.hasMarkers(traceOut) || subTypes.hasText(traceOut)) {
56+
coerce('marker.maxdisplayed');
57+
}
58+
59+
coerce('fill');
60+
if(traceOut.fill !== 'none') {
61+
handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);
62+
if(!subTypes.hasLines(traceOut)) lineShapeDefaults(traceIn, traceOut, coerce);
63+
}
64+
65+
errorBarsSupplyDefaults(traceIn, traceOut, defaultColor, {axis: 'y'});
66+
errorBarsSupplyDefaults(traceIn, traceOut, defaultColor, {axis: 'x', inherit: 'y'});
67+
};
68+
69+
function lineShapeDefaults(traceIn, traceOut, coerce) {
70+
var shape = coerce('line.shape');
71+
if(shape==='spline') coerce('line.smoothing');
72+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright 2012-2016, 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+
14+
15+
// common to 'scatter' and 'scattergl'
16+
module.exports = function fillColorDefaults(traceIn, traceOut, defaultColor, coerce) {
17+
var inheritColorFromMarker = false;
18+
19+
if(traceOut.marker) {
20+
// don't try to inherit a color array
21+
var markerColor = traceOut.marker.color,
22+
markerLineColor = (traceOut.marker.line || {}).color;
23+
24+
if(markerColor && !Array.isArray(markerColor)) {
25+
inheritColorFromMarker = markerColor;
26+
}
27+
else if(markerLineColor && !Array.isArray(markerLineColor)) {
28+
inheritColorFromMarker = markerLineColor;
29+
}
30+
}
31+
32+
coerce('fillcolor', Color.addOpacity(
33+
(traceOut.line || {}).color ||
34+
inheritColorFromMarker ||
35+
defaultColor, 0.5
36+
));
37+
};

src/traces/scatter/index.js

Lines changed: 1 addition & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ scatter.moduleType = 'trace';
3737
scatter.name = 'scatter';
3838
scatter.categories = ['cartesian', 'symbols', 'markerColorscale', 'errorBarsOK', 'showLegend'];
3939
scatter.meta = {
40+
Scatter.supplyDefaults = require('./defaults');
4041
description: [
4142
'The scatter trace type encompasses line charts, scatter charts, text charts, and bubble charts.',
4243
'The data visualized as scatter point or lines is set in `x` and `y`.',
@@ -52,142 +53,6 @@ scatter.PTS_LINESONLY = 20;
5253

5354
scatter.attributes = require('./attributes');
5455

55-
var handleXYDefaults = require('./xy_defaults');
56-
57-
scatter.supplyDefaults = function(traceIn, traceOut, defaultColor, layout) {
58-
function coerce(attr, dflt) {
59-
return Lib.coerce(traceIn, traceOut, scatter.attributes, attr, dflt);
60-
}
61-
62-
var len = handleXYDefaults(traceIn, traceOut, coerce),
63-
// TODO: default mode by orphan points...
64-
defaultMode = len < scatter.PTS_LINESONLY ? 'lines+markers' : 'lines';
65-
if(!len) {
66-
traceOut.visible = false;
67-
return;
68-
}
69-
70-
coerce('text');
71-
coerce('mode', defaultMode);
72-
73-
if(scatter.hasLines(traceOut)) {
74-
scatter.lineDefaults(traceIn, traceOut, defaultColor, coerce);
75-
lineShapeDefaults(traceIn, traceOut, coerce);
76-
coerce('connectgaps');
77-
}
78-
79-
if(scatter.hasMarkers(traceOut)) {
80-
scatter.markerDefaults(traceIn, traceOut, defaultColor, layout, coerce);
81-
}
82-
83-
if(scatter.hasText(traceOut)) {
84-
scatter.textDefaults(traceIn, traceOut, layout, coerce);
85-
}
86-
87-
if(scatter.hasMarkers(traceOut) || scatter.hasText(traceOut)) {
88-
coerce('marker.maxdisplayed');
89-
}
90-
91-
coerce('fill');
92-
if(traceOut.fill !== 'none') {
93-
scatter.fillColorDefaults(traceIn, traceOut, defaultColor, coerce);
94-
if(!scatter.hasLines(traceOut)) lineShapeDefaults(traceIn, traceOut, coerce);
95-
}
96-
97-
ErrorBars.supplyDefaults(traceIn, traceOut, defaultColor, {axis: 'y'});
98-
ErrorBars.supplyDefaults(traceIn, traceOut, defaultColor, {axis: 'x', inherit: 'y'});
99-
};
100-
101-
// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
102-
scatter.lineDefaults = function(traceIn, traceOut, defaultColor, coerce) {
103-
var markerColor = (traceIn.marker || {}).color;
104-
105-
// don't try to inherit a color array
106-
coerce('line.color', (Array.isArray(markerColor) ? false : markerColor) ||
107-
defaultColor);
108-
coerce('line.width');
109-
coerce('line.dash');
110-
};
111-
112-
function lineShapeDefaults(traceIn, traceOut, coerce) {
113-
var shape = coerce('line.shape');
114-
if(shape==='spline') coerce('line.smoothing');
115-
}
116-
117-
// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
118-
scatter.markerDefaults = function(traceIn, traceOut, defaultColor, layout, coerce) {
119-
var isBubble = scatter.isBubble(traceIn),
120-
lineColor = (traceIn.line || {}).color,
121-
defaultMLC;
122-
123-
if(lineColor) defaultColor = lineColor;
124-
125-
coerce('marker.symbol');
126-
coerce('marker.opacity', isBubble ? 0.7 : 1);
127-
coerce('marker.size');
128-
129-
coerce('marker.color', defaultColor);
130-
if(Colorscale.hasColorscale(traceIn, 'marker')) {
131-
Colorscale.handleDefaults(
132-
traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'}
133-
);
134-
}
135-
136-
// if there's a line with a different color than the marker, use
137-
// that line color as the default marker line color
138-
// mostly this is for transparent markers to behave nicely
139-
if(lineColor && traceOut.marker.color!==lineColor) {
140-
defaultMLC = lineColor;
141-
}
142-
else if(isBubble) defaultMLC = Color.background;
143-
else defaultMLC = Color.defaultLine;
144-
145-
coerce('marker.line.color', defaultMLC);
146-
if(Colorscale.hasColorscale(traceIn, 'marker.line')) {
147-
Colorscale.handleDefaults(
148-
traceIn, traceOut, layout, coerce, {prefix: 'marker.line.', cLetter: 'c'}
149-
);
150-
}
151-
152-
coerce('marker.line.width', isBubble ? 1 : 0);
153-
154-
if(isBubble) {
155-
coerce('marker.sizeref');
156-
coerce('marker.sizemin');
157-
coerce('marker.sizemode');
158-
}
159-
};
160-
161-
// common to 'scatter', 'scatter3d' and 'scattergeo'
162-
scatter.textDefaults = function(traceIn, traceOut, layout, coerce) {
163-
coerce('textposition');
164-
Lib.coerceFont(coerce, 'textfont', layout.font);
165-
};
166-
167-
// common to 'scatter' and 'scattergl'
168-
scatter.fillColorDefaults = function(traceIn, traceOut, defaultColor, coerce) {
169-
var inheritColorFromMarker = false;
170-
171-
if(traceOut.marker) {
172-
// don't try to inherit a color array
173-
var markerColor = traceOut.marker.color,
174-
markerLineColor = (traceOut.marker.line || {}).color;
175-
176-
if(markerColor && !Array.isArray(markerColor)) {
177-
inheritColorFromMarker = markerColor;
178-
}
179-
else if(markerLineColor && !Array.isArray(markerLineColor)) {
180-
inheritColorFromMarker = markerLineColor;
181-
}
182-
}
183-
184-
coerce('fillcolor', Color.addOpacity(
185-
(traceOut.line || {}).color ||
186-
inheritColorFromMarker ||
187-
defaultColor, 0.5
188-
));
189-
};
190-
19156
scatter.cleanData = function(fullData) {
19257
var i,
19358
tracei,

src/traces/scatter/line_defaults.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright 2012-2016, 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+
// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
14+
module.exports = function lineDefaults(traceIn, traceOut, defaultColor, coerce) {
15+
var markerColor = (traceIn.marker || {}).color;
16+
17+
// don't try to inherit a color array
18+
coerce('line.color', (Array.isArray(markerColor) ? false : markerColor) ||
19+
defaultColor);
20+
coerce('line.width');
21+
coerce('line.dash');
22+
};

src/traces/scatter/marker_defaults.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Copyright 2012-2016, 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 hasColorscale = require('../../components/colorscale/has_colorscale');
14+
var colorscaleDefaults = require('../../components/colorscale/defaults');
15+
16+
var subTypes = require('./subtypes');
17+
18+
19+
// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
20+
module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
21+
var isBubble = subTypes.isBubble(traceIn),
22+
lineColor = (traceIn.line || {}).color,
23+
defaultMLC;
24+
25+
if(lineColor) defaultColor = lineColor;
26+
27+
coerce('marker.symbol');
28+
coerce('marker.opacity', isBubble ? 0.7 : 1);
29+
coerce('marker.size');
30+
31+
coerce('marker.color', defaultColor);
32+
if(hasColorscale(traceIn, 'marker')) {
33+
colorscaleDefaults(
34+
traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'}
35+
);
36+
}
37+
38+
// if there's a line with a different color than the marker, use
39+
// that line color as the default marker line color
40+
// mostly this is for transparent markers to behave nicely
41+
if(lineColor && traceOut.marker.color!==lineColor) {
42+
defaultMLC = lineColor;
43+
}
44+
else if(isBubble) defaultMLC = Color.background;
45+
else defaultMLC = Color.defaultLine;
46+
47+
coerce('marker.line.color', defaultMLC);
48+
if(hasColorscale(traceIn, 'marker.line')) {
49+
colorscaleDefaults(
50+
traceIn, traceOut, layout, coerce, {prefix: 'marker.line.', cLetter: 'c'}
51+
);
52+
}
53+
54+
coerce('marker.line.width', isBubble ? 1 : 0);
55+
56+
if(isBubble) {
57+
coerce('marker.sizeref');
58+
coerce('marker.sizemin');
59+
coerce('marker.sizemode');
60+
}
61+
};

src/traces/scatter/text_defaults.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2012-2016, 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 Lib = require('../../lib');
13+
14+
15+
// common to 'scatter', 'scatter3d' and 'scattergeo'
16+
module.exports = function(traceIn, traceOut, layout, coerce) {
17+
coerce('textposition');
18+
Lib.coerceFont(coerce, 'textfont', layout.font);
19+
};

0 commit comments

Comments
 (0)