Skip to content
Browse files

Added some method for us unemployment example

  • Loading branch information...
1 parent 69e26c6 commit b5d6bb3411e57c67b64408b47d9641ffa7c71f5b @bjornd committed Jun 10, 2012
Showing with 78 additions and 8 deletions.
  1. +14 −8 lib/data-series.js
  2. +64 −0 lib/jvectormap.js
View
22 lib/data-series.js
@@ -14,7 +14,7 @@ jvm.DataSeries = function(params, elements) {
this.setAttributes(params.attributes);
}
- this.scale = new scaleConstructor(params.scale, params.normalizeFunction, params.valueMin, params.valueMax);
+ this.scale = new scaleConstructor(params.scale, params.normalizeFunction, params.min, params.max);
if (params.values) {
this.values = params.values;
this.setValues(params.values);
@@ -38,19 +38,25 @@ jvm.DataSeries.prototype = {
},
setValues: function(values) {
- var max = 0,
+ var max = Number.MIN_VALUE,
min = Number.MAX_VALUE,
val,
cc,
attrs = {};
- for (cc in values) {
- val = parseFloat(values[cc]);
- if (val > max) max = values[cc];
- if (val && val < min) min = val;
+ if (!this.params.min || !this.params.max) {
+ for (cc in values) {
+ val = parseFloat(values[cc]);
+ if (val > max) max = values[cc];
+ if (val < min) min = val;
+ }
+ }
+ if (!this.params.min) {
+ this.scale.setMin(min);
+ }
+ if (!this.params.max) {
+ this.scale.setMax(max);
}
- this.scale.setMin(min);
- this.scale.setMax(max);
for (cc in values) {
val = parseFloat(values[cc]);
View
64 lib/jvectormap.js
@@ -15,5 +15,69 @@ var jvm = {
target.prototype[prop] = source.prototype[prop];
}
}
+ },
+
+ min: function(values){
+ var min = Number.MAX_VALUE,
+ i;
+
+ if (values instanceof Array) {
+ for (i = 0; i < values.length; i++) {
+ if (values[i] < min) {
+ min = values[i];
+ }
+ }
+ } else {
+ for (i in values) {
+ if (values[i] < min) {
+ min = values[i];
+ }
+ }
+ }
+ return min;
+ },
+
+ max: function(values){
+ var max = Number.MIN_VALUE,
+ i;
+
+ if (values instanceof Array) {
+ for (i = 0; i < values.length; i++) {
+ if (values[i] > max) {
+ max = values[i];
+ }
+ }
+ } else {
+ for (i in values) {
+ if (values[i] > max) {
+ max = values[i];
+ }
+ }
+ }
+ return max;
+ },
+
+ keys: function(object){
+ var keys = [],
+ key;
+
+ for (key in object) {
+ keys.push(key);
+ }
+ return keys;
+ },
+
+ values: function(object){
+ var values = [],
+ key,
+ i;
+
+ for (i = 0; i < arguments.length; i++) {
+ object = arguments[i];
+ for (key in object) {
+ values.push(object[key]);
+ }
+ }
+ return values;
}
};

0 comments on commit b5d6bb3

Please sign in to comment.
Something went wrong with that request. Please try again.