renderPoints method

void renderPoints()

Implementation

void renderPoints() {
  var ctx = startRender();

  chartWidth = width - _rightMargin - _leftMargin;
  chartHeight = height - _bottomMargin - _topMargin;

  mouseTransform = ChartTransform.forScale(
      minTime: minTime!,
      maxTime: maxTime!,
      width: chartWidth,
      leftMargin: _leftMargin,
      minValue: 0.0,
      maxValue: 1.0,
      height: 1,
      topMargin: 0);

  for (var i = 0; i < series.length; i++) {
    series[i].transform = ChartTransform.forScale(
        minTime: minTime!,
        maxTime: maxTime!,
        width: chartWidth,
        leftMargin: _leftMargin,
        minValue: series[i].minValue.toDouble(),
        maxValue: series[i].maxValue.toDouble(),
        height: chartHeight,
        topMargin: _topMargin);
  }

  xToTime.clear();
  for (var time in allKeysList) {
    xToTime[mouseTransform!.apply(time, 0).x.round()] = time;
  }

  if (font != null) {
    //TODO: wait on load and reload
    //font.load().then(() => {});
    ctx.font = '${font!.style} ${font!.weight} ${fontSize}px ${font!.family}';
  } else {
    ctx.font = '${fontSize}px Arial';
  }

  ctx.lineWidth = 1;
  ctx.strokeStyle = gridColor.toJS;
  ctx.fillStyle = gridColor.toJS;

  if (showGrid) {
    ctx.strokeRect(_leftMargin, _topMargin, chartWidth, chartHeight);
  }
  if (highlightCurrentInterval && interval != null && currentTime != null && mouseTransform != null) {
    final hX1 = mouseTransform!.apply((currentTime! - (interval!.inMilliseconds / 2)).round(), 0).x;
    final hX2 = mouseTransform!.apply((currentTime! + (interval!.inMilliseconds / 2)).round(), 0).x;
    ctx.fillRect(hX1, _topMargin, hX2 - hX1, chartHeight);
  }

  ctx.save();
  ctx.textBaseline = "middle";
  int marginIdx = 0;
  var leftScaleX = _leftMargin - textMargin;
  var rightScaleX = _leftMargin + chartWidth + textMargin;

  if (showValueScale) {
    for (var scale in allScales) {
      var valueStepWidth = chartHeight / (scale.lines.length - 1);
      int i = 0;
      for (var line in scale.lines) {
        var y = _topMargin + chartHeight - (i * valueStepWidth);
        ctx.strokeStyle = gridColor.toJS;
        ctx.beginPath();
        ctx.moveTo(_leftMargin, y);
        ctx.lineTo(width - _rightMargin, y);
        ctx.stroke();
        //ctx.fillStyle;

        ctx.fillStyle = 'black'.toJS; //series[j].color.toJS;

        if (scale.position == ChartScalePosition.left) {
          ctx.textAlign = "right";
          ctx.fillText(scale.formatLegendValue(line), leftScaleX, y);
        } else {
          ctx.textAlign = "left";
          ctx.fillText(scale.formatLegendValue(line), rightScaleX, y);
        }
        i++;
      }

      if (scale.position == ChartScalePosition.left) {
        leftScaleX -= scaleMargins[marginIdx++];
      } else {
        rightScaleX += scaleMargins[marginIdx++];
      }
    }
  }

  ctx.fillStyle = textColor.toJS;
  ctx.strokeStyle = gridColor.toJS;

  if (rotateTimeLabels) {
    ctx.translate(_leftMargin, height - _bottomMargin);
    ctx.rotate(-pi / 2);
    ctx.textAlign = "right";
    ctx.textBaseline = "middle";
    for (var time in timeLabels.keys) {
      ctx.save();
      ctx.translate(0, chartWidth * ((time - minTime!) / (maxTime! - minTime!)));
      ctx.beginPath();
      ctx.moveTo(0, 0);
      ctx.lineTo(chartHeight, 0);
      ctx.stroke();
      ctx.fillText(timeLabels[time]!, -textMargin, 0);
      ctx.restore();
    }
    ctx.restore();
  } else {
    ctx.textAlign = "center";
    ctx.textBaseline = "top";
    for (var time in timeLabels.keys) {
      final left = _leftMargin + (chartWidth * ((time - minTime!) / (maxTime! - minTime!)));

      ctx.beginPath();
      ctx.moveTo(left, _topMargin);
      ctx.lineTo(left, _topMargin + chartHeight);
      ctx.stroke();

      ctx.fillText(timeLabels[time]!, left, _topMargin + chartHeight + textMargin);
    }
  }

  for (var j = 0; j < series.length; j++) {
    series[j].render(this, ctx);
  }
}