diff --git a/app/rollerverbrauch/__init__.py b/app/rollerverbrauch/__init__.py index 495ab17..664e15d 100644 --- a/app/rollerverbrauch/__init__.py +++ b/app/rollerverbrauch/__init__.py @@ -179,7 +179,7 @@ def create_pit_stop_form(vid): form.litres.default = last_pitstop.litres form.date.default = date.today() form.process() - return render_template('newPitStopForm.html', form=form, vehicle = vehicle) + return render_template('newPitStopForm.html', form=form, vehicle=vehicle) @app.route('/pitstops', methods=['GET']) diff --git a/app/rollerverbrauch/filters.py b/app/rollerverbrauch/filters.py index 00a0e59..f3ce080 100644 --- a/app/rollerverbrauch/filters.py +++ b/app/rollerverbrauch/filters.py @@ -1,4 +1,5 @@ from rollerverbrauch import app +import hashlib @app.template_filter('none_filter') @@ -7,3 +8,15 @@ def none_filter(value): return '' else: return value + + +@app.template_filter('md5') +def md5_filter(value): + m = hashlib.md5() + m.update(str(value).encode('UTF-8')) + return m.hexdigest() + + +@app.template_filter('str') +def str_filter(value): + return str(value) diff --git a/app/rollerverbrauch/static/main.js b/app/rollerverbrauch/static/main.js index 8b13789..4f1b963 100644 --- a/app/rollerverbrauch/static/main.js +++ b/app/rollerverbrauch/static/main.js @@ -1 +1,80 @@ - +function createChart(id, data, unit) { + return AmCharts.makeChart(id, { + "type": "serial", + //"theme": "chalk", + //"marginRight": 40, + //"marginLeft": 40, + //"autoMarginOffset": 20, + "mouseWheelZoomEnabled":true, + "dataDateFormat": "YYYY-MM-DD", + "valueAxes": [{ + "id": "v1", + "axisAlpha": 0, + "position": "left", + "ignoreAxisWidth":true, +// "title": unit + }], + "balloon": { + "borderThickness": 1, + "shadowAlpha": 10, + }, + "graphs": [{ + "id": "g1", + "balloon":{ + "drop":false, + "adjustBorderColor":false, + "color":"#ffffff", + }, + "bullet": "round", + "bulletBorderAlpha": 1, + "bulletColor": "#000000", + "bulletSize": 5, + "hideBulletsCount": 50, + "lineThickness": 2, + // "title": unit, + //"useLineColorForBulletBorder": true, + "valueField": "value", + "balloonText": "[[value]] "+unit+"" + }], + "chartScrollbar": { + "graph": "g1", + "oppositeAxis":false, + "offset":30, + "scrollbarHeight": 80, + "backgroundAlpha": 0, + "selectedBackgroundAlpha": 0.1, + "selectedBackgroundColor": "#888888", + "graphFillAlpha": 0, + "graphLineAlpha": 0.5, + "selectedGraphFillAlpha": 0, + "selectedGraphLineAlpha": 1, + "autoGridCount":true, + "color":"#AAAAAA" + }, + "chartCursor": { + "pan": true, + "valueLineEnabled": true, + "valueLineBalloonEnabled": true, + "cursorAlpha":1, + "cursorColor":"#258cbb", + "limitToGraph":"g1", + "valueLineAlpha":0.2, + "valueZoomable":true + }, + "valueScrollbar":{ + "oppositeAxis":false, + "offset":50, + "scrollbarHeight":10 + }, + "categoryField": "date", + "categoryAxis": { + "parseDates": true, + "dashLength": 1, +// "minorGridEnabled": true + }, + "export": { + "enabled": true + }, + "dataProvider": data + }); +} diff --git a/app/rollerverbrauch/templates/layout.html b/app/rollerverbrauch/templates/layout.html index e44af45..8b7e982 100644 --- a/app/rollerverbrauch/templates/layout.html +++ b/app/rollerverbrauch/templates/layout.html @@ -59,6 +59,31 @@ {% endmacro %} +{% macro chartScript(divId, data, unit)%} + {% set hash = divId | md5 %} + + data_{{ hash }} = [{% for stop in data %}{ + "date": "{{stop.date}}", + "value": {{stop.value}} + }{% if not loop.last %},{%endif%} + {% endfor%} + ] + var chart_{{ hash }} = createChart('{{divId}}', data_{{ hash }}, '{{unit}}'); + + function zoom_chart_{{ hash }}() { + chart_{{ hash }}.zoomToIndexes( + chart_{{ hash }}.dataProvider.length - 40, + chart_{{ hash }}.dataProvider.length - 1 + ); + } + + chart_{{ hash }}.addListener("rendered", zoom_chart_{{ hash }}); + + zoom_chart_{{ hash }}() + +{% endmacro %} + + @@ -94,6 +119,10 @@ + + + +