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

Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.

Commit eb327f0

Browse files
committed
make histogram2d and histogram2dcontour have distinct defaults step:
- split up histogram2d sample attr logic to be reused in histogram2dcontour defaults - use contour style defaults in histogram2dcontour defaults
1 parent 03b1557 commit eb327f0

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

src/traces/histogram2d/defaults.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 Lib = require('../../lib');
13+
var Colorscale = require('../../components/colorscale');
14+
15+
var handleSampleDefaults = require('./sample_defaults');
16+
var attributes = require('./attributes');
17+
18+
19+
module.exports = function supplyDefaults(traceIn, traceOut, layout) {
20+
function coerce(attr, dflt) {
21+
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
22+
}
23+
24+
handleSampleDefaults(traceIn, traceOut, coerce);
25+
26+
coerce('zsmooth');
27+
28+
Colorscale.handleDefaults(
29+
traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'}
30+
);
31+
};
Lines 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 handleBinDefaults = require('../histogram/bin_defaults');
13+
14+
15+
module.exports = function handleSampleDefaults(traceIn, traceOut, coerce) {
16+
var x = coerce('x'),
17+
y = coerce('y');
18+
19+
// we could try to accept x0 and dx, etc...
20+
// but that's a pretty weird use case.
21+
// for now require both x and y explicitly specified.
22+
if(!(x && x.length && y && y.length)) {
23+
traceOut.visible = false;
24+
return;
25+
}
26+
27+
// if marker.color is an array, we can use it in aggregation instead of z
28+
var hasAggregationData = coerce('z') || coerce('marker.color');
29+
30+
if(hasAggregationData) coerce('histfunc');
31+
32+
var binDirections = ['x', 'y'];
33+
handleBinDefaults(traceIn, traceOut, coerce, binDirections);
34+
};
Lines 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 Lib = require('../../lib');
13+
14+
var handleSampleDefaults = require('../histogram2d/sample_defaults');
15+
var handleStyleDefaults = require('../contour/style_defaults');
16+
var attributes = require('./attributes');
17+
18+
19+
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
20+
function coerce(attr, dflt) {
21+
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
22+
}
23+
24+
handleSampleDefaults(traceIn, traceOut, coerce);
25+
26+
var contourStart = Lib.coerce2(traceIn, traceOut, attributes, 'contours.start'),
27+
contourEnd = Lib.coerce2(traceIn, traceOut, attributes, 'contours.end'),
28+
autocontour = coerce('autocontour', !(contourStart && contourEnd));
29+
30+
if(autocontour) coerce('ncontours');
31+
else coerce('contours.size');
32+
33+
handleStyleDefaults(traceIn, traceOut, coerce, layout);
34+
};

0 commit comments

Comments
 (0)