Resolves #120
This commit is contained in:
parent
efab8b60b1
commit
3b99f4feeb
@ -17,7 +17,7 @@ class CombinedHistoryChartWidget extends StatefulWidget {
|
|||||||
class _CombinedHistoryChartWidgetState extends State<CombinedHistoryChartWidget> {
|
class _CombinedHistoryChartWidgetState extends State<CombinedHistoryChartWidget> {
|
||||||
|
|
||||||
int _selectedId = -1;
|
int _selectedId = -1;
|
||||||
List<charts.Series<CombinedEntityStateHistoryMoment, DateTime>> _parsedHistory;
|
List<charts.Series<EntityHistoryMoment, DateTime>> _parsedHistory;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -46,7 +46,7 @@ class _CombinedHistoryChartWidgetState extends State<CombinedHistoryChartWidget>
|
|||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
CombinedHistoryControlWidget(
|
HistoryControlWidget(
|
||||||
selectedTimeStart: selectedTime,
|
selectedTimeStart: selectedTime,
|
||||||
selectedStates: selectedStates,
|
selectedStates: selectedStates,
|
||||||
onPrevTap: () => _selectPrev(),
|
onPrevTap: () => _selectPrev(),
|
||||||
@ -93,13 +93,13 @@ class _CombinedHistoryChartWidgetState extends State<CombinedHistoryChartWidget>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<charts.Series<CombinedEntityStateHistoryMoment, DateTime>> _parseHistory() {
|
List<charts.Series<EntityHistoryMoment, DateTime>> _parseHistory() {
|
||||||
TheLogger.debug(" parsing history...");
|
TheLogger.debug(" parsing history...");
|
||||||
Map<String, List<CombinedEntityStateHistoryMoment>> numericDataLists = {};
|
Map<String, List<EntityHistoryMoment>> numericDataLists = {};
|
||||||
int colorIdCounter = 0;
|
int colorIdCounter = 0;
|
||||||
widget.config.numericAttributesToShow.forEach((String attrName) {
|
widget.config.numericAttributesToShow.forEach((String attrName) {
|
||||||
TheLogger.debug(" parsing attribute $attrName");
|
TheLogger.debug(" parsing attribute $attrName");
|
||||||
List<CombinedEntityStateHistoryMoment> data = [];
|
List<EntityHistoryMoment> data = [];
|
||||||
DateTime now = DateTime.now();
|
DateTime now = DateTime.now();
|
||||||
for (var i = 0; i < widget.rawHistory.length; i++) {
|
for (var i = 0; i < widget.rawHistory.length; i++) {
|
||||||
var stateData = widget.rawHistory[i];
|
var stateData = widget.rawHistory[i];
|
||||||
@ -121,9 +121,28 @@ class _CombinedHistoryChartWidgetState extends State<CombinedHistoryChartWidget>
|
|||||||
hiddenLine = hiddenDot;
|
hiddenLine = hiddenDot;
|
||||||
endTime = now;
|
endTime = now;
|
||||||
}
|
}
|
||||||
data.add(CombinedEntityStateHistoryMoment(value, previousValue, hiddenDot, hiddenLine, stateData["state"], startTime, endTime, i, colorIdCounter));
|
data.add(EntityHistoryMoment(
|
||||||
|
value: value,
|
||||||
|
previousValue: previousValue,
|
||||||
|
hiddenDot: hiddenDot,
|
||||||
|
hiddenLine: hiddenLine,
|
||||||
|
state: stateData["state"],
|
||||||
|
startTime: startTime,
|
||||||
|
endTime: endTime,
|
||||||
|
id: i,
|
||||||
|
colorId: colorIdCounter
|
||||||
|
));
|
||||||
}
|
}
|
||||||
data.add(CombinedEntityStateHistoryMoment(data.last.value, data.last.previousValue, data.last.hiddenDot, data.last.hiddenLine, data.last.state, now, null, widget.rawHistory.length, colorIdCounter));
|
data.add(EntityHistoryMoment(
|
||||||
|
value: data.last.value,
|
||||||
|
previousValue: data.last.previousValue,
|
||||||
|
hiddenDot: data.last.hiddenDot,
|
||||||
|
hiddenLine: data.last.hiddenLine,
|
||||||
|
state: data.last.state,
|
||||||
|
startTime: now,
|
||||||
|
id: widget.rawHistory.length,
|
||||||
|
colorId: colorIdCounter
|
||||||
|
));
|
||||||
numericDataLists.addAll({attrName: data});
|
numericDataLists.addAll({attrName: data});
|
||||||
colorIdCounter += 1;
|
colorIdCounter += 1;
|
||||||
});
|
});
|
||||||
@ -131,14 +150,14 @@ class _CombinedHistoryChartWidgetState extends State<CombinedHistoryChartWidget>
|
|||||||
if ((_selectedId == -1) && (numericDataLists.isNotEmpty)) {
|
if ((_selectedId == -1) && (numericDataLists.isNotEmpty)) {
|
||||||
_selectedId = 0;
|
_selectedId = 0;
|
||||||
}
|
}
|
||||||
List<charts.Series<CombinedEntityStateHistoryMoment, DateTime>> result = [];
|
List<charts.Series<EntityHistoryMoment, DateTime>> result = [];
|
||||||
numericDataLists.forEach((attrName, dataList) {
|
numericDataLists.forEach((attrName, dataList) {
|
||||||
TheLogger.debug(" adding ${dataList.length} data values");
|
TheLogger.debug(" adding ${dataList.length} data values");
|
||||||
result.add(
|
result.add(
|
||||||
new charts.Series<CombinedEntityStateHistoryMoment, DateTime>(
|
new charts.Series<EntityHistoryMoment, DateTime>(
|
||||||
id: "value",
|
id: "value",
|
||||||
colorFn: (CombinedEntityStateHistoryMoment historyMoment, __) => EntityColors.chartHistoryStateColor("_", historyMoment.colorId),
|
colorFn: (EntityHistoryMoment historyMoment, __) => EntityColors.chartHistoryStateColor("_", historyMoment.colorId),
|
||||||
radiusPxFn: (CombinedEntityStateHistoryMoment historyMoment, __) {
|
radiusPxFn: (EntityHistoryMoment historyMoment, __) {
|
||||||
if (historyMoment.hiddenDot) {
|
if (historyMoment.hiddenDot) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
} else if (historyMoment.id == _selectedId) {
|
} else if (historyMoment.id == _selectedId) {
|
||||||
@ -147,9 +166,9 @@ class _CombinedHistoryChartWidgetState extends State<CombinedHistoryChartWidget>
|
|||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
strokeWidthPxFn: (CombinedEntityStateHistoryMoment historyMoment, __) => historyMoment.hiddenLine ? 0.0 : 2.0,
|
strokeWidthPxFn: (EntityHistoryMoment historyMoment, __) => historyMoment.hiddenLine ? 0.0 : 2.0,
|
||||||
domainFn: (CombinedEntityStateHistoryMoment historyMoment, _) => historyMoment.startTime,
|
domainFn: (EntityHistoryMoment historyMoment, _) => historyMoment.startTime,
|
||||||
measureFn: (CombinedEntityStateHistoryMoment historyMoment, _) => historyMoment.value ?? historyMoment.previousValue,
|
measureFn: (EntityHistoryMoment historyMoment, _) => historyMoment.value ?? historyMoment.previousValue,
|
||||||
data: dataList,
|
data: dataList,
|
||||||
/*domainLowerBoundFn: (CombinedEntityStateHistoryMoment historyMoment, _) => historyMoment.time.subtract(Duration(hours: 1)),
|
/*domainLowerBoundFn: (CombinedEntityStateHistoryMoment historyMoment, _) => historyMoment.time.subtract(Duration(hours: 1)),
|
||||||
domainUpperBoundFn: (CombinedEntityStateHistoryMoment historyMoment, _) => historyMoment.time.add(Duration(hours: 1)),*/
|
domainUpperBoundFn: (CombinedEntityStateHistoryMoment historyMoment, _) => historyMoment.time.add(Duration(hours: 1)),*/
|
||||||
@ -157,13 +176,13 @@ class _CombinedHistoryChartWidgetState extends State<CombinedHistoryChartWidget>
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
result.add(
|
result.add(
|
||||||
new charts.Series<CombinedEntityStateHistoryMoment, DateTime>(
|
new charts.Series<EntityHistoryMoment, DateTime>(
|
||||||
id: 'state',
|
id: 'state',
|
||||||
radiusPxFn: (CombinedEntityStateHistoryMoment historyMoment, __) => (historyMoment.id == _selectedId) ? 5.0 : 4.0,
|
radiusPxFn: (EntityHistoryMoment historyMoment, __) => (historyMoment.id == _selectedId) ? 5.0 : 4.0,
|
||||||
colorFn: (CombinedEntityStateHistoryMoment historyMoment, __) => EntityColors.chartHistoryStateColor(historyMoment.state, historyMoment.colorId),
|
colorFn: (EntityHistoryMoment historyMoment, __) => EntityColors.chartHistoryStateColor(historyMoment.state, historyMoment.colorId),
|
||||||
domainFn: (CombinedEntityStateHistoryMoment historyMoment, _) => historyMoment.startTime,
|
domainFn: (EntityHistoryMoment historyMoment, _) => historyMoment.startTime,
|
||||||
domainLowerBoundFn: (CombinedEntityStateHistoryMoment historyMoment, _) => historyMoment.startTime,
|
domainLowerBoundFn: (EntityHistoryMoment historyMoment, _) => historyMoment.startTime,
|
||||||
domainUpperBoundFn: (CombinedEntityStateHistoryMoment historyMoment, _) => historyMoment.endTime ?? DateTime.now(),
|
domainUpperBoundFn: (EntityHistoryMoment historyMoment, _) => historyMoment.endTime ?? DateTime.now(),
|
||||||
// No measure values are needed for symbol annotations.
|
// No measure values are needed for symbol annotations.
|
||||||
measureFn: (_, __) => null,
|
measureFn: (_, __) => null,
|
||||||
data: numericDataLists[numericDataLists.keys.first],
|
data: numericDataLists[numericDataLists.keys.first],
|
||||||
@ -209,102 +228,3 @@ class _CombinedHistoryChartWidgetState extends State<CombinedHistoryChartWidget>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CombinedHistoryControlWidget extends StatelessWidget {
|
|
||||||
|
|
||||||
final Function onPrevTap;
|
|
||||||
final Function onNextTap;
|
|
||||||
final DateTime selectedTimeStart;
|
|
||||||
final DateTime selectedTimeEnd;
|
|
||||||
final List<String> selectedStates;
|
|
||||||
final List<int> colorIndexes;
|
|
||||||
|
|
||||||
const CombinedHistoryControlWidget({Key key, this.onPrevTap, this.onNextTap, this.selectedTimeStart, this.selectedTimeEnd, this.selectedStates, @ required this.colorIndexes}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
if (selectedTimeStart != null) {
|
|
||||||
return
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: <Widget>[
|
|
||||||
IconButton(
|
|
||||||
icon: Icon(Icons.chevron_left),
|
|
||||||
padding: EdgeInsets.all(0.0),
|
|
||||||
iconSize: 40.0,
|
|
||||||
onPressed: onPrevTap,
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.only(right: 10.0),
|
|
||||||
child: _buildStates(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
_buildTime(),
|
|
||||||
IconButton(
|
|
||||||
icon: Icon(Icons.chevron_right),
|
|
||||||
padding: EdgeInsets.all(0.0),
|
|
||||||
iconSize: 40.0,
|
|
||||||
onPressed: onNextTap,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return Container(height: 48.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildStates() {
|
|
||||||
List<Widget> children = [];
|
|
||||||
for (int i = 0; i < selectedStates.length; i++) {
|
|
||||||
children.add(
|
|
||||||
Text(
|
|
||||||
"${selectedStates[i] ?? '-'}",
|
|
||||||
textAlign: TextAlign.right,
|
|
||||||
style: TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: EntityColors.historyStateColor(selectedStates[i], colorIndexes[i]),
|
|
||||||
fontSize: 22.0
|
|
||||||
),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
|
||||||
children: children,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildTime() {
|
|
||||||
List<Widget> children = [];
|
|
||||||
children.add(
|
|
||||||
Text("${formatDate(selectedTimeStart, [M, ' ', d, ', ', HH, ':', nn, ':', ss])}", textAlign: TextAlign.left,)
|
|
||||||
);
|
|
||||||
if (selectedTimeEnd != null) {
|
|
||||||
children.add(
|
|
||||||
Text("${formatDate(selectedTimeEnd, [M, ' ', d, ', ', HH, ':', nn, ':', ss])}", textAlign: TextAlign.left,)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: children,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class CombinedEntityStateHistoryMoment {
|
|
||||||
final DateTime startTime;
|
|
||||||
final DateTime endTime;
|
|
||||||
final double value;
|
|
||||||
final double previousValue;
|
|
||||||
final int id;
|
|
||||||
final int colorId;
|
|
||||||
final String state;
|
|
||||||
final bool hiddenDot;
|
|
||||||
final bool hiddenLine;
|
|
||||||
|
|
||||||
CombinedEntityStateHistoryMoment(this.value, this.previousValue, this.hiddenDot, this.hiddenLine, this.state, this.startTime, this.endTime, this.id, this.colorId);
|
|
||||||
}
|
|
||||||
|
25
lib/entity_widgets/history_chart/entity_history_moment.dart
Normal file
25
lib/entity_widgets/history_chart/entity_history_moment.dart
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
part of '../../main.dart';
|
||||||
|
|
||||||
|
class EntityHistoryMoment {
|
||||||
|
final DateTime startTime;
|
||||||
|
final DateTime endTime;
|
||||||
|
final double value;
|
||||||
|
final double previousValue;
|
||||||
|
final int id;
|
||||||
|
final int colorId;
|
||||||
|
final String state;
|
||||||
|
final bool hiddenDot;
|
||||||
|
final bool hiddenLine;
|
||||||
|
|
||||||
|
EntityHistoryMoment({
|
||||||
|
this.value,
|
||||||
|
this.previousValue,
|
||||||
|
this.hiddenDot,
|
||||||
|
this.hiddenLine,
|
||||||
|
this.state,
|
||||||
|
@required this.startTime,
|
||||||
|
this.endTime,
|
||||||
|
@required this.id,
|
||||||
|
this.colorId
|
||||||
|
});
|
||||||
|
}
|
86
lib/entity_widgets/history_chart/history_control_widget.dart
Normal file
86
lib/entity_widgets/history_chart/history_control_widget.dart
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
part of '../../main.dart';
|
||||||
|
|
||||||
|
class HistoryControlWidget extends StatelessWidget {
|
||||||
|
|
||||||
|
final Function onPrevTap;
|
||||||
|
final Function onNextTap;
|
||||||
|
final DateTime selectedTimeStart;
|
||||||
|
final DateTime selectedTimeEnd;
|
||||||
|
final List<String> selectedStates;
|
||||||
|
final List<int> colorIndexes;
|
||||||
|
|
||||||
|
const HistoryControlWidget({Key key, this.onPrevTap, this.onNextTap, this.selectedTimeStart, this.selectedTimeEnd, this.selectedStates, @ required this.colorIndexes}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (selectedTimeStart != null) {
|
||||||
|
return
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: <Widget>[
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.chevron_left),
|
||||||
|
padding: EdgeInsets.all(0.0),
|
||||||
|
iconSize: 40.0,
|
||||||
|
onPressed: onPrevTap,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.only(right: 10.0),
|
||||||
|
child: _buildStates(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
_buildTime(),
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.chevron_right),
|
||||||
|
padding: EdgeInsets.all(0.0),
|
||||||
|
iconSize: 40.0,
|
||||||
|
onPressed: onNextTap,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return Container(height: 48.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildStates() {
|
||||||
|
List<Widget> children = [];
|
||||||
|
for (int i = 0; i < selectedStates.length; i++) {
|
||||||
|
children.add(
|
||||||
|
Text(
|
||||||
|
"${selectedStates[i] ?? '-'}",
|
||||||
|
textAlign: TextAlign.right,
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: EntityColors.historyStateColor(selectedStates[i], colorIndexes[i]),
|
||||||
|
fontSize: 22.0
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
|
children: children,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildTime() {
|
||||||
|
List<Widget> children = [];
|
||||||
|
children.add(
|
||||||
|
Text("${formatDate(selectedTimeStart, [M, ' ', d, ', ', HH, ':', nn, ':', ss])}", textAlign: TextAlign.left,)
|
||||||
|
);
|
||||||
|
if (selectedTimeEnd != null) {
|
||||||
|
children.add(
|
||||||
|
Text("${formatDate(selectedTimeEnd, [M, ' ', d, ', ', HH, ':', nn, ':', ss])}", textAlign: TextAlign.left,)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: children,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -17,7 +17,7 @@ class NumericStateHistoryChartWidget extends StatefulWidget {
|
|||||||
class _NumericStateHistoryChartWidgetState extends State<NumericStateHistoryChartWidget> {
|
class _NumericStateHistoryChartWidgetState extends State<NumericStateHistoryChartWidget> {
|
||||||
|
|
||||||
int _selectedId = -1;
|
int _selectedId = -1;
|
||||||
List<charts.Series<NumericEntityStateHistoryMoment, DateTime>> _parsedHistory;
|
List<charts.Series<EntityHistoryMoment, DateTime>> _parsedHistory;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -25,7 +25,7 @@ class _NumericStateHistoryChartWidgetState extends State<NumericStateHistoryChar
|
|||||||
DateTime selectedTime;
|
DateTime selectedTime;
|
||||||
double selectedState;
|
double selectedState;
|
||||||
if ((_selectedId > -1) && (_parsedHistory != null) && (_parsedHistory.first.data.length >= (_selectedId + 1))) {
|
if ((_selectedId > -1) && (_parsedHistory != null) && (_parsedHistory.first.data.length >= (_selectedId + 1))) {
|
||||||
selectedTime = _parsedHistory.first.data[_selectedId].time;
|
selectedTime = _parsedHistory.first.data[_selectedId].startTime;
|
||||||
selectedState = _parsedHistory.first.data[_selectedId].value;
|
selectedState = _parsedHistory.first.data[_selectedId].value;
|
||||||
}
|
}
|
||||||
return Column(
|
return Column(
|
||||||
@ -34,10 +34,10 @@ class _NumericStateHistoryChartWidgetState extends State<NumericStateHistoryChar
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
HistoryControlWidget(
|
HistoryControlWidget(
|
||||||
selectedTimeStart: selectedTime,
|
selectedTimeStart: selectedTime,
|
||||||
selectedState: "${selectedState ?? '-'}",
|
selectedStates: ["${selectedState ?? '-'}"],
|
||||||
onPrevTap: () => _selectPrev(),
|
onPrevTap: () => _selectPrev(),
|
||||||
onNextTap: () => _selectNext(),
|
onNextTap: () => _selectNext(),
|
||||||
colorIndex: -1,
|
colorIndexes: [-1],
|
||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 150.0,
|
height: 150.0,
|
||||||
@ -66,8 +66,8 @@ class _NumericStateHistoryChartWidgetState extends State<NumericStateHistoryChar
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<charts.Series<NumericEntityStateHistoryMoment, DateTime>> _parseHistory() {
|
List<charts.Series<EntityHistoryMoment, DateTime>> _parseHistory() {
|
||||||
List<NumericEntityStateHistoryMoment> data = [];
|
List<EntityHistoryMoment> data = [];
|
||||||
DateTime now = DateTime.now();
|
DateTime now = DateTime.now();
|
||||||
for (var i = 0; i < widget.rawHistory.length; i++) {
|
for (var i = 0; i < widget.rawHistory.length; i++) {
|
||||||
var stateData = widget.rawHistory[i];
|
var stateData = widget.rawHistory[i];
|
||||||
@ -85,21 +85,35 @@ class _NumericStateHistoryChartWidgetState extends State<NumericStateHistoryChar
|
|||||||
} else {
|
} else {
|
||||||
hiddenLine = hiddenDot;
|
hiddenLine = hiddenDot;
|
||||||
}
|
}
|
||||||
data.add(NumericEntityStateHistoryMoment(value, previousValue, hiddenDot, hiddenLine, time, i));
|
data.add(EntityHistoryMoment(
|
||||||
|
value: value,
|
||||||
|
previousValue: previousValue,
|
||||||
|
hiddenDot: hiddenDot,
|
||||||
|
hiddenLine: hiddenLine,
|
||||||
|
startTime: time,
|
||||||
|
id: i
|
||||||
|
));
|
||||||
}
|
}
|
||||||
data.add(NumericEntityStateHistoryMoment(data.last.value, data.last.previousValue, data.last.hiddenDot, data.last.hiddenLine, now, widget.rawHistory.length));
|
data.add(EntityHistoryMoment(
|
||||||
|
value: data.last.value,
|
||||||
|
previousValue: data.last.previousValue,
|
||||||
|
hiddenDot: data.last.hiddenDot,
|
||||||
|
hiddenLine: data.last.hiddenLine,
|
||||||
|
startTime: now,
|
||||||
|
id: widget.rawHistory.length
|
||||||
|
));
|
||||||
if (_selectedId == -1) {
|
if (_selectedId == -1) {
|
||||||
_selectedId = 0;
|
_selectedId = 0;
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
new charts.Series<NumericEntityStateHistoryMoment, DateTime>(
|
new charts.Series<EntityHistoryMoment, DateTime>(
|
||||||
id: 'State',
|
id: 'State',
|
||||||
colorFn: (NumericEntityStateHistoryMoment historyMoment, __) => EntityColors.chartHistoryStateColor("on", -1),
|
colorFn: (EntityHistoryMoment historyMoment, __) => EntityColors.chartHistoryStateColor("on", -1),
|
||||||
domainFn: (NumericEntityStateHistoryMoment historyMoment, _) => historyMoment.time,
|
domainFn: (EntityHistoryMoment historyMoment, _) => historyMoment.startTime,
|
||||||
measureFn: (NumericEntityStateHistoryMoment historyMoment, _) => historyMoment.value ?? historyMoment.previousValue,
|
measureFn: (EntityHistoryMoment historyMoment, _) => historyMoment.value ?? historyMoment.previousValue,
|
||||||
data: data,
|
data: data,
|
||||||
strokeWidthPxFn: (NumericEntityStateHistoryMoment historyMoment, __) => historyMoment.hiddenLine ? 0.0 : 2.0,
|
strokeWidthPxFn: (EntityHistoryMoment historyMoment, __) => historyMoment.hiddenLine ? 0.0 : 2.0,
|
||||||
radiusPxFn: (NumericEntityStateHistoryMoment historyMoment, __) {
|
radiusPxFn: (EntityHistoryMoment historyMoment, __) {
|
||||||
if (historyMoment.hiddenDot) {
|
if (historyMoment.hiddenDot) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
} else if (historyMoment.id == _selectedId) {
|
} else if (historyMoment.id == _selectedId) {
|
||||||
@ -144,14 +158,3 @@ class _NumericStateHistoryChartWidgetState extends State<NumericStateHistoryChar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NumericEntityStateHistoryMoment {
|
|
||||||
final DateTime time;
|
|
||||||
final double value;
|
|
||||||
final double previousValue;
|
|
||||||
final int id;
|
|
||||||
final bool hiddenDot;
|
|
||||||
final bool hiddenLine;
|
|
||||||
|
|
||||||
NumericEntityStateHistoryMoment(this.value, this.previousValue, this.hiddenDot, this.hiddenLine, this.time, this.id);
|
|
||||||
}
|
|
@ -16,7 +16,7 @@ class SimpleStateHistoryChartWidget extends StatefulWidget {
|
|||||||
class _SimpleStateHistoryChartWidgetState extends State<SimpleStateHistoryChartWidget> {
|
class _SimpleStateHistoryChartWidgetState extends State<SimpleStateHistoryChartWidget> {
|
||||||
|
|
||||||
int _selectedId = -1;
|
int _selectedId = -1;
|
||||||
List<charts.Series<SimpleEntityStateHistoryMoment, DateTime>> _parsedHistory;
|
List<charts.Series<EntityHistoryMoment, DateTime>> _parsedHistory;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -36,10 +36,10 @@ class _SimpleStateHistoryChartWidgetState extends State<SimpleStateHistoryChartW
|
|||||||
HistoryControlWidget(
|
HistoryControlWidget(
|
||||||
selectedTimeStart: selectedTimeStart,
|
selectedTimeStart: selectedTimeStart,
|
||||||
selectedTimeEnd: selectedTimeEnd,
|
selectedTimeEnd: selectedTimeEnd,
|
||||||
selectedState: selectedState,
|
selectedStates: [selectedState],
|
||||||
onPrevTap: () => _selectPrev(),
|
onPrevTap: () => _selectPrev(),
|
||||||
onNextTap: () => _selectNext(),
|
onNextTap: () => _selectNext(),
|
||||||
colorIndex: _parsedHistory.first.data[_selectedId].colorId,
|
colorIndexes: [_parsedHistory.first.data[_selectedId].colorId],
|
||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 70.0,
|
height: 70.0,
|
||||||
@ -70,8 +70,8 @@ class _SimpleStateHistoryChartWidgetState extends State<SimpleStateHistoryChartW
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<charts.Series<SimpleEntityStateHistoryMoment, DateTime>> _parseHistory() {
|
List<charts.Series<EntityHistoryMoment, DateTime>> _parseHistory() {
|
||||||
List<SimpleEntityStateHistoryMoment> data = [];
|
List<EntityHistoryMoment> data = [];
|
||||||
DateTime now = DateTime.now();
|
DateTime now = DateTime.now();
|
||||||
Map<String, int> cachedStates = {};
|
Map<String, int> cachedStates = {};
|
||||||
for (var i = 0; i < widget.rawHistory.length; i++) {
|
for (var i = 0; i < widget.rawHistory.length; i++) {
|
||||||
@ -86,35 +86,46 @@ class _SimpleStateHistoryChartWidgetState extends State<SimpleStateHistoryChartW
|
|||||||
if (cachedStates[stateData["state"]] == null) {
|
if (cachedStates[stateData["state"]] == null) {
|
||||||
cachedStates.addAll({"${stateData["state"]}": cachedStates.length});
|
cachedStates.addAll({"${stateData["state"]}": cachedStates.length});
|
||||||
}
|
}
|
||||||
data.add(SimpleEntityStateHistoryMoment(stateData["state"], startTime, endTime, i, cachedStates[stateData["state"]]));
|
data.add(EntityHistoryMoment(
|
||||||
|
state: stateData["state"],
|
||||||
|
startTime: startTime,
|
||||||
|
endTime: endTime,
|
||||||
|
id: i,
|
||||||
|
colorId: cachedStates[stateData["state"]]
|
||||||
|
));
|
||||||
}
|
}
|
||||||
data.add(SimpleEntityStateHistoryMoment(data.last.state, now, null, widget.rawHistory.length, data.last.colorId));
|
data.add(EntityHistoryMoment(
|
||||||
|
state: data.last.state,
|
||||||
|
startTime: now,
|
||||||
|
id: widget.rawHistory.length,
|
||||||
|
colorId: data.last.colorId
|
||||||
|
));
|
||||||
if (_selectedId == -1) {
|
if (_selectedId == -1) {
|
||||||
_selectedId = 0;
|
_selectedId = 0;
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
new charts.Series<SimpleEntityStateHistoryMoment, DateTime>(
|
new charts.Series<EntityHistoryMoment, DateTime>(
|
||||||
id: 'State',
|
id: 'State',
|
||||||
strokeWidthPxFn: (SimpleEntityStateHistoryMoment historyMoment, __) => (historyMoment.id == _selectedId) ? 6.0 : 3.0,
|
strokeWidthPxFn: (EntityHistoryMoment historyMoment, __) => (historyMoment.id == _selectedId) ? 6.0 : 3.0,
|
||||||
colorFn: (SimpleEntityStateHistoryMoment historyMoment, __) => EntityColors.chartHistoryStateColor(historyMoment.state, historyMoment.colorId),
|
colorFn: (EntityHistoryMoment historyMoment, __) => EntityColors.chartHistoryStateColor(historyMoment.state, historyMoment.colorId),
|
||||||
domainFn: (SimpleEntityStateHistoryMoment historyMoment, _) => historyMoment.startTime,
|
domainFn: (EntityHistoryMoment historyMoment, _) => historyMoment.startTime,
|
||||||
measureFn: (SimpleEntityStateHistoryMoment historyMoment, _) => 10,
|
measureFn: (EntityHistoryMoment historyMoment, _) => 10,
|
||||||
data: data,
|
data: data,
|
||||||
),
|
),
|
||||||
new charts.Series<SimpleEntityStateHistoryMoment, DateTime>(
|
new charts.Series<EntityHistoryMoment, DateTime>(
|
||||||
id: 'State',
|
id: 'State',
|
||||||
radiusPxFn: (SimpleEntityStateHistoryMoment historyMoment, __) => (historyMoment.id == _selectedId) ? 5.0 : 3.0,
|
radiusPxFn: (EntityHistoryMoment historyMoment, __) => (historyMoment.id == _selectedId) ? 5.0 : 3.0,
|
||||||
colorFn: (SimpleEntityStateHistoryMoment historyMoment, __) => EntityColors.chartHistoryStateColor(historyMoment.state, historyMoment.colorId),
|
colorFn: (EntityHistoryMoment historyMoment, __) => EntityColors.chartHistoryStateColor(historyMoment.state, historyMoment.colorId),
|
||||||
domainFn: (SimpleEntityStateHistoryMoment historyMoment, _) => historyMoment.startTime,
|
domainFn: (EntityHistoryMoment historyMoment, _) => historyMoment.startTime,
|
||||||
measureFn: (SimpleEntityStateHistoryMoment historyMoment, _) => 10,
|
measureFn: (EntityHistoryMoment historyMoment, _) => 10,
|
||||||
data: data,
|
data: data,
|
||||||
)..setAttribute(charts.rendererIdKey, 'startValuePoints'),
|
)..setAttribute(charts.rendererIdKey, 'startValuePoints'),
|
||||||
new charts.Series<SimpleEntityStateHistoryMoment, DateTime>(
|
new charts.Series<EntityHistoryMoment, DateTime>(
|
||||||
id: 'State',
|
id: 'State',
|
||||||
radiusPxFn: (SimpleEntityStateHistoryMoment historyMoment, __) => (historyMoment.id == _selectedId) ? 5.0 : 3.0,
|
radiusPxFn: (EntityHistoryMoment historyMoment, __) => (historyMoment.id == _selectedId) ? 5.0 : 3.0,
|
||||||
colorFn: (SimpleEntityStateHistoryMoment historyMoment, __) => EntityColors.chartHistoryStateColor(historyMoment.state, historyMoment.colorId),
|
colorFn: (EntityHistoryMoment historyMoment, __) => EntityColors.chartHistoryStateColor(historyMoment.state, historyMoment.colorId),
|
||||||
domainFn: (SimpleEntityStateHistoryMoment historyMoment, _) => historyMoment.endTime ?? DateTime.now(),
|
domainFn: (EntityHistoryMoment historyMoment, _) => historyMoment.endTime ?? DateTime.now(),
|
||||||
measureFn: (SimpleEntityStateHistoryMoment historyMoment, _) => 10,
|
measureFn: (EntityHistoryMoment historyMoment, _) => 10,
|
||||||
data: data,
|
data: data,
|
||||||
)..setAttribute(charts.rendererIdKey, 'endValuePoints')
|
)..setAttribute(charts.rendererIdKey, 'endValuePoints')
|
||||||
];
|
];
|
||||||
@ -153,78 +164,7 @@ class _SimpleStateHistoryChartWidgetState extends State<SimpleStateHistoryChartW
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class HistoryControlWidget extends StatelessWidget {
|
/*
|
||||||
|
|
||||||
final Function onPrevTap;
|
|
||||||
final Function onNextTap;
|
|
||||||
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, @ required this.colorIndex}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
if (selectedTimeStart != null) {
|
|
||||||
return
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: <Widget>[
|
|
||||||
IconButton(
|
|
||||||
icon: Icon(Icons.chevron_left),
|
|
||||||
padding: EdgeInsets.all(0.0),
|
|
||||||
iconSize: 40.0,
|
|
||||||
onPressed: onPrevTap,
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.only(right: 10.0),
|
|
||||||
child: Text(
|
|
||||||
"${selectedState ?? '-'}",
|
|
||||||
textAlign: TextAlign.right,
|
|
||||||
style: TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: EntityColors.historyStateColor(selectedState, colorIndex),
|
|
||||||
fontSize: 22.0
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
_buildTime(),
|
|
||||||
IconButton(
|
|
||||||
icon: Icon(Icons.chevron_right),
|
|
||||||
padding: EdgeInsets.all(0.0),
|
|
||||||
iconSize: 40.0,
|
|
||||||
onPressed: onNextTap,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return Container(height: 48.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildTime() {
|
|
||||||
List<Widget> children = [];
|
|
||||||
children.add(
|
|
||||||
Text("${formatDate(selectedTimeStart, [M, ' ', d, ', ', HH, ':', nn, ':', ss])}", textAlign: TextAlign.left,)
|
|
||||||
);
|
|
||||||
if (selectedTimeEnd != null) {
|
|
||||||
children.add(
|
|
||||||
Text("${formatDate(selectedTimeEnd, [M, ' ', d, ', ', HH, ':', nn, ':', ss])}", textAlign: TextAlign.left,)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: children,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class SimpleEntityStateHistoryMoment {
|
class SimpleEntityStateHistoryMoment {
|
||||||
final DateTime startTime;
|
final DateTime startTime;
|
||||||
final DateTime endTime;
|
final DateTime endTime;
|
||||||
@ -233,4 +173,4 @@ class SimpleEntityStateHistoryMoment {
|
|||||||
final int colorId;
|
final int colorId;
|
||||||
|
|
||||||
SimpleEntityStateHistoryMoment(this.state, this.startTime, this.endTime, this.id, this.colorId);
|
SimpleEntityStateHistoryMoment(this.state, this.startTime, this.endTime, this.id, this.colorId);
|
||||||
}
|
}*/
|
||||||
|
@ -42,6 +42,8 @@ part 'entity_widgets/history_chart/entity_history.dart';
|
|||||||
part 'entity_widgets/history_chart/simple_state_history_chart.dart';
|
part 'entity_widgets/history_chart/simple_state_history_chart.dart';
|
||||||
part 'entity_widgets/history_chart/numeric_state_history_chart.dart';
|
part 'entity_widgets/history_chart/numeric_state_history_chart.dart';
|
||||||
part 'entity_widgets/history_chart/combined_history_chart.dart';
|
part 'entity_widgets/history_chart/combined_history_chart.dart';
|
||||||
|
part 'entity_widgets/history_chart/history_control_widget.dart';
|
||||||
|
part 'entity_widgets/history_chart/entity_history_moment.dart';
|
||||||
part 'entity_widgets/state/switch_state.dart';
|
part 'entity_widgets/state/switch_state.dart';
|
||||||
part 'entity_widgets/state/slider_state.dart';
|
part 'entity_widgets/state/slider_state.dart';
|
||||||
part 'entity_widgets/state/text_input_state.dart';
|
part 'entity_widgets/state/text_input_state.dart';
|
||||||
|
Reference in New Issue
Block a user