ReportIncludePlugin: fixed not working with Trac 1.0
@@ -32,7 +32,7 @@ | ||
32 | 32 | |
33 | 33 | def get_templates_dirs(self): |
34 | 34 | return [pkg_resources.resource_filename(__name__, 'templates')] |
35 | - | |
35 | + | |
36 | 36 | # IWikiMacroProvider methods |
37 | 37 | def get_macros(self): |
38 | 38 | yield 'ReportInclude' |
@@ -65,7 +65,7 @@ | ||
65 | 65 | * legendXOffset: グラフの凡例位置の横方向のオフセットを指定します。未指定の場合は12となります。 |
66 | 66 | * legendYOffset: グラフの凡例位置の縦方向のオフセットを指定します。未指定の場合は12となります。 |
67 | 67 | * dateFormat: X軸の値を日付としてグラフ表示する場合の、日付フォーマットを指定します。コロンに続けて、yyyy/MM/dd のように指定します。未指定の場合は、デフォルト値としてyyyy-MM-ddを使用します。 |
68 | - * width: グラフの幅をpx単位で指定します。未指定の場合は536pxとなります。 | |
68 | + * width: グラフの幅をpx単位で指定します。未指定の場合は536pxとなります。 | |
69 | 69 | * height: グラフの高さをpx単位で指定します。未指定の場合は300pxとなります。 |
70 | 70 | * table: TracReportのテーブルを出力を制御できます。コロンに続けて、以下の記載が可能です。 |
71 | 71 | * hide[[BR]] |
@@ -120,13 +120,13 @@ | ||
120 | 120 | ''' |
121 | 121 | |
122 | 122 | def expand_macro(self, formatter, name, content): |
123 | - | |
123 | + | |
124 | 124 | if not content: |
125 | - raise ResourceNotFound(u"[[ReportInclude(1)]]のように引数を指定してください。") | |
125 | + raise ResourceNotFound(u"[[ReportInclude(1)]]のように引数を指定してください。") | |
126 | 126 | req = formatter.req |
127 | - | |
127 | + | |
128 | 128 | self._add_script(req) |
129 | - | |
129 | + | |
130 | 130 | if self._is_async(content): |
131 | 131 | return self._render_async(req, content) |
132 | 132 | else: |
@@ -135,7 +135,7 @@ | ||
135 | 135 | def _add_script(self, req): |
136 | 136 | if not hasattr(req, '_reportinclude'): |
137 | 137 | #add_stylesheet(req, 'reportinclude/css/reportinclude.css') |
138 | - | |
138 | + | |
139 | 139 | # add script and css for jqplot |
140 | 140 | add_script(req, 'reportinclude/js/jqplot/excanvas.min.js') |
141 | 141 | add_script(req, 'reportinclude/js/jqplot/jquery.jqplot.min.js') |
@@ -148,11 +148,11 @@ | ||
148 | 148 | add_script(req, 'reportinclude/js/jqplot/jqplot.highlighter.min.js') |
149 | 149 | add_script(req, 'reportinclude/js/jqplot/reportgraph.js') |
150 | 150 | add_stylesheet(req, 'reportinclude/css/jqplot/jquery.jqplot.min.css') |
151 | - | |
151 | + | |
152 | 152 | req._reportinclude = 0 |
153 | 153 | else: |
154 | 154 | req._reportinclude = req._reportinclude + 1 |
155 | - | |
155 | + | |
156 | 156 | def _is_async(self, content): |
157 | 157 | match = re.match(r'.*(async\s*:\s*false).*', content.lower()) |
158 | 158 | if match: |
@@ -159,42 +159,37 @@ | ||
159 | 159 | return False |
160 | 160 | # default Ajax Mode |
161 | 161 | return True |
162 | - | |
162 | + | |
163 | 163 | def _render(self, req, content): |
164 | 164 | renderer = ReportRenderer(self.env) |
165 | 165 | return renderer.render(req, content) |
166 | - | |
166 | + | |
167 | 167 | def _render_async(self, req, content): |
168 | 168 | index = req._reportinclude |
169 | - | |
169 | + | |
170 | 170 | div = tag.div(id="reportgraphtable_async_%d" %(index)) |
171 | - script = """ | |
172 | -jQuery(function(){ | |
173 | - jQuery("#reportgraphtable_loading_%d").ajaxStart(function(){ | |
174 | - jQuery(this).show(); | |
175 | - }); | |
176 | - jQuery("#reportgraphtable_loading_%d").ajaxStop(function(){ | |
177 | - jQuery(this).hide(); | |
178 | - }); | |
171 | + script = """\ | |
172 | +jQuery(document).ready(function($){ | |
173 | + var loading = $("#reportgraphtable_loading_%d"); | |
174 | + loading.ajaxStart(function() { jQuery(this).show() }); | |
175 | + loading.ajaxStop(function() { $(this).hide() }); | |
179 | 176 | |
180 | - jQuery.ajax({ | |
177 | + $.ajax({ | |
181 | 178 | type: "POST", |
182 | 179 | url: "%s", |
183 | 180 | data: "__FORM_TOKEN=%s;index=%s;params=%s", |
184 | 181 | dataType: "html", |
185 | - success: function (data) { | |
186 | - jQuery("#reportgraphtable_%d").html(data); | |
187 | - } | |
182 | + success: function (data) { $("#reportgraphtable_%d").html(data) } | |
188 | 183 | }) |
189 | 184 | }); |
190 | -""" % (index, index, req.href.tracreportinclude(), | |
185 | +""" % (index, req.href.tracreportinclude(), | |
191 | 186 | req.form_token, index, content.replace('&', '__AND__'), index) |
192 | - | |
187 | + | |
193 | 188 | div.append(tag.script(script, type='text/javascript')) |
194 | 189 | div.append(tag.div((tag.img(src=req.href.chrome('reportinclude/image/loading.gif')), |
195 | 190 | tag.div('loading...')), |
196 | 191 | id='reportgraphtable_loading_%d' %(index), |
197 | 192 | style='border: solid 1px black; top: 50%; left: 50%; width: 50%; height: 200px; padding-top: 100px; text-align: center; top: 50%;')) |
198 | - div.append(tag.div('', id='reportgraphtable_%d' %(index))) | |
199 | - | |
193 | + div.append(tag.div('', id='reportgraphtable_%d' % index)) | |
194 | + | |
200 | 195 | return div |
@@ -1,33 +1,35 @@ | ||
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | |
3 | 3 | from genshi.builder import tag |
4 | -from genshi.filters import Transformer | |
5 | 4 | |
6 | 5 | from trac.core import TracError |
6 | +from trac.db.api import get_column_names | |
7 | 7 | from trac.resource import ResourceNotFound |
8 | 8 | from trac.ticket.report import ReportModule |
9 | 9 | from trac.util.datefmt import format_datetime, format_date, format_time, parse_date |
10 | 10 | from trac.util.presentation import to_json |
11 | +from trac.util.translation import _ | |
11 | 12 | |
13 | + | |
12 | 14 | class ReportRenderer(object): |
13 | - | |
15 | + | |
14 | 16 | def __init__(self, env): |
15 | 17 | self.env = env |
16 | - | |
18 | + | |
17 | 19 | def render(self, req, params): |
18 | 20 | u"""TracReportsの結果をHTMLで返す。オプションによってはテーブル、グラフそれぞれを表示する。 |
19 | 21 | """ |
20 | 22 | self.index = req._reportinclude |
21 | - | |
23 | + | |
22 | 24 | id, vars, opts = self._parse_params(req, params) |
23 | 25 | report = self._get_report_info(id) |
24 | - | |
26 | + | |
25 | 27 | if len(report) == 1: |
26 | 28 | title, sql, desc = report[0] |
27 | - | |
29 | + | |
28 | 30 | if opts['title'] == '': |
29 | 31 | opts['title'] = title |
30 | - | |
32 | + | |
31 | 33 | table, columns, table_data = self._render_table(req, id, vars, opts, title, sql, desc) |
32 | 34 | table = self._render_graph(req, opts, table, columns, table_data, title, desc) |
33 | 35 | return table |
@@ -35,20 +37,20 @@ | ||
35 | 37 | raise ResourceNotFound( |
36 | 38 | _('Report [%(num)] does not exist.', num=id), |
37 | 39 | _('Invalid Report Number')) |
38 | - | |
40 | + | |
39 | 41 | def _render_table(self, req, id, vars, opts, title, sql, desc): |
40 | 42 | db = self.env.get_db_cnx() |
41 | - | |
43 | + | |
42 | 44 | sql, vars , missing_vars = self._sql_sub_vars(sql, vars, db) |
43 | - | |
45 | + | |
44 | 46 | cursor = db.cursor() |
45 | 47 | cursor.execute(sql, vars) |
46 | - | |
48 | + | |
47 | 49 | if opts['table'] == 'hide': |
48 | 50 | table_display = 'none' |
49 | 51 | else: |
50 | 52 | table_display = 'inline' |
51 | - | |
53 | + | |
52 | 54 | table = tag.table(class_="listing tickets", |
53 | 55 | id="reportgraphtable_%d" %(self.index), |
54 | 56 | style="display:%s" %(table_display)) |
@@ -55,51 +57,44 @@ | ||
55 | 57 | caption = tag.caption(tag.a('%s(report:%s)' %(title, id), href='%s' % req.href.report(id)), |
56 | 58 | align='center') |
57 | 59 | table.append(caption) |
58 | - | |
60 | + | |
61 | + columns = get_column_names(cursor) | |
62 | + table_data = dict((column, []) for column in columns) | |
63 | + | |
59 | 64 | tr = tag.tr() |
60 | - columns = [] | |
61 | - for desc in cursor.description: | |
62 | - columns.append(desc[0]) | |
63 | - if desc[0] == '__color__' or desc[0] == '__group__': | |
65 | + for column in columns: | |
66 | + if column.startswith('_'): | |
64 | 67 | continue |
65 | - if desc[0].startswith('_'): | |
66 | - continue | |
67 | - | |
68 | - tr.append(tag.th('%s' % desc[0])) | |
69 | - | |
68 | + tr.append(tag.th(column)) | |
69 | + | |
70 | 70 | table.append(tag.thead(tr)) |
71 | - | |
72 | 71 | tbody = tag.tbody() |
73 | 72 | table.append(tbody) |
74 | - | |
75 | - table_data = {} | |
76 | - for col in columns: | |
77 | - table_data[col] = [] | |
78 | - | |
73 | + | |
79 | 74 | for idx, row in enumerate(cursor): |
80 | - | |
75 | + | |
81 | 76 | odd_or_even = (idx % 2 == 0) and 'odd' or 'even' |
82 | 77 | tr = tag.tr() |
83 | 78 | css_class = '' |
84 | - | |
79 | + | |
85 | 80 | for col_idx, col in enumerate(row): |
86 | 81 | column = columns[col_idx] |
87 | - | |
82 | + | |
88 | 83 | if column == '__color__' and css_class is '': |
89 | 84 | css_class = 'color%s-' % col |
90 | 85 | continue |
91 | 86 | if column.startswith('_'): |
92 | 87 | continue |
93 | - | |
88 | + | |
94 | 89 | converted_col = self._convert_col(req, column, col) |
95 | - | |
90 | + | |
96 | 91 | tr = tr(tag.td(converted_col)) |
97 | 92 | table_data[column].append(col) |
98 | - | |
93 | + | |
99 | 94 | css_class = css_class + odd_or_even |
100 | 95 | tr = tr(class_ = css_class) |
101 | 96 | tbody.append(tr) |
102 | - | |
97 | + | |
103 | 98 | #add_stylesheet(req, 'wikitable/css/wikitable.css') |
104 | 99 | return table, columns, table_data |
105 | 100 |
@@ -106,11 +101,11 @@ | ||
106 | 101 | def _render_graph(self, req, opts, table, columns, table_data, title, desc): |
107 | 102 | u"""TracReportsの結果をグラフで表示する。 |
108 | 103 | """ |
109 | - if opts['graph'] not in ('lines', 'bars', 'pie'): | |
104 | + if opts['graph'] not in ('lines', 'bars', 'pie'): | |
110 | 105 | return table |
111 | - | |
106 | + | |
112 | 107 | ticks = table_data[columns[0]] |
113 | - | |
108 | + | |
114 | 109 | data = '[' |
115 | 110 | for column in columns[1:]: |
116 | 111 | #print table_data[column] |
@@ -117,47 +112,55 @@ | ||
117 | 112 | values = self._to_js_array(table_data[column]) |
118 | 113 | data = data + values + ',' |
119 | 114 | data = data[:-1] + ']' |
120 | - | |
115 | + | |
121 | 116 | xaxisType = self._getXAxisType(req, ticks, opts) |
122 | 117 | if isinstance(opts['barWidth'], basestring) and opts['barWidth'].isdigit(): |
123 | 118 | opts['barWidth'] = int(opts['barWidth']) |
124 | 119 | |
125 | - script = """ | |
126 | -jQuery(document).ready(function($) { | |
127 | - $('#reportgraph_%d').reportGraph({ | |
128 | - graph: '%s', | |
129 | - seriesLabel: %s, | |
130 | - data: %s, | |
131 | - ticks: %s, | |
132 | - title: '%s', | |
133 | - stack: %s, | |
134 | - legendLoc: '%s', | |
135 | - legendXOffset: %s, | |
136 | - legendYOffset: %s, | |
137 | - xaxisType: '%s', | |
138 | - xaxisMin: %s, | |
139 | - xaxisMax: %s, | |
140 | - yaxisMin: %s, | |
141 | - yaxisMax: %s, | |
142 | - xaxisFormatString: '%s', | |
143 | - yaxisFormatString: '%s', | |
144 | - barWidth: %s | |
145 | - }); | |
146 | -}); | |
147 | - """ % (self.index, opts['graph'], self._to_js_array(columns[1:]), | |
148 | - data, self._to_js_array(ticks), | |
149 | - opts['title'], opts['stack'].lower(), opts['legendLoc'], | |
150 | - opts['legendXOffset'], opts['legendYOffset'], | |
151 | - xaxisType, opts['xaxisMin'], opts['xaxisMax'], | |
152 | - opts['yaxisMin'], opts['yaxisMax'], | |
153 | - opts['xaxisFormatString'], opts['yaxisFormatString'], | |
154 | - to_json(opts['barWidth'])) | |
155 | - | |
156 | - self.env.log.debug(script); | |
120 | + script = """\ | |
121 | +(function($) { | |
122 | + var options = { | |
123 | + graph: '%(graph)s', seriesLabel: %(seriesLabel)s, data: %(data)s, | |
124 | + ticks: %(ticks)s, title: %(title)s, stack: %(stack)s, | |
125 | + legendLoc: %(legendLoc)s, | |
126 | + legendXOffset: %(legendXOffset)s, legendYOffset: %(legendYOffset)s, | |
127 | + xaxisType: %(xaxisType)s, xaxisMin: %(xaxisMin)s, xaxisMax: %(xaxisMax)s, | |
128 | + yaxisMin: %(yaxisMin)s, yaxisMax: %(yaxisMax)s, | |
129 | + xaxisFormatString: %(xaxisFormatString)s, | |
130 | + yaxisFormatString: %(yaxisFormatString)s, barWidth: %(barWidth)s | |
131 | + }; | |
132 | + if ($.fn.reportGraph) { | |
133 | + $('#reportgraph_%(index)d').reportGraph(options); | |
134 | + } | |
135 | + else { | |
136 | + window.reportgraph_data_%(index)d = options; | |
137 | + } | |
138 | +})(jQuery); | |
139 | + """ % { | |
140 | + 'index': self.index, | |
141 | + 'graph': opts['graph'], | |
142 | + 'seriesLabel': self._to_js_array(columns[1:]), | |
143 | + 'data': data, | |
144 | + 'ticks': self._to_js_array(ticks), | |
145 | + 'title': to_json(opts['title']), | |
146 | + 'stack': opts['stack'].lower(), | |
147 | + 'legendLoc': to_json(opts['legendLoc']), | |
148 | + 'legendXOffset': opts['legendXOffset'], | |
149 | + 'legendYOffset': opts['legendYOffset'], | |
150 | + 'xaxisType': to_json(xaxisType), | |
151 | + 'xaxisMin': opts['xaxisMin'], | |
152 | + 'xaxisMax': opts['xaxisMax'], | |
153 | + 'yaxisMin': opts['yaxisMin'], | |
154 | + 'yaxisMax': opts['yaxisMax'], | |
155 | + 'xaxisFormatString': to_json(opts['xaxisFormatString']), | |
156 | + 'yaxisFormatString': to_json(opts['yaxisFormatString']), | |
157 | + 'barWidth': to_json(opts['barWidth']), | |
158 | + } | |
157 | 159 | |
158 | 160 | div = tag.div( |
159 | - tag.div(' ', | |
160 | - id="reportgraph_%d" % (self.index), | |
161 | + tag.div('', | |
162 | + id="reportgraph_%d" % self.index, | |
163 | + class_='reportgraph_chart', | |
161 | 164 | style="width:%spx;height:%spx;" % |
162 | 165 | (opts["width"],opts["height"])), |
163 | 166 | tag.br(), |
@@ -164,10 +167,9 @@ | ||
164 | 167 | table, |
165 | 168 | tag.script(script, type="text/javascript"), |
166 | 169 | class_="reportgraph", |
167 | - id="reporinclude_%d" % (self.index) | |
168 | - ) | |
170 | + id="reporinclude_%d" % self.index) | |
169 | 171 | return div |
170 | - | |
172 | + | |
171 | 173 | def _parse_params(self, req, params): |
172 | 174 | opts = { |
173 | 175 | 'title':'', |
@@ -192,7 +194,7 @@ | ||
192 | 194 | 'yaxisFormatString':'', |
193 | 195 | 'barWidth':'50' |
194 | 196 | } |
195 | - | |
197 | + | |
196 | 198 | vars = {} |
197 | 199 | for (index, param) in enumerate(params.split(',')): |
198 | 200 | if index == 0: |
@@ -199,7 +201,7 @@ | ||
199 | 201 | id = param |
200 | 202 | id, vars = self._parse_vars(req, id) |
201 | 203 | continue |
202 | - | |
204 | + | |
203 | 205 | colon_split = param.split(':') |
204 | 206 | key = colon_split[0].strip() |
205 | 207 | value = '' |
@@ -209,17 +211,17 @@ | ||
209 | 211 | value = True |
210 | 212 | opts[key] = value |
211 | 213 | return id, vars, opts |
212 | - | |
214 | + | |
213 | 215 | def _parse_vars(self, req, id): |
214 | 216 | vars = {} |
215 | - | |
217 | + | |
216 | 218 | if id.find('?') == -1: |
217 | 219 | return id, vars |
218 | - | |
220 | + | |
219 | 221 | id_and_params = id.split('?') |
220 | 222 | params = id_and_params[1] |
221 | 223 | id = id_and_params[0] |
222 | - | |
224 | + | |
223 | 225 | if params.find('&') != -1: |
224 | 226 | for (index, param) in enumerate(params.split('&')): |
225 | 227 | if param.find('=') == -1: |
@@ -233,23 +235,23 @@ | ||
233 | 235 | vars[entry[0]] = entry[1] |
234 | 236 | if vars[entry[0]] == '$USER': |
235 | 237 | vars[entry[0]] = req.authname |
236 | - | |
238 | + | |
237 | 239 | return id, vars |
238 | - | |
240 | + | |
239 | 241 | def _get_report_info(self, id): |
240 | 242 | db = self.env.get_db_cnx() |
241 | 243 | cursor = db.cursor() |
242 | 244 | cursor.execute("SELECT title,query,description from report " |
243 | 245 | "WHERE id=%s", (id,)) |
244 | - | |
246 | + | |
245 | 247 | report = [(title, sql, desc) for title, sql, desc in cursor] |
246 | 248 | return report |
247 | - | |
249 | + | |
248 | 250 | def _sql_sub_vars(self, sql, vars, db): |
249 | 251 | rm = ReportModule(self.env) |
250 | 252 | sql, vars, missing_vars = rm.sql_sub_vars(sql, vars, db) |
251 | 253 | return sql, vars, missing_vars |
252 | - | |
254 | + | |
253 | 255 | def _getXAxisType(self, req, ticks, opts): |
254 | 256 | if ticks and len(ticks) > 0: |
255 | 257 | try: |
@@ -257,34 +259,18 @@ | ||
257 | 259 | return 'number' |
258 | 260 | except ValueError: |
259 | 261 | pass |
260 | - | |
262 | + | |
261 | 263 | try: |
262 | 264 | parse_date(ticks[0], req.tz) |
263 | 265 | return 'date' |
264 | 266 | except TracError: |
265 | 267 | pass |
266 | - | |
268 | + | |
267 | 269 | return 'string' |
268 | - | |
270 | + | |
269 | 271 | def _to_js_array(self, array): |
270 | - if array is None: | |
271 | - return 'null' | |
272 | - if len(array) == 0: | |
273 | - return '[]' | |
274 | - | |
275 | - is_number = True | |
276 | - for value in array: | |
277 | - try: | |
278 | - int(value) | |
279 | - except ValueError: | |
280 | - is_number = False | |
281 | - pass | |
282 | - | |
283 | - if is_number: | |
284 | - return "[" + ",".join(map(str, array)) + "]" | |
285 | - else: | |
286 | - return "['" + "','".join(map(str, array)) + "']" | |
287 | - | |
272 | + return to_json(array) | |
273 | + | |
288 | 274 | def _convert_col(self, req, column, col): |
289 | 275 | if column == 'time' or column.endswith(u'時刻'): |
290 | 276 | col = col != None and format_time(int(col)) or '--' |
@@ -292,7 +278,7 @@ | ||
292 | 278 | col = col != None and format_date(int(col)) or '--' |
293 | 279 | if column == 'datetime' or column.endswith(u'日時'): |
294 | 280 | col = col != None and format_datetime(int(col)) or '--' |
295 | - | |
281 | + | |
296 | 282 | if column.lower() in ('ticket', 'id', u'チケット'): |
297 | 283 | col = tag.a('#' + str(col), title='View Ticket', class_='ticket', |
298 | 284 | href=req.href.ticket(str(col))) |
@@ -8,9 +8,9 @@ | ||
8 | 8 | from renderer import ReportRenderer |
9 | 9 | |
10 | 10 | class ReportIncludeModule(Component): |
11 | - | |
11 | + | |
12 | 12 | implements(IRequestHandler) |
13 | - | |
13 | + | |
14 | 14 | # IRequestHandler methods |
15 | 15 | def match_request(self, req): |
16 | 16 | match = re.match(r'^/tracreportinclude(?:/(.*))?', req.path_info) |
@@ -21,21 +21,20 @@ | ||
21 | 21 | |
22 | 22 | def process_request(self, req): |
23 | 23 | req.perm.assert_permission('REPORT_VIEW') |
24 | - | |
24 | + | |
25 | 25 | try: |
26 | 26 | index, content = self._parse_args(req.args) |
27 | 27 | except KeyError: |
28 | 28 | return 'reportinclude_response.html', {'response':''}, None |
29 | - | |
29 | + | |
30 | 30 | req._reportinclude = index |
31 | - | |
31 | + | |
32 | 32 | renderer = ReportRenderer(self.env) |
33 | 33 | report = renderer.render(req, content) |
34 | - | |
34 | + | |
35 | 35 | data = {'response': report.generate()} |
36 | - | |
36 | + | |
37 | 37 | return 'reportinclude_response.html', data, None |
38 | - | |
38 | + | |
39 | 39 | def _parse_args(self, args): |
40 | 40 | return (int(args['index']), args['params'].replace('__AND__', '&')) |
41 | - | |
\ No newline at end of file |
@@ -1,5 +1,5 @@ | ||
1 | -(function(jQuery) { | |
2 | - jQuery.fn.reportGraph = function(options) { | |
1 | +(function($) { | |
2 | + $.fn.reportGraph = function(options) { | |
3 | 3 | var defaults = { |
4 | 4 | 'graph': 'lines', |
5 | 5 | 'stack' : false, |
@@ -15,12 +15,12 @@ | ||
15 | 15 | 'yaxisFormatString' : null |
16 | 16 | }; |
17 | 17 | |
18 | - var setting = jQuery.extend(defaults, options); | |
18 | + var setting = $.extend(defaults, options); | |
19 | 19 | var id = this.attr('id'); |
20 | - | |
20 | + | |
21 | 21 | var graph = _getGraph(setting); |
22 | 22 | graph.draw(id); |
23 | - | |
23 | + | |
24 | 24 | return this; |
25 | 25 | }; |
26 | 26 |
@@ -36,13 +36,13 @@ | ||
36 | 36 | return new PieGraph(setting); |
37 | 37 | } |
38 | 38 | } |
39 | - | |
39 | + | |
40 | 40 | /** |
41 | 41 | * Class: Graph |
42 | 42 | */ |
43 | 43 | function Graph(setting) { |
44 | 44 | this.setting = setting; |
45 | - | |
45 | + | |
46 | 46 | this.data = this.getData(); |
47 | 47 | this.title = setting.title; |
48 | 48 | this.stack = setting.stack; |
@@ -68,9 +68,9 @@ | ||
68 | 68 | tickOptions: {formatString: setting.yaxisFormatString} |
69 | 69 | }; |
70 | 70 | } |
71 | - | |
71 | + | |
72 | 72 | Graph.prototype.draw = function(id) { |
73 | - jQuery.jqplot(id, this.data, { | |
73 | + $.jqplot(id, this.data, { | |
74 | 74 | legend: this.legendOption, |
75 | 75 | title: this.title, |
76 | 76 | stackSeries: this.stack, |
@@ -86,7 +86,7 @@ | ||
86 | 86 | cursor: {show: true} |
87 | 87 | }); |
88 | 88 | }; |
89 | - | |
89 | + | |
90 | 90 | Graph.prototype.getSeriesDefaults = function() { |
91 | 91 | var seriesDefaults = {}; |
92 | 92 | seriesDefaults = { |
@@ -98,11 +98,11 @@ | ||
98 | 98 | } |
99 | 99 | return seriesDefaults; |
100 | 100 | }; |
101 | - | |
101 | + | |
102 | 102 | Graph.prototype.getRenderer = function() { |
103 | - return jQuery.jqplot.LineRenderer; | |
103 | + return $.jqplot.LineRenderer; | |
104 | 104 | }; |
105 | - | |
105 | + | |
106 | 106 | Graph.prototype.getData = function() { |
107 | 107 | if (this.setting.xaxisType == 'date' || this.setting.xaxisType == 'number') { |
108 | 108 | return _getData(this.setting); |
@@ -109,7 +109,7 @@ | ||
109 | 109 | } |
110 | 110 | return this.setting.data; |
111 | 111 | }; |
112 | - | |
112 | + | |
113 | 113 | Graph.prototype.getTicks = function() { |
114 | 114 | if (this.setting.xaxisType == 'date' || this.setting.xaxisType == 'number') { |
115 | 115 | return [] |
@@ -116,23 +116,23 @@ | ||
116 | 116 | } |
117 | 117 | return this.setting.ticks; |
118 | 118 | }; |
119 | - | |
119 | + | |
120 | 120 | Graph.prototype.getNumberTicks = function() { |
121 | 121 | var number = this.setting.ticks.length; |
122 | 122 | return number; |
123 | 123 | }; |
124 | - | |
124 | + | |
125 | 125 | Graph.prototype.getXAxisRenderer = function() { |
126 | 126 | if (this.setting.xaxisType == 'number') { |
127 | - return jQuery.jqplot.LinerAxisRenderer; | |
127 | + return $.jqplot.LinerAxisRenderer; | |
128 | 128 | } |
129 | 129 | if (this.setting.xaxisType == 'date') { |
130 | - return jQuery.jqplot.DateAxisRenderer; | |
130 | + return $.jqplot.DateAxisRenderer; | |
131 | 131 | } |
132 | 132 | // string |
133 | - return jQuery.jqplot.CategoryAxisRenderer; | |
133 | + return $.jqplot.CategoryAxisRenderer; | |
134 | 134 | }; |
135 | - | |
135 | + | |
136 | 136 | Graph.prototype.getXAxisMin = function() { |
137 | 137 | if (this.setting.xaxisMin == null) { |
138 | 138 | return this.setting.ticks[0]; |
@@ -139,7 +139,7 @@ | ||
139 | 139 | } |
140 | 140 | return this.setting.xaxisMin; |
141 | 141 | }; |
142 | - | |
142 | + | |
143 | 143 | Graph.prototype.getXAxisMax = function() { |
144 | 144 | if (this.setting.xaxisMax == null) { |
145 | 145 | return this.setting.ticks[this.setting.ticks.length-1]; |
@@ -146,16 +146,16 @@ | ||
146 | 146 | } |
147 | 147 | return this.setting.xaxisMax; |
148 | 148 | }; |
149 | - | |
149 | + | |
150 | 150 | Graph.prototype.getSeries = function() { |
151 | 151 | var series = []; |
152 | - jQuery.each(this.setting.seriesLabel, function(index, value){ | |
152 | + $.each(this.setting.seriesLabel, function(index, value){ | |
153 | 153 | // use default renderer. |
154 | 154 | series.push({label: value}) |
155 | 155 | }); |
156 | 156 | return series; |
157 | 157 | }; |
158 | - | |
158 | + | |
159 | 159 | /** |
160 | 160 | * Class: BarGraph |
161 | 161 | */ |
@@ -162,12 +162,12 @@ | ||
162 | 162 | function BarGraph(setting) { |
163 | 163 | Graph.apply(this, arguments); |
164 | 164 | } |
165 | - | |
165 | + | |
166 | 166 | // extend Graph |
167 | - jQuery.extend(BarGraph.prototype, Graph.prototype); | |
168 | - | |
167 | + $.extend(BarGraph.prototype, Graph.prototype); | |
168 | + | |
169 | 169 | BarGraph.prototype.getRenderer = function() { |
170 | - return jQuery.jqplot.BarRenderer; | |
170 | + return $.jqplot.BarRenderer; | |
171 | 171 | }; |
172 | 172 | |
173 | 173 | BarGraph.prototype.getSeriesDefaults = function() { |
@@ -177,7 +177,7 @@ | ||
177 | 177 | }; |
178 | 178 | return seriesDefaults; |
179 | 179 | }; |
180 | - | |
180 | + | |
181 | 181 | /** |
182 | 182 | * Class: LineGraph |
183 | 183 | */ |
@@ -184,14 +184,14 @@ | ||
184 | 184 | function LineGraph(setting) { |
185 | 185 | Graph.apply(this, arguments); |
186 | 186 | } |
187 | - | |
187 | + | |
188 | 188 | // extend Graph |
189 | - jQuery.extend(LineGraph.prototype, Graph.prototype); | |
189 | + $.extend(LineGraph.prototype, Graph.prototype); | |
190 | 190 | |
191 | 191 | LineGraph.prototype.getRenderer = function() { |
192 | - return jQuery.jqplot.LineRenderer; | |
192 | + return $.jqplot.LineRenderer; | |
193 | 193 | }; |
194 | - | |
194 | + | |
195 | 195 | /** |
196 | 196 | * Class: PieGraph |
197 | 197 | */ |
@@ -198,42 +198,42 @@ | ||
198 | 198 | function PieGraph(setting) { |
199 | 199 | Graph.apply(this, arguments); |
200 | 200 | } |
201 | - | |
201 | + | |
202 | 202 | // extend Graph |
203 | - jQuery.extend(PieGraph.prototype, Graph.prototype); | |
203 | + $.extend(PieGraph.prototype, Graph.prototype); | |
204 | 204 | |
205 | 205 | PieGraph.prototype.getRenderer = function() { |
206 | - return jQuery.jqplot.PieRenderer; | |
206 | + return $.jqplot.PieRenderer; | |
207 | 207 | }; |
208 | - | |
208 | + | |
209 | 209 | PieGraph.prototype.getData = function() { |
210 | 210 | return _getData(this.setting); |
211 | 211 | }; |
212 | - | |
212 | + | |
213 | 213 | PieGraph.prototype.getTicks = function() { |
214 | 214 | return [] |
215 | 215 | }; |
216 | - | |
216 | + | |
217 | 217 | PieGraph.prototype.getXAxisRenderer = function() { |
218 | - return jQuery.jqplot.LinerAxisRenderer; | |
218 | + return $.jqplot.LinerAxisRenderer; | |
219 | 219 | }; |
220 | - | |
220 | + | |
221 | 221 | // Utility |
222 | 222 | function _getData(setting) { |
223 | 223 | var rtn = []; |
224 | - jQuery.each(setting.data, function(seriesIndex, seriesValue) { | |
224 | + $.each(setting.data, function(seriesIndex, seriesValue) { | |
225 | 225 | var newSeries = []; |
226 | - | |
226 | + | |
227 | 227 | // caluculate sum for pie. |
228 | 228 | var sum = 0; |
229 | 229 | if (setting.graph == 'pie') { |
230 | - jQuery.each(seriesValue, function(dataIndex, dataValue) { | |
230 | + $.each(seriesValue, function(dataIndex, dataValue) { | |
231 | 231 | sum += dataValue; |
232 | 232 | }); |
233 | 233 | } |
234 | - | |
234 | + | |
235 | 235 | // create series. |
236 | - jQuery.each(seriesValue, function(dataIndex, dataValue) { | |
236 | + $.each(seriesValue, function(dataIndex, dataValue) { | |
237 | 237 | var newTick = setting.ticks[dataIndex]; |
238 | 238 | if (setting.graph == 'pie') { |
239 | 239 | newTick += ': ' + dataValue + ' (' + Math.round((dataValue/sum)*100*100)/100 + '%)'; |
@@ -244,6 +244,18 @@ | ||
244 | 244 | }); |
245 | 245 | return rtn; |
246 | 246 | } |
247 | - | |
247 | + | |
248 | + if ($.documentReady) { | |
249 | + $.documentReady(function() { | |
250 | + $('.reportgraph_chart').each(function() { | |
251 | + var name = 'reportgraph_data_' + this.id.replace(/^reportgraph_/, ''); | |
252 | + var data = window[name]; | |
253 | + if (data) { | |
254 | + window[name] = undefined; | |
255 | + $(this).reportGraph(data); | |
256 | + } | |
257 | + }); | |
258 | + }); | |
259 | + } | |
260 | + | |
248 | 261 | })(jQuery); |
249 | - |