MCPcopy
hub / github.com/chartjs/Chart.js / getBarBounds

Function getBarBounds

src/elements/element.bar.js:15–35  ·  view source on GitHub ↗

* Helper function to get the bounds of the bar regardless of the orientation * @param {BarElement} bar the bar * @param {boolean} [useFinalPosition] * @return {object} bounds of the bar * @private

(bar, useFinalPosition)

Source from the content-addressed store, hash-verified

13 * @private
14 */
15function getBarBounds(bar, useFinalPosition) {
16 const {x, y, base, width, height} = /** @type {BarProps} */ (bar.getProps(['x', 'y', 'base', 'width', 'height'], useFinalPosition));
17
18 let left, right, top, bottom, half;
19
20 if (bar.horizontal) {
21 half = height / 2;
22 left = Math.min(x, base);
23 right = Math.max(x, base);
24 top = y - half;
25 bottom = y + half;
26 } else {
27 half = width / 2;
28 left = x - half;
29 right = x + half;
30 top = Math.min(y, base);
31 bottom = Math.max(y, base);
32 }
33
34 return {left, top, right, bottom};
35}
36
37function skipOrLimit(skip, value, min, max) {
38 return skip ? 0 : _limitValue(value, min, max);

Callers 2

boundingRectsFunction · 0.85
inRangeFunction · 0.85

Calls 1

getPropsMethod · 0.80

Tested by

no test coverage detected