WIP #120 Random color for states
This commit is contained in:
@ -22,7 +22,6 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> {
|
||||
|
||||
List _history;
|
||||
bool _needToUpdateHistory;
|
||||
int _selectedId = -1;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -66,7 +65,7 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> {
|
||||
);
|
||||
} else if (_history.isEmpty) {
|
||||
children.add(
|
||||
Text("No history for last 24h")
|
||||
Text("No history")
|
||||
);
|
||||
} else {
|
||||
children.add(
|
||||
|
@ -36,6 +36,7 @@ class _NumericStateHistoryChartWidgetState extends State<NumericStateHistoryChar
|
||||
selectedState: "$selectedState",
|
||||
onPrevTap: () => _selectPrev(),
|
||||
onNextTap: () => _selectNext(),
|
||||
colorIndex: -1,
|
||||
),
|
||||
SizedBox(
|
||||
height: 150.0,
|
||||
@ -79,18 +80,21 @@ class _NumericStateHistoryChartWidgetState extends State<NumericStateHistoryChar
|
||||
data.add(NumericEntityStateHistoryMoment(double.tryParse(stateData["state"]), time, i));
|
||||
}
|
||||
data.add(NumericEntityStateHistoryMoment(data.last.value, now, widget.rawHistory.length));
|
||||
if (_selectedId == -1) {
|
||||
_selectedId = 0;
|
||||
}
|
||||
return [
|
||||
new charts.Series<NumericEntityStateHistoryMoment, DateTime>(
|
||||
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<NumericEntityStateHistoryMoment, DateTime>(
|
||||
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,
|
||||
|
@ -39,6 +39,7 @@ class _SimpleStateHistoryChartWidgetState extends State<SimpleStateHistoryChartW
|
||||
selectedState: selectedState,
|
||||
onPrevTap: () => _selectPrev(),
|
||||
onNextTap: () => _selectNext(),
|
||||
colorIndex: _selectedId,
|
||||
),
|
||||
SizedBox(
|
||||
height: 70.0,
|
||||
@ -79,11 +80,14 @@ class _SimpleStateHistoryChartWidgetState extends State<SimpleStateHistoryChartW
|
||||
data.add(SimpleEntityStateHistoryMoment(stateData["state"], startTime, endTime, i));
|
||||
}
|
||||
data.add(SimpleEntityStateHistoryMoment(data.last.state, now, null, widget.rawHistory.length));
|
||||
if (_selectedId == -1) {
|
||||
_selectedId = 0;
|
||||
}
|
||||
return [
|
||||
new charts.Series<SimpleEntityStateHistoryMoment, DateTime>(
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user