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

Skip to content

Commit f4f1a93

Browse files
committed
make histogram2d and histogram2dcontour have distinct attribute objs
1 parent 9c90e0a commit f4f1a93

File tree

4 files changed

+107
-109
lines changed

4 files changed

+107
-109
lines changed

src/traces/heatmap/attributes.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,8 @@ module.exports = {
8383
'in the `z` data are filled in.'
8484
].join(' ')
8585
},
86-
_nestedModules: { // nested module coupling
86+
87+
_nestedModules: {
8788
'colorbar': 'Colorbar'
88-
},
89-
_composedModules: { // composed module coupling
90-
'histogram2d': 'Histogram',
91-
'histogram2dcontour': 'Histogram'
9289
}
9390
};

src/traces/heatmap/defaults.js

Lines changed: 12 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -9,122 +9,30 @@
99

1010
'use strict';
1111

12-
var isNumeric = require('fast-isnumeric');
13-
14-
var Plots = require('../../plots/plots');
1512
var Lib = require('../../lib');
1613
var Colorscale = require('../../components/colorscale');
1714

18-
var histogramSupplyDefaults = require('../histogram/defaults');
19-
var attributes = require('./attributes');
2015
var hasColumns = require('./has_columns');
16+
var handleXYZDefaults = require('./xyz_defaults');
17+
var attributes = require('./attributes');
2118

2219

2320
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
24-
var isContour = Plots.traceIs(traceOut, 'contour');
25-
2621
function coerce(attr, dflt) {
2722
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
2823
}
2924

30-
if(!isContour) coerce('zsmooth');
31-
32-
if(Plots.traceIs(traceOut, 'histogram')) {
33-
// x, y, z, marker.color, and x0, dx, y0, dy are coerced
34-
// in Histogram.supplyDefaults
35-
// (along with histogram-specific attributes)
36-
histogramSupplyDefaults(traceIn, traceOut);
37-
if(traceOut.visible === false) return;
25+
var len = handleXYZDefaults(traceIn, traceOut, coerce);
26+
if(!len) {
27+
traceOut.visible = false;
28+
return;
3829
}
39-
else {
40-
var len = handleXYZDefaults(traceIn, traceOut, coerce);
41-
if(!len) {
42-
traceOut.visible = false;
43-
return;
44-
}
45-
46-
coerce('text');
4730

48-
var _hasColumns = hasColumns(traceOut);
31+
coerce('text');
32+
coerce('zsmooth');
33+
coerce('connectgaps', hasColumns(traceOut) && (traceOut.zsmooth !== false));
4934

50-
if(!_hasColumns) coerce('transpose');
51-
coerce('connectgaps', _hasColumns &&
52-
(isContour || traceOut.zsmooth !== false));
53-
}
54-
55-
if(!isContour || (traceOut.contours || {}).coloring!=='none') {
56-
Colorscale.handleDefaults(
57-
traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'}
58-
);
59-
}
35+
Colorscale.handleDefaults(
36+
traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'}
37+
);
6038
};
61-
62-
function handleXYZDefaults(traceIn, traceOut, coerce) {
63-
var z = coerce('z');
64-
var x, y;
65-
66-
if(z===undefined || !z.length) return 0;
67-
68-
if(hasColumns(traceIn)) {
69-
x = coerce('x');
70-
y = coerce('y');
71-
72-
// column z must be accompanied by 'x' and 'y' arrays
73-
if(!x || !y) return 0;
74-
}
75-
else {
76-
x = coordDefaults('x', coerce);
77-
y = coordDefaults('y', coerce);
78-
79-
// TODO put z validation elsewhere
80-
if(!isValidZ(z)) return 0;
81-
}
82-
83-
return traceOut.z.length;
84-
}
85-
86-
function coordDefaults(coordStr, coerce) {
87-
var coord = coerce(coordStr),
88-
coordType = coord ?
89-
coerce(coordStr + 'type', 'array') :
90-
'scaled';
91-
92-
if(coordType === 'scaled') {
93-
coerce(coordStr + '0');
94-
coerce('d' + coordStr);
95-
}
96-
97-
return coord;
98-
}
99-
100-
function isValidZ(z) {
101-
var allRowsAreArrays = true,
102-
oneRowIsFilled = false,
103-
hasOneNumber = false,
104-
zi;
105-
106-
/*
107-
* Without this step:
108-
*
109-
* hasOneNumber = false breaks contour but not heatmap
110-
* allRowsAreArrays = false breaks contour but not heatmap
111-
* oneRowIsFilled = false breaks both
112-
*/
113-
114-
for(var i = 0; i < z.length; i++) {
115-
zi = z[i];
116-
if(!Array.isArray(zi)) {
117-
allRowsAreArrays = false;
118-
break;
119-
}
120-
if(zi.length > 0) oneRowIsFilled = true;
121-
for(var j = 0; j < zi.length; j++) {
122-
if(isNumeric(zi[j])) {
123-
hasOneNumber = true;
124-
break;
125-
}
126-
}
127-
}
128-
129-
return (allRowsAreArrays && oneRowIsFilled && hasOneNumber);
130-
}

src/traces/histogram2d/attributes.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
var histogramAttrs = require('../histogram/attributes');
11+
var heatmapAttrs = require('../heatmap/attributes');
12+
13+
module.exports = {
14+
x: histogramAttrs.x,
15+
y: histogramAttrs.y,
16+
17+
z: {
18+
valType: 'data_array',
19+
description: 'Sets the aggregation data.'
20+
},
21+
marker: {
22+
color: {
23+
valType: 'data_array',
24+
description: 'Sets the aggregation data.'
25+
}
26+
},
27+
28+
histnorm: histogramAttrs.histnorm,
29+
histfunc: histogramAttrs.histfunc,
30+
autobinx:histogramAttrs.autobinx,
31+
nbinsx: histogramAttrs.nbinsx,
32+
xbins: histogramAttrs.xbins,
33+
autobiny: histogramAttrs.autobiny,
34+
nbinsy: histogramAttrs.nbinsy,
35+
ybins: histogramAttrs.ybins,
36+
37+
zauto: heatmapAttrs.zauto,
38+
zmin: heatmapAttrs.zmin,
39+
zmax: heatmapAttrs.zmax,
40+
colorscale: heatmapAttrs.colorscale,
41+
autocolorscale: heatmapAttrs.autocolorscale,
42+
reversescale: heatmapAttrs.reversescale,
43+
showscale: heatmapAttrs.showscale,
44+
45+
zsmooth: heatmapAttrs.zsmooth,
46+
47+
_nestedModules: {
48+
'colorbar': 'Colorbar'
49+
}
50+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
var histogram2dAttrs = require('../histogram2d/attributes');
10+
var contourAttrs = require('../contour/attributes');
11+
12+
module.exports = {
13+
x: histogram2dAttrs.x,
14+
y: histogram2dAttrs.y,
15+
z: histogram2dAttrs.z,
16+
marker: histogram2dAttrs.marker,
17+
18+
histnorm: histogram2dAttrs.histnorm,
19+
histfunc: histogram2dAttrs.histfunc,
20+
autobinx:histogram2dAttrs.autobinx,
21+
nbinsx: histogram2dAttrs.nbinsx,
22+
xbins: histogram2dAttrs.xbins,
23+
autobiny: histogram2dAttrs.autobiny,
24+
nbinsy: histogram2dAttrs.nbinsy,
25+
ybins: histogram2dAttrs.ybins,
26+
27+
zauto: contourAttrs.zauto,
28+
zmin: contourAttrs.zmin,
29+
zmax: contourAttrs.zmax,
30+
colorscale: contourAttrs.colorscale,
31+
autocolorscale: contourAttrs.autocolorscale,
32+
reversescale: contourAttrs.reversescale,
33+
showscale: contourAttrs.showscale,
34+
35+
autocontour: contourAttrs.autocontour,
36+
ncontours: contourAttrs.ncontours,
37+
contours: contourAttrs.contours,
38+
line: contourAttrs.line,
39+
40+
_nestedModules: {
41+
'colorbar': 'Colorbar'
42+
}
43+
};

0 commit comments

Comments
 (0)