jenkins-bot has submitted this change and it was merged.
Change subject: Updated shared graph lib - tabular support
..
Updated shared graph lib - tabular support
Change-Id: I5aaee38092fb277fc2409e07f51c1c3a808d333a
---
M lib/graph2.compiled.js
1 file changed, 25 insertions(+), 41 deletions(-)
Approvals:
MaxSem: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/graph2.compiled.js b/lib/graph2.compiled.js
index bd95538..933bf1c 100644
--- a/lib/graph2.compiled.js
+++ b/lib/graph2.compiled.js
@@ -316,7 +316,6 @@
case 'wikiraw:':
case 'tabular:':
-case 'tabularinfo:':
// wikiraw:///MyPage/data
// Get content of a wiki page, where the path is the title
// of the page with an additional leading '/' which gets
removed.
@@ -403,20 +402,23 @@
// Converts it into a snapshot image request for Kartotherian:
//
https://maps.wikimedia.org/img/{style},{zoom},{lat},{lon},{width}x{height}[@{scale}x].{format}
// (scale will be set to 2, and format to png)
-// Uses the same configuration as geoshape service, so reuse
settings
-this._validateExternalService(urlParts, sanitizedHost,
opt.url, 'geoshape:');
if (!urlParts.query) {
throw new Error('mapsnapshot: missing required
parameters');
}
+validate(urlParts, 'width', 1, 4096);
+validate(urlParts, 'height', 1, 4096);
+validate(urlParts, 'zoom', 0, 22);
+validate(urlParts, 'lat', -90, 90, true);
+validate(urlParts, 'lon', -180, 180, true);
+
var query = urlParts.query;
-validate(query, 'width', 1, 4096);
-validate(query, 'height', 1, 4096);
-validate(query, 'zoom', 0, 22);
-validate(query, 'lat', -90, 90, true);
-validate(query, 'lon', -180, 180, true);
if (query.style && !/^[-_0-9a-z]$/.test(query.style)) {
throw new Error('mapsnapshot: if style is given, it must
be letters/numbers/dash/underscores only');
}
+
+// Uses the same configuration as geoshape service, so reuse
settings
+this._validateExternalService(urlParts, sanitizedHost,
opt.url, 'geoshape:');
+
urlParts.pathname = '/img/' + (query.style || 'osm-intl') +
',' + query.zoom + ',' +
query.lat + ',' + query.lon + ',' + query.width + 'x' +
query.height + '@2x.png';
urlParts.query = {}; // deleting it would cause errors in
mw.Uri()
@@ -430,19 +432,18 @@
return this.formatUrl(urlParts, opt);
};
-function validate(obj, name, min, max, isFloat) {
-if (!obj.hasOwnProperty(name)) {
-throw new Error('mapsnapshot: parameter ' + name + ' is not set');
+function validate(urlParts, name, min, max, isFloat) {
+var value = urlParts.query[name];
+if (value === undefined) {
+throw new Error(urlParts.protocol + ' parameter ' + name + ' is not
set');
}
-var value = obj[name];
if (!(isFloat ? /^-?[0-9]+\.?[0-9]*$/ : /^-?[0-9]+$/).test(value)) {
-throw new Error('mapsnapshot: parameter ' + name + ' is not a number');
+throw new Error(urlParts.protocol + ' parameter ' + name + ' is not a
number');
}
value = isFloat ? parseFloat(value) : parseInt(value);
if (value < min || value > max) {
-throw new Error('mapsnapshot: parameter ' + name + ' is not valid');
+throw new Error(urlParts.protocol + ' parameter ' + name + ' is not
valid');
}
-return value;
}
VegaWrapper.prototype._validateExternalService = function
_validateExternalService(urlParts, sanitizedHost, url, protocolOverride) {
@@ -495,7 +496,6 @@
* Performs post-processing of the data requested by the graph's spec, and
throw on error
*/
VegaWrapper.prototype.parseDataOrThrow = function parseDataOrThrow(data, opt) {
-var result;
switch (opt.graphProtocol) {
case 'wikiapi:':
data = this.parseMWApiResponse(data);
@@ -510,30 +510,14 @@
break;
case 'tabular:':
data = this.parseMWApiResponse(data).jsondata;
-result = [];
-data.rows.forEach(function(v) {
-var row = {};
-for (var i = 0; i < data.headers.length; i++) {
-row[data.headers[i]] = v[i];
+var fields = data.schema.fields.map(function(v) { return v.name;
});
+data.data = data.data.map(function(v) {
+var row = {}, i;
+for (i = 0; i < fields.length; i++) {
+row[fields[i]] = v[i];
}
-result.push(row);
+return row;