-
Notifications
You must be signed in to change notification settings - Fork 0
Implement attributes base, offset and width in bar traces (issue 80) #3
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
Changes from 21 commits
03e5072
bbdc385
7b14fcd
fe66e3c
d422f67
97da55b
93ca66e
80fdfbd
3b87e85
a7ca755
1400311
4294cad
4866cda
79f2e8d
10b678b
23f7415
6f05b34
d4f7747
0e6e0f1
e83f4c5
f4143e8
125c537
f0a0c92
2ca7605
497121d
54a0967
6f58cd0
bb93aba
307d955
bad5c51
6c6d680
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,13 +25,15 @@ module.exports = function calc(gd, trace) { | |
var xa = Axes.getFromId(gd, trace.xaxis || 'x'), | ||
ya = Axes.getFromId(gd, trace.yaxis || 'y'), | ||
orientation = trace.orientation || ((trace.x && !trace.y) ? 'h' : 'v'), | ||
pos, size, i; | ||
sa, pos, size, i; | ||
|
||
if(orientation === 'h') { | ||
sa = xa; | ||
size = xa.makeCalcdata(trace, 'x'); | ||
pos = ya.makeCalcdata(trace, 'y'); | ||
} | ||
else { | ||
sa = ya; | ||
size = ya.makeCalcdata(trace, 'y'); | ||
pos = xa.makeCalcdata(trace, 'x'); | ||
} | ||
|
@@ -40,14 +42,43 @@ module.exports = function calc(gd, trace) { | |
var serieslen = Math.min(pos.length, size.length), | ||
cd = []; | ||
|
||
// set position | ||
for(i = 0; i < serieslen; i++) { | ||
|
||
// add bars with non-numeric sizes to calcdata | ||
// so that ensure that traces with gaps are | ||
// plotted in the correct order | ||
|
||
if(isNumeric(pos[i])) { | ||
cd.push({p: pos[i], s: size[i], b: 0}); | ||
cd.push({p: pos[i]}); | ||
} | ||
} | ||
|
||
// set base | ||
var base = trace.base, | ||
b; | ||
|
||
if(Array.isArray(base)) { | ||
for(i = 0; i < Math.min(base.length, cd.length); i++) { | ||
b = sa.d2c(base[i]); | ||
cd[i].b = (isNumeric(b)) ? b : 0; | ||
} | ||
for(; i < cd.length; i++) { | ||
cd[i].b = 0; | ||
} | ||
} | ||
else { | ||
b = sa.d2c(base); | ||
b = (isNumeric(b)) ? b : 0; | ||
for(i = 0; i < cd.length; i++) { | ||
cd[i].b = b; | ||
} | ||
} | ||
|
||
// set size | ||
for(i = 0; i < cd.length; i++) { | ||
if(isNumeric(size[i])) { | ||
cd[i].s = size[i] - cd[i].b; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛔ We'll have to guard against non-numeric In brief, in the supply-defaults step, scalar There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh and by the way, half-valid array inputs are an example of test cases that should included in our jasmine suites. |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,8 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { | |
xa = pointData.xa, | ||
ya = pointData.ya, | ||
barDelta = (hovermode === 'closest') ? | ||
t.barwidth / 2 : t.dbar * (1 - xa._gd._fullLayout.bargap) / 2, | ||
t.barwidth / 2 : | ||
t.bargroupwidth, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice simplification. 👍 |
||
barPos; | ||
|
||
if(hovermode !== 'closest') barPos = function(di) { return di.p; }; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,30 +34,39 @@ module.exports = function plot(gd, plotinfo, cdbar) { | |
.attr('class', 'points') | ||
.each(function(d) { | ||
var t = d[0].t, | ||
trace = d[0].trace; | ||
trace = d[0].trace, | ||
poffset = t.poffset, | ||
poffsetIsArray = Array.isArray(poffset), | ||
barwidth = t.barwidth, | ||
barwidthIsArray = Array.isArray(barwidth); | ||
|
||
arraysToCalcdata(d); | ||
|
||
d3.select(this).selectAll('path') | ||
.data(Lib.identity) | ||
.enter().append('path') | ||
.each(function(di) { | ||
.each(function(di, i) { | ||
// now display the bar | ||
// clipped xf/yf (2nd arg true): non-positive | ||
// log values go off-screen by plotwidth | ||
// so you see them continue if you drag the plot | ||
var p0 = di.p + ((poffsetIsArray) ? poffset[i] : poffset), | ||
p1 = p0 + ((barwidthIsArray) ? barwidth[i] : barwidth), | ||
s0 = di.b, | ||
s1 = s0 + di.s; | ||
|
||
var x0, x1, y0, y1; | ||
if(trace.orientation === 'h') { | ||
y0 = ya.c2p(t.poffset + di.p, true); | ||
y1 = ya.c2p(t.poffset + di.p + t.barwidth, true); | ||
x0 = xa.c2p(di.b, true); | ||
x1 = xa.c2p(di.s + di.b, true); | ||
y0 = ya.c2p(p0, true); | ||
y1 = ya.c2p(p1, true); | ||
x0 = xa.c2p(s0, true); | ||
x1 = xa.c2p(s1, true); | ||
} | ||
else { | ||
x0 = xa.c2p(t.poffset + di.p, true); | ||
x1 = xa.c2p(t.poffset + di.p + t.barwidth, true); | ||
y1 = ya.c2p(di.s + di.b, true); | ||
y0 = ya.c2p(di.b, true); | ||
x0 = xa.c2p(p0, true); | ||
x1 = xa.c2p(p1, true); | ||
y0 = ya.c2p(s0, true); | ||
y1 = ya.c2p(s1, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very clean here. 🍻 |
||
} | ||
|
||
if(!isNumeric(x0) || !isNumeric(x1) || | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make the fact that these attributes are optional, we usually set the
dflt: null
(e.g. contour tracestart
,end
,size
).Note that,
null
are ignored uponLib.nestedProperty(/**/).set()
, so yourfullTrace.base === undefined
will still work.