Skip to content

Commit

Permalink
Added some method for us unemployment example
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornd committed Jun 10, 2012
1 parent 69e26c6 commit b5d6bb3
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/data-series.js
Expand Up @@ -14,7 +14,7 @@ jvm.DataSeries = function(params, elements) {
this.setAttributes(params.attributes); 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) { if (params.values) {
this.values = params.values; this.values = params.values;
this.setValues(params.values); this.setValues(params.values);
Expand All @@ -38,19 +38,25 @@ jvm.DataSeries.prototype = {
}, },


setValues: function(values) { setValues: function(values) {
var max = 0, var max = Number.MIN_VALUE,
min = Number.MAX_VALUE, min = Number.MAX_VALUE,
val, val,
cc, cc,
attrs = {}; attrs = {};


for (cc in values) { if (!this.params.min || !this.params.max) {
val = parseFloat(values[cc]); for (cc in values) {
if (val > max) max = values[cc]; val = parseFloat(values[cc]);
if (val && val < min) min = val; 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) { for (cc in values) {
val = parseFloat(values[cc]); val = parseFloat(values[cc]);
Expand Down
64 changes: 64 additions & 0 deletions lib/jvectormap.js
Expand Up @@ -15,5 +15,69 @@ var jvm = {
target.prototype[prop] = source.prototype[prop]; 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.