diff --git a/lib/entity_class/entity.class.dart b/lib/entity_class/entity.class.dart index a01c49d..d6c7efd 100644 --- a/lib/entity_class/entity.class.dart +++ b/lib/entity_class/entity.class.dart @@ -1,41 +1,5 @@ part of '../main.dart'; -class EntityColors { - static const _stateColors = { - "on": Colors.amber, - "auto": Colors.amber, - "idle": Colors.amber, - "playing": Colors.amber, - "above_horizon": Colors.amber, - "home": Colors.amber, - "open": Colors.amber, - "off": Color.fromRGBO(68, 115, 158, 1.0), - "closed": Color.fromRGBO(68, 115, 158, 1.0), - "default": Color.fromRGBO(68, 115, 158, 1.0), - "heat": Colors.redAccent, - "cool": Colors.lightBlue, - "closing": Colors.cyan, - "opening": Colors.purple, - "unavailable": Colors.black26, - "unknown": Colors.black26, - }; - - static Color stateColor(String state) { - return _stateColors[state] ?? _stateColors["default"]; - } - - static charts.Color historyStateColor(String state) { - Color c = stateColor(state); - return charts.Color( - r: c.red, - g: c.green, - b: c.blue, - a: c.alpha - ); - } - -} - class Entity { static const badgeColors = { diff --git a/lib/entity_widgets/entity_colors.class.dart b/lib/entity_widgets/entity_colors.class.dart new file mode 100644 index 0000000..8186905 --- /dev/null +++ b/lib/entity_widgets/entity_colors.class.dart @@ -0,0 +1,56 @@ +part of '../main.dart'; + +class EntityColors { + static const _stateColors = { + "on": Colors.amber, + "auto": Colors.amber, + "idle": Colors.amber, + "playing": Colors.amber, + "above_horizon": Colors.amber, + "home": Colors.amber, + "open": Colors.amber, + "off": Color.fromRGBO(68, 115, 158, 1.0), + "closed": Color.fromRGBO(68, 115, 158, 1.0), + "below_horizon": Color.fromRGBO(68, 115, 158, 1.0), + "default": Color.fromRGBO(68, 115, 158, 1.0), + "heat": Colors.redAccent, + "cool": Colors.lightBlue, + "closing": Colors.cyan, + "opening": Colors.purple, + "unavailable": Colors.black26, + "unknown": Colors.black26, + }; + + static Color stateColor(String state) { + return _stateColors[state] ?? _stateColors["default"]; + } + + static charts.Color chartHistoryStateColor(String state, int id) { + Color c = _stateColors[state]; + if (c != null) { + return charts.Color( + r: c.red, + g: c.green, + b: c.blue, + a: c.alpha + ); + } else { + return charts.MaterialPalette.getOrderedPalettes(id+1)[id].shadeDefault; + } + } + + static Color historyStateColor(String state, int id) { + Color c = _stateColors[state]; + if (c != null) { + return c; + } else { + if (id > -1) { + charts.Color c1 = charts.MaterialPalette.getOrderedPalettes(id + 1)[id].shadeDefault; + return Color.fromARGB(c1.a, c1.r, c1.g, c1.b); + } else { + return _stateColors["default"]; + } + } + } + +} \ No newline at end of file diff --git a/lib/entity_widgets/history_chart/entity_history.dart b/lib/entity_widgets/history_chart/entity_history.dart index 102ccf7..face272 100644 --- a/lib/entity_widgets/history_chart/entity_history.dart +++ b/lib/entity_widgets/history_chart/entity_history.dart @@ -22,7 +22,6 @@ class _EntityHistoryWidgetState extends State { List _history; bool _needToUpdateHistory; - int _selectedId = -1; @override void initState() { @@ -66,7 +65,7 @@ class _EntityHistoryWidgetState extends State { ); } else if (_history.isEmpty) { children.add( - Text("No history for last 24h") + Text("No history") ); } else { children.add( diff --git a/lib/entity_widgets/history_chart/numeric_state_history_chart.dart b/lib/entity_widgets/history_chart/numeric_state_history_chart.dart index ef30478..ea630a4 100644 --- a/lib/entity_widgets/history_chart/numeric_state_history_chart.dart +++ b/lib/entity_widgets/history_chart/numeric_state_history_chart.dart @@ -36,6 +36,7 @@ class _NumericStateHistoryChartWidgetState extends State _selectPrev(), onNextTap: () => _selectNext(), + colorIndex: -1, ), SizedBox( height: 150.0, @@ -79,18 +80,21 @@ class _NumericStateHistoryChartWidgetState extends State( id: 'State', - colorFn: (NumericEntityStateHistoryMoment historyMoment, __) => EntityColors.historyStateColor("unavailable"), + colorFn: (NumericEntityStateHistoryMoment historyMoment, __) => EntityColors.chartHistoryStateColor("unavailable", historyMoment.id), domainFn: (NumericEntityStateHistoryMoment historyMoment, _) => historyMoment.time, measureFn: (NumericEntityStateHistoryMoment historyMoment, _) => historyMoment.value, data: data, ), new charts.Series( id: 'State', - radiusPxFn: (NumericEntityStateHistoryMoment historyMoment, __) => (historyMoment.id == _selectedId) ? 4.0 : 2.0, - colorFn: (NumericEntityStateHistoryMoment historyMoment, __) => (historyMoment.id == _selectedId) ? EntityColors.historyStateColor("on") : EntityColors.historyStateColor("off"), + radiusPxFn: (NumericEntityStateHistoryMoment historyMoment, __) => (historyMoment.id == _selectedId) ? 5.0 : 2.0, + colorFn: (NumericEntityStateHistoryMoment historyMoment, __) => EntityColors.chartHistoryStateColor("off", historyMoment.id), domainFn: (NumericEntityStateHistoryMoment historyMoment, _) => historyMoment.time, measureFn: (NumericEntityStateHistoryMoment historyMoment, _) => historyMoment.value, data: data, diff --git a/lib/entity_widgets/history_chart/simple_state_history_chart.dart b/lib/entity_widgets/history_chart/simple_state_history_chart.dart index 2ea8c6c..6cc2286 100644 --- a/lib/entity_widgets/history_chart/simple_state_history_chart.dart +++ b/lib/entity_widgets/history_chart/simple_state_history_chart.dart @@ -39,6 +39,7 @@ class _SimpleStateHistoryChartWidgetState extends State _selectPrev(), onNextTap: () => _selectNext(), + colorIndex: _selectedId, ), SizedBox( height: 70.0, @@ -79,11 +80,14 @@ class _SimpleStateHistoryChartWidgetState extends State( id: 'State', strokeWidthPxFn: (SimpleEntityStateHistoryMoment historyMoment, __) => (historyMoment.id == _selectedId) ? 70.0 : 40.0, - colorFn: (SimpleEntityStateHistoryMoment historyMoment, __) => EntityColors.historyStateColor(historyMoment.state), + colorFn: (SimpleEntityStateHistoryMoment historyMoment, __) => EntityColors.chartHistoryStateColor(historyMoment.state, historyMoment.id), domainFn: (SimpleEntityStateHistoryMoment historyMoment, _) => historyMoment.startTime, measureFn: (SimpleEntityStateHistoryMoment historyMoment, _) => 0, data: data, @@ -131,8 +135,9 @@ class HistoryControlWidget extends StatelessWidget { final DateTime selectedTimeStart; final DateTime selectedTimeEnd; final String selectedState; + final int colorIndex; - const HistoryControlWidget({Key key, this.onPrevTap, this.onNextTap, this.selectedTimeStart, this.selectedTimeEnd, this.selectedState}) : super(key: key); + const HistoryControlWidget({Key key, this.onPrevTap, this.onNextTap, this.selectedTimeStart, this.selectedTimeEnd, this.selectedState, @ required this.colorIndex}) : super(key: key); @override Widget build(BuildContext context) { @@ -156,7 +161,7 @@ class HistoryControlWidget extends StatelessWidget { textAlign: TextAlign.right, style: TextStyle( fontWeight: FontWeight.bold, - color: EntityColors.stateColor(selectedState), + color: EntityColors.historyStateColor(selectedState, colorIndex), fontSize: 22.0 ), ), @@ -173,7 +178,7 @@ class HistoryControlWidget extends StatelessWidget { ); } else { - return Container(height: 32.0); + return Container(height: 48.0); } } @@ -187,11 +192,9 @@ class HistoryControlWidget extends StatelessWidget { Text("${formatDate(selectedTimeEnd, [M, ' ', d, ', ', HH, ':', nn, ':', ss])}", textAlign: TextAlign.left,) ); } - return Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: children, - ), + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: children, ); } diff --git a/lib/main.dart b/lib/main.dart index c4b24e9..9a8f5b2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -14,6 +14,7 @@ import 'package:date_format/date_format.dart'; import 'package:http/http.dart' as http; import 'package:flutter_colorpicker/material_picker.dart'; import 'package:charts_flutter/flutter.dart' as charts; +import 'dart:math' as math; part 'entity_class/entity.class.dart'; part 'entity_class/switch_entity.class.dart'; @@ -35,6 +36,7 @@ part 'entity_widgets/entity_name.dart'; part 'entity_widgets/last_updated.dart'; part 'entity_widgets/mode_swicth.dart'; part 'entity_widgets/mode_selector.dart'; +part 'entity_widgets/entity_colors.class.dart'; part 'entity_widgets/entity_page_container.dart'; part 'entity_widgets/history_chart/entity_history.dart'; part 'entity_widgets/history_chart/simple_state_history_chart.dart';