jvectormap-rails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/Gemfile
ADDED
data/History.txt
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
jvectormap-rails is licensed under the same terms as jVectorMap, which can be found at:
|
2
|
+
https://github.com/jquery/jquery-color/blob/2.1.2/MIT-LICENSE.txt
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
4
|
+
|
5
|
+
require 'bundler'
|
6
|
+
require 'rubygems/package_task'
|
7
|
+
|
8
|
+
Bundler::GemHelper.install_tasks
|
9
|
+
|
10
|
+
task :download_maps do
|
11
|
+
require 'open-uri'
|
12
|
+
# This task scrapes jvectormap.com/maps and downloads them
|
13
|
+
# I wish there was a better way to get the map data, but I can't find a repo or anything, so here we are...
|
14
|
+
|
15
|
+
output_dir = File.join(File.dirname(__FILE__), "vendor")
|
16
|
+
puts "Getting list of map urls..."
|
17
|
+
home = open("http://jvectormap.com/maps/").read
|
18
|
+
links = home.scan(/<a\shref="(\/maps.*)">/).flatten.uniq
|
19
|
+
|
20
|
+
js_files = links.flat_map do |link|
|
21
|
+
puts "Getting list of maps for #{link}..."
|
22
|
+
content = open(File.join("http://jvectormap.com", link)).read
|
23
|
+
content.scan(/<a\shref=\"(\/js\/jquery-jvectormap[\w\d\-]+\.js)">/).flatten.uniq
|
24
|
+
end
|
25
|
+
|
26
|
+
js_files.uniq.each do |file|
|
27
|
+
puts "Downloading map #{File.basename(file)}..."
|
28
|
+
map_data = open(File.join("http://jvectormap.com", file)).read
|
29
|
+
save_name = map_data.scan(/\$\.fn\.vectorMap\('addMap',\s'([\w_\-]+)'/).flatten.first
|
30
|
+
File.open(File.join(output_dir, "assets/javascripts/jvectormap/maps", "#{save_name}.js"), "w+") do |f|
|
31
|
+
f.write(map_data)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
puts "Done."
|
36
|
+
end
|
37
|
+
|
38
|
+
load "tasks/jvectormap.rake"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), 'lib')
|
2
|
+
require 'jvectormap/rails/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "jvectormap-rails"
|
6
|
+
s.version = ::JVectorMap::Rails::VERSION
|
7
|
+
s.authors = ["Cameron Dutro", "Kirill Lebedev"]
|
8
|
+
s.email = ["camertron@gmail.com", "echo.bjornd@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/bjornd/jvectormap"
|
10
|
+
|
11
|
+
s.description = s.summary = "jVectorMap for the Rails asset pipeline"
|
12
|
+
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
s.has_rdoc = true
|
15
|
+
|
16
|
+
s.add_dependency 'railties', '~> 3.1'
|
17
|
+
|
18
|
+
s.require_path = 'lib'
|
19
|
+
s.files = Dir["{lib,vendor,tasks}/**/*", "Gemfile", "History.txt", "LICENSE", "README.md", "Rakefile", "jvectormap-rails.gemspec"]
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module JVectorMap
|
4
|
+
module Rails
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
# maps that will be added to asset precompilation
|
9
|
+
def precompile_maps
|
10
|
+
@precompile_maps ||= []
|
11
|
+
end
|
12
|
+
|
13
|
+
def gem_root
|
14
|
+
File.expand_path(File.join(File.dirname(__FILE__), "../"))
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rails'
|
23
|
+
|
24
|
+
require 'jvectormap/rails/version'
|
25
|
+
require 'jvectormap/rails/engine'
|
26
|
+
require 'jvectormap/rails/railtie'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module JVectorMap
|
4
|
+
module Rails
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
rake_tasks do
|
7
|
+
load File.join(JVectorMap::Rails.gem_root, "tasks/jvectormap.rake")
|
8
|
+
end
|
9
|
+
|
10
|
+
config.after_initialize do
|
11
|
+
::Rails.application.config.assets.precompile += JVectorMap::Rails.precompile_maps.map do |map_name|
|
12
|
+
"jvectormap/maps/#{map_name}.js"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
//= require jvectormap/jquery-jvectormap.js
|
2
|
+
//= require jvectormap/jquery-mousewheel.js
|
3
|
+
//= require jvectormap/lib/jvectormap.js
|
4
|
+
//= require jvectormap/lib/abstract-element.js
|
5
|
+
//= require jvectormap/lib/abstract-canvas-element.js
|
6
|
+
//= require jvectormap/lib/abstract-shape-element.js
|
7
|
+
//= require jvectormap/lib/svg-element.js
|
8
|
+
//= require jvectormap/lib/svg-group-element.js
|
9
|
+
//= require jvectormap/lib/svg-canvas-element.js
|
10
|
+
//= require jvectormap/lib/svg-shape-element.js
|
11
|
+
//= require jvectormap/lib/svg-path-element.js
|
12
|
+
//= require jvectormap/lib/svg-circle-element.js
|
13
|
+
//= require jvectormap/lib/vml-element.js
|
14
|
+
//= require jvectormap/lib/vml-group-element.js
|
15
|
+
//= require jvectormap/lib/vml-canvas-element.js
|
16
|
+
//= require jvectormap/lib/vml-shape-element.js
|
17
|
+
//= require jvectormap/lib/vml-path-element.js
|
18
|
+
//= require jvectormap/lib/vml-circle-element.js
|
19
|
+
//= require jvectormap/lib/vector-canvas.js
|
20
|
+
//= require jvectormap/lib/simple-scale.js
|
21
|
+
//= require jvectormap/lib/ordinal-scale.js
|
22
|
+
//= require jvectormap/lib/numeric-scale.js
|
23
|
+
//= require jvectormap/lib/color-scale.js
|
24
|
+
//= require jvectormap/lib/data-series.js
|
25
|
+
//= require jvectormap/lib/proj.js
|
26
|
+
//= require jvectormap/lib/world-map.js
|
@@ -0,0 +1,45 @@
|
|
1
|
+
/**
|
2
|
+
* jVectorMap version 1.2.1
|
3
|
+
*
|
4
|
+
* Copyright 2011-2013, Kirill Lebedev
|
5
|
+
* Licensed under the MIT license.
|
6
|
+
*
|
7
|
+
*/
|
8
|
+
(function( $ ){
|
9
|
+
var apiParams = {
|
10
|
+
set: {
|
11
|
+
colors: 1,
|
12
|
+
values: 1,
|
13
|
+
backgroundColor: 1,
|
14
|
+
scaleColors: 1,
|
15
|
+
normalizeFunction: 1,
|
16
|
+
focus: 1
|
17
|
+
},
|
18
|
+
get: {
|
19
|
+
selectedRegions: 1,
|
20
|
+
selectedMarkers: 1,
|
21
|
+
mapObject: 1,
|
22
|
+
regionName: 1
|
23
|
+
}
|
24
|
+
};
|
25
|
+
|
26
|
+
$.fn.vectorMap = function(options) {
|
27
|
+
var map,
|
28
|
+
methodName,
|
29
|
+
event,
|
30
|
+
map = this.children('.jvectormap-container').data('mapObject');
|
31
|
+
|
32
|
+
if (options === 'addMap') {
|
33
|
+
jvm.WorldMap.maps[arguments[1]] = arguments[2];
|
34
|
+
} else if ((options === 'set' || options === 'get') && apiParams[options][arguments[1]]) {
|
35
|
+
methodName = arguments[1].charAt(0).toUpperCase()+arguments[1].substr(1);
|
36
|
+
return map[options+methodName].apply(map, Array.prototype.slice.call(arguments, 2));
|
37
|
+
} else {
|
38
|
+
options = options || {};
|
39
|
+
options.container = this;
|
40
|
+
map = new jvm.WorldMap(options);
|
41
|
+
}
|
42
|
+
|
43
|
+
return this;
|
44
|
+
};
|
45
|
+
})( jQuery );
|
@@ -0,0 +1,84 @@
|
|
1
|
+
/*! Copyright (c) 2011 Brandon Aaron (http://brandonaaron.net)
|
2
|
+
* Licensed under the MIT License (LICENSE.txt).
|
3
|
+
*
|
4
|
+
* Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
|
5
|
+
* Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
|
6
|
+
* Thanks to: Seamus Leahy for adding deltaX and deltaY
|
7
|
+
*
|
8
|
+
* Version: 3.0.6
|
9
|
+
*
|
10
|
+
* Requires: 1.2.2+
|
11
|
+
*/
|
12
|
+
|
13
|
+
(function($) {
|
14
|
+
|
15
|
+
var types = ['DOMMouseScroll', 'mousewheel'];
|
16
|
+
|
17
|
+
if ($.event.fixHooks) {
|
18
|
+
for ( var i=types.length; i; ) {
|
19
|
+
$.event.fixHooks[ types[--i] ] = $.event.mouseHooks;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
$.event.special.mousewheel = {
|
24
|
+
setup: function() {
|
25
|
+
if ( this.addEventListener ) {
|
26
|
+
for ( var i=types.length; i; ) {
|
27
|
+
this.addEventListener( types[--i], handler, false );
|
28
|
+
}
|
29
|
+
} else {
|
30
|
+
this.onmousewheel = handler;
|
31
|
+
}
|
32
|
+
},
|
33
|
+
|
34
|
+
teardown: function() {
|
35
|
+
if ( this.removeEventListener ) {
|
36
|
+
for ( var i=types.length; i; ) {
|
37
|
+
this.removeEventListener( types[--i], handler, false );
|
38
|
+
}
|
39
|
+
} else {
|
40
|
+
this.onmousewheel = null;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
};
|
44
|
+
|
45
|
+
$.fn.extend({
|
46
|
+
mousewheel: function(fn) {
|
47
|
+
return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
|
48
|
+
},
|
49
|
+
|
50
|
+
unmousewheel: function(fn) {
|
51
|
+
return this.unbind("mousewheel", fn);
|
52
|
+
}
|
53
|
+
});
|
54
|
+
|
55
|
+
|
56
|
+
function handler(event) {
|
57
|
+
var orgEvent = event || window.event, args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;
|
58
|
+
event = $.event.fix(orgEvent);
|
59
|
+
event.type = "mousewheel";
|
60
|
+
|
61
|
+
// Old school scrollwheel delta
|
62
|
+
if ( orgEvent.wheelDelta ) { delta = orgEvent.wheelDelta/120; }
|
63
|
+
if ( orgEvent.detail ) { delta = -orgEvent.detail/3; }
|
64
|
+
|
65
|
+
// New school multidimensional scroll (touchpads) deltas
|
66
|
+
deltaY = delta;
|
67
|
+
|
68
|
+
// Gecko
|
69
|
+
if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
|
70
|
+
deltaY = 0;
|
71
|
+
deltaX = -1*delta;
|
72
|
+
}
|
73
|
+
|
74
|
+
// Webkit
|
75
|
+
if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY/120; }
|
76
|
+
if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = -1*orgEvent.wheelDeltaX/120; }
|
77
|
+
|
78
|
+
// Add event and delta to the front of the arguments
|
79
|
+
args.unshift(event, delta, deltaX, deltaY);
|
80
|
+
|
81
|
+
return ($.event.dispatch || $.event.handle).apply(this, args);
|
82
|
+
}
|
83
|
+
|
84
|
+
})(jQuery);
|
@@ -0,0 +1,67 @@
|
|
1
|
+
/**
|
2
|
+
* Implements abstract vector canvas.
|
3
|
+
* @constructor
|
4
|
+
* @param {HTMLElement} container Container to put element to.
|
5
|
+
* @param {Number} width Width of canvas.
|
6
|
+
* @param {Number} height Height of canvas.
|
7
|
+
*/
|
8
|
+
jvm.AbstractCanvasElement = function(container, width, height){
|
9
|
+
this.container = container;
|
10
|
+
this.setSize(width, height);
|
11
|
+
this.rootElement = new jvm[this.classPrefix+'GroupElement']();
|
12
|
+
this.node.appendChild( this.rootElement.node );
|
13
|
+
this.container.appendChild(this.node);
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Add element to the certain group inside of the canvas.
|
18
|
+
* @param {HTMLElement} element Element to add to canvas.
|
19
|
+
* @param {HTMLElement} group Group to add element into or into root group if not provided.
|
20
|
+
*/
|
21
|
+
jvm.AbstractCanvasElement.prototype.add = function(element, group){
|
22
|
+
group = group || this.rootElement;
|
23
|
+
group.add(element);
|
24
|
+
element.canvas = this;
|
25
|
+
}
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Create path and add it to the canvas.
|
29
|
+
* @param {Object} config Parameters of path to create.
|
30
|
+
* @param {Object} style Styles of the path to create.
|
31
|
+
* @param {HTMLElement} group Group to add path into.
|
32
|
+
*/
|
33
|
+
jvm.AbstractCanvasElement.prototype.addPath = function(config, style, group){
|
34
|
+
var el = new jvm[this.classPrefix+'PathElement'](config, style);
|
35
|
+
|
36
|
+
this.add(el, group);
|
37
|
+
return el;
|
38
|
+
};
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Create circle and add it to the canvas.
|
42
|
+
* @param {Object} config Parameters of path to create.
|
43
|
+
* @param {Object} style Styles of the path to create.
|
44
|
+
* @param {HTMLElement} group Group to add circle into.
|
45
|
+
*/
|
46
|
+
jvm.AbstractCanvasElement.prototype.addCircle = function(config, style, group){
|
47
|
+
var el = new jvm[this.classPrefix+'CircleElement'](config, style);
|
48
|
+
|
49
|
+
this.add(el, group);
|
50
|
+
return el;
|
51
|
+
};
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Add group to the another group inside of the canvas.
|
55
|
+
* @param {HTMLElement} group Group to add circle into or root group if not provided.
|
56
|
+
*/
|
57
|
+
jvm.AbstractCanvasElement.prototype.addGroup = function(parentGroup){
|
58
|
+
var el = new jvm[this.classPrefix+'GroupElement']();
|
59
|
+
|
60
|
+
if (parentGroup) {
|
61
|
+
parentGroup.node.appendChild(el.node);
|
62
|
+
} else {
|
63
|
+
this.node.appendChild(el.node);
|
64
|
+
}
|
65
|
+
el.canvas = this;
|
66
|
+
return el;
|
67
|
+
};
|
@@ -0,0 +1,73 @@
|
|
1
|
+
/**
|
2
|
+
* Basic wrapper for DOM element.
|
3
|
+
* @constructor
|
4
|
+
* @param {String} name Tag name of the element
|
5
|
+
* @param {Object} config Set of parameters to initialize element with
|
6
|
+
*/
|
7
|
+
jvm.AbstractElement = function(name, config){
|
8
|
+
/**
|
9
|
+
* Underlying DOM element
|
10
|
+
* @type {DOMElement}
|
11
|
+
* @private
|
12
|
+
*/
|
13
|
+
this.node = this.createElement(name);
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Name of underlying element
|
17
|
+
* @type {String}
|
18
|
+
* @private
|
19
|
+
*/
|
20
|
+
this.name = name;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Internal store of attributes
|
24
|
+
* @type {Object}
|
25
|
+
* @private
|
26
|
+
*/
|
27
|
+
this.properties = {};
|
28
|
+
|
29
|
+
if (config) {
|
30
|
+
this.set(config);
|
31
|
+
}
|
32
|
+
};
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Set attribute of the underlying DOM element.
|
36
|
+
* @param {String} name Name of attribute
|
37
|
+
* @param {Number|String} config Set of parameters to initialize element with
|
38
|
+
*/
|
39
|
+
jvm.AbstractElement.prototype.set = function(property, value){
|
40
|
+
var key;
|
41
|
+
|
42
|
+
if (typeof property === 'object') {
|
43
|
+
for (key in property) {
|
44
|
+
this.properties[key] = property[key];
|
45
|
+
this.applyAttr(key, property[key]);
|
46
|
+
}
|
47
|
+
} else {
|
48
|
+
this.properties[property] = value;
|
49
|
+
this.applyAttr(property, value);
|
50
|
+
}
|
51
|
+
};
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Returns value of attribute.
|
55
|
+
* @param {String} name Name of attribute
|
56
|
+
*/
|
57
|
+
jvm.AbstractElement.prototype.get = function(property){
|
58
|
+
return this.properties[property];
|
59
|
+
};
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Applies attribute value to the underlying DOM element.
|
63
|
+
* @param {String} name Name of attribute
|
64
|
+
* @param {Number|String} config Value of attribute to apply
|
65
|
+
* @private
|
66
|
+
*/
|
67
|
+
jvm.AbstractElement.prototype.applyAttr = function(property, value){
|
68
|
+
this.node.setAttribute(property, value);
|
69
|
+
};
|
70
|
+
|
71
|
+
jvm.AbstractElement.prototype.remove = function(){
|
72
|
+
jvm.$(this.node).remove();
|
73
|
+
};
|