mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 09:16:54 +00:00
refactor(charts): Optimize wasted calculation for network chart
This commit is contained in:
parent
bf99d3b73d
commit
48c7d7be2c
|
@ -33,7 +33,12 @@ class NetworkChart extends StatelessWidget {
|
|||
}
|
||||
|
||||
@override
|
||||
Widget build(final BuildContext context) => LineChart(
|
||||
Widget build(final BuildContext context) {
|
||||
final listDataMax = [
|
||||
...listData[0].map((final e) => e.value),
|
||||
...listData[1].map((final e) => e.value),
|
||||
].reduce(max);
|
||||
return LineChart(
|
||||
LineChartData(
|
||||
lineTouchData: LineTouchData(
|
||||
enabled: true,
|
||||
|
@ -112,11 +117,7 @@ class NetworkChart extends StatelessWidget {
|
|||
),
|
||||
],
|
||||
minY: 0,
|
||||
maxY: [
|
||||
...listData[0].map((final e) => e.value),
|
||||
...listData[1].map((final e) => e.value),
|
||||
].reduce(max) *
|
||||
1.2,
|
||||
maxY: listDataMax * 1.2,
|
||||
minX: 0,
|
||||
titlesData: FlTitlesData(
|
||||
topTitles: const AxisTitles(
|
||||
|
@ -157,12 +158,7 @@ class NetworkChart extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
),
|
||||
interval: [
|
||||
...listData[0].map((final e) => e.value),
|
||||
...listData[1].map((final e) => e.value),
|
||||
].reduce(max) *
|
||||
2 /
|
||||
6.5,
|
||||
interval: listDataMax * 2 / 6.5,
|
||||
showTitles: true,
|
||||
),
|
||||
),
|
||||
|
@ -171,12 +167,7 @@ class NetworkChart extends StatelessWidget {
|
|||
show: true,
|
||||
drawVerticalLine: true,
|
||||
verticalInterval: 40,
|
||||
horizontalInterval: [
|
||||
...listData[0].map((final e) => e.value),
|
||||
...listData[1].map((final e) => e.value),
|
||||
].reduce(max) *
|
||||
2 /
|
||||
6.5,
|
||||
horizontalInterval: listDataMax * 2 / 6.5,
|
||||
getDrawingHorizontalLine: (final value) => FlLine(
|
||||
color: Theme.of(context).colorScheme.outline.withOpacity(0.3),
|
||||
strokeWidth: 1,
|
||||
|
@ -209,6 +200,7 @@ class NetworkChart extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool checkToShowTitle(
|
||||
final double minValue,
|
||||
|
|
Loading…
Reference in a new issue