Skip to content

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 all commits
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
26 changes: 0 additions & 26 deletions src/components/colorbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,29 +575,3 @@ colorbar.supplyDefaults = function(containerIn, containerOut, layout) {
Plotly.Lib.coerceFont(coerce, 'titlefont', layout.font);
coerce('titleside');
};

colorbar.traceColorbar = function(gd, cd) {
var trace = cd[0].trace,
cbId = 'cb' + trace.uid,
scl = Plotly.Colorscale.getScale(trace.colorscale),
zmin = trace.zmin,
zmax = trace.zmax;

if(!isNumeric(zmin)) zmin = Plotly.Lib.aggNums(Math.min, null, trace.z);
if(!isNumeric(zmax)) zmax = Plotly.Lib.aggNums(Math.max, null, trace.z);

gd._fullLayout._infolayer.selectAll('.'+cbId).remove();
if(!trace.showscale){
Plotly.Plots.autoMargin(gd, cbId);
return;
}

var cb = cd[0].t.cb = colorbar(gd, cbId);
cb.fillcolor(d3.scale.linear()
.domain(scl.map(function(v){ return zmin + v[0]*(zmax-zmin); }))
.range(scl.map(function(v){ return v[1]; })))
.filllevels({start: zmin, end: zmax, size: (zmax-zmin)/254})
.options(trace.colorbar)();

Plotly.Lib.markTime('done colorbar');
};
3 changes: 2 additions & 1 deletion src/plot_api/plot_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,13 @@ function assignPolarLayoutAttrs(layoutAttributes) {
}

function getSubplotRegistry(traceType) {
if(traceType === 'area') return {}; // FIXME

var subplotsRegistry = Plotly.Plots.subplotsRegistry,
subplotType = Object.keys(subplotsRegistry).filter(function(subplotType) {
return Plotly.Plots.traceIs({type: traceType}, subplotType);
})[0];

if(traceType === 'area') return {}; // FIXME
if(subplotType === undefined) return {};

return subplotsRegistry[subplotType];
Expand Down
6 changes: 4 additions & 2 deletions src/plotly.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ exports.ModeBar = require('./components/modebar');

// traces
exports.Scatter = require('./traces/scatter');
exports.Bars = require('./traces/bars');
exports.Boxes = require('./traces/boxes');
exports.Bar = require('./traces/bar');
exports.Box = require('./traces/box');
exports.Heatmap = require('./traces/heatmap');
exports.Histogram = require('./traces/histogram');
exports.Histogram2d = require('./traces/histogram2d');
exports.Histogram2dContour = require('./traces/histogram2dcontour');
exports.Pie = require('./traces/pie');
exports.Contour = require('./traces/contour');
exports.Scatter3D = require('./traces/scatter3d');
Expand Down
2 changes: 1 addition & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut) {
plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData) {
var moduleLayoutDefaults = [
'Axes', 'Annotations', 'Shapes', 'Fx',
'Bars', 'Boxes', 'Gl3dLayout', 'GeoLayout', 'Pie', 'Legend'
'Bar', 'Box', 'Gl3dLayout', 'GeoLayout', 'Pie', 'Legend'
];

var i, module;
Expand Down
26 changes: 26 additions & 0 deletions src/traces/bar/arrays_to_calcdata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* 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 mergeArray = require('../../lib').mergeArray;


// arrayOk attributes, merge them into calcdata array
module.exports = function arraysToCalcdata(cd) {
var trace = cd[0].trace,
marker = trace.marker,
markerLine = marker.line;

mergeArray(trace.text, cd, 'tx');
mergeArray(marker.opacity, cd, 'mo');
mergeArray(marker.color, cd, 'mc');
mergeArray(markerLine.color, cd, 'mlc');
mergeArray(markerLine.width, cd, 'mlw');
};
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ module.exports = {
}
},

r: scatterAttrs.r, // FIXME this shouldn't get included in 'histogram'
r: scatterAttrs.r,
t: scatterAttrs.t,

_composedModules: { // composed module coupling
'histogram': 'Histogram'
},
_nestedModules: { // nested module coupling
'error_y': 'ErrorBars',
'error_x': 'ErrorBars',
Expand Down
55 changes: 55 additions & 0 deletions src/traces/bar/calc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* 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 Plotly = require('../../plotly');


module.exports = function calc(gd, trace) {
// depending on bar direction, set position and size axes
// and data ranges
// note: this logic for choosing orientation is
// duplicated in graph_obj->setstyles

var xa = Plotly.Axes.getFromId(gd, trace.xaxis||'x'),
ya = Plotly.Axes.getFromId(gd, trace.yaxis||'y'),
orientation = trace.orientation || ((trace.x && !trace.y) ? 'h' : 'v'),
pos, size, i;

if(orientation==='h') {
size = xa.makeCalcdata(trace, 'x');
pos = ya.makeCalcdata(trace, 'y');
}
else {
size = ya.makeCalcdata(trace, 'y');
pos = xa.makeCalcdata(trace, 'x');
}

// create the "calculated data" to plot
var serieslen = Math.min(pos.length, size.length),
cd = [];
for(i=0; i<serieslen; i++) {
if((isNumeric(pos[i]) && isNumeric(size[i]))) {
cd.push({p: pos[i], s: size[i], b: 0});
}
}

// auto-z and autocolorscale if applicable
if(Plotly.Colorscale.hasColorscale(trace, 'marker')) {
Plotly.Colorscale.calc(trace, trace.marker.color, 'marker', 'c');
}
if(Plotly.Colorscale.hasColorscale(trace, 'marker.line')) {
Plotly.Colorscale.calc(trace, trace.marker.line.color, 'marker.line', 'c');
}

return cd;
};
40 changes: 40 additions & 0 deletions src/traces/bar/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 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 Lib = require('../../lib');
var Color = require('../../components/color');

var handleXYDefaults = require('../scatter/xy_defaults');
var handleStyleDefaults = require('../bar/style_defaults');
var errorBarsSupplyDefaults = require('../../components/errorbars/defaults');
var attributes = require('./attributes');


module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}

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

coerce('orientation', (traceOut.x && !traceOut.y) ? 'h' : 'v');
coerce('text');

handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout);

// override defaultColor for error bars with defaultLine
errorBarsSupplyDefaults(traceIn, traceOut, Color.defaultLine, {axis: 'y'});
errorBarsSupplyDefaults(traceIn, traceOut, Color.defaultLine, {axis: 'x', inherit: 'y'});
};
88 changes: 88 additions & 0 deletions src/traces/bar/hover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* 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 Plotly = require('../../plotly');
var Color = require('../../components/color');


module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
var cd = pointData.cd,
trace = cd[0].trace,
t = cd[0].t,
xa = pointData.xa,
ya = pointData.ya,
barDelta = (hovermode==='closest') ?
t.barwidth/2 : t.dbar*(1-xa._td._fullLayout.bargap)/2,
barPos;

if(hovermode!=='closest') barPos = function(di) { return di.p; };
else if(trace.orientation==='h') barPos = function(di) { return di.y; };
else barPos = function(di) { return di.x; };

var dx, dy;
if(trace.orientation==='h') {
dx = function(di){
// add a gradient so hovering near the end of a
// bar makes it a little closer match
return Plotly.Fx.inbox(di.b-xval, di.x-xval) + (di.x-xval)/(di.x-di.b);
};
dy = function(di){
var centerPos = barPos(di) - yval;
return Plotly.Fx.inbox(centerPos - barDelta, centerPos + barDelta);
};
}
else {
dy = function(di){
return Plotly.Fx.inbox(di.b-yval, di.y-yval) + (di.y-yval)/(di.y-di.b);
};
dx = function(di){
var centerPos = barPos(di) - xval;
return Plotly.Fx.inbox(centerPos - barDelta, centerPos + barDelta);
};
}

var distfn = Plotly.Fx.getDistanceFunction(hovermode, dx, dy);
Plotly.Fx.getClosest(cd, distfn, pointData);

// skip the rest (for this trace) if we didn't find a close point
if(pointData.index===false) return;

// the closest data point
var di = cd[pointData.index],
mc = di.mcc || trace.marker.color,
mlc = di.mlcc || trace.marker.line.color,
mlw = di.mlw || trace.marker.line.width;
if(Color.opacity(mc)) pointData.color = mc;
else if(Color.opacity(mlc) && mlw) pointData.color = mlc;

if(trace.orientation==='h') {
pointData.x0 = pointData.x1 = xa.c2p(di.x, true);
pointData.xLabelVal = di.s;

pointData.y0 = ya.c2p(barPos(di) - barDelta, true);
pointData.y1 = ya.c2p(barPos(di) + barDelta, true);
pointData.yLabelVal = di.p;
}
else {
pointData.y0 = pointData.y1 = ya.c2p(di.y,true);
pointData.yLabelVal = di.s;

pointData.x0 = xa.c2p(barPos(di) - barDelta, true);
pointData.x1 = xa.c2p(barPos(di) + barDelta, true);
pointData.xLabelVal = di.p;
}

if(di.tx) pointData.text = di.tx;

Plotly.ErrorBars.hoverInfo(di, trace, pointData);

return [pointData];
};
45 changes: 45 additions & 0 deletions src/traces/bar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* 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 Plotly = require('../../plotly');

Plotly.Plots.register(exports, 'bar',
['cartesian', 'bar', 'oriented', 'markerColorscale', 'errorBarsOK', 'showLegend'], {
description: [
'The data visualized by the span of the bars is set in `y`',
'if `orientation` is set th *v* (the default)',
'and the labels are set in `x`.',

'By setting `orientation` to *h*, the roles are interchanged.'
].join(' ')
});

exports.attributes = require('./attributes');

exports.layoutAttributes = require('./layout_attributes');

exports.supplyDefaults = require('./defaults');

exports.supplyLayoutDefaults = require('./layout_defaults');

exports.calc = require('./calc');

exports.setPositions = require('./set_positions');

exports.colorbar = require('../scatter/colorbar');

exports.arraysToCalcdata = require('./arrays_to_calcdata');

exports.plot = require('./plot');

exports.style = require('./style');

exports.hoverPoints = require('./hover');
Loading