highcharts-ng-rails 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d44849fc5f006276f6f570d58cc84cd977e0dfd
4
+ data.tar.gz: 47a5f57fc5653de34d947dff8d2dc78ebfff2c5b
5
+ SHA512:
6
+ metadata.gz: c99170b2331eaba3c511d6c7fa98b5c79ce878e3f1f42bb6292d4ca070828f2fcd24b80564f4e501eed8ea159262be7ffa6b303afaeff4fcd7cd62d7e717b370
7
+ data.tar.gz: 5e6507837b3b63f84fe381e1c16e7ead84dbb690d4f56208857257708a1eb227d715393404db3442898f3bcf4bba2164f6e32fa470c67464151d4229bd558edf
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ sauce
6
+ tmp
7
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) 2011 Iven Hsu <ivenvd@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ # Highcharts-NG-Rails
2
+
3
+ This gem just includes [highcharts-ng](https://github.com/pablojim/highcharts-ng) as an asset in the Rails 3.1 (or newer) asset pipeline.
4
+
5
+ ## Installation
6
+
7
+ Add the gem to the Gemfile
8
+
9
+ gem "highcharts-rails"
10
+ gem "highcharts-ng-rails", "~> 0.0.3"
11
+ # The gem version mirrors the included version of highcharts-ng
12
+
13
+ ## Usage
14
+
15
+ In your JavaScript manifest (e.g. `application.js`)
16
+
17
+ //= require highcharts-ng
18
+
19
+ ## Licensing
20
+
21
+ Both highcharts-ng and the gem itself is released under the MIT license
22
+
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,199 @@
1
+ 'use strict';
2
+
3
+ angular.module('highcharts-ng', [])
4
+ .directive('highchart', function () {
5
+
6
+ function prependMethod(obj, method, func) {
7
+ var original = obj[method];
8
+ obj[method] = function () {
9
+ var args = Array.prototype.slice.call(arguments);
10
+ func.apply(this, args);
11
+ if(original) {
12
+ return original.apply(this, args);
13
+ } else {
14
+ return;
15
+ }
16
+
17
+ };
18
+ }
19
+
20
+ function deepExtend(destination, source) {
21
+ for (var property in source) {
22
+ if (source[property] && source[property].constructor &&
23
+ source[property].constructor === Object) {
24
+ destination[property] = destination[property] || {};
25
+ deepExtend(destination[property], source[property]);
26
+ } else {
27
+ destination[property] = source[property];
28
+ }
29
+ }
30
+ return destination;
31
+ }
32
+
33
+ var seriesId = 0;
34
+ var ensureIds = function (series) {
35
+ series.forEach(function (s) {
36
+ if (!angular.isDefined(s.id)) {
37
+ s.id = "series-" + seriesId++;
38
+ }
39
+ });
40
+ }
41
+
42
+ var defaultOptions = {
43
+ chart: {
44
+ events: {}
45
+ },
46
+ title: {},
47
+ series: [],
48
+ navigator: {enabled: false}
49
+ }
50
+
51
+ var getMergedOptions = function (scope, element, config) {
52
+ var mergedOptions = {}
53
+ if (config.options) {
54
+ mergedOptions = deepExtend(defaultOptions, config.options);
55
+ } else {
56
+ mergedOptions = defaultOptions;
57
+ }
58
+ mergedOptions.chart.renderTo = element[0];
59
+ if(config.xAxis) {
60
+ prependMethod(mergedOptions.chart.events, 'selection', function(e){
61
+ var thisChart = this;
62
+ if(e.xAxis) {
63
+ scope.$apply(function () {
64
+ scope.config.xAxis.currentMin = e.xAxis[0].min;
65
+ scope.config.xAxis.currentMax = e.xAxis[0].max;
66
+ });
67
+ } else {
68
+ //handle reset button - zoom out to all
69
+ scope.$apply(function () {
70
+ scope.config.xAxis.currentMin = thisChart.xAxis[0].dataMin;
71
+ scope.config.xAxis.currentMax = thisChart.xAxis[0].dataMax;
72
+ });
73
+ }
74
+ });
75
+
76
+ prependMethod(mergedOptions.chart.events, 'addSeries', function(e){
77
+ scope.config.xAxis.currentMin = this.xAxis[0].min || scope.config.xAxis.currentMin;
78
+ scope.config.xAxis.currentMax = this.xAxis[0].max || scope.config.xAxis.currentMax;
79
+ });
80
+ }
81
+
82
+ if(config.xAxis) {
83
+ mergedOptions.xAxis = angular.copy(config.xAxis)
84
+ }
85
+ if(config.title) {
86
+ mergedOptions.title = config.title
87
+ }
88
+ return mergedOptions
89
+ }
90
+
91
+ var updateZoom = function (axis, modelAxis) {
92
+ var extremes = axis.getExtremes();
93
+ if(modelAxis.currentMin !== extremes.dataMin || modelAxis.currentMax !== extremes.dataMax) {
94
+ axis.setExtremes(modelAxis.currentMin, modelAxis.currentMax, false);
95
+ }
96
+ }
97
+
98
+ var processExtremes = function(chart, axis) {
99
+ if(axis.currentMin || axis.currentMax) {
100
+ chart.xAxis[0].setExtremes(axis.currentMin, axis.currentMax, true);
101
+ }
102
+ }
103
+
104
+ var processSeries = function(chart, series) {
105
+ var ids = []
106
+ if(series) {
107
+ ensureIds(series);
108
+
109
+ //Find series to add or update
110
+ series.forEach(function (s) {
111
+ ids.push(s.id)
112
+ var chartSeries = chart.get(s.id);
113
+ if (chartSeries) {
114
+ chartSeries.update(angular.copy(s), false);
115
+ } else {
116
+ chart.addSeries(angular.copy(s), false)
117
+ }
118
+ });
119
+ }
120
+
121
+ //Now remove any missing series
122
+ for(var i = chart.series.length - 1; i >= 0; i--) {
123
+ var s = chart.series[i];
124
+ if (ids.indexOf(s.options.id) < 0) {
125
+ s.remove(false);
126
+ }
127
+ };
128
+
129
+ }
130
+
131
+ var initialiseChart = function(scope, element, config) {
132
+ config || (config = {});
133
+ var mergedOptions = getMergedOptions(scope, element, config);
134
+ var chart = config.useHighStocks ? new Highcharts.StockChart(mergedOptions) : new Highcharts.Chart(mergedOptions);
135
+ if(config.xAxis) {
136
+ processExtremes(chart, config.xAxis);
137
+ }
138
+ processSeries(chart, config.series);
139
+ if(config.loading) {
140
+ chart.showLoading()
141
+ }
142
+ chart.redraw();
143
+ return chart;
144
+ }
145
+
146
+
147
+ return {
148
+ restrict: 'EAC',
149
+ replace: true,
150
+ template: '<div></div>',
151
+ scope: {
152
+ config: '='
153
+ },
154
+ link: function (scope, element, attrs) {
155
+
156
+ var chart = initialiseChart(scope, element, scope.config);
157
+
158
+ scope.$watch("config.series", function (newSeries, oldSeries) {
159
+ //do nothing when called on registration
160
+ if (newSeries === oldSeries) return;
161
+ processSeries(chart, newSeries);
162
+ chart.redraw();
163
+ }, true);
164
+
165
+ scope.$watch("config.title", function (newTitle) {
166
+ chart.setTitle(newTitle, true);
167
+ }, true);
168
+
169
+ scope.$watch("config.loading", function (loading) {
170
+ if(loading) {
171
+ chart.showLoading()
172
+ } else {
173
+ chart.hideLoading()
174
+ }
175
+ });
176
+
177
+ scope.$watch("config.useHighStocks", function (useHighStocks) {
178
+ chart.destroy();
179
+ chart = initialiseChart(scope, element, scope.config);
180
+ });
181
+
182
+ scope.$watch("config.xAxis", function (newAxes, oldAxes) {
183
+ if (newAxes === oldAxes) return;
184
+ if(newAxes) {
185
+ chart.xAxis[0].update(newAxes);
186
+ updateZoom(chart.xAxis[0], angular.copy(newAxes));
187
+ chart.redraw();
188
+ }
189
+ }, true);
190
+ scope.$watch("config.options", function (newOptions, oldOptions, scope) {
191
+ //do nothing when called on registration
192
+ if (newOptions === oldOptions) return;
193
+ chart.destroy();
194
+ chart = initialiseChart(scope, element, scope.config);
195
+
196
+ }, true);
197
+ }
198
+ }
199
+ });
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "highcharts-ng/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "highcharts-ng-rails"
7
+ s.version = HighchartsNG::VERSION
8
+ s.authors = ["Iven Hsu"]
9
+ s.email = ["ivenvd@gmail.com"]
10
+ s.homepage = "https://github.com/iven/highcharts-ng-rails"
11
+ s.summary = %q{AngularJS directive for Highcharts}
12
+ s.description = %q{Gem that includes AngularJS directive for Highcharts (Interactive JavaScript charts for your web projects), in the Rails Asset Pipeline introduced in Rails 3.1}
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency "railties", ">= 3.1"
21
+ s.add_development_dependency "bundler", "~> 1.0"
22
+ s.add_development_dependency "rails", ">= 3.1"
23
+ end
@@ -0,0 +1,2 @@
1
+ require 'highcharts-ng/version'
2
+ require 'highcharts-ng/rails'
@@ -0,0 +1,6 @@
1
+ module HighchartsNG
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module HighchartsNG
2
+ VERSION = "0.0.3"
3
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: highcharts-ng-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Iven Hsu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ description: Gem that includes AngularJS directive for Highcharts (Interactive JavaScript
56
+ charts for your web projects), in the Rails Asset Pipeline introduced in Rails 3.1
57
+ email:
58
+ - ivenvd@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.markdown
67
+ - Rakefile
68
+ - app/assets/javascripts/highcharts-ng.js
69
+ - highcharts-ng-rails.gemspec
70
+ - lib/highcharts-ng-rails.rb
71
+ - lib/highcharts-ng/rails.rb
72
+ - lib/highcharts-ng/version.rb
73
+ homepage: https://github.com/iven/highcharts-ng-rails
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.3
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: AngularJS directive for Highcharts
97
+ test_files: []