jvectormap-rails4 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/History.txt +3 -0
- data/README.md +60 -0
- data/Rakefile +38 -0
- data/jvectormap-rails4.gemspec +20 -0
- data/lib/jvectormap/rails4/engine.rb +8 -0
- data/lib/jvectormap/rails4/railtie.rb +17 -0
- data/lib/jvectormap/rails4/version.rb +8 -0
- data/lib/jvectormap/rails4.rb +7 -0
- data/lib/jvectormap-rails4.rb +26 -0
- data/tasks/jvectormap.rake +6 -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/javascripts/jvectormap.js +26 -0
- data/vendor/assets/stylesheets/jvectormap.css +37 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 114dde5e685858ff01de065221f786edb4892613
|
4
|
+
data.tar.gz: 66b32f20d9507c1697684850a92e1f428ae641aa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b2bd4450b339ca0fd5be807e18f46deeabf3645b240761ddfcd8f61b7fb429c6c4054fadca16e7063d9e11415f229237b54cab55f9b54fa0335a43d9ccd6e72
|
7
|
+
data.tar.gz: fa3691edccb3b5b1ff74fb08a7e6da709241be239fa0bf8bec254f1ccd76fe529dfe3107a67e4851531bdd1d16c758fc4ebdff0b24011ac2bbe98e0303accfba
|
data/Gemfile
ADDED
data/History.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Jvectormap::Rails4
|
2
|
+
|
3
|
+
[jVectorMap](http://jvectormap.com/) for the Rails asset pipeline
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'jvectormap-rails4'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install jvectormap-rails4
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
You can add jvectormap-rails to your `application.js` file using a require statement like this:
|
22
|
+
|
23
|
+
```
|
24
|
+
//= require jvectormap
|
25
|
+
```
|
26
|
+
|
27
|
+
To add support for whatever maps you want to use, include them from the `jvectormap/maps` path:
|
28
|
+
|
29
|
+
```
|
30
|
+
//= require jvectormap
|
31
|
+
//= require jvectormap/maps/us_merc_en
|
32
|
+
```
|
33
|
+
|
34
|
+
The basic pattern is `{country}-{region}_{city}_{projection}_{language}`. For example, the map `us-il-chicago_mill_en` has a country of `us` (United States), region of `il` (Illinois), city of `chicago`, projection of `mill` (Miller), and a language of `en` (English). Other common projections include Mercator (`merc`), and Albers equal area (`aea`).
|
35
|
+
|
36
|
+
|
37
|
+
### Asset Precompilation
|
38
|
+
|
39
|
+
jvectormap-rails supports precompiling individual maps. Add an initializer to your app, eg. `config/initializers/jvectormap.rb`:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
JVectorMap::Rails.precompile_maps << "us_merc_en"
|
43
|
+
```
|
44
|
+
|
45
|
+
### Rake Tasks
|
46
|
+
|
47
|
+
Get a list of all available maps by running this from within your Rails app's root:
|
48
|
+
|
49
|
+
```
|
50
|
+
bundle exec rake jvectormap:maps
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
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/rails4/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "jvectormap-rails4"
|
6
|
+
s.version = ::JVectorMap::Rails4::VERSION
|
7
|
+
s.authors = ["Frank Xie"]
|
8
|
+
s.email = ["frank@51shepherd.com"]
|
9
|
+
s.homepage = "https://github.com/FrankXie2012/jvectormap-rails4"
|
10
|
+
|
11
|
+
s.description = s.summary = "jVectorMap for the Rails 4 asset pipeline"
|
12
|
+
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
s.has_rdoc = true
|
15
|
+
|
16
|
+
s.add_dependency 'railties', '~> 4.0.0'
|
17
|
+
|
18
|
+
s.require_path = 'lib'
|
19
|
+
s.files = Dir["{lib,vendor,tasks}/**/*", "Gemfile", "History.txt", "LICENSE", "README.md", "Rakefile", "jvectormap-rails4.gemspec"]
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module JVectorMap
|
4
|
+
module Rails4
|
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
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module JVectorMap
|
4
|
+
module Rails4
|
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/rails4/version'
|
25
|
+
require 'jvectormap/rails4/engine'
|
26
|
+
require 'jvectormap/rails4/railtie'
|
@@ -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
|
+
};
|
@@ -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
|
+
};
|