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

Method drawGrid

src/core/core.scale.js:1470–1519  ·  view source on GitHub ↗

* @protected

(chartArea)

Source from the content-addressed store, hash-verified

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

Callers 2

drawMethod · 0.95
_layersMethod · 0.95

Calls 1

_computeGridLineItemsMethod · 0.95

Tested by

no test coverage detected