Skip to content

Commit

Permalink
change the way layout.barcornerradius is handled
Browse files Browse the repository at this point in the history
  • Loading branch information
emilykl committed Nov 8, 2023
1 parent 5dfd686 commit 484f21b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 39 deletions.
19 changes: 11 additions & 8 deletions src/traces/bar/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
});

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

coerce('marker.cornerradius');
var lineColor = (traceOut.marker.line || {}).color;

// override defaultColor for error bars with defaultLine
Expand All @@ -61,16 +61,19 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function crossTraceDefaults(fullData, fullLayout) {
var traceIn, traceOut;

function coerce(attr) {
return Lib.coerce(traceOut._input, traceOut, attributes, attr);
function coerce(attr, dflt) {
return Lib.coerce(traceOut._input, traceOut, attributes, attr, dflt);
}

if(fullLayout.barmode === 'group') {
for(var i = 0; i < fullData.length; i++) {
traceOut = fullData[i];
for(var i = 0; i < fullData.length; i++) {
traceOut = fullData[i];

if(traceOut.type === 'bar') {
traceIn = traceOut._input;
if(traceOut.type === 'bar') {
traceIn = traceOut._input;
// This needs to happen here rather than in handleStyleDefaults() because
// it needs to happen after `layout.barcornerradius` has been coerced
coerce('marker.cornerradius', fullLayout.barcornerradius);
if(fullLayout.barmode === 'group') {
handleGroupingDefaults(traceIn, traceOut, fullLayout, coerce);
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,7 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
y1 = fixpx(y1, y0, !isHorizontal);
}

// Here is where bar is drawn
// TODO: Implement rounded corners here

// Construct path string for bar
function calcCornerRadius(radiusParam) {
var barWidth = isHorizontal ? Math.abs(y1 - y0) : Math.abs(x1 - x0);
if(!radiusParam) {
Expand All @@ -246,7 +244,7 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
return Math.max(Math.min(radiusParam, barWidth / 2), 0);
}
}
var r = calcCornerRadius(trace.marker.cornerradius || fullLayout.barcornerradius);
var r = calcCornerRadius(trace.marker.cornerradius);
var bardir = isHorizontal ? Math.sign(x1 - x0) : Math.sign(y0 - y1);
var cornersweep = bardir >= 0 ? 1 : 0;

Expand Down
82 changes: 55 additions & 27 deletions test/image/mocks/bar-rounded-corners.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,60 @@
{
"data": [
{
"x": [
"giraffes",
"orangutans",
"monkeys",
"capybaras"
],
"y": [20, -14, 2, 18
],
"type": "bar",
"marker": {"cornerradius": 10}
},
{
"y": [
"giraffes",
"orangutans",
"monkeys",
"capybaras"
],
"x": [20, -4, -12, 18],
"type": "bar",
"orientation": "h",
"xaxis": "x2",
"yaxis": "y2"
}

{
"x": [
"giraffes",
"orangutans",
"monkeys",
"capybaras"
],
"y": [20, -14, 2, 18],
"type": "bar",
"marker": {"cornerradius": 10}
},
{
"y": [
"giraffes",
"orangutans",
"monkeys",
"capybaras"
],
"x": [20, -4, 1, 18],
"type": "bar",
"orientation": "h",
"xaxis": "x2",
"yaxis": "y2"
},
{
"x": [
"giraffes",
"orangutans",
"monkeys",
"capybaras"
],
"y": [20, -14, 2, 18],
"type": "bar",
"marker": {"cornerradius": 10},
"xaxis": "x3",
"yaxis": "y3"
},
{
"x": [
"giraffes",
"orangutans",
"monkeys",
"capybaras"
],
"y": [20, -14, 2, 18],
"type": "bar",
"marker": {"cornerradius": 10},
"xaxis": "x3",
"yaxis": "y3"
}
],
"layout": {"grid": {"rows": 1, "columns": 2, "pattern": "independent"}, "barcornerradius": "30%"}
"layout": {
"grid": {"rows": 2, "columns": 2, "pattern": "independent"},
"barmode": "stack",
"barcornerradius": "50%"
}
}

0 comments on commit 484f21b

Please sign in to comment.