Skip to content

Commit d71fe49

Browse files
committed
handle negative bars
1 parent b0c6258 commit d71fe49

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

Diff for: src/traces/bar/plot.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -250,22 +250,24 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
250250
}
251251
}
252252
var r = calcCornerRadius(trace.marker.cornerradius || fullLayout.barcornerradius);
253-
253+
var bardir = isHorizontal ? Math.sign(x1 - x0) : Math.sign(y0 - y1);
254+
var cornersweep = bardir >= 0 ? 1 : 0;
255+
254256
var path;
255257
if(r && isHorizontal) {
256258
path = 'M' + x0 + ',' + y0
257259
+ 'V' + y1
258-
+ 'H' + (x1 - r)
259-
+ 'a ' + r + ',' + r + ' 0 0 1 ' + r + ',' + r
260+
+ 'H' + (x1 - r*bardir)
261+
+ 'a ' + r + ',' + r + ' 0 0 '+cornersweep+' ' + r*bardir + ',' + r
260262
+ 'V' + (y0 - r)
261-
+ 'a ' + r + ',' + r + ' 0 0 1 ' + -r + ',' + r
263+
+ 'a ' + r + ',' + r + ' 0 0 '+cornersweep+' ' + -r*bardir + ',' + r
262264
+ 'Z';
263265
} else if(r) {
264266
path = 'M' + x0 + ',' + y0
265-
+ 'V' + (y1 + r)
266-
+ 'a ' + r + ',' + r + ' 0 0 1 ' + r + ',' + -r
267+
+ 'V' + (y1 + r*bardir)
268+
+ 'a ' + r + ',' + r + ' 0 0 '+cornersweep+' ' + r + ',' + -r*bardir
267269
+ 'H' + (x1 - r)
268-
+ 'a ' + r + ',' + r + ' 0 0 1 ' + r + ',' + r
270+
+ 'a ' + r + ',' + r + ' 0 0 '+cornersweep+' ' + r + ',' + r*bardir
269271
+ 'V' + y0 + 'Z';
270272
} else {
271273
path = 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z';

Diff for: test/image/mocks/bar-rounded-corners.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"monkeys",
88
"capybaras"
99
],
10-
"y": [20, 14, 2, 18
10+
"y": [20, -14, 2, 18
1111
],
1212
"type": "bar",
1313
"marker": {"cornerradius": 10}
@@ -19,7 +19,7 @@
1919
"monkeys",
2020
"capybaras"
2121
],
22-
"x": [20, 14, 2, 18],
22+
"x": [20, -4, -12, 18],
2323
"type": "bar",
2424
"orientation": "h",
2525
"xaxis": "x2",

0 commit comments

Comments
 (0)