drawDataPoints method
void
drawDataPoints(
)
override
Implementation
@override
void drawDataPoints() {
var minY = getLabelMinY();
var maxY = getLabelMaxY();
var totalBarWidth = getBarWidth();
var barMinPxX = gridMinPxX;
var barMaxPxX = gridMaxPxX;
if (maxLabelWidthX > getBarWidth()) {
barMinPxX = gridMinPxX + max(0, (maxLabelWidthX - getBarWidth())/2);
barMaxPxX = gridMaxPxX - max(0, (maxLabelWidthX - getBarWidth())/2);
}
var barSetIndex = 0;
var spaceX = (barMaxPxX - totalBarWidth - barMinPxX) / (_dataPoints.length - 1);
var alignmentOffsetX = 0.0;
if (_dataPoints.length == 1) { // Start to draw from the center
alignmentOffsetX = (barMaxPxX - barMinPxX - totalBarWidth)/2 - barMinPxX - totalBarWidth/2;
spaceX = 0;
}
_hoverPaths.clear();
for (var x in keys) {
var mapPoints = _dataPoints[x];
var barIndex = 0;
for (var graphName in _graphKeys) {
var y = mapPoints![graphName];
if (y == null) {
barIndex++;
continue;
}
var offset = barIndex * singleBarWidth + barIndex * barMargin + spaceX * barSetIndex + alignmentOffsetX;
// Clamp the value so it does not get drawn outside the graph.
var clampedY = min(y, maxY);
var pxY = lerp(clampedY, minY, maxY, gridMaxPxY, gridMinPxY);
var bar = Path2D();
var hoverPath = _BarHoverPath(bar, barMinPxX + offset, pxY, max(gridMaxPxY - pxY, 1));
bar.rect(hoverPath.pxX, hoverPath.pxY, singleBarWidth, hoverPath.height);
ctx.fillStyle = (barFillStyle[graphName] ?? barFillStyle[keyAllGraph])!.toJS;
ctx.fillRect(hoverPath.pxX, hoverPath.pxY, singleBarWidth, hoverPath.height);
if (_hoverPaths[x] == null) {
_hoverPaths[x] = {graphName: hoverPath};
} else {
_hoverPaths[x]![graphName] = hoverPath;
}
barIndex++;
}
barSetIndex++;
}
}