Skip to content

Commit

Permalink
Merge pull request #4 from gregertw:zoompan_extras
Browse files Browse the repository at this point in the history
Fixes #2 and #3
  • Loading branch information
gregertw committed Dec 15, 2020
2 parents 05a1b76 + a86142f commit 2b9fe0c
Show file tree
Hide file tree
Showing 20 changed files with 182 additions and 165 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## Dec 15, 2020

* Increase test coverage with more widget tests
* Fix [#2](https://github.com/gregertw/cognite_flutter_demo/issues/2)
* Add support for double-tap/click to zoom and buttons to pan [#3](https://github.com/gregertw/cognite_flutter_demo/issues/3)
* Improve build predictibility for Android (still need to do flutter build apk --debug, then --profile before flutter build apk)
* Release of 0.3.0

## Nov 30, 2020

* Initial version 0.2.0 available on Github Pages
10 changes: 9 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "io.greger.cognite_flutter_demo"
minSdkVersion 16
minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand All @@ -69,6 +69,7 @@ android {
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
}
}
}
Expand All @@ -79,6 +80,13 @@ flutter {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:26.1.1')

// Declare the dependencies for the Crashlytics and Analytics libraries
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics-ktx'
}
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.gms.google-services' // Gradle plugin for Google Services
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.3' // Google Services plugin
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'
classpath 'com.google.gms:google-services:4.3.4' // Google Services plugin
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'
}
}

Expand Down
1 change: 1 addition & 0 deletions android/settings_aar.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ':app'
2 changes: 2 additions & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ class MessageLookup extends MessageLookupByLibrary {
"chartHistory" : MessageLookupByLibrary.simpleMessage("Request History"),
"chartInfo" : MessageLookupByLibrary.simpleMessage("Documentation"),
"chartInterpolation" : MessageLookupByLibrary.simpleMessage("Interpolation(on/off)"),
"chartLeft" : MessageLookupByLibrary.simpleMessage("Pan Left"),
"chartMarkers" : MessageLookupByLibrary.simpleMessage("Markers"),
"chartMaximum" : MessageLookupByLibrary.simpleMessage("Maximum(on/off)"),
"chartMinimum" : MessageLookupByLibrary.simpleMessage("Minimum(on/off)"),
"chartRawValues" : MessageLookupByLibrary.simpleMessage("Raw Values < 1h (on/off)"),
"chartReset" : MessageLookupByLibrary.simpleMessage("Reset"),
"chartRight" : MessageLookupByLibrary.simpleMessage("Pan Right"),
"chartStepInterpolation" : MessageLookupByLibrary.simpleMessage("Step Interpolation(on/off)"),
"chartTooltip" : MessageLookupByLibrary.simpleMessage("Tooltip"),
"chartTotalVariance" : MessageLookupByLibrary.simpleMessage("Total Variance(on/off)"),
Expand Down
2 changes: 2 additions & 0 deletions lib/generated/intl/messages_nb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ class MessageLookup extends MessageLookupByLibrary {
"chartHistory" : MessageLookupByLibrary.simpleMessage("Forespørselhistorie"),
"chartInfo" : MessageLookupByLibrary.simpleMessage("Dokumentasjon"),
"chartInterpolation" : MessageLookupByLibrary.simpleMessage("Interpolering(av/på)"),
"chartLeft" : MessageLookupByLibrary.simpleMessage("Gå venstre"),
"chartMarkers" : MessageLookupByLibrary.simpleMessage("Punkter"),
"chartMaximum" : MessageLookupByLibrary.simpleMessage("Maximum(av/på)"),
"chartMinimum" : MessageLookupByLibrary.simpleMessage("Minimum(av/på)"),
"chartRawValues" : MessageLookupByLibrary.simpleMessage("Rå verdier < 1t (av/på)"),
"chartReset" : MessageLookupByLibrary.simpleMessage("Tilbakestill"),
"chartRight" : MessageLookupByLibrary.simpleMessage("Gå høyre"),
"chartStepInterpolation" : MessageLookupByLibrary.simpleMessage("Stegvis interpolering(av/på)"),
"chartTooltip" : MessageLookupByLibrary.simpleMessage("Markørinfo"),
"chartTotalVariance" : MessageLookupByLibrary.simpleMessage("Total varians(av/på)"),
Expand Down
20 changes: 20 additions & 0 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"configTimeseriesIdEmpty": "Timeseries id cannot be empty",
"configNrOfDays": "Enter number of days in initial range",
"configProjectFailed": "Not able to access CDF project",
"chartLeft": "Pan Left",
"chartRight": "Pan Right",
"chartZoomIn": "Zoom In",
"chartZoomOut": "Zoom Out",
"chartReset": "Reset",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/intl_nb.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"configTimeseriesIdEmpty": "Tidsserie-id kan ikke være tom",
"configNrOfDays": "Sett antall dager i første diagram",
"configProjectFailed": "Tilgang til CDF prosjektet feilet",
"chartLeft": "Gå venstre",
"chartRight": "Gå høyre",
"chartZoomIn": "Zoom inn",
"chartZoomOut": "Zoom ut",
"chartReset": "Tilbakestill",
Expand Down
4 changes: 3 additions & 1 deletion lib/models/appstate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class AppStateModel with ChangeNotifier {
log.d('Sent analytics events: $name');
}

void verifyCDF() async {
Future<bool> verifyCDF() async {
_cdfApiKey = prefs.getString('cdfApiKey') ?? '';
_cdfProject = prefs.getString('cdfProject') ?? 'publicdata';
_cdfURL = prefs.getString('cdfURL') ?? 'https://api.cognitedata.com';
Expand All @@ -166,6 +166,7 @@ class AppStateModel with ChangeNotifier {
log.d(_cdfStatus);
} catch (e) {
_cdfStatus = null;
return false;
}
if (_cdfStatus != null) {
setUserInfo(Map.from({'email': _cdfStatus.user, 'name': 'N/A'}));
Expand All @@ -175,6 +176,7 @@ class AppStateModel with ChangeNotifier {
sendAnalyticsEvent(
'login', {'project': _cdfProject, 'timeseries': _cdfTimeSeriesId});
notifyListeners();
return true;
}

void setUserInfo(data) {
Expand Down
20 changes: 18 additions & 2 deletions lib/models/chartstate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class ChartFeatureModel with ChangeNotifier {
String _dateAxisFormat;
int startRange = 0;
int endRange = 0;
int _startSpan = 0;
int _endSpan = 0;
int resolution;
int resolutionFactor;
get startRangeDate => DateTime.fromMillisecondsSinceEpoch(startRange);
Expand All @@ -17,6 +19,8 @@ class ChartFeatureModel with ChangeNotifier {
RangeController _rangeController;

RangeController get rangeController => _rangeController;
get startSpan => _startSpan;
get endSpan => _endSpan;

ChartFeatureModel(this.resolutionFactor) {
showMarker = false;
Expand Down Expand Up @@ -48,17 +52,29 @@ class ChartFeatureModel with ChangeNotifier {
}
}

void initRange(int start, int end) {
void initRange(int start, int end, {int startSpan, int endSpan}) {
if (startRange == 0 || endRange == 0) {
setNewRange(start: start, end: end);
_startSpan = startSpan;
_endSpan = endSpan;
}
}

void setNewRange({int start, int end, double zoom: 0.0}) {
void setNewRange({int start, int end, double zoom: 0.0, double pan: 0.0}) {
if (zoom != 0.0) {
var range = (endRange - startRange) / 2;
startRange = startRange + (range * zoom).round();
endRange = endRange - (range * zoom).round();
} else if (pan != 0.0) {
var range = (endRange - startRange) / 2;
startRange = startRange + (range * pan).round();
endRange = endRange + (range * pan).round();
// Don't go outside range controller min and max range
if (startRange < _startSpan) {
startRange = _startSpan;
} else if (endRange > _endSpan) {
endRange = _endSpan;
}
} else {
startRange = start;
endRange = end;
Expand Down
8 changes: 4 additions & 4 deletions lib/ui/pages/home/drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ class HomePageDrawer extends StatelessWidget {
title: Text(S.of(context).drawerAbout),
onTap: () {
showSimpleNotification(Text(S.of(context).drawerAboutTitle),
key: Key('DrawerMenu_NotificationAbout'),
leading: Icon(
Icons.info_outline,
size: 28,
color: Colors.blue.shade300,
), trailing: Builder(builder: (context) {
return FlatButton(
autofocus: true,
textColor: Colors.yellow,
onPressed: () {
OverlaySupportEntry.of(context).dismiss();
launch(
"https://github.com/gregertw/cognite-flutter-demo/issues");
},
child: Text(
"https://github.com/gregertw/cognite-flutter-demo/issues",
style: TextStyle(color: Colors.amber),
),
child:
Icon(Icons.link, size: 28, color: Colors.blue.shade300),
);
}),
subtitle: Text(S.of(context).drawerAboutMessage),
Expand Down
43 changes: 43 additions & 0 deletions lib/ui/pages/timeseries_chart/checkboxes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,49 @@ class CheckBoxButtons extends StatelessWidget {
direction: Axis.horizontal,
alignment: WrapAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(24, 0, 0, 0),
child: IconButton(
tooltip: S.of(context).chartLeft,
icon: Icon(Icons.arrow_back, color: Theme.of(context).accentColor),
onPressed: () {
chart.setNewRange(pan: -0.5);
chart.applyRangeController();
hbm.setFilter(
start: chart.startRange,
end: chart.endRange,
resolution: chart.resolution);
// Only load raw datapoints when we have a short range
if (((chart.endRange - chart.startRange) / 1000).round() < 3600) {
hbm.loadTimeSeries(raw: true);
} else {
hbm.loadTimeSeries();
}
},
),
),
Padding(
padding: const EdgeInsets.fromLTRB(24, 0, 0, 0),
child: IconButton(
tooltip: S.of(context).chartRight,
icon:
Icon(Icons.arrow_forward, color: Theme.of(context).accentColor),
onPressed: () {
chart.setNewRange(pan: 0.5);
chart.applyRangeController();
hbm.setFilter(
start: chart.startRange,
end: chart.endRange,
resolution: chart.resolution);
// Only load raw datapoints when we have a short range
if (((chart.endRange - chart.startRange) / 1000).round() < 3600) {
hbm.loadTimeSeries(raw: true);
} else {
hbm.loadTimeSeries();
}
},
),
),
Padding(
padding: const EdgeInsets.fromLTRB(24, 0, 0, 0),
child: IconButton(
Expand Down
29 changes: 28 additions & 1 deletion lib/ui/pages/timeseries_chart/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ class TimeSeriesChart extends StatelessWidget {
Widget build(BuildContext context) {
var hbm = Provider.of<HeartBeatModel>(context, listen: false);
var chart = Provider.of<ChartFeatureModel>(context);
var zoomPan = ZoomPanBehavior(enableDoubleTapZooming: true);
// Initialise the range and controller
chart.initRange(
(hbm.rangeStart + (hbm.rangeEnd - hbm.rangeStart) / 3).round(),
(hbm.rangeEnd - (hbm.rangeEnd - hbm.rangeStart) / 3).round());
(hbm.rangeEnd - (hbm.rangeEnd - hbm.rangeStart) / 3).round(),
startSpan: hbm.rangeStart,
endSpan: hbm.rangeEnd);
return SingleChildScrollView(
child: Padding(
padding: EdgeInsets.fromLTRB(5, 0, 5, 50),
Expand All @@ -36,6 +39,7 @@ class TimeSeriesChart extends StatelessWidget {
dateFormat: DateFormat(chart.dateAxisFormat)),
primaryYAxis: NumericAxis(
isVisible: true, anchorRangeToVisiblePoints: true),
zoomPanBehavior: zoomPan,
legend: Legend(
isVisible: true,
position: LegendPosition.top,
Expand All @@ -47,6 +51,29 @@ class TimeSeriesChart extends StatelessWidget {
opacity: 0.4,
format: 'point.y',
tooltipPosition: TooltipPosition.pointer),
onZoomEnd: (ZoomPanArgs args) {
// Double-click zoom
if (args.axis is DateTimeAxis &&
args.currentZoomFactor < args.previousZoomFactor) {
// We don't want to zoom in more than 11s
if ((chart.endRange - chart.startRange).round() > 11000) {
chart.setNewRange(zoom: 0.4);
chart.applyRangeController();
zoomPan.reset();
hbm.setFilter(
start: chart.startRange,
end: chart.endRange,
resolution: chart.resolution);
// Only load raw datapoints when we have a short range
if (((chart.endRange - chart.startRange) / 1000).round() <
3600) {
hbm.loadTimeSeries(raw: true);
} else {
hbm.loadTimeSeries();
}
}
}
},
series: <CartesianSeries<DatapointModel, DateTime>>[
LineSeries<DatapointModel, DateTime>(
isVisible: true,
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: cognite_flutter_demo
description: A demo application for Cognite CDF
homepage: https://docs.cognite.com/dev/
version: 0.2.1
homepage: https://github.com/gregertw/cognite_flutter_demo
version: 0.3.0
publish_to: none

environment:
Expand All @@ -18,6 +18,7 @@ dependencies:
provider: ^4.3.2+2
logger: ^0.9.4
shared_preferences: ^0.5.12
firebase_core: ^0.5.3
firebase_analytics: ^6.3.0
firebase_crashlytics: ^0.2.4
overlay_support: ^1.0.5
Expand Down Expand Up @@ -48,7 +49,6 @@ flutter_icons:
image_path: "assets/icon.png"

flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
Expand Down
Loading

0 comments on commit 2b9fe0c

Please sign in to comment.