Add graph animation; support for line graphs
[harbour-pedalo.git] / qml / pages / Stats.qml
index f6e319c..235ca1c 100644 (file)
@@ -1,5 +1,6 @@
 import QtQuick 2.0
 import Sailfish.Silica 1.0
 import QtQuick 2.0
 import Sailfish.Silica 1.0
+import harbour.pedalo.graph 1.0
 import "../components"
 
 Page {
 import "../components"
 
 Page {
@@ -7,61 +8,126 @@ Page {
 
     // The effective value will be restricted by ApplicationWindow.allowedOrientations
     allowedOrientations: Orientation.All
 
     // The effective value will be restricted by ApplicationWindow.allowedOrientations
     allowedOrientations: Orientation.All
+    property int showingindex: 0
 
     SilicaFlickable {
         id: statsView
         anchors.fill: parent
 
     SilicaFlickable {
         id: statsView
         anchors.fill: parent
-        contentHeight: statsColumn.implicitHeight
+        contentHeight: statsColumn.implicitHeight + headerItem.height
 
         VerticalScrollDecorator {}
 
 
         VerticalScrollDecorator {}
 
+        PageHeader {
+            id: headerItem
+            title: qsTr("Stats")
+        }
+
         Column {
             id: statsColumn
             spacing: Theme.paddingLarge
         Column {
             id: statsColumn
             spacing: Theme.paddingLarge
-            width: parent.width
-
-            PageHeader {
-                title: qsTr("Stats")
-            }
+            width: isPortrait ? parent.width : parent.width * 0.5
+            y: headerItem.height
 
             InfoRow {
                 label: qsTr("Journeys:")
 
             InfoRow {
                 label: qsTr("Journeys:")
-                value: "0"
+                value: currentStatus.getJourneyCount()
                 midlineRatio: 0.7
                 midlineMin: Theme.fontSizeSmall * 10
                 midlineRatio: 0.7
                 midlineMin: Theme.fontSizeSmall * 10
-                midlineMax: Theme.fontSizeSmall * 15
+                midlineMax: Theme.fontSizeSmall * 20
                 pixelSize: Theme.fontSizeMedium
                 labelTextBold: true
                 pixelSize: Theme.fontSizeMedium
                 labelTextBold: true
+                horizontalAlignment: Text.AlignRight
             }
 
             InfoRow {
                 label: qsTr("Time spent cycling:")
             }
 
             InfoRow {
                 label: qsTr("Time spent cycling:")
-                value: "0"
-                midlineRatio: 0.7
+                value: currentStatus.getFormattedTime(currentStatus.getTimeSpentCycling(), 0, 5)
+                midlineRatio: 0.5
                 midlineMin: Theme.fontSizeSmall * 10
                 midlineMin: Theme.fontSizeSmall * 10
-                midlineMax: Theme.fontSizeSmall * 15
+                midlineMax: Theme.fontSizeSmall * 20
                 pixelSize: Theme.fontSizeMedium
                 labelTextBold: true
                 pixelSize: Theme.fontSizeMedium
                 labelTextBold: true
+                horizontalAlignment: Text.AlignRight
             }
 
             InfoRow {
                 label: qsTr("Average journey duration:")
             }
 
             InfoRow {
                 label: qsTr("Average journey duration:")
-                value: "0"
-                midlineRatio: 0.7
+                value: currentStatus.getFormattedTime(currentStatus.getAverageDuration(), 1, 5)
+                midlineRatio: 0.6
                 midlineMin: Theme.fontSizeSmall * 10
                 midlineMin: Theme.fontSizeSmall * 10
-                midlineMax: Theme.fontSizeSmall * 15
+                midlineMax: Theme.fontSizeSmall * 20
                 pixelSize: Theme.fontSizeMedium
                 labelTextBold: true
                 pixelSize: Theme.fontSizeMedium
                 labelTextBold: true
+                horizontalAlignment: Text.AlignRight
             }
 
             InfoRow {
                 label: qsTr("Speed percentile:")
             }
 
             InfoRow {
                 label: qsTr("Speed percentile:")
-                value: "0%"
+                value: Math.round(100.0 - currentStatus.getSpeedPercentile() * 100) + "%"
                 midlineRatio: 0.7
                 midlineMin: Theme.fontSizeSmall * 10
                 midlineRatio: 0.7
                 midlineMin: Theme.fontSizeSmall * 10
-                midlineMax: Theme.fontSizeSmall * 15
+                midlineMax: Theme.fontSizeSmall * 20
                 pixelSize: Theme.fontSizeMedium
                 labelTextBold: true
                 pixelSize: Theme.fontSizeMedium
                 labelTextBold: true
+                horizontalAlignment: Text.AlignRight
+            }
+        }
+
+        SlideshowView {
+            id: graphsView
+            width: isPortrait ? parent.width : parent.width * 0.5
+            height: (isPortrait ? statsPage.height / 2.0 : statsPage.height) - Theme.paddingLarge
+            itemWidth: width
+            clip: true
+            anchors.left: isPortrait ? statsColumn.left : statsColumn.right
+            anchors.leftMargin: 0
+
+            y: (isPortrait ? (statsPage.height / 2.0) : statsColumn.y)
+
+            onModelChanged: {
+                console.log("Model changed");
+                model.updateAll();
+            }
+
+            model: statsmodel
+            delegate: Item {
+                id: delegateItem
+                width: graphsView.itemWidth
+                height: graphsView.height
+
+                SectionHeader {
+                    id: sectionHeaderItem
+                    text: title
+                }
+
+                Graph {
+                    id: graph
+                    width: parent.width - Theme.horizontalPageMargin
+                    anchors.top: sectionHeaderItem.bottom
+                    height: (isPortrait ? (statsPage.height / 2.0) - Theme.paddingLarge : statsPage.height - Theme.paddingLarge - headerItem.height) - sectionHeaderItem.height
+                    anchors.left: parent.left
+                    bardata: barvalues
+                    //linedata: barvalues
+                    labelsx: labels
+                    //labelsy: ["0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"]
+                    unitsy: units
+                    primary: Theme.primaryColor
+                    secondary: Theme.highlightColor
+                    highlight: Theme.secondaryColor
+                    miny: minval
+                    maxy: maxval
+                    stepy: step
+                    gap: 0.1
+                    fontsize: Theme.fontSizeExtraSmall
+                    animate: (graphsView.currentItem === delegateItem) ? 1.0 : 0.0
+
+                    Behavior on animate {
+                        NumberAnimation {
+                            easing.type: Easing.OutExpo
+                            duration: 2000
+                        }
+                    }
+                }
             }
         }
     }
             }
         }
     }