-
Notifications
You must be signed in to change notification settings - Fork 82
/
QChart.qml
99 lines (81 loc) · 2.67 KB
/
QChart.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* QChart.qml ---
*
* Author: Julien Wintz
* Created: Thu Feb 13 20:59:40 2014 (+0100)
* Version:
* Last-Updated: Thu Feb 13 23:57:44 2014 (+0100)
* By: Julien Wintz
* Update #: 68
*/
/* Change Log:
*
*/
import QtQuick 2.2
import "QChart.js" as Charts
Canvas {
id: canvas;
// ///////////////////////////////////////////////////////////////
property var chart;
property var chartData;
property int chartType: 0;
property bool chartAnimated: true;
property alias chartAnimationEasing: chartAnimator.easing.type;
property alias chartAnimationDuration: chartAnimator.duration;
property int chartAnimationProgress: 0;
// /////////////////////////////////////////////////////////////////
// Callbacks
// /////////////////////////////////////////////////////////////////
onPaint: {
if(!chart) {
switch(chartType) {
case Charts.ChartType.BAR:
chart = new Charts.Chart(this, this.getContext("2d")).Bar(chartData);
break;
case Charts.ChartType.DOUGHNUT:
chart = new Charts.Chart(this, this.getContext("2d")).Doughnut(chartData);
break;
case Charts.ChartType.LINE:
chart = new Charts.Chart(this, this.getContext("2d")).Line(chartData);
break;
case Charts.ChartType.PIE:
chart = new Charts.Chart(this, this.getContext("2d")).Pie(chartData);
break;
case Charts.ChartType.POLAR:
chart = new Charts.Chart(this, this.getContext("2d")).PolarArea(chartData);
break;
case Charts.ChartType.RADAR:
chart = new Charts.Chart(this, this.getContext("2d")).Radar(chartData);
break;
default:
console.log('Chart type should be specified.');
}
chart.init();
if (chartAnimated)
chartAnimator.start();
else
chartAnimationProgress = 100;
}
chart.draw(chartAnimationProgress/100);
}
onChartAnimationProgressChanged: {
requestPaint();
}
// /////////////////////////////////////////////////////////////////
// Functions
// /////////////////////////////////////////////////////////////////
function repaint() {
chartAnimationProgress = 0;
chartAnimator.start();
}
// /////////////////////////////////////////////////////////////////
// Internals
// /////////////////////////////////////////////////////////////////
PropertyAnimation {
id: chartAnimator;
target: canvas;
property: "chartAnimationProgress";
to: 100;
duration: 500;
easing.type: Easing.InOutElastic;
}
}