mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-02-02 14:16:58 +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
|
@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(
|
LineChartData(
|
||||||
lineTouchData: LineTouchData(
|
lineTouchData: LineTouchData(
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
@ -112,11 +117,7 @@ class NetworkChart extends StatelessWidget {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
minY: 0,
|
minY: 0,
|
||||||
maxY: [
|
maxY: listDataMax * 1.2,
|
||||||
...listData[0].map((final e) => e.value),
|
|
||||||
...listData[1].map((final e) => e.value),
|
|
||||||
].reduce(max) *
|
|
||||||
1.2,
|
|
||||||
minX: 0,
|
minX: 0,
|
||||||
titlesData: FlTitlesData(
|
titlesData: FlTitlesData(
|
||||||
topTitles: const AxisTitles(
|
topTitles: const AxisTitles(
|
||||||
|
@ -157,12 +158,7 @@ class NetworkChart extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
interval: [
|
interval: listDataMax * 2 / 6.5,
|
||||||
...listData[0].map((final e) => e.value),
|
|
||||||
...listData[1].map((final e) => e.value),
|
|
||||||
].reduce(max) *
|
|
||||||
2 /
|
|
||||||
6.5,
|
|
||||||
showTitles: true,
|
showTitles: true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -171,12 +167,7 @@ class NetworkChart extends StatelessWidget {
|
||||||
show: true,
|
show: true,
|
||||||
drawVerticalLine: true,
|
drawVerticalLine: true,
|
||||||
verticalInterval: 40,
|
verticalInterval: 40,
|
||||||
horizontalInterval: [
|
horizontalInterval: listDataMax * 2 / 6.5,
|
||||||
...listData[0].map((final e) => e.value),
|
|
||||||
...listData[1].map((final e) => e.value),
|
|
||||||
].reduce(max) *
|
|
||||||
2 /
|
|
||||||
6.5,
|
|
||||||
getDrawingHorizontalLine: (final value) => FlLine(
|
getDrawingHorizontalLine: (final value) => FlLine(
|
||||||
color: Theme.of(context).colorScheme.outline.withOpacity(0.3),
|
color: Theme.of(context).colorScheme.outline.withOpacity(0.3),
|
||||||
strokeWidth: 1,
|
strokeWidth: 1,
|
||||||
|
@ -209,6 +200,7 @@ class NetworkChart extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
bool checkToShowTitle(
|
bool checkToShowTitle(
|
||||||
final double minValue,
|
final double minValue,
|
||||||
|
|
Loading…
Reference in a new issue