getNSTGraph method

Future<List<String>?> getNSTGraph(
  1. Test? data,
  2. Interpretations2? interpretation
)

Generates the NST (Non-Stress Test) graph and returns a list of file paths to the generated images. data contains the test data. interpretation is the interpretation data. Returns a Future that completes with a list of file paths to the generated images.

Implementation

Future<List<String>?> getNSTGraph(
    Test? data, Interpretations2? interpretation) async {
  mData = data;
  if (mData!.lengthOfTest! > 3600) {
    auto = false;
    scale = 1;
    timeScaleFactor = 6;
  }

  interpretation = interpretation;

  pointsPerPage = (10 * timeScaleFactor * XDIV);
  pointsPerDiv = timeScaleFactor * 10;
  int pages = (mData!.bpmEntries!.length / pointsPerPage).truncate();
  //pages += 1;
  if (mData!.bpmEntries!.length % pointsPerPage > 20) pages++;
  //pages++;
  //bitmaps = new Bitmap[pages];
  recorder = <ui.PictureRecorder>[];
  canvas = <Canvas>[];
  images = <ui.Image>[];
  paths = <String>[];
  for (int i = 0; i < pages; i++) {
    recorder.add(ui.PictureRecorder());
    canvas.add(Canvas(
        recorder[i],
        Rect.fromPoints(Offset(0.0, 0.0),
            Offset(WIDTH_PX.toDouble(), HEIGHT_PX.toDouble()))));
    canvas.last.scale(0.3,0.3);
  }

  drawGraph(pages);
  //drawBpmLine(bpmList, pages);
  drawLine(mData!.bpmEntries, pages, graphBpmLine);
  //await drawLine(interpretation.baselineBpmList,pages,graphBpmLine);
  drawTocoLine(mData!.tocoEntries, pages);
  drawMovements(mData!.movementEntries, pages);
  drawAutoMovements(mData!.autoFetalMovement, pages);
  //return bitmaps;

  if (interpretation != null && auto && highlight) {
    drawInterpretationAreas(
        interpretation.getAccelerationsList(), pages, graphSafeZone);
    drawInterpretationAreas(
        interpretation.getDecelerationsList(), pages, graphUnSafeZone);
    drawInterpretationAreas(
        interpretation.getNoiseAreaList(), pages, graphNoiseZone);
  }

  for (int i = 0; i < pages; i++) {
    final picture = recorder[i].endRecording();
    images.add(await picture.toImage(WIDTH_PX, HEIGHT_PX));
    paths!.add(await saveImage(i));
  }
  return paths;
}