Skip to content
This repository has been archived by the owner on Nov 17, 2017. It is now read-only.

Charts update #74

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions charts/demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<artifactId>charts-ui</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.richfaces.sandbox.ui.bootstrap</groupId>
<artifactId>bootstrap-ui</artifactId>
<version>5.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
Expand Down
18 changes: 14 additions & 4 deletions charts/demo/src/main/java/org/richfaces/chart/Bean.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import java.util.GregorianCalendar;
import java.util.LinkedList;
import java.util.List;
import javax.annotation.PostConstruct;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import org.richfaces.sandbox.chart.PlotClickEvent;
import org.richfaces.sandbox.chart.model.ChartDataModel;
import org.richfaces.sandbox.chart.model.ChartDataModel.ChartType;
import org.richfaces.sandbox.chart.model.DateChartDataModel;
import org.richfaces.sandbox.chart.model.NumberChartDataModel;
import org.richfaces.sandbox.chart.model.StringChartDataModel;
Expand Down Expand Up @@ -43,14 +45,15 @@ public class Bean implements Serializable {

List<GDPRecord> gdp;



NumberChartDataModel err;
List<Country> err2;



@PostConstruct
public void init(){

err2 = new LinkedList<Country>();
err = new NumberChartDataModel(ChartType.line);

position = "ne";
sorting = "";
Expand Down Expand Up @@ -196,6 +199,10 @@ public void init(){

}

public NumberChartDataModel getErr() {
return err;
}

public NumberChartDataModel getA() {
return a;
}
Expand All @@ -216,6 +223,9 @@ public StringChartDataModel getCategory2() {
return category2;
}

public List<Country> getErr2() {
return err2;
}


public NumberChartDataModel getBarModel() {
Expand Down
86 changes: 86 additions & 0 deletions charts/demo/src/main/java/org/richfaces/chart/FileConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
**/
package org.richfaces.chart;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
import javax.servlet.ServletContext;
import java.io.*;
import java.util.Scanner;

/**
* @author <a href="http://community.jboss.org/people/bleathem">Brian Leathem</a>
*/
@FacesConverter(value = "FileConverter")
public class FileConverter implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
return null; // this is a one-way converter
}

@Override
public String getAsString(FacesContext facesContext, UIComponent component, Object value) {
String filePath = value.toString();
BufferedInputStream inputStream = null;
String string;
try {
ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
inputStream = new BufferedInputStream(servletContext.getResourceAsStream(filePath));
string = new Scanner(inputStream).useDelimiter("\\A").next();

// Suppress useless tags <ui:composition> and </ui:composition>
// in order to save space and focus on what is really important
if(string.startsWith("<ui:composition")) {
int indexOfGt = string.indexOf(">");
int indexOfLt = string.lastIndexOf("<");
string = string.substring(indexOfGt+1, indexOfLt);

// Correct indentation
string = string.replaceAll("\n ", "\n");
}

// Removing useless empty lines at the beginning and at the end
// of the code source
int indexOfNewline = string.indexOf("\n");
while(indexOfNewline == 0) {
string = string.substring(1);
indexOfNewline = string.indexOf("\n");
}

int lastIndexOfNewline = string.lastIndexOf("\n");
int length = string.length();
while(lastIndexOfNewline+1 == length) {
string = string.substring(0, lastIndexOfNewline);
lastIndexOfNewline = string.lastIndexOf("\n");
length = string.length();
}
} catch (java.util.NoSuchElementException e) {
throw new ConverterException(e);
} finally {
if (inputStream != null) try { inputStream.close(); } catch (IOException ignored) { }
}
return string;
}
}
42 changes: 13 additions & 29 deletions charts/demo/src/main/webapp/examples/_charts.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,27 @@
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:r="http://richfaces.org"
xmlns:s="http://richfaces.org/sandbox/prototyping">
xmlns:s="http://richfaces.org/sandbox/prototyping"
xmlns:b="http://richfaces.org/sandbox/bootstrap">
<ui:param name="title" value="General" />


<ui:define name="content">
<style type="text/css">
.graf{width:450px;}
</style>


Countries by carbon dioxide emissions per capita.

<ui:include src="/resources/sample.xhtml">
<ui:param name="facelet" value="basic"/>
</ui:include>
<a href="http://en.wikipedia.org/wiki/List_of_countries_by_carbon_dioxide_emissions_per_capita">data</a>
<br/><br/>
<s:chart>
<r:repeat value="#{bean.countries}" var="country" >
<s:series label="#{country.name}" type="line">
<r:repeat value="#{country.data}" var="record">
<s:point x="#{record.year}" y="#{record.tons}" />
</r:repeat>
</s:series>
</r:repeat>
<s:xaxis label="year"/>
<s:yaxis label="metric tons of CO2 per capita"/>
</s:chart>





Countries by vehicles per capita
<br/>
<br/>
<ui:include src="/resources/sample.xhtml">
<ui:param name="facelet" value="categoryBar"/>
</ui:include>
<a href="http://en.wikipedia.org/wiki/List_of_countries_by_vehicles_per_capita">data</a>
<br/><br/>
<s:chart id="barChart" >
<s:series data="#{bean.cars}" type="bar" />
<s:yaxis label="Motor vehicles per 1000 people"/>
</s:chart>

See <a href="https://github.com/Lukindo/richfaces-sandbox/blob/master/charts/demo/src/main/webapp/examples/_charts.xhtml#L37">source</a>
<br/>
See <a href="https://github.com/Lukindo/richfaces-sandbox/blob/master/charts/demo/src/main/java/org/richfaces/chart/Bean.java">backing bean source</a>
</ui:define>
</ui:composition>
40 changes: 7 additions & 33 deletions charts/demo/src/main/webapp/examples/axes.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,44 +32,18 @@


<ui:define name="content">
<ul>


<ui:include src="/resources/sample.xhtml">
<ui:param name="facelet" value="axes"/>
</ui:include>

<ul>
<li>min</li>
<li>max</li>
<li>pad</li>
<li>label</li>
<li>format</li>
</ul>
<br/><br/><br/>
<s:chart>
<r:repeat value="#{bean.countries}" var="country" >
<s:series label="#{country.name}" type="line">
<r:repeat value="#{country.data}" var="record">
<s:point x="#{record.year}" y="#{record.tons}" />
</r:repeat>
</s:series>
</r:repeat>
<s:xaxis label="year" />
<s:yaxis label="metric tons of CO2 per capita" min="7"/>
</s:chart>
<p>Same chart as in <h:link outcome="_charts">general</h:link> with following changes
<ul>
<li>x-axis:
<ul>

<li>label = year</li>
</ul>
</li>
<li>y-axis:
<ul>
<li>min = 7</li>
<li>label = metric tons of CO2 per capita</li>
</ul>

</li>
</ul>
</p>


See <a href="https://github.com/Lukindo/richfaces-sandbox/blob/master/charts/demo/src/main/webapp/examples/axes.xhtml">source</a>
</ui:define>
</ui:composition>
15 changes: 4 additions & 11 deletions charts/demo/src/main/webapp/examples/bar.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,10 @@
<ui:define name="content">


<s:chart id="myChart" >
<s:legend sorting="ascending"/>
<r:repeat value="#{bean.gdp}" var="country">
<s:series label="#{country.state}" type="bar">
<s:point x="Agricultural" y="#{country.agricult}"/>
<s:point x="Industrial" y="#{country.industry}"/>
<s:point x="Service" y="#{country.service}"/>
</s:series>
</r:repeat>
</s:chart>
<ui:include src="/resources/sample.xhtml">
<ui:param name="facelet" value="bars"/>
</ui:include>
GDP sector composition <a href="http://en.wikipedia.org/wiki/List_of_countries_by_GDP_sector_composition">data</a>
<br/> See <a href="https://github.com/Lukindo/richfaces-sandbox/blob/master/charts/demo/src/main/webapp/examples/bar.xhtml">source</a>
<br/>
</ui:define>
</ui:composition>
10 changes: 4 additions & 6 deletions charts/demo/src/main/webapp/examples/combined.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@
<ui:define name="content">


<s:chart id="myChart" >
<s:legend sorting="ascending"/>
<s:series data="#{bean.barModel}" type="bar"/>
<s:series data="#{bean.a}" type="line"/>
</s:chart>
See <a href="https://github.com/Lukindo/richfaces-sandbox/blob/master/charts/demo/src/main/webapp/examples/pie.xhtml">source</a>
<ui:include src="/resources/sample.xhtml">
<ui:param name="facelet" value="combined"/>
</ui:include>

</ui:define>
</ui:composition>
53 changes: 7 additions & 46 deletions charts/demo/src/main/webapp/examples/events.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@


<ui:define name="content">
Client side

<ui:include src="/resources/sample.xhtml">
<ui:param name="facelet" value="events"/>
</ui:include>


Client side
<ul>
<li>plotclick</li>
<li>mouseover</li>
Expand All @@ -43,51 +49,6 @@
<ul>
<li>plotclick</li>
</ul>

<script type='text/javascript'>
//<![CDATA[
function log(e,type){
$('#clickInfo').text(type+" Series index: "+e.data.seriesIndex
+" DataIndex: "+e.data.dataIndex+' ['+e.data.x+','+e.data.y+']');
}
function bClick(e){
$("#bInfo").text("This handler is callend only when B product clicked");
}
function hover(e){
$("#hoverInfo").text('['+e.data.x+','+e.data.y+']');
}
function barHover(e){
$("#barHover").text('['+e.data.x+','+e.data.y+']');
}
function clear(){
$("#hoverInfo").text("");
$("#barHover").text("");
}
//]]>
</script>

<h:form>

<s:chart onplotclick="log(event,'Line chart')" onmouseover="hover(event)" onmouseout="clear()" clickListener="#{eventBean.handler}">
<r:repeat value="#{eventBean.countries}" var="country" >
<s:series label="#{country.name}" type="line">
<r:repeat value="#{country.data}" var="record">
<s:point x="#{record.year}" y="#{record.tons}" />
</r:repeat>
</s:series>
</r:repeat>
<r:ajax event="plotclick" render="msg" execute="msg"/>
<s:xaxis label="year"/>
<s:yaxis label="metric tons of CO2 per capita"/>
</s:chart>

<h:outputText id="msg" value="#{eventBean.msg}"/>
</h:form>
<span id='hoverInfo'/><br/>
<span id='clickInfo'></span><br/>
<br/>


See <a href="https://github.com/Lukindo/richfaces-sandbox/blob/master/charts/demo/src/main/webapp/examples/events.xhtml">source</a>
</ui:define>
</ui:composition>
Loading