MCPcopy Create free account
hub / github.com/chartjs/Chart.js / _computeGridLineItems

Method _computeGridLineItems

src/core/core.scale.js:1018–1147  ·  view source on GitHub ↗

* @private

(chartArea)

Source from the content-addressed store, hash-verified

1016 * @private
1017 */
1018 _computeGridLineItems(chartArea) {
1019 const axis = this.axis;
1020 const chart = this.chart;
1021 const options = this.options;
1022 const {grid, position, border} = options;
1023 const offset = grid.offset;
1024 const isHorizontal = this.isHorizontal();
1025 const ticks = this.ticks;
1026 const ticksLength = ticks.length + (offset ? 1 : 0);
1027 const tl = getTickMarkLength(grid);
1028 const items = [];
1029
1030 const borderOpts = border.setContext(this.getContext());
1031 const axisWidth = borderOpts.display ? borderOpts.width : 0;
1032 const axisHalfWidth = axisWidth / 2;
1033 const alignBorderValue = function(pixel) {
1034 return _alignPixel(chart, pixel, axisWidth);
1035 };
1036 let borderValue, i, lineValue, alignedLineValue;
1037 let tx1, ty1, tx2, ty2, x1, y1, x2, y2;
1038
1039 if (position === 'top') {
1040 borderValue = alignBorderValue(this.bottom);
1041 ty1 = this.bottom - tl;
1042 ty2 = borderValue - axisHalfWidth;
1043 y1 = alignBorderValue(chartArea.top) + axisHalfWidth;
1044 y2 = chartArea.bottom;
1045 } else if (position === 'bottom') {
1046 borderValue = alignBorderValue(this.top);
1047 y1 = chartArea.top;
1048 y2 = alignBorderValue(chartArea.bottom) - axisHalfWidth;
1049 ty1 = borderValue + axisHalfWidth;
1050 ty2 = this.top + tl;
1051 } else if (position === 'left') {
1052 borderValue = alignBorderValue(this.right);
1053 tx1 = this.right - tl;
1054 tx2 = borderValue - axisHalfWidth;
1055 x1 = alignBorderValue(chartArea.left) + axisHalfWidth;
1056 x2 = chartArea.right;
1057 } else if (position === 'right') {
1058 borderValue = alignBorderValue(this.left);
1059 x1 = chartArea.left;
1060 x2 = alignBorderValue(chartArea.right) - axisHalfWidth;
1061 tx1 = borderValue + axisHalfWidth;
1062 tx2 = this.left + tl;
1063 } else if (axis === 'x') {
1064 if (position === 'center') {
1065 borderValue = alignBorderValue((chartArea.top + chartArea.bottom) / 2 + 0.5);
1066 } else if (isObject(position)) {
1067 const positionAxisID = Object.keys(position)[0];
1068 const value = position[positionAxisID];
1069 borderValue = alignBorderValue(this.chart.scales[positionAxisID].getPixelForValue(value));
1070 }
1071
1072 y1 = chartArea.top;
1073 y2 = chartArea.bottom;
1074 ty1 = borderValue + axisHalfWidth;
1075 ty2 = ty1 + tl;

Callers 1

drawGridMethod · 0.95

Calls 9

isHorizontalMethod · 0.95
getContextMethod · 0.95
getTickMarkLengthFunction · 0.85
isObjectFunction · 0.85
valueOrDefaultFunction · 0.85
getPixelForGridLineFunction · 0.85
_alignPixelFunction · 0.85
setContextMethod · 0.80
getPixelForValueMethod · 0.65

Tested by

no test coverage detected