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