commit | author | age
|
1e2d2f
|
1 |
/* |
T |
2 |
* Copyright 2011 gitblit.com. |
|
3 |
* |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
* you may not use this file except in compliance with the License. |
|
6 |
* You may obtain a copy of the License at |
|
7 |
* |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
* See the License for the specific language governing permissions and |
|
14 |
* limitations under the License. |
|
15 |
*/ |
|
16 |
package com.gitblit.wicket.charting; |
|
17 |
|
|
18 |
import javax.servlet.ServletContext; |
|
19 |
|
|
20 |
import org.apache.wicket.markup.html.IHeaderResponse; |
|
21 |
import org.apache.wicket.protocol.http.WebApplication; |
|
22 |
|
|
23 |
/** |
|
24 |
* Concrete class for Flotr2 charts |
|
25 |
* |
|
26 |
* @author Tim Ryan |
|
27 |
* |
|
28 |
*/ |
|
29 |
public class Flotr2Charts extends Charts { |
|
30 |
|
|
31 |
private static final long serialVersionUID = 1L; |
|
32 |
|
|
33 |
@Override |
|
34 |
public void renderHead(IHeaderResponse response) { |
7fb8d1
|
35 |
|
1e2d2f
|
36 |
// add Google Chart JS API reference |
T |
37 |
ServletContext servletContext = WebApplication.get().getServletContext(); |
|
38 |
String contextPath = servletContext.getContextPath(); |
7fb8d1
|
39 |
|
1e2d2f
|
40 |
response.renderJavascriptReference(contextPath + "/bootstrap/js/jquery.js"); |
T |
41 |
response.renderJavascriptReference(contextPath + "/flotr2/flotr2.min.js"); |
|
42 |
response.renderCSSReference(contextPath + "/flotr2/flotr2.custom.css"); |
7fb8d1
|
43 |
|
1e2d2f
|
44 |
// prepare draw chart function |
T |
45 |
StringBuilder sb = new StringBuilder(); |
7fb8d1
|
46 |
|
1e2d2f
|
47 |
line(sb, "$( document ).ready(function() {"); |
7fb8d1
|
48 |
line(sb, "try {"); |
1e2d2f
|
49 |
// add charts to header |
T |
50 |
for (Chart chart : charts) { |
|
51 |
chart.appendChart(sb); |
|
52 |
} |
7fb8d1
|
53 |
line(sb, "} catch (exception) {"); |
JM |
54 |
line(sb, " if (window.console && window.console.log) {"); |
|
55 |
line(sb, " window.console.log('flotr2 exception');"); |
|
56 |
line(sb, " window.console.log(exception);"); |
|
57 |
line(sb, " }"); |
|
58 |
line(sb, "}"); |
1e2d2f
|
59 |
// end draw chart function |
T |
60 |
line(sb, "});"); |
|
61 |
response.renderJavascript(sb.toString(), null); |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public Chart createPieChart(String tagId, String title, String keyName, |
|
66 |
String valueName) { |
|
67 |
return new Flotr2PieChart(tagId, title, keyName, valueName); |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
public Chart createLineChart(String tagId, String title, String keyName, |
|
72 |
String valueName) { |
|
73 |
return new Flotr2LineChart(tagId, title, keyName, valueName); |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public Chart createBarChart(String tagId, String title, String keyName, |
|
78 |
String valueName) { |
|
79 |
return new Flotr2BarChart(tagId, title, keyName, valueName); |
|
80 |
} |
7fb8d1
|
81 |
|
1e2d2f
|
82 |
} |