Daniel Werner has submitted this change and it was merged.
Change subject: [coordinate.js] Optimized precision handling
......................................................................
[coordinate.js] Optimized precision handling
GlobeCoordinate object only deals with "valid" precisions registered in the
globeCoordinate
settings now.
Change-Id: Ib6ed7a98718a2b4f6bb9d8e9dfedb176cc359be4
---
M DataValues/resources/globeCoordinate.js/src/globeCoordinate.GlobeCoordinate.js
M DataValues/resources/globeCoordinate.js/src/globeCoordinate.js
M DataValues/resources/globeCoordinate.js/tests/globeCoordinate.tests.js
M
ValueView/resources/jquery.valueview/valueview.experts/experts.GlobeCoordinateInput.js
4 files changed, 62 insertions(+), 54 deletions(-)
Approvals:
Daniel Werner: Looks good to me, approved
jenkins-bot: Verified
diff --git
a/DataValues/resources/globeCoordinate.js/src/globeCoordinate.GlobeCoordinate.js
b/DataValues/resources/globeCoordinate.js/src/globeCoordinate.GlobeCoordinate.js
index e00daae..06f1b0d 100644
---
a/DataValues/resources/globeCoordinate.js/src/globeCoordinate.GlobeCoordinate.js
+++
b/DataValues/resources/globeCoordinate.js/src/globeCoordinate.GlobeCoordinate.js
@@ -12,7 +12,7 @@
* @dependency globeCoordinate
* @dependency globeCoordinate.parser
*/
-globeCoordinate.GlobeCoordinate = ( function( globeCcoordinate,
globeCoordinateParser ) {
+globeCoordinate.GlobeCoordinate = ( function( globeCoordinate,
globeCoordinateParser ) {
'use strict';
/**
@@ -59,7 +59,20 @@
// TODO: Capture altitude and globe
}
- this._globe = 'http://wikidata.org/id/Q2'; // TODO: Support
other globes
+ // Keep precision boundaries:
+ // TODO: get definition of precisions out of global settings
and put them into
+ // a globeCoordinate.GlobeCoordinate.PRECISION constant.
+ var precisions = globeCoordinate.settings.precisions,
+ minPrecision = precisions[0].level,
+ maxPrecision = precisions[precisions.length - 1].level;
+
+ if( this._precision > minPrecision ) {
+ this._precision = minPrecision;
+ } else if( this._precision < maxPrecision ) {
+ this._precision = maxPrecision;
+ }
+
+ this._globe = 'http://www.wikidata.org/entity/Q2'; // TODO:
Support other globes
}
GlobeCoordinate.prototype = {
diff --git a/DataValues/resources/globeCoordinate.js/src/globeCoordinate.js
b/DataValues/resources/globeCoordinate.js/src/globeCoordinate.js
index 4e237c2..39e2aa4 100644
--- a/DataValues/resources/globeCoordinate.js/src/globeCoordinate.js
+++ b/DataValues/resources/globeCoordinate.js/src/globeCoordinate.js
@@ -36,14 +36,14 @@
{ level: 0.1 },
{ level: 1 / 60, text: 'to an arcminute' },
{ level: 0.01 },
- { level: 1 / 3600, text: 'to an arcsecond' },
{ level: 0.001 },
- { level: 1 / 36000, text: 'to 1/10 of an
arcsecond' },
+ { level: 1 / 3600, text: 'to an arcsecond' },
{ level: 0.0001 },
- { level: 1 / 360000, text: 'to 1/100 of an
arcsecond' },
+ { level: 1 / 36000, text: 'to 1/10 of an
arcsecond' },
{ level: 0.00001 },
- { level: 1 / 3600000, text: 'to 1/1000 of an
arcsecond' },
- { level: 0.000001 }
+ { level: 1 / 360000, text: 'to 1/100 of an
arcsecond' },
+ { level: 0.000001 },
+ { level: 1 / 3600000, text: 'to 1/1000 of an
arcsecond' }
]
},
@@ -58,16 +58,17 @@
for( var i in this.settings.precisions ) {
if(
this.settings.precisions.hasOwnProperty( i )
- && this.settings.precisions[i].level
=== precision
+ && Math.abs( precision -
this.settings.precisions[i].level ) < 0.0000001
) {
- return i;
+ return parseInt( i, 10 );
}
}
return -1;
},
/**
- * Returns the given precision increased by one step.
+ * Returns the given precision increased by one step or -1 if
the current precision is
+ * invalid.
*
* @param {number} precision
* @return {number}
@@ -75,34 +76,34 @@
increasePrecision: function( precision ) {
var index = this.getPrecisionIndex( precision );
- if( index === this.settings.precisions.length - 1 ||
index === -1 ) {
- var newPrecision = precision / 10;
- return ( newPrecision < 1e-9 ) ? 1e-9 :
newPrecision;
+ // Current precision is invalid:
+ if( index === -1 ) {
+ return -1;
}
- return this.settings.precisions[index + 1].level;
+ return ( index + 1 < this.settings.precisions.length )
+ ? this.settings.precisions[index + 1].level
+ : precision; // Highest precision is set
already.
},
/**
- * Returns the given precision decreased by one step.
+ * Returns the given precision decreased by one step or -1 if
the current precision is
+ * invalid.
*
* @param {number} precision
* @return {number}
*/
decreasePrecision: function( precision ) {
- if( precision < 1e-9) {
- return 1e-9;
- }
-
var index = this.getPrecisionIndex( precision );
- if( index === 0 ) {
- return 180;
- } else if( index < 0 ) {
- return Math.min( precision * 10, 180 );
+ // Current precision is invalid:
+ if( index === -1 ) {
+ return -1;
}
- return this.settings.precisions[index-1].level;
+ return ( index - 1 >= 0 )
+ ? this.settings.precisions[index - 1].level
+ : precision; // Lowest precision is set already.
},
/**
@@ -120,17 +121,14 @@
if(
this.settings.precisions.hasOwnProperty( i )
&& Math.abs( precision -
this.settings.precisions[i].level ) < 0.0000001
+ && this.settings.precisions[i].text
) {
precisionText =
this.settings.precisions[i].text;
}
}
if( !precisionText ) {
- if( precision < 9e-10 ) {
- precision = 1e-9;
- }
- // 0x000B1 is the plus/minus sign
- precisionText = String.fromCharCode( 0x00B1 ) +
precision + this.settings.degree;
+ precisionText = '±' + precision +
this.settings.degree;
}
return precisionText;
diff --git
a/DataValues/resources/globeCoordinate.js/tests/globeCoordinate.tests.js
b/DataValues/resources/globeCoordinate.js/tests/globeCoordinate.tests.js
index a790169..1347afd 100644
--- a/DataValues/resources/globeCoordinate.js/tests/globeCoordinate.tests.js
+++ b/DataValues/resources/globeCoordinate.js/tests/globeCoordinate.tests.js
@@ -13,10 +13,10 @@
var precisions = {
0: {
- tech: String.fromCharCode( 0x00B1 ) + '1e-9°',
+ tech: '±0°',
earth: '1 mm',
- increased: 1e-9,
- decreased: 1e-9,
+ increased: -1,
+ decreased: -1,
toDecimal: [0, 0.06, 0.4, 0.5, 1, 10],
toDegree: [
{ degree: 0, minute: 0, second: 0 },
@@ -43,10 +43,10 @@
]
},
2: {
- tech: String.fromCharCode( 0x00B1 ) + '2°',
+ tech: '±2°',
earth: '200 km',
- increased: 0.2,
- decreased: 20,
+ increased: -1,
+ decreased: -1,
toDecimal: [0, 0, 0, 1, 1, 10],
toDegree: [
{ degree: 0, minute: undefined, second:
undefined },
@@ -60,8 +60,8 @@
1.00000001: {
tech: 1,
earth: '100 km',
- increased: 0.10000000099999999,
- decreased: 10.0000001,
+ increased: 0.1,
+ decreased: 10,
toDecimal: [0, 0, 0, 1, 1, 10],
toDegree: [
{ degree: 0, minute: undefined, second:
undefined },
@@ -75,8 +75,8 @@
0.016666666666666666: {
tech: 1 / 60,
earth: '2 km',
- increased: 0.0016666666666666666,
- decreased: 0.16666666666666666,
+ increased: 0.01,
+ decreased: 0.1,
toDecimal: [0, 0.06, 0.4, 0.5, 1, 10],
toDegree: [
{ degree: 0, minute: 0, second: undefined },
@@ -90,8 +90,8 @@
2.7777777777777776e-7: {
tech: 1 / 3600000,
earth: '3 cm',
- increased: 2.7777777777777777e-8,
- decreased: 0.0000027777777777777775,
+ increased: 0.000001,
+ decreased: 0.00001,
toDecimal: [0, 0.06, 0.4, 0.5, 1, 10],
toDegree: [
{ degree: 0, minute: 0, second: 0 },
@@ -103,10 +103,10 @@
]
},
1.0000000001e-10: {
- tech: String.fromCharCode( 0x00B1 ) + '1e-9°',
+ tech: '±1.0000000001e-10°',
earth: '1 mm',
- increased: 1e-9,
- decreased: 1e-9,
+ increased: -1,
+ decreased: -1,
toDecimal: [0, 0.06, 0.4, 0.5, 1, 10],
toDegree: [
{ degree: 0, minute: 0, second: 0 },
@@ -118,10 +118,10 @@
]
},
1.0000001: {
- tech: String.fromCharCode( 0x00B1 ) + '1.0000001°',
+ tech: '±1.0000001°',
earth: '100 km',
- increased: 0.10000001,
- decreased: 10.000001000000001,
+ increased: -1,
+ decreased: -1,
toDecimal: [0, 0, 0, 1, 1, 10],
toDegree: [
{ degree: 0, minute: undefined, second:
undefined },
@@ -133,10 +133,10 @@
]
},
1.1: {
- tech: String.fromCharCode( 0x00B1 ) + '1.1°',
+ tech: '±1.1°',
earth: '100 km',
- increased: 0.11000000000000001,
- decreased: 11,
+ increased: -1,
+ decreased: -1,
toDecimal: [0, 0, 0, 1, 1, 10],
toDegree: [
{ degree: 0, minute: undefined, second:
undefined },
diff --git
a/ValueView/resources/jquery.valueview/valueview.experts/experts.GlobeCoordinateInput.js
b/ValueView/resources/jquery.valueview/valueview.experts/experts.GlobeCoordinateInput.js
index 13eb128..b19e328 100644
---
a/ValueView/resources/jquery.valueview/valueview.experts/experts.GlobeCoordinateInput.js
+++
b/ValueView/resources/jquery.valueview/valueview.experts/experts.GlobeCoordinateInput.js
@@ -68,10 +68,7 @@
var precisionValues = [];
$.each( globeCoordinateSettings.precisions, function(
i, precisionDefinition ) {
- var label = ( precisionDefinition.text )
- ? precisionDefinition.text
- : precisionDefinition.level;
-
+ var label = globeCoordinate.precisionText(
precisionDefinition.level );
precisionValues.push( { value:
precisionDefinition.level, label: label } );
} );
--
To view, visit https://gerrit.wikimedia.org/r/66244
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib6ed7a98718a2b4f6bb9d8e9dfedb176cc359be4
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits