ChartTransform.forScale constructor

ChartTransform.forScale({
  1. required int minTime,
  2. required int maxTime,
  3. required int width,
  4. required int leftMargin,
  5. required double minValue,
  6. required double maxValue,
  7. required int height,
  8. required int topMargin,
})

Implementation

factory ChartTransform.forScale({
  required int minTime,
  required int maxTime,
  required int width,
  required int leftMargin,
  required double minValue,
  required double maxValue,
  required int height,
  required int topMargin,
}) {
  final sx = (width) / (maxTime - minTime);
  final tx = leftMargin - sx * minTime;

  final rawSy = (height) / (maxValue - minValue);
  final sy = -rawSy;
  final ty = height + topMargin + rawSy * minValue;

  return ChartTransform(sx: sx, tx: tx, sy: sy, ty: ty);
}