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

Function computeFitCategoryTraits

src/controllers/controller.bar.js:61–81  ·  view source on GitHub ↗

* Computes an "ideal" category based on the absolute bar thickness or, if undefined or null, * uses the smallest interval (see computeMinSampleSize) that prevents bar overlapping. This * mode currently always generates bars equally sized (until we introduce scriptable options?). * @private

(index, ruler, options, stackCount)

Source from the content-addressed store, hash-verified

59 * @private
60 */
61function computeFitCategoryTraits(index, ruler, options, stackCount) {
62 const thickness = options.barThickness;
63 let size, ratio;
64
65 if (isNullOrUndef(thickness)) {
66 size = ruler.min * options.categoryPercentage;
67 ratio = options.barPercentage;
68 } else {
69 // When bar thickness is enforced, category and bar percentages are ignored.
70 // Note(SB): we could add support for relative bar thickness (e.g. barThickness: '50%')
71 // and deprecate barPercentage since this value is ignored when thickness is absolute.
72 size = thickness * stackCount;
73 ratio = 1;
74 }
75
76 return {
77 chunk: size / stackCount,
78 ratio,
79 start: ruler.pixels[index] - (size / 2)
80 };
81}
82
83/**
84 * Computes an "optimal" category that globally arranges bars side by side (no gap when

Callers 1

Calls 1

isNullOrUndefFunction · 0.85

Tested by

no test coverage detected