[MediaWiki-commits] [Gerrit] mediawiki...Graph[master]: Updated shared graph lib - tabular support

2016-12-05 Thread jenkins-bot (Code Review)
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;

[MediaWiki-commits] [Gerrit] mediawiki...Graph[master]: Updated shared graph lib - tabular support

2016-12-03 Thread Yurik (Code Review)
Yurik has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/325143

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, 9 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Graph 
refs/changes/43/325143/1

diff --git a/lib/graph2.compiled.js b/lib/graph2.compiled.js
index bd95538..d1bb42e 100644
--- a/lib/graph2.compiled.js
+++ b/lib/graph2.compiled.js
@@ -495,7 +495,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 +509,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;
 });
-data = result;
-break;
-case 'tabularinfo:':
-data = this.parseMWApiResponse(data).jsondata;
-result = {
-license: data.license,
-info: data.info,
-types: {},
-titles: {},
-count: data.rows ? data.rows.length : 0
-};
-for (var i = 0; i < data.headers.length; i++) {
-result.types[data.headers[i]] = data.types[i];
-result.titles[data.headers[i]] = data.titles[i];
-}
-data = result;
 break;
 case 'wikidatasparql:':
 data = JSON.parse(data);
@@ -568,10 +551,10 @@
'use strict';
/* global require */
 
-   var wrapper,
-   VegaWrapper = require( 'graph-shared' );
+   var VegaWrapper = require( 'graph-shared' );
 
-   wrapper = new VegaWrapper( {
+   // eslint-disable-next-line no-new
+   new VegaWrapper( {
datalib: vg.util,
useXhr: true,
isTrusted: mw.config.get( 'wgGraphIsTrusted' ),

-- 
To view, visit https://gerrit.wikimedia.org/r/325143
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5aaee38092fb277fc2409e07f51c1c3a808d333a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Graph
Gerrit-Branch: master
Gerrit-Owner: Yurik 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits