-
Notifications
You must be signed in to change notification settings - Fork 0
/
Coin.qml
151 lines (124 loc) · 2.96 KB
/
Coin.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import QtQuick 2.0
import QtCharts 2.0
Item {
property string symbolId
property string dataSource
property alias _name: nameLabel.text;
property alias _euro: valueEURO.text;
property real _percentage: 0.0
height: chart.height
signal doUpdate();
onDoUpdate: {
var doc = new XMLHttpRequest();
doc.onreadystatechange = function() {
if (doc.readyState == XMLHttpRequest.DONE) {
var value = 0;
if(dataSource == "coinmarketcap")
{
var a = doc.responseText;
var jsonObject = eval('(' + a + ')');
_name = jsonObject[0]["name"]
value = parseFloat(jsonObject[0]["price_eur"])
_euro = Math.round(value*100)/100 + "€"
_percentage = jsonObject[0]["percent_change_24h"]
}
else if(dataSource == "googlestock")
{
var a = doc.responseText;
a = a.substring(3)
var jsonObject = eval('(' + a + ')');
_name = jsonObject[0]["name"]
value = parseFloat(jsonObject[0]["l"]);
value = value * appWindow.exchangeRates.usdToEuro
_euro = Math.round(value*100)/100 + "€"
_percentage = jsonObject[0]["c"]
}
historySeries.update(value)
}
}
if(dataSource == 'coinmarketcap')
{
doc.open("GET", "https://api.coinmarketcap.com/v1/ticker/%1/?convert=EUR".arg(symbolId));
}
else if(dataSource == 'googlestock')
{
doc.open("GET", "https://finance.google.com/finance?q=%1&output=json".arg(symbolId));
}
doc.send();
}
Text {
id: nameLabel
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
}
Row {
anchors.right: chart.left
spacing: 2
id: data
anchors.verticalCenter: parent.verticalCenter
Text {
id: valueEURO;
}
Text {
id: percent;
text: "(%1%)".arg(_percentage)
color: _percentage < 0 ? "red" : "green"
}
}
Item {
id:chart
width: 40
height: data.height
anchors.right: parent.right
ChartView {
x: -10
y: -10
width: parent.width+20
height: parent.height+20
antialiasing: true
backgroundRoundness: 0.0
backgroundColor: "transparent"
legend.visible: false
margins {
bottom: 0
top: 0
right: 0
left: 0
}
ValueAxis {
id: axisX
visible: false
}
ValueAxis {
id: axisY
visible: false
}
LineSeries {
id: historySeries
axisX: axisX
axisY: axisY
pointLabelsVisible: false
property int i : 0;
property int maxPoints: chart.width/2
function update(value) {
if(i > maxPoints)
{
historySeries.remove(0)
}
historySeries.append(i, value)
i=i+1
axisX.min = historySeries.at(0).x
axisY.min = historySeries.at(0).y
axisY.max = axisY.min
for(var pi=0;pi<historySeries.count;pi++) {
axisY.min = Math.min(axisY.min, historySeries.at(pi).y)
axisY.max = Math.max(axisY.max, historySeries.at(pi).y)
axisX.max = historySeries.at(pi).x
}
axisY.min -= 5
axisY.max += 5
}
}
}
}
}