|
9 | 9 |
|
10 | 10 | 'use strict'; |
11 | 11 |
|
12 | | -var d3 = require('d3'); |
13 | | -var isNumeric = require('fast-isnumeric'); |
14 | | - |
15 | | -var Lib = require('../../lib'); |
16 | | -var Color = require('../color'); |
17 | | -var subTypes = require('../../traces/scatter/subtypes'); |
18 | | - |
19 | | - |
20 | 12 | var errorBars = module.exports = {}; |
21 | 13 |
|
22 | 14 | errorBars.attributes = require('./attributes'); |
@@ -49,123 +41,9 @@ errorBars.calcFromTrace = function(trace, layout) { |
49 | 41 | return calcdataMock; |
50 | 42 | }; |
51 | 43 |
|
52 | | -// the main drawing function for errorbars |
53 | | -errorBars.plot = function(gd, plotinfo, cd) { |
54 | | - // ___ <-- "errorhats" |
55 | | - // | |
56 | | - // | <-- "errorbars" |
57 | | - // | |
58 | | - // ___ <-- "errorshoes" |
59 | | - |
60 | | - var xa = plotinfo.x(), |
61 | | - ya = plotinfo.y(); |
62 | | - |
63 | | - // first remove all existing errorbars |
64 | | - // TODO: use enter/exit instead |
65 | | - plotinfo.plot.select('.errorlayer').selectAll('g.errorbars').remove(); |
66 | | - var coords; |
67 | | - |
68 | | - // draw the errorbars |
69 | | - plotinfo.plot.select('.errorlayer').selectAll('g.errorbars') |
70 | | - .data(cd) |
71 | | - .enter().append('g') |
72 | | - .attr('class','errorbars') |
73 | | - .each(function(d) { |
74 | | - var trace = d[0].trace, |
75 | | - xObj = trace.error_x, |
76 | | - yObj = trace.error_y, |
77 | | - sparse = subTypes.hasMarkers(trace) && |
78 | | - trace.marker.maxdisplayed>0; |
79 | | - |
80 | | - if(!yObj.visible && !xObj.visible) return; |
81 | | - |
82 | | - d3.select(this).selectAll('g') |
83 | | - .data(Lib.identity) |
84 | | - .enter().append('g') |
85 | | - .each(function(d) { |
86 | | - coords = errorcoords(d, xa, ya); |
87 | | - var eb = d3.select(this), |
88 | | - path; |
89 | | - if(sparse && !d.vis) return; |
90 | | - |
91 | | - if(yObj.visible && isNumeric(coords.x) && |
92 | | - isNumeric(coords.yh) && |
93 | | - isNumeric(coords.ys)) { |
94 | | - var yw = yObj.width; |
95 | | - path = 'M'+(coords.x-yw)+','+coords.yh+'h'+(2*yw) + // hat |
96 | | - 'm-'+yw+',0V'+coords.ys; // bar |
97 | | - if(!coords.noYS) path += 'm-'+yw+',0h'+(2*yw); // shoe |
98 | | - |
99 | | - eb.append('path') |
100 | | - .classed('yerror', true) |
101 | | - .attr('d', path); |
102 | | - } |
103 | | - if(xObj.visible && isNumeric(coords.y) && |
104 | | - isNumeric(coords.xh) && |
105 | | - isNumeric(coords.xs)) { |
106 | | - var xw = (xObj.copy_ystyle ? yObj : xObj).width; |
107 | | - path = 'M'+coords.xh+','+(coords.y-xw)+'v'+(2*xw) + // hat |
108 | | - 'm0,-'+xw+'H'+coords.xs; // bar |
109 | | - if(!coords.noXS) path += 'm0,-'+xw+'v'+(2*xw); // shoe |
110 | | - |
111 | | - eb.append('path') |
112 | | - .classed('xerror', true) |
113 | | - .attr('d', path); |
114 | | - } |
115 | | - }); |
116 | | - }); |
117 | | -}; |
118 | | - |
119 | | -errorBars.style = function(gd) { |
120 | | - d3.select(gd).selectAll('g.errorbars').each(function(d) { |
121 | | - var eb = d3.select(this), |
122 | | - trace = d[0].trace, |
123 | | - yObj = trace.error_y||{}, |
124 | | - xObj = trace.error_x||{}; |
125 | | - |
126 | | - eb.selectAll('g path.yerror') |
127 | | - .style('stroke-width', yObj.thickness+'px') |
128 | | - .call(Color.stroke, yObj.color); |
129 | | - |
130 | | - if(xObj.copy_ystyle) xObj = yObj; |
131 | | - |
132 | | - eb.selectAll('g path.xerror') |
133 | | - .style('stroke-width', xObj.thickness+'px') |
134 | | - .call(Color.stroke, xObj.color); |
135 | | - }); |
136 | | -}; |
137 | | - |
138 | | -function errorcoords(d, xa, ya) { |
139 | | - // compute the coordinates of the error-bar objects |
140 | | - var out = { |
141 | | - x: xa.c2p(d.x), |
142 | | - y: ya.c2p(d.y) |
143 | | - }; |
144 | | - |
145 | | - // calculate the error bar size and hat and shoe locations |
146 | | - if(d.yh!==undefined) { |
147 | | - out.yh = ya.c2p(d.yh); |
148 | | - out.ys = ya.c2p(d.ys); |
149 | | - |
150 | | - // if the shoes go off-scale (ie log scale, error bars past zero) |
151 | | - // clip the bar and hide the shoes |
152 | | - if(!isNumeric(out.ys)) { |
153 | | - out.noYS = true; |
154 | | - out.ys = ya.c2p(d.ys, true); |
155 | | - } |
156 | | - } |
157 | | - if(d.xh!==undefined) { |
158 | | - out.xh = xa.c2p(d.xh); |
159 | | - out.xs = xa.c2p(d.xs); |
160 | | - |
161 | | - if(!isNumeric(out.xs)) { |
162 | | - out.noXS = true; |
163 | | - out.xs = xa.c2p(d.xs, true); |
164 | | - } |
165 | | - } |
| 44 | +errorBars.plot = require('./plot'); |
166 | 45 |
|
167 | | - return out; |
168 | | -} |
| 46 | +errorBars.style = require('./style'); |
169 | 47 |
|
170 | 48 | errorBars.hoverInfo = function(calcPoint, trace, hoverPoint) { |
171 | 49 | if(trace.error_y.visible) { |
|
0 commit comments