kitechart 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ebe859905323674263f28b93817e4caa51278f0c
4
+ data.tar.gz: a0b08984926d949d2ecb1714b48622af5688c4e1
5
+ SHA512:
6
+ metadata.gz: e7edfb7e417583d9cc1bde8b32995700af24b5232f0e72b07924bb32635b2e0f12741d7f71cc3970a50e1810f4d586db351f1f23621054cf01fb5617da200752
7
+ data.tar.gz: 31dd6ebfa75e2d88f76c2b638907889a0565867651dbae04a4830c03a5e76f608561386a49bd7bca7a13574ae8d83e685056d18d303d0a07fb9489c509434c8c
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
11
+ *.gem
@@ -0,0 +1 @@
1
+ -global
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ 2.3.0
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kitechart.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 TODO: Write your name
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,92 @@
1
+ # Kitechart
2
+ A data formatter and highcharts drilldown wrapper gem
3
+
4
+ Sponsored by [tworedkites](http://tworedkites.com/).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'kitechart', '~> 0.1.0'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install kitechart
21
+
22
+ Then add this line to your application.js file
23
+
24
+ ```
25
+ //= require kitechart
26
+ ```
27
+
28
+ ## Useage
29
+
30
+ To setup a two level drilldown highchart add the following code to your project.
31
+
32
+ This is the code contained in the view file
33
+
34
+ ```
35
+ <div id="container" class="ui container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
36
+ ```
37
+
38
+ This is the code contained in the views javascript file
39
+
40
+ ```
41
+ $(function () {
42
+ 'use strict';
43
+ window.Kites = {
44
+ getData: function () {
45
+ $.getJSON($(location).attr('href')+'kites.json').then(function (data) {
46
+ Chart.generateChart('Kites By Color', 'Count', 'column', data['colors'], data['size'], data['material']);
47
+ });
48
+ }
49
+ };
50
+ });
51
+ ```
52
+
53
+ This is the code contained in the controller file
54
+
55
+ ```
56
+ class KitesController < ApplicationController
57
+ def index
58
+ @kites = Kite.all
59
+
60
+ respond_to do |format|
61
+ format.html
62
+ format.json do
63
+ colors, size, material = get_json_data
64
+ render json: { colors: colors, size: size, material: material }
65
+ end
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ def get_json_data
72
+ Kitechart::DataFormatter.new(@kites,
73
+ 'color',
74
+ 'size',
75
+ 'material').get_data
76
+ end
77
+ end
78
+ ```
79
+
80
+ ## Demo
81
+ The demo app webpage for the kitechart gem is viewable [here](https://protected-shore-59130.herokuapp.com/)
82
+ The demo app codebase can also be viewed [here](https://github.com/Mbuckley0/kitechart)
83
+
84
+ ## Contributing
85
+
86
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mbuckley0/kitechart.
87
+
88
+
89
+ ## License
90
+
91
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
92
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,59 @@
1
+ $(function () {
2
+ window.Chart = {
3
+ generateChart: function(title, yAxisTitle, chartType, options) {
4
+ var options = options || {};
5
+ if (options['thirdLevelData'] != undefined) {
6
+ Chart.generateThirdLevelChart(options['topLevelData'], options['secondLevelData'], options['thirdLevelData'], title, yAxisTitle, chartType, options);
7
+ } else if (options['secondLevelData'] != undefined) {
8
+ Chart.generateSecondLevelChart(options['topLevelData'], options['secondLevelData'], title, yAxisTitle, chartType, options);
9
+ } else if(options['topLevelData'] != undefined) {
10
+ Chart.generateTopLevelChart(options['topLevelData'], title, yAxisTitle, chartType, options);
11
+ }
12
+ },
13
+
14
+ generateTopLevelChart: function(topLevelData, title, yAxisTitle, chartType, options) {
15
+ formattedData = topLevelData;
16
+ $.each(topLevelData, function(key, value) {
17
+ formattedData[key] = Math.round(value);
18
+ });
19
+ TopLevelChart.displayChart(formattedData, title, yAxisTitle, chartType, options);
20
+ },
21
+
22
+ generateSecondLevelChart: function(topLevelData, secondLevelData, title, yAxisTitle, chartType, options) {
23
+ formattedData = topLevelData;
24
+ $.each(topLevelData, function(key, value) {
25
+ formattedData[key] = {label: Math.round(value)};
26
+ formattedData[key]['drilldown'] = secondLevelData[key];
27
+ $.each(formattedData[key]['drilldown'], function(drilldownKey, drilldownValue) {
28
+ formattedData[key]['drilldown'][drilldownKey] = Math.round(drilldownValue)
29
+ });
30
+ });
31
+ OneLevelDownChart.displayChart(formattedData, title, yAxisTitle, chartType, options);
32
+ },
33
+
34
+ generateThirdLevelChart: function(topLevelData, secondLevelData, thirdLevelData, title, yAxisTitle, chartType, options) {
35
+ formattedData = topLevelData;
36
+ $.each(topLevelData, function(key, value) {
37
+ i = 0;
38
+ formattedData[key] = {label: Math.round(value)};
39
+
40
+ formattedData[key]['drilldown'] = { label: secondLevelData[key] };
41
+ formattedData[key]['drilldown']['drilldown'] = [];
42
+ $.each(formattedData[key]['drilldown']['label'], function(drilldownKey) {
43
+ formattedData[key]['drilldown']['label'][drilldownKey] = Math.round(formattedData[key]['drilldown']['label'][drilldownKey]);
44
+ formattedData[key]['drilldown']['drilldown'].push({ drilldownKey: thirdLevelData[key][drilldownKey] });
45
+
46
+ $.each(formattedData[key]['drilldown']['drilldown'][i], function(secondDrilldownIDKey, secondDrilldownIDValue) {
47
+ if(secondDrilldownIDValue != undefined) {
48
+ $.each(secondDrilldownIDValue, function(secondDrilldownKey, secondDrilldownValue) {
49
+ formattedData[key]['drilldown']['drilldown'][i][secondDrilldownIDKey][secondDrilldownKey] = Math.round(secondDrilldownValue);
50
+ });
51
+ }
52
+ });
53
+ i++
54
+ });
55
+ });
56
+ TwoLevelDownChart.displayChart(formattedData, title, yAxisTitle, chartType, options);
57
+ }
58
+ }
59
+ });
@@ -0,0 +1,3 @@
1
+ //= require highcharts
2
+ //= require drilldown
3
+ //= require_tree .
@@ -0,0 +1,95 @@
1
+ $(function () {
2
+ // Data is expected to be in the form of {label: {label: value, drilldown: {label: value}}, label: {label: value, drilldown:{label: value}}}
3
+ window.OneLevelDownChart = {
4
+ displayChart: function (data, title, yAxisTitle, chartType, options) {
5
+ var options = options || {};
6
+ var chartData = OneLevelDownChart.formatTopLevelData(data);
7
+ var drilldownData = OneLevelDownChart.formatFirstDrilldownData(data);
8
+
9
+ $('#container').highcharts({
10
+ chart: {
11
+ type: chartType,
12
+ backgroundColor: options['chart-backgroundColor'] || 'white'
13
+ },
14
+ title: {
15
+ text: title
16
+ },
17
+ subtitle: {
18
+ text: options['subtitle-text'] || 'Click the columns to drill down.'
19
+ },
20
+ xAxis: {
21
+ type: options['xAxis-type'] || 'category'
22
+ },
23
+ yAxis: {
24
+ title: {
25
+ text: yAxisTitle
26
+ }
27
+
28
+ },
29
+ plotOptions: {
30
+ series: {
31
+ borderWidth: options['plotOptions-series-borderWidth'] || 0,
32
+ dataLabels: {
33
+ enabled: options['plotOptions-series-dataLabel-enabled'] || true,
34
+ format: options['plotOptions-series-dataLabel-format'] || '{point.y:,.0f}'
35
+ }
36
+ }
37
+ },
38
+ legend: {
39
+ enabled: options['legend-enabled'] || false
40
+ },
41
+ tooltip: {
42
+ headerFormat: options['tooltip-headerFormat'] || '',
43
+ pointFormat: options['tooltip-pointFormat'] || '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:,.2f}</b><br/>'
44
+ },
45
+ series: [{
46
+ point: {
47
+ events: {
48
+ click: options['series-point-events-click'] || ''
49
+ }
50
+ },
51
+ colorByPoint: options['series-colorByPoint'] || true,
52
+ data: chartData
53
+ }],
54
+ drilldown: {
55
+ series: drilldownData
56
+ }
57
+ });
58
+ },
59
+
60
+ formatTopLevelData: function(data) {
61
+ var chartData = [];
62
+
63
+ $.each(data, function(key,value){
64
+ chartData.push({
65
+ name: key,
66
+ y: value['label'],
67
+ drilldown: key
68
+ });
69
+ });
70
+
71
+ return chartData;
72
+ },
73
+
74
+ formatFirstDrilldownData: function(data) {
75
+ var drilldownData = [];
76
+
77
+ $.each(data, function(key, value) {
78
+ objectData = [];
79
+ for(var drilldownKey in value['drilldown']) {
80
+ objectData.push([
81
+ drilldownKey,
82
+ value['drilldown'][drilldownKey]
83
+ ]);
84
+ }
85
+
86
+ drilldownData.push({
87
+ name: key,
88
+ id: key,
89
+ data: objectData
90
+ });
91
+ });
92
+ return drilldownData;
93
+ }
94
+ }
95
+ });
@@ -0,0 +1,67 @@
1
+ $(function () {
2
+ // Data is expected to be in the form of {label: value, label: value, label: value}
3
+ window.TopLevelChart = {
4
+ displayChart: function (data, title, yAxisTitle, chartType, options) {
5
+ var options = options || {};
6
+ var chartData = TopLevelChart.formatData(data);
7
+
8
+ $('#container').highcharts({
9
+ chart: {
10
+ type: chartType,
11
+ backgroundColor: options['chart-backgroundColor'] || 'white'
12
+ },
13
+ title: {
14
+ text: title
15
+ },
16
+ subtitle: {
17
+ text: options['subtitle-text'] || ''
18
+ },
19
+ xAxis: {
20
+ type: options['xAxis-type'] || 'category'
21
+ },
22
+ yAxis: {
23
+ min: 0,
24
+ title: {
25
+ text: yAxisTitle
26
+ }
27
+ },
28
+ plotOptions: {
29
+ series: {
30
+ borderWidth: options['plotOptions-series-borderWidth'] || 0,
31
+ dataLabels: {
32
+ enabled: options['plotOptions-series-dataLabel-enabled'] || true,
33
+ format: options['plotOptions-series-dataLabel-format'] || '{point.y:,.0f}'
34
+ }
35
+ }
36
+ },
37
+ legend: {
38
+ enabled: options['legend-enabled'] || false
39
+ },
40
+ tooltip: {
41
+ headerFormat: options['tooltip-headerFormat'] || '',
42
+ pointFormat: options['tooltip-pointFormat'] || '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:,.2f}</b><br/>'
43
+ },
44
+ series: [{
45
+ point: {
46
+ events: {
47
+ click: options['series-point-events-click'] || ''
48
+ }
49
+ },
50
+ colorByPoint: options['series-colorByPoint'] || true,
51
+ data: chartData
52
+ }]
53
+ });
54
+ },
55
+
56
+ formatData: function (data) {
57
+ var chartData = [];
58
+ $.each(data, function(key, value){
59
+ chartData.push({
60
+ name: key,
61
+ y: value
62
+ });
63
+ });
64
+ return chartData;
65
+ }
66
+ }
67
+ });
@@ -0,0 +1,120 @@
1
+ $(function () {
2
+ // Data is expected to be in the form of {label: {label: value, drilldown: {label: value}}, label: {label: value, drilldown:{label: value}}}
3
+ window.TwoLevelDownChart = {
4
+ displayChart: function (data, title, yAxisTitle, chartType, options) {
5
+ var options = options || {};
6
+ var chartData = TwoLevelDownChart.formatTopLevelData(data);
7
+ var drilldownData = TwoLevelDownChart.formatDrilldownData(data);
8
+
9
+ $('#container').highcharts({
10
+ chart: {
11
+ type: chartType,
12
+ backgroundColor: options['chart-backgroundColor'] || 'white'
13
+ },
14
+ title: {
15
+ text: title
16
+ },
17
+ subtitle: {
18
+ text: options['subtitle-text'] || 'Click the columns to drill down.'
19
+ },
20
+ xAxis: {
21
+ type: options['xAxis-type'] || 'category'
22
+ },
23
+ yAxis: {
24
+ title: {
25
+ text: yAxisTitle
26
+ }
27
+
28
+ },
29
+ plotOptions: {
30
+ series: {
31
+ borderWidth: options['plotOptions-series-borderWidth'] || 0,
32
+ dataLabels: {
33
+ enabled: options['plotOptions-series-dataLabel-enabled'] || true,
34
+ format: options['plotOptions-series-dataLabel-format'] || '{point.y:,.0f}'
35
+ }
36
+ }
37
+ },
38
+ legend: {
39
+ enabled: options['legend-enabled'] || false
40
+ },
41
+ tooltip: {
42
+ headerFormat: options['tooltip-headerFormat'] || '',
43
+ pointFormat: options['tooltip-pointFormat'] || '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:,.2f}</b><br/>'
44
+ },
45
+ series: [{
46
+ point: {
47
+ events: {
48
+ click: options['series-point-events-click'] || ''
49
+ }
50
+ },
51
+ colorByPoint: options['series-colorByPoint'] || true,
52
+ data: chartData
53
+ }],
54
+ drilldown: {
55
+ series: drilldownData
56
+ }
57
+ });
58
+ },
59
+
60
+ formatTopLevelData: function (data) {
61
+ var chartData = [];
62
+
63
+ $.each(data, function(key, value) {
64
+ chartData.push({
65
+ name: key,
66
+ y: value['label'],
67
+ drilldown: key
68
+ });
69
+ });
70
+ return chartData;
71
+ },
72
+
73
+ formatDrilldownData: function (data) {
74
+ var drilldownData = [];
75
+
76
+ $.each(data, function(key, value) {
77
+ firstObjectData = [];
78
+ i = 0;
79
+ $.each(value['drilldown']['label'], function(firstDrilldownKey, firstDrilldownValue) {
80
+ secondObjectData = [];
81
+ firstObjectData.push({
82
+ name: firstDrilldownKey,
83
+ y: firstDrilldownValue,
84
+ drilldown: key + '_' + firstDrilldownKey
85
+ });
86
+
87
+
88
+ $.each(value['drilldown']['drilldown'][i], function(secondDrilldownIDKey, secondDrilldownIDValue) {
89
+ if(secondDrilldownIDValue != undefined) {
90
+ $.each(secondDrilldownIDValue, function(secondDrilldownKey, secondDrilldownValue) {
91
+ secondObjectData.push([
92
+ secondDrilldownKey,
93
+ data[key]['drilldown']['drilldown'][i][secondDrilldownIDKey][secondDrilldownKey]
94
+ ]);
95
+ });
96
+ }
97
+ });
98
+
99
+ if (secondObjectData.length >= 1) {
100
+ drilldownData.push({
101
+ name: firstDrilldownKey,
102
+ id: key + '_' + firstDrilldownKey,
103
+ data: secondObjectData
104
+ });
105
+ }
106
+ i++;
107
+ });
108
+
109
+ if (firstObjectData.length >= 1) {
110
+ drilldownData.push({
111
+ name: key,
112
+ id: key,
113
+ data: firstObjectData
114
+ });
115
+ }
116
+ });
117
+ return drilldownData;
118
+ }
119
+ }
120
+ });