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

Method drawGrid

src/core/core.scale.js:1473–1522  ·  view source on GitHub ↗

* @protected

(chartArea)

Source from the content-addressed store, hash-verified

1471 * @protected
1472 */
1473 drawGrid(chartArea) {
1474 const grid = this.options.grid;
1475 const ctx = this.ctx;
1476 const items = this._gridLineItems || (this._gridLineItems = this._computeGridLineItems(chartArea));
1477 let i, ilen;
1478
1479 const drawLine = (p1, p2, style) => {
1480 if (!style.width || !style.color) {
1481 return;
1482 }
1483 ctx.save();
1484 ctx.lineWidth = style.width;
1485 ctx.strokeStyle = style.color;
1486 ctx.setLineDash(style.borderDash || []);
1487 ctx.lineDashOffset = style.borderDashOffset;
1488
1489 ctx.beginPath();
1490 ctx.moveTo(p1.x, p1.y);
1491 ctx.lineTo(p2.x, p2.y);
1492 ctx.stroke();
1493 ctx.restore();
1494 };
1495
1496 if (grid.display) {
1497 for (i = 0, ilen = items.length; i < ilen; ++i) {
1498 const item = items[i];
1499
1500 if (grid.drawOnChartArea) {
1501 drawLine(
1502 {x: item.x1, y: item.y1},
1503 {x: item.x2, y: item.y2},
1504 item
1505 );
1506 }
1507
1508 if (grid.drawTicks) {
1509 drawLine(
1510 {x: item.tx1, y: item.ty1},
1511 {x: item.tx2, y: item.ty2},
1512 {
1513 color: item.tickColor,
1514 width: item.tickWidth,
1515 borderDash: item.tickBorderDash,
1516 borderDashOffset: item.tickBorderDashOffset
1517 }
1518 );
1519 }
1520 }
1521 }
1522 }
1523
1524 /**
1525 * @protected

Callers 2

drawMethod · 0.95
_layersMethod · 0.95

Calls 1

_computeGridLineItemsMethod · 0.95

Tested by

no test coverage detected