Skip to content

Commit b08c402

Browse files
committed
fixes #621 - make x/y/z dependent error bar attributes
... by using utilizing component-to-schema logic, instead of punching the error bar attributes into the trace declarations.
1 parent 973abbc commit b08c402

File tree

8 files changed

+77
-34
lines changed

8 files changed

+77
-34
lines changed

src/components/errorbars/index.js

+49-14
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,57 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

12-
var errorBars = module.exports = {};
11+
var Lib = require('../../lib');
12+
var overrideAll = require('../../plot_api/edit_types').overrideAll;
13+
14+
var attributes = require('./attributes');
15+
var calc = require('./calc');
16+
17+
var xyAttrs = {
18+
error_x: Lib.extendFlat({}, attributes),
19+
error_y: Lib.extendFlat({}, attributes)
20+
};
21+
delete xyAttrs.error_x.copy_zstyle;
22+
delete xyAttrs.error_y.copy_zstyle;
23+
delete xyAttrs.error_y.copy_ystyle;
24+
25+
var xyzAttrs = {
26+
error_x: Lib.extendFlat({}, attributes),
27+
error_y: Lib.extendFlat({}, attributes),
28+
error_z: Lib.extendFlat({}, attributes)
29+
};
30+
delete xyzAttrs.error_x.copy_ystyle;
31+
delete xyzAttrs.error_y.copy_ystyle;
32+
delete xyzAttrs.error_z.copy_ystyle;
33+
delete xyzAttrs.error_z.copy_zstyle;
34+
35+
module.exports = {
36+
moduleType: 'component',
37+
name: 'errorbars',
1338

14-
errorBars.attributes = require('./attributes');
39+
schema: {
40+
traces: {
41+
scatter: xyAttrs,
42+
bar: xyAttrs,
43+
histogram: xyAttrs,
44+
scatter3d: overrideAll(xyzAttrs, 'calc', 'nested'),
45+
scattergl: overrideAll(xyAttrs, 'calc', 'nested')
46+
}
47+
},
1548

16-
errorBars.supplyDefaults = require('./defaults');
49+
supplyDefaults: require('./defaults'),
1750

18-
errorBars.calc = require('./calc');
51+
calc: calc,
52+
calcFromTrace: calcFromTrace,
1953

20-
errorBars.calcFromTrace = function(trace, layout) {
54+
plot: require('./plot'),
55+
style: require('./style'),
56+
hoverInfo: hoverInfo
57+
};
58+
59+
function calcFromTrace(trace, layout) {
2160
var x = trace.x || [],
2261
y = trace.y || [],
2362
len = x.length || y.length;
@@ -33,19 +72,15 @@ errorBars.calcFromTrace = function(trace, layout) {
3372

3473
calcdataMock[0].trace = trace;
3574

36-
errorBars.calc({
75+
calc({
3776
calcdata: [calcdataMock],
3877
_fullLayout: layout
3978
});
4079

4180
return calcdataMock;
42-
};
81+
}
4382

44-
errorBars.plot = require('./plot');
45-
46-
errorBars.style = require('./style');
47-
48-
errorBars.hoverInfo = function(calcPoint, trace, hoverPoint) {
83+
function hoverInfo(calcPoint, trace, hoverPoint) {
4984
if((trace.error_y || {}).visible) {
5085
hoverPoint.yerr = calcPoint.yh - calcPoint.y;
5186
if(!trace.error_y.symmetric) hoverPoint.yerrneg = calcPoint.y - calcPoint.ys;
@@ -54,4 +89,4 @@ errorBars.hoverInfo = function(calcPoint, trace, hoverPoint) {
5489
hoverPoint.xerr = calcPoint.xh - calcPoint.x;
5590
if(!trace.error_x.symmetric) hoverPoint.xerrneg = calcPoint.x - calcPoint.xs;
5691
}
57-
};
92+
}

src/core.js

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ exports.register([
6868
require('./components/rangeslider'),
6969
require('./components/rangeselector'),
7070
require('./components/grid'),
71+
require('./components/errorbars')
7172
]);
7273

7374
// locales en and en-US are required for default behavior

src/traces/bar/attributes.js

-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
var scatterAttrs = require('../scatter/attributes');
1212
var colorAttributes = require('../../components/colorscale/color_attributes');
13-
var errorBarAttrs = require('../../components/errorbars/attributes');
1413
var colorbarAttrs = require('../../components/colorbar/attributes');
1514
var fontAttrs = require('../../plots/font_attributes');
1615

@@ -190,9 +189,6 @@ module.exports = {
190189
r: scatterAttrs.r,
191190
t: scatterAttrs.t,
192191

193-
error_y: errorBarAttrs,
194-
error_x: errorBarAttrs,
195-
196192
_deprecated: {
197193
bardir: {
198194
valType: 'enumerated',

src/traces/histogram/attributes.js

-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
var barAttrs = require('../bar/attributes');
1212

13-
1413
module.exports = {
1514
x: {
1615
valType: 'data_array',
@@ -194,9 +193,6 @@ module.exports = {
194193
selected: barAttrs.selected,
195194
unselected: barAttrs.unselected,
196195

197-
error_y: barAttrs.error_y,
198-
error_x: barAttrs.error_x,
199-
200196
_deprecated: {
201197
bardir: barAttrs._deprecated.bardir
202198
}

src/traces/scatter/attributes.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
'use strict';
1010

1111
var colorAttributes = require('../../components/colorscale/color_attributes');
12-
var errorBarAttrs = require('../../components/errorbars/attributes');
1312
var colorbarAttrs = require('../../components/colorbar/attributes');
1413
var fontAttrs = require('../../plots/font_attributes');
1514
var dash = require('../../components/drawing/attributes').dash;
@@ -490,8 +489,5 @@ module.exports = {
490489
'Please switch to *scatterpolar* trace type.',
491490
'Sets the angular coordinates.'
492491
].join('')
493-
},
494-
495-
error_y: errorBarAttrs,
496-
error_x: errorBarAttrs
492+
}
497493
};

src/traces/scatter3d/attributes.js

-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
var scatterAttrs = require('../scatter/attributes');
1212
var colorAttributes = require('../../components/colorscale/color_attributes');
13-
var errorBarAttrs = require('../../components/errorbars/attributes');
1413
var baseAttrs = require('../../plots/attributes');
1514
var DASHES = require('../../constants/gl3d_dashes');
1615

@@ -169,10 +168,6 @@ var attrs = module.exports = overrideAll({
169168
textposition: extendFlat({}, scatterAttrs.textposition, {dflt: 'top center'}),
170169
textfont: scatterAttrs.textfont,
171170

172-
error_x: errorBarAttrs,
173-
error_y: errorBarAttrs,
174-
error_z: errorBarAttrs,
175-
176171
hoverinfo: extendFlat({}, baseAttrs.hoverinfo)
177172
}, 'calc', 'nested');
178173

src/traces/scattergl/attributes.js

-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ var attrs = module.exports = overrideAll({
8787
editType: 'calc'
8888
}),
8989

90-
error_y: scatterAttrs.error_y,
91-
error_x: scatterAttrs.error_x
9290
}, 'calc', 'nested');
9391

9492
attrs.x.editType = attrs.y.editType = attrs.x0.editType = attrs.y0.editType = 'calc+clearAxisTypes';

test/jasmine/tests/plotschema_test.js

+26
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,32 @@ describe('plot schema', function() {
317317
expect(plotSchema.frames.items.frames_entry).toBeDefined();
318318
expect(plotSchema.frames.items.frames_entry.role).toEqual('object');
319319
});
320+
321+
it('should list trace-dependent & direction-dependent error bar attributes', function() {
322+
var scatterSchema = plotSchema.traces.scatter.attributes;
323+
expect(scatterSchema.error_x.copy_ystyle).toBeDefined();
324+
expect(scatterSchema.error_x.copy_ystyle.editType).toBe('plot');
325+
expect(scatterSchema.error_x.copy_zstyle).toBeUndefined();
326+
expect(scatterSchema.error_y.copy_ystyle).toBeUndefined();
327+
expect(scatterSchema.error_y.copy_zstyle).toBeUndefined();
328+
329+
var scatter3dSchema = plotSchema.traces.scatter3d.attributes;
330+
expect(scatter3dSchema.error_x.copy_ystyle).toBeUndefined();
331+
expect(scatter3dSchema.error_x.copy_zstyle).toBeDefined();
332+
expect(scatter3dSchema.error_x.copy_zstyle.editType).toBe('calc');
333+
expect(scatter3dSchema.error_y.copy_ystyle).toBeUndefined();
334+
expect(scatter3dSchema.error_y.copy_zstyle).toBeDefined();
335+
expect(scatter3dSchema.error_y.copy_zstyle.editType).toBe('calc');
336+
expect(scatter3dSchema.error_z.copy_ystyle).toBeUndefined();
337+
expect(scatter3dSchema.error_z.copy_zstyle).toBeUndefined();
338+
339+
var scatterglSchema = plotSchema.traces.scattergl.attributes;
340+
expect(scatterglSchema.error_x.copy_ystyle).toBeDefined();
341+
expect(scatterglSchema.error_x.copy_ystyle.editType).toBe('calc');
342+
expect(scatterglSchema.error_x.copy_zstyle).toBeUndefined();
343+
expect(scatterglSchema.error_y.copy_ystyle).toBeUndefined();
344+
expect(scatterglSchema.error_y.copy_zstyle).toBeUndefined();
345+
});
320346
});
321347

322348
describe('getTraceValObject', function() {

0 commit comments

Comments
 (0)