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

Function titleArgs

src/core/core.scale.js:131–166  ·  view source on GitHub ↗
(scale, offset, position, align)

Source from the content-addressed store, hash-verified

129}
130
131function titleArgs(scale, offset, position, align) {
132 const {top, left, bottom, right, chart} = scale;
133 const {chartArea, scales} = chart;
134 let rotation = 0;
135 let maxWidth, titleX, titleY;
136 const height = bottom - top;
137 const width = right - left;
138
139 if (scale.isHorizontal()) {
140 titleX = _alignStartEnd(align, left, right);
141
142 if (isObject(position)) {
143 const positionAxisID = Object.keys(position)[0];
144 const value = position[positionAxisID];
145 titleY = scales[positionAxisID].getPixelForValue(value) + height - offset;
146 } else if (position === 'center') {
147 titleY = (chartArea.bottom + chartArea.top) / 2 + height - offset;
148 } else {
149 titleY = offsetFromEdge(scale, position, offset);
150 }
151 maxWidth = right - left;
152 } else {
153 if (isObject(position)) {
154 const positionAxisID = Object.keys(position)[0];
155 const value = position[positionAxisID];
156 titleX = scales[positionAxisID].getPixelForValue(value) - width + offset;
157 } else if (position === 'center') {
158 titleX = (chartArea.left + chartArea.right) / 2 - width + offset;
159 } else {
160 titleX = offsetFromEdge(scale, position, offset);
161 }
162 titleY = _alignStartEnd(align, bottom, top);
163 rotation = position === 'left' ? -HALF_PI : HALF_PI;
164 }
165 return {titleX, titleY, maxWidth, rotation};
166}
167
168export default class Scale extends Element {
169

Callers 1

drawTitleMethod · 0.85

Calls 5

_alignStartEndFunction · 0.85
isObjectFunction · 0.85
offsetFromEdgeFunction · 0.85
isHorizontalMethod · 0.65
getPixelForValueMethod · 0.65

Tested by

no test coverage detected