UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

30 lines 1.14 kB
import { darkenColor } from "./helpers"; export default (function () { return function (plotter) { if (plotter.seriesIndex !== 0) return; var g = plotter.dygraph; var ctx = plotter.drawingContext; var sets = plotter.allSeriesPoints; var y_bottom = g.toDomYCoord(0); var min_sep = Infinity; sets.forEach(function (points) { var sep = points[1].canvasx - points[0].canvasx; if (sep < min_sep) min_sep = sep; }); var bar_width = Math.floor(2.0 / 3 * min_sep); var fillColors = g.getColors(); var strokeColors = g.getColors().map(function (color) { return darkenColor(color); }); sets.forEach(function (points, j) { ctx.fillStyle = fillColors[j]; ctx.strokeStyle = strokeColors[j]; points.forEach(function (p) { var center_x = p.canvasx; var x_left = center_x - bar_width / 2 * (1 - j / (sets.length > 1 ? sets.length - 1 : 1)); ctx.fillRect(x_left, p.canvasy, bar_width / sets.length, y_bottom - p.canvasy); ctx.strokeRect(x_left, p.canvasy, bar_width / sets.length, y_bottom - p.canvasy); }); }); }; });