forked from eatvio/eatvio_app
146 lines
4.7 KiB
Dart
146 lines
4.7 KiB
Dart
/*import 'package:flutter/material.dart';
|
|
import 'package:fl_chart/fl_chart.dart';
|
|
|
|
buildChart(
|
|
BuildContext context, List<double> chartPoints, List<String>? dates) {
|
|
// Определение осей графика
|
|
List<FlSpot> spots = [];
|
|
for (int i = 0; i < 4; i++) {
|
|
spots.add(
|
|
FlSpot((i * 10 / 10) + 1, chartPoints[i]),
|
|
);
|
|
}
|
|
|
|
Widget bottomTitleWidgets(
|
|
double value, TitleMeta meta, double chartWidth, List<String>? dates) {
|
|
if (value % 1 != 0) {
|
|
return Container();
|
|
}
|
|
final style = TextStyle(
|
|
color: Colors.blue,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: min(13, 13 * chartWidth / 300),
|
|
);
|
|
int index = value.toInt();
|
|
if (index >= 0 && index < dates!.length) {
|
|
// Проверка на допустимый индекс в массиве dates
|
|
String formattedDate =
|
|
DateFormat('dd.MM').format(DateTime.parse(dates[index]));
|
|
return SideTitleWidget(
|
|
axisSide: meta.axisSide,
|
|
space: 16,
|
|
child: Text(formattedDate, style: style),
|
|
);
|
|
} else {
|
|
return Container();
|
|
}
|
|
}
|
|
|
|
Widget leftTitleWidgets(double value, TitleMeta meta, double chartWidth) {
|
|
final style = TextStyle(
|
|
color: Colors.blue,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: min(18, 18 * chartWidth / 300),
|
|
);
|
|
return SideTitleWidget(
|
|
axisSide: meta.axisSide,
|
|
space: 16,
|
|
child: Text(meta.formattedValue, style: style),
|
|
);
|
|
}
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 12,
|
|
right: 20,
|
|
),
|
|
child: AspectRatio(
|
|
aspectRatio: 1,
|
|
child: LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
return LineChart(
|
|
LineChartData(
|
|
lineTouchData: LineTouchData(
|
|
touchTooltipData: LineTouchTooltipData(
|
|
maxContentWidth: 100,
|
|
tooltipBgColor: Colors.black,
|
|
getTooltipItems: mapSpots(),
|
|
),
|
|
handleBuiltInTouches: true,
|
|
getTouchLineStart: (data, index) => 0,
|
|
),
|
|
lineBarsData: [
|
|
LineChartBarData(
|
|
color: Colors.pink,
|
|
spots: spots,
|
|
isCurved: true,
|
|
isStrokeCapRound: true,
|
|
barWidth: 3,
|
|
belowBarData: BarAreaData(
|
|
show: false,
|
|
),
|
|
dotData: const FlDotData(show: false),
|
|
),
|
|
],
|
|
minY: chartPoints.reduce(
|
|
(value, element) => value < element ? value : element),
|
|
maxY: chartPoints.reduce(
|
|
(value, element) => value > element ? value : element),
|
|
minX: 1,
|
|
maxX: 4,
|
|
titlesData: FlTitlesData(
|
|
leftTitles: AxisTitles(
|
|
sideTitles: SideTitles(
|
|
showTitles: true,
|
|
getTitlesWidget: (value, meta) =>
|
|
leftTitleWidgets(value, meta, constraints.maxWidth),
|
|
reservedSize: 56,
|
|
),
|
|
drawBelowEverything: true,
|
|
),
|
|
rightTitles: const AxisTitles(
|
|
sideTitles: SideTitles(showTitles: false),
|
|
),
|
|
bottomTitles: AxisTitles(
|
|
sideTitles: SideTitles(
|
|
showTitles: true,
|
|
getTitlesWidget: (value, meta) => bottomTitleWidgets(
|
|
value, meta, constraints.maxWidth, dates),
|
|
reservedSize: 36,
|
|
interval: 1,
|
|
),
|
|
drawBelowEverything: true,
|
|
),
|
|
topTitles: const AxisTitles(
|
|
sideTitles: SideTitles(showTitles: false),
|
|
),
|
|
),
|
|
gridData: FlGridData(
|
|
show: true,
|
|
drawHorizontalLine: true,
|
|
drawVerticalLine: true,
|
|
horizontalInterval: 1.5,
|
|
verticalInterval: 5,
|
|
checkToShowHorizontalLine: valuteToInt(),
|
|
getDrawingHorizontalLine: (_) => FlLine(
|
|
color: Colors.blue.withOpacity(1),
|
|
dashArray: [8, 2],
|
|
strokeWidth: 0.8,
|
|
),
|
|
getDrawingVerticalLine: (_) => FlLine(
|
|
color: Colors.blue.withOpacity(1),
|
|
dashArray: [8, 2],
|
|
strokeWidth: 0.8,
|
|
),
|
|
checkToShowVerticalLine: valuteToInt(),
|
|
),
|
|
borderData: FlBorderData(show: false),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
*/
|