jvectormap-rails4 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/History.txt +3 -0
  4. data/README.md +60 -0
  5. data/Rakefile +38 -0
  6. data/jvectormap-rails4.gemspec +20 -0
  7. data/lib/jvectormap/rails4/engine.rb +8 -0
  8. data/lib/jvectormap/rails4/railtie.rb +17 -0
  9. data/lib/jvectormap/rails4/version.rb +8 -0
  10. data/lib/jvectormap/rails4.rb +7 -0
  11. data/lib/jvectormap-rails4.rb +26 -0
  12. data/tasks/jvectormap.rake +6 -0
  13. data/vendor/assets/javascripts/jvectormap/jquery-jvectormap.js +45 -0
  14. data/vendor/assets/javascripts/jvectormap/jquery-mousewheel.js +84 -0
  15. data/vendor/assets/javascripts/jvectormap/lib/abstract-canvas-element.js +67 -0
  16. data/vendor/assets/javascripts/jvectormap/lib/abstract-element.js +73 -0
  17. data/vendor/assets/javascripts/jvectormap/lib/abstract-shape-element.js +85 -0
  18. data/vendor/assets/javascripts/jvectormap/lib/color-scale.js +44 -0
  19. data/vendor/assets/javascripts/jvectormap/lib/data-series.js +139 -0
  20. data/vendor/assets/javascripts/jvectormap/lib/jvectormap.js +99 -0
  21. data/vendor/assets/javascripts/jvectormap/lib/numeric-scale.js +147 -0
  22. data/vendor/assets/javascripts/jvectormap/lib/ordinal-scale.js +7 -0
  23. data/vendor/assets/javascripts/jvectormap/lib/proj.js +181 -0
  24. data/vendor/assets/javascripts/jvectormap/lib/simple-scale.js +7 -0
  25. data/vendor/assets/javascripts/jvectormap/lib/svg-canvas-element.js +22 -0
  26. data/vendor/assets/javascripts/jvectormap/lib/svg-circle-element.js +5 -0
  27. data/vendor/assets/javascripts/jvectormap/lib/svg-element.js +48 -0
  28. data/vendor/assets/javascripts/jvectormap/lib/svg-group-element.js +9 -0
  29. data/vendor/assets/javascripts/jvectormap/lib/svg-path-element.js +6 -0
  30. data/vendor/assets/javascripts/jvectormap/lib/svg-shape-element.js +7 -0
  31. data/vendor/assets/javascripts/jvectormap/lib/vector-canvas.js +16 -0
  32. data/vendor/assets/javascripts/jvectormap/lib/vml-canvas-element.js +45 -0
  33. data/vendor/assets/javascripts/jvectormap/lib/vml-circle-element.js +26 -0
  34. data/vendor/assets/javascripts/jvectormap/lib/vml-element.js +106 -0
  35. data/vendor/assets/javascripts/jvectormap/lib/vml-group-element.js +13 -0
  36. data/vendor/assets/javascripts/jvectormap/lib/vml-path-element.js +111 -0
  37. data/vendor/assets/javascripts/jvectormap/lib/vml-shape-element.js +49 -0
  38. data/vendor/assets/javascripts/jvectormap/lib/world-map.js +977 -0
  39. data/vendor/assets/javascripts/jvectormap/maps/ar_merc_en.js +1 -0
  40. data/vendor/assets/javascripts/jvectormap/maps/ar_mill_en.js +1 -0
  41. data/vendor/assets/javascripts/jvectormap/maps/at_merc_en.js +1 -0
  42. data/vendor/assets/javascripts/jvectormap/maps/at_mill_en.js +1 -0
  43. data/vendor/assets/javascripts/jvectormap/maps/au_merc_en.js +1 -0
  44. data/vendor/assets/javascripts/jvectormap/maps/au_mill_en.js +1 -0
  45. data/vendor/assets/javascripts/jvectormap/maps/be_merc_en.js +1 -0
  46. data/vendor/assets/javascripts/jvectormap/maps/be_mill_en.js +1 -0
  47. data/vendor/assets/javascripts/jvectormap/maps/ca_lcc_en.js +1 -0
  48. data/vendor/assets/javascripts/jvectormap/maps/ca_merc_en.js +1 -0
  49. data/vendor/assets/javascripts/jvectormap/maps/ca_mill_en.js +1 -0
  50. data/vendor/assets/javascripts/jvectormap/maps/ch_merc_en.js +1 -0
  51. data/vendor/assets/javascripts/jvectormap/maps/ch_mill_en.js +1 -0
  52. data/vendor/assets/javascripts/jvectormap/maps/cn_merc_en.js +1 -0
  53. data/vendor/assets/javascripts/jvectormap/maps/cn_mill_en.js +1 -0
  54. data/vendor/assets/javascripts/jvectormap/maps/co_merc_en.js +1 -0
  55. data/vendor/assets/javascripts/jvectormap/maps/co_mill_en.js +1 -0
  56. data/vendor/assets/javascripts/jvectormap/maps/de_merc_en.js +1 -0
  57. data/vendor/assets/javascripts/jvectormap/maps/de_mill_en.js +1 -0
  58. data/vendor/assets/javascripts/jvectormap/maps/dk_merc_en.js +1 -0
  59. data/vendor/assets/javascripts/jvectormap/maps/dk_mill_en.js +1 -0
  60. data/vendor/assets/javascripts/jvectormap/maps/es_merc_en.js +1 -0
  61. data/vendor/assets/javascripts/jvectormap/maps/es_mill_en.js +1 -0
  62. data/vendor/assets/javascripts/jvectormap/maps/europe_merc_en.js +1 -0
  63. data/vendor/assets/javascripts/jvectormap/maps/europe_mill_en.js +1 -0
  64. data/vendor/assets/javascripts/jvectormap/maps/fr_merc_en.js +1 -0
  65. data/vendor/assets/javascripts/jvectormap/maps/fr_mill_en.js +1 -0
  66. data/vendor/assets/javascripts/jvectormap/maps/in_merc_en.js +1 -0
  67. data/vendor/assets/javascripts/jvectormap/maps/in_mill_en.js +1 -0
  68. data/vendor/assets/javascripts/jvectormap/maps/it_merc_en.js +1 -0
  69. data/vendor/assets/javascripts/jvectormap/maps/it_mill_en.js +1 -0
  70. data/vendor/assets/javascripts/jvectormap/maps/nl_merc_en.js +1 -0
  71. data/vendor/assets/javascripts/jvectormap/maps/nl_mill_en.js +1 -0
  72. data/vendor/assets/javascripts/jvectormap/maps/no_merc_en.js +1 -0
  73. data/vendor/assets/javascripts/jvectormap/maps/no_mill_en.js +1 -0
  74. data/vendor/assets/javascripts/jvectormap/maps/nz_merc_en.js +1 -0
  75. data/vendor/assets/javascripts/jvectormap/maps/nz_mill_en.js +1 -0
  76. data/vendor/assets/javascripts/jvectormap/maps/ph_regions_merc_en.js +1 -0
  77. data/vendor/assets/javascripts/jvectormap/maps/ph_regions_mill_en.js +1 -0
  78. data/vendor/assets/javascripts/jvectormap/maps/pl_merc_en.js +1 -0
  79. data/vendor/assets/javascripts/jvectormap/maps/pl_mill_en.js +1 -0
  80. data/vendor/assets/javascripts/jvectormap/maps/pt_merc_en.js +1 -0
  81. data/vendor/assets/javascripts/jvectormap/maps/pt_mill_en.js +1 -0
  82. data/vendor/assets/javascripts/jvectormap/maps/se_merc_en.js +1 -0
  83. data/vendor/assets/javascripts/jvectormap/maps/se_mill_en.js +1 -0
  84. data/vendor/assets/javascripts/jvectormap/maps/th_merc_en.js +1 -0
  85. data/vendor/assets/javascripts/jvectormap/maps/th_mill_en.js +1 -0
  86. data/vendor/assets/javascripts/jvectormap/maps/th_regions_merc_en.js +1 -0
  87. data/vendor/assets/javascripts/jvectormap/maps/th_regions_mill_en.js +1 -0
  88. data/vendor/assets/javascripts/jvectormap/maps/uk_merc_en.js +1 -0
  89. data/vendor/assets/javascripts/jvectormap/maps/uk_mill_en.js +1 -0
  90. data/vendor/assets/javascripts/jvectormap/maps/us-il-chicago_mill_en.js +1 -0
  91. data/vendor/assets/javascripts/jvectormap/maps/us-ny-newyork_mill_en.js +1 -0
  92. data/vendor/assets/javascripts/jvectormap/maps/us_aea_en.js +1 -0
  93. data/vendor/assets/javascripts/jvectormap/maps/us_lcc_en.js +1 -0
  94. data/vendor/assets/javascripts/jvectormap/maps/us_merc_en.js +1 -0
  95. data/vendor/assets/javascripts/jvectormap/maps/us_mill_en.js +1 -0
  96. data/vendor/assets/javascripts/jvectormap/maps/ve_merc_en.js +1 -0
  97. data/vendor/assets/javascripts/jvectormap/maps/ve_mill_en.js +1 -0
  98. data/vendor/assets/javascripts/jvectormap/maps/world_merc_en.js +1 -0
  99. data/vendor/assets/javascripts/jvectormap/maps/world_mill_en.js +1 -0
  100. data/vendor/assets/javascripts/jvectormap/maps/za_merc_en.js +1 -0
  101. data/vendor/assets/javascripts/jvectormap/maps/za_mill_en.js +1 -0
  102. data/vendor/assets/javascripts/jvectormap.js +26 -0
  103. data/vendor/assets/stylesheets/jvectormap.css +37 -0
  104. metadata +159 -0
@@ -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
+ };
@@ -0,0 +1,7 @@
1
+ jvm.OrdinalScale = function(scale){
2
+ this.scale = scale;
3
+ };
4
+
5
+ jvm.OrdinalScale.prototype.getValue = function(value){
6
+ return this.scale[value];
7
+ };
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Contains methods for transforming point on sphere to
3
+ * Cartesian coordinates using various projections.
4
+ * @class
5
+ */
6
+ jvm.Proj = {
7
+ degRad: 180 / Math.PI,
8
+ radDeg: Math.PI / 180,
9
+ radius: 6381372,
10
+
11
+ sgn: function(n){
12
+ if (n > 0) {
13
+ return 1;
14
+ } else if (n < 0) {
15
+ return -1;
16
+ } else {
17
+ return n;
18
+ }
19
+ },
20
+
21
+ /**
22
+ * Converts point on sphere to the Cartesian coordinates using Miller projection
23
+ * @param {Number} lat Latitude in degrees
24
+ * @param {Number} lng Longitude in degrees
25
+ * @param {Number} c Central meridian in degrees
26
+ */
27
+ mill: function(lat, lng, c){
28
+ return {
29
+ x: this.radius * (lng - c) * this.radDeg,
30
+ y: - this.radius * Math.log(Math.tan((45 + 0.4 * lat) * this.radDeg)) / 0.8
31
+ };
32
+ },
33
+
34
+ /**
35
+ * Inverse function of mill()
36
+ * Converts Cartesian coordinates to point on sphere using Miller projection
37
+ * @param {Number} x X of point in Cartesian system as integer
38
+ * @param {Number} y Y of point in Cartesian system as integer
39
+ * @param {Number} c Central meridian in degrees
40
+ */
41
+ mill_inv: function(x, y, c){
42
+ return {
43
+ lat: (2.5 * Math.atan(Math.exp(0.8 * y / this.radius)) - 5 * Math.PI / 8) * this.degRad,
44
+ lng: (c * this.radDeg + x / this.radius) * this.degRad
45
+ };
46
+ },
47
+
48
+ /**
49
+ * Converts point on sphere to the Cartesian coordinates using Mercator projection
50
+ * @param {Number} lat Latitude in degrees
51
+ * @param {Number} lng Longitude in degrees
52
+ * @param {Number} c Central meridian in degrees
53
+ */
54
+ merc: function(lat, lng, c){
55
+ return {
56
+ x: this.radius * (lng - c) * this.radDeg,
57
+ y: - this.radius * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360))
58
+ };
59
+ },
60
+
61
+ /**
62
+ * Inverse function of merc()
63
+ * Converts Cartesian coordinates to point on sphere using Mercator projection
64
+ * @param {Number} x X of point in Cartesian system as integer
65
+ * @param {Number} y Y of point in Cartesian system as integer
66
+ * @param {Number} c Central meridian in degrees
67
+ */
68
+ merc_inv: function(x, y, c){
69
+ return {
70
+ lat: (2 * Math.atan(Math.exp(y / this.radius)) - Math.PI / 2) * this.degRad,
71
+ lng: (c * this.radDeg + x / this.radius) * this.degRad
72
+ };
73
+ },
74
+
75
+ /**
76
+ * Converts point on sphere to the Cartesian coordinates using Albers Equal-Area Conic
77
+ * projection
78
+ * @see <a href="http://mathworld.wolfram.com/AlbersEqual-AreaConicProjection.html">Albers Equal-Area Conic projection</a>
79
+ * @param {Number} lat Latitude in degrees
80
+ * @param {Number} lng Longitude in degrees
81
+ * @param {Number} c Central meridian in degrees
82
+ */
83
+ aea: function(lat, lng, c){
84
+ var fi0 = 0,
85
+ lambda0 = c * this.radDeg,
86
+ fi1 = 29.5 * this.radDeg,
87
+ fi2 = 45.5 * this.radDeg,
88
+ fi = lat * this.radDeg,
89
+ lambda = lng * this.radDeg,
90
+ n = (Math.sin(fi1)+Math.sin(fi2)) / 2,
91
+ C = Math.cos(fi1)*Math.cos(fi1)+2*n*Math.sin(fi1),
92
+ theta = n*(lambda-lambda0),
93
+ ro = Math.sqrt(C-2*n*Math.sin(fi))/n,
94
+ ro0 = Math.sqrt(C-2*n*Math.sin(fi0))/n;
95
+
96
+ return {
97
+ x: ro * Math.sin(theta) * this.radius,
98
+ y: - (ro0 - ro * Math.cos(theta)) * this.radius
99
+ };
100
+ },
101
+
102
+ /**
103
+ * Converts Cartesian coordinates to the point on sphere using Albers Equal-Area Conic
104
+ * projection
105
+ * @see <a href="http://mathworld.wolfram.com/AlbersEqual-AreaConicProjection.html">Albers Equal-Area Conic projection</a>
106
+ * @param {Number} x X of point in Cartesian system as integer
107
+ * @param {Number} y Y of point in Cartesian system as integer
108
+ * @param {Number} c Central meridian in degrees
109
+ */
110
+ aea_inv: function(xCoord, yCoord, c){
111
+ var x = xCoord / this.radius,
112
+ y = yCoord / this.radius,
113
+ fi0 = 0,
114
+ lambda0 = c * this.radDeg,
115
+ fi1 = 29.5 * this.radDeg,
116
+ fi2 = 45.5 * this.radDeg,
117
+ n = (Math.sin(fi1)+Math.sin(fi2)) / 2,
118
+ C = Math.cos(fi1)*Math.cos(fi1)+2*n*Math.sin(fi1),
119
+ ro0 = Math.sqrt(C-2*n*Math.sin(fi0))/n,
120
+ ro = Math.sqrt(x*x+(ro0-y)*(ro0-y)),
121
+ theta = Math.atan( x / (ro0 - y) );
122
+
123
+ return {
124
+ lat: (Math.asin((C - ro * ro * n * n) / (2 * n))) * this.degRad,
125
+ lng: (lambda0 + theta / n) * this.degRad
126
+ };
127
+ },
128
+
129
+ /**
130
+ * Converts point on sphere to the Cartesian coordinates using Lambert conformal
131
+ * conic projection
132
+ * @see <a href="http://mathworld.wolfram.com/LambertConformalConicProjection.html">Lambert Conformal Conic Projection</a>
133
+ * @param {Number} lat Latitude in degrees
134
+ * @param {Number} lng Longitude in degrees
135
+ * @param {Number} c Central meridian in degrees
136
+ */
137
+ lcc: function(lat, lng, c){
138
+ var fi0 = 0,
139
+ lambda0 = c * this.radDeg,
140
+ lambda = lng * this.radDeg,
141
+ fi1 = 33 * this.radDeg,
142
+ fi2 = 45 * this.radDeg,
143
+ fi = lat * this.radDeg,
144
+ n = Math.log( Math.cos(fi1) * (1 / Math.cos(fi2)) ) / Math.log( Math.tan( Math.PI / 4 + fi2 / 2) * (1 / Math.tan( Math.PI / 4 + fi1 / 2) ) ),
145
+ F = ( Math.cos(fi1) * Math.pow( Math.tan( Math.PI / 4 + fi1 / 2 ), n ) ) / n,
146
+ ro = F * Math.pow( 1 / Math.tan( Math.PI / 4 + fi / 2 ), n ),
147
+ ro0 = F * Math.pow( 1 / Math.tan( Math.PI / 4 + fi0 / 2 ), n );
148
+
149
+ return {
150
+ x: ro * Math.sin( n * (lambda - lambda0) ) * this.radius,
151
+ y: - (ro0 - ro * Math.cos( n * (lambda - lambda0) ) ) * this.radius
152
+ };
153
+ },
154
+
155
+ /**
156
+ * Converts Cartesian coordinates to the point on sphere using Lambert conformal conic
157
+ * projection
158
+ * @see <a href="http://mathworld.wolfram.com/LambertConformalConicProjection.html">Lambert Conformal Conic Projection</a>
159
+ * @param {Number} x X of point in Cartesian system as integer
160
+ * @param {Number} y Y of point in Cartesian system as integer
161
+ * @param {Number} c Central meridian in degrees
162
+ */
163
+ lcc_inv: function(xCoord, yCoord, c){
164
+ var x = xCoord / this.radius,
165
+ y = yCoord / this.radius,
166
+ fi0 = 0,
167
+ lambda0 = c * this.radDeg,
168
+ fi1 = 33 * this.radDeg,
169
+ fi2 = 45 * this.radDeg,
170
+ n = Math.log( Math.cos(fi1) * (1 / Math.cos(fi2)) ) / Math.log( Math.tan( Math.PI / 4 + fi2 / 2) * (1 / Math.tan( Math.PI / 4 + fi1 / 2) ) ),
171
+ F = ( Math.cos(fi1) * Math.pow( Math.tan( Math.PI / 4 + fi1 / 2 ), n ) ) / n,
172
+ ro0 = F * Math.pow( 1 / Math.tan( Math.PI / 4 + fi0 / 2 ), n ),
173
+ ro = this.sgn(n) * Math.sqrt(x*x+(ro0-y)*(ro0-y)),
174
+ theta = Math.atan( x / (ro0 - y) );
175
+
176
+ return {
177
+ lat: (2 * Math.atan(Math.pow(F/ro, 1/n)) - Math.PI / 2) * this.degRad,
178
+ lng: (lambda0 + theta / n) * this.degRad
179
+ };
180
+ }
181
+ };
@@ -0,0 +1,7 @@
1
+ jvm.SimpleScale = function(scale){
2
+ this.scale = scale;
3
+ };
4
+
5
+ jvm.SimpleScale.prototype.getValue = function(value){
6
+ return value;
7
+ };
@@ -0,0 +1,22 @@
1
+ jvm.SVGCanvasElement = function(container, width, height){
2
+ this.classPrefix = 'SVG';
3
+ jvm.SVGCanvasElement.parentClass.call(this, 'svg');
4
+ jvm.AbstractCanvasElement.apply(this, arguments);
5
+ }
6
+
7
+ jvm.inherits(jvm.SVGCanvasElement, jvm.SVGElement);
8
+ jvm.mixin(jvm.SVGCanvasElement, jvm.AbstractCanvasElement);
9
+
10
+ jvm.SVGCanvasElement.prototype.setSize = function(width, height){
11
+ this.width = width;
12
+ this.height = height;
13
+ this.node.setAttribute('width', width);
14
+ this.node.setAttribute('height', height);
15
+ };
16
+
17
+ jvm.SVGCanvasElement.prototype.applyTransformParams = function(scale, transX, transY) {
18
+ this.scale = scale;
19
+ this.transX = transX;
20
+ this.transY = transY;
21
+ this.rootElement.node.setAttribute('transform', 'scale('+scale+') translate('+transX+', '+transY+')');
22
+ };
@@ -0,0 +1,5 @@
1
+ jvm.SVGCircleElement = function(config, style){
2
+ jvm.SVGCircleElement.parentClass.call(this, 'circle', config, style);
3
+ };
4
+
5
+ jvm.inherits(jvm.SVGCircleElement, jvm.SVGShapeElement);
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Wrapper for SVG element.
3
+ * @constructor
4
+ * @extends jvm.AbstractElement
5
+ * @param {String} name Tag name of the element
6
+ * @param {Object} config Set of parameters to initialize element with
7
+ */
8
+
9
+ jvm.SVGElement = function(name, config){
10
+ jvm.SVGElement.parentClass.apply(this, arguments);
11
+ }
12
+
13
+ jvm.inherits(jvm.SVGElement, jvm.AbstractElement);
14
+
15
+ jvm.SVGElement.svgns = "http://www.w3.org/2000/svg";
16
+
17
+ /**
18
+ * Creates DOM element.
19
+ * @param {String} tagName Name of element
20
+ * @private
21
+ * @returns DOMElement
22
+ */
23
+ jvm.SVGElement.prototype.createElement = function( tagName ){
24
+ return document.createElementNS( jvm.SVGElement.svgns, tagName );
25
+ };
26
+
27
+ /**
28
+ * Adds CSS class for underlying DOM element.
29
+ * @param {String} className Name of CSS class name
30
+ */
31
+ jvm.SVGElement.prototype.addClass = function( className ){
32
+ this.node.setAttribute('class', className);
33
+ };
34
+
35
+ /**
36
+ * Returns constructor for element by name prefixed with 'VML'.
37
+ * @param {String} ctr Name of basic constructor to return
38
+ * proper implementation for.
39
+ * @returns Function
40
+ * @private
41
+ */
42
+ jvm.SVGElement.prototype.getElementCtr = function( ctr ){
43
+ return jvm['SVG'+ctr];
44
+ };
45
+
46
+ jvm.SVGElement.prototype.getBBox = function(){
47
+ return this.node.getBBox();
48
+ };
@@ -0,0 +1,9 @@
1
+ jvm.SVGGroupElement = function(){
2
+ jvm.SVGGroupElement.parentClass.call(this, 'g');
3
+ }
4
+
5
+ jvm.inherits(jvm.SVGGroupElement, jvm.SVGElement);
6
+
7
+ jvm.SVGGroupElement.prototype.add = function(element){
8
+ this.node.appendChild( element.node );
9
+ };
@@ -0,0 +1,6 @@
1
+ jvm.SVGPathElement = function(config, style){
2
+ jvm.SVGPathElement.parentClass.call(this, 'path', config, style);
3
+ this.node.setAttribute('fill-rule', 'evenodd');
4
+ }
5
+
6
+ jvm.inherits(jvm.SVGPathElement, jvm.SVGShapeElement);
@@ -0,0 +1,7 @@
1
+ jvm.SVGShapeElement = function(name, config, style){
2
+ jvm.SVGShapeElement.parentClass.call(this, name, config);
3
+ jvm.AbstractShapeElement.apply(this, arguments);
4
+ };
5
+
6
+ jvm.inherits(jvm.SVGShapeElement, jvm.SVGElement);
7
+ jvm.mixin(jvm.SVGShapeElement, jvm.AbstractShapeElement);