drawGraph method

void drawGraph(
  1. Feature feature,
  2. Canvas canvas,
  3. Size graph,
  4. Size cell,
  5. Size margin,
)

Implementation

void drawGraph(
    Feature feature, Canvas canvas, Size graph, Size cell, Size margin) {
  Paint fillPaint = Paint()
    ..color = feature.color.withOpacity(graphOpacity)
    ..style = PaintingStyle.fill;
  Paint strokePaint = Paint()
    ..color = feature.color
    ..strokeWidth = 2
    ..style = PaintingStyle.stroke;

  Path path = Path();
  Path linePath = Path();
  path.moveTo(margin.width, graph.height + margin.height);
  path.lineTo(
    margin.width,
    margin.height + graph.height - feature.data[0] * graph.height,
  );
  linePath.moveTo(
    margin.width,
    margin.height + graph.height - feature.data[0] * graph.height,
  );
  int i = 0;
  for (i = 1; i < labelX!.length && i < feature.data.length; i++) {
    if (feature.data[i] > 1) {
      feature.data[i] = 1;
    }
    if (feature.data[i] < 0) {
      feature.data[i] = 0;
    }
    path.lineTo(
      margin.width + i * cell.width,
      margin.height + graph.height - feature.data[i] * graph.height,
    );
    linePath.lineTo(
      margin.width + i * cell.width,
      margin.height + graph.height - feature.data[i] * graph.height,
    );
  }
  // path.lineTo(
  //     margin.width + (feature.data.length - 1) * cell.width, margin.height);
  path.lineTo(
    margin.width + cell.width * (i - 1),
    margin.height + graph.height,
  );
  canvas.drawPath(path, fillPaint);
  canvas.drawPath(linePath, strokePaint);
}