2024-08-01 14:08:34 +08:00
|
|
|
|
import 'dart:math';
|
|
|
|
|
|
2024-07-30 18:20:27 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:fl_chart/fl_chart.dart';
|
2024-08-01 14:08:34 +08:00
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
import 'package:gnss/gnss.dart';
|
2024-07-30 18:20:27 +08:00
|
|
|
|
|
2024-08-01 14:08:34 +08:00
|
|
|
|
import '../Controller/gnss_controller.dart';
|
2024-07-30 18:20:27 +08:00
|
|
|
|
|
2024-08-01 14:08:34 +08:00
|
|
|
|
const signalPrefixList = <String>["G", "R", "E", "B", "Q"];
|
|
|
|
|
const List<Color> signalColorList = [
|
|
|
|
|
Color.fromARGB(255, 255, 0, 0),
|
|
|
|
|
Color.fromARGB(255, 0, 255, 0),
|
|
|
|
|
Color.fromARGB(255, 0, 0, 255),
|
|
|
|
|
Color.fromARGB(255, 255, 255, 0),
|
|
|
|
|
Color.fromARGB(255, 0, 255, 255)
|
|
|
|
|
];
|
2024-07-30 18:20:27 +08:00
|
|
|
|
|
2024-08-01 18:17:57 +08:00
|
|
|
|
class ChartPart extends GetView<GnssController> {
|
|
|
|
|
ChartPart({super.key});
|
|
|
|
|
|
2024-08-01 14:08:34 +08:00
|
|
|
|
List<BarChartGroupData> checkSVData = [];
|
2024-08-01 18:17:57 +08:00
|
|
|
|
|
2024-08-01 14:08:34 +08:00
|
|
|
|
double maxY = 0;
|
|
|
|
|
int maxX = 10;
|
|
|
|
|
double xLength = 0;
|
|
|
|
|
|
2024-08-01 18:17:57 +08:00
|
|
|
|
// void drawBarChart(
|
|
|
|
|
// Canvas canvas,
|
|
|
|
|
// Size size,
|
|
|
|
|
// int index,
|
|
|
|
|
// Paint paint,
|
|
|
|
|
// ) {
|
|
|
|
|
// for (int index = 0; index < QselectedSignal.length; index++) {
|
|
|
|
|
// if (QselectedSignal[index]) {
|
|
|
|
|
// var snr = signalGNSS[index];
|
|
|
|
|
// List<int> signal = snr.values.toList(); // 从 snr Map 中提取值并生成整数数组
|
|
|
|
|
// print('signal= $signal');
|
|
|
|
|
// for (int i = 0; i < signal.length; i++) {
|
|
|
|
|
// if (signal[0] == 0 &&
|
|
|
|
|
// signal[1] == 0 &&
|
|
|
|
|
// signal[2] == 0 &&
|
|
|
|
|
// signal[3] == 0 &&
|
|
|
|
|
// signal[4] == 0) {
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// maxX = max(maxX, 16);
|
|
|
|
|
// List<int> listy = [
|
|
|
|
|
// signal[0],
|
|
|
|
|
// signal[1],
|
|
|
|
|
// signal[2],
|
|
|
|
|
// signal[3],
|
|
|
|
|
// signal[4]
|
|
|
|
|
// ];
|
|
|
|
|
// int maxItem = listy.reduce(max);
|
|
|
|
|
// maxY = max(maxY, maxItem.toDouble());
|
|
|
|
|
// checkSVData.add(makeGroupData(i + 1, listy, signalColorList[0]));
|
|
|
|
|
// xLength++;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2024-08-01 14:08:34 +08:00
|
|
|
|
|
2024-08-01 18:17:57 +08:00
|
|
|
|
// if (checkSVData.isNotEmpty) {
|
|
|
|
|
// if (controller.startIndex.value < checkSVData.length - 8) {
|
|
|
|
|
// checkSVData = checkSVData.sublist(
|
|
|
|
|
// controller.startIndex.value, controller.startIndex.value + 8);
|
|
|
|
|
// } else {
|
|
|
|
|
// checkSVData = checkSVData.sublist(
|
|
|
|
|
// controller.startIndex.value, checkSVData.length - 1);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2024-08-01 14:08:34 +08:00
|
|
|
|
|
2024-08-01 18:17:57 +08:00
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-08-01 14:08:34 +08:00
|
|
|
|
final size = MediaQuery.of(context).size;
|
|
|
|
|
final orientation =
|
|
|
|
|
MediaQuery.of(context).orientation == Orientation.portrait;
|
2024-08-01 18:17:57 +08:00
|
|
|
|
return Obx(() {
|
|
|
|
|
controller.singnalUpdate.value;
|
|
|
|
|
List<SignalGNSS> signalGNSS = controller.signalData == null
|
|
|
|
|
? []
|
|
|
|
|
: (controller.signalData!['BDS'] ?? []);
|
|
|
|
|
//
|
|
|
|
|
for (var i = 0; i < signalGNSS.length; i++) {}
|
|
|
|
|
|
|
|
|
|
return SizedBox(
|
|
|
|
|
width: size.width,
|
|
|
|
|
// decoration: const BoxDecoration(color: Colors.white),
|
|
|
|
|
child: AspectRatio(
|
|
|
|
|
aspectRatio: 1,
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(10),
|
|
|
|
|
child: Stack(
|
|
|
|
|
children: [
|
|
|
|
|
Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Obx(() {
|
|
|
|
|
controller.startIndex.value;
|
|
|
|
|
return BarChart(
|
|
|
|
|
swapAnimationDuration:
|
|
|
|
|
const Duration(milliseconds: 0),
|
|
|
|
|
BarChartData(
|
|
|
|
|
maxY: 100, // 提示需要+ 20 因为 提示是根据柱状图位置进行计算的
|
|
|
|
|
barTouchData: BarTouchData(
|
|
|
|
|
enabled: false,
|
|
|
|
|
touchTooltipData: BarTouchTooltipData(
|
|
|
|
|
// tooltipBgColor: Colors.blueGrey,
|
|
|
|
|
getTooltipItem: (
|
|
|
|
|
BarChartGroupData group,
|
|
|
|
|
int groupIndex,
|
|
|
|
|
BarChartRodData rod,
|
|
|
|
|
int rodIndex,
|
|
|
|
|
) {
|
|
|
|
|
return BarTooltipItem(
|
|
|
|
|
'L1:${group.barRods[0].toY}\n',
|
|
|
|
|
const TextStyle(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
decoration: TextDecoration.none,
|
|
|
|
|
color: Colors.black,
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
shadows: [
|
|
|
|
|
Shadow(
|
|
|
|
|
color: Colors.black26,
|
|
|
|
|
blurRadius: 12,
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
touchCallback: (event, response) {
|
|
|
|
|
if (event.isInterestedForInteractions &&
|
|
|
|
|
response != null &&
|
|
|
|
|
response.spot != null) {
|
|
|
|
|
// setState(() {
|
|
|
|
|
// touchedGroupIndex =
|
|
|
|
|
// response.spot!.touchedBarGroupIndex;
|
|
|
|
|
// });
|
|
|
|
|
} else {
|
|
|
|
|
// setState(() {
|
|
|
|
|
// touchedGroupIndex = -100;
|
|
|
|
|
// });
|
|
|
|
|
}
|
2024-08-01 14:08:34 +08:00
|
|
|
|
},
|
|
|
|
|
),
|
2024-08-01 18:17:57 +08:00
|
|
|
|
titlesData: FlTitlesData(
|
|
|
|
|
show: true,
|
|
|
|
|
rightTitles: const AxisTitles(
|
|
|
|
|
sideTitles: SideTitles(showTitles: false),
|
2024-08-01 14:08:34 +08:00
|
|
|
|
),
|
2024-08-01 18:17:57 +08:00
|
|
|
|
topTitles: const AxisTitles(
|
|
|
|
|
sideTitles: SideTitles(showTitles: false),
|
|
|
|
|
),
|
|
|
|
|
bottomTitles: AxisTitles(
|
|
|
|
|
sideTitles: SideTitles(
|
|
|
|
|
showTitles: true,
|
|
|
|
|
getTitlesWidget: bottomTitles,
|
|
|
|
|
reservedSize: 42,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
leftTitles: AxisTitles(
|
|
|
|
|
sideTitles: SideTitles(
|
|
|
|
|
showTitles: true,
|
|
|
|
|
reservedSize: 40,
|
|
|
|
|
interval: 1,
|
|
|
|
|
getTitlesWidget: leftTitles,
|
|
|
|
|
),
|
2024-08-01 14:08:34 +08:00
|
|
|
|
),
|
|
|
|
|
),
|
2024-08-01 18:17:57 +08:00
|
|
|
|
borderData: FlBorderData(
|
|
|
|
|
show: false,
|
|
|
|
|
),
|
|
|
|
|
barGroups:
|
|
|
|
|
List.generate(signalGNSS.length, (index) {
|
|
|
|
|
List<int> listy = [];
|
|
|
|
|
Map snr = signalGNSS[index].snr;
|
|
|
|
|
|
|
|
|
|
snr.forEach((key, value) {
|
|
|
|
|
listy.add(value);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return makeGroupData(
|
|
|
|
|
index, listy, signalColorList[0]);
|
|
|
|
|
}),
|
|
|
|
|
gridData: const FlGridData(show: true),
|
2024-08-01 14:08:34 +08:00
|
|
|
|
),
|
2024-08-01 18:17:57 +08:00
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
orientation
|
|
|
|
|
? const SizedBox(
|
|
|
|
|
height: 50,
|
|
|
|
|
)
|
|
|
|
|
: const Text(""),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
Positioned(
|
|
|
|
|
bottom: 0,
|
|
|
|
|
left: 0,
|
|
|
|
|
right: 0,
|
|
|
|
|
height: size.height,
|
|
|
|
|
child: Opacity(
|
|
|
|
|
opacity: 0, // 设置 Slider 组件的透明度为 0,使其不可见
|
|
|
|
|
child: Slider(
|
|
|
|
|
value: controller.startIndex.toDouble(),
|
|
|
|
|
onChanged: (newvalue) {
|
|
|
|
|
controller.updateSlider(newvalue);
|
|
|
|
|
},
|
|
|
|
|
min: 0,
|
|
|
|
|
max: xLength <= 5 ? 0 : xLength - 5,
|
|
|
|
|
),
|
2024-07-30 18:20:27 +08:00
|
|
|
|
),
|
|
|
|
|
),
|
2024-08-01 18:17:57 +08:00
|
|
|
|
],
|
|
|
|
|
),
|
2024-08-01 14:08:34 +08:00
|
|
|
|
),
|
|
|
|
|
),
|
2024-08-01 18:17:57 +08:00
|
|
|
|
);
|
|
|
|
|
});
|
2024-08-01 14:08:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget leftTitles(double value, TitleMeta meta) {
|
|
|
|
|
const style = TextStyle(
|
|
|
|
|
color: Color(0xff7589a2),
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
decoration: TextDecoration.none);
|
|
|
|
|
String text;
|
|
|
|
|
int intValue = (value).ceil();
|
|
|
|
|
if (intValue % 10 == 0 && intValue <= maxY) {
|
|
|
|
|
text = intValue.toString();
|
|
|
|
|
} else {
|
|
|
|
|
return Container();
|
|
|
|
|
}
|
|
|
|
|
return SideTitleWidget(
|
|
|
|
|
axisSide: meta.axisSide,
|
|
|
|
|
space: 0,
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.only(right: 20),
|
|
|
|
|
child: Text(text, style: style)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map svMap = {
|
|
|
|
|
"BEIDOU": "BSV",
|
|
|
|
|
"GLONASS": "ESV",
|
|
|
|
|
"GPS": "GSV",
|
|
|
|
|
"GALILEO": "RSV",
|
|
|
|
|
};
|
|
|
|
|
Widget bottomTitles(double index, TitleMeta meta) {
|
|
|
|
|
String text = "";
|
|
|
|
|
int intValue = (index - 1).ceil();
|
2024-08-01 18:17:57 +08:00
|
|
|
|
|
|
|
|
|
// if (signal[].isNotEmpty) {
|
|
|
|
|
// var data = svData[intValue];
|
|
|
|
|
// String? name = svMap[data.name];
|
|
|
|
|
// if (name != null) {
|
|
|
|
|
// text = "${name.substring(0, 1)}${data.sn}";
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2024-08-01 14:08:34 +08:00
|
|
|
|
|
|
|
|
|
return SideTitleWidget(
|
|
|
|
|
axisSide: meta.axisSide,
|
|
|
|
|
space: 10, //margin top
|
|
|
|
|
|
|
|
|
|
child: Text(
|
|
|
|
|
text,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Color(0xff7589a2),
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
decoration: TextDecoration.none,
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
),
|
|
|
|
|
textAlign: TextAlign.left,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final double width = 15;
|
|
|
|
|
final Color leftBarColor = const Color.fromARGB(95, 101, 98, 98);
|
|
|
|
|
final Color rightBarColor = const Color.fromRGBO(33, 150, 243, 1);
|
|
|
|
|
|
|
|
|
|
BarChartGroupData makeGroupData(int x, List<int> listy,
|
|
|
|
|
[Color color = const Color.fromRGBO(33, 150, 243, 1)]) {
|
|
|
|
|
List<BarChartRodData> list = [];
|
|
|
|
|
for (var i = 0; i < listy.length; i++) {
|
|
|
|
|
list.add(BarChartRodData(
|
|
|
|
|
toY: listy[i].toDouble(),
|
|
|
|
|
color: color.withOpacity((i + 1) * .2),
|
|
|
|
|
borderRadius: const BorderRadius.all(
|
|
|
|
|
Radius.circular(2),
|
|
|
|
|
),
|
|
|
|
|
width: width,
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
return BarChartGroupData(
|
|
|
|
|
barsSpace: 0, x: x, showingTooltipIndicators: [], barRods: list);
|
2024-07-30 18:20:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|