Skip to content

Commit

Permalink
color gradient for history reports
Browse files Browse the repository at this point in the history
  • Loading branch information
dchristl committed Oct 7, 2023
1 parent ae29f5e commit 2388d0a
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions headless_haystack/lib/history/accessory_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:headless_haystack/history/days_selection_slider.dart';
import 'package:headless_haystack/history/location_popup.dart';

import 'dart:math';

class AccessoryHistory extends StatefulWidget {
final Accessory accessory;

Expand Down Expand Up @@ -37,19 +38,44 @@ class _AccessoryHistoryState extends State<AccessoryHistory> {
_mapController = MapController();

DateTime latest = widget.accessory.latestHistoryEntry();
numberOfDays = min(latest.difference(DateTime.now()).inDays + 1, numberOfDays);
numberOfDays =
min(latest.difference(DateTime.now()).inDays + 1, numberOfDays);
WidgetsBinding.instance.addPostFrameCallback((_) {
mapReady();
});
}

@override
Widget build(BuildContext context) {
var historyEntries = widget.accessory.locationHistory;
var historyLength = historyEntries.length - 1;
List<Polyline> polylines = [];

if (historyLength > 255) {
historyLength = 255;
}
int delta = (255 ~/ historyLength).ceil();
var blue = delta;

for (int i = 0; i < historyEntries.length - 1; i++) {
var entry = historyEntries[i];
var nextEntry = historyEntries[i + 1];
List<LatLng> points = [];
points.add(entry.location);
points.add(nextEntry.location);
polylines.add(Polyline(
points: points,
strokeWidth: 4,
color: Color.fromRGBO(33, 150, blue, 1),
));
blue += min(delta.toInt(), 255);
}

// Filter for the locations after the specified cutoff date (now - number of days)
return Scaffold(
appBar: AppBar(
title: Text(
"${widget.accessory.name} (${widget.accessory.locationHistory.length} history reports)"),
title:
Text("${widget.accessory.name} ($historyLength history reports)"),
),
body: SafeArea(
child: Column(
Expand Down Expand Up @@ -116,15 +142,7 @@ class _AccessoryHistoryState extends State<AccessoryHistory> {
subdomains: const ['a', 'b', 'c']),
// The line connecting the locations chronologically
PolylineLayer(
polylines: [
Polyline(
points: widget.accessory.locationHistory
.map((entry) => entry.location)
.toList(),
strokeWidth: 4,
color: Theme.of(context).colorScheme.primary,
),
],
polylines: polylines,
),
// The markers for the historic locations
MarkerLayer(
Expand Down

0 comments on commit 2388d0a

Please sign in to comment.