birt 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2dbe60a6cb1ae6007827db8ec686023e7fc75089
4
- data.tar.gz: 7c0f4a629690cc1f7c3e9849a90f8b2c1e089242
3
+ metadata.gz: 928c19e29b5822e9f31cb341f7d9e8fb1253d640
4
+ data.tar.gz: 67df5e8d09dca61f5228ea3875be177969d34060
5
5
  SHA512:
6
- metadata.gz: 5d944213a3a0fb69c351c7673509bc610930d9d3863b5df53ad295587c2fad995a1f60cf983283e85e35e0f2e2b8148b549a60a952f51e61182eec7253a67388
7
- data.tar.gz: a9b61a25159ae319540d91047a63bf16c742a1c3e4f24c12520375d00c98b670c058b83e7928850636efd4793a30504f6fbf3209fd9730221ed5d5858b61540b
6
+ metadata.gz: 2df786a2ab27f01ee7ad2652c597b8adcf79f603d4a1c0684b198c0f006dbfe74a4ea28676b7a4af3115de091a4d48affc03804f4973d4edad6a2cdb8d55a7fb
7
+ data.tar.gz: d8c95e8f7cc2eb6120b3237c458f6bbb4b2476dbfa394a0062442c327149e8b6a43eced6745743e8198bd62afc442cc3ca2a23a89ae82d98f4fb58732da93e5f
data/.gitignore CHANGED
@@ -8,7 +8,7 @@ capybara-*.html
8
8
  /public/system
9
9
  /coverage/
10
10
  /spec/tmp
11
- /birt/
11
+ /birt/reports/*.rptdesign
12
12
  /config/database.yml
13
13
  *.gem
14
14
  /.idea/
data/.project ADDED
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>birt</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ </buildSpec>
9
+ <natures>
10
+ <nature>org.eclipse.birt.report.designer.ui.reportprojectnature</nature>
11
+ </natures>
12
+ </projectDescription>
@@ -1,4 +1,4 @@
1
1
  class BirtTestController < ApplicationController
2
2
  def index
3
3
  end
4
- end
4
+ end
@@ -3,6 +3,7 @@ json.rpt_design do
3
3
  json.tables @rpt_design.reports[:tables].values do |table|
4
4
  json.id table.id
5
5
  json.header parse_table_header(table.header)
6
- json.detail parse_table_detail(table.detail,table)
6
+ json.detail parse_table_detail(table.detail, table)
7
7
  end
8
+ json.line_charts @rpt_design.reports[:line_charts].values.inject([]) { |acc, line_chart| acc<<line_chart.json; acc }
8
9
  end
data/birt.gemspec CHANGED
@@ -30,8 +30,9 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "bundler", "~> 1.9"
31
31
  spec.add_development_dependency "rake", "~> 10.4"
32
32
  spec.add_development_dependency 'rails', '~> 0'
33
- spec.add_development_dependency "core_extend", "~> 0.1.5"
34
- spec.add_development_dependency "highcharts-rails", "~> 4.1"
35
- spec.add_development_dependency "mysql2","~> 0.3.19"
33
+
34
+ spec.add_runtime_dependency "core_extend", "~> 0.1.5"
35
+ spec.add_runtime_dependency "highcharts-rails", "~> 4.1"
36
+ spec.add_runtime_dependency "mysql2","~> 0.3.19"
36
37
 
37
38
  end
@@ -26,11 +26,17 @@ var Birt = (function () {
26
26
  rptDesignJsonData = data.rpt_design;
27
27
  _this.showDisplayName();
28
28
  console.log(data.rpt_design.tables);
29
+
29
30
  var tables = data.rpt_design.tables;
30
31
  for (var i = 0; i < tables.length; i++) {
31
32
  var table = tables[i];
32
33
  _this.showTable(table);
33
34
  }
35
+
36
+ var lineCharts = data.rpt_design.line_charts;
37
+ for (var i = 0; i < lineCharts.length; i++) {
38
+ _this.showLineChart(lineCharts[i]);
39
+ }
34
40
  },
35
41
  error: function (data) {
36
42
  $.birtLoading('hide');
@@ -43,6 +49,7 @@ var Birt = (function () {
43
49
  $birt.append('<h2>{0}</h2>'.format(rptDesignJsonData.display_name));
44
50
  };
45
51
 
52
+
46
53
  /**
47
54
  * 显示行
48
55
  * @param rowData
@@ -86,5 +93,36 @@ var Birt = (function () {
86
93
  console.log(table);
87
94
  return table_html;
88
95
  };
96
+
97
+
98
+ Birt.prototype.showLineChart = function (lineChart) {
99
+ $(".birt").append("<div id='report_{0}'></div>".format(lineChart.id));
100
+ new Highcharts.Chart({
101
+ chart: {
102
+ renderTo: "report_{0}".format(lineChart.id),
103
+ plotBackgroundColor: null,
104
+ plotBorderWidth: null,
105
+ defaultSeriesType: 'spline'
106
+ },
107
+ title: {
108
+ text: lineChart.title
109
+ },
110
+ xAxis: {
111
+ categories: lineChart.x_data,
112
+ labels: {
113
+ rotation: -45, //字体倾斜
114
+ align: 'right',
115
+ style: {font: 'normal 13px 宋体'}
116
+ }
117
+ },
118
+ yAxis: {
119
+ title: {
120
+ text: "销量/元"
121
+ }
122
+ },
123
+
124
+ series: lineChart.series
125
+ });
126
+ };
89
127
  return Birt;
90
128
  })();
@@ -6,9 +6,10 @@ table.birt-table {
6
6
  margin-bottom: 12px;
7
7
  tr {
8
8
  td, th {
9
+ font-size: 10pt;
9
10
  border-bottom: 1px solid #ddd;
10
11
  border-right: 1px solid #ddd;
11
- padding: 5px 8px;
12
+ padding: 3px 5px;
12
13
  &:last-child {
13
14
  border-right: none;
14
15
  }
@@ -16,5 +17,8 @@ table.birt-table {
16
17
  &:last-child td {
17
18
  border-bottom: none;
18
19
  }
20
+ &:nth-child(odd){
21
+ background: #FAF9F9;
22
+ }
19
23
  }
20
24
  }
@@ -9,4 +9,9 @@ class Birt::Core::BaseReport
9
9
  yield(self) if block_given?
10
10
  end
11
11
 
12
+ def elem_text(xml_element, xpath)
13
+ elements = xml_element.get_elements(xpath)
14
+ elements&&elements[0] ? elements[0].text : nil
15
+ end
16
+
12
17
  end
@@ -0,0 +1,63 @@
1
+ class Birt::Core::LineChartReport < Birt::Core::BaseReport
2
+ attr_accessor :data_set
3
+
4
+ attr_accessor :title_label
5
+ attr_accessor :legend_label
6
+
7
+ attr_accessor :horizontal_label
8
+ attr_accessor :vertical_label
9
+
10
+ attr_accessor :horizontal_row
11
+ attr_accessor :series_rows
12
+
13
+
14
+ def initialize(xml_e)
15
+ @series_rows = []
16
+ super(xml_e) do
17
+ @title_label = elem_text(xml_e, "/model:ChartWithAxes/Block/Children[@xsi:type='layout:TitleBlock']/Label/Caption/Value")
18
+ @legend_label = elem_text(xml_e, "/model:ChartWithAxes/Block/Children[@xsi:type='layout:Legend']/Title/Caption/Value")
19
+ @vertical_label = elem_text(xml_e, "/model:ChartWithAxes/Axes/AssociatedAxes/Title/Caption/Value")
20
+ @horizontal_label = elem_text(xml_e, "/model:ChartWithAxes/Axes/Title/Caption/Value")
21
+
22
+ @horizontal_row = elem_text(xml_e, "/model:ChartWithAxes/Axes/SeriesDefinitions/Series/DataDefinition/Definition").gsub("row[\"", '').gsub("\"]", '')
23
+
24
+
25
+ xml_e.get_elements("/model:ChartWithAxes/Axes/AssociatedAxes/SeriesDefinitions/Series[@xsi:type='type:LineSeries']/DataDefinition/Definition").each do |item|
26
+ @series_rows << item.text.gsub("row[\"", '').gsub("\"]", '')
27
+ end
28
+
29
+ # @series_rows << elem_text(xml_e, "/model:ChartWithAxes/Axes/AssociatedAxes/SeriesDefinitions/Series[@xsi:type='type:LineSeries']/DataDefinition/Definition").gsub("row[\"", '').gsub("\"]", '')
30
+ end
31
+
32
+ yield(self) if block_given?
33
+ end
34
+
35
+ def json
36
+ @json = {}
37
+ @json[:id] = @id
38
+ @json[:title] = @title_label
39
+
40
+ data_set_result = self.data_set.data_set_result
41
+
42
+ _series_data = ->(data_result, series_name) {
43
+ if series_name =~ /\//
44
+ name = series_name.split("/")[0]
45
+ num = series_name.split("/")[1].to_i
46
+ data_result.columns[data_result.column_headers.index(name)].inject([]) { |acc, item| acc<<item/num; acc }
47
+ else
48
+ data_result.columns[data_result.column_headers.index(series_name)]
49
+ end
50
+ }
51
+
52
+ @json[:x_data] = data_set_result.columns[data_set_result.column_headers.index(@horizontal_row)]
53
+ @json[:series] = []
54
+ @series_rows.each { |series_name|
55
+ @json[:series] << {
56
+ name: series_name,
57
+ data: _series_data.call(data_set_result, series_name)
58
+ }
59
+ }
60
+ @json
61
+ end
62
+
63
+ end
@@ -19,7 +19,7 @@ class Birt::Core::RptDesign
19
19
  def initialize(rpt_design_path)
20
20
  self.rpt_design_path = rpt_design_path
21
21
  @data_sources, @data_sets = {}, {}
22
- @reports = {tables: {}}
22
+ @reports = {tables: {}, line_charts: {}}
23
23
  end
24
24
 
25
25
  def display_name(root=nil)
@@ -50,12 +50,26 @@ class Birt::Core::RptDesign
50
50
  end
51
51
  end
52
52
 
53
- #报表
53
+ #table报表
54
54
  _root.each_element(xpath='/report/body/table') do |item|
55
55
  @reports[:tables]["#{item.attribute(:id).value}"] = Birt::Core::TableReport.new(item) do |report|
56
56
  report.data_set = @data_sets[item.get_elements("property[@name='dataSet']")[0].text]
57
57
  end
58
58
  end
59
+
60
+ #Chart报表
61
+ _root.each_element(xpath="/report/body/extended-item[@extensionName='Chart']") do |item|
62
+ item_data = REXML::Document.new(item.get_elements("xml-property[@name='xmlRepresentation']")[0].text).root
63
+
64
+ #线性报表
65
+ if item_data.get_elements("Type")[0].text=='Line Chart'
66
+ @reports[:line_charts]["#{item.attribute(:id).value}"] = Birt::Core::LineChartReport.new(item_data) do |report|
67
+ report.id = item.attribute(:id).value
68
+ report.data_set = @data_sets[item.get_elements("property[@name='dataSet']")[0].text]
69
+ end
70
+ @reports[:line_charts]["#{item.attribute(:id).value}"].json
71
+ end
72
+ end
59
73
  end
60
74
 
61
75
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/lib/birt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Birt
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  module Core
4
4
 
5
5
  end
data/lib/birt.rb CHANGED
@@ -5,7 +5,8 @@ require 'pry'
5
5
  require 'mysql2'
6
6
 
7
7
  Dir.glob("#{File.dirname(__FILE__)}/birt/core/*.rb") { |f| require f }
8
- Dir.glob("#{File.dirname(__FILE__)}/birt/core/report/*.rb") { |f| require f }
8
+ Dir.glob("#{File.dirname(__FILE__)}/birt/core/table/*.rb") { |f| require f }
9
+ Dir.glob("#{File.dirname(__FILE__)}/birt/core/chart/*.rb") { |f| require f }
9
10
 
10
11
  module Birt
11
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: birt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - saxer
@@ -59,7 +59,7 @@ dependencies:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: 0.1.5
62
- type: :development
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
@@ -73,7 +73,7 @@ dependencies:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '4.1'
76
- type: :development
76
+ type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
@@ -87,7 +87,7 @@ dependencies:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: 0.3.19
90
- type: :development
90
+ type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
@@ -102,6 +102,7 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - ".gitignore"
105
+ - ".project"
105
106
  - ".travis.yml"
106
107
  - Gemfile
107
108
  - Gemfile.lock
@@ -140,22 +141,23 @@ files:
140
141
  - lib/birt.rb
141
142
  - lib/birt/api.rb
142
143
  - lib/birt/core.rb
144
+ - lib/birt/core/base_report.rb
145
+ - lib/birt/core/chart/line_chart_report.rb
143
146
  - lib/birt/core/data_set.rb
144
147
  - lib/birt/core/data_set_result.rb
145
148
  - lib/birt/core/data_source.rb
146
149
  - lib/birt/core/mysql.rb
147
- - lib/birt/core/report/base_report.rb
148
- - lib/birt/core/report/property.rb
149
- - lib/birt/core/report/table_cell_data.rb
150
- - lib/birt/core/report/table_cell_label.rb
151
- - lib/birt/core/report/table_detail.rb
152
- - lib/birt/core/report/table_footer.rb
153
- - lib/birt/core/report/table_header.rb
154
- - lib/birt/core/report/table_report.rb
155
- - lib/birt/core/report/table_row.rb
156
- - lib/birt/core/report/table_row_cell.rb
157
- - lib/birt/core/report/text_property.rb
158
150
  - lib/birt/core/rpt_design.rb
151
+ - lib/birt/core/table/property.rb
152
+ - lib/birt/core/table/table_cell_data.rb
153
+ - lib/birt/core/table/table_cell_label.rb
154
+ - lib/birt/core/table/table_detail.rb
155
+ - lib/birt/core/table/table_footer.rb
156
+ - lib/birt/core/table/table_header.rb
157
+ - lib/birt/core/table/table_report.rb
158
+ - lib/birt/core/table/table_row.rb
159
+ - lib/birt/core/table/table_row_cell.rb
160
+ - lib/birt/core/table/text_property.rb
159
161
  - lib/birt/version.rb
160
162
  homepage: https://github.com/mumaoxi/birt
161
163
  licenses: