jquery_cheats 2.3.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,7 +5,7 @@ library.
5
5
  It is as easy as adding this to your Gemfile
6
6
 
7
7
  ```ruby
8
- gem 'jquery_cheats','~>2.1.0'
8
+ gem 'jquery_cheats','~>3.0.0'
9
9
  ```
10
10
 
11
11
  Then add the following to app/assets/application.js
@@ -73,14 +73,4 @@ string such as(item=4&item2=3)
73
73
 
74
74
  JQuery Cheats comes packaged with JQueryPlots as of 2.1.0, but some functions may not be available until later dates.
75
75
 
76
- ###Barchart
77
-
78
- JQuery Cheats Barchart is the first graph to be implemented and uses XML to parse the data.
79
-
80
- Make sure the following is in your app/assets/javascripts/application.js file
81
-
82
- ```js
83
- //= require jqplot/plugins/jqplot.barRenderer.min.js
84
- //= require jqplot/plugins/jqplot.categoryAxisRenderer.min.js
85
- //= require jqplot/plugins/jqplot.pointLabels.min.js
86
- ```
76
+ See the wiki to learn how to make a bar chart, or pie chart.
@@ -1,269 +1,184 @@
1
- var categoryPos = 0;
2
1
  $(document).ready(function(){
3
- //make select boxes ajax-compatible by adding two params data-onchange=true and data-url="/path/to"
4
- $('select[data-onchange]').live("change",function(){
5
- $.ajax({type: "post",
6
- url: $(this).attr("data-url"),
7
- data: $(this).serialize(),
8
- success: function(data){eval(data);},
9
- dataType: "script"});
10
- });
11
- //make radio buttons onclick compatible
12
- $('input[type="radio"][data-onclick]').live("change",function()
2
+ //the following are for AJAX requests of form objects
3
+ $("select[data-onchange]").live("change",function()
13
4
  {
14
- data = $(this).serialize();
5
+ $.ajax({type: "post",
6
+ url: $(this).attr("data-url"),
7
+ data: $(this).serialize(),
8
+ success: function(data){eval(data);},
9
+ dataType: "script"});
10
+ });
11
+ $('input[type="radio"][data-onclick]').live("change", function(){
12
+ data = $(this).serialze();
15
13
  if($(this).attr("data-params"))
16
14
  {
17
15
  data += "&"+$(this).attr("data-params");
18
16
  }
19
- $.ajax({type: "post",
20
- url: eval($(this).attr("data-onclick")),
21
- data: data,
22
- success: function(data){eval(data);},
23
- dataType: "script"});
17
+ $.ajax({
18
+ type: "post",
19
+ url: eval($(this).attr("data-onclick")),
20
+ data: data,
21
+ success: function(data){eval(data);},
22
+ dataType: "script"
23
+ })
24
24
  });
25
- //start loading the pie charts...
25
+ //The following Load jqPlot graphs and charts
26
26
  $("div.piechart").each(function(){
27
27
  pieChart($(this).attr("id"),$(this).attr("data-xmlurl"));
28
28
  });
29
- $("div.piechart").bind('jqplotDataClick',
30
- function(ev,seriesIndex,pointIndex,data){
31
- if(data[2] != "")
32
- {
33
- window.location = data[2];
34
- }
29
+ $("div.barchart").each(function(){
30
+ barChart($(this).attr("id"),$(this).attr("data-xmlurl"));
31
+ });
32
+ //The following provide click-to-link capabilities in charts
33
+ $("div.piechart").bind('jqplotDataClick',function(ev,seriesIndex,pointIndex,data){
34
+ if(data[2] != "") window.location = data[2];
35
+ });
36
+ $("div.barchart").bind('jqplotDataClick',function(ev,seriesIndex,pointIndex,data){
37
+ if(data[2] != "") window.location = data[2];
35
38
  });
36
- //bind click events to piehcart
37
- //start by loading the barcharts...
38
- $("div.barchart").each(function(){BarChart($(this).attr("id"),$(this).attr("data-xmlurl"))});
39
- $('div.barchart').bind('jqplotDataClick',
40
- function (ev, seriesIndex, pointIndex, data) {
41
- /* To open in a NEW window use: */
42
- /* window.open(data[2]); */
43
- /* To open in the same window use: */
44
- for(i = 0; i < data.length; i++) $("#debug").append("\nData["+i+"]:"+data[i]);
45
- $("#debug").append("\nlink: "+data[2]);
46
- window.location = data[2]
47
- }
48
- );
49
-
50
- //#TO PREVENT PROBLEMS WITH DEBUG IF IT DOES NOT EXIST
51
- if(!$("#debug"))
52
- {
53
- $("html").append("<div id=\"debug\"></div>");
54
- $("div#debug").css("display","none");
55
- }
56
39
  });
57
-
58
- ///some helpter functions here
59
-
60
- //####THIS ONE HELPS PROCESS XML
61
-
62
-
63
- function BarChart(name,xmlurl)
40
+ //functions specific to barchart
41
+ function barChart(name,xmlurl)
64
42
  {
65
- //this is the BarChart Method
66
- //get the XML data
67
43
  $.get(xmlurl,function(xml){
68
- //we have the URL object as xml
69
- var width = XMLWidth(xml);//The width of the chart
70
- var height = XMLHeight(xml);
71
- var bars = getBars(xml);
72
- //append these to the div
73
- $("div#"+name).css("width",width);
74
- $("div#"+name).css("height",height);
75
- $.jqplot(name,getBars(xml),{ seriesDefaults:{
76
- renderer:$.jqplot.BarRenderer,
77
- rendererOptions: {fillToZero: true, barWidth: barWidth(xml)}
78
- },
79
- axes: {
80
- // Use a category axis on the x axis and use our custom ticks.
81
- xaxis: {
82
- renderer: $.jqplot.CategoryAxisRenderer,
83
- ticks: getTicks(xml),
84
- autoscale: true
85
- },
86
- yaxis: {
87
- min: getYAxisMin(xml),
88
- max: getYAxisMax(xml),
89
- autoscale: true,
90
- tickInterval: getTickInterval(xml)
91
- }
92
- }
93
- });
94
- });
95
- }
96
-
97
- function barWidth(xml)
98
- {
99
- var width = $(xml).find("render").attr("barWidth");
100
- if(width) return width; else return null;
44
+ loadBGImage(name,xml);
45
+ establishSize(name,xml);
46
+ $.jqplot(name,[getBars(xml)],{
47
+ seriesDefaults:
48
+ {
49
+ renderer: $.jqplot.BarRenderer,
50
+ renderOptions:
51
+ {
52
+ fillToZero:true, barWidth: getBarWidth(xml)
53
+ }
54
+ },
55
+ title:
56
+ {
57
+ text: getTitle(xml)
58
+ },
59
+ grid:
60
+ {
61
+ background: getBGColor(xml),
62
+ gridLine: getGridLineColor(xml),
63
+ borderColor: getGridBorderColor(xml)
64
+ },
65
+ axes:
66
+ {
67
+ xaxis:
68
+ {
69
+ renderer: $.jqplot.CategoryAxisRenderer,
70
+ ticks: getTicks(xml),
71
+ autoscale: true
72
+ }
73
+ }
74
+ });
75
+ });
101
76
  }
102
-
103
- function getYAxisMin(xml)
77
+ function getBars(xml)
104
78
  {
105
- var min = $(xml).find("yaxis").attr("min");
106
- if(min)
107
- {
108
- return min;
109
- }
110
- else
111
- {
112
- return null;
113
- }
79
+ var bars =[];
80
+ var bar = [];
81
+ var categoryId = 1;
82
+ $(xml).find("category").each(function(){
83
+ $(this).find("bar").each(function()
84
+ {
85
+ bar.push(categoryId);
86
+ bar.push(parseInt($(this).attr("size")));
87
+ var link = $(this).attr("link");
88
+ if(link) bar.push(link); else bar.push("");
89
+ bars.push(bar);
90
+ bar = new Array();
91
+ });
92
+ categoryId++;
93
+ });
94
+ return bars;
114
95
  }
115
-
116
- function getYAxisMax(xml)
96
+ function getBarWidth(xml)
117
97
  {
118
- var max = $(xml).find("yaxis").attr("max");
119
- if(max) return max;
120
- if(!max) return null;
98
+ var width = $(xml).find("render").attr("barwidth");
99
+ if(!width) return null; else return width;
121
100
  }
122
101
  function getTicks(xml)
123
102
  {
124
- //this function should get the ticks from the XML
125
103
  var ticks = [];
126
- $(xml).find("tick").each(function(){
127
- ticks.push($(this).attr("text"));
104
+ $(xml).find("category").each(function(){
105
+ ticks.push ($(this).find("tick").attr("text"));
128
106
  });
129
107
  return ticks;
130
108
  }
131
- function loadBars(categoryid, xml) {
132
- var bar = [];
133
- var bars = [];
134
- $(xml).find("bar").each(function() {
135
- bar.push(parseInt(categoryid, 10));
136
- bar.push(parseInt($(this).attr("size"), 10));
137
- bar.push($(this).attr("link"));
138
- bars.push(bar);
139
- });
140
- return bars; //moved from end of "each" iterator to here.
141
- }
142
- function getBars(xml) {
143
- var categoryid = 1;
144
- var bars = [];
145
- $(xml).find("category").each(function() {
146
- bars.push(loadBars(categoryid, $(this)));
147
- categoryid++;
148
- });
149
- return bars;
150
- }
151
-
152
- function XMLWidth(xml)
109
+ //functions specific to piechart
110
+ function pieChart(name,xmlurl)
153
111
  {
154
- //get the width and height of the object via XML
155
- return $(xml).find("size").attr("width");
112
+ $.get(xmlurl,function(xml)
113
+ {
114
+ establishSize(name,xml);
115
+ loadBGImage(name,xml);
116
+ $.jqplot(name,[getSlices(xml)],
117
+ {
118
+ seriesDefaults:
119
+ {
120
+ renderer: $.jqplot.PieRenderer,
121
+ renderOptions:
122
+ {
123
+ showDataLabels: true
124
+ }
125
+ },
126
+ legend:
127
+ {
128
+ show: true,
129
+ location: 'e'
130
+ }
131
+ });
132
+ });
156
133
  }
157
-
158
- function XMLHeight(xml)
134
+ function getSlices(xml)
159
135
  {
160
- return $(xml).find("size").attr("height");
136
+ var slices = [];
137
+ $(xml).find("category").each(function(){
138
+ $(this).find("slice").each(function(){
139
+ slice = new Array($(this).attr("name"));
140
+ slice.push(parseInt($(this).attr("size")));
141
+ var link = $(this).attr("link");
142
+ alert(link);
143
+ if(link) slice.push(link); else slice.push("");
144
+ slices.push(slice);
145
+ });
146
+ });
147
+ return slices;
161
148
  }
162
-
163
- /*function loadBars(xml,categoryid)
149
+ //functions that can be used by all
150
+ function loadBGImage(name,xml)
164
151
  {
165
- bars = [];//the category to put the bar...probably shouldn't go here.
166
- $(xml).find("bar").each(
167
- function(){
168
- //categoryPos = categoryPos+1;
169
- //$("#debug").append("\nCATEGORY POSSITION:"+categoryPos)
170
- //bars.push(categoryPos);
171
- bar= new Array();
172
- bar.push(parseInt(categoryid));
173
- bar.push(parseInt($(this).attr("size")));
174
- link = $(this).attr("link");
175
- if(link)bar.push(link); else links.push("#");
176
- bars.push(bar);
177
- });
178
- $("#debug").append("\nDEBUG bars Array in Loadbars:");
179
- debug2dArray(bars);
180
- return bars;
181
- }*/
182
-
183
-
184
- function getTickInterval(xml)
152
+ var bgimage="none";
153
+ $(xml).find("backgroundImage").each(function()
154
+ {
155
+ bgimage = "url('"+$(this).text()+"')";
156
+ });
157
+ $("div#"+name).css("background-image",bgimage);
158
+ }
159
+ function establishSize(name,xml)
185
160
  {
186
- var interval = $(xml).find("yaxis").attr("tickInterval");
187
- if(interval) return interval;
188
- else return null;
161
+ var $grid = $(xml).find("grid");
162
+ $("div#"+name).css("width",$grid.find("width").text());
163
+ $("div#"+name).css("height",$grid.find("height").text());
189
164
  }
190
-
191
- function debug2dArray(arr)
165
+ function getTitle(xml)
192
166
  {
193
- $("#debug").append("\n[");
194
- for(i = 0; i < arr.length; i++)
195
- {
196
- $("#debug").append("\n[");
197
- for(j = 0; j < arr[i].length; j++)
198
- {
199
- if(j != 0) $("#debug").append(",");
200
- $("#debug").append(arr[i][j]);
201
- }
202
- $("#debug").append("]");
203
- }
204
- $("#debug").append("\n]");
205
- return arr;
167
+ var title = null;
168
+ $(xml).find("title").each(function(){
169
+ title = $(this).text();
170
+ });
171
+ return title;
206
172
  }
207
-
208
- ///THIS IS THE PIE CHART SECTION, Somethings may be borrowed from BarCharts
209
- //###THINGS BORROWED FROM BARCHARTS: debug2dArray
210
-
211
- function pieChart(name,xmlurl)
173
+ function getBGColor(xml)
212
174
  {
213
- $.get(xmlurl,function(xml)
214
- {
215
-
216
- loadSize(name,xml);
217
- slices= new Array();
218
- slices.push(loadSlices(xml));
219
- $("#debug").append("\nSLICES ARR (getting ready to load):");
220
- debug2dArray(slices);
221
- //debug2dArray(slices)
222
- //now load in the pie chart
223
- var plot1 = $.jqplot(name,[slices],
224
- {
225
- seriesDefaults:{
226
- renderer: $.jqplot.PieRenderer,
227
- rendererOptions: {
228
- // Put data labels on the pie slices.
229
- // By default, labels show the percentage of the slice.
230
- showDataLabels: true
231
- }
232
- },
233
- legend:{show: true, location: 'e'}
234
- });
235
- });//end get AJAX request
175
+ return $(xml).find("background").text();
236
176
  }
237
-
238
-
239
-
240
- function loadSlices(xml)
177
+ function getGridLineColor(xml)
241
178
  {
242
- slices = new Array();
243
- $(xml).find("category").each(
244
- function()
245
- {
246
- $(this).find("slice").each(
247
- function()
248
- {
249
- slice = new Array($(this).attr("name"));
250
- slice.push(parseInt($(this).attr("size")));
251
- link = $(this).attr("link");
252
- if(link)slice.push(link);
253
- else slice.push("");
254
- slices.push(slice);
255
- }
256
- );
257
- }
258
- );
259
- return slices;
179
+ return $(xml).find("grid lineColor").text();
260
180
  }
261
-
262
- function loadSize(divid,xml)
181
+ function getGridBorderColor(xml)
263
182
  {
264
- width = $(xml).find("size").attr("width");
265
- if(width) $("#"+divid).css("width",width);
266
- height = $(xml).find("size").attr("height");
267
- if(height) $("#"+divid).css("height",height);
268
- $("#debug").append("\nWidth: "+width+"\nHeight:"+height);
183
+ return $(xml).find("grid borderColor").text();
269
184
  }
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "jquery_cheats"
5
- s.version = "2.3.0"
5
+ s.version = "3.0.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Travis Pessettto"]
9
- s.date = "2012-06-15"
9
+ s.date = "2012-06-20"
10
10
  s.description = "JQuery, JQPlot graphing, and other useful items for jquery."
11
11
  s.email = "travis@pessetto.com"
12
12
  s.extra_rdoc_files = ["README.md", "lib/jquery_cheats.rb"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery_cheats
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 3.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-15 00:00:00.000000000Z
12
+ date: 2012-06-20 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: JQuery, JQPlot graphing, and other useful items for jquery.
15
15
  email: travis@pessetto.com