jvectormap-rails 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +3 -0
- data/History.txt +3 -0
- data/LICENSE +21 -0
- data/README.md +4 -0
- data/Rakefile +38 -0
- data/jvectormap-rails.gemspec +20 -0
- data/lib/jvectormap-rails.rb +26 -0
- data/lib/jvectormap/rails/engine.rb +8 -0
- data/lib/jvectormap/rails/railtie.rb +17 -0
- data/lib/jvectormap/rails/version.rb +8 -0
- data/tasks/jvectormap.rake +6 -0
- data/vendor/assets/javascripts/jvectormap.js +26 -0
- data/vendor/assets/javascripts/jvectormap/jquery-jvectormap.js +45 -0
- data/vendor/assets/javascripts/jvectormap/jquery-mousewheel.js +84 -0
- data/vendor/assets/javascripts/jvectormap/lib/abstract-canvas-element.js +67 -0
- data/vendor/assets/javascripts/jvectormap/lib/abstract-element.js +73 -0
- data/vendor/assets/javascripts/jvectormap/lib/abstract-shape-element.js +85 -0
- data/vendor/assets/javascripts/jvectormap/lib/color-scale.js +44 -0
- data/vendor/assets/javascripts/jvectormap/lib/data-series.js +139 -0
- data/vendor/assets/javascripts/jvectormap/lib/jvectormap.js +99 -0
- data/vendor/assets/javascripts/jvectormap/lib/numeric-scale.js +147 -0
- data/vendor/assets/javascripts/jvectormap/lib/ordinal-scale.js +7 -0
- data/vendor/assets/javascripts/jvectormap/lib/proj.js +181 -0
- data/vendor/assets/javascripts/jvectormap/lib/simple-scale.js +7 -0
- data/vendor/assets/javascripts/jvectormap/lib/svg-canvas-element.js +22 -0
- data/vendor/assets/javascripts/jvectormap/lib/svg-circle-element.js +5 -0
- data/vendor/assets/javascripts/jvectormap/lib/svg-element.js +48 -0
- data/vendor/assets/javascripts/jvectormap/lib/svg-group-element.js +9 -0
- data/vendor/assets/javascripts/jvectormap/lib/svg-path-element.js +6 -0
- data/vendor/assets/javascripts/jvectormap/lib/svg-shape-element.js +7 -0
- data/vendor/assets/javascripts/jvectormap/lib/vector-canvas.js +16 -0
- data/vendor/assets/javascripts/jvectormap/lib/vml-canvas-element.js +45 -0
- data/vendor/assets/javascripts/jvectormap/lib/vml-circle-element.js +26 -0
- data/vendor/assets/javascripts/jvectormap/lib/vml-element.js +106 -0
- data/vendor/assets/javascripts/jvectormap/lib/vml-group-element.js +13 -0
- data/vendor/assets/javascripts/jvectormap/lib/vml-path-element.js +111 -0
- data/vendor/assets/javascripts/jvectormap/lib/vml-shape-element.js +49 -0
- data/vendor/assets/javascripts/jvectormap/lib/world-map.js +977 -0
- data/vendor/assets/javascripts/jvectormap/maps/ar_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/ar_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/at_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/at_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/au_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/au_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/be_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/be_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/ca_lcc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/ca_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/ca_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/ch_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/ch_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/cn_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/cn_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/co_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/co_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/de_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/de_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/dk_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/dk_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/es_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/es_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/europe_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/europe_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/fr_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/fr_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/in_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/in_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/it_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/it_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/nl_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/nl_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/no_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/no_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/nz_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/nz_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/ph_regions_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/ph_regions_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/pl_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/pl_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/pt_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/pt_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/se_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/se_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/th_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/th_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/th_regions_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/th_regions_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/uk_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/uk_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/us-il-chicago_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/us-ny-newyork_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/us_aea_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/us_lcc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/us_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/us_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/ve_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/ve_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/world_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/world_mill_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/za_merc_en.js +1 -0
- data/vendor/assets/javascripts/jvectormap/maps/za_mill_en.js +1 -0
- data/vendor/assets/stylesheets/jvectormap.css +37 -0
- metadata +165 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract shape element. Shape element represents some visual vector or raster object.
|
|
3
|
+
* @constructor
|
|
4
|
+
* @param {String} name Tag name of the element.
|
|
5
|
+
* @param {Object} config Set of parameters to initialize element with.
|
|
6
|
+
* @param {Object} style Object with styles to set on element initialization.
|
|
7
|
+
*/
|
|
8
|
+
jvm.AbstractShapeElement = function(name, config, style){
|
|
9
|
+
this.style = style || {};
|
|
10
|
+
this.style.current = {};
|
|
11
|
+
this.isHovered = false;
|
|
12
|
+
this.isSelected = false;
|
|
13
|
+
this.updateStyle();
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Set hovered state to the element. Hovered state means mouse cursor is over element. Styles will be updates respectively.
|
|
18
|
+
* @param {Boolean} isHovered <code>true</code> to make element hovered, <code>false</code> otherwise.
|
|
19
|
+
*/
|
|
20
|
+
jvm.AbstractShapeElement.prototype.setHovered = function(isHovered){
|
|
21
|
+
if (this.isHovered !== isHovered) {
|
|
22
|
+
this.isHovered = isHovered;
|
|
23
|
+
this.updateStyle();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Set selected state to the element. Styles will be updates respectively.
|
|
29
|
+
* @param {Boolean} isSelected <code>true</code> to make element selected, <code>false</code> otherwise.
|
|
30
|
+
*/
|
|
31
|
+
jvm.AbstractShapeElement.prototype.setSelected = function(isSelected){
|
|
32
|
+
if (this.isSelected !== isSelected) {
|
|
33
|
+
this.isSelected = isSelected;
|
|
34
|
+
this.updateStyle();
|
|
35
|
+
jvm.$(this.node).trigger('selected', [isSelected]);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Set element's style.
|
|
41
|
+
* @param {Object|String} property Could be string to set only one property or object to set several style properties at once.
|
|
42
|
+
* @param {String} value Value to set in case only one property should be set.
|
|
43
|
+
*/
|
|
44
|
+
jvm.AbstractShapeElement.prototype.setStyle = function(property, value){
|
|
45
|
+
var styles = {};
|
|
46
|
+
|
|
47
|
+
if (typeof property === 'object') {
|
|
48
|
+
styles = property;
|
|
49
|
+
} else {
|
|
50
|
+
styles[property] = value;
|
|
51
|
+
}
|
|
52
|
+
jvm.$.extend(this.style.current, styles);
|
|
53
|
+
this.updateStyle();
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
jvm.AbstractShapeElement.prototype.updateStyle = function(){
|
|
58
|
+
var attrs = {};
|
|
59
|
+
|
|
60
|
+
jvm.AbstractShapeElement.mergeStyles(attrs, this.style.initial);
|
|
61
|
+
jvm.AbstractShapeElement.mergeStyles(attrs, this.style.current);
|
|
62
|
+
if (this.isHovered) {
|
|
63
|
+
jvm.AbstractShapeElement.mergeStyles(attrs, this.style.hover);
|
|
64
|
+
}
|
|
65
|
+
if (this.isSelected) {
|
|
66
|
+
jvm.AbstractShapeElement.mergeStyles(attrs, this.style.selected);
|
|
67
|
+
if (this.isHovered) {
|
|
68
|
+
jvm.AbstractShapeElement.mergeStyles(attrs, this.style.selectedHover);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
this.set(attrs);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
jvm.AbstractShapeElement.mergeStyles = function(styles, newStyles){
|
|
75
|
+
var key;
|
|
76
|
+
|
|
77
|
+
newStyles = newStyles || {};
|
|
78
|
+
for (key in newStyles) {
|
|
79
|
+
if (newStyles[key] === null) {
|
|
80
|
+
delete styles[key];
|
|
81
|
+
} else {
|
|
82
|
+
styles[key] = newStyles[key];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
jvm.ColorScale = function(colors, normalizeFunction, minValue, maxValue) {
|
|
2
|
+
jvm.ColorScale.parentClass.apply(this, arguments);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
jvm.inherits(jvm.ColorScale, jvm.NumericScale);
|
|
6
|
+
|
|
7
|
+
jvm.ColorScale.prototype.setScale = function(scale) {
|
|
8
|
+
var i;
|
|
9
|
+
|
|
10
|
+
for (i = 0; i < scale.length; i++) {
|
|
11
|
+
this.scale[i] = jvm.ColorScale.rgbToArray(scale[i]);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
jvm.ColorScale.prototype.getValue = function(value) {
|
|
16
|
+
return jvm.ColorScale.numToRgb(jvm.ColorScale.parentClass.prototype.getValue.call(this, value));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
jvm.ColorScale.arrayToRgb = function(ar) {
|
|
20
|
+
var rgb = '#',
|
|
21
|
+
d,
|
|
22
|
+
i;
|
|
23
|
+
|
|
24
|
+
for (i = 0; i < ar.length; i++) {
|
|
25
|
+
d = ar[i].toString(16);
|
|
26
|
+
rgb += d.length == 1 ? '0'+d : d;
|
|
27
|
+
}
|
|
28
|
+
return rgb;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
jvm.ColorScale.numToRgb = function(num) {
|
|
32
|
+
num = num.toString(16);
|
|
33
|
+
|
|
34
|
+
while (num.length < 6) {
|
|
35
|
+
num = '0' + num;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return '#'+num;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
jvm.ColorScale.rgbToArray = function(rgb) {
|
|
42
|
+
rgb = rgb.substr(1);
|
|
43
|
+
return [parseInt(rgb.substr(0, 2), 16), parseInt(rgb.substr(2, 2), 16), parseInt(rgb.substr(4, 2), 16)];
|
|
44
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates data series.
|
|
3
|
+
* @constructor
|
|
4
|
+
* @param {Object} params Parameters to initialize series with.
|
|
5
|
+
* @param {Array} params.values The data set to visualize.
|
|
6
|
+
* @param {String} params.attribute Numberic or color attribute to use for data visualization. This could be: <code>fill</code>, <code>stroke</code>, <code>fill-opacity</code>, <code>stroke-opacity</code> for markers and regions and <code>r</code> (radius) for markers only.
|
|
7
|
+
* @param {Array} params.scale Values used to map a dimension of data to a visual representation. The first value sets visualization for minimum value from the data set and the last value sets visualization for the maximum value. There also could be intermidiate values. Default value is <code>['#C8EEFF', '#0071A4']</code>
|
|
8
|
+
* @param {Function|String} params.normalizeFunction The function used to map input values to the provided scale. This parameter could be provided as function or one of the strings: <code>'linear'</code> or <code>'polynomial'</code>, while <code>'linear'</code> is used by default. The function provided takes value from the data set as an input and returns corresponding value from the scale.
|
|
9
|
+
* @param {Number} params.min Minimum value of the data set. Could be calculated automatically if not provided.
|
|
10
|
+
* @param {Number} params.min Maximum value of the data set. Could be calculated automatically if not provided.
|
|
11
|
+
*/
|
|
12
|
+
jvm.DataSeries = function(params, elements) {
|
|
13
|
+
var scaleConstructor;
|
|
14
|
+
|
|
15
|
+
params = params || {};
|
|
16
|
+
params.attribute = params.attribute || 'fill';
|
|
17
|
+
|
|
18
|
+
this.elements = elements;
|
|
19
|
+
this.params = params;
|
|
20
|
+
|
|
21
|
+
if (params.attributes) {
|
|
22
|
+
this.setAttributes(params.attributes);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (jvm.$.isArray(params.scale)) {
|
|
26
|
+
scaleConstructor = (params.attribute === 'fill' || params.attribute === 'stroke') ? jvm.ColorScale : jvm.NumericScale;
|
|
27
|
+
this.scale = new scaleConstructor(params.scale, params.normalizeFunction, params.min, params.max);
|
|
28
|
+
} else if (params.scale) {
|
|
29
|
+
this.scale = new jvm.OrdinalScale(params.scale);
|
|
30
|
+
} else {
|
|
31
|
+
this.scale = new jvm.SimpleScale(params.scale);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
this.values = params.values || {};
|
|
35
|
+
this.setValues(this.values);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
jvm.DataSeries.prototype = {
|
|
39
|
+
setAttributes: function(key, attr){
|
|
40
|
+
var attrs = key,
|
|
41
|
+
code;
|
|
42
|
+
|
|
43
|
+
if (typeof key == 'string') {
|
|
44
|
+
if (this.elements[key]) {
|
|
45
|
+
this.elements[key].setStyle(this.params.attribute, attr);
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
for (code in attrs) {
|
|
49
|
+
if (this.elements[code]) {
|
|
50
|
+
this.elements[code].element.setStyle(this.params.attribute, attrs[code]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Set values for the data set.
|
|
58
|
+
* @param {Object} values Object which maps codes of regions or markers to values.
|
|
59
|
+
*/
|
|
60
|
+
setValues: function(values) {
|
|
61
|
+
var max = Number.MIN_VALUE,
|
|
62
|
+
min = Number.MAX_VALUE,
|
|
63
|
+
val,
|
|
64
|
+
cc,
|
|
65
|
+
attrs = {};
|
|
66
|
+
|
|
67
|
+
if (!(this.scale instanceof jvm.OrdinalScale) && !(this.scale instanceof jvm.SimpleScale)) {
|
|
68
|
+
if (!this.params.min || !this.params.max) {
|
|
69
|
+
for (cc in values) {
|
|
70
|
+
val = parseFloat(values[cc]);
|
|
71
|
+
if (val > max) max = values[cc];
|
|
72
|
+
if (val < min) min = val;
|
|
73
|
+
}
|
|
74
|
+
if (!this.params.min) {
|
|
75
|
+
this.scale.setMin(min);
|
|
76
|
+
}
|
|
77
|
+
if (!this.params.max) {
|
|
78
|
+
this.scale.setMax(max);
|
|
79
|
+
}
|
|
80
|
+
this.params.min = min;
|
|
81
|
+
this.params.max = max;
|
|
82
|
+
}
|
|
83
|
+
for (cc in values) {
|
|
84
|
+
val = parseFloat(values[cc]);
|
|
85
|
+
if (!isNaN(val)) {
|
|
86
|
+
attrs[cc] = this.scale.getValue(val);
|
|
87
|
+
} else {
|
|
88
|
+
attrs[cc] = this.elements[cc].element.style.initial[this.params.attribute];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
for (cc in values) {
|
|
93
|
+
if (values[cc]) {
|
|
94
|
+
attrs[cc] = this.scale.getValue(values[cc]);
|
|
95
|
+
} else {
|
|
96
|
+
attrs[cc] = this.elements[cc].element.style.initial[this.params.attribute];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
this.setAttributes(attrs);
|
|
102
|
+
jvm.$.extend(this.values, values);
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
clear: function(){
|
|
106
|
+
var key,
|
|
107
|
+
attrs = {};
|
|
108
|
+
|
|
109
|
+
for (key in this.values) {
|
|
110
|
+
if (this.elements[key]) {
|
|
111
|
+
attrs[key] = this.elements[key].element.style.initial[this.params.attribute];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
this.setAttributes(attrs);
|
|
115
|
+
this.values = {};
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Set scale of the data series.
|
|
120
|
+
* @param {Array} scale Values representing scale.
|
|
121
|
+
*/
|
|
122
|
+
setScale: function(scale) {
|
|
123
|
+
this.scale.setScale(scale);
|
|
124
|
+
if (this.values) {
|
|
125
|
+
this.setValues(this.values);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Set normalize function of the data series.
|
|
131
|
+
* @param {Function|String} normilizeFunction.
|
|
132
|
+
*/
|
|
133
|
+
setNormalizeFunction: function(f) {
|
|
134
|
+
this.scale.setNormalizeFunction(f);
|
|
135
|
+
if (this.values) {
|
|
136
|
+
this.setValues(this.values);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @namespace jvm Holds core methods and classes used by jVectorMap.
|
|
3
|
+
*/
|
|
4
|
+
var jvm = {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Inherits child's prototype from the parent's one.
|
|
8
|
+
* @param {Function} child
|
|
9
|
+
* @param {Function} parent
|
|
10
|
+
*/
|
|
11
|
+
inherits: function(child, parent) {
|
|
12
|
+
function temp() {}
|
|
13
|
+
temp.prototype = parent.prototype;
|
|
14
|
+
child.prototype = new temp();
|
|
15
|
+
child.prototype.constructor = child;
|
|
16
|
+
child.parentClass = parent;
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Mixes in methods from the source constructor to the target one.
|
|
21
|
+
* @param {Function} target
|
|
22
|
+
* @param {Function} source
|
|
23
|
+
*/
|
|
24
|
+
mixin: function(target, source){
|
|
25
|
+
var prop;
|
|
26
|
+
|
|
27
|
+
for (prop in source.prototype) {
|
|
28
|
+
if (source.prototype.hasOwnProperty(prop)) {
|
|
29
|
+
target.prototype[prop] = source.prototype[prop];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
min: function(values){
|
|
35
|
+
var min = Number.MAX_VALUE,
|
|
36
|
+
i;
|
|
37
|
+
|
|
38
|
+
if (values instanceof Array) {
|
|
39
|
+
for (i = 0; i < values.length; i++) {
|
|
40
|
+
if (values[i] < min) {
|
|
41
|
+
min = values[i];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
for (i in values) {
|
|
46
|
+
if (values[i] < min) {
|
|
47
|
+
min = values[i];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return min;
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
max: function(values){
|
|
55
|
+
var max = Number.MIN_VALUE,
|
|
56
|
+
i;
|
|
57
|
+
|
|
58
|
+
if (values instanceof Array) {
|
|
59
|
+
for (i = 0; i < values.length; i++) {
|
|
60
|
+
if (values[i] > max) {
|
|
61
|
+
max = values[i];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
for (i in values) {
|
|
66
|
+
if (values[i] > max) {
|
|
67
|
+
max = values[i];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return max;
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
keys: function(object){
|
|
75
|
+
var keys = [],
|
|
76
|
+
key;
|
|
77
|
+
|
|
78
|
+
for (key in object) {
|
|
79
|
+
keys.push(key);
|
|
80
|
+
}
|
|
81
|
+
return keys;
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
values: function(object){
|
|
85
|
+
var values = [],
|
|
86
|
+
key,
|
|
87
|
+
i;
|
|
88
|
+
|
|
89
|
+
for (i = 0; i < arguments.length; i++) {
|
|
90
|
+
object = arguments[i];
|
|
91
|
+
for (key in object) {
|
|
92
|
+
values.push(object[key]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return values;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
jvm.$ = jQuery;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
jvm.NumericScale = function(scale, normalizeFunction, minValue, maxValue) {
|
|
2
|
+
this.scale = [];
|
|
3
|
+
|
|
4
|
+
normalizeFunction = normalizeFunction || 'linear';
|
|
5
|
+
|
|
6
|
+
if (scale) this.setScale(scale);
|
|
7
|
+
if (normalizeFunction) this.setNormalizeFunction(normalizeFunction);
|
|
8
|
+
if (minValue) this.setMin(minValue);
|
|
9
|
+
if (maxValue) this.setMax(maxValue);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
jvm.NumericScale.prototype = {
|
|
13
|
+
setMin: function(min) {
|
|
14
|
+
this.clearMinValue = min;
|
|
15
|
+
if (typeof this.normalize === 'function') {
|
|
16
|
+
this.minValue = this.normalize(min);
|
|
17
|
+
} else {
|
|
18
|
+
this.minValue = min;
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
setMax: function(max) {
|
|
23
|
+
this.clearMaxValue = max;
|
|
24
|
+
if (typeof this.normalize === 'function') {
|
|
25
|
+
this.maxValue = this.normalize(max);
|
|
26
|
+
} else {
|
|
27
|
+
this.maxValue = max;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
setScale: function(scale) {
|
|
32
|
+
var i;
|
|
33
|
+
|
|
34
|
+
for (i = 0; i < scale.length; i++) {
|
|
35
|
+
this.scale[i] = [scale[i]];
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
setNormalizeFunction: function(f) {
|
|
40
|
+
if (f === 'polynomial') {
|
|
41
|
+
this.normalize = function(value) {
|
|
42
|
+
return Math.pow(value, 0.2);
|
|
43
|
+
}
|
|
44
|
+
} else if (f === 'linear') {
|
|
45
|
+
delete this.normalize;
|
|
46
|
+
} else {
|
|
47
|
+
this.normalize = f;
|
|
48
|
+
}
|
|
49
|
+
this.setMin(this.clearMinValue);
|
|
50
|
+
this.setMax(this.clearMaxValue);
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
getValue: function(value) {
|
|
54
|
+
var lengthes = [],
|
|
55
|
+
fullLength = 0,
|
|
56
|
+
l,
|
|
57
|
+
i = 0,
|
|
58
|
+
c;
|
|
59
|
+
|
|
60
|
+
if (typeof this.normalize === 'function') {
|
|
61
|
+
value = this.normalize(value);
|
|
62
|
+
}
|
|
63
|
+
for (i = 0; i < this.scale.length-1; i++) {
|
|
64
|
+
l = this.vectorLength(this.vectorSubtract(this.scale[i+1], this.scale[i]));
|
|
65
|
+
lengthes.push(l);
|
|
66
|
+
fullLength += l;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
c = (this.maxValue - this.minValue) / fullLength;
|
|
70
|
+
for (i=0; i<lengthes.length; i++) {
|
|
71
|
+
lengthes[i] *= c;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
i = 0;
|
|
75
|
+
value -= this.minValue;
|
|
76
|
+
while (value - lengthes[i] >= 0) {
|
|
77
|
+
value -= lengthes[i];
|
|
78
|
+
i++;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (i == this.scale.length - 1) {
|
|
82
|
+
value = this.vectorToNum(this.scale[i])
|
|
83
|
+
} else {
|
|
84
|
+
value = (
|
|
85
|
+
this.vectorToNum(
|
|
86
|
+
this.vectorAdd(this.scale[i],
|
|
87
|
+
this.vectorMult(
|
|
88
|
+
this.vectorSubtract(this.scale[i+1], this.scale[i]),
|
|
89
|
+
(value) / (lengthes[i])
|
|
90
|
+
)
|
|
91
|
+
)
|
|
92
|
+
)
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return value;
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
vectorToNum: function(vector) {
|
|
100
|
+
var num = 0,
|
|
101
|
+
i;
|
|
102
|
+
|
|
103
|
+
for (i = 0; i < vector.length; i++) {
|
|
104
|
+
num += Math.round(vector[i])*Math.pow(256, vector.length-i-1);
|
|
105
|
+
}
|
|
106
|
+
return num;
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
vectorSubtract: function(vector1, vector2) {
|
|
110
|
+
var vector = [],
|
|
111
|
+
i;
|
|
112
|
+
|
|
113
|
+
for (i = 0; i < vector1.length; i++) {
|
|
114
|
+
vector[i] = vector1[i] - vector2[i];
|
|
115
|
+
}
|
|
116
|
+
return vector;
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
vectorAdd: function(vector1, vector2) {
|
|
120
|
+
var vector = [],
|
|
121
|
+
i;
|
|
122
|
+
|
|
123
|
+
for (i = 0; i < vector1.length; i++) {
|
|
124
|
+
vector[i] = vector1[i] + vector2[i];
|
|
125
|
+
}
|
|
126
|
+
return vector;
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
vectorMult: function(vector, num) {
|
|
130
|
+
var result = [],
|
|
131
|
+
i;
|
|
132
|
+
|
|
133
|
+
for (i = 0; i < vector.length; i++) {
|
|
134
|
+
result[i] = vector[i] * num;
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
vectorLength: function(vector) {
|
|
140
|
+
var result = 0,
|
|
141
|
+
i;
|
|
142
|
+
for (i = 0; i < vector.length; i++) {
|
|
143
|
+
result += vector[i] * vector[i];
|
|
144
|
+
}
|
|
145
|
+
return Math.sqrt(result);
|
|
146
|
+
}
|
|
147
|
+
};
|