Skip to content

Commit

Permalink
RadarChart related lerps added to lerp.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
payam-zahedi committed Feb 18, 2021
1 parent 34828f9 commit fd00abe
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 15 deletions.
32 changes: 27 additions & 5 deletions lib/src/chart/radar_chart/radar_chart_darta.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'dart:ui';

import 'package:fl_chart/fl_chart.dart';
import 'package:fl_chart/src/utils/lerp.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';

typedef GetTitleByIndexFunction = String Function(int index);
Expand All @@ -8,17 +12,27 @@ class RadarChartData extends BaseChartData {
final List<RadarDataSet> dataSets;
final GetTitleByIndexFunction getTitle;
final int count;
final Color fillColor;

RadarChartData({
this.dataSets = const [],
this.getTitle,
@required this.count,
this.fillColor = Colors.transparent,
}) : assert(count != null);

@override
BaseChartData lerp(BaseChartData a, BaseChartData b, double t) {
//ToDo(payam) : complete this method
throw Exception('Illegal State');
RadarChartData lerp(BaseChartData a, BaseChartData b, double t) {
if (a is RadarChartData && b is RadarChartData && t != null) {
return RadarChartData(
getTitle: b.getTitle,
count: lerpInt(a.count, b.count, t),
fillColor: Color.lerp(a.fillColor, b.fillColor, t),
dataSets: lerpRadarDataSetList(a.dataSets, b.dataSets, t),
);
} else {
throw Exception('Illegal State');
}
}
}

Expand All @@ -31,12 +45,20 @@ class RadarDataSet {
this.color,
});

//ToDo(payam) : add lerp function
static RadarDataSet lerp(RadarDataSet a, RadarDataSet b, double t) {
return RadarDataSet(
dataEntries: lerpRadarEntryList(a.dataEntries, b.dataEntries, t),
color: Color.lerp(a.color, b.color, t),
);
}
}

class RadarEntry {
final double value;

RadarEntry({this.value = 0});
//ToDo(payam) : add lerp function

static RadarEntry lerp(RadarEntry a, RadarEntry b, double t) {
return RadarEntry(value: lerpDouble(a.value, b.value, t));
}
}
47 changes: 37 additions & 10 deletions lib/src/utils/lerp.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import 'dart:ui';

import 'package:fl_chart/fl_chart.dart';
import 'package:fl_chart/src/chart/radar_chart/radar_chart_darta.dart';
import 'package:fl_chart/src/chart/scatter_chart/scatter_chart_data.dart';

List<Color> lerpColorList(List<Color> a, List<Color> b, double t) {
Expand Down Expand Up @@ -38,7 +38,6 @@ int lerpInt(int a, int b, double t) {
return (a + (b - a) * t).round();
}


List<FlSpot> lerpFlSpotList(List<FlSpot> a, List<FlSpot> b, double t) {
if (a != null && b != null && a.length == b.length) {
return List.generate(a.length, (i) {
Expand All @@ -49,7 +48,8 @@ List<FlSpot> lerpFlSpotList(List<FlSpot> a, List<FlSpot> b, double t) {
}
}

List<HorizontalLine> lerpHorizontalLineList(List<HorizontalLine> a, List<HorizontalLine> b, double t) {
List<HorizontalLine> lerpHorizontalLineList(
List<HorizontalLine> a, List<HorizontalLine> b, double t) {
if (a != null && b != null && a.length == b.length) {
return List.generate(a.length, (i) {
return HorizontalLine.lerp(a[i], b[i], t);
Expand All @@ -69,7 +69,8 @@ List<VerticalLine> lerpVerticalLineList(List<VerticalLine> a, List<VerticalLine>
}
}

List<LineChartBarData> lerpLineChartBarDataList(List<LineChartBarData> a, List<LineChartBarData> b, double t) {
List<LineChartBarData> lerpLineChartBarDataList(
List<LineChartBarData> a, List<LineChartBarData> b, double t) {
if (a != null && b != null && a.length == b.length) {
return List.generate(a.length, (i) {
return LineChartBarData.lerp(a[i], b[i], t);
Expand All @@ -79,7 +80,8 @@ List<LineChartBarData> lerpLineChartBarDataList(List<LineChartBarData> a, List<L
}
}

List<BetweenBarsData> lerpBetweenBarsDataList(List<BetweenBarsData> a, List<BetweenBarsData> b, double t) {
List<BetweenBarsData> lerpBetweenBarsDataList(
List<BetweenBarsData> a, List<BetweenBarsData> b, double t) {
if (a != null && b != null && a.length == b.length) {
return List.generate(a.length, (i) {
return BetweenBarsData.lerp(a[i], b[i], t);
Expand All @@ -89,7 +91,8 @@ List<BetweenBarsData> lerpBetweenBarsDataList(List<BetweenBarsData> a, List<Betw
}
}

List<BarChartGroupData> lerpBarChartGroupDataList(List<BarChartGroupData> a, List<BarChartGroupData> b, double t) {
List<BarChartGroupData> lerpBarChartGroupDataList(
List<BarChartGroupData> a, List<BarChartGroupData> b, double t) {
if (a != null && b != null && a.length == b.length) {
return List.generate(a.length, (i) {
return BarChartGroupData.lerp(a[i], b[i], t);
Expand All @@ -99,7 +102,8 @@ List<BarChartGroupData> lerpBarChartGroupDataList(List<BarChartGroupData> a, Lis
}
}

List<BarChartRodData> lerpBarChartRodDataList(List<BarChartRodData> a, List<BarChartRodData> b, double t) {
List<BarChartRodData> lerpBarChartRodDataList(
List<BarChartRodData> a, List<BarChartRodData> b, double t) {
if (a != null && b != null && a.length == b.length) {
return List.generate(a.length, (i) {
return BarChartRodData.lerp(a[i], b[i], t);
Expand All @@ -109,7 +113,8 @@ List<BarChartRodData> lerpBarChartRodDataList(List<BarChartRodData> a, List<BarC
}
}

List<PieChartSectionData> lerpPieChartSectionDataList(List<PieChartSectionData> a, List<PieChartSectionData> b, double t) {
List<PieChartSectionData> lerpPieChartSectionDataList(
List<PieChartSectionData> a, List<PieChartSectionData> b, double t) {
if (a != null && b != null && a.length == b.length) {
return List.generate(a.length, (i) {
return PieChartSectionData.lerp(a[i], b[i], t);
Expand All @@ -128,12 +133,34 @@ List<ScatterSpot> lerpScatterSpotList(List<ScatterSpot> a, List<ScatterSpot> b,
return b;
}
}
List<BarChartRodStackItem> lerpBarChartRodStackList(List<BarChartRodStackItem> a, List<BarChartRodStackItem> b, double t) {

List<BarChartRodStackItem> lerpBarChartRodStackList(
List<BarChartRodStackItem> a, List<BarChartRodStackItem> b, double t) {
if (a != null && b != null && a.length == b.length) {
return List.generate(a.length, (i) {
return BarChartRodStackItem.lerp(a[i], b[i], t);
});
} else {
return b;
}
}
}

List<RadarEntry> lerpRadarEntryList(List<RadarEntry> a, List<RadarEntry> b, double t) {
if (a != null && b != null && a.length == b.length) {
return List.generate(a.length, (i) {
return RadarEntry.lerp(a[i], b[i], t);
});
} else {
return b;
}
}

List<RadarDataSet> lerpRadarDataSetList(List<RadarDataSet> a, List<RadarDataSet> b, double t) {
if (a != null && b != null && a.length == b.length) {
return List.generate(a.length, (i) {
return RadarDataSet.lerp(a[i], b[i], t);
});
} else {
return b;
}
}

0 comments on commit fd00abe

Please sign in to comment.