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

Trace type <-> trace module 1-to-1 correspondance #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Dec 17, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1e923c9
break up heatmap index:
etpinard Dec 15, 2015
6b8885a
split parts of the scatter index:
etpinard Dec 16, 2015
c0f85e6
split up bars index
etpinard Dec 16, 2015
503fd93
mv traceColorbar from colorbar/ to heatmap/
etpinard Dec 16, 2015
7f1801e
split up contour index
etpinard Dec 16, 2015
2ba8f80
split up histogram index
etpinard Dec 16, 2015
27b0910
mv histogram calc2d to histogram2d/
etpinard Dec 16, 2015
50f290c
register histogram module, require parts for Bars in it.
etpinard Dec 16, 2015
ab7ff1d
register histogram2d module, require parts of heatmap in it.
etpinard Dec 16, 2015
1a90968
register histogram2dcontour, require pars of contour in it.
etpinard Dec 16, 2015
2f3bd84
require histogram2d/calc in heatmap/calc,
etpinard Dec 16, 2015
bb542ab
require histogram/defaults in heatmap/defaults
etpinard Dec 16, 2015
0d6fecc
require xy defaults + errorbar defaults in scattergl defaults
etpinard Dec 16, 2015
67ae5aa
adapt jasmine tests
etpinard Dec 16, 2015
1d18222
require in new trace modules,
etpinard Dec 16, 2015
c42a6d1
rm trailing lines
etpinard Dec 16, 2015
1f0b92d
rename bars / Bars --> bar / Bar consistently with trace type
etpinard Dec 16, 2015
db469d8
rename boxes / Boxes --> box / Box consistently with trace type
etpinard Dec 16, 2015
b043ec3
update layout module definition with Bar and Box
etpinard Dec 16, 2015
de92572
make bar and histogram have distinct attribute object,
etpinard Dec 17, 2015
9c90e0a
make contour and heatmap have distinct attribute objects
etpinard Dec 17, 2015
f4f1a93
make histogram2d and histogram2dcontour have distinct attribute objs
etpinard Dec 17, 2015
7bc3e75
make bar and histogram have distinct defaults step:
etpinard Dec 17, 2015
03b1557
make contour and heatmap have distinct defaults step:
etpinard Dec 17, 2015
eb327f0
make histogram2d and histogram2dcontour have distinct defaults step:
etpinard Dec 17, 2015
dccf3ed
update histogram* index files,
etpinard Dec 17, 2015
c1055b6
lint (name module.exports functions to help out during debugging)
etpinard Dec 17, 2015
2247b7c
remove warnings on PlotSchema.get() :
etpinard Dec 17, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make contour and heatmap have distinct defaults step:
- split up xyz heatmap defaults logic to be reused by contour defaults
- split up contour style defaults logic to be resued by
  histogram2d and histogram2dcontour
  • Loading branch information
etpinard committed Dec 17, 2015
commit 03b1557a6d273bf2f6226220fb1038c69d9521d7
27 changes: 13 additions & 14 deletions 27 src/traces/contour/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
'use strict';

var Lib = require('../../lib');
var heatmapSupplyDefaults = require('../heatmap/defaults');

var hasColumns = require('../heatmap/has_columns');
var handleXYZDefaults = require('../heatmap/xyz_defaults');
var handleStyleDefaults = require('../contour/style_defaults');
var attributes = require('./attributes');


Expand All @@ -20,24 +22,21 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}

var len = handleXYZDefaults(traceIn, traceOut, coerce);
if(!len) {
traceOut.visible = false;
return;
}

coerce('text');
coerce('connectgaps', hasColumns(traceOut));

var contourStart = Lib.coerce2(traceIn, traceOut, attributes, 'contours.start'),
contourEnd = Lib.coerce2(traceIn, traceOut, attributes, 'contours.end'),
autocontour = coerce('autocontour', !(contourStart && contourEnd));

if(autocontour) coerce('ncontours');
else coerce('contours.size');

var coloring = coerce('contours.coloring');

if(coloring === 'fill') coerce('contours.showlines');

if(traceOut.contours.showlines!==false) {
if(coloring !== 'lines') coerce('line.color', '#000');
coerce('line.width', 0.5);
coerce('line.dash');
}

coerce('line.smoothing');

heatmapSupplyDefaults(traceIn, traceOut, defaultColor, layout);
handleStyleDefaults(traceIn, traceOut, coerce, layout);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcjohnson no more Contour.supplyDefaults calling Heatmap.supplyDefaults.

The common part between the two in now in heatmap/xyz_defaults.js.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

composition over inheritance - generally a good pattern :)

};
34 changes: 34 additions & 0 deletions 34 src/traces/contour/style_defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright 2012-2015, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var Colorscale = require('../../components/colorscale');


module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout) {
var coloring = coerce('contours.coloring');

var showLines;
if(coloring === 'fill') showLines = coerce('contours.showlines');

if(showLines !== false) {
if(coloring !== 'lines') coerce('line.color', '#000');
coerce('line.width', 0.5);
coerce('line.dash');
}

coerce('line.smoothing');

if((traceOut.contours || {}).coloring !== 'none') {
Colorscale.handleDefaults(
traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'}
);
}
};
87 changes: 87 additions & 0 deletions 87 src/traces/heatmap/xyz_defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* Copyright 2012-2015, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var isNumeric = require('fast-isnumeric');

var hasColumns = require('./has_columns');


module.exports = function handleXYZDefaults(traceIn, traceOut, coerce) {
var z = coerce('z');
var x, y;

if(z===undefined || !z.length) return 0;

if(hasColumns(traceIn)) {
x = coerce('x');
y = coerce('y');

// column z must be accompanied by 'x' and 'y' arrays
if(!x || !y) return 0;
}
else {
x = coordDefaults('x', coerce);
y = coordDefaults('y', coerce);

// TODO put z validation elsewhere
if(!isValidZ(z)) return 0;

coerce('transpose');
}

return traceOut.z.length;
};

function coordDefaults(coordStr, coerce) {
var coord = coerce(coordStr),
coordType = coord ?
coerce(coordStr + 'type', 'array') :
'scaled';

if(coordType === 'scaled') {
coerce(coordStr + '0');
coerce('d' + coordStr);
}

return coord;
}

function isValidZ(z) {
var allRowsAreArrays = true,
oneRowIsFilled = false,
hasOneNumber = false,
zi;

/*
* Without this step:
*
* hasOneNumber = false breaks contour but not heatmap
* allRowsAreArrays = false breaks contour but not heatmap
* oneRowIsFilled = false breaks both
*/

for(var i = 0; i < z.length; i++) {
zi = z[i];
if(!Array.isArray(zi)) {
allRowsAreArrays = false;
break;
}
if(zi.length > 0) oneRowIsFilled = true;
for(var j = 0; j < zi.length; j++) {
if(isNumeric(zi[j])) {
hasOneNumber = true;
break;
}
}
}

return (allRowsAreArrays && oneRowIsFilled && hasOneNumber);
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.