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,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,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,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,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);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class for vector images manipulations.
|
|
3
|
+
* @constructor
|
|
4
|
+
* @param {DOMElement} container to place canvas to
|
|
5
|
+
* @param {Number} width
|
|
6
|
+
* @param {Number} height
|
|
7
|
+
*/
|
|
8
|
+
jvm.VectorCanvas = function(container, width, height) {
|
|
9
|
+
this.mode = window.SVGAngle ? 'svg' : 'vml';
|
|
10
|
+
if (this.mode == 'svg') {
|
|
11
|
+
this.impl = new jvm.SVGCanvasElement(container, width, height);
|
|
12
|
+
} else {
|
|
13
|
+
this.impl = new jvm.VMLCanvasElement(container, width, height);
|
|
14
|
+
}
|
|
15
|
+
return this.impl;
|
|
16
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
jvm.VMLCanvasElement = function(container, width, height){
|
|
2
|
+
this.classPrefix = 'VML';
|
|
3
|
+
jvm.VMLCanvasElement.parentClass.call(this, 'group');
|
|
4
|
+
jvm.AbstractCanvasElement.apply(this, arguments);
|
|
5
|
+
this.node.style.position = 'absolute';
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
jvm.inherits(jvm.VMLCanvasElement, jvm.VMLElement);
|
|
9
|
+
jvm.mixin(jvm.VMLCanvasElement, jvm.AbstractCanvasElement);
|
|
10
|
+
|
|
11
|
+
jvm.VMLCanvasElement.prototype.setSize = function(width, height){
|
|
12
|
+
var paths,
|
|
13
|
+
groups,
|
|
14
|
+
i,
|
|
15
|
+
l;
|
|
16
|
+
|
|
17
|
+
this.width = width;
|
|
18
|
+
this.height = height;
|
|
19
|
+
this.node.style.width = width + "px";
|
|
20
|
+
this.node.style.height = height + "px";
|
|
21
|
+
this.node.coordsize = width+' '+height;
|
|
22
|
+
this.node.coordorigin = "0 0";
|
|
23
|
+
if (this.rootElement) {
|
|
24
|
+
paths = this.rootElement.node.getElementsByTagName('shape');
|
|
25
|
+
for(i = 0, l = paths.length; i < l; i++) {
|
|
26
|
+
paths[i].coordsize = width+' '+height;
|
|
27
|
+
paths[i].style.width = width+'px';
|
|
28
|
+
paths[i].style.height = height+'px';
|
|
29
|
+
}
|
|
30
|
+
groups = this.node.getElementsByTagName('group');
|
|
31
|
+
for(i = 0, l = groups.length; i < l; i++) {
|
|
32
|
+
groups[i].coordsize = width+' '+height;
|
|
33
|
+
groups[i].style.width = width+'px';
|
|
34
|
+
groups[i].style.height = height+'px';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
jvm.VMLCanvasElement.prototype.applyTransformParams = function(scale, transX, transY) {
|
|
40
|
+
this.scale = scale;
|
|
41
|
+
this.transX = transX;
|
|
42
|
+
this.transY = transY;
|
|
43
|
+
this.rootElement.node.coordorigin = (this.width-transX-this.width/100)+','+(this.height-transY-this.height/100);
|
|
44
|
+
this.rootElement.node.coordsize = this.width/scale+','+this.height/scale;
|
|
45
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
jvm.VMLCircleElement = function(config, style){
|
|
2
|
+
jvm.VMLCircleElement.parentClass.call(this, 'oval', config, style);
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
jvm.inherits(jvm.VMLCircleElement, jvm.VMLShapeElement);
|
|
6
|
+
|
|
7
|
+
jvm.VMLCircleElement.prototype.applyAttr = function(attr, value){
|
|
8
|
+
switch (attr) {
|
|
9
|
+
case 'r':
|
|
10
|
+
this.node.style.width = value*2+'px';
|
|
11
|
+
this.node.style.height = value*2+'px';
|
|
12
|
+
this.applyAttr('cx', this.get('cx') || 0);
|
|
13
|
+
this.applyAttr('cy', this.get('cy') || 0);
|
|
14
|
+
break;
|
|
15
|
+
case 'cx':
|
|
16
|
+
if (!value) return;
|
|
17
|
+
this.node.style.left = value - (this.get('r') || 0) + 'px';
|
|
18
|
+
break;
|
|
19
|
+
case 'cy':
|
|
20
|
+
if (!value) return;
|
|
21
|
+
this.node.style.top = value - (this.get('r') || 0) + 'px';
|
|
22
|
+
break;
|
|
23
|
+
default:
|
|
24
|
+
jvm.VMLCircleElement.parentClass.prototype.applyAttr.call(this, attr, value);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrapper for VML 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.VMLElement = function(name, config){
|
|
10
|
+
if (!jvm.VMLElement.VMLInitialized) {
|
|
11
|
+
jvm.VMLElement.initializeVML();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
jvm.VMLElement.parentClass.apply(this, arguments);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
jvm.inherits(jvm.VMLElement, jvm.AbstractElement);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Shows if VML was already initialized for the current document or not.
|
|
21
|
+
* @static
|
|
22
|
+
* @private
|
|
23
|
+
* @type {Boolean}
|
|
24
|
+
*/
|
|
25
|
+
jvm.VMLElement.VMLInitialized = false;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Initializes VML handling before creating the first element
|
|
29
|
+
* (adds CSS class and creates namespace). Adds one of two forms
|
|
30
|
+
* of createElement method depending of support by browser.
|
|
31
|
+
* @static
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
// The following method of VML handling is borrowed from the
|
|
36
|
+
// Raphael library by Dmitry Baranovsky.
|
|
37
|
+
|
|
38
|
+
jvm.VMLElement.initializeVML = function(){
|
|
39
|
+
try {
|
|
40
|
+
if (!document.namespaces.rvml) {
|
|
41
|
+
document.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates DOM element.
|
|
45
|
+
* @param {String} tagName Name of element
|
|
46
|
+
* @private
|
|
47
|
+
* @returns DOMElement
|
|
48
|
+
*/
|
|
49
|
+
jvm.VMLElement.prototype.createElement = function (tagName) {
|
|
50
|
+
return document.createElement('<rvml:' + tagName + ' class="rvml">');
|
|
51
|
+
};
|
|
52
|
+
} catch (e) {
|
|
53
|
+
/**
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
jvm.VMLElement.prototype.createElement = function (tagName) {
|
|
57
|
+
return document.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
document.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
|
|
61
|
+
jvm.VMLElement.VMLInitialized = true;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Returns constructor for element by name prefixed with 'VML'.
|
|
66
|
+
* @param {String} ctr Name of basic constructor to return
|
|
67
|
+
* proper implementation for.
|
|
68
|
+
* @returns Function
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
jvm.VMLElement.prototype.getElementCtr = function( ctr ){
|
|
72
|
+
return jvm['VML'+ctr];
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Adds CSS class for underlying DOM element.
|
|
77
|
+
* @param {String} className Name of CSS class name
|
|
78
|
+
*/
|
|
79
|
+
jvm.VMLElement.prototype.addClass = function( className ){
|
|
80
|
+
jvm.$(this.node).addClass(className);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Applies attribute value to the underlying DOM element.
|
|
85
|
+
* @param {String} name Name of attribute
|
|
86
|
+
* @param {Number|String} config Value of attribute to apply
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
jvm.VMLElement.prototype.applyAttr = function( attr, value ){
|
|
90
|
+
this.node[attr] = value;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Returns boundary box for the element.
|
|
95
|
+
* @returns {Object} Boundary box with numeric fields: x, y, width, height
|
|
96
|
+
* @override
|
|
97
|
+
*/
|
|
98
|
+
jvm.VMLElement.prototype.getBBox = function(){
|
|
99
|
+
var node = jvm.$(this.node);
|
|
100
|
+
return {
|
|
101
|
+
x: node.position().left / this.canvas.scale,
|
|
102
|
+
y: node.position().top / this.canvas.scale,
|
|
103
|
+
width: node.width() / this.canvas.scale,
|
|
104
|
+
height: node.height() / this.canvas.scale
|
|
105
|
+
};
|
|
106
|
+
};
|