mixtli-flex_chart 0.1.2

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.
data/Manifest ADDED
@@ -0,0 +1,8 @@
1
+ README.rdoc
2
+ Manifest
3
+ init.rb
4
+ public/swfs/FlexChart.swf
5
+ flex/FlexChart.mxml
6
+ tasks/flex_chart.rake
7
+ lib/flex_chart.rb
8
+ Rakefile
data/README.rdoc ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # Rakefile
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'echoe'
5
+
6
+ Echoe.new('flex_chart', '0.1.2') do |p|
7
+ p.description = "Interface to Flex Charting Components"
8
+ p.url = "http://github.com/mixtli/flex_chart"
9
+ p.author = "Ron McClain"
10
+ p.email = "mixtli@github.com"
11
+ p.ignore_pattern = ["tmp/*", "script/*"]
12
+ p.development_dependencies = []
13
+ end
14
+
15
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
16
+
@@ -0,0 +1,140 @@
1
+ <?xml version="1.0"?>
2
+ <!-- charts/DateTimeAxisSample.mxml -->
3
+ <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" creationComplete="initApp()">
4
+ <mx:Script><![CDATA[
5
+ import mx.charts.*;
6
+ import mx.charts.series.*;
7
+ import mx.charts.chartClasses.*;
8
+ import mx.controls.Alert;
9
+ import mx.charts.HitData;
10
+ import flash.net.URLVariables;
11
+ //import mx.rpc.http.HTTPService;
12
+ import mx.rpc.events.ResultEvent
13
+ import mx.utils.URLUtil;
14
+ import mx.graphics.SolidColor;
15
+ import mx.graphics.Stroke;
16
+
17
+
18
+ [Bindable]
19
+ public var data_url:String;
20
+
21
+ [Bindable]
22
+ public var graph_title:String;
23
+
24
+ [Bindable]
25
+ public var y_label:String = "Dollars";
26
+
27
+ [Bindable]
28
+ public var x_label:String = "Date";
29
+
30
+ [Bindable]
31
+ public var chart;
32
+
33
+ private function initApp():void {
34
+ trace("tracing on");
35
+ data_url = Application.application.parameters.data_url;
36
+ trace("data_url = " + data_url);
37
+ graphService.addEventListener("result", createGraph);
38
+ graphService.send();
39
+ }
40
+
41
+ private function createGraph(event:ResultEvent):void {
42
+ var result:XML = XML(event.result);
43
+ var x_axis;
44
+ var y_axis;
45
+
46
+ chart_panel.title = result.title;
47
+ trace("x_axis_type = " + result.x_axis_type);
48
+ switch(String(result.x_axis_type)) {
49
+ case "Log" :
50
+ x_axis = new LogAxis();
51
+ break;
52
+ case "DateTime" :
53
+ x_axis = new DateTimeAxis();
54
+ break;
55
+ default :
56
+ x_axis = new LinearAxis();
57
+ }
58
+
59
+ switch(String(result.y_axis_type)) {
60
+ case 'Log':
61
+ y_axis = new LogAxis();
62
+ break;
63
+ case 'DateTime':
64
+ y_axis = new DateTimeAxis();
65
+ break;
66
+ default:
67
+ y_axis = new LinearAxis();
68
+ }
69
+
70
+ y_label = result.y_label;
71
+ x_label = result.x_label;
72
+
73
+ switch(String(result.chart_type)) {
74
+ case 'Line':
75
+ chart = new LineChart();
76
+ break;
77
+ case 'Pie':
78
+ chart = new PieChart();
79
+ break;
80
+ case 'Area':
81
+ chart = new AreaChart();
82
+ break;
83
+ case 'Bar':
84
+ chart = new BarChart();
85
+ break;
86
+ default:
87
+ chart = new LineChart();
88
+ }
89
+ chart.setStyle("color", int(result.color));
90
+ chart.setStyle("fill", int(result.fill_color));
91
+ x_axis.title = x_label;
92
+ chart.horizontalAxis = x_axis;
93
+ y_axis.title = y_label;
94
+ chart.verticalAxis = y_axis;
95
+ chart.percentWidth = 100;
96
+ chart.percentHeight = 100;
97
+ chart.showDataTips = true;
98
+ chart.dataTipFunction = tooltipCallback;
99
+ //chart.height = "100%";
100
+ //chart.width = "100%";
101
+ chart.id = "chart";
102
+
103
+ chart_panel.addChild(chart);
104
+
105
+ var graph_items:XMLList = XMLList(result.graph_item);
106
+ var stroke:Stroke;
107
+ for each(var item:XML in graph_items) {
108
+ var ls:LineSeries = new LineSeries();
109
+ var ds:XMLList = XMLList(item.dataset.data);
110
+ ls.dataProvider = ds;
111
+ ls.yField = "y_value";
112
+ ls.xField = "x_value";
113
+ trace("color = " + int(item.color));
114
+ var s:Stroke = new Stroke(int(item.color), 1);
115
+ s.color = int(item.color);
116
+ s.alpha = 1;
117
+ ls.setStyle("lineStroke", s);
118
+ ls.displayName = item.title;
119
+ // chart.series.push(ls); # for some reason, this doesn't work. wtf?
120
+ var currentSeries:Array = chart.series;
121
+ currentSeries.push(ls);
122
+ chart.series = currentSeries;
123
+ }
124
+ }
125
+
126
+ private function tooltipCallback(hd:HitData):String {
127
+ return hd.item.x_value + "\n" + hd.item.y_value;
128
+ }
129
+ private function graphUri():String {
130
+ return URLUtil.objectToString(Application.application.parameters, '&', true);
131
+ }
132
+
133
+ ]]></mx:Script>
134
+
135
+ <mx:HTTPService id="graphService" url="{data_url}" resultFormat="e4x"/>
136
+
137
+ <mx:Panel width="100%" height="100%" id="chart_panel">
138
+ <mx:Legend dataProvider="{chart}"/>
139
+ </mx:Panel>
140
+ </mx:Application>
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{flex_chart}
5
+ s.version = "0.1.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ron McClain"]
9
+ s.date = %q{2009-04-14}
10
+ s.description = %q{Interface to Flex Charting Components}
11
+ s.email = %q{mixtli@github.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "tasks/flex_chart.rake", "lib/flex_chart.rb"]
13
+ s.files = ["README.rdoc", "Manifest", "init.rb", "public/swfs/FlexChart.swf", "flex/FlexChart.mxml", "tasks/flex_chart.rake", "lib/flex_chart.rb", "Rakefile", "flex_chart.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/mixtli/flex_chart}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Flex_chart", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{flex_chart}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Interface to Flex Charting Components}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'flex_chart'
data/lib/flex_chart.rb ADDED
@@ -0,0 +1,60 @@
1
+ module FlexChart
2
+ class Base
3
+ attr_accessor :title, :x_label, :y_label, :series, :x_axis_type, :y_axis_type, :color, :fill_color
4
+
5
+ def initialize(options = {})
6
+ @series = []
7
+ @x_axis_type = "Linear"
8
+ @y_axis_type = "Linear"
9
+ end
10
+
11
+ def fix_color(color)
12
+ c = color.sub("#", "")
13
+ newstr = ""
14
+ c.each_char {|char| newstr << "#{char}0" }
15
+ "0x" + newstr
16
+ end
17
+
18
+ def to_xml
19
+ xml = Builder::XmlMarkup.new
20
+ xml.graph do
21
+ xml.title(@title)
22
+ xml.x_label(@x_label)
23
+ xml.y_label(@y_label)
24
+ xml.x_axis_type(@x_axis_type)
25
+ xml.y_axis_type(@y_axis_type)
26
+ xml.color(fix_color(@color))
27
+ xml.fill_color(fix_color(@fill_color))
28
+ xml.chart_type(self.class.to_s.split("::")[1])
29
+ series.each do |item|
30
+ xml.graph_item do
31
+ xml.title(item.title)
32
+ xml.color(fix_color(item.color))
33
+ xml.dataset do
34
+ item.values.each do |data|
35
+ xml.data do
36
+ xml.x_value(data[:x_value].strftime("%m/%d/%Y"))
37
+ xml.y_value(data[:y_value])
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ class Series
48
+ attr_accessor :title, :color, :values
49
+ end
50
+
51
+ class Line < Base
52
+ end
53
+
54
+ class Pie < Base
55
+ end
56
+
57
+ class Area < Base
58
+ end
59
+
60
+ end
Binary file
@@ -0,0 +1,13 @@
1
+ namespace :flex_chart do
2
+
3
+ desc 'build flex component'
4
+ task :build do
5
+ system("mxmlc -output public/swfs/FlexChart.swf flex/FlexChart.mxml")
6
+ end
7
+
8
+ desc 'Install swf'
9
+ task :install_public => :environment do
10
+ system("cp #{File.dirname(__FILE__)}/public/swfs/FlexChart.swf #{RAILS_ROOT}/public/swfs")
11
+ end
12
+ end
13
+
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mixtli-flex_chart
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Ron McClain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-14 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Interface to Flex Charting Components
17
+ email: mixtli@github.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - tasks/flex_chart.rake
25
+ - lib/flex_chart.rb
26
+ files:
27
+ - README.rdoc
28
+ - Manifest
29
+ - init.rb
30
+ - public/swfs/FlexChart.swf
31
+ - flex/FlexChart.mxml
32
+ - tasks/flex_chart.rake
33
+ - lib/flex_chart.rb
34
+ - Rakefile
35
+ - flex_chart.gemspec
36
+ has_rdoc: true
37
+ homepage: http://github.com/mixtli/flex_chart
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --line-numbers
41
+ - --inline-source
42
+ - --title
43
+ - Flex_chart
44
+ - --main
45
+ - README.rdoc
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "1.2"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project: flex_chart
63
+ rubygems_version: 1.2.0
64
+ signing_key:
65
+ specification_version: 2
66
+ summary: Interface to Flex Charting Components
67
+ test_files: []
68
+