Skip to content
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

Only enable the bar borderRadius at the end of the stacks #8941

Merged
merged 9 commits into from Apr 18, 2021
3 changes: 3 additions & 0 deletions src/controllers/controller.bar.js
Expand Up @@ -269,10 +269,13 @@ export default class BarController extends DatasetController {
const parsed = me.getParsed(i);
const vpixels = reset || isNullOrUndef(parsed[vScale.axis]) ? {base, head: base} : me._calculateBarValuePixels(i);
const ipixels = me._calculateBarIndexPixels(i, ruler);
const stack = me.getStack(i);

const properties = {
horizontal,
base: vpixels.base,
endOfStack: me.index === stack._top || me.index === stack._bottom,
float: isFloatBar(parsed._custom),
x: horizontal ? vpixels.head : ipixels.center,
y: horizontal ? ipixels.center : vpixels.head,
height: horizontal ? ipixels.size : undefined,
Expand Down
17 changes: 17 additions & 0 deletions src/core/core.datasetController.js
Expand Up @@ -127,6 +127,11 @@ function getOrCreateStack(stacks, stackKey, indexValue) {
return subStack[indexValue] || (subStack[indexValue] = {});
}

function getLastIndexInStack(stack, positive) {
const items = Object.entries(stack).filter(([key, v]) => key !== '_top' && key !== '_bottom').filter(([dsIndex, value]) => positive ? value > 0 : value < 0).reverse();
return items.length ? parseInt(items[0][0], 10) : null;
}

function updateStacks(controller, parsed) {
const {chart, _cachedMeta: meta} = controller;
const stacks = chart._stacks || (chart._stacks = {}); // map structure is {stackKey: {datasetIndex: value}}
Expand All @@ -143,6 +148,9 @@ function updateStacks(controller, parsed) {
const itemStacks = item._stacks || (item._stacks = {});
stack = itemStacks[vAxis] = getOrCreateStack(stacks, key, index);
stack[datasetIndex] = value;

stack._top = getLastIndexInStack(stack, true);
stack._bottom = getLastIndexInStack(stack, false);
}
}

Expand Down Expand Up @@ -533,6 +541,15 @@ export default class DatasetController {
return applyStack(stack, value, meta.index, {mode});
}

/**
* @protected
*/
getStack(index) {
const {iScale, vScale} = this._cachedMeta;
const key = getStackKey(iScale, vScale, this._cachedMeta);
return this.chart._stacks[key][index];
}

/**
* @protected
*/
Expand Down
12 changes: 8 additions & 4 deletions src/elements/element.bar.js
Expand Up @@ -83,16 +83,19 @@ function parseBorderWidth(bar, maxW, maxH) {
}

function parseBorderRadius(bar, maxW, maxH) {
const {endOfStack, float} = bar.getProps(['endOfStack', 'float']);
const value = bar.options.borderRadius;
const o = toTRBLCorners(value);
const maxR = Math.min(maxW, maxH);
const skip = parseBorderSkipped(bar);

const enableBorder = endOfStack || float;
etimberg marked this conversation as resolved.
Show resolved Hide resolved

return {
topLeft: skipOrLimit(skip.top || skip.left, o.topLeft, 0, maxR),
topRight: skipOrLimit(skip.top || skip.right, o.topRight, 0, maxR),
bottomLeft: skipOrLimit(skip.bottom || skip.left, o.bottomLeft, 0, maxR),
bottomRight: skipOrLimit(skip.bottom || skip.right, o.bottomRight, 0, maxR)
topLeft: skipOrLimit(!enableBorder || skip.top || skip.left, o.topLeft, 0, maxR),
topRight: skipOrLimit(!enableBorder || skip.top || skip.right, o.topRight, 0, maxR),
bottomLeft: skipOrLimit(!enableBorder || skip.bottom || skip.left, o.bottomLeft, 0, maxR),
bottomRight: skipOrLimit(!enableBorder || skip.bottom || skip.right, o.bottomRight, 0, maxR)
};
}

Expand Down Expand Up @@ -224,6 +227,7 @@ BarElement.defaults = {
borderSkipped: 'start',
borderWidth: 0,
borderRadius: 0,
endOfStack: false,
etimberg marked this conversation as resolved.
Show resolved Hide resolved
pointStyle: undefined
};

Expand Down