SP-1723-FE-Integrate-Charts-with-API-s-for-AQI-sensor.

This commit is contained in:
Faris Armoush
2025-06-16 11:26:27 +03:00
parent 5b3152e833
commit 1da0cdad4b
2 changed files with 16 additions and 16 deletions

View File

@ -34,8 +34,8 @@ class OccupancyHeatMapGradient extends StatelessWidget {
width: 1,
),
gradient: LinearGradient(
begin: AlignmentDirectional.centerEnd,
end: AlignmentDirectional.centerStart,
begin: AlignmentDirectional.centerStart,
end: AlignmentDirectional.centerEnd,
colors: _heatMapColors(),
),
),

View File

@ -28,11 +28,11 @@ class OccupancyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final Paint fillPaint = Paint();
final Paint borderPaint = Paint()
final fillPaint = Paint();
final borderPaint = Paint()
..color = ColorsManager.grayBorder.withValues(alpha: 0.4)
..style = PaintingStyle.stroke;
final Paint hoveredBorderPaint = Paint()
final hoveredBorderPaint = Paint()
..color = Colors.black
..style = PaintingStyle.stroke
..strokeWidth = 1.5;
@ -48,7 +48,6 @@ class OccupancyPainter extends CustomPainter {
final rect = Rect.fromLTWH(x, y, cellSize, cellSize);
canvas.drawRect(rect, fillPaint);
// Highlight the hovered item
if (hoveredItem != null && hoveredItem!.index == item.index) {
canvas.drawRect(rect, hoveredBorderPaint);
} else {
@ -73,16 +72,16 @@ class OccupancyPainter extends CustomPainter {
}
void _drawDashedLine(Canvas canvas, Offset start, Offset end, Paint paint) {
const double dashWidth = 2.0;
const double dashSpace = 4.0;
final double totalLength = (end - start).distance;
final Offset direction = (end - start) / (end - start).distance;
const dashWidth = 2.0;
const dashSpace = 4.0;
final totalLength = (end - start).distance;
final direction = (end - start) / (end - start).distance;
double currentLength = 0.0;
var currentLength = 0.0;
while (currentLength < totalLength) {
final Offset dashStart = start + direction * currentLength;
final double nextLength = currentLength + dashWidth;
final Offset dashEnd =
final dashStart = start + direction * currentLength;
final nextLength = currentLength + dashWidth;
final dashEnd =
start + direction * (nextLength < totalLength ? nextLength : totalLength);
canvas.drawLine(dashStart, dashEnd, paint);
currentLength = nextLength + dashSpace;
@ -91,8 +90,9 @@ class OccupancyPainter extends CustomPainter {
Color _getColor(int value) {
if (maxValue == 0) return ColorsManager.vividBlue.withValues(alpha: 0);
final opacity = value.clamp(0, maxValue) / maxValue;
return ColorsManager.vividBlue.withValues(alpha: opacity);
final clampedValue = 0.075 + (1 * value.clamp(0, maxValue) / maxValue);
final opacity = value == 0 ? 0 : clampedValue;
return ColorsManager.vividBlue.withValues(alpha: opacity.toDouble());
}
@override