|
|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/charts/app_time_series_chart.dart';
|
|
|
|
|
import 'package:fl_chart/fl_chart.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
@ -10,15 +11,26 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
final int indexes;
|
|
|
|
|
final double horizontalInterval;
|
|
|
|
|
|
|
|
|
|
ShowChart({this.title, this.timeSeries, this.indexes, this.horizontalInterval = 20.0});
|
|
|
|
|
ShowChart({this.title, this.timeSeries, this.indexes, this.horizontalInterval = 8.0});
|
|
|
|
|
|
|
|
|
|
List<int> xAxixs = List();
|
|
|
|
|
List<double> yAxixs = List();
|
|
|
|
|
|
|
|
|
|
double minY = 0;
|
|
|
|
|
double maxY = 0;
|
|
|
|
|
double intialY = 0;
|
|
|
|
|
double lastY = 0;
|
|
|
|
|
|
|
|
|
|
double minX = 0;
|
|
|
|
|
double maxX = 0;
|
|
|
|
|
double increasingY = 0;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
getXaxix();
|
|
|
|
|
getYaxix();
|
|
|
|
|
getInitialY();
|
|
|
|
|
calculateMaxAndMin();
|
|
|
|
|
return AspectRatio(
|
|
|
|
|
aspectRatio: 1.0,
|
|
|
|
|
child: Container(
|
|
|
|
|
@ -31,17 +43,20 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
const SizedBox(
|
|
|
|
|
height: 4,
|
|
|
|
|
),
|
|
|
|
|
Text(
|
|
|
|
|
title,
|
|
|
|
|
style: TextStyle(color: Colors.black, fontSize: 16, letterSpacing: -0.64, fontWeight: FontWeight.w600),
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 10,
|
|
|
|
|
Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Text(
|
|
|
|
|
title,
|
|
|
|
|
style: TextStyle(color: Colors.black, fontSize: 16, letterSpacing: -0.64, fontWeight: FontWeight.w600),
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
mHeight(10),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.only(right: 18.0, left: 16.0),
|
|
|
|
|
@ -72,91 +87,14 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getYaxix() {
|
|
|
|
|
int indexess = (timeSeries.length * 0.30).toInt();
|
|
|
|
|
for (int index = 0; index < timeSeries.length; index++) {
|
|
|
|
|
int mIndex = indexess * index;
|
|
|
|
|
int mIndex = indexes * index;
|
|
|
|
|
if (mIndex < timeSeries.length) {
|
|
|
|
|
yAxixs.add(timeSeries[mIndex].sales);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LineChartData sampleData1(context) {
|
|
|
|
|
// return LineChartData(
|
|
|
|
|
// lineTouchData: LineTouchData(
|
|
|
|
|
// touchTooltipData: LineTouchTooltipData(
|
|
|
|
|
// tooltipBgColor: Colors.white,
|
|
|
|
|
// ),
|
|
|
|
|
// touchCallback: (LineTouchResponse touchResponse) {},
|
|
|
|
|
// handleBuiltInTouches: true,
|
|
|
|
|
// ),
|
|
|
|
|
// gridData: FlGridData(show: true, drawVerticalLine: true, drawHorizontalLine: true, horizontalInterval: 14, verticalInterval: 14),
|
|
|
|
|
// titlesData: FlTitlesData(
|
|
|
|
|
// bottomTitles: SideTitles(
|
|
|
|
|
// showTitles: true,
|
|
|
|
|
// getTextStyles: (value) => const TextStyle(
|
|
|
|
|
// color: Colors.black,
|
|
|
|
|
// fontSize: 10,
|
|
|
|
|
// ),
|
|
|
|
|
// // rotateAngle: 90,
|
|
|
|
|
// //rotateAngle:-65,
|
|
|
|
|
// margin: 22,
|
|
|
|
|
// getTitles: (value) {
|
|
|
|
|
// if (timeSeries.length < 15) {
|
|
|
|
|
// if (timeSeries.length > value.toInt()) {
|
|
|
|
|
// return '${timeSeries[value.toInt()].time.month}/ ${timeSeries[value.toInt()].time.year}';
|
|
|
|
|
// } else
|
|
|
|
|
// return '';
|
|
|
|
|
// } else {
|
|
|
|
|
// if (value.toInt() == 0) return '${timeSeries[value.toInt()].time.month}/ ${timeSeries[value.toInt()].time.year}';
|
|
|
|
|
// if (value.toInt() == timeSeries.length - 1) return '${timeSeries[value.toInt()].time.month}/ ${timeSeries[value.toInt()].time.year}';
|
|
|
|
|
// if (xAxixs.contains(value.toInt())) {
|
|
|
|
|
// return '${timeSeries[value.toInt()].time.month}/ ${timeSeries[value.toInt()].time.year}';
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// return '';
|
|
|
|
|
// },
|
|
|
|
|
// ),
|
|
|
|
|
// leftTitles: SideTitles(
|
|
|
|
|
// showTitles: true,
|
|
|
|
|
// // interval:getMaxY() - getMinY() <=500?50:getMaxY() - getMinY() <=1000?100:200,
|
|
|
|
|
// interval: 3,
|
|
|
|
|
// getTextStyles: (value) => const TextStyle(
|
|
|
|
|
// color: Colors.black,
|
|
|
|
|
// fontWeight: FontWeight.bold,
|
|
|
|
|
// fontSize: 10,
|
|
|
|
|
// ),
|
|
|
|
|
//
|
|
|
|
|
// margin: 12,
|
|
|
|
|
// ),
|
|
|
|
|
// ),
|
|
|
|
|
// borderData: FlBorderData(
|
|
|
|
|
// show: true,
|
|
|
|
|
// border: const Border(
|
|
|
|
|
// bottom: BorderSide(
|
|
|
|
|
// color: Colors.black,
|
|
|
|
|
// width: 0.5,
|
|
|
|
|
// ),
|
|
|
|
|
// left: BorderSide(
|
|
|
|
|
// color: Colors.black,
|
|
|
|
|
// ),
|
|
|
|
|
// right: BorderSide(
|
|
|
|
|
// color: Colors.black,
|
|
|
|
|
// ),
|
|
|
|
|
// top: BorderSide(
|
|
|
|
|
// color: Colors.transparent,
|
|
|
|
|
// ),
|
|
|
|
|
// ),
|
|
|
|
|
// ),
|
|
|
|
|
// minX: 0,
|
|
|
|
|
// maxX: (timeSeries.length - 1).toDouble(),
|
|
|
|
|
// maxY: getMaxY() + 0.3,
|
|
|
|
|
// minY: 0,
|
|
|
|
|
// //getMinY(),
|
|
|
|
|
// lineBarsData: getData(context),
|
|
|
|
|
// );
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
LineChartData sampleData1(context) {
|
|
|
|
|
return LineChartData(
|
|
|
|
|
lineTouchData: LineTouchData(
|
|
|
|
|
@ -166,7 +104,7 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
touchCallback: (LineTouchResponse touchResponse) {},
|
|
|
|
|
handleBuiltInTouches: true,
|
|
|
|
|
),
|
|
|
|
|
gridData: FlGridData(show: true, drawVerticalLine: true, drawHorizontalLine: true, horizontalInterval: 14, verticalInterval: 14),
|
|
|
|
|
gridData: FlGridData(show: true, drawVerticalLine: true, drawHorizontalLine: true, horizontalInterval: horizontalInterval, verticalInterval: horizontalInterval),
|
|
|
|
|
titlesData: FlTitlesData(
|
|
|
|
|
bottomTitles: SideTitles(
|
|
|
|
|
showTitles: true,
|
|
|
|
|
@ -200,15 +138,6 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
),
|
|
|
|
|
interval: 3.0,
|
|
|
|
|
// interval: getMaxY() - getMinY() <= 500
|
|
|
|
|
// ? getMaxY() - getMinY() <= 50
|
|
|
|
|
// ? 10
|
|
|
|
|
// : 10
|
|
|
|
|
// : getMaxY() - getMinY() <= 1000
|
|
|
|
|
// ? 100
|
|
|
|
|
// : getMaxY() - getMinY() >= 10000
|
|
|
|
|
// ? 5000
|
|
|
|
|
// : 200,
|
|
|
|
|
margin: 12,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
@ -230,32 +159,73 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
minX: 0,
|
|
|
|
|
maxX: (timeSeries.length - 1).toDouble(),
|
|
|
|
|
maxY: getMaxY() + 0.3,
|
|
|
|
|
minY: 0,
|
|
|
|
|
//getMinY(),
|
|
|
|
|
minX: minX,
|
|
|
|
|
maxX: maxX,
|
|
|
|
|
maxY: lastY + 1,
|
|
|
|
|
minY: intialY - 0.5,
|
|
|
|
|
lineBarsData: getData(context),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
calculateMaxAndMin() {
|
|
|
|
|
getMaxY();
|
|
|
|
|
getMaxX();
|
|
|
|
|
getMin();
|
|
|
|
|
getMinY();
|
|
|
|
|
increasingY = ((maxY - minY) / timeSeries.length - 1) * 15;
|
|
|
|
|
maxY += increasingY.abs();
|
|
|
|
|
minY -= increasingY.abs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double getMaxY() {
|
|
|
|
|
double max = 0;
|
|
|
|
|
maxY = 0;
|
|
|
|
|
timeSeries.forEach((element) {
|
|
|
|
|
double resultValueDouble = element.sales;
|
|
|
|
|
if (resultValueDouble > maxY) {
|
|
|
|
|
lastY = resultValueDouble;
|
|
|
|
|
maxY = resultValueDouble;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
print("maxY " + lastY.toString());
|
|
|
|
|
return maxY.roundToDouble();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double getInitialY() {
|
|
|
|
|
try {
|
|
|
|
|
intialY = timeSeries.first.sales;
|
|
|
|
|
timeSeries.forEach((element) {
|
|
|
|
|
double resultValueDouble = element.sales;
|
|
|
|
|
if (resultValueDouble < intialY) intialY = resultValueDouble;
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
intialY = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print("minY " + intialY.toString());
|
|
|
|
|
return intialY.roundToDouble();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getMaxX() {
|
|
|
|
|
maxX = (timeSeries.length - 1).toDouble();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double getMin() {
|
|
|
|
|
minX = 0;
|
|
|
|
|
timeSeries.forEach((element) {
|
|
|
|
|
double resultValueDouble = element.sales;
|
|
|
|
|
if (resultValueDouble > max) max = resultValueDouble;
|
|
|
|
|
if (resultValueDouble < minX) minX = resultValueDouble;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return max.roundToDouble();
|
|
|
|
|
return minX.roundToDouble();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double getMinY() {
|
|
|
|
|
double min = timeSeries.isEmpty ? 0 : timeSeries.first.sales;
|
|
|
|
|
minY = 0;
|
|
|
|
|
timeSeries.forEach((element) {
|
|
|
|
|
double resultValueDouble = element.sales;
|
|
|
|
|
if (resultValueDouble < min) min = resultValueDouble;
|
|
|
|
|
if (resultValueDouble < minY) minY = resultValueDouble;
|
|
|
|
|
});
|
|
|
|
|
int value = min.toInt();
|
|
|
|
|
int value = minY.toInt();
|
|
|
|
|
|
|
|
|
|
return value.toDouble();
|
|
|
|
|
}
|
|
|
|
|
|