|
@@
-31,23
+31,21
Rectangle {
|
|
31
|
anchors.bottom: weatherImageRow.top
|
|
31
|
anchors.bottom: weatherImageRow.top
|
|
32
|
anchors.left: parent.left
|
|
32
|
anchors.left: parent.left
|
|
33
|
anchors.right: parent.right
|
|
33
|
anchors.right: parent.right
|
|
|
|
|
34
|
title: "Weather forecast"
|
|
34
|
axisX.min: 0
|
|
35
|
axisX.min: 0
|
|
35
|
axisX.max: 6
|
|
36
|
axisX.max: 4
|
|
36
|
axisY.min: 0
|
|
37
|
axisY.min: 0
|
|
37
|
axisY.max: 50
|
|
38
|
axisY.max: 0
|
|
38
|
|
|
39
|
legend: ChartView.LegendTop
|
|
39
|
// TODO: implement categories
|
|
|
|
|
40
|
// AxisCategory { axis: AxisCategory.AxisX; value: 0.0; label: "" }
|
|
|
|
|
41
|
// AxisCategory { axis: AxisCategory.AxisX; value: 1.0; label: "Today" }
|
|
|
|
|
42
|
// AxisCategory { axis: AxisCategory.AxisX; value: 2.0; label: "Tomorrow" }
|
|
|
|
|
43
|
// AxisCategory { axis: AxisCategory.AxisX; value: 3.0; label: "Day after tomorrow" }
|
|
|
|
|
44
|
|
|
40
|
|
|
45
|
LineSeries {
|
|
41
|
LineSeries {
|
|
46
|
model: maxModel
|
|
42
|
model: maxModel
|
|
|
|
|
43
|
name: "Max. temperature"
|
|
47
|
}
|
|
44
|
}
|
|
48
|
|
|
45
|
|
|
49
|
LineSeries {
|
|
46
|
LineSeries {
|
|
50
|
model: minModel
|
|
47
|
model: minModel
|
|
|
|
|
48
|
name: "Min. temperature"
|
|
51
|
}
|
|
49
|
}
|
|
52
|
|
|
50
|
|
|
53
|
// TODO: use a single base model with mappings instead of two separate xy models
|
|
51
|
// TODO: use a single base model with mappings instead of two separate xy models
|
|
@@
-80,33
+78,46
Rectangle {
|
|
80
|
}
|
|
78
|
}
|
|
81
|
|
|
79
|
|
|
82
|
Component.onCompleted: {
|
|
80
|
Component.onCompleted: {
|
|
83
|
// TODO: use live data instead of hard coded example data
|
|
81
|
if (weatherAppKey != "") {
|
|
84
|
// in case an application key was defined for this demo app
|
|
82
|
var xhr = new XMLHttpRequest;
|
|
85
|
// var xhr = new XMLHttpRequest;
|
|
83
|
xhr.open("GET", "http://free.worldweatheronline.com/feed/weather.ashx?q=Jyv%c3%a4skyl%c3%a4,Finland&format=json&num_of_days=5&key=" + weatherAppKey);
|
|
86
|
// var appKey = "";
|
|
84
|
xhr.onreadystatechange = function() {
|
|
87
|
// xhr.open("GET", "http://free.worldweatheronline.com/feed/weather.ashx?q=Jyv%c3%a4skyl%c3%a4,Finland&format=json&num_of_days=5&key=" + appKey");
|
|
85
|
if (xhr.readyState == XMLHttpRequest.DONE) {
|
|
88
|
// xhr.onreadystatechange = function() {
|
|
86
|
var a = JSON.parse(xhr.responseText);
|
|
89
|
// if (xhr.readyState == XMLHttpRequest.DONE) {
|
|
87
|
parseWeatherData(a);
|
|
90
|
// var a = JSON.parse(xhr.responseText);
|
|
88
|
}
|
|
91
|
// console.log("a: " + a);
|
|
89
|
}
|
|
92
|
// console.log("response: " + xhr.responseText);
|
|
90
|
xhr.send();
|
|
93
|
// for (var b in a) {
|
|
91
|
} else {
|
|
94
|
// var o = a[b];
|
|
92
|
// No app key for worldweatheronline.com given by the user -> use static data
|
|
95
|
// console.log("o: " + o);
|
|
93
|
var responseText = "{ \"data\": { \"current_condition\": [ {\"cloudcover\": \"10\", \"humidity\": \"61\", \"observation_time\": \"06:26 AM\", \"precipMM\": \"0.0\", \"pressure\": \"1022\", \"temp_C\": \"6\", \"temp_F\": \"43\", \"visibility\": \"10\", \"weatherCode\": \"113\", \"weatherDesc\": [ {\"value\": \"Sunny\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png\" } ], \"winddir16Point\": \"SE\", \"winddirDegree\": \"140\", \"windspeedKmph\": \"7\", \"windspeedMiles\": \"4\" } ], \"request\": [ {\"query\": \"Jyvaskyla, Finland\", \"type\": \"City\" } ], \"weather\": [ {\"date\": \"2012-05-09\", \"precipMM\": \"0.4\", \"tempMaxC\": \"14\", \"tempMaxF\": \"57\", \"tempMinC\": \"7\", \"tempMinF\": \"45\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"S\", \"winddirDegree\": \"179\", \"winddirection\": \"S\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-10\", \"precipMM\": \"2.4\", \"tempMaxC\": \"13\", \"tempMaxF\": \"55\", \"tempMinC\": \"8\", \"tempMinF\": \"46\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SW\", \"winddirDegree\": \"219\", \"winddirection\": \"SW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" }, {\"date\": \"2012-05-11\", \"precipMM\": \"11.1\", \"tempMaxC\": \"15\", \"tempMaxF\": \"59\", \"tempMinC\": \"7\", \"tempMinF\": \"44\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SSW\", \"winddirDegree\": \"200\", \"winddirection\": \"SSW\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-12\", \"precipMM\": \"2.8\", \"tempMaxC\": \"7\", \"tempMaxF\": \"44\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"317\", \"weatherDesc\": [ {\"value\": \"Light sleet\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0021_cloudy_with_sleet.png\" } ], \"winddir16Point\": \"NW\", \"winddirDegree\": \"311\", \"winddirection\": \"NW\", \"windspeedKmph\": \"24\", \"windspeedMiles\": \"15\" }, {\"date\": \"2012-05-13\", \"precipMM\": \"0.4\", \"tempMaxC\": \"6\", \"tempMaxF\": \"42\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"WNW\", \"winddirDegree\": \"281\", \"winddirection\": \"WNW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" } ] }}";
|
|
96
|
//// model.append({id: o.id, name: o.name, duration: o.duration});
|
|
94
|
var a = JSON.parse(responseText);
|
|
97
|
// }
|
|
95
|
parseWeatherData(a);
|
|
98
|
// }
|
|
96
|
}
|
|
99
|
// }
|
|
97
|
}
|
|
100
|
// xhr.send();
|
|
98
|
|
|
101
|
|
|
99
|
function parseWeatherData(weatherData) {
|
|
102
|
var responseText = "{ \"data\": { \"current_condition\": [ {\"cloudcover\": \"10\", \"humidity\": \"61\", \"observation_time\": \"06:26 AM\", \"precipMM\": \"0.0\", \"pressure\": \"1022\", \"temp_C\": \"6\", \"temp_F\": \"43\", \"visibility\": \"10\", \"weatherCode\": \"113\", \"weatherDesc\": [ {\"value\": \"Sunny\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png\" } ], \"winddir16Point\": \"SE\", \"winddirDegree\": \"140\", \"windspeedKmph\": \"7\", \"windspeedMiles\": \"4\" } ], \"request\": [ {\"query\": \"Jyvaskyla, Finland\", \"type\": \"City\" } ], \"weather\": [ {\"date\": \"2012-05-09\", \"precipMM\": \"0.4\", \"tempMaxC\": \"14\", \"tempMaxF\": \"57\", \"tempMinC\": \"7\", \"tempMinF\": \"45\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"S\", \"winddirDegree\": \"179\", \"winddirection\": \"S\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-10\", \"precipMM\": \"2.4\", \"tempMaxC\": \"13\", \"tempMaxF\": \"55\", \"tempMinC\": \"8\", \"tempMinF\": \"46\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SW\", \"winddirDegree\": \"219\", \"winddirection\": \"SW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" }, {\"date\": \"2012-05-11\", \"precipMM\": \"11.1\", \"tempMaxC\": \"15\", \"tempMaxF\": \"59\", \"tempMinC\": \"7\", \"tempMinF\": \"44\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SSW\", \"winddirDegree\": \"200\", \"winddirection\": \"SSW\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-12\", \"precipMM\": \"2.8\", \"tempMaxC\": \"7\", \"tempMaxF\": \"44\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"317\", \"weatherDesc\": [ {\"value\": \"Light sleet\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0021_cloudy_with_sleet.png\" } ], \"winddir16Point\": \"NW\", \"winddirDegree\": \"311\", \"winddirection\": \"NW\", \"windspeedKmph\": \"24\", \"windspeedMiles\": \"15\" }, {\"date\": \"2012-05-13\", \"precipMM\": \"0.4\", \"tempMaxC\": \"6\", \"tempMaxF\": \"42\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"WNW\", \"winddirDegree\": \"281\", \"winddirection\": \"WNW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" } ] }}";
|
|
100
|
for (var i in weatherData.data.weather) {
|
|
103
|
var a = JSON.parse(responseText);
|
|
101
|
var weatherObj = weatherData.data.weather[i];
|
|
104
|
|
|
102
|
|
|
105
|
for (var i in a.data.weather) {
|
|
103
|
// Add min and max temperature values into models used by series
|
|
106
|
var weatherObj = a.data.weather[i];
|
|
104
|
maxModel.append([Number(i), weatherObj.tempMaxC]);
|
|
107
|
maxModel.append([Number(i) + 1, weatherObj.tempMaxC]);
|
|
105
|
minModel.append([Number(i), weatherObj.tempMinC]);
|
|
108
|
minModel.append([Number(i) + 1, weatherObj.tempMinC]);
|
|
|
|
|
109
|
weatherImageModel.append({"imageSource":weatherObj.weatherIconUrl[0].value});
|
|
106
|
weatherImageModel.append({"imageSource":weatherObj.weatherIconUrl[0].value});
|
|
|
|
|
107
|
|
|
|
|
|
108
|
// Update scale of the chart
|
|
|
|
|
109
|
while (chartView.axisY.min >= Number(weatherObj.tempMinC))
|
|
|
|
|
110
|
chartView.axisY.min = chartView.axisY.min - 10;
|
|
|
|
|
111
|
while (chartView.axisY.max <= Number(weatherObj.tempMaxC))
|
|
|
|
|
112
|
chartView.axisY.max = chartView.axisY.max + 10;
|
|
|
|
|
113
|
|
|
|
|
|
114
|
// Set the x-axis labels to the dates of the forecast
|
|
|
|
|
115
|
// TODO: the API could probably be more intuitive..
|
|
|
|
|
116
|
// Now it takes an array of strings: chartView.axisXLabels = ["value1", "label1", "value2", "label2", ...]
|
|
|
|
|
117
|
var xLabels = chartView.axisXLabels;
|
|
|
|
|
118
|
xLabels[Number(i) * 2] = i;
|
|
|
|
|
119
|
xLabels[(Number(i) * 2) + 1] = weatherObj.date.substring(5, 10);
|
|
|
|
|
120
|
chartView.axisXLabels = xLabels;
|
|
110
|
}
|
|
121
|
}
|
|
111
|
}
|
|
122
|
}
|
|
112
|
|
|
123
|
|