OW2 Consortium ofccharts

Compare Revisions

Ignore whitespace Rev 4 → Rev 5

/trunk/project/ofccharts/build.xml
New file
0,0 → 1,359
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE project [
 
<!ENTITY versionEntity "3.1">
]
>
 
<!-- ============================================================================================== -->
<!-- -->
<!-- OFC-Charts build file -->
<!-- -->
<!-- Targets are: -->
<!-- -->
<!-- o init : inits all the needed variables -->
<!-- o info (Default): print available targets -->
<!-- o debug: see the value of variables used by Ant -->
<!-- o compile: compile the ofc API -->
<!-- o javadoc: make javadoc for the packaged application -->
<!-- o clean: cleans the docs and classes directories -->
<!-- o clean-all: clean, distrib-clean -->
<!-- o jar: creates the jar files -->
<!-- o all: clean, compile, javadoc, jar -->
<!-- o distrib-clean: cleans the distrib directory -->
<!-- o distrib-copydocs: copy the docs to the distrib directory -->
<!-- o distrib-copysample: copies all the sample needed files to distrib -->
<!-- o distrib: makes distrib-clean, distrib-copydocs, -->
<!-- + zipping the distrib files -->
<!-- ============================================================================================== -->
 
<project name="OFC Charts" default="info" basedir=".">
 
<!-- ======================================================================= -->
<!-- INIT: set project environment -->
<!-- ======================================================================= -->
<target name="init">
<tstamp/>
<property name="ant.home" value="." />
<!-- project variables -->
<property name="project.name" value="OFC Charts" />
<property name="product.name" value="Charts" />
<property name="version" value="&versionEntity;" />
<property name="date" value="${DSTAMP}_${TSTAMP}" />
<!-- project paths -->
<property name="ofc.home" value="${basedir}" />
<property name="ofc.lib" value="${basedir}/lib" />
<property name="ofc.src.dir" value="${basedir}/src" />
<property name="ofc.classes.dir" value="${basedir}/classes" />
<property name="ofc.javadoc.dir" value="${basedir}/docs/api" />
<property name="ofc.distrib.dir" value="${basedir}/distrib" />
<property name="ofc.tmp.dir" value="${basedir}/tmp" />
<property name="ofc.etc.dir" value="${basedir}/etc" />
<!-- java librairies -->
<property name="project.classpath" value="${lib.all}" />
<!-- uncomment if you want to use jikes (must be in your path) -->
<!--property name="build.compiler" value="jikes" /-->
<echo message="==============================================================" />
<echo message="" />
<echo message="** Project: ${project.name} ** " />
<echo message="** Version: ${version} **" />
<echo message="** ${TODAY} : ${TSTAMP} **" />
<echo message="** Basedir: ${basedir}" />
<echo message="" />
<echo message="==============================================================" />
<mkdir dir="${ofc.classes.dir}" />
<mkdir dir="${ofc.javadoc.dir}" />
<mkdir dir="${ofc.distrib.dir}" />
<mkdir dir="${ofc.tmp.dir}" />
 
</target>
 
<!-- ======================================================================= -->
<!-- INFO: print available targets -->
<!-- ======================================================================= -->
<target name="info" depends="init">
<echo message="" />
<echo message="Targets are : " />
<echo message="" />
<echo message=" o init : inits all the needed variables" />
<echo message=" o info (Default): print available targets" />
<echo message=" o debug: see the value of variables used by Ant" />
<echo message=" o compile: compile the ofc API, the samples and the Apps" />
<echo message=" o clean: cleans the docs and classes directories" />
<echo message=" o clean-all: clean, distrib-clean" />
<echo message=" o all: clean, compile, javadoc, jar" />
<echo message=" o distrib-clean: cleans the distrib directory" />
<echo message=" o distrib-copydocs: copy the docs to the distrib directory" />
<echo message=" o distrib: makes distrib-clean," />
<echo message=" distrib-copydocs, distrib-copysample" />
<echo message=" + zipping the distrib files" />
<echo message=" o javadoc : generates the javadoc of connection" />
<echo message=" o jar : create the jar files of connection" />
<echo message="" />
</target>
 
<!-- ======================================================================= -->
<!-- ALL: compile and javadoc -->
<!-- ======================================================================= -->
<target name="all" depends="clean, jar, javadoc">
</target>
<!-- ======================================================================= -->
<!-- DEBUG: print debug info -->
<!-- ======================================================================= -->
<target name="debug" depends="init">
<echo message="################################################" />
<echo message="Debug information" />
<echo message="################################################" />
<echo message="-- Project" />
<echo message=" version = ${version}" />
<echo message=" date = ${TODAY} : ${TSTAMP} " />
<echo message="################################################" />
<echo message="-- Paths" />
<echo message=" ofc.src.dir = ${ofc.src.dir}" />
<echo message=" ofc.classes.dir = ${ofc.classes.dir}" />
<echo message=" ofc.javadoc.dir = ${ofc.javadoc.dir}" />
<echo message=" ofc.lib = ${ofc.lib}" />
<echo message="################################################" />
<echo message="-- Librairies" />
<echo message=" lib.all = ${lib.all}" />
<echo message="################################################" />
<echo message="-- Classpath" />
<echo message=" project.classpath = ${project.classpath}" />
<echo message="################################################" />
<echo message="--------------------------------------------------" />
</target>
 
<!-- ========================================================================== -->
<!-- GENERATE-VERSION: generate the version class with the parameter ${version} -->
<!-- ========================================================================== -->
<target name="generate-version" depends="init">
<java classname="generateVersion" fork="yes" classpath="./etc">
<arg line="
-Product=${product.name}
-Version=${version}
-Package=
" />
</java>
</target>
 
<!-- ======================================================================= -->
<!-- COMPILE: compile all source files (default with javac) -->
<!-- ======================================================================= -->
<target name="compile" depends="init, clean">
<echo message="################################################" />
<mkdir dir="${ofc.classes.dir}" />
 
<echo message="---------- Compiling the API ----------------" />
<javac srcdir="${ofc.src.dir}"
destdir="${ofc.classes.dir}"
classpath="${project.classpath}"
excludes="**/CVS/**, **/Cvs/**"
depend="yes"
/>
<echo message="################################################" />
</target>
 
<!-- ======================================================================= -->
<!-- CLEAN: delete the classes directory and the docs -->
<!-- ======================================================================= -->
<target name="clean" depends="init">
<echo message="################################################" />
<delete dir="${ofc.classes.dir}"/>
<delete>
<fileset dir="${ofc.javadoc.dir}" excludes="**/CVS/**, **/Cvs/**" />
</delete>
<echo message="################################################" />
</target>
 
<!-- ======================================================================= -->
<!-- DISTRIB-CLEAN : clean distribution directory -->
<!-- ======================================================================= -->
<target name="distrib-clean" depends="init">
<echo message="################################################" />
<echo message="---------- Deleting the distrib directory ----------------" />
<delete dir="${ofc.distrib.dir}" />
<echo message="---------- Creating the distrib directory ----------------" />
<mkdir dir="${ofc.distrib.dir}" />
<echo message="################################################" />
</target>
<!-- ======================================================================= -->
<!-- DISTRIB-COPYJAR : copy ofcCharts.jar to the distrib -->
<!-- ======================================================================= -->
<target name="distrib-copyjar" depends="init,jar">
<echo message="################################################" />
<echo message="-------------- Copying the ofcCharts.jar ------------------" />
<copy todir="${ofc.distrib.dir}" file="${ofc.classes.dir}/ofcCharts.jar" />
<echo message="################################################" />
</target>
 
<!-- ======================================================================= -->
<!-- DISTRIB-COPYDOCS : copy the docs to the distrib -->
<!-- ======================================================================= -->
<target name="distrib-copydocs" depends="init,javadoc">
<echo message="################################################" />
<echo message="-------------- Copying the doc files ------------------" />
<copy todir="${ofc.distrib.dir}/docs" >
<fileset dir="${ofc.home}/docs" excludes="**/*.doc"/>
</copy>
<echo message="################################################" />
</target>
 
 
<!-- ======================================================================= -->
<!-- DISTRIB-COPYLIBS : copy the external librairies -->
<!-- ======================================================================= -->
<target name="distrib-copylibs" depends="init">
<echo message="################################################" />
<echo message="------------- Copying the extern librairies files ----------------" />
<mkdir dir="${ofc.distrib.dir}/lib" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/js.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/crimson-parser.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/crimson.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/jaxp.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/batik-xml.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/batik-util.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/batik-transcoder.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/batik-svggen.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/batik-svg-dom.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/batik-script.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/batik-parser.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/batik-gvt.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/batik-gui-util.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/batik-extension.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/batik-ext.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/batik-dom.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/batik-css.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/batik-bridge.jar" />
<copy todir="${ofc.distrib.dir}/lib" file="${ofc.lib}/batik-awt-util.jar" />
<echo message="################################################" />
</target>
 
<!-- ======================================================================= -->
<!-- DISTRIB : makes the distribution release -->
<!-- ======================================================================= -->
<target name="distrib" depends="clean-all, distrib-libs, distrib-docs">
<echo message="################################################" />
<echo message="----------------- Ziping the files --------------------" />
<zip zipfile="${ofc.distrib.dir}/ofcChartsDocs.zip" basedir="${ofc.distrib.dir}" includes="docs/**" />
<echo message="################################################" />
</target>
<!-- ======================================================================= -->
<!-- DISTRIB-LIBS : makes the distribution release -->
<!-- ======================================================================= -->
<target name="distrib-libs" depends="distrib-copyjar, distrib-copylibs">
<echo message="################################################" />
<echo message="----------------- Ziping the files --------------------" />
<zip zipfile="${ofc.distrib.dir}/ofcChartsLibs.zip" basedir="${ofc.distrib.dir}" includes="ofcCharts.jar, lib/** " />
<echo message="################################################" />
</target>
 
<!-- ======================================================================= -->
<!-- DISTRIB-DOCS : makes the distribution release -->
<!-- ======================================================================= -->
<target name="distrib-docs" depends="distrib-copydocs">
<echo message="################################################" />
<echo message="----------------- Ziping the files --------------------" />
<zip zipfile="${ofc.distrib.dir}/ofcChartsDocs.zip" basedir="${ofc.distrib.dir}" includes="docs/**" />
<echo message="################################################" />
</target>
 
<!-- ======================================================================= -->
<!-- CLEAN-ALL : cleans all the stuff -->
<!-- ======================================================================= -->
<target name="clean-all" depends="clean, distrib-clean">
</target>
<!-- ======================================================================= -->
<!-- JAVADOC: make external javadoc -->
<!-- ======================================================================= -->
<target name="javadoc" depends="init">
<echo message="################################################" />
<mkdir dir="${ofc.javadoc.dir}" />
<javadoc packagenames="
com.oxymel.ofc.charts,
com.oxymel.ofc.charts.exception, com.oxymel.ofc.charts.data,
com.oxymel.ofc.charts.animation,
com.oxymel.ofc.charts.data.grid.Grid,
com.oxymel.ofc.charts.data.grid.GridNode,
com.oxymel.ofc.charts.data.grid.IrregularGrid,
com.oxymel.ofc.charts.data.grid.RegularGrid,
com.oxymel.ofc.charts.animation.Contour2DAnimator,
com.oxymel.ofc.charts.animation.SVGAnimationContext,
com.oxymel.ofc.charts.animation.ChartAnimator,
com.oxymel.ofc.charts.series"
sourcepath="${ofc.src.dir}"
classpath="${project.classpath}"
destdir="${ofc.javadoc.dir}"
author="false"
version="false"
public="true"
windowtitle="${project.name} API Documentation"
>
 
<header><![CDATA[<h4> ${project.name} ${version}</h4>]]> </header>
<doctitle><![CDATA[ ${project.name} <br>
API Specification <br>
<h5> This document is the API specification for the ${project.name} component, version ${version} </h5> ]]>
</doctitle>
<bottom><![CDATA[<i>Copyright &#169; 2006 Oxymel SA All Rights Reserved.</i>]]></bottom>
</javadoc>
<echo message="################################################" />
</target>
<!-- ======================================================================= -->
<!-- JAR: creates the jar files -->
<!-- ======================================================================= -->
 
<target name="jar" depends="compile">
<echo message="################################################" />
<delete file="${ofc.classes.dir}/ofcCharts.jar" />
 
<jar jarfile="${ofc.classes.dir}/ofcCharts.jar">
<fileset dir="${ofc.classes.dir}" includes=" com/oxymel/ofc/**/*.class" />
<include name="build"/>
<manifest>
<attribute name="Built-By" value="Oxymel"/>
<section name=" OFC-Charts ${version}, ${TODAY} "/>
</manifest>
</jar>
 
<delete dir="${ofc.tmp.dir}/ofccharts" />
<echo message="################################################" />
</target>
 
</project>
/trunk/project/ofccharts/build.bat.ref
New file
0,0 → 1,39
@echo off
 
rem =================================================================================
rem
rem build.bat
rem
rem ant launcher for OFC-Charts
rem
rem
rem =================================================================================
 
rem Give the correct path to the JAVA_HOME (without white space)
 
set JAVA_HOME=%JAVA_HOME%
 
rem =================================================================================
 
 
set OFC_HOME=.
set CLASSPATH=%OFC_HOME%\lib\ant.jar;%JAVA_HOME%\lib\tools.jar;%OFC_HOME%\lib\;%JAVA_HOME%\jre\lib\rt.jar
set CLASSPATH=%OFC_HOME%\lib\jaxp.jar;%OFC_HOME%\lib\crimson.jar;%CLASSPATH%
set CLASSPATH=%OFC_HOME%\lib\js.jar;%OFC_HOME%\lib\crimson-parser.jar;%OFC_HOME%\lib\batik-xml.jar;%CLASSPATH%
set CLASSPATH=%OFC_HOME%\lib\batik-util.jar;%OFC_HOME%\lib\batik-transcoder.jar;%OFC_HOME%\lib\batik-svggen.jar;%CLASSPATH%
set CLASSPATH=%OFC_HOME%\lib\batik-svg-dom.jar;%OFC_HOME%\lib\batik-script.jar;%CLASSPATH%
set CLASSPATH=%OFC_HOME%\lib\batik-parser.jar;%OFC_HOME%\lib\batik-gvt.jar;%OFC_HOME%\lib\batik-gui-util.jar;%CLASSPATH%
set CLASSPATH=%OFC_HOME%\lib\batik-extension.jar;%OFC_HOME%\lib\batik-ext.jar;%CLASSPATH%
set CLASSPATH=%OFC_HOME%\lib\batik-dom.jar;%OFC_HOME%\lib\batik-css.jar;%OFC_HOME%\lib\batik-bridge.jar;%CLASSPATH%
set CLASSPATH=%OFC_HOME%\lib\batik-awt-util.jar;%OFC_HOME%\lib\;%CLASSPATH%
 
set ANT_PARAMETER=-Djava.home=%JAVA_HOME%
set ANT_PARAMETER=%ANT_PARAMETER% -Dlib.all=%CLASSPATH%
set PATH=%PATH%;%OFC_HOME%\bin;%JAVA_HOME%\bin
 
echo %JAVA_HOME%
 
%JAVA_HOME%\bin\java -Dofc.home=%OFC_HOME% -classpath "%CLASSPATH%" org.apache.tools.ant.Main %ANT_PARAMETER% %1 %2 %3 %4 %5 %6 %7 %8 %9
goto exit
 
:exit
/trunk/project/ofccharts/lib/batik-gui-util.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/batik-ext.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/batik-gvt.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/batik-xml.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/batik-script.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/batik-transcoder.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/batik-awt-util.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/jaxp.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/crimson-parser.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/batik-extension.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/batik-svg-dom.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/batik-util.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/batik-dom.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/crimson.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/js.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/batik-css.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/batik-svggen.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/ant.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/batik-bridge.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/lib/batik-parser.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/VerticalAxisCommon.java
New file
0,0 → 1,52
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.Graphics2D;
import java.awt.Font;
 
//ofc
import com.oxymel.ofc.charts.util.Graphics2DTools;
 
/**
* This class provides the common vertical axis management
*/
abstract class VerticalAxisCommon extends Axis
{
protected VerticalAxisCommon(String label)
{
super(label);
}
 
abstract protected String getLargerStringValue();
 
protected int getNbPixelUsedForWriteYValues(Graphics2D graphics2D)
{
String szMaxValueOfGapIndicator = getLargerStringValue();
if(getSuffixAllValues() != null){
szMaxValueOfGapIndicator += getSuffixAllValues();
}
 
Font font = graphics2D.getFont();
graphics2D.setFont(getFont(graphics2D));
int nbPixelFreeForWriteYValues = Graphics2DTools.getNbPixelWidthOfTxt(graphics2D, szMaxValueOfGapIndicator);
graphics2D.setFont(font);
return nbPixelFreeForWriteYValues;
}
 
 
protected int getNbPixelUsedByLabel(Graphics2D graphics2D)
{
return Graphics2DTools.getNbPixelHeightOfTxt(graphics2D, getLabel());
}
 
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/GaugeChart.java
New file
0,0 → 1,482
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//batik
import java.awt.*;
import java.awt.geom.*;
 
import org.apache.batik.svggen.*;
import com.oxymel.ofc.charts.animation.*;
import com.oxymel.ofc.charts.exception.*;
import com.oxymel.ofc.charts.series.*;
import com.oxymel.ofc.charts.util.*;
 
/**
* This class provides a gauge chart management
* It is an indicator which looks like a gauge.
* It indicates a value and all colored zone (ie: all range value)
*/
public class GaugeChart extends Chart
{
private int _nbPixelToDecalGraduation = 2;
private double _radialGradientValue = 1;
private double _radialGradientValueForAnimation = 4;
 
 
private RangeValueSeriesContainer _rangeValueSeriesContainer;
private double _gaugeValue;
 
//
ColoredVerticalNumberAxis _coloredAxis = new ColoredVerticalNumberAxis("");
 
/**
* Constructor
* @param chartWidth image width
* @param chartHeight image height
* @param rangeValueSeriesContainer colored range indicator
* @param gaugeValue value to display
* @throws OFCChartsException
*/
public GaugeChart(int chartWidth, int chartHeight,
RangeValueSeriesContainer rangeValueSeriesContainer,
double gaugeValue) throws OFCChartsException
{
super(chartWidth, chartHeight);
setRangeValueSeriesContainer(rangeValueSeriesContainer);
_gaugeValue = gaugeValue;
set3dEffectValue(10);
 
//
_coloredAxis.setAxisColor(Color.black);
_coloredAxis.setValueWriteColor(Color.black);
_coloredAxis.setArrowLength(0);
_coloredAxis.setMaxValue(Math.max(_rangeValueSeriesContainer.getMaxValue(), gaugeValue));
_coloredAxis.setMinValue(Math.min(_rangeValueSeriesContainer.getMinValue(), gaugeValue));
 
_coloredAxis.setNbColoredPixelArroundAxis(15);
_coloredAxis.setRangeValueSeriesContainer(_rangeValueSeriesContainer);
}
 
/**
* Change data used to draw chart
* @param rangeValueSeriesContainer All range value series
*/
public void setRangeValueSeriesContainer(RangeValueSeriesContainer rangeValueSeriesContainer)
{
_rangeValueSeriesContainer = rangeValueSeriesContainer;
setAllSeriesColorFromPalette(rangeValueSeriesContainer);
}
 
protected SeriesContainer getSeriesContainer(){return _rangeValueSeriesContainer;}
 
protected void doDrawChart(Graphics2D graphics2D) throws OFCChartsException
{
int xTopLeftGraphic = getXTopLeftGraphic(graphics2D);
int yTopLeftGraphic = getYTopLeftGraphic(graphics2D);
int graphicWidth = getGraphicWidth(graphics2D);
int graphicHeight = getGraphicHeight(graphics2D);
 
//drawGraphicBackground(xTopLeftGraphic, yTopLeftGraphic,
// graphicWidth, graphicHeight, graphics2D);
 
//_legend.drawLegend(getXTopLeftLegend(graphics2D), getYTopLeftLegend(graphics2D),
// getSeriesContainer().getAllSeriesOrderByDisplayNumber(), graphics2D);
 
//bug à voir plus tard
if (_legend.getLegendDisplayMode() > 0){
_legend.drawLegend(
getXTopLeftLegend(xTopLeftGraphic, yTopLeftGraphic, graphicWidth,
graphicHeight, graphics2D),
getYTopLeftLegend(xTopLeftGraphic, yTopLeftGraphic, graphicWidth,
graphicHeight, graphics2D),
getSeriesContainer().getAllSeriesOrderByDisplayNumber(), graphics2D);
}
 
drawGraphic(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D, false, null);
}
 
/**
* Value 0 : no legend
* Value 1 : align right
* @param legendDisplayMode int
*/
public void setLegendDisplayMode(int legendDisplayMode) {
if (legendDisplayMode == 0) _legend.setLegendDisplayMode(Legend.LEGEND_ALIGN_MODE_NONE);
else _legend.setLegendDisplayMode(Legend.LEGEND_DISPLAY_MODE_RIGHT);
}
 
/**
* Value 0 : no legend
* Value 1 : align right
* @param legendAlignMode The legend align mode to set.
* @see Legend
*/
public void setLegendAlignMode(int legendAlignMode) {
if (legendAlignMode == 0) _legend.setLegendDisplayMode(Legend.LEGEND_ALIGN_MODE_NONE);
else _legend.setLegendDisplayMode(Legend.LEGEND_DISPLAY_MODE_RIGHT);
}
 
protected void doDrawAnimateSVGChart(SVGGraphics2D graphics2D, SVGAnimationContext svgAnimationContext) throws OFCChartsException
{
int xTopLeftGraphic = getXTopLeftGraphic(graphics2D);
int yTopLeftGraphic = getYTopLeftGraphic(graphics2D);
int graphicWidth = getGraphicWidth(graphics2D);
int graphicHeight = getGraphicHeight(graphics2D);
 
drawGraphic(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D, true, svgAnimationContext);
}
 
 
private void drawGraphic(int xTopLeftGraphic, int yTopLeftGraphic, int graphicWidth, int graphicHeight,
Graphics2D graphics2D, boolean isAnimateGauge, SVGAnimationContext svgAnimationContext) throws OFCChartsException
{
int xTopLeft = xTopLeftGraphic;
int yTopLeft = yTopLeftGraphic;
int width = graphicWidth;
int height = graphicHeight;
 
//draw Thermometer base
int withThermometerBase = width/4;
int heightThermometerBase = height/4;
int xTopLeftThermometerBase = xTopLeft + width/2 - withThermometerBase/2;
int yTopLeftThermometerBase = yTopLeft + height - heightThermometerBase;
Arc2D arc = new Arc2D.Double((double)xTopLeftThermometerBase,
(double)yTopLeftThermometerBase,
(double)withThermometerBase, (double)heightThermometerBase, 120, 300 , Arc2D.OPEN);
drawArcWithRadialGradientEffect3D(arc, Color.lightGray, _radialGradientValue, graphics2D);
 
//draw tube
int withThermometerTube = (int)(arc.getEndPoint().getX() - arc.getStartPoint().getX());
int heightThermometerTube = (int)(height - heightThermometerBase + (arc.getEndPoint().getY() - yTopLeftThermometerBase));
int xTopLeftThermometerTube = xTopLeftThermometerBase + withThermometerTube/2;
int yTopLeftThermometerTube = yTopLeft;
drawTubeWithHorizontalLinearGradientEffect3D(xTopLeftThermometerTube,
yTopLeftThermometerTube, withThermometerTube, heightThermometerTube,
Color.lightGray, graphics2D);
 
//drawArcAtTopOfTube
/*
Arc2D arcTopTube = getArcTopOfTube(xTopLeftThermometerTube, yTopLeftThermometerTube,
withThermometerTube, heightThermometerTube);
graphics2D.setColor(Color.gray);
graphics2D.fill(arcTopTube);
*/
 
//draw graduation
drawGraduation(xTopLeftThermometerTube - _nbPixelToDecalGraduation, yTopLeftThermometerTube, graphicWidth,
heightThermometerTube, xTopLeftThermometerTube - _nbPixelToDecalGraduation,
yTopLeftThermometerTube + heightThermometerTube, graphics2D);
 
//
if(!isAnimateGauge){
drawThermometerValue(_gaugeValue, arc, xTopLeftThermometerTube, yTopLeftThermometerTube,
withThermometerTube, heightThermometerTube, _radialGradientValue, graphics2D);
}
else{
drawArcWithRadialGradientEffect3D(arc, Color.blue, _radialGradientValue, graphics2D);
drawAnimateThermometerValue(_gaugeValue, arc, xTopLeftThermometerTube, yTopLeftThermometerTube,
withThermometerTube, heightThermometerTube, (SVGGraphics2D)graphics2D, svgAnimationContext);
}
 
}
 
private void drawThermometerValue(double value, Arc2D arc,
int xTopLeftThermometerTube, int yTopLeftThermometerTube,
int withThermometerTube, int heightThermometerTube, double radialGradientValue,
Graphics2D graphics2D)
{
drawArcWithRadialGradientEffect3D(arc, Color.blue, radialGradientValue, graphics2D);
drawTubeAndValue(value, arc,
xTopLeftThermometerTube, yTopLeftThermometerTube,
withThermometerTube, heightThermometerTube, radialGradientValue,
graphics2D);
}
 
private void drawTubeAndValue(double value, Arc2D arc,
int xTopLeftThermometerTube, int yTopLeftThermometerTube,
int withThermometerTube, int heightThermometerTube, double radialGradientValue,
Graphics2D graphics2D)
{
double relativeSizeOfValue = Graphics2DTools.getRelativeSizeOfValue(value,
_coloredAxis.getGapValue(), _coloredAxis.getSizeOfGap());
drawValue(value, arc, Color.black, graphics2D);
double yTopLetfOfLiquideInTube = getYTopLetfOfLiquideInTube(yTopLeftThermometerTube,
heightThermometerTube, relativeSizeOfValue);
drawTubeWithHorizontalLinearGradientEffect3D(xTopLeftThermometerTube, yTopLetfOfLiquideInTube,
withThermometerTube,
getHeightOfLiquideInTube(relativeSizeOfValue, yTopLetfOfLiquideInTube, yTopLeftThermometerTube, heightThermometerTube),
Color.blue, graphics2D);
}
 
private double getYTopLetfOfLiquideInTube(int yTopLeftThermometerTube,
int heightThermometerTube, double relativeSizeOfValue)
{
if(relativeSizeOfValue >= 0){
return yTopLeftThermometerTube + heightThermometerTube - (relativeSizeOfValue +
(_coloredAxis.getSizeOfGap() * _coloredAxis.getNbNegativeGapToIncludeMinValue()));
}else{
relativeSizeOfValue = (-1) * relativeSizeOfValue;
return yTopLeftThermometerTube + heightThermometerTube -
(_coloredAxis.getSizeOfGap() * _coloredAxis.getNbNegativeGapToIncludeMinValue()) +
relativeSizeOfValue;
}
}
 
private double getHeightOfLiquideInTube(double relativeSizeOfValue, double yTopLetfOfLiquideInTube,
double yTopLeftThermometerTube, double heightThermometerTube)
{
if(relativeSizeOfValue >= 0){
return relativeSizeOfValue +
(_coloredAxis.getSizeOfGap() * _coloredAxis.getNbNegativeGapToIncludeMinValue());
}else{
double yBottomTube = yTopLeftThermometerTube + heightThermometerTube;
return yBottomTube - (yTopLetfOfLiquideInTube ) ;
}
}
 
private void drawValue(double valueToDraw, Arc2D arc, Color color, Graphics2D graphics2D)
{
graphics2D.setColor(color);
String value = ""+ (int)valueToDraw;
Font font = graphics2D.getFont();
graphics2D.setFont(getFont(graphics2D, 12));
graphics2D.drawString(value,
Graphics2DTools.getXToAlignTxt(graphics2D,
(int)(arc.getCenterX()), value),
Graphics2DTools.getYToAlignTxt(graphics2D,
(int)arc.getCenterY(), value));
graphics2D.setFont(font);
}
 
private void drawAnimateThermometerValue(double arrowValue, Arc2D arc,
int xTopLeftThermometerTube, int yTopLeftThermometerTube,
int withThermometerTube, int heightThermometerTube,
SVGGraphics2D graphics2D, SVGAnimationContext svgAnimationContext)
{
/*
SVGGraphics2DAnimateMgr.generateAnimation(graphics2D, svgAnimationContext,
new GaugeAnimation(arrowValue, arc,
xTopLeftThermometerTube, yTopLeftThermometerTube,
withThermometerTube, heightThermometerTube,
svgAnimationContext.getNbImage()));
*/
double firstValueOnAxis = _coloredAxis.getFirstValueOnAxis();
double intervalValue = Graphics2DTools.getIntervalValue(firstValueOnAxis, arrowValue);
new SVGGraphics2DAnimateMgr().generateAnimation(graphics2D, svgAnimationContext,
new GaugeAnimation(arc,
xTopLeftThermometerTube, yTopLeftThermometerTube,
withThermometerTube, heightThermometerTube,
new ValueCursor(firstValueOnAxis,
intervalValue/svgAnimationContext.getNbImage(),
arrowValue)));
 
}
 
private void drawGraduation(int xTop, int yTop, int width, int height,
int xOrigine, int yOrigine, Graphics2D graphics2D) throws OFCChartsException
{
_coloredAxis.setNbPixelSize(height);
_coloredAxis.setNbGapMax(graphics2D);
_coloredAxis.draw(width, height, xTop, yTop,
xOrigine,
yOrigine - (_coloredAxis.getSizeOfGap() * _coloredAxis.getNbNegativeGapToIncludeMinValue()),
graphics2D);
 
}
 
private void drawArcWithRadialGradientEffect3D(Arc2D arc, Color color, double angleExtent, Graphics2D graphics2D)
{
graphics2D.setColor(color);
graphics2D.fill(arc);
 
double initialAngleStart = arc.getAngleStart();
double initialAngleExtent = arc.getAngleExtent();
 
double angleStart = 0;
arc.setAngleStart(0);
arc.setAngleExtent(0);
Paint paint = graphics2D.getPaint();
while(angleStart< 360){
arc.setAngleStart(angleStart);
arc.setAngleExtent(angleExtent);
GradientPaint gradientPaint;
gradientPaint = new GradientPaint(new Point2D.Double(arc.getCenterX(), arc.getCenterY()),
Color.white, new Point2D.Double(arc.getEndPoint().getX(), arc.getEndPoint().getY()), color);
graphics2D.setPaint(gradientPaint);
graphics2D.drawLine((int)arc.getCenterX(), (int)arc.getCenterY(), (int)arc.getEndPoint().getX(), (int)arc.getEndPoint().getY());
angleStart += angleExtent;
}
graphics2D.setPaint(paint);
arc.setAngleStart(initialAngleStart);
arc.setAngleExtent(initialAngleExtent);
}
 
private void drawTubeWithHorizontalLinearGradientEffect3D(double xTopLeftThermometerTube,
double yTopLeftThermometerTube, double withThermometerTube, double heightThermometerTube,
Color color, Graphics2D graphics2D)
{
Arc2D arcTopOfTube = getArcTopOfTube(xTopLeftThermometerTube, yTopLeftThermometerTube,
withThermometerTube, heightThermometerTube);
Arc2D arcBottomOfTube = getArcBottomOfTube(xTopLeftThermometerTube, yTopLeftThermometerTube,
withThermometerTube, heightThermometerTube);
 
//tube left part
arcTopOfTube.setAngleStart(180);
arcTopOfTube.setAngleExtent(90);
arcBottomOfTube.setAngleStart(180);
arcBottomOfTube.setAngleExtent(90);
GeneralPath tubeLeftPart = getGeneralPathOfTube(arcTopOfTube, arcBottomOfTube);
 
//tube right part
arcTopOfTube.setAngleStart(270);
arcTopOfTube.setAngleExtent(90);
arcBottomOfTube.setAngleStart(270);
arcBottomOfTube.setAngleExtent(90);
GeneralPath tubeRightPart = getGeneralPathOfTube(arcTopOfTube, arcBottomOfTube);
 
//color
Paint paint = graphics2D.getPaint();
GradientPaint gradientPaint = new GradientPaint(
(float)xTopLeftThermometerTube, (float)yTopLeftThermometerTube, color,
(float)(xTopLeftThermometerTube + withThermometerTube), (float)yTopLeftThermometerTube, Color.white);
graphics2D.setPaint(gradientPaint);
graphics2D.fill(tubeLeftPart);
graphics2D.setPaint(paint);
 
gradientPaint = new GradientPaint(
(float)xTopLeftThermometerTube, (float)yTopLeftThermometerTube, Color.white,
(float)(xTopLeftThermometerTube + withThermometerTube), (float)yTopLeftThermometerTube, color);
graphics2D.setPaint(gradientPaint);
graphics2D.fill(tubeRightPart);
graphics2D.setPaint(paint);
 
//drawArcAtTopOfTube
arcTopOfTube.setAngleStart(0);
arcTopOfTube.setAngleExtent(360);
graphics2D.setColor(color.darker());
graphics2D.fill(arcTopOfTube);
}
 
private GeneralPath getGeneralPathOfTube(Arc2D arcTopOfTube, Arc2D arcBottomOfTube)
{
GeneralPath tubePart = new GeneralPath();
tubePart.moveTo((int)arcTopOfTube.getStartPoint().getX(), (int)arcTopOfTube.getStartPoint().getY());
tubePart.append(arcTopOfTube.getPathIterator(null), true);
tubePart.lineTo((int)arcTopOfTube.getEndPoint().getX(), (int)arcTopOfTube.getEndPoint().getY());
 
tubePart.lineTo((int)arcBottomOfTube.getEndPoint().getX(), (int)arcBottomOfTube.getEndPoint().getY());
tubePart.append(arcBottomOfTube.getPathIterator(null), true);
tubePart.lineTo((int)arcBottomOfTube.getStartPoint().getX(), (int)arcBottomOfTube.getStartPoint().getY());
tubePart.lineTo((int)arcTopOfTube.getStartPoint().getX(), (int)arcTopOfTube.getStartPoint().getY());
 
return tubePart;
}
 
private Arc2D getArcTopOfTube(double xTopLeftThermometerTube, double yTopLeftThermometerTube,
double withThermometerTube, double heightThermometerTube)
{
double heightTopTube = get3dEffectValue();
return new Arc2D.Double((double)xTopLeftThermometerTube,
(double)yTopLeftThermometerTube - heightTopTube/2,
(double)withThermometerTube, heightTopTube, 0, 360 , Arc2D.OPEN);
}
 
private Arc2D getArcBottomOfTube(double xTopLeftThermometerTube, double yTopLeftThermometerTube,
double withThermometerTube, double heightThermometerTube)
{
double heightBottomTube = get3dEffectValue();
double xTopLeftBottomTube = xTopLeftThermometerTube;
double yTopLeftBottomTube = yTopLeftThermometerTube + heightThermometerTube - heightBottomTube/2;
return new Arc2D.Double(xTopLeftBottomTube,
yTopLeftBottomTube,
(double)withThermometerTube, heightBottomTube, 0, 360 , Arc2D.OPEN);
}
 
 
private Font getFont(Graphics2D graphics2D, int sizeFont)
{
Font font = graphics2D.getFont();
if(sizeFont > 0){
return new Font(font.getName(), font.getStyle(), sizeFont);
}
else{
return font;
}
}
 
 
private class GaugeAnimation implements AnimationInterface
{
//
private Arc2D _arc;
private int _xTopLeftThermometerTube;
private int _yTopLeftThermometerTube;
private int _withThermometerTube;
private int _heightThermometerTube;
private ValueCursor _valueCursor;
 
 
//ValueCursor(double value, double step, double valueStart)
 
public GaugeAnimation(Arc2D arc,
int xTopLeftThermometerTube, int yTopLeftThermometerTube,
int withThermometerTube, int heightThermometerTube,
ValueCursor valueCursor)
{
//
_arc = arc;
_xTopLeftThermometerTube = xTopLeftThermometerTube;
_yTopLeftThermometerTube = yTopLeftThermometerTube;
_withThermometerTube = withThermometerTube;
_heightThermometerTube = heightThermometerTube;
 
//
_valueCursor = valueCursor;
 
//
//_valueCursor = new ValueCursor(_value, Math.abs(value)/nbImage, valueStart);
//Math.abs()
 
//_value = value;
//_step = value/nbImage;
}
 
public boolean hasNextImage()
{
return _valueCursor.hasMoreValue();
}
 
public void drawImage(SVGGraphics2D graphics2D)
{
drawTubeAndValue(_valueCursor.nextValue(), _arc, _xTopLeftThermometerTube, _yTopLeftThermometerTube,
_withThermometerTube, _heightThermometerTube, _radialGradientValue, graphics2D);
/*
if(_currentValue == _value){
_currentValue ++;
return;
}
if(_currentValue < _value){
_currentValue += _step;
if(_currentValue > _value){
_currentValue = _value;
}
}
*/
}
 
}
 
/*
public static void main(String[] argv) throws Exception
{
}
*/
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/RadarChart.java
New file
0,0 → 1,397
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.util.*;
import java.awt.*;
//ofc
import com.oxymel.ofc.charts.data.*;
import com.oxymel.ofc.charts.exception.*;
import com.oxymel.ofc.charts.series.*;
 
 
public class RadarChart extends Chart
{
private RadarSeriesContainer _radarSeriesContainer;
private Vector _nameOfCategories;
private int _margin=0;
private int _nbMaxGap = 5;
private int _gapSize = 0;
private double _gapValue = 0;
private boolean _drawNet = true;
private boolean _showValues = false;
private boolean _fillArea = false;
 
public RadarChart(int chartWidth,int chartHeight,RadarSeriesContainer radarSeriesContainer,Vector nameOfCategories)
{
super(chartWidth, chartHeight);
setCategoryValueSeriesContainer(radarSeriesContainer);
_nameOfCategories = nameOfCategories;
}
 
public void setDrawNet(boolean b)
{
_drawNet = b;
}
 
public void setShowValues(boolean b)
{
_showValues = b;
}
 
public void setFillArea(boolean b)
{
_fillArea = b;
}
 
public int getLegendWidthMax(Graphics2D graphics2D)
{
int max = 0;
for(int i=0; i<_nameOfCategories.size(); i++)
{
Dimension d = getLegendDimension((String)_nameOfCategories.elementAt(i),graphics2D);
int legendWidth = (int)d.getWidth();
if(legendWidth > max)
max = legendWidth;
}
return max;
}
 
public void setCategoryValueSeriesContainer(RadarSeriesContainer radarSeriesContainer)
{
_radarSeriesContainer = radarSeriesContainer;
setAllSeriesColorFromPalette(radarSeriesContainer);
}
 
 
protected SeriesContainer getSeriesContainer(){return _radarSeriesContainer;}
 
 
protected void doDrawChart(Graphics2D graphics2D) throws OFCChartsException
{
int xTopLeftGraphic = getXTopLeftGraphic(graphics2D);
int yTopLeftGraphic = getYTopLeftGraphic(graphics2D);
int graphicWidth = getGraphicWidth(graphics2D);
int graphicHeight = getGraphicHeight(graphics2D);
 
drawGraphicBackground(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D);
 
_legend.drawLegend(getXTopLeftLegend(graphics2D), getYTopLeftLegend(graphics2D),
getSeriesContainer().getAllSeriesOrderByDisplayNumber(), graphics2D);
 
/*bug à voir plus tard
_legend.drawLegend(
getXTopLeftLegend(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D),
getYTopLeftLegend(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D),
getSeriesContainer().getAllSeriesOrderByDisplayNumber(), graphics2D);
*/
_margin = getLegendWidthMax(graphics2D);
int valMin = Math.min(graphicWidth, graphicHeight);
valMin -=(_margin*2);
 
double max = _radarSeriesContainer.getMaxValueSeries();
_gapValue = (double)(max/_nbMaxGap);
_gapSize = valMin/_nbMaxGap;
 
xTopLeftGraphic+=_margin;
yTopLeftGraphic+=_margin;
 
for(int i=0; i<_nbMaxGap; i++)
{
if(i==0)
drawAxis(xTopLeftGraphic+(i*(_gapSize/2)), yTopLeftGraphic+(i*(_gapSize/2)), valMin-(i*_gapSize), valMin -(i*_gapSize),graphics2D, true, max-(i*_gapValue));
else
drawAxis(xTopLeftGraphic+(i*(_gapSize/2)), yTopLeftGraphic+(i*(_gapSize/2)), valMin-(i*_gapSize), valMin -(i*_gapSize),graphics2D, false, max-(i*_gapValue));
}
// drawAxis(xTopLeftGraphic+_margin, yTopLeftGraphic+_margin, valMin, valMin ,graphics2D,true);
_gapSize = (_gapSize/2);
if(_fillArea)
sortSeries();
drawGraphic(xTopLeftGraphic, yTopLeftGraphic, valMin, valMin, graphics2D);
if(_fillArea)
{
graphics2D.setColor(Color.black.brighter());
boolean drawNetSave = _drawNet;
_drawNet = false;
for(int i=0; i<_nbMaxGap; i++)
{
if(i==0)
drawAxis(xTopLeftGraphic+(i*(_gapSize)), yTopLeftGraphic+(i*(_gapSize)), valMin-(i*_gapSize*2), valMin -(i*_gapSize*2),graphics2D, true, max-(i*_gapValue));
else
drawAxis(xTopLeftGraphic+(i*(_gapSize)), yTopLeftGraphic+(i*(_gapSize)), valMin-(i*_gapSize*2), valMin -(i*_gapSize*2),graphics2D, false, max-(i*_gapValue));
}
_drawNet = drawNetSave;
}
}
 
 
private void sortSeries()
{
//la plus petite devant
int nbSeries = _radarSeriesContainer.getNbSeries();
int [] seriesWeigth = new int[nbSeries];
RadarSeries [] mySeries = new RadarSeries[nbSeries];
for(int j=0; j<nbSeries;j++)
seriesWeigth[j]=0;
Enumeration enum0 = _radarSeriesContainer.getEnumAllSeriesOrderByDisplayNumber();
int i = 0;
int maxValues = 0;
while(enum0.hasMoreElements())
{
mySeries[i] = (RadarSeries)enum0.nextElement();
if(mySeries[i].getNbValues()>maxValues)
maxValues = mySeries[i].getNbValues();
i++;
}
 
for(i=0; i<maxValues;i++)
{
// int idxMax = 0;
for(int k=0;k<mySeries.length;k++)
{
double maxValue = mySeries[k].getValueAt(i);
int poids = mySeries.length;
for(int j=0;j<mySeries.length;j++)
{
if(maxValue < mySeries[j].getValueAt(i))
{
poids--;
}
}
seriesWeigth[k]+=poids;
}
}
for(i=0;i<mySeries.length;i++)System.out.println("Serie "+mySeries[i].getId()+" poids: "+seriesWeigth[i]);
_radarSeriesContainer = new RadarSeriesContainer();
for(i=0; i<mySeries.length;i++)
{
double maxValue = -1;
int idxMax = 0;
for(int j=0;j<mySeries.length;j++)
{
if(maxValue < seriesWeigth[j])
{
maxValue = seriesWeigth[j];
idxMax = j;
}
}
seriesWeigth[idxMax] = -1;
_radarSeriesContainer.addRadarSeries(mySeries[idxMax]);
}
}
 
 
private void drawAxis(int xTopLeftGraphic, int yTopLeftGraphic, int graphicWidth, int graphicHeight,
Graphics2D graphics2D, boolean drawLegend, double maxValOnAxis)
{
int xCenter = xTopLeftGraphic + graphicHeight/2;
int yCenter = yTopLeftGraphic + graphicWidth/2;
int xDest = 0;
int yDest = 0;
 
int nbCategories = _nameOfCategories.size();
int angle = (int)(360/nbCategories);
int startAngle = 90;
int lastX = 0;
int lastY = 0;
int firstX = 0;
int firstY = 0;
 
for(int i=0; i<nbCategories ; i++)
{
Point2D p = getNewPointOfCircle(xCenter,yCenter,graphicWidth,graphicHeight,startAngle,angle,graphics2D);
xDest = (int)p.getX();
yDest = (int)p.getY();
 
int legendHeight = 0;
int legendWidth = 0;
Dimension d = null;
Stroke stroke = graphics2D.getStroke();
// if(startAngle == 90 || startAngle == 180 || startAngle == 270 || startAngle == 360 || startAngle == 0)
if(startAngle != 90 || startAngle != 180 || startAngle != 270 || startAngle != 360 || startAngle != 0)
graphics2D.setStroke(new BasicStroke(0.4f));
graphics2D.drawLine(xCenter,yCenter,xDest,yDest);
graphics2D.setStroke(stroke);
if(lastX!=0 && lastY!=0)
{
if(_drawNet)
graphics2D.drawLine(lastX,lastY,xDest,yDest);
}
else
{
String s = Double.toString(maxValOnAxis);
s=s.substring(0,s.indexOf(".")+2);
d = getLegendDimension(s,graphics2D);
legendHeight = (int)d.getHeight();
legendWidth = (int)d.getWidth();
graphics2D.drawString(s,xDest-legendWidth,yDest-1);
}
lastX = xDest;
lastY = yDest;
if(firstX==0 && firstY==0)
{
firstX = xDest;
firstY = yDest;
}
d = getLegendDimension((String)_nameOfCategories.elementAt(i),graphics2D);
legendHeight = (int)d.getHeight();
legendWidth = (int)d.getWidth();
 
int decalLegendX = 1;
int decalLegendY = 1;
 
if(startAngle > 90 && startAngle<270)
decalLegendX = -1;
else
decalLegendX = 0;
if(startAngle<=180 || startAngle==360)
decalLegendY = 0;
 
if(drawLegend)
{
if(startAngle == 90)
graphics2D.drawString((String)_nameOfCategories.elementAt(i),xDest+(legendWidth*decalLegendX),yDest+(legendHeight*decalLegendY)-10);
else
graphics2D.drawString((String)_nameOfCategories.elementAt(i),xDest+(legendWidth*decalLegendX),yDest+(legendHeight*decalLegendY));
}
 
if((startAngle + angle)>360)
startAngle = angle - (360-startAngle);
else
startAngle += angle;
}
if(_drawNet)
graphics2D.drawLine(firstX,firstY,xDest,yDest);
}
 
 
private Dimension getLegendDimension(String s, Graphics2D graphics2D)
{
FontMetrics fm = graphics2D.getFontMetrics();
int wTmp = fm.stringWidth(s);
int hTmp = fm.getHeight();
Dimension d = new Dimension(wTmp,hTmp);
return d;
}
 
 
private Point2D getNewPointOfCircle(int centreX,int centreY,int graphicWidth,int graphicHeight,int startAngle,int arcAngle,Graphics2D graphics2D)
{
Point2D point = null;
int angleBisec = startAngle;
int rayonX = graphicWidth;
int rayonY = graphicHeight;
int decalX = 1;
int decalY = 1;
System.out.println(">>>"+angleBisec);
 
if(angleBisec < 180)
decalY = -1;
 
if(angleBisec > 90 && angleBisec < 270)
{
decalX = -1;
}
 
int angleBisecTmp = angleBisec; //sauvegarde de l'angle de la bisectrice de la part courante
 
while(angleBisec > 90)
angleBisec -= 90;
 
 
if(angleBisecTmp>270 || (angleBisecTmp>90 && angleBisecTmp<=180))
{
int x = (int)(Math.sin(Math.toRadians((double)angleBisec))*((double)((rayonX)/2))); //il faudra certainement retirer la marge.
int y = (int)(Math.cos(Math.toRadians((double)angleBisec))*((double)((rayonY)/2))); //il faudra certainement retirer la marge.
x = x*decalX;
y = y*decalY;
point = new Point2D(centreX+x, centreY+y);
}
else
{
int x = (int)(Math.sin(Math.toRadians((double)angleBisec))*((double)((rayonY)/2))); //il faudra certainement retirer la marge.
int y = (int)(Math.cos(Math.toRadians((double)angleBisec))*((double)((rayonX)/2)));
x = x*decalY;
y = y*decalX;
point = new Point2D(centreX+y,centreY+x);
}
return point;
}
 
 
private void drawGraphic(int xTopLeftGraphic, int yTopLeftGraphic, int graphicWidth, int graphicHeight,Graphics2D graphics2D)
{
System.out.println("entre dans drawGraphic");
int yCenter = xTopLeftGraphic + (graphicWidth/2);
int xCenter = yTopLeftGraphic + (graphicHeight/2);
int angle = (int)(360/_nameOfCategories.size());
Enumeration enum0 = _radarSeriesContainer.getEnumAllSeriesOrderByDisplayNumber();
while(enum0.hasMoreElements())
{
RadarSeries serie = (RadarSeries)enum0.nextElement();
int angleDepart = 90;
int lastX = 0;
int lastY = 0;
int firstX = 0;
int firstY = 0;
Polygon forme = new Polygon();
Color c = serie.getColor();
for(int i = 0; i<serie.getNbValues();i++)
{
int x=0;
int y=0;
graphics2D.setColor(c);
int angleCourant = angleDepart+(i*angle);
int deplacement = (int)((double)(_gapSize*serie.getValueAt(i))/(_gapValue));
x = xCenter+(int)(Math.cos(Math.toRadians(angleCourant))*(double)deplacement);
y = yCenter-(int)(Math.sin(Math.toRadians(angleCourant))*(double)deplacement);
forme.addPoint(x,y);
if(i==0)
{
graphics2D.drawLine(x,y,x,y);
firstX = x;
firstY = y;
lastX = x;
lastY = y;
}
else
{
//on trace une ligne
graphics2D.drawLine(x,y,lastX,lastY);
lastX = x;
lastY = y;
}
if(_showValues)
{
// graphics2D.setColor(Color.black);
graphics2D.drawString(Double.toString(serie.getValueAt(i)),x,y);
// graphics2D.setColor(c);
}
//System.out.println("serie "+ serie.getNameAt(i) +" valeur:"+serie.getValueAt(i) );
}
graphics2D.drawLine(firstX,firstY,lastX,lastY);
if(_fillArea)
{
graphics2D.setColor(c);
graphics2D.fill(forme);
graphics2D.setColor(Color.black);
graphics2D.drawPolygon(forme);
graphics2D.setColor(c);
}
}
}
 
/*
public static void main(String[] args)
{
}
*/
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/VerticalTimeAxisRight.java
New file
0,0 → 1,99
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
//java
import java.awt.*;
//ofc
import com.oxymel.ofc.charts.util.*;
 
class VerticalTimeAxisRight extends VerticalNumberAxisRight
{
public static final int UNIT_IS_MILLISECONDS = 1;
public static final int UNIT_IS_SECONDS = 1000;
public static final int UNIT_IS_MINUTES = 60000;
public static final int UNIT_IS_HOURS = 3600000;
 
private String _format = "HHhMMminSSs";
private int _typeUnits =UNIT_IS_MILLISECONDS;
 
public VerticalTimeAxisRight(String label)
{
super(label);
}
 
public String getTimeFormat()
{
return _format;
}
 
public int getTimeUnits()
{
return _typeUnits;
}
 
public void setTypeUnits(int unit)
{
_typeUnits = unit;
}
 
public void setFormat(String format)
{
_format = format;
}
 
protected void drawValues(int graphicWidth, int graphicHeight, int xTopLeftGraphic, int yTopLeftGraphic,
int xOrigine, int yOrigine, Graphics2D graphics2D)
{
int xAxisRight = xTopLeftGraphic + graphicWidth;
int nbGapOnY = getNbGap();
int sizeOfGapOnY = graphicHeight / nbGapOnY;
int yOfGap = yTopLeftGraphic + graphicHeight;
graphics2D.setColor(getValueWriteColor());
int gapValueOnY = getGapValue();
int currentGap = 0;
if(isContainsNegativeValue()){
currentGap = getNbNegativeGapToIncludeMinValue() * gapValueOnY * (-1);
}
for(int i=0; i<nbGapOnY + 1; i++){
String szCurrentGap = ""+currentGap;
if(getSuffixAllValues() != null){
szCurrentGap += getSuffixAllValues();
}
//>>>>
szCurrentGap = getFormattedString(szCurrentGap);
//<<<<
graphics2D.drawString(szCurrentGap, xAxisRight + _nbPixelOfGapIndicator +
_nbPixelBetweenValueAndGapIndicator,
Graphics2DTools.getYToAlignTxt(graphics2D, yOfGap, szCurrentGap));
currentGap += gapValueOnY;
yOfGap -= sizeOfGapOnY;
}
}
 
public String getFormattedString(String date)
{
return DateUtilities.getFormattedDate(_format, _typeUnits, date);
}
 
//vertical axis interface
protected String getLargerStringValue()
{
double negativeValue = 0;
if(getNbNegativeGapToIncludeMinValue() > 0){
negativeValue = getNbNegativeGapToIncludeMinValue() * getGapValue() * (-1);
}
double positiveValue = getNbGap() * getGapValue();
 
String strNegativeValue = getFormattedString("" + (int)negativeValue);
String strPositiveValue = getFormattedString("" + (int)positiveValue);
return (strPositiveValue.length() > strNegativeValue.length())? strPositiveValue : strNegativeValue;
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/ColoredVerticalNumberAxis.java
New file
0,0 → 1,141
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.Graphics2D;
import java.awt.Font;
import java.awt.Color;
import java.awt.Stroke;
import java.awt.BasicStroke;
import java.util.Enumeration;
 
//ofc
import com.oxymel.ofc.charts.util.Graphics2DTools;
import com.oxymel.ofc.charts.series.RangeValueSeriesContainer;
import com.oxymel.ofc.charts.series.Series;
import com.oxymel.ofc.charts.series.RangeValueSeries;
 
 
/**
* This class provides a vertical number axis which could be colored by range value
*/
class ColoredVerticalNumberAxis extends VerticalNumberAxis
{
private int _nbColoredPixelArroundAxis = 0;
private RangeValueSeriesContainer _rangeValueSeriesContainer;
 
/**
* Constructor
* @param label Axis Label
* @param rangeValueSeriesContainer
*/
public ColoredVerticalNumberAxis(String label, RangeValueSeriesContainer rangeValueSeriesContainer)
{
super(label);
_rangeValueSeriesContainer = rangeValueSeriesContainer;
}
 
ColoredVerticalNumberAxis(String label)
{
super(label);
}
 
void setNbColoredPixelArroundAxis(int nbColoredPixelArroundAxis){_nbColoredPixelArroundAxis = nbColoredPixelArroundAxis;}
void setRangeValueSeriesContainer(RangeValueSeriesContainer rangeValueSeriesContainer){_rangeValueSeriesContainer = rangeValueSeriesContainer;}
 
void draw(int graphicWidth, int graphicHeight, int xTopLeftGraphic, int yTopLeftGraphic,
int xOrigine, int yOrigine, Graphics2D graphics2D)
{
/*
double predecessorValue = 0;
int yCurrent = yOrigine;
int xTopLeft = xTopLeftGraphic - getNbPixelUsedAtLeft(graphics2D) - getNbPixelUsedAtRight(graphics2D);
int width = getNbPixelUsedAtLeft(graphics2D) + getNbPixelUsedAtRight(graphics2D);
Enumeration enumAllSeries = _rangeValueSeriesContainer.getEnumAllSeriesOrderByDisplayNumber();
while(enumAllSeries.hasMoreElements()){
RangeValueSeries valueSeries = (RangeValueSeries)enumAllSeries.nextElement();
double currentValue = valueSeries.getMax();
if(currentValue > predecessorValue){
int relativeSizeOfValue = Graphics2DTools.getRelativeSizeOfValue(currentValue - predecessorValue, getGapValue(), getSizeOfGap());
drawBar(xTopLeft, yCurrent, width, relativeSizeOfValue, valueSeries, graphics2D);
yCurrent -= relativeSizeOfValue;
predecessorValue = currentValue;
}
}
*/
 
double lastValueOnAxis = getLastValueOnAxis();
double firstValueOnAxis = getFirstValueOnAxis();
double predecessorValue = 0;
int yCurrent = yOrigine;
int xTopLeft = xTopLeftGraphic - getNbPixelUsedAtLeft(graphics2D) - getNbPixelUsedAtRight(graphics2D);
int width = getNbPixelUsedAtLeft(graphics2D) + getNbPixelUsedAtRight(graphics2D);
Enumeration enumAllSeries = _rangeValueSeriesContainer.getEnumAllSeriesOrderByDisplayNumber();
while(enumAllSeries.hasMoreElements()){
RangeValueSeries rangeValueSeries = (RangeValueSeries)enumAllSeries.nextElement();
double minInterval = rangeValueSeries.getMin();
if(minInterval < firstValueOnAxis){
minInterval = firstValueOnAxis;
}
 
double maxInterval = rangeValueSeries.getMax();
if(maxInterval > lastValueOnAxis){
maxInterval = lastValueOnAxis;
}
 
if((minInterval <0) && (maxInterval <0)){
yCurrent = yOrigine + ((-1)*Graphics2DTools.getRelativeSizeOfValue(maxInterval, getGapValue(), getSizeOfGap()));
int relativeSizeOfValue = Graphics2DTools.getRelativeSizeOfValue(minInterval - maxInterval, getGapValue(), getSizeOfGap());
drawBar(xTopLeft, yCurrent, width, relativeSizeOfValue, rangeValueSeries, graphics2D);
}
else{
if((minInterval >=0) && (maxInterval >=0)){
yCurrent = yOrigine - Graphics2DTools.getRelativeSizeOfValue(minInterval, getGapValue(), getSizeOfGap());
int relativeSizeOfValue = Graphics2DTools.getRelativeSizeOfValue(maxInterval - minInterval, getGapValue(), getSizeOfGap());
drawBar(xTopLeft, yCurrent, width, relativeSizeOfValue, rangeValueSeries, graphics2D);
}
else{
yCurrent = yOrigine;
int relativeSizeOfValue = Graphics2DTools.getRelativeSizeOfValue(minInterval, getGapValue(), getSizeOfGap());
drawBar(xTopLeft, yCurrent, width, relativeSizeOfValue, rangeValueSeries, graphics2D);
relativeSizeOfValue = Graphics2DTools.getRelativeSizeOfValue(maxInterval, getGapValue(), getSizeOfGap());
drawBar(xTopLeft, yCurrent, width, relativeSizeOfValue, rangeValueSeries, graphics2D);
}
}
}
 
super.draw(graphicWidth, graphicHeight, xTopLeftGraphic - getNbPixelUsedAtRight(graphics2D), yTopLeftGraphic,
xOrigine - getNbPixelUsedAtRight(graphics2D), yOrigine, graphics2D);
}
 
private void drawBar(int xBarTopLeft, int yOrigine, int widthOfBarHisto, int relativeSizeOfValue, Series series,
Graphics2D graphics2D)
{
int yBarTopLeft = (relativeSizeOfValue < 0)? yOrigine : yOrigine - relativeSizeOfValue;
int heightOfBarHisto = (relativeSizeOfValue < 0)? (relativeSizeOfValue*(-1)) : relativeSizeOfValue;
 
graphics2D.setColor(series.getColor());
graphics2D.fillRect(xBarTopLeft, yBarTopLeft, widthOfBarHisto, heightOfBarHisto);
//graphics2D.setColor(Color.black);
//graphics2D.drawRect(xBarTopLeft, yBarTopLeft, widthOfBarHisto, heightOfBarHisto);
}
 
int getNbPixelUsedAtLeft(Graphics2D graphics2D)
{
return super.getNbPixelUsedAtLeft(graphics2D) + 5;
}
 
int getNbPixelUsedAtRight(Graphics2D graphics2D)
{
return super.getNbPixelUsedAtRight(graphics2D) + _nbPixelOfGapIndicator + 5;
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/Contour2D.java
New file
0,0 → 1,383
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.util.Vector;
import java.util.Enumeration;
 
import java.awt.geom.GeneralPath;
import java.awt.Graphics2D;
import java.awt.Color;
 
//ofc
import com.oxymel.ofc.charts.series.CategoryValueSeries;
import com.oxymel.ofc.charts.exception.OFCChartsException;
import com.oxymel.ofc.charts.util.Graphics2DTools;
import com.oxymel.ofc.charts.series.CategoryValueSeriesContainer;
import com.oxymel.ofc.charts.series.SeriesContainer;
 
import com.oxymel.ofc.charts.data.grid.Grid;
import com.oxymel.ofc.charts.data.Point2D;
import com.oxymel.ofc.charts.geographic.Isoline;
import com.oxymel.ofc.charts.geographic.Graph;
import com.oxymel.ofc.charts.geographic.Arc;
import com.oxymel.ofc.charts.geographic.Vertex;
import com.oxymel.ofc.charts.geographic.Face;
 
 
/**
* This class allows to manage 2D Contour graphics.
* It generates isolines from a grid and fill the areas delimited by these isolines with colors according to the defined ColorPalette.
*
*/
public class Contour2D extends ChartWithAxisXY
{
private VerticalNumberAxis _axisY;
private HorizontalNumberAxis _axisX;
private Grid _grid;
 
private Graph _isolineGraph;
private Isoline _isoline;
 
private Vector _allHorizontalLineInfo = new Vector();
/**
* Constructor
* @param chartWidth Chart width
* @param chartHeight Chart height
* @param axisX horizontal graduated axis
* @param axisY vertical graduated axis
* @param grid input data used to compute the isolines
* @param zStart isoline start value
* @param zEnd isoline end value
* @param zStep isoline step value
*/
public Contour2D(int chartWidth, int chartHeight,
HorizontalNumberAxis axisX, VerticalNumberAxis axisY,
Grid grid, double zStart, double zEnd, double zStep)
{
super(chartWidth, chartHeight);
_axisX = axisX;
_axisY = axisY;
_grid = grid;
_isoline = new Isoline(_grid, zStart, zEnd, zStep);
 
//default parameters
ColorPalette colorPalette = new ColorPalette();
colorPalette.initPaletteHotToColdFromData(getNumberOfData(zStart, zEnd, zStep));
this.setColorPalette(colorPalette);
setInternalGridVisible(false);
 
_legend = new LegendInterval(zStart, zEnd, zStep, colorPalette, chartHeight);
 
//_isolineGraph = _isoline.getGraph();
_isolineGraph = _isoline.getClosedGraph();
}
 
/**
* Sets color Palette.
* This Palette replaces the default one.
* @param colorPalette Palette of colors to be set
*/
public void setColorPalette(ColorPalette colorPalette)
{
super.setColorPalette(colorPalette);
if(_legend instanceof LegendInterval){
((LegendInterval)_legend).setColorPalette(colorPalette);
}
}
 
/**
* Calcul du nb de données
* @param min double
* @param max double
* @param step double
* @return int
*/
private int getNumberOfData(double min,
double max,
double step)
{
double minIntervalValue = Math.min(min, max);
double maxIntervalValue = Math.max(min, max);
step = Math.abs(step);
 
Vector _allInterval = new Vector();
int nb = 1;
 
_allInterval.addElement(nb+"");
 
double currentMinIntervalValue = minIntervalValue;
while(currentMinIntervalValue < maxIntervalValue){
nb++;
double currentMaxIntervalValue = currentMinIntervalValue + step;
if(currentMaxIntervalValue > maxIntervalValue){
currentMaxIntervalValue = maxIntervalValue;
}
 
_allInterval.addElement(nb+"");
currentMinIntervalValue = currentMaxIntervalValue;
 
}
nb++;
_allInterval.addElement(nb+"");
 
return _allInterval.size();
 
}
protected Axis getAxisX(){return _axisX;}
protected Axis getAxisY(){return _axisY;}
 
protected void setAxisParameters() throws OFCChartsException
{
_axisX.setMaxValue(_grid.getXMax());
_axisX.setMinValue(_grid.getXMin());
_axisY.setMaxValue(_grid.getYMax());
_axisY.setMinValue(_grid.getYMin());
}
 
//tmp:
protected SeriesContainer getSeriesContainer()
{
CategoryValueSeriesContainer tmp = new CategoryValueSeriesContainer();
tmp.addCategoryValueSeries(new CategoryValueSeries("s1", "toto"));
return tmp;
}
 
protected void drawGraphic(int xTopLeftGraphic, int yTopLeftGraphic, int graphicWidth, int graphicHeight,
int xOrigine, int yOrigine, Graphics2D graphics2D)
{
int sizeOfGapOnY = graphicHeight / _axisY.getNbGap();
int sizeOfGapOnX = graphicWidth / _axisX.getNbGap();
int gapValueOnX = _axisX.getGapValue();
int gapValueOnY = _axisY.getGapValue();
 
//graphics2D.setColor(_colorPalette.getColor(0));
//graphics2D.fillRect(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight);
 
 
//Enumeration enumAllFace = _isoline.getEnumAllFace();
//* correct
Enumeration enumAllFace = _isoline.getEnumAllFaceOrderByDisplayPosition();
int nbFace = 0;
while(enumAllFace.hasMoreElements()){
nbFace ++;
Face face = (Face)enumAllFace.nextElement();
if(face.isIntervalValueDefined()){
GeneralPath facePath = new GeneralPath();
Enumeration enumAllArc = face.getEnumAllArc();
Vertex lastVertex = null;
if(enumAllArc.hasMoreElements()){
Arc arc = (Arc)enumAllArc.nextElement();
if(face.isArcFirstInGoodDirection()){
getArcGeneralPath(arc, sizeOfGapOnY, sizeOfGapOnX,
gapValueOnX, gapValueOnY, xOrigine, yOrigine, facePath, true);
lastVertex = arc.getFinalVertex();
}else{
getArcReverseGeneralPath(arc, sizeOfGapOnY, sizeOfGapOnX,
gapValueOnX, gapValueOnY, xOrigine, yOrigine, facePath, true);
lastVertex = arc.getInitialVertex();
}
}
while(enumAllArc.hasMoreElements()){
Arc arc = (Arc)enumAllArc.nextElement();
if(arc.getInitialVertex().equals(lastVertex)){
getArcGeneralPath(arc, sizeOfGapOnY, sizeOfGapOnX,
gapValueOnX, gapValueOnY, xOrigine, yOrigine, facePath, false);
lastVertex = arc.getFinalVertex();
}else{
getArcReverseGeneralPath(arc, sizeOfGapOnY, sizeOfGapOnX,
gapValueOnX, gapValueOnY, xOrigine, yOrigine, facePath, false);
lastVertex = arc.getInitialVertex();
}
}
 
facePath.closePath();
//graphics2D.setColor(Color.black);
//graphics2D.draw(facePath);
LegendInterval legend = (LegendInterval)_legend;
graphics2D.setColor(legend.getColor(face.getMinValue(), face.getMaxValue()));
graphics2D.fill(facePath);
 
Enumeration enumAllHorizontalLineInfo = _allHorizontalLineInfo.elements();
while(enumAllHorizontalLineInfo.hasMoreElements()){
HorizontalLineInfo horizontalLineInfo = (HorizontalLineInfo)enumAllHorizontalLineInfo.nextElement();
horizontalLineInfo.draw(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
}
 
}
}
 
//end coirrect*/
 
/*
enumAllFace = _isoline.getEnumAllFaceOrderByDisplayPosition();
nbFace = 0;
while(enumAllFace.hasMoreElements()){
nbFace ++;
Face face = (Face)enumAllFace.nextElement();
Enumeration enumAllArc = face.getEnumAllArc();
Arc arcPred = null;
if(enumAllArc.hasMoreElements()){
arcPred = (Arc)enumAllArc.nextElement();
drawArc(arcPred, sizeOfGapOnY, sizeOfGapOnX,
gapValueOnX, gapValueOnY, xOrigine, yOrigine, graphics2D);
}
while(enumAllArc.hasMoreElements()){
Arc arc = (Arc)enumAllArc.nextElement();
if(arc.isSameDirectionAsArcPredecessor(arcPred)){
drawArc(arc, sizeOfGapOnY, sizeOfGapOnX,
gapValueOnX, gapValueOnY, xOrigine, yOrigine, graphics2D);
}else{
drawArcReverse(arc, sizeOfGapOnY, sizeOfGapOnX,
gapValueOnX, gapValueOnY, xOrigine, yOrigine, graphics2D);
}
arcPred = arc;
}
 
}
System.out.println("Nb face = " + nbFace);
*/
 
/*
int nbArc = 0;
Enumeration enumAllArc = _isolineGraph.getEnumAllArc();
while(enumAllArc.hasMoreElements()){
nbArc ++;
Arc arc = (Arc)enumAllArc.nextElement();
System.out.println("arc" + nbArc + " = " + arc.toString());
drawArc(arc, sizeOfGapOnY, sizeOfGapOnX,
gapValueOnX, gapValueOnY, xOrigine, yOrigine, graphics2D);
}
System.out.println("nbArc = " + nbArc);
*/
}
 
private void drawArc(Arc arc, int sizeOfGapOnY, int sizeOfGapOnX,
int gapValueOnX, int gapValueOnY, int xOrigine, int yOrigine,
Graphics2D graphics2D)
{
GeneralPath generalPath = getArcGeneralPath(arc, sizeOfGapOnY, sizeOfGapOnX,
gapValueOnX, gapValueOnY, xOrigine, yOrigine);
graphics2D.setColor(Color.black);
graphics2D.draw(generalPath);
}
 
private GeneralPath getArcGeneralPath(Arc arc, int sizeOfGapOnY, int sizeOfGapOnX,
int gapValueOnX, int gapValueOnY, int xOrigine, int yOrigine)
{
GeneralPath generalPath = new GeneralPath();
getArcGeneralPath(arc, sizeOfGapOnY, sizeOfGapOnX,
gapValueOnX, gapValueOnY, xOrigine, yOrigine, generalPath, true);
return generalPath;
}
 
private void getArcGeneralPath(Arc arc, int sizeOfGapOnY, int sizeOfGapOnX,
int gapValueOnX, int gapValueOnY, int xOrigine, int yOrigine,
GeneralPath generalPath, boolean isFirstArcInPath)
{
//System.out.println("***** getArcGeneralPath = " + arc.toString());
 
Vertex initialVertex = arc.getInitialVertex();
//System.out.println("** Arc initialVertex = " + initialVertex.toString());
if(isFirstArcInPath){
generalPath.moveTo(
getXRelative(initialVertex.getX(), gapValueOnX, sizeOfGapOnX, xOrigine),
getYRelative(initialVertex.getY(), gapValueOnY, sizeOfGapOnY, yOrigine));
}
Enumeration enumAllIntermediaryPoint = arc.getEnumAllIntermediaryPoint();
while(enumAllIntermediaryPoint.hasMoreElements()){
Point2D intermediaryPoint = (Point2D)enumAllIntermediaryPoint.nextElement();
//System.out.println("Arc intermediaryPoint = " + intermediaryPoint.toString());
generalPath.lineTo(
getXRelative(intermediaryPoint.getX(), gapValueOnX, sizeOfGapOnX, xOrigine),
getYRelative(intermediaryPoint.getY(), gapValueOnY, sizeOfGapOnY, yOrigine));
}
Vertex finalVertex = arc.getFinalVertex();
//System.out.println("** Arc finalVertex = " + finalVertex.toString());
generalPath.lineTo(
getXRelative(finalVertex.getX(), gapValueOnX, sizeOfGapOnX, xOrigine),
getYRelative(finalVertex.getY(), gapValueOnY, sizeOfGapOnY, yOrigine));
}
 
private void drawArcReverse(Arc arc, int sizeOfGapOnY, int sizeOfGapOnX,
int gapValueOnX, int gapValueOnY, int xOrigine, int yOrigine,
Graphics2D graphics2D)
{
GeneralPath generalPath = getArcReverseGeneralPath(arc, sizeOfGapOnY, sizeOfGapOnX,
gapValueOnX, gapValueOnY, xOrigine, yOrigine);
graphics2D.setColor(Color.black);
graphics2D.draw(generalPath);
}
 
private GeneralPath getArcReverseGeneralPath(Arc arc, int sizeOfGapOnY, int sizeOfGapOnX,
int gapValueOnX, int gapValueOnY, int xOrigine, int yOrigine)
{
GeneralPath generalPath = new GeneralPath();
getArcReverseGeneralPath(arc, sizeOfGapOnY, sizeOfGapOnX,
gapValueOnX, gapValueOnY, xOrigine, yOrigine, generalPath, true);
return generalPath;
}
 
private void getArcReverseGeneralPath(Arc arc, int sizeOfGapOnY, int sizeOfGapOnX,
int gapValueOnX, int gapValueOnY, int xOrigine, int yOrigine, GeneralPath generalPath, boolean isFirstArcInPath)
{
//System.out.println("***** getArcReverseGeneralPath = " + arc.toString());
 
Vertex initialVertex = arc.getFinalVertex();
//System.out.println("** Reverse Arc initialVertex = " + initialVertex.toString());
if(isFirstArcInPath){
generalPath.moveTo(
getXRelative(initialVertex.getX(), gapValueOnX, sizeOfGapOnX, xOrigine),
getYRelative(initialVertex.getY(), gapValueOnY, sizeOfGapOnY, yOrigine));
}
Vector allIntermediaryPoint = arc.getAllIntermediaryPoint();
for(int i=allIntermediaryPoint.size() - 1; i>=0; i--){
Point2D intermediaryPoint = (Point2D)allIntermediaryPoint.elementAt(i);
//System.out.println("Reverse Arc intermediaryPoint = " + intermediaryPoint.toString());
generalPath.lineTo(
getXRelative(intermediaryPoint.getX(), gapValueOnX, sizeOfGapOnX, xOrigine),
getYRelative(intermediaryPoint.getY(), gapValueOnY, sizeOfGapOnY, yOrigine));
}
Vertex finalVertex = arc.getInitialVertex();
//System.out.println("** Reverse Arc finalVertex = " + finalVertex.toString());
generalPath.lineTo(
getXRelative(finalVertex.getX(), gapValueOnX, sizeOfGapOnX, xOrigine),
getYRelative(finalVertex.getY(), gapValueOnY, sizeOfGapOnY, yOrigine));
}
 
 
private int getXRelative(double x, int gapValueOnX, int sizeOfGapOnX, int xOrigine)
{
return xOrigine + Graphics2DTools.getRelativeSizeOfValue(x, gapValueOnX, sizeOfGapOnX);
}
 
private int getYRelative(double y, int gapValueOnY, int sizeOfGapOnY, int yOrigine)
{
return yOrigine - Graphics2DTools.getRelativeSizeOfValue(y, gapValueOnY, sizeOfGapOnY);
}
 
/**
* Adds an horizontal line info to the graphic
* @param horizontalLineInfo An horizontal line info
*/
public void addHorizontalLineInfo(HorizontalLineInfo horizontalLineInfo)
{
horizontalLineInfo.setVerticalNumberAxis(_axisY);
_allHorizontalLineInfo.addElement(horizontalLineInfo);
}
 
/*
public static void main(String[] argv) throws Exception
{
}
*/
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/VerticalBarChart.java
New file
0,0 → 1,393
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.*;
//batik
import org.apache.batik.svggen.*;
//ofc
import com.oxymel.ofc.charts.animation.*;
import com.oxymel.ofc.charts.exception.*;
import com.oxymel.ofc.charts.series.*;
 
 
/**
* This class manages vertical bar charts, it has subclasses allowing to customize the representation of the bar charts.
*/
public class VerticalBarChart extends BarChart
{
protected VerticalNumberAxis _axisY;
protected HorizontalCategoryAxis _axisX;
 
private VerticalBarChartRenderer _renderer;
 
/**
* Constructor
* @param chartWidth Width of vertical bar chart
* @param chartHeight Height of vertical bar chart
* @param axisX Horizontal axis to display categories
* @param axisY Vertical number axis
* @param categoryValueSeriesContainer All series of couple category-value
*/
public VerticalBarChart(int chartWidth, int chartHeight,
HorizontalCategoryAxis axisX, VerticalNumberAxis axisY,
CategoryValueSeriesContainer categoryValueSeriesContainer)
{
super(chartWidth, chartHeight, categoryValueSeriesContainer);
_axisX = axisX;
_axisY = axisY;
_renderer = new VerticalBarChartRenderer(categoryValueSeriesContainer);
_renderer.setPercentageBetweenEachBarHisto(0);
_renderer.setPercentageFreeBeforeSeries(5);
_renderer.setPercentageFreeAfterSeries(5);
}
 
//tmp à mettre sur la classe de base
/*
public void setCategoryValueSeriesContainer(CategoryValueSeriesContainer categoryValueSeriesContainer)
{
_categoryValueSeriesContainer = categoryValueSeriesContainer;
setAllSeriesColorFromPalette(categoryValueSeriesContainer);
_renderer.setCategoryValueSeriesContainer(categoryValueSeriesContainer);
}
*/
 
/**
* Provides a backward circular translation of data.
* After the operation the first data series becomes the last one, and the
* second one becomes the first and so on. This feature may be used when
* managing animated graphics for instance.
*/
public void moveDataBackCircular()
{
_categoryValueSeriesContainer.moveDataBackCircular();
}
 
/**
* Replaces the first data series by the one given as argument and then
* provides a backward circular translation of data series.
* After the operation the first data series does not exist anymore and
* the other series are translated from their original position to the previous
* one. The new last series is the one given as parameter.
* @param newValueAddAtEnd the new last data series in the container.
*/
public void moveDataBack(double newValueAddAtEnd)
{
_categoryValueSeriesContainer.moveDataBack(newValueAddAtEnd);
}
 
 
/**
* Provides a forward circular translation of data.
* After the operation the first data series becomes the second one,.., and the
* last one becomes the first and so on. This feature may be used when
* managing animated graphics for instance.
*/
 
public void moveDataForwardCircular()
{
_categoryValueSeriesContainer.moveDataForwardCircular();
}
 
/**
* Move data forward. All data are moved. The end is removed. The first value became the second value etc..
* The new data is the new first value
*/
/**
* Replaces the last data series by the one given as argument and then
* provides a forward circular translation of data series.
* After the operation the last data series does not exist anymore and
* the other series are translated from their original position to the next
* one. The new first series is the one given as parameter.
* @param newValueAddAtStart the new first data series in the container.
*/
public void moveDataForward(double newValueAddAtStart)
{
_categoryValueSeriesContainer.moveDataForward(newValueAddAtStart);
}
 
/**
* Sets the legend display mode. The legend may look like a table.
* @param legendDisplayMode The legend display mode to be set.
* @see Legend
*/
public void setLegendDisplayMode(int legendDisplayMode)
{
if((_legend.getLegendDisplayMode() == Legend.LEGEND_DISPLAY_MODE_TABLE) &&
(legendDisplayMode != Legend.LEGEND_DISPLAY_MODE_TABLE)){
_legend = new Legend();
}
 
if(legendDisplayMode == Legend.LEGEND_DISPLAY_MODE_TABLE){
_legend = new LegendTable(_renderer.getCategoryValueSeriesContainer());
return;
}
super.setLegendDisplayMode(legendDisplayMode);
}
 
protected VerticalBarChartRenderer getChartRenderer(){return _renderer;};
 
protected void setAxisXDrawingInfo()
{
_axisX.setNbPixelDecalYToStartWriteValues(
_axisY.getNbNegativeGapToIncludeMinValue() * _axisY.getSizeOfGap());
}
 
protected BarChartRenderer getBarChartRenderer(){return _renderer;}
 
protected Axis getAxisX(){return _axisX;}
protected Axis getAxisY(){return _axisY;}
 
protected void setAxisParameters() throws OFCChartsException
{
_axisX.setAllCategoriesOrderByDisplayNumber(_categoryValueSeriesContainer.getAllCategoriesOrderByDisplayNumber());
_axisY.setMaxValue(_categoryValueSeriesContainer.getMaxValueOfAllSeries());
_axisY.setMinValue(_categoryValueSeriesContainer.getMinValueOfAllSeries());
 
}
 
protected void drawGraphic(int xTopLeftGraphic, int yTopLeftGraphic, int graphicWidth, int graphicHeight,
int xOrigine, int yOrigine, Graphics2D graphics2D)
{
//rapide integration en force a changer
if(_legend instanceof LegendTable){
((LegendTable)_legend).setNbPixelColumnWidth(_axisX.getSizeOfGap());
((LegendTable)_legend).setXOrigine(xOrigine);
((LegendTable)_legend).setYOrigine(yOrigine);
}
//fin rapide integration
 
//VerticalBarChartRenderer renderer = new VerticalBarChartRenderer(getCategoryValueSeriesContainer());
VerticalBarChartRenderer renderer = _renderer;
renderer.setNbGapOnX(_axisX.getNbGap());
renderer.setNbGapOnY(_axisY.getNbGap());
renderer.setGapValueOnY(_axisY.getGapValue());
//BEGIN_BLOCKER_CHART_3D
renderer.set3dEffectValue(get3dEffectValue());
//END_BLOCKER_CHART_3D
renderer.drawGraphic(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight,
xOrigine, yOrigine, graphics2D);
}
 
 
protected void drawAnimateGraphic(int xTopLeftGraphic, int yTopLeftGraphic, int graphicWidth, int graphicHeight,
int xOrigine, int yOrigine, SVGGraphics2D graphics2D, SVGAnimationContext svgAnimationContext)
{
if(svgAnimationContext.isExternalAnimation()){
drawGraphic(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight,
xOrigine, yOrigine, graphics2D);
return;
}
 
//rapide integration en force (sale) a changer
if(_legend instanceof LegendTable){
((LegendTable)_legend).setNbPixelColumnWidth(_axisX.getSizeOfGap());
((LegendTable)_legend).setXOrigine(xOrigine);
((LegendTable)_legend).setYOrigine(yOrigine);
}
//fin rapide integration
 
//VerticalBarChartRenderer renderer = new VerticalBarChartRenderer(getCategoryValueSeriesContainer());
VerticalBarChartRenderer renderer = getChartRenderer();
renderer.setNbGapOnX(_axisX.getNbGap());
renderer.setNbGapOnY(_axisY.getNbGap());
renderer.setGapValueOnY(_axisY.getGapValue());
//BEGIN_BLOCKER_CHART_3D
renderer.set3dEffectValue(get3dEffectValue());
//END_BLOCKER_CHART_3D
//renderer.drawGraphic(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight,
// xOrigine, yOrigine, graphics2D);
 
 
drawAnimateCircularGraphic(renderer,
xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight,
xOrigine, yOrigine, graphics2D, svgAnimationContext);
 
}
 
private void drawAnimateCircularGraphic(VerticalBarChartRenderer renderer,
int xTopLeftGraphic, int yTopLeftGraphic, int graphicWidth, int graphicHeight,
int xOrigine, int yOrigine, SVGGraphics2D graphics2D, SVGAnimationContext svgAnimationContext)
{
new SVGGraphics2DAnimateMgr().generateAnimation((SVGGraphics2D)graphics2D, svgAnimationContext,
new CircularAnimation( renderer,
xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight,
xOrigine, yOrigine));
}
 
private class CircularAnimation implements AnimationInterface
{
private VerticalBarChartRenderer _renderer;
private int _xTopLeftGraphic;
private int _yTopLeftGraphic;
private int _graphicWidth;
private int _graphicHeight;
private int _xOrigine;
private int _yOrigine;
 
//
int _currentImage = 0;
int _nbImage;
 
public CircularAnimation(VerticalBarChartRenderer renderer,
int xTopLeftGraphic, int yTopLeftGraphic, int graphicWidth, int graphicHeight,
int xOrigine, int yOrigine)
{
//
_renderer = renderer;
_xTopLeftGraphic = xTopLeftGraphic;
_yTopLeftGraphic = yTopLeftGraphic;
_graphicWidth = graphicWidth;
_graphicHeight = graphicHeight;
_xOrigine = xOrigine;
_yOrigine = yOrigine;
 
//
_nbImage = _renderer.getCategoryValueSeriesContainer().getNbCategories() + 1;
}
 
public boolean hasNextImage()
{
return (_currentImage < _nbImage);
}
 
public void drawImage(SVGGraphics2D graphics2D)
{
_renderer.drawGraphic(_xTopLeftGraphic, _yTopLeftGraphic, _graphicWidth, _graphicHeight,
_xOrigine, _yOrigine, graphics2D);
_currentImage++;
if(hasNextImage()){
_categoryValueSeriesContainer.moveDataBackCircular();
/*
Vector allCategories = _categoryValueSeriesContainer.getAllCategoriesOrderByDisplayNumber();
Enumeration enumAllSeries = _categoryValueSeriesContainer.getEnumAllSeriesOrderByDisplayNumber();
while(enumAllSeries.hasMoreElements()){
CategoryValueSeries categoryValueSeries = (CategoryValueSeries)enumAllSeries.nextElement();
Category category = (Category)allCategories.elementAt(0);
CategoryValue categoryValue = categoryValueSeries.getCategoryValue(category.getId());
double firstValue = categoryValue.getValue();
 
for(int i= 1; i<allCategories.size(); i++){
category = (Category)allCategories.elementAt(i);
CategoryValue categoryValueToMove = categoryValueSeries.getCategoryValue(category.getId());
categoryValue.setValue(categoryValueToMove.getValue());
categoryValue = categoryValueToMove;
}
categoryValue.setValue(firstValue);
}
*/
}
}
}
 
 
 
 
/*
protected void drawGraphic(int xTopLeftGraphic, int yTopLeftGraphic, int graphicWidth, int graphicHeight,
int xOrigine, int yOrigine, Graphics2D graphics2D)
{
int sizeOfGapOnY = graphicHeight / _axisY.getNbGap();
int sizeOfGapOnX = graphicWidth / _axisX.getNbGap();
 
//draw bar histo
int widthOfBarHisto = sizeOfGapOnX - _nbPixelFreeBeforeSeries - _nbPixelFreeAfterSeries;
int nbSeries = _categoryValueSeriesContainer.getNbSeries();
if(nbSeries > 0){
widthOfBarHisto -= ((_categoryValueSeriesContainer.getNbSeries() - 1) * _nbPixelBetweenEachBarHisto);
widthOfBarHisto = widthOfBarHisto / nbSeries;
}
 
Vector allCategories = _categoryValueSeriesContainer.getAllCategoriesOrderByDisplayNumber();
 
for(int i= 0; i<allCategories.size(); i++){
Category category = (Category)allCategories.elementAt(i);
int xBarTopLeft = xOrigine + (sizeOfGapOnX * i) + _nbPixelFreeBeforeSeries;
 
Enumeration enumAllSeries = _categoryValueSeriesContainer.getEnumAllSeriesOrderByDisplayNumber();
while(enumAllSeries.hasMoreElements()){
CategoryValueSeries categoryValueSeries = (CategoryValueSeries)enumAllSeries.nextElement();
if(categoryValueSeries.isVisible()){
double value = categoryValueSeries.getCategoryValueAsDouble(category.getId());
if(value != 0){
 
drawBar(xBarTopLeft, yOrigine, widthOfBarHisto,
Graphics2DTools.getRelativeSizeOfValue(value, _axisY.getGapValue(), sizeOfGapOnY),
categoryValueSeries, graphics2D);
}
}
xBarTopLeft += widthOfBarHisto + _nbPixelBetweenEachBarHisto;
}
//xOfGap += _nbPixelFreeAfterSeries;
}
}
*/
 
/*
protected void drawBar(int xBarTopLeft, int yOrigine, int widthOfBarHisto, int relativeSizeOfValue, CategoryValueSeries series,
Graphics2D graphics2D)
{
int yBarTopLeft = (relativeSizeOfValue < 0)? yOrigine : yOrigine - relativeSizeOfValue;
int heightOfBarHisto = (relativeSizeOfValue < 0)? (relativeSizeOfValue*(-1)) : relativeSizeOfValue;
 
graphics2D.setColor(series.getColor());
graphics2D.fillRect(xBarTopLeft, yBarTopLeft, widthOfBarHisto, heightOfBarHisto);
graphics2D.setColor(Color.black);
graphics2D.drawRect(xBarTopLeft, yBarTopLeft, widthOfBarHisto, heightOfBarHisto);
//graphics2D.draw3DRect(xBarTopLeft, yBarTopLeft, widthOfBarHisto, heightOfBarHisto, false);
 
//BEGIN_BLOCKER_CHART_3D
if(get3dEffectValue() != 0){
set3DEffect(xBarTopLeft, yBarTopLeft, widthOfBarHisto, heightOfBarHisto, get3dEffectValue(), series, graphics2D);
}
//END_BLOCKER_CHART_3D
}
*/
 
/*
//BEGIN_BLOCKER_CHART_3D
private void set3DEffect(int xBarTopLeft, int yBarTopLeft, int widthOfBarHisto, int heightOfBarHisto, int effect3dValue,
CategoryValueSeries series, Graphics2D graphics2D)
{
GeneralPath bar3dRight = new GeneralPath();
bar3dRight.moveTo((float)(xBarTopLeft + widthOfBarHisto), (float)yBarTopLeft);
bar3dRight.lineTo((float)(xBarTopLeft + widthOfBarHisto), (float)(yBarTopLeft+heightOfBarHisto));
bar3dRight.lineTo((float)(xBarTopLeft + widthOfBarHisto + effect3dValue),
(float)(yBarTopLeft + heightOfBarHisto - effect3dValue));
bar3dRight.lineTo((float)(xBarTopLeft + widthOfBarHisto+effect3dValue), (float)(yBarTopLeft - effect3dValue));
//graphics2D.setColor(series.getColor().darker());
graphics2D.setColor(series.getColor().darker().darker());
graphics2D.fill(bar3dRight);
 
GeneralPath bar3dTop = new GeneralPath();
bar3dTop.moveTo( (float) xBarTopLeft, (float) yBarTopLeft);
bar3dTop.lineTo((float) (xBarTopLeft + effect3dValue), (float) (yBarTopLeft - effect3dValue));
bar3dTop.lineTo((float) (xBarTopLeft + widthOfBarHisto+effect3dValue), (float) (yBarTopLeft - effect3dValue));
bar3dTop.lineTo((float) (xBarTopLeft + widthOfBarHisto), (float) (yBarTopLeft) );
//graphics2D.setColor(series.getColor().brighter());
graphics2D.setColor(series.getColor().darker());
graphics2D.fill(bar3dTop);
 
graphics2D.setColor(Color.black);
graphics2D.draw(bar3dRight);
graphics2D.draw(bar3dTop);
 
}
//END_BLOCKER_CHART_3D
*/
 
/*
public static void main(String[] argv) throws Exception
{
}
*/
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/VerticalLinePlot.java
New file
0,0 → 1,147
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.util.*;
import java.awt.*;
import com.oxymel.ofc.charts.data.*;
import com.oxymel.ofc.charts.exception.*;
import com.oxymel.ofc.charts.series.*;
import com.oxymel.ofc.charts.util.*;
 
/**
* This class provides a vertical line plot
*/
public class VerticalLinePlot
extends ChartWithAxisXY {
 
private int _nbPixelFreeBeforeUnit = 5;
 
private VerticalNumberAxis _axisY;
private HorizontalNumberAxis _axisX;
 
private Point2DSeriesContainer _point2DSeriesContainer;
 
/**
* Constructor
* @param chartWidth Width of vertical bar chart
* @param chartHeight Height of vertical bar chart
* @param axisX Horizontal axis to display categories
* @param axisY Vertical number axis
* @param point2DSeriesContainer All series of couple category-value
*/
public VerticalLinePlot(int chartWidth, int chartHeight,
HorizontalNumberAxis axisX, VerticalNumberAxis axisY,
Point2DSeriesContainer point2DSeriesContainer) {
super(chartWidth, chartHeight);
_legend.setDisplayAsBar(false);
_axisX = axisX;
_axisY = axisY;
setPoint2DSeriesContainer(point2DSeriesContainer);
}
 
/**
* Change data used to draw chart
* @param point2DSeriesContainer All series of couple category-value
*/
public void setPoint2DSeriesContainer(Point2DSeriesContainer
point2DSeriesContainer) {
_point2DSeriesContainer = point2DSeriesContainer;
setAllSeriesColorFromPalette(point2DSeriesContainer);
}
 
protected SeriesContainer getSeriesContainer() {
return _point2DSeriesContainer;
}
 
protected Axis getAxisX() {
return _axisX;
}
 
protected Axis getAxisY() {
return _axisY;
}
 
protected void setAxisParameters() throws OFCChartsException {
_axisX.setMinValue(_point2DSeriesContainer.getXMinOfAllSeries());
_axisX.setMaxValue(_point2DSeriesContainer.getXMaxOfAllSeries());
//_axisX.setFontSize(9);
 
_axisY.setMinValue(_point2DSeriesContainer.getYMinOfAllSeries());
_axisY.setMaxValue(_point2DSeriesContainer.getYMaxOfAllSeries());
_axisY.setNbGapMax(10);
}
 
protected void drawGraphic(int xTopLeftGraphic, int yTopLeftGraphic,
int graphicWidth, int graphicHeight,
int xOrigine, int yOrigine, Graphics2D graphics2D) {
int sizeOfGapOnY = graphicHeight / _axisY.getNbGap();
int sizeOfGapOnX = graphicWidth / _axisX.getNbGap();
int gapValueOnX = _axisX.getGapValue();
int gapValueOnY = _axisY.getGapValue();
Enumeration enumAllSeries = _point2DSeriesContainer.
getEnumAllSeriesOrderByDisplayNumber();
while (enumAllSeries.hasMoreElements()) {
Point2DSeries point2DSeries = (Point2DSeries) enumAllSeries.nextElement();
if (point2DSeries.isVisible()) {
drawLine(xOrigine, yOrigine, point2DSeries, gapValueOnX, sizeOfGapOnX,
gapValueOnY, sizeOfGapOnY, graphics2D);
}
}
 
}
 
private void drawLine(int xOrigine, int yOrigine, Point2DSeries point2DSeries,
int gapValueOnX, int sizeOfGapOnX,
int gapValueOnY, int sizeOfGapOnY,
Graphics2D graphics2D) {
graphics2D.setColor(point2DSeries.getColor());
 
Enumeration enumAllPoint2D = point2DSeries.getEnumAllPoint2D();
if (!enumAllPoint2D.hasMoreElements()) {
return;
}
Point2D initialPoint = (Point2D) enumAllPoint2D.nextElement();
while (enumAllPoint2D.hasMoreElements()) {
Point2D finalPoint = (Point2D) enumAllPoint2D.nextElement();
 
int x1 = xOrigine +
Graphics2DTools.getRelativeSizeOfValue(initialPoint.getX(),
gapValueOnX, sizeOfGapOnX);
int y1 = yOrigine -
Graphics2DTools.getRelativeSizeOfValue(initialPoint.getY(),
gapValueOnY, sizeOfGapOnY);
int x2 = xOrigine +
Graphics2DTools.getRelativeSizeOfValue(finalPoint.getX(), gapValueOnX,
sizeOfGapOnX);
int y2 = yOrigine -
Graphics2DTools.getRelativeSizeOfValue(finalPoint.getY(), gapValueOnY,
sizeOfGapOnY);
 
point2DSeries.drawIndicator(x1, y1, graphics2D);
point2DSeries.drawIndicator(x2, y2, graphics2D);
 
Stroke initialStroke = graphics2D.getStroke();
graphics2D.setStroke(new BasicStroke(2.0f));
graphics2D.drawLine(x1, y1, x2, y2);
graphics2D.setStroke(initialStroke);
initialPoint = finalPoint;
}
}
 
/*
public static void main(String[] argv) throws Exception
{
 
}
*/
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/VerticalAreaChart.java
New file
0,0 → 1,109
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.*;
//ofc
import com.oxymel.ofc.charts.series.*;
 
 
/**
* This class allows to draw bar charts as areas. In such a presentation
* the tops of the bars within a given series are joined together to provide
* a line. The different areas delimited by the lines corresponding to the
* series are colored according to the color palette.
*/
public class VerticalAreaChart extends VerticalBarChart
{
private VerticalAreaChartRenderer _renderer;
 
/**
* Constructor
* @param chartWidth Width of vertical bar chart
* @param chartHeight Height of vertical bar chart
* @param axisX Horizontal axis to display categories
* @param axisY Vertical number axis
* @param categoryValueSeriesContainer All series of couple category-value
*/
public VerticalAreaChart(int chartWidth, int chartHeight,
HorizontalCategoryAxis axisX, VerticalNumberAxis axisY,
CategoryValueSeriesContainer categoryValueSeriesContainer)
{
super(chartWidth, chartHeight, axisX, axisY, categoryValueSeriesContainer);
_renderer = new VerticalAreaChartRenderer(categoryValueSeriesContainer);
}
 
 
protected VerticalBarChartRenderer getChartRenderer(){return _renderer;};
 
protected void drawGraphic(int xTopLeftGraphic, int yTopLeftGraphic, int graphicWidth, int graphicHeight,
int xOrigine, int yOrigine, Graphics2D graphics2D)
{
_renderer.setNbGapOnX(_axisX.getNbGap());
_renderer.setNbGapOnY(_axisY.getNbGap());
_renderer.setGapValueOnY(_axisY.getGapValue());
_renderer.drawGraphic( xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight,
xOrigine, yOrigine, graphics2D);
 
/*
int sizeOfGapOnY = graphicHeight / _axisY.getNbGap();
int sizeOfGapOnX = graphicWidth / _axisX.getNbGap();
 
Vector allCategories = _categoryValueSeriesContainer.getAllCategoriesOrderByDisplayNumber();
 
Enumeration enumAllSeries = _categoryValueSeriesContainer.getEnumAllSeriesOrderByDisplayNumber();
while(enumAllSeries.hasMoreElements()){
int xCurrent = xOrigine + (sizeOfGapOnX/2);
GeneralPath generalPath = new GeneralPath();
generalPath.moveTo(xCurrent, yOrigine);
CategoryValueSeries categoryValueSeries = (CategoryValueSeries)enumAllSeries.nextElement();
if(categoryValueSeries.isVisible()){
for(int i= 0; i<allCategories.size(); i++){
Category category = (Category)allCategories.elementAt(i);
xCurrent = xOrigine + (sizeOfGapOnX * i) + (sizeOfGapOnX/2);
double value = categoryValueSeries.getCategoryValueAsDouble(category.getId());
addLineArea(xCurrent, yOrigine, sizeOfGapOnX,
Graphics2DTools.getRelativeSizeOfValue(value, _axisY.getGapValue(), sizeOfGapOnY),
categoryValueSeries, generalPath, graphics2D);
}
generalPath.lineTo(xCurrent, yOrigine);
 
xCurrent = xOrigine + (sizeOfGapOnX/2);
generalPath.lineTo(xCurrent, yOrigine);
graphics2D.setColor(categoryValueSeries.getColor());
graphics2D.fill(generalPath);
graphics2D.draw(generalPath);
}
}
*/
}
 
/*
private void addLineArea(int xCurrent, int yOrigine, int sizeOfGapOnX, int relativeSizeOfValue,
CategoryValueSeries series, GeneralPath generalPath, Graphics2D graphics2D)
{
int x1 = xCurrent;
 
int y1 = yOrigine - relativeSizeOfValue;
 
generalPath.lineTo(x1, y1);
 
 
}
*/
 
/*
public static void main(String[] argv) throws Exception
{
}
*/
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/ExplodedPieChart.java
New file
0,0 → 1,755
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.util.*;
 
import java.awt.*;
 
import com.oxymel.ofc.charts.exception.*;
import com.oxymel.ofc.charts.series.*;
 
public class ExplodedPieChart
extends Chart {
/**
* The value to set if the tags to write are labels.
* Example : <br>
* <li>pieChart.setTypeOfTag( ExplodedPieChart.TAG_LABEL );
*/
public static final int TAG_LABEL = 1;
 
/**
* The value to set if the tags to write are values (default).
* Example : <br>
* <li>pieChart.setTypeOfTag( ExplodedPieChart.TAG_VALUE );
*/
public static final int TAG_VALUE = 2;
 
private int _typeOfTag = TAG_VALUE;
private ValueSeriesContainer _valueSeriesContainer;
 
//these attributes can be setting by user
private boolean _isCircular = true;
private boolean _verticalEllipse = false;
private boolean _is3D = false;
private boolean _isPieWithTags = false;
 
private double _marginPercent = 0.2; //default value equals 20 per cent of image size, translation width is (_margin/2)
private int maxDegree = 360;
private boolean _isTagLabelToCut = false;
private int _minPercentToDisplayTag = 2;
 
//these attributes are used by API to define display appearence
private int _profondeur = 16;
private int _margin = 0;
private double _rationElipseX = 1.0;
private double _rationElipseY = 1.0;
private int _externalGraphicLegendMargin = 0;
/**
* Constructor of the exploded pie chart.
* @param chartWidth Width of pie chart
* @param chartHeight Height of pie chart
* @param valueSeriesContainer ValueSeriesContainer - All series of couple category-value
*/
public ExplodedPieChart(int chartWidth, int chartHeight,
ValueSeriesContainer valueSeriesContainer) {
super(chartWidth, chartHeight);
setCategoryValueSeriesContainer(valueSeriesContainer);
}
 
/**
* Constructor of the exploded pie chart.
* @param chartWidth int
* @param chartHeight int
* @param valueSeriesContainer ValueSeriesContainer - All series of couple category-value
* @param margin double (default value = 0.02 corresponding to 20% of the image size)
*/
public ExplodedPieChart(int chartWidth, int chartHeight,
ValueSeriesContainer valueSeriesContainer,
double margin) {
super(chartWidth, chartHeight);
setCategoryValueSeriesContainer(valueSeriesContainer);
_marginPercent = margin;
}
 
/**
* Change margin value.
* @param margin new margin value
*/
public void setMargin(int margin) {
_margin = margin;
}
 
/**
* To set the external graphic legend margin (default value = 0).<br>
* Allows to extend the line between the graphic and the legend.
* @param longTag int
*/
public void setTagOnPieWidth(int longTag) {
_externalGraphicLegendMargin = longTag;
}
 
/**
* If is3D is true, the pie chart is displayed on 3D.
* @param is3D boolean
*/
public void set3D(boolean is3D) {
_is3D = is3D;
if (!_is3D)
_profondeur = 0;
}
 
/**
* Sets the value of the 3D effect.
* @param profondeur int
*/
public void set3Dprofondeur(int prof) {
_profondeur = prof;
if (_profondeur > 0) _is3D = true;
}
 
/**
* If isCircular is true, the pie chart is displayed as circular Pie.
* @param isCircular boolean
*/
public void setCircular(boolean isCircular) {
_isCircular = isCircular;
}
 
/**
* If verticalEllipse is true, the pie chart is displayed as a vertical Ellipse.
* @param verticalEllipse boolean
*/
public void setVerticalEllipse(boolean verticalEllipse) {
_verticalEllipse = verticalEllipse;
}
 
/**
* If isPieWithTags is true, each arc of the pie chart has a legend tag.
* @param isPieWithTags boolean
*/
public void setPieWithTags(boolean isPieWithTags) {
_isPieWithTags = isPieWithTags;
}
 
/**
* Sets the type of legend on the tags.<br>
* Possibles value are :
* <ul>
* <li>ExplodedPieChart.TAG_VALUE (default)
* <li>ExplodedPieChart.TAG_LABEL
* </ul>
* @param type int
*/
public void setTypeOfTag(int type) {
if (type == TAG_VALUE) {
_externalGraphicLegendMargin = 1;
_marginPercent = 0.05;
}
_typeOfTag = type;
}
 
/**
* If isHalfPie is true, the pie chart is displayed as an half pie (0-180°).
* @param isHalfPie boolean
*/
public void setIsHalfPie(boolean isHalfPie) {
if (isHalfPie)
maxDegree = 180;
else
maxDegree = 360;
}
 
/**
* Allows to cut the long labels on the graphic's sections if toCut is true.
* If toCut is false, the long labels will be replaced by the value.
* @param toCut boolean
*/
public void setTagLabelToCut(boolean toCut) {
_isTagLabelToCut = toCut;
}
 
private boolean getTagLabelToCut(){
if (_typeOfTag == TAG_LABEL)
return _isTagLabelToCut;
else return false;
 
}
/**
* Allows to fix the minimum percent value to display tag (by default minPercentToDisplayTag = 2).
* @param minPercentToDisplayTag int
*/
public void setMinPercentToDisplayTag(int minPercentToDisplayTag) {
_minPercentToDisplayTag = minPercentToDisplayTag;
}
 
 
/**
* Changes the data used to draw chart.
* @param categoryValueSeriesContainer ValueSeriesContainer - All series of couple category-value
*/
public void setCategoryValueSeriesContainer(ValueSeriesContainer
valueSeriesContainer) {
_valueSeriesContainer = valueSeriesContainer;
setAllSeriesColorFromPalette(valueSeriesContainer);
}
 
int maxLabelSize = 0;
protected SeriesContainer getSeriesContainer() {
return _valueSeriesContainer;
}
 
protected void doDrawChart(Graphics2D graphics2D) throws OFCChartsException {
int xTopLeftGraphic = getXTopLeftGraphic(graphics2D);
int yTopLeftGraphic = getYTopLeftGraphic(graphics2D);
int graphicWidth = getGraphicWidth(graphics2D);
int graphicHeight = getGraphicHeight(graphics2D);
 
drawGraphicBackground(xTopLeftGraphic, yTopLeftGraphic,
graphicWidth, graphicHeight, graphics2D);
 
_legend.drawLegend(getXTopLeftLegend(graphics2D),
getYTopLeftLegend(graphics2D),
getSeriesContainer().getAllSeriesOrderByDisplayNumber(),
graphics2D);
 
/*bug à voir plus tard
_legend.drawLegend(
getXTopLeftLegend(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D),
getYTopLeftLegend(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D),
getSeriesContainer().getAllSeriesOrderByDisplayNumber(), graphics2D);
*/
int graphWidth = getGraphicWidth(graphics2D);
int graphHeight = getGraphicHeight(graphics2D);
 
int decalY = 0;
int maxLengthLegend = 0;
updateRatio(graphWidth, graphHeight); //update _ratioEllipseX and _ratioEllipseY attributes
 
//if only half Pie is displayed, final graph have to be centered on Image
if (maxDegree == 180)
decalY = graphHeight / 4;
 
// if tags are displayed on graph, free space is allowed on GraphWith
// this free space size is defined with Font and the longer Word to display
if (_isPieWithTags) {
maxLengthLegend = getMaxLengthForLegend(graphics2D) + _externalGraphicLegendMargin;
if (_typeOfTag == TAG_LABEL) {
//permet de couper les labels trops longs
if (getTagLabelToCut()) {
int nbToCut = 0;
while (maxLengthLegend > graphWidth / 4) {
nbToCut++;
maxLengthLegend = getMaxLengthForLegend(graphics2D, nbToCut) +
_externalGraphicLegendMargin;
}
}
else {
if (maxLengthLegend > graphWidth / 4) {
_typeOfTag = TAG_VALUE;
maxLengthLegend = getMaxLengthForLegend(graphics2D) +
_externalGraphicLegendMargin;
}
}
}
graphWidth -= (maxLengthLegend * 2);
}
 
if (_isCircular) {
int valMin = Math.min(graphWidth, graphHeight);
_margin = (int) (valMin * _marginPercent); //initialization of _margin value
 
int x = xTopLeftGraphic + ( (graphWidth - valMin) / 2) + maxLengthLegend;
int y = yTopLeftGraphic + ( (graphHeight - valMin) / 2) + decalY;
if (_is3D) {
for (int i = _profondeur; i > 0; i--)
drawGraphic3D(x, y + i, valMin, valMin, graphics2D);
}
drawGraphic(x, y, valMin, valMin, graphics2D);
}
else {
int decalHeight = 0;
int decalWidth = 0;
//if graph is displayed as vertical Ellipse, Dimensions of drawing area are transformed to obtain Heigth longer than width
if (_verticalEllipse) {
if (graphWidth >= graphHeight) { //transforme en rectangle une zone de dessin carré pour obtenir une ellipse
decalWidth = graphWidth - graphHeight;
graphWidth = graphHeight;
graphWidth = (int) ( (double) graphWidth * 0.80);
decalWidth += (int) ( (double) graphWidth * 0.20);
}
}
else {
if (graphWidth <= graphHeight) { //transforme en rectangle une zone de dessin carré pour obtenir une ellipse
decalHeight = graphHeight - graphWidth;
graphHeight = graphWidth;
graphHeight = (int) ( (double) graphHeight * 0.80);
decalHeight += (int) ( (double) graphHeight * 0.20);
}
}
 
int valMin = Math.min(graphWidth, graphHeight);
_margin = (int) (valMin * _marginPercent); //initialization of _margin value
 
int x = xTopLeftGraphic + maxLengthLegend + (decalWidth / 2);
int y = yTopLeftGraphic + (decalHeight / 2) + decalY;
if (_is3D) {
for (int i = _profondeur; i > 0; i--)
drawGraphic3D(x, y + i, graphWidth, graphHeight - (_profondeur * 2),
graphics2D);
}
drawGraphic(x, y, graphWidth, graphHeight - (_profondeur * 2), graphics2D);
}
}
 
/**
* This method get max StringWidth to display as tag legend
*/
private int getMaxLengthForLegend(Graphics2D graphics2D) {
Vector allPieSeries = _valueSeriesContainer.getAllSeriesOrderByDisplayNumber();
int max = 0;
for (int i = 0; i < allPieSeries.size(); i++) {
PieSeries pieSeries = (PieSeries) allPieSeries.elementAt(i);
FontMetrics fm = graphics2D.getFontMetrics();
int tmp = 0;
if (_typeOfTag == TAG_VALUE)
tmp = fm.stringWidth(Integer.toString( (int) pieSeries.getValue()));
else {
tmp = fm.stringWidth(pieSeries.getLegendLabel());
if (maxLabelSize == 0 ||
maxLabelSize < pieSeries.getLegendLabel().length())
maxLabelSize = pieSeries.getLegendLabel().length();
}
if (max < tmp)
max = tmp;
}
return max;
}
 
/**
* This method get max StringWidth to display as tag legend
* adaptate to the graphic width
* @param graphics2D Graphics2D
* @param nbToCut int
* @return int
*/
private int getMaxLengthForLegend(Graphics2D graphics2D, int nbToCut) {
Vector allPieSeries = _valueSeriesContainer.getAllSeriesOrderByDisplayNumber();
int max = 0;
maxLabelSize = maxLabelSize - nbToCut;
 
for (int i = 0; i < allPieSeries.size(); i++) {
PieSeries pieSeries = (PieSeries) allPieSeries.elementAt(i);
FontMetrics fm = graphics2D.getFontMetrics();
int tmp = 0;
if (_typeOfTag == TAG_VALUE)
tmp = fm.stringWidth(Integer.toString( (int) pieSeries.getValue()));
else {
String label = pieSeries.getLegendLabel();
if (label.length() > maxLabelSize)
label = label.substring(0, maxLabelSize);
tmp = fm.stringWidth(label);
}
if (max < tmp)
max = tmp;
}
 
return max;
}
 
/**
* This method update ration values to display graph as Ellipse
*/
private void updateRatio(int width, int height) {
if (width > height) {
_rationElipseY = (double) ( ( (double) height) / ( (double) width));
}
if (width < height) {
_rationElipseX = (double) ( ( (double) width) / ( (double) height));
}
}
 
private void drawGraphic(int xTopLeftGraphic, int yTopLeftGraphic,
int graphicWidth, int graphicHeight,
Graphics2D graphics2D) {
updateExplodedPercentValues();
 
Vector allPieSeries = _valueSeriesContainer.
getAllSeriesOrderByDisplayNumber();
 
double sumAllValues = _valueSeriesContainer.getSumAllValues();
 
int startAngle = 0;
int arcAngle = 0;
for (int i = 0; i < allPieSeries.size(); i++) {
PieSeries pieSeries = (PieSeries) allPieSeries.elementAt(i);
if (pieSeries.isVisible()) {
double value = pieSeries.getValue();
if (i + 1 < allPieSeries.size()) {
arcAngle = (int) ( (getValueAsPercentage(value, sumAllValues) *
( (double) maxDegree)) / 100);
}
else {
arcAngle = maxDegree - startAngle;
}
 
graphics2D.setColor(pieSeries.getColor());
if (pieSeries.isExploded()) { //verification si la tranche doit être décalée
int angleBisec = startAngle + (arcAngle / 2);
int valTranslate = (int) ( (_margin * pieSeries.getExplodedPercent()) /
2);
int decalX = getVarX(startAngle, arcAngle, angleBisec, valTranslate);
int decalY = getVarY(startAngle, arcAngle, angleBisec, valTranslate);
 
if (angleBisec > 270 || (angleBisec > 90 && angleBisec < 180)) {
graphics2D.fillArc(xTopLeftGraphic + (_margin / 2) +
( (int) ( (decalY) * _rationElipseX)),
yTopLeftGraphic + (_margin / 2) +
( (int) ( (decalX) * _rationElipseY)),
graphicWidth - _margin, graphicHeight - _margin,
startAngle, arcAngle);
if (_isPieWithTags &&
( (int) getValueAsPercentage(value, sumAllValues)) >=
_minPercentToDisplayTag){
drawTagOnArc(xTopLeftGraphic + (_margin / 2) +
( (int) ( (decalY) * _rationElipseX)),
yTopLeftGraphic + (_margin / 2) +
( (int) ( (decalX) * _rationElipseY)),
graphicWidth - _margin, graphicHeight - _margin,
startAngle, arcAngle, graphics2D, pieSeries);
}
}
else {
graphics2D.fillArc(xTopLeftGraphic + (_margin / 2) +
( (int) ( (decalX) * _rationElipseX)),
yTopLeftGraphic + (_margin / 2) +
( (int) ( (decalY) * _rationElipseY)),
graphicWidth - _margin, graphicHeight - _margin,
startAngle, arcAngle);
if (_isPieWithTags &&
( (int) getValueAsPercentage(value, sumAllValues)) >= _minPercentToDisplayTag){
drawTagOnArc(xTopLeftGraphic + (_margin / 2) +
( (int) ( (decalX) * _rationElipseX)),
yTopLeftGraphic + (_margin / 2) +
( (int) ( (decalY) * _rationElipseY)),
graphicWidth - _margin, graphicHeight - _margin,
startAngle, arcAngle, graphics2D, pieSeries);
}
}
}
else {
graphics2D.fillArc(xTopLeftGraphic + (_margin / 2),
yTopLeftGraphic + (_margin / 2),
graphicWidth - _margin, graphicHeight - _margin,
startAngle, arcAngle);
if (_isPieWithTags &&
( (int) getValueAsPercentage(value, sumAllValues)) >=
_minPercentToDisplayTag)
drawTagOnArc(xTopLeftGraphic + (_margin / 2),
yTopLeftGraphic + (_margin / 2),
graphicWidth - _margin, graphicHeight - _margin,
startAngle, arcAngle, graphics2D, pieSeries);
}
startAngle += arcAngle;
}
}
}
 
private void drawTagOnArc(int xTopLeftGraphic, int yTopLeftGraphic,
int graphicWidth, int graphicHeight, int startAngle,
int arcAngle, Graphics2D graphics2D,
PieSeries pieSeries) {
int angleBisec = startAngle + (arcAngle / 2);
int centreX = xTopLeftGraphic + ( (graphicWidth) / 2);
int centreY = yTopLeftGraphic + ( (graphicHeight) / 2);
int rayonX = graphicWidth;
int rayonY = graphicHeight;
int legendX = _externalGraphicLegendMargin;
int decalX = 1;
int decalY = 1;
int decalLegend = 0;
 
if (angleBisec < 180)
decalY = -1;
 
if (angleBisec > 90 && angleBisec < 270) {
decalX = -1;
FontMetrics fm = graphics2D.getFontMetrics();
String label = Integer.toString( (int) pieSeries.getValue());
if (_typeOfTag == TAG_LABEL){
label = pieSeries.getLegendLabel();
if (getTagLabelToCut()) {
if (label.length() > maxLabelSize)
if (label.length() > maxLabelSize - 3)
label = label.substring(0, maxLabelSize - 3) + "...";
}
}
 
decalLegend = -1 * (fm.stringWidth(label));
decalLegend -= 5;
}
else
decalLegend = 5;
 
int angleBisecTmp = angleBisec; //sauvegarde de l'angle de la bisectrice de la part courante
 
while (angleBisec > 90)
angleBisec -= 90;
 
legendX = legendX * decalX;
graphics2D.setColor(Color.black);
 
if (angleBisecTmp > 270 || (angleBisecTmp > 90 && angleBisecTmp < 180)) {
int x = (int) (Math.sin(Math.toRadians( (double) angleBisec)) *
( (double) ( (rayonX) / 2))); //il faudra certainement retirer la marge.
int y = (int) (Math.cos(Math.toRadians( (double) angleBisec)) *
( (double) ( (rayonY) / 2))); //il faudra certainement retirer la marge.
x = x * decalX;
y = y * decalY;
/*if (_typeOfTag == TAG_VALUE) {
if (angleBisecTmp > 270){
graphics2D.drawString(Integer.toString( (int) pieSeries.getValue()),
centreX + x + 1,
centreY + y + _profondeur +(graphics2D.getFontMetrics().getHeight() / 2) +1
);
}else{
graphics2D.drawString(Integer.toString( (int) pieSeries.getValue()),
centreX+x-graphics2D.getFontMetrics().stringWidth(Integer.toString((int)pieSeries.getValue()))-1,
centreY + y - 1);
}
}
else {*/
String label;
if (_typeOfTag == TAG_LABEL){
label = pieSeries.getLegendLabel();
if (getTagLabelToCut()) {
if (label.length() > maxLabelSize)
if (label.length() > maxLabelSize - 3)
label = label.substring(0, maxLabelSize - 3) + "...";
}
}else {
label = Integer.toString( (int) pieSeries.getValue());
}
graphics2D.drawLine(centreX + x, centreY + y,
centreX + ( (rayonX / 2) * decalX) + legendX,
centreY + y);
 
graphics2D.drawString(label,
centreX + ( (rayonX / 2) * decalX) + legendX +
decalLegend, centreY + y);
//}
}
else {
int x = (int) (Math.sin(Math.toRadians( (double) angleBisec)) *
( (double) ( (rayonY) / 2))); //il faudra certainement retirer la marge.
int y = (int) (Math.cos(Math.toRadians( (double) angleBisec)) *
( (double) ( (rayonX) / 2)));
x = x * decalY;
y = y * decalX;
/*if (_typeOfTag == TAG_VALUE) {
if (angleBisecTmp > 180){
graphics2D.drawString(Integer.toString( (int) pieSeries.getValue()),
centreX + y - graphics2D.getFontMetrics().stringWidth(Integer.toString( (int) pieSeries.getValue())) - 1,
centreY + x + _profondeur +
(graphics2D.getFontMetrics().getHeight() / 2) +
1);
} else {
graphics2D.drawString(Integer.toString( (int) pieSeries.getValue()),
centreX + y + 1, centreY + x - 1);
}
}
else {*/
String label;
if (_typeOfTag == TAG_LABEL) {
label = pieSeries.getLegendLabel();
if (getTagLabelToCut()) {
if (label.length() > maxLabelSize)
if (label.length() > maxLabelSize - 3)
label = label.substring(0, maxLabelSize - 3) + "...";
}
}else {
label = Integer.toString( (int) pieSeries.getValue());
}
graphics2D.drawLine(centreX + y, centreY + x,
centreX + ( (rayonX / 2) * decalX) + legendX,
centreY + x);
graphics2D.drawString(label,
centreX + ( (rayonX / 2) * decalX) + legendX +
decalLegend, centreY + x);
//}
}
}
 
private int getVarX(int startAngle, int arcAngle, int angleBisec,
int longTranslate) {
int varSigne = 0;
 
if (angleBisec > 90 && angleBisec < 270)
varSigne = -1;
if (angleBisec < 90)
varSigne = 1;
if (angleBisec > 270)
varSigne = 1;
if (angleBisec == 90 || angleBisec == 270)
varSigne = 0;
 
while (angleBisec > 90)
angleBisec -= 90;
 
angleBisec = 90 - angleBisec;
 
float varX = longTranslate * ( (float) (angleBisec / 90.0));
 
return varSigne * ( (int) varX);
}
 
private int getVarY(int startAngle, int arcAngle, int angleBisec,
int longTranslate) {
int varSigne = 0;
 
if (angleBisec < 180)
varSigne = -1;
if (angleBisec > 180)
varSigne = 1;
if (angleBisec == 0 || angleBisec == 180)
varSigne = 0;
 
while (angleBisec > 90)
angleBisec -= 90;
 
float varY = ( (float) (longTranslate * angleBisec)) / 90;
 
return varSigne * ( (int) varY);
}
 
private void updateExplodedPercentValues() {
Vector allPieSeries = _valueSeriesContainer.
getAllSeriesOrderByDisplayNumber();
int totalWeight = 0;
 
for (int i = 0; i < allPieSeries.size(); i++) {
PieSeries pieSeries = (PieSeries) allPieSeries.elementAt(i);
totalWeight += pieSeries.getExplodedWeight();
}
 
if (totalWeight == 0)
return;
 
for (int i = 0; i < allPieSeries.size(); i++) {
PieSeries pieSeries = (PieSeries) allPieSeries.elementAt(i);
pieSeries.setExplodedPercent( (double) ( ( (double) pieSeries.
getExplodedWeight()) /
( (double) totalWeight)));
}
}
 
private double getValueAsPercentage(double value, double sumAllValues) {
return ( (value * 100) / sumAllValues);
}
 
private void drawGraphic3D(int xTopLeftGraphic, int yTopLeftGraphic,
int graphicWidth, int graphicHeight,
Graphics2D graphics2D) {
updateExplodedPercentValues();
 
Vector allPieSeries = _valueSeriesContainer.
getAllSeriesOrderByDisplayNumber();
 
double sumAllValues = _valueSeriesContainer.getSumAllValues();
 
int startAngle = 0;
int arcAngle = 0;
for (int i = 0; i < allPieSeries.size(); i++) {
PieSeries pieSeries = (PieSeries) allPieSeries.elementAt(i);
if (pieSeries.isVisible()) {
double value = pieSeries.getValue();
if (i + 1 < allPieSeries.size()) {
arcAngle = (int) ( (getValueAsPercentage(value, sumAllValues) *
( (double) maxDegree)) / 100);
}
else {
arcAngle = maxDegree - startAngle;
}
 
graphics2D.setColor(pieSeries.getColor().darker());
 
if (pieSeries.isExploded()) { //verification si la tranche doit être décalée
int angleBisec = startAngle + (arcAngle / 2);
int valTranslate = (int) ( (_margin * pieSeries.getExplodedPercent()) /
2);
int decalX = getVarX(startAngle, arcAngle, angleBisec, valTranslate);
int decalY = getVarY(startAngle, arcAngle, angleBisec, valTranslate);
 
if (angleBisec > 270 || (angleBisec > 90 && angleBisec < 180)) {
graphics2D.fillArc(xTopLeftGraphic + (_margin / 2) +
( (int) ( (decalY) * _rationElipseX)),
yTopLeftGraphic + (_margin / 2) +
( (int) ( (decalX) * _rationElipseY)),
graphicWidth - _margin, graphicHeight - _margin,
startAngle, arcAngle);
}
else {
graphics2D.fillArc(xTopLeftGraphic + (_margin / 2) +
( (int) ( (decalX) * _rationElipseX)),
yTopLeftGraphic + (_margin / 2) +
( (int) ( (decalY) * _rationElipseY)),
graphicWidth - _margin, graphicHeight - _margin,
startAngle, arcAngle);
}
}
else {
graphics2D.fillArc(xTopLeftGraphic + (_margin / 2),
yTopLeftGraphic + (_margin / 2),
graphicWidth - _margin, graphicHeight - _margin,
startAngle, arcAngle);
}
startAngle += arcAngle;
}
}
}
 
/*
static private void bug() throws Exception
{
ValueSeriesContainer valueSeriesContainer = new ValueSeriesContainer();
valueSeriesContainer.addValueSeries(new PieSeries("102", "D.S.I", 50));
valueSeriesContainer.addValueSeries(new PieSeries("202", "D.P.E", 20));
valueSeriesContainer.addValueSeries(new PieSeries("302", "D. Medical", 15));
valueSeriesContainer.addValueSeries(new PieSeries("602", "Entreprise", 15));
valueSeriesContainer.addValueSeries(new PieSeries("402", "D. Mktg", 12));
valueSeriesContainer.addValueSeries(new PieSeries("403", "G.M.S", 12));
valueSeriesContainer.addValueSeries(new PieSeries("404", "D.R.H", 12));
valueSeriesContainer.addValueSeries(new PieSeries("405", "D.A.E.P", 12));
 
 
ExplodedPieChart pieChart = new ExplodedPieChart(300, 200, valueSeriesContainer,0);
pieChart.setCircular(false);
pieChart.setVerticalEllipse(false);
pieChart.set3D(true);
pieChart.setPieWithTags(false);
pieChart.setIsHalfPie(false);
pieChart.setLegendDisplayMode(Legend.LEGEND_DISPLAY_MODE_BOTTOM);
pieChart.setLegendFontSize(9);
pieChart.drawJPEG("bug.jpg");
pieChart.setImageBagroundColor(new Color(244,244,236));
pieChart.setGraphicBagroundColor(new Color(244,244,236));
pieChart.drawSVG("bug.svg");
 
}
*/
 
/*
public static void main(String[] argv) throws Exception
{
}
*/
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/BarChart.java
New file
0,0 → 1,129
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//ofc
import com.oxymel.ofc.charts.series.CategoryValueSeriesContainer;
import com.oxymel.ofc.charts.series.SeriesContainer;
 
/**
* BarChart is the abstract superclass for all Bar chart
*/
abstract class BarChart extends ChartWithAxisXY
{
/*
protected final int _nbPixelBetweenEachBarHisto = 0;
protected int _nbPixelFreeBeforeSeries = 5;
protected int _nbPixelFreeAfterSeries = 5;
*/
 
protected CategoryValueSeriesContainer _categoryValueSeriesContainer;
 
protected BarChart(int chartWidth, int chartHeight,
CategoryValueSeriesContainer categoryValueSeriesContainer)
{
super(chartWidth, chartHeight);
setCategoryValueSeriesContainer(categoryValueSeriesContainer);
}
 
/**
* Replaces the data series used to draw the chart.
* It can be used to draw several graphics with the same characteristics
* but different input data.
* @param categoryValueSeriesContainer All series defining the couples category-value, they are grouped within a series container.
*/
public void setCategoryValueSeriesContainer(CategoryValueSeriesContainer categoryValueSeriesContainer)
{
_categoryValueSeriesContainer = categoryValueSeriesContainer;
setAllSeriesColorFromPalette(categoryValueSeriesContainer);
}
 
/**
* Gets the series container defining the input data.
* @return CategoryValueSeriesContainer currently used to draw chart
*/
public CategoryValueSeriesContainer getCategoryValueSeriesContainer(){return _categoryValueSeriesContainer;}
 
 
 
/**
* Sets the free space beetween two bars.
* The space is given on a percentage basis, assuming that 100% corresponds
* to the whole space required to display one information category.
* Setting this information is not mandatory and furthermore the OFC-Chart
* kernel used it only if it provides a consistent resulting graphic.
* @param percentageBetweenEachBarHisto the free space percentage
* beetween two bars
*/
public void setPercentageBetweenEachBarHisto(int percentageBetweenEachBarHisto)
{
getBarChartRenderer().setPercentageBetweenEachBarHisto(percentageBetweenEachBarHisto);
}
 
/**
* Sets the free space before the first bar within a category.
* The space is given on a percentage basis, assuming that 100% corresponds
* to the whole space required to display one information category.
* The acceptance of this percentage by the OFC-Chart kernel depends on the
* resulting graphic consistency.
* @param percentageFreeBeforeSeries the free space percentage before the
* first bar
*/
public void setPercentageFreeBeforeSeries(int percentageFreeBeforeSeries)
{
getBarChartRenderer().setPercentageFreeBeforeSeries(percentageFreeBeforeSeries);
}
 
/**
* Sets the free space after the last bar within a category.
* The space is given on a percentage basis, assuming that 100% corresponds
* to the whole space required to display one information category.
* The acceptance of this percentage by the OFC-Chart kernel depends on the
* resulting graphic consistency.
* @param percentageFreeAfterSeries the free space percentage after the
* last bar
*/
public void setPercentageFreeAfterSeries(int percentageFreeAfterSeries)
{
getBarChartRenderer().setPercentageFreeAfterSeries(percentageFreeAfterSeries);
}
 
/**
* Customizes the bar width by giving a maximum size.
* The maximum width is given on a percentage basis, assuming that 100%
* corresponds
* to the whole space required to display one information category.
* This information is taken into account only if it provides a consistent
* resulting graphic.
* @param percentageBarWidthMax the percentage of bar width max
*/
public void setPercentageBarWidthMax(int percentageBarWidthMax)
{
getBarChartRenderer().setPercentageBarWidthMax(percentageBarWidthMax);
}
 
/**
* Customizes the bar width by giving a minimum size.
* The maximum width is given on a percentage basis, assuming that 100%
* corresponds
* to the whole space required to display one information category.
* This information is taken into account only if it provides a consistent
* resulting graphic.
* @param percentageBarWidthMin the percentage of bar width min
*/
public void setPercentageBarWidthMin(int percentageBarWidthMin)
{
getBarChartRenderer().setPercentageBarWidthMax(percentageBarWidthMin);
}
 
abstract protected BarChartRenderer getBarChartRenderer();
protected SeriesContainer getSeriesContainer(){return _categoryValueSeriesContainer;}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/geographic/IsolineGC.java
New file
0,0 → 1,188
package com.oxymel.ofc.charts.geographic;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.io.*;
import java.util.Vector;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;
 
//ofc
import com.oxymel.ofc.charts.data.grid.Grid;
import com.oxymel.ofc.charts.exception.OFCChartsException;
import com.oxymel.ofc.charts.geographic.Graph;
import com.oxymel.ofc.charts.data.grid.Ridge;
import com.oxymel.ofc.charts.data.Point2D;
import com.oxymel.ofc.charts.exception.OFCChartsRuntimeException;
import com.oxymel.ofc.charts.util.OFCMath;
import com.oxymel.ofc.charts.util.ContainerTools;
 
import com.oxymel.ofc.charts.data.grid.RegularGrid;
import com.oxymel.ofc.charts.interpolation.PointContainer;
import com.oxymel.ofc.charts.interpolation.InvertDistanceSquareInterpolation;
import com.oxymel.ofc.charts.interpolation.LaporteInterpolation;
import com.oxymel.ofc.charts.interpolation.InterpolationMethod;
 
/**
*
* <p>Title: Isoline</p>
* <p>Description: Generate isolines. </p>
*/
public class IsolineGC
{
private static final String GC_HEADER = "//$VERSION 5.0\n//$DELIMITER \"tab\"\n//$QUOTED-TEXT \"no\"\n//$CHARSET ANSI\n//$UNIT Distance:m\n//$FORMAT 2\n//$SYSCOORD {Type:1}\n";
 
private Isoline _isoline;
private String _typeName = "isoType";
private String _subTypeName = "isoSubType";
 
public IsolineGC(PointContainer pointContainer, InterpolationMethod interpolationMethode, int nbLine, int nbColumn,
double zStep)
{
RegularGrid grid = new RegularGrid(nbLine, nbColumn,
pointContainer.getStepXOfGridContainsAllPoint(nbColumn), pointContainer.getStepYOfGridContainsAllPoint(nbLine),
pointContainer.getXMin(), pointContainer.getYMin());
long startTimeMillis = System.currentTimeMillis();
System.out.println("start interpolateAllZ");
grid.interpolateAllZ(pointContainer.getAllPoint(), interpolationMethode);
System.out.println("end interpolateAllZ" + "- Nb ms = " + (System.currentTimeMillis() - startTimeMillis));
 
/*
double zMin = grid.getZMin();
double zStart = (((int)(zMin / zStep)) * zStep);
if(zMin < 0){
zStart -= zStep;
}
*/
 
_isoline = new Isoline(grid, zStep);
}
 
 
public void writeIsoline(String fileName) throws Exception
{
long startTimeMillis = System.currentTimeMillis();
System.out.println("start compute isoline graph");
Graph graph = _isoline.getGraph();
System.out.println("end compute isoline graph" + "- Nb ms = " + (System.currentTimeMillis() - startTimeMillis));
 
FileWriter writer = new FileWriter(fileName);
writer.write(GC_HEADER);
 
startTimeMillis = System.currentTimeMillis();
System.out.println("start write GC format");
int nbIsoline = 0;
Enumeration enumAllArc = graph.getEnumAllArc();
while(enumAllArc.hasMoreElements()){
nbIsoline++;
Arc arc = (Arc)enumAllArc.nextElement();
//System.out.println("arc" + nbArc + " = " + arc.toString());
StringBuffer strBuffer = getArcAsGCFormat(arc, nbIsoline);
writer.write(strBuffer.toString());
 
}
System.out.println("nbIsoline = " + nbIsoline);
System.out.println("end write GC format" + "- Nb ms = " + (System.currentTimeMillis() - startTimeMillis));
}
 
private StringBuffer getArcAsGCFormat(Arc arc, int arcId)
{
StringBuffer stringBuffer = new StringBuffer();
 
Vertex initialVertex = arc.getInitialVertex();
Vertex finalVertex = arc.getFinalVertex();
 
//identificateur
stringBuffer.append(arcId);
stringBuffer.append("\t");
 
//type
stringBuffer.append(_typeName);
stringBuffer.append("\t");
 
//sous type
stringBuffer.append(_subTypeName);
stringBuffer.append("\t");
 
//nom de objet
stringBuffer.append("\t");
 
//nombre de champs
stringBuffer.append("1\t");
 
//Z
stringBuffer.append(arc.getValue());
stringBuffer.append("\t");
 
 
// X Sommet init
stringBuffer.append(initialVertex.getX());
stringBuffer.append("\t");
 
 
// Y Sommet init
stringBuffer.append(initialVertex.getY());
stringBuffer.append("\t");
 
// X Sommet fin
stringBuffer.append(finalVertex.getX());
stringBuffer.append("\t");
 
// Y Sommet fin
stringBuffer.append(finalVertex.getY());
stringBuffer.append("\t");
 
Vector allIntermediaryPoint = arc.getAllIntermediaryPoint();
 
//Nombre de point de l'objet
stringBuffer.append(allIntermediaryPoint.size() + 1);
stringBuffer.append("\t");
 
//double xPred = initialVertex.getX();
//double yPred = initialVertex.getY();
for(int i=0; i< allIntermediaryPoint.size(); i++){
Point2D intermediaryPoint = (Point2D)allIntermediaryPoint.elementAt(i);
 
//X relatif Pt Inter par rapport point precedent
//double xCurrent = intermediaryPoint.getX();
//stringBuffer.append(xCurrent - xPred);
stringBuffer.append(intermediaryPoint.getX());
stringBuffer.append("\t");
 
//Y relatif Pt Inter par rapport point precedent
//double yCurrent = intermediaryPoint.getY();
//stringBuffer.append(yCurrent - yPred);
stringBuffer.append(intermediaryPoint.getY());
stringBuffer.append("\t");
 
//xPred = xCurrent;
//yPred = yCurrent;
 
}
 
stringBuffer.append(finalVertex.getX());
stringBuffer.append("\t");
stringBuffer.append(finalVertex.getY());
stringBuffer.append("\t");
 
 
stringBuffer.append("\n");
return stringBuffer;
}
 
/*
public static void main(String[] argv) throws Exception
{
}
*/
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/geographic/Vertex.java
New file
0,0 → 1,100
package com.oxymel.ofc.charts.geographic;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import java.util.Vector;
import java.util.Enumeration;
 
//ofc
import com.oxymel.ofc.charts.data.Point2D;
import com.oxymel.ofc.charts.util.Segment;
 
/**
*
* <p>Title: Point2D </p>
* <p>Description: Manage Point2D</p>
*/
public class Vertex extends Point2D
{
private Vector _allArcGoIn = new Vector();
private Vector _allArcGoOut = new Vector();
 
/**
* Constructor
* @param x X of point
* @param y Y of Point
*/
public Vertex(double x, double y)
{
super(x, y);
}
 
static public String getKey(double x, double y)
{
StringBuffer key = new StringBuffer();
key.append("X");
key.append(x);
key.append("Y");
key.append(y);
return key.toString();
}
 
public boolean isOnSegment(double xInitial, double yInitial, double xFinal, double yFinal)
{
return Segment.isPointOnSegment(getX(), getY(),
xInitial, yInitial, xFinal, yFinal);
}
 
public int getNbArcGoIn(){return _allArcGoIn.size();}
public int getNbArcGoOut(){return _allArcGoOut.size();}
 
public Enumeration getEnumAllArcGoInOut(Arc arcToExclude)
{
return getArcGoInOut(arcToExclude).elements();
}
 
Vector getArcGoInOut(Arc arcToExclude)
{
Vector allArcGoInOut = new Vector();
 
for(int i=0;i<_allArcGoIn.size();i++){
Arc arc = (Arc)_allArcGoIn.elementAt(i);
if(!arc.equals(arcToExclude)){
allArcGoInOut.addElement(arc);
}
}
 
for(int i=0;i<_allArcGoOut.size();i++){
Arc arc = (Arc)_allArcGoOut.elementAt(i);
if(!arc.equals(arcToExclude)){
allArcGoInOut.addElement(arc);
}
}
 
return allArcGoInOut;
}
 
public void clearAllArcGoInOut()
{
_allArcGoIn.clear();
_allArcGoOut.clear();
}
 
public void addArcGoIn(Arc arc)
{
_allArcGoIn.addElement(arc);
}
 
public void addArcGoOut(Arc arc)
{
_allArcGoOut.addElement(arc);
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/geographic/Face.java
New file
0,0 → 1,146
package com.oxymel.ofc.charts.geographic;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import java.util.Vector;
import java.util.Enumeration;
 
//ofc
import com.oxymel.ofc.charts.data.Point2D;
 
/**
*
*/
public class Face
{
 
private Vector _allArc = new Vector();
private Rectangle _boundingRectangle = null;
private double _minValue;
private double _maxValue;
private boolean _isIntervalValueDefined = false;
 
boolean _isArcFirstInGoodDirection = true;
 
/**
* Constructor
*/
public Face()
{
}
 
public boolean isArcFirstInGoodDirection(){return _isArcFirstInGoodDirection;}
public void setIsArcFirstInGoodDirection(boolean isArcFirstInGoodDirection){_isArcFirstInGoodDirection = isArcFirstInGoodDirection;}
 
public void addArc(Arc arc)
{
_allArc.addElement(arc);
}
 
public Enumeration getEnumAllArc()
{
return _allArc.elements();
}
 
public boolean isIntervalValueDefined(){return _isIntervalValueDefined;}
public double getMinValue(){return _minValue;}
public double getMaxValue(){return _maxValue;}
public void setIntervalValue()
{
if(_allArc.size() == 0){
return;
}
 
int firstArcPosition = 0;
for(firstArcPosition=0; firstArcPosition<_allArc.size(); firstArcPosition++){
Arc arcCurrent = (Arc)_allArc.elementAt(firstArcPosition);
if(arcCurrent.isValueDefined()){
_isIntervalValueDefined = true;
_minValue = arcCurrent.getValue();
_maxValue = arcCurrent.getValue();
break;
}
}
 
for(int i=firstArcPosition+1; i<_allArc.size(); i++){
Arc arcCurrent = (Arc)_allArc.elementAt(i);
if(arcCurrent.isValueDefined()){
_minValue = Math.min(arcCurrent.getValue(), _minValue);
_maxValue = Math.max(arcCurrent.getValue(), _maxValue);
}
}
}
 
public void setIntervalValue(double value)
{
_minValue = Math.min(value, _minValue);
_maxValue = Math.max(value, _maxValue);
_isIntervalValueDefined = true;
}
 
public void setIntervalValue(double minValue, double maxValue)
{
_minValue = minValue;
_maxValue = maxValue;
_isIntervalValueDefined = true;
}
 
public Rectangle getBoundingRectangle()
{
if(_boundingRectangle != null){
return _boundingRectangle;
}
 
double xMin = 0;
double yMin = 0;
double xMax = 0;
double yMax = 0;
 
if(_allArc.size() == 0){
_boundingRectangle = new Rectangle(xMin, yMin, xMax, yMax);
return _boundingRectangle;
}else{
Arc arc = (Arc)_allArc.elementAt(0);
Rectangle rectangle = arc.getBoundingRectangle();
xMin = rectangle.getXMin();
yMin = rectangle.getYMin();
xMax = rectangle.getXMax();
yMax = rectangle.getYMax();
}
 
for(int i=0;i<_allArc.size();i++){
Arc arc = (Arc)_allArc.elementAt(i);
Rectangle rectangle = arc.getBoundingRectangle();
xMin = Math.min(rectangle.getXMin(), xMin);
yMin = Math.min(rectangle.getYMin(), yMin);
xMax = Math.max(rectangle.getXMax(), xMax);
yMax = Math.max(rectangle.getYMax(), yMax);
}
 
_boundingRectangle = new Rectangle(xMin, yMin, xMax, yMax);
return _boundingRectangle;
}
 
public boolean isPointOnLimit(double x, double y)
{
for(int i=0;i<_allArc.size();i++){
Arc arc = (Arc)_allArc.elementAt(i);
if(arc.isPointOnArc(x, y)){
return true;
}
}
return false;
}
 
public String toString()
{
return "minValue = " + _minValue + " - maxValue = " + _maxValue;
}
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/geographic/Point3D.java
New file
0,0 → 1,43
package com.oxymel.ofc.charts.geographic;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import java.util.Vector;
 
import com.oxymel.ofc.charts.data.Point2D;
 
public class Point3D extends Point2D
{
private double _z;
 
/**
* Constructor
* @param x X of point
* @param y Y of Point
*/
public Point3D(double x, double y, double z)
{
super(x, y);
_z = z;
}
 
public double getZ()
{
return _z;
}
 
 
public String toString()
{
return super.toString() + " - z = " + getZ();
}
 
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/geographic/Graph.java
New file
0,0 → 1,414
package com.oxymel.ofc.charts.geographic;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import java.util.Vector;
import java.util.Enumeration;
import java.util.Hashtable;
 
//ofc
import com.oxymel.ofc.charts.data.Point2D;
import com.oxymel.ofc.charts.data.grid.Grid;
import com.oxymel.ofc.charts.exception.OFCChartsRuntimeException;
 
/**
*
*/
public class Graph
{
Hashtable _allVertex = new Hashtable();
Vector _allArc = new Vector();
 
/**
* Constructor
*/
public Graph()
{
 
}
 
/*
public Graph clone(Enumeration allArcToClone)
{
Graph graphClone = new Graph();
while(allArcToClone.hasMoreElements()){
Arc arc = (Arc)allArcToClone.nextElement();
graphClone.addElement();
}
return graphClone;
}
 
private void addArcToClone(Arc)
{
_allArc.
}
*/
 
public boolean isArcExist(double xInitialVertex, double yInitialVertex, Vector allIntermediaryPoint,
double xFinalVertex, double yFinalVertex)
{
Enumeration enumAllArc = getEnumAllArc();
while(enumAllArc.hasMoreElements()){
Arc arc = (Arc)enumAllArc.nextElement();
Vertex initialVertex = arc.getInitialVertex();
if(initialVertex.isSameXY(xInitialVertex, yInitialVertex)){
Vertex finalVertex = arc.getFinalVertex();
if(finalVertex.isSameXY(xFinalVertex, yFinalVertex)){
if(arc.isIntermediaryPointEquals(allIntermediaryPoint)){
return true;
}
}
}
}
return false;
}
 
public Arc addArc(double xInitialVertex, double yInitialVertex, Vector allIntermediaryPoint,
double xFinalVertex, double yFinalVertex, double value)
{
Arc arc = new Arc(getVertex(xInitialVertex, yInitialVertex), allIntermediaryPoint,
getVertex(xFinalVertex, yFinalVertex), value);
_allArc.addElement(arc);
return arc;
}
 
public Arc addArc(Arc arcToAdd)
{
Arc arc = new Arc(getVertex(arcToAdd.getInitialVertex().getX(), arcToAdd.getInitialVertex().getY()), arcToAdd.getAllIntermediaryPoint(),
getVertex(arcToAdd.getFinalVertex().getX(), arcToAdd.getFinalVertex().getY()));
_allArc.addElement(arc);
return arc;
}
 
public void addAllArc(Enumeration enumAllArc)
{
while(enumAllArc.hasMoreElements()){
Arc arc = (Arc)enumAllArc.nextElement();
if(!isArcExist(arc)){
arc.reverse();
if(!isArcExist(arc)){
arc.reverse();
addArc(arc);
}else{
arc.reverse();
}
}
}
}
 
public void setArcIntersection(Vertex vertex)
{
Enumeration enumAllArc = getEnumAllArc();
while(enumAllArc.hasMoreElements()){
Arc arc = (Arc)enumAllArc.nextElement();
if(setArcIntersection(arc, vertex)){
return;
}
}
}
 
public Face getFace(Arc arcStart, boolean isFindInArcDirection)
{
//System.out.println("******* Start FACE");
//System.out.println("arcStart = " + arcStart.toString());
Face face = new Face();
face.setIsArcFirstInGoodDirection(isFindInArcDirection);
face.addArc(arcStart);
Arc arcCurrent = arcStart;
boolean isArcCurrentInGoodDirection = isFindInArcDirection;
 
Vertex currentVertexFinal;
if(isArcCurrentInGoodDirection){
currentVertexFinal = arcCurrent.getFinalVertex();
}else{
currentVertexFinal = arcCurrent.getInitialVertex();
}
Arc arcSuccessor = arcCurrent.getArcMoreAtLeftSuccessor(isArcCurrentInGoodDirection);
while(arcSuccessor != null){
boolean isArcSuccessorInGoodDirection = (arcSuccessor.getInitialVertex().equals(currentVertexFinal));
//System.out.println("arcSuccessor = " + arcSuccessor.toString());
 
face.addArc(arcSuccessor);
arcCurrent = arcSuccessor;
isArcCurrentInGoodDirection = isArcSuccessorInGoodDirection;
if(isArcCurrentInGoodDirection){
currentVertexFinal = arcCurrent.getFinalVertex();
arcCurrent.setIsTraveledInThisDirection();
}else{
currentVertexFinal = arcCurrent.getInitialVertex();
arcCurrent.setIsTraveledInOppositeDirection();
}
arcSuccessor = arcCurrent.getArcMoreAtLeftSuccessor(isArcCurrentInGoodDirection);
if(arcSuccessor != null){
if(arcSuccessor.equals(arcStart)){
arcSuccessor = null;
}
}
}
//System.out.println("******* End FACE");
return face;
}
 
private boolean isArcExist(Arc arc)
{
Vertex initialVertex = arc.getInitialVertex();
Vertex finalVertex = arc.getFinalVertex();
return isArcExist(initialVertex.getX(), initialVertex.getY(), arc.getAllIntermediaryPoint(),
finalVertex.getX(), finalVertex.getY());
}
 
private boolean setArcIntersection(Arc arcToIntersect, Vertex vertexIntersection)
{
if(vertexIntersection.isSameXY(arcToIntersect.getInitialVertex())){
return true;
}
if(vertexIntersection.isSameXY(arcToIntersect.getFinalVertex())){
return true;
}
 
double xInitial = arcToIntersect.getInitialVertex().getX();
double yInitial = arcToIntersect.getInitialVertex().getY();
Vector allIntermediaryPoint = arcToIntersect.getAllIntermediaryPoint();
double xIntersection = vertexIntersection.getX();
double yIntersection = vertexIntersection.getY();
 
if(allIntermediaryPoint.size() == 0){
double xFinal = arcToIntersect.getFinalVertex().getX();
double yFinal = arcToIntersect.getFinalVertex().getY();
if(vertexIntersection.isOnSegment(xInitial, yInitial, xFinal, yFinal)){
_allArc.remove(arcToIntersect);
Arc arcFirst = new Arc(getVertex(xInitial, yInitial), getVertex(xIntersection, yIntersection));
_allArc.addElement(arcFirst);
Arc arcSecond = new Arc(getVertex(xIntersection, yIntersection), getVertex(xFinal, yFinal));
_allArc.addElement(arcSecond);
return true;
}
return false;
}
 
double xPred = xInitial;
double yPred = yInitial;
Point2D pointPred = null;
boolean isPredInitialVertex = true;
Vector allIntermediaryPointFirstArc = new Vector();
Vector allIntermediaryPointSecondArc = new Vector();
boolean isArcIntersected = false;
for(int i=0; i< allIntermediaryPoint.size(); i++){
Point2D pointCurrent = (Point2D)allIntermediaryPoint.elementAt(i);
double xCurrent = pointCurrent.getX();
double yCurrent = pointCurrent.getY();
if(!isArcIntersected){
if(vertexIntersection.isOnSegment(xPred, yPred, xCurrent, yCurrent)){
isArcIntersected = true;
}
if(!isPredInitialVertex){
if(!pointPred.isSameXY(xIntersection, yIntersection)){
allIntermediaryPointFirstArc.addElement(pointPred);
}
}
}else{
if(!isPredInitialVertex){
if(!pointPred.isSameXY(xIntersection, yIntersection)){
allIntermediaryPointSecondArc.addElement(pointPred);
}
}
}
xPred = xCurrent;
yPred = yCurrent;
pointPred = pointCurrent;
isPredInitialVertex = false;
}
 
double xFinal = arcToIntersect.getFinalVertex().getX();
double yFinal = arcToIntersect.getFinalVertex().getY();
if(!isArcIntersected){
if(vertexIntersection.isOnSegment(xPred, yPred, xFinal, yFinal)){
isArcIntersected = true;
}
if(!isPredInitialVertex){
if(!pointPred.isSameXY(xIntersection, yIntersection)){
allIntermediaryPointFirstArc.addElement(pointPred);
}
}
}else{
if(!isPredInitialVertex){
if(!pointPred.isSameXY(xIntersection, yIntersection)){
allIntermediaryPointSecondArc.addElement(pointPred);
}
}
}
 
if(isArcIntersected){
_allArc.remove(arcToIntersect);
Arc arcFirst = new Arc(getVertex(xInitial, yInitial), allIntermediaryPointFirstArc, getVertex(xIntersection, yIntersection));
_allArc.addElement(arcFirst);
Arc arcSecond = new Arc(getVertex(xIntersection, yIntersection), allIntermediaryPointSecondArc, getVertex(xFinal, yFinal));
_allArc.addElement(arcSecond);
}
return isArcIntersected;
}
 
public Enumeration getEnumAllArc(){return _allArc.elements();}
 
public Vector getAllArcOpen()
{
Vector allArcToFind = new Vector();
for(int i=0;i<_allArc.size();i++){
Arc arc = (Arc)_allArc.elementAt(i);
if(!arc.getInitialVertex().equals(arc.getFinalVertex())){
allArcToFind.addElement(arc);
}
}
return allArcToFind;
}
 
public Vector getAllArcClose()
{
Vector allArcToFind = new Vector();
for(int i=0;i<_allArc.size();i++){
Arc arc = (Arc)_allArc.elementAt(i);
if(arc.getInitialVertex().equals(arc.getFinalVertex())){
allArcToFind.addElement(arc);
}
}
return allArcToFind;
}
 
static public Arc getBoundingArc(Grid grid)
{
Enumeration enumAllPointBorderGrid = grid.getEnumAllBorderPointInHorlogeDirection();
if(!enumAllPointBorderGrid.hasMoreElements()){
throw new OFCChartsRuntimeException("Grid data error");
}
 
Point2D pointTopLeftGrid = (Point2D)enumAllPointBorderGrid.nextElement();
Vertex vertex = new Vertex(pointTopLeftGrid.getX(), pointTopLeftGrid.getY()) ;
 
Vector allIntermediaryPoint = new Vector();
while(enumAllPointBorderGrid.hasMoreElements()){
Point2D point = (Point2D)enumAllPointBorderGrid.nextElement();
allIntermediaryPoint.addElement(point);
}
return new Arc(vertex, allIntermediaryPoint, vertex);
 
/*
double xInitial = grid.getX(0,0);
double yInitial = grid.getY(0,0);
Vertex vertex = new Vertex(xInitial, yInitial) ;
Vector allIntermediaryPoint = new Vector();
allIntermediaryPoint.addElement(new Point2D(
grid.getX(0, grid.getNbColumn() - 1),
grid.getY(0, grid.getNbColumn() - 1)));
allIntermediaryPoint.addElement(new Point2D(
grid.getX(grid.getNbLine() - 1, grid.getNbColumn() - 1),
grid.getY(grid.getNbLine() - 1, grid.getNbColumn() - 1)));
allIntermediaryPoint.addElement(new Point2D(
grid.getX(grid.getNbLine() - 1, 0),
grid.getY(grid.getNbLine() - 1, 0)));
 
return new Arc(vertex, allIntermediaryPoint, vertex);
*/
/*
double xInitial = grid.getX(0,0);
double yInitial = grid.getY(0,0);
Vector allIntermediaryPoint = new Vector();
int nbColumn = grid.getNbColumn();
int nbLine = grid.getNbLine();
for(int i=1; i< nbColumn; i++){
double xCurrent = grid.getX(0,i);
double yCurrent = grid.getY(0,i);
allIntermediaryPoint.addElement(new Point2D(xCurrent, yCurrent));
}
int numColumnLast = nbColumn - 1;
for(int i=0; i< nbLine; i++){
double xCurrent = grid.getX(i, numColumnLast);
double yCurrent = grid.getY(i, numColumnLast);
allIntermediaryPoint.addElement(new Point2D(xCurrent, yCurrent));
}
int numLineLast = nbLine - 1;
for(int i=numColumnLast; i >= 0; i--){
double xCurrent = grid.getX(numLineLast,i);
double yCurrent = grid.getY(numLineLast,i);
allIntermediaryPoint.addElement(new Point2D(xCurrent, yCurrent));
}
for(int i=numLineLast; i > 0; i--){
double xCurrent = grid.getX(i, 0);
double yCurrent = grid.getY(i, 0);
allIntermediaryPoint.addElement(new Point2D(xCurrent, yCurrent));
}
 
Vertex vertex = new Vertex(xInitial, yInitial) ;
return new Arc(vertex, allIntermediaryPoint, vertex);
*/
}
 
public void setArcGoInOutForAllVertex()
{
Enumeration enumAllVertex = _allVertex.elements();
while(enumAllVertex.hasMoreElements()){
Vertex vertex = (Vertex)enumAllVertex.nextElement();
vertex.clearAllArcGoInOut();
}
 
for(int i=0; i<_allArc.size();i++){
Arc arc = (Arc)_allArc.elementAt(i);
Vertex initialVertex = arc.getInitialVertex();
initialVertex.addArcGoOut(arc);
Vertex finalVertex = arc.getFinalVertex();
finalVertex.addArcGoIn(arc);
}
 
}
 
public void displayAllVertexInfo()
{
Enumeration enumAllVertex = _allVertex.elements();
while(enumAllVertex.hasMoreElements()){
Vertex vertex = (Vertex)enumAllVertex.nextElement();
System.out.println("X = " + vertex.getX() + " - Y = " + vertex.getY() +
" - Nb Arc Go IN = " + vertex.getNbArcGoIn() + " - Nb Arc Go OUT = " + vertex.getNbArcGoOut());
}
}
 
 
public void displayAllArcInfo()
{
Enumeration enumAllArc = _allArc.elements();
System.out.println("**START All Arc Info");
int i = 0;
while(enumAllArc.hasMoreElements()){
i++;
Arc arc = (Arc)enumAllArc.nextElement();
System.out.println("Arc" + i+ " = " + arc.toString());
}
System.out.println("**End All Arc Info");
}
 
 
 
private Vertex getVertex(double x, double y)
{
String vertexKey = Vertex.getKey(x, y);
Vertex vertex = (Vertex)_allVertex.get(vertexKey);
/*
if(vertex == null){
System.out.println("New Vertex");
}else{
System.out.println("Old Vertex");
}
*/
if(vertex == null){
vertex = new Vertex(x, y);
_allVertex.put(vertexKey, vertex);
}
return vertex;
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/geographic/Isoline.java
New file
0,0 → 1,838
package com.oxymel.ofc.charts.geographic;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.io.*;
import java.util.Vector;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;
 
//ofc
import com.oxymel.ofc.charts.data.grid.Grid;
import com.oxymel.ofc.charts.exception.OFCChartsException;
import com.oxymel.ofc.charts.geographic.Graph;
import com.oxymel.ofc.charts.data.grid.Ridge;
import com.oxymel.ofc.charts.data.Point2D;
import com.oxymel.ofc.charts.exception.OFCChartsRuntimeException;
import com.oxymel.ofc.charts.util.OFCMath;
import com.oxymel.ofc.charts.util.ContainerTools;
 
/**
*
* <p>Title: Isoline</p>
* <p>Description: Generate isolines. </p>
*/
public class Isoline
{
private Grid _grid;
private double _zStart;
private double _zEnd;
private double _zStep;
 
//
private Graph _graph = null;
private Vector _allFace = null;
private Vector _allFaceOrdered = null;
 
public Isoline(Grid grid, double zStart, double zEnd, double zStep)
{
_zStart = zStart;
_zEnd = zEnd;
setParameters(grid, zStep);
}
 
public Isoline(Grid grid, double zStep)
{
setParameters(grid, zStep);
double zMin = grid.getZMin();
_zStart = (((int)(zMin / _zStep)) * _zStep);
if(zMin < 0){
_zStart -= _zStep;
}
_zEnd = _grid.getZMax();
}
 
private void setParameters(Grid grid, double isolineStep)
{
_grid = grid;
if(isolineStep == 0){
throw new OFCChartsRuntimeException("Invalid isoline step");
}
_zStep = Math.abs(isolineStep);
//_zStep = isolineStep;
_graph = null;
_allFace = null;
_allFaceOrdered = null;
}
 
 
public Graph getGraph()
{
if(_graph != null){
return _graph;
}
_graph = new Graph();
//double zCurrent = _grid.getZMin();
double zCurrent = _zStart;
//double zMax = _grid.getZMax();
double zMax = _zEnd;
//long startTimeMillis = System.currentTimeMillis();
while(zCurrent <= zMax){
//long currentTimeMillis = System.currentTimeMillis();
getIsolineGraph(zCurrent, _graph);
//System.out.println("** End Compute Isoline = " + zCurrent + " Nb ms = " + (System.currentTimeMillis() - currentTimeMillis));
zCurrent += _zStep;
//System.out.println("zCurrent = " + zCurrent + " _zStep = " + _zStep);
}
//System.out.println("***** End Compute All Isoline - Nb ms = " + (System.currentTimeMillis() - startTimeMillis));
return _graph;
}
 
public Enumeration getEnumAllFace()
{
return getAllFace().elements();
}
 
private Vector getAllFace()
{
if(_allFace != null){
return _allFace;
}
 
_allFace = new Vector();
 
Graph isolineGraph = getGraph();
Vector allArcIsolineOpen = isolineGraph.getAllArcOpen();
Graph graphClose = getGraphOpenIsolineClosedByGrid(allArcIsolineOpen);
 
//System.out.println("***** graphClose Start displayAllVertexInfo");
//graphClose.displayAllVertexInfo();
//System.out.println("***** graphClose End displayAllVertexInfo");
 
isolineGraph.addAllArc(graphClose.getEnumAllArc());
isolineGraph.setArcGoInOutForAllVertex();
 
//System.out.println("***** Start displayAllVertexInfo");
//isolineGraph.displayAllVertexInfo();
//System.out.println("***** End displayAllVertexInfo");
 
for(int i=0; i<allArcIsolineOpen.size();i++){
Arc arc = (Arc)allArcIsolineOpen.elementAt(i);
if(!arc.isTraveledInThisDirection()){
Face face = isolineGraph.getFace(arc, true);
setIntervalValueOfFaceOnGridBorder(face, arc);
_allFace.addElement(face);
}
}
 
for(int i=0; i<allArcIsolineOpen.size();i++){
Arc arc = (Arc)allArcIsolineOpen.elementAt(i);
if(!arc.isTraveledInOppositeDirection()){
Face face = isolineGraph.getFace(arc, false);
setIntervalValueOfFaceOnGridBorder(face, arc);
_allFace.addElement(face);
}
}
 
Vector allArcIsolineClose = isolineGraph.getAllArcClose();
for(int i=0; i<allArcIsolineClose.size();i++){
Arc arc = (Arc)allArcIsolineClose.elementAt(i);
Face face = new Face();
face.addArc(arc);
face.setIntervalValue();
_allFace.addElement(face);
}
 
return _allFace;
}
 
public Enumeration getEnumAllFaceOrderByDisplayPosition()
{
return getAllFaceOrderByDisplayPosition().elements();
}
 
private void setIntervalValueOfFaceOnGridBorder(Face face, Arc arcOpenIsoline)
{
//case : face with different isoline
face.setIntervalValue();
if(face.getMinValue() != face.getMaxValue()){
return;
}
 
//case : open isoline = close isoline
int nbIsoline = 0;
Enumeration enumAllArc = face.getEnumAllArc();
while(enumAllArc.hasMoreElements()){
Arc arc = (Arc)enumAllArc.nextElement();
if(arc.isValueDefined()){
nbIsoline ++;
if(nbIsoline > 1){
return;
}
}
}
 
//other case = face with only one isoline
Hashtable allRidge = getAllRidgeIntersecteByOpenIsoline(arcOpenIsoline.getValue());
 
double value = getValueOfFaceOnGridBorder(allRidge.elements(), arcOpenIsoline.getInitialVertex(), face, arcOpenIsoline);
if(value != arcOpenIsoline.getValue()){
face.setIntervalValue(value);
return;
}
 
face.setIntervalValue(getValueOfFaceOnGridBorder(allRidge.elements(), arcOpenIsoline.getFinalVertex(), face, arcOpenIsoline));
}
 
private double getValueOfFaceOnGridBorder(Enumeration enumAllRidge, Vertex vertexToCompare, Face face, Arc arcOpenIsoline)
{
while(enumAllRidge.hasMoreElements()){
Ridge ridge = (Ridge)enumAllRidge.nextElement();
if(vertexToCompare.isOnSegment(ridge.getXInitialNode(_grid), ridge.getYInitialNode(_grid),
ridge.getXFinalNode(_grid), ridge.getYFinalNode(_grid))){
int lineNumber = ridge.getLineNumberInitialNode();
int columnNumber = ridge.getColumnNumberInitialNode();
double x = _grid.getX(lineNumber, columnNumber);
double y = _grid.getY(lineNumber, columnNumber);
if((!vertexToCompare.isSameXY(x, y)) && (face.isPointOnLimit(x, y))) {
return _grid.getZ(lineNumber, columnNumber);
}
 
lineNumber = ridge.getLineNumberFinalNode();
columnNumber = ridge.getColumnNumberFinalNode();
x = _grid.getX(lineNumber, columnNumber);
y = _grid.getY(lineNumber, columnNumber);
if((!vertexToCompare.isSameXY(x, y)) && (face.isPointOnLimit(x, y))) {
return _grid.getZ(lineNumber, columnNumber);
}
}
}
return arcOpenIsoline.getValue();
}
 
 
private Vector getAllFaceOrderByDisplayPosition()
{
if(_allFaceOrdered != null){
return _allFaceOrdered;
}
 
_allFaceOrdered = new Vector();
Vector allFace = getAllFace();
if(allFace.size() == 0){
return _allFaceOrdered;
}else{
_allFaceOrdered.addElement(allFace.elementAt(0));
}
for(int i=1; i< allFace.size(); i++){
Face face = (Face)allFace.elementAt(i);
boolean isFaceAdd = false;
Rectangle rectangle = face.getBoundingRectangle();
for(int j=0; j < _allFaceOrdered.size(); j++){
Face faceOrdered = (Face)_allFaceOrdered.elementAt(j);
Rectangle rectangleOrdered = faceOrdered.getBoundingRectangle();
if(rectangleOrdered.isIncludeIn(rectangle)){
_allFaceOrdered.insertElementAt(face, j);
isFaceAdd = true;
break;
}
}
if(!isFaceAdd){
_allFaceOrdered.addElement(face);
}
}
 
if(_allFaceOrdered.size() > 1){
Face firstFace = (Face)_allFaceOrdered.elementAt(0);
if(!firstFace.isIntervalValueDefined()){
//case : univers not defined = no isoline open
Face includeFace = (Face)_allFaceOrdered.elementAt(1);
double includeFaceValue = includeFace.getMinValue();
firstFace.setIntervalValue(includeFaceValue - _zStep, includeFaceValue);
}
}
if(_allFaceOrdered.size() == 1){
//only univers = grid limit. No isoline found
double zMin = _grid.getZMin();
double zMax = _grid.getZMax();
//if(zMin == zMax){
//cas = zoom on isoline closed. limite of isoline are not visible in grid scope
Face firstFace = (Face)_allFaceOrdered.elementAt(0);
firstFace.setIntervalValue(zMin, zMax);
//}
}
return _allFaceOrdered;
}
 
public Graph getClosedGraph()
{
Graph isolineGraph = getGraph();
Vector allArcIsolineOpen = isolineGraph.getAllArcOpen();
Graph graphClose = getGraphOpenIsolineClosedByGrid(allArcIsolineOpen);
graphClose.addAllArc(isolineGraph.getAllArcClose().elements());
graphClose.addAllArc(allArcIsolineOpen.elements());
return graphClose;
}
 
private Graph getGraphOpenIsolineClosedByGrid(Vector allOpenIsolineArc)
{
Graph graph = new Graph();
graph.addArc(Graph.getBoundingArc(_grid));
 
//tmp:
//Arc toto = Graph.getBoundingArc(_grid);
//System.out.println("getBoundingArc = " + toto.toString());
 
for(int i=0; i<allOpenIsolineArc.size(); i++){
Arc arc = (Arc)allOpenIsolineArc.elementAt(i);
 
//System.out.println("getInitialVertex = " + arc.getInitialVertex().toString() );
graph.setArcIntersection(arc.getInitialVertex());
// graph.displayAllArcInfo();
 
//System.out.println("getFinalVertex = " + arc.getFinalVertex().toString());
graph.setArcIntersection(arc.getFinalVertex());
//graph.displayAllArcInfo();
}
 
return graph;
}
 
 
private Graph getIsolineGraph(double zIsoline, Graph graph)
{
//long currentTimeMillis = System.currentTimeMillis();
Hashtable allRidgeIntersectByOpenIsoline = getAllRidgeIntersecteByOpenIsoline(zIsoline);
//System.out.println("getAllRidgeIntersecteByOpenIsoline Nb ms = " + (System.currentTimeMillis() - currentTimeMillis));
 
//currentTimeMillis = System.currentTimeMillis();
Hashtable allRidgeIntersectByIsoline = getAllRidgeIntersecteByClosedIsoline(zIsoline);
//System.out.println("getAllRidgeIntersecteByClosedIsoline Nb ms = " + (System.currentTimeMillis() - currentTimeMillis));
 
//currentTimeMillis = System.currentTimeMillis();
allRidgeIntersectByIsoline.putAll(allRidgeIntersectByOpenIsoline);
//System.out.println("putAll in Hashtable Nb ms = " + (System.currentTimeMillis() - currentTimeMillis));
 
//currentTimeMillis = System.currentTimeMillis();
getGraphAllOpenIsoline(allRidgeIntersectByOpenIsoline, allRidgeIntersectByIsoline, zIsoline, graph);
//System.out.println("getGraphAllOpenIsoline Nb ms = " + (System.currentTimeMillis() - currentTimeMillis));
 
//currentTimeMillis = System.currentTimeMillis();
getGraphAllCloseIsoline(allRidgeIntersectByIsoline, zIsoline, graph);
//System.out.println("getGraphAllCloseIsoline Nb ms = " + (System.currentTimeMillis() - currentTimeMillis));
return graph;
}
 
private Hashtable getAllRidgeIntersecteByOpenIsoline(double zIsoline)
{
Hashtable allRidge = new Hashtable();
 
//first line
getHorizontalGridRidgeIntersectByIsoline(0, 0,
0, _grid.getNbColumn() - 2, zIsoline, allRidge);
//last line
getHorizontalGridRidgeIntersectByIsoline(_grid.getNbLine() - 1, _grid.getNbLine() - 1,
0, _grid.getNbColumn() - 2, zIsoline, allRidge);
 
//first column
getVerticalGridRidgeIntersectByIsoline(0, _grid.getNbLine() - 2,
0, 0, zIsoline, allRidge);
//last column
getVerticalGridRidgeIntersectByIsoline(0, _grid.getNbLine() - 2,
_grid.getNbColumn() - 1, _grid.getNbColumn() - 1, zIsoline, allRidge);
 
return allRidge;
}
 
private Hashtable getAllRidgeIntersecteByClosedIsoline(double zIsoline)
{
Hashtable allRidge = new Hashtable();
 
//all line whithout first and last line
getHorizontalGridRidgeIntersectByIsoline(1, _grid.getNbLine() - 2,
0, _grid.getNbColumn() - 2, zIsoline, allRidge);
 
//all column whithout first and last column
getVerticalGridRidgeIntersectByIsoline(0, _grid.getNbLine() - 2,
1, _grid.getNbColumn() - 2, zIsoline, allRidge);
 
return allRidge;
}
 
private void getGraphAllOpenIsoline(Hashtable allRidgeIntersectByOpenIsoline,
Hashtable allRidgeIntersectByIsoline, double zIsoline, Graph graph)
{
Enumeration enumAllRidgeIntersectByOpenIsoline = allRidgeIntersectByOpenIsoline.elements();
while(enumAllRidgeIntersectByOpenIsoline.hasMoreElements()){
Ridge ridge = (Ridge)enumAllRidgeIntersectByOpenIsoline.nextElement();
getGraphOpenIsoline(ridge, allRidgeIntersectByOpenIsoline, allRidgeIntersectByIsoline, zIsoline, graph);
enumAllRidgeIntersectByOpenIsoline = allRidgeIntersectByOpenIsoline.elements();
}
}
 
private void getGraphOpenIsoline(Ridge ridgeStart, Hashtable allRidgeIntersectByOpenIsoline,
Hashtable allRidgeIntersectByIsoline, double zIsoline, Graph graph)
{
//System.out.println("Start getGraphOpenIsoline");
boolean isOneRidgeNodeEqualsToZ = ridgeStart.isRidgeNodeEqualsToZ(zIsoline, _grid);
double xInitialVertex = getXIsolineIntersection(ridgeStart, zIsoline);
double yInitialVertex = getYIsolineIntersection(ridgeStart, zIsoline);
 
double xPredecessorPoint = xInitialVertex;
double yPredecessorPoint = yInitialVertex;
 
//System.out.println("xInitialVertex = " + xInitialVertex + " - yInitialVertex = " + yInitialVertex);
 
allRidgeIntersectByIsoline.remove(ridgeStart.getKey());
allRidgeIntersectByOpenIsoline.remove(ridgeStart.getKey());
Vector allIntermediaryPoint = new Vector();
Ridge lastRidge = ridgeStart;
Ridge currentRidge = getRidgeSuccessor(ridgeStart, allRidgeIntersectByIsoline);
while(currentRidge != null){
if(!isOneRidgeNodeEqualsToZ){
isOneRidgeNodeEqualsToZ = currentRidge.isRidgeNodeEqualsToZ(zIsoline, _grid);
}
double xCurrent = getXIsolineIntersection(currentRidge, zIsoline);
double yCurrent = getYIsolineIntersection(currentRidge, zIsoline);
if(!((xCurrent == xPredecessorPoint) && (yCurrent == yPredecessorPoint))){
allIntermediaryPoint.addElement(new Point2D(xCurrent,yCurrent));
xPredecessorPoint = xCurrent;
yPredecessorPoint = yCurrent;
}
allRidgeIntersectByIsoline.remove(currentRidge.getKey());
allRidgeIntersectByOpenIsoline.remove(currentRidge.getKey());
lastRidge = currentRidge;
currentRidge = getRidgeSuccessor(currentRidge, allRidgeIntersectByIsoline);
}
if(allIntermediaryPoint.size() == 0){
//System.out.println("end return getGraphOpenIsoline");
return;
}
Point2D finalPoint2D = (Point2D)allIntermediaryPoint.lastElement();
allIntermediaryPoint.removeElementAt(allIntermediaryPoint.size()-1);
 
if(isOneRidgeNodeEqualsToZ){
//on essaye d'eliminer le cas suivant visible sur l'exemple ci-apres. soit le maillage suivant:
//3 3 3 3
//4 4 4 4
//5 5 5 5
//4 4 4 4
// on obtient 2 isolines horizontal passant par les noeud 5
//avec une recherche d'isoline=5 on passe 2 fois sur la line des 5
//on a 2 isolines superposées (de direction opposée) car on passe par les memes nodes
if(graph.isArcExist(xInitialVertex, yInitialVertex, allIntermediaryPoint,
finalPoint2D.getX(), finalPoint2D.getY())){
return;
}
ContainerTools.reverseAllElement(allIntermediaryPoint);
if(graph.isArcExist(finalPoint2D.getX(), finalPoint2D.getY(), allIntermediaryPoint,
xInitialVertex, yInitialVertex)){
return;
}
ContainerTools.reverseAllElement(allIntermediaryPoint);
}
 
Arc arc = graph.addArc(xInitialVertex, yInitialVertex, allIntermediaryPoint,
finalPoint2D.getX(), finalPoint2D.getY(), zIsoline);
setIsolineWithUpperZAtLeft(arc, lastRidge);
//System.out.println("return getGraphOpenIsoline");
}
 
private void getGraphAllCloseIsoline(Hashtable allRidgeIntersectByIsoline, double zIsoline, Graph graph)
{
Enumeration enumAllRidgeIntersectByIsoline = allRidgeIntersectByIsoline.elements();
while(enumAllRidgeIntersectByIsoline.hasMoreElements()){
Ridge ridge = (Ridge)enumAllRidgeIntersectByIsoline.nextElement();
getGraphCloseIsoline(ridge, allRidgeIntersectByIsoline, zIsoline, graph);
enumAllRidgeIntersectByIsoline = allRidgeIntersectByIsoline.elements();
}
}
 
private void getGraphCloseIsoline(Ridge ridgeStart, Hashtable allRidgeIntersectByIsoline, double zIsoline, Graph graph)
{
double xInitialVertex = getXIsolineIntersection(ridgeStart, zIsoline);
double yInitialVertex = getYIsolineIntersection(ridgeStart, zIsoline);
allRidgeIntersectByIsoline.remove(ridgeStart.getKey());
Vector allIntermediaryPoint = new Vector();
Ridge currentRidge = getRidgeSuccessor(ridgeStart, allRidgeIntersectByIsoline);
while(currentRidge != null){
allIntermediaryPoint.addElement(new Point2D(
getXIsolineIntersection(currentRidge, zIsoline),
getYIsolineIntersection(currentRidge, zIsoline)));
allRidgeIntersectByIsoline.remove(currentRidge.getKey());
currentRidge = getRidgeSuccessor(currentRidge, allRidgeIntersectByIsoline);
}
//isoline closed have same initial and final vertex
graph.addArc(xInitialVertex, yInitialVertex, allIntermediaryPoint,
xInitialVertex, yInitialVertex, zIsoline);
}
 
private Ridge getRidgeSuccessor(Ridge ridge, Hashtable allRidgeIntersectByIsoline)
{
Ridge successorRidge = null;
switch(ridge.getPositionType()){
case Ridge.RIDGE_HORIZONTAL:
successorRidge = getHorizontalRidgeSuccessorInMeshBottom(ridge, allRidgeIntersectByIsoline);
if(successorRidge == null){
successorRidge = getHorizontalRidgeSuccessorInMeshTop(ridge, allRidgeIntersectByIsoline);
}
break;
case Ridge.RIDGE_VERTICAL:
successorRidge = getVerticalRidgeSuccessorInMeshRight(ridge, allRidgeIntersectByIsoline);
if(successorRidge == null){
successorRidge = getVerticalRidgeSuccessorInMeshLeft(ridge, allRidgeIntersectByIsoline);
}
break;
default:
throw new OFCChartsRuntimeException("Invalid ridge type");
}
return successorRidge;
}
 
private Ridge getHorizontalRidgeSuccessorInMeshBottom(Ridge ridge, Hashtable allRidgeIntersectByIsoline)
{
//Sample horizontal ridge :
//First node of Ridge = (line = 0, column = 0)
 
//successor is on ridge vertical right of mesh right:
//First node of Ridge sucessor = (line = 0, column = 0)
Ridge forcedSuccessor = getRidgeFromKey(
Ridge.getKey(ridge.getLineNumberInitialNode(), ridge.getColumnNumberInitialNode() + 1, Ridge.RIDGE_VERTICAL),
allRidgeIntersectByIsoline);
if(forcedSuccessor != null){
return forcedSuccessor;
}
 
//successor is on ridge horizontal bottom of mesh right:
Ridge horizontalSuccessor = getRidgeFromKey(
Ridge.getKey(ridge.getLineNumberInitialNode() + 1, ridge.getColumnNumberInitialNode(), Ridge.RIDGE_HORIZONTAL),
allRidgeIntersectByIsoline);
 
//successor is on ridge vertical left of mesh right:
Ridge verticalSuccessor = getRidgeFromKey(
Ridge.getKey(ridge.getLineNumberInitialNode(), ridge.getColumnNumberInitialNode(), Ridge.RIDGE_VERTICAL),
allRidgeIntersectByIsoline);
 
//if only one ridge find, return this one
if((verticalSuccessor == null) && (horizontalSuccessor != null)){
return horizontalSuccessor;
}
if((horizontalSuccessor == null) && (verticalSuccessor != null)){
return verticalSuccessor;
}
 
return null;
}
 
private Ridge getHorizontalRidgeSuccessorInMeshTop(Ridge ridge, Hashtable allRidgeIntersectByIsoline)
{
//successor is on ridge vertical left of mesh left:
Ridge forcedSuccessor = getRidgeFromKey(
Ridge.getKey(ridge.getLineNumberInitialNode() - 1, ridge.getColumnNumberInitialNode() + 1, Ridge.RIDGE_VERTICAL),
allRidgeIntersectByIsoline);
if(forcedSuccessor != null){
return forcedSuccessor;
}
 
//successor is on ridge horizontal top of mesh left:
Ridge horizontalSuccessor = getRidgeFromKey(
Ridge.getKey(ridge.getLineNumberInitialNode() - 1, ridge.getColumnNumberInitialNode(), Ridge.RIDGE_HORIZONTAL),
allRidgeIntersectByIsoline);
 
//successor is on ridge vertical right of mesh left:
Ridge verticalSuccessor = getRidgeFromKey(
Ridge.getKey(ridge.getLineNumberInitialNode() - 1, ridge.getColumnNumberInitialNode(), Ridge.RIDGE_VERTICAL),
allRidgeIntersectByIsoline);
 
//if only one ridge find, return this one
if((verticalSuccessor == null) && (horizontalSuccessor != null)){
return horizontalSuccessor;
}
if((horizontalSuccessor == null) && (verticalSuccessor != null)){
return verticalSuccessor;
}
 
return null;
}
 
 
private Ridge getVerticalRidgeSuccessorInMeshRight(Ridge ridge, Hashtable allRidgeIntersectByIsoline)
{
//successor is on ridge vertical right of mesh right:
Ridge forcedSuccessor = getRidgeFromKey(
Ridge.getKey(ridge.getLineNumberInitialNode() + 1, ridge.getColumnNumberInitialNode(), Ridge.RIDGE_HORIZONTAL),
allRidgeIntersectByIsoline);
if(forcedSuccessor != null){
return forcedSuccessor;
}
 
//successor is on ridge horizontal bottom of mesh right:
Ridge horizontalSuccessor = getRidgeFromKey(
Ridge.getKey(ridge.getLineNumberInitialNode(), ridge.getColumnNumberInitialNode(), Ridge.RIDGE_HORIZONTAL),
allRidgeIntersectByIsoline);
 
//successor is on ridge vertical left of mesh right:
Ridge verticalSuccessor = getRidgeFromKey(
Ridge.getKey(ridge.getLineNumberInitialNode(), ridge.getColumnNumberInitialNode() + 1, Ridge.RIDGE_VERTICAL),
allRidgeIntersectByIsoline);
 
//if only one ridge find, return this one
if((verticalSuccessor == null) && (horizontalSuccessor != null)){
return horizontalSuccessor;
}
if((horizontalSuccessor == null) && (verticalSuccessor != null)){
return verticalSuccessor;
}
 
return null;
}
 
private Ridge getVerticalRidgeSuccessorInMeshLeft(Ridge ridge, Hashtable allRidgeIntersectByIsoline)
{
//successor is on ridge vertical left of mesh left:
Ridge forcedSuccessor = getRidgeFromKey(
Ridge.getKey(ridge.getLineNumberInitialNode(), ridge.getColumnNumberInitialNode() - 1, Ridge.RIDGE_HORIZONTAL),
allRidgeIntersectByIsoline);
if(forcedSuccessor != null){
return forcedSuccessor;
}
 
//successor is on ridge horizontal top of mesh left:
Ridge horizontalSuccessor = getRidgeFromKey(
Ridge.getKey(ridge.getLineNumberInitialNode() + 1, ridge.getColumnNumberInitialNode() - 1, Ridge.RIDGE_HORIZONTAL),
allRidgeIntersectByIsoline);
 
//successor is on ridge vertical right of mesh left:
Ridge verticalSuccessor = getRidgeFromKey(
Ridge.getKey(ridge.getLineNumberInitialNode(), ridge.getColumnNumberInitialNode() - 1, Ridge.RIDGE_VERTICAL),
allRidgeIntersectByIsoline);
 
//if only one ridge find, return this one
if((verticalSuccessor == null) && (horizontalSuccessor != null)){
return horizontalSuccessor;
}
if((horizontalSuccessor == null) && (verticalSuccessor != null)){
return verticalSuccessor;
}
 
return null;
}
 
 
private Ridge getRidgeFromKey(String ridgeKey, Hashtable allRidgeIntersectByIsoline)
{
return (Ridge)allRidgeIntersectByIsoline.get(ridgeKey);
}
 
private void getHorizontalGridRidgeIntersectByIsoline(int lineNumberStart, int lineNumberEnd,
int columnNumberStart, int columnNumberEnd, double zIsoline, Hashtable allRidgeIntersected)
{
for(int lineNumber = lineNumberStart; lineNumber <= lineNumberEnd; lineNumber ++){
for(int columnNumber = columnNumberStart; columnNumber <= columnNumberEnd; columnNumber ++){
if(isRidgeIntersectByIsoline(_grid.getZ(lineNumber, columnNumber), _grid.getZ(lineNumber, columnNumber + 1), zIsoline)){
allRidgeIntersected.put(Ridge.getKey(lineNumber, columnNumber, Ridge.RIDGE_HORIZONTAL),
new Ridge(lineNumber, columnNumber, Ridge.RIDGE_HORIZONTAL));
}
}
}
}
 
private void getVerticalGridRidgeIntersectByIsoline(int lineNumberStart, int lineNumberEnd,
int columnNumberStart, int columnNumberEnd, double zIsoline, Hashtable allRidgeIntersected)
{
for(int columnNumber = columnNumberStart; columnNumber <= columnNumberEnd; columnNumber ++){
for(int lineNumber = lineNumberStart; lineNumber <= lineNumberEnd; lineNumber ++){
if(isRidgeIntersectByIsoline(_grid.getZ(lineNumber, columnNumber), _grid.getZ(lineNumber +1, columnNumber), zIsoline)){
allRidgeIntersected.put(Ridge.getKey(lineNumber, columnNumber, Ridge.RIDGE_VERTICAL),
new Ridge(lineNumber, columnNumber, Ridge.RIDGE_VERTICAL));
}
}
}
}
 
 
private boolean isRidgeIntersectByIsoline(double zNodeFirst, double zNodeSecond, double zIsoline)
{
//*initial:
return ( (((zNodeFirst < zIsoline)&&(zNodeSecond >= zIsoline))||
((zNodeFirst >= zIsoline)&&(zNodeSecond < zIsoline))) );
//*/
 
/* essai
return ( (((zNodeFirst <= zIsoline)&&(zNodeSecond >= zIsoline))||
((zNodeFirst >= zIsoline)&&(zNodeSecond <= zIsoline))) );
*/
 
//correction:
/*
return ( (((zNodeFirst < zIsoline)&&(zNodeSecond >= zIsoline)) || (((zNodeFirst <= zIsoline)&&(zNodeSecond > zIsoline)) ||
((zNodeFirst >= zIsoline)&&(zNodeSecond < zIsoline))) || ((zNodeFirst > zIsoline)&&(zNodeSecond <= zIsoline))));
*/
}
 
private double getXIsolineIntersection(Ridge ridge, double zIsoline)
{
if(ridge.getPositionType() == Ridge.RIDGE_VERTICAL){
return ridge.getXInitialNode(_grid);
}
 
return getXYIsolineIntersection(ridge, zIsoline,
ridge.getXInitialNode(_grid), ridge.getXFinalNode(_grid));
}
 
private double getYIsolineIntersection(Ridge ridge, double zIsoline)
{
if(ridge.getPositionType() == Ridge.RIDGE_HORIZONTAL){
return ridge.getYInitialNode(_grid);
}
 
return getXYIsolineIntersection(ridge, zIsoline,
ridge.getYInitialNode(_grid), ridge.getYFinalNode(_grid));
}
 
 
private double getXYIsolineIntersection(Ridge ridge, double zIsoline,
double xyInitialNode, double xyFinalNode)
{
double zInitialNode = ridge.getZInitialNode(_grid);
double zFinalNode = ridge.getZFinalNode(_grid);
double zNodeTop = Math.max(zInitialNode, zFinalNode);
double zNodeBottom = Math.min(zInitialNode, zFinalNode);
 
double xyNodeTop;
double xyNodeBottom;
if(zNodeTop == zInitialNode){
xyNodeTop = xyInitialNode;
xyNodeBottom = xyFinalNode;
}else{
xyNodeTop = xyFinalNode;
xyNodeBottom = xyInitialNode;
}
 
 
//double xyNodeTop = Math.max(xyInitialNode, xyFinalNode);
//double xyNodeBottom = Math.min(xyInitialNode, xyFinalNode);
 
if(zNodeTop == zIsoline){
return xyNodeTop;
}
 
if(zNodeBottom == zIsoline){
return xyNodeBottom;
}
 
double coeffLinearInterpol;
if(zIsoline - zNodeBottom != 0){
coeffLinearInterpol = (zNodeTop - zIsoline)/(zIsoline - zNodeBottom);
}
else{
coeffLinearInterpol = 0;
}
 
if((1 + coeffLinearInterpol) !=0){
return (xyNodeTop + coeffLinearInterpol * xyNodeBottom)/(1 + coeffLinearInterpol);
}
 
return 0;
}
 
 
private void setIsolineWithUpperZAtLeft(Arc arcIsoline, Ridge lastRidgeIntersectByIsoline)
{
if(!isIsolineWithUpperZAtLeft(arcIsoline, lastRidgeIntersectByIsoline)){
//System.out.println("************ reverse arc");
arcIsoline.reverse();
}
}
 
/**
* isIsolineWithUpperZAtLeft
* Role : Par convention une isoline doit etre oriente de telle sorte qu'elle ait
* l'isoligne d'altitude superieur à gauche. Pour determiner si on doit
* retourner ou non l'isoligne, on effectue un produit vectoriel avec
* 2 points d'intersections concecutifs des aretes du maillage par
* l'isoligne Z0, et les noeuds de l'aretes sur laquel on a obtenu le
* 2ème points d'intersection. Alors le signe du produit vectoriel obtenu
* avec le noeud le plus bas ou le noued le plus haut, permet de
* determiner l'orientation des isolignes.
* Return : Renvoie TRUE si l'isoline a l'altitude superieur à gauche
*/
boolean isIsolineWithUpperZAtLeft(Arc isolineArc, Ridge lastRidgeIntersectByIsoline)
{
//find point before last point
Point2D point2D = isolineArc.getLastIntermediaryPoint();
double xPointBeforeLast;
double yPointBeforeLast;
if(point2D != null){
xPointBeforeLast = point2D.getX();
yPointBeforeLast = point2D.getY();
}else{
Vertex initialVertex = isolineArc.getInitialVertex();
xPointBeforeLast = initialVertex.getX();
yPointBeforeLast = initialVertex.getY();
}
 
//find last point
Vertex finalVertex = isolineArc.getFinalVertex();
double xLastPoint = finalVertex.getX();
double yLastPoint = finalVertex.getY();
 
//get xy node bottom of last ridge intersect by isoline
double zInitialNode = lastRidgeIntersectByIsoline.getZInitialNode(_grid);
double zFinalNode = lastRidgeIntersectByIsoline.getZFinalNode(_grid);
double zNodeBottom = Math.min(zInitialNode, zFinalNode);
double xNodeBottom;
double yNodeBottom;
if(zNodeBottom == zInitialNode){
xNodeBottom = lastRidgeIntersectByIsoline.getXInitialNode(_grid);
yNodeBottom = lastRidgeIntersectByIsoline.getYInitialNode(_grid);
}else{
xNodeBottom = lastRidgeIntersectByIsoline.getXFinalNode(_grid);
yNodeBottom = lastRidgeIntersectByIsoline.getYFinalNode(_grid);
}
 
//Produit vectoriel :
double prodVectWithNodeBottom = OFCMath.getVectorialProduct(xPointBeforeLast, yPointBeforeLast,
xLastPoint, yLastPoint, xNodeBottom, yNodeBottom);
if(prodVectWithNodeBottom > 0)
return false;
if(prodVectWithNodeBottom < 0)
return true;
 
//get xy node top of last ridge intersect by isoline
double zNodeTop = Math.max(zInitialNode, zFinalNode);
double xNodeTop;
double yNodeTop;
if(zNodeTop == zInitialNode){
xNodeTop = lastRidgeIntersectByIsoline.getXInitialNode(_grid);
yNodeTop = lastRidgeIntersectByIsoline.getYInitialNode(_grid);
}else{
xNodeBottom = lastRidgeIntersectByIsoline.getXInitialNode(_grid);
yNodeBottom = lastRidgeIntersectByIsoline.getYInitialNode(_grid);
xNodeTop = lastRidgeIntersectByIsoline.getXFinalNode(_grid);
yNodeTop = lastRidgeIntersectByIsoline.getYFinalNode(_grid);
}
 
//Produit vectoriel :
double prodVectWithNodeTop = OFCMath.getVectorialProduct(xPointBeforeLast, yPointBeforeLast,
xLastPoint, yLastPoint, xNodeTop, yNodeTop);
if(prodVectWithNodeTop < 0)
return false;
if(prodVectWithNodeTop > 0)
return true;
 
return false;
}
 
 
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/geographic/Rectangle.java
New file
0,0 → 1,120
package com.oxymel.ofc.charts.geographic;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import com.oxymel.ofc.charts.data.Point2D;
 
/**
*
* <p>Title: Rectangle </p>
* <p>Description: Manage Rectangle</p>
*/
public class Rectangle
{
private double _xMin;
private double _yMin;
private double _xMax;
private double _yMax;
 
 
/**
* Constructor
* @param x X of point
* @param y Y of Point
*/
public Rectangle(double xMin, double yMin, double xMax, double yMax)
{
_xMin = xMin;
_yMin = yMin;
_xMax = xMax;
_yMax = yMax;
}
 
public Rectangle()
{
}
 
/**
* Get X of point
* @return X of point
*/
public double getXMax()
{
return _xMax;
}
 
/**
* Get Y of point
* @return Y of point
*/
public double getYMax()
{
return _yMax;
}
 
 
/**
* Get X of point
* @return X of point
*/
public double getXMin()
{
return _xMin;
}
 
/**
* Get Y of point
* @return Y of point
*/
public double getYMin()
{
return _yMin;
}
 
public void setXMax(double xMax)
{
_xMax = xMax;
}
 
public void setYMax(double yMax)
{
_yMax = yMax;
}
 
public void setXMin(double xMin)
{
_xMin = xMin;
}
 
public void setYMin(double yMin)
{
_yMin = yMin;
}
 
 
public boolean isIncludeIn(Rectangle boundingRectangle)
{
return ( (_xMin >= boundingRectangle.getXMin()) && (_xMin <= boundingRectangle.getXMax()) &&
(_xMax >= boundingRectangle.getXMin()) && (_xMax <= boundingRectangle.getXMax()) &&
(_yMin >= boundingRectangle.getYMin()) && (_yMin <= boundingRectangle.getYMax()) &&
(_yMax >= boundingRectangle.getYMin()) && (_yMax <= boundingRectangle.getYMax()) );
}
 
public boolean isContains(Point2D point)
{
return isContains(point.getX(), point.getY());
}
 
public boolean isContains(double x, double y)
{
return ( (_xMin <= x) && (_xMax >= x) && (_yMin <= y) && (_yMax >= y) );
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/geographic/Arc.java
New file
0,0 → 1,332
package com.oxymel.ofc.charts.geographic;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import java.util.Vector;
import java.util.Enumeration;
 
//ofc
import com.oxymel.ofc.charts.data.Point2D;
import com.oxymel.ofc.charts.geographic.Rectangle;
import com.oxymel.ofc.charts.util.ContainerTools;
import com.oxymel.ofc.charts.util.OFCMath;
import com.oxymel.ofc.charts.util.Segment;
 
 
public class Arc
{
private Vertex _initialVertex;
private Vertex _finalVertex;
private Vector _allIntermediaryPoint;
private Rectangle _boundingRectangle = null;
 
private double _value;
private boolean _isValueDefined = false;
 
private boolean _isTraveledInThisDirection = false;
private boolean _isTraveledInOppositeDirection = false;
 
public Arc(Vertex initialVertex, Vertex finalVertex)
{
_initialVertex = initialVertex;
_finalVertex = finalVertex;
_allIntermediaryPoint = new Vector();
}
 
public Arc(Vertex initialVertex, Vector allIntermediaryPoint, Vertex finalVertex)
{
_initialVertex = initialVertex;
_finalVertex = finalVertex;
_allIntermediaryPoint = allIntermediaryPoint;
}
 
public void setIsTraveledInThisDirection(){_isTraveledInThisDirection = true;}
public boolean isTraveledInThisDirection(){return _isTraveledInThisDirection;}
 
public void setIsTraveledInOppositeDirection(){_isTraveledInOppositeDirection = true;}
public boolean isTraveledInOppositeDirection(){return _isTraveledInOppositeDirection;}
 
 
 
public Arc(Vertex initialVertex, Vector allIntermediaryPoint, Vertex finalVertex, double value)
{
this(initialVertex, allIntermediaryPoint, finalVertex);
_value = value;
_isValueDefined = true;
}
 
public double getValue(){return _value;}
public boolean isValueDefined(){return _isValueDefined;}
 
public Vertex getInitialVertex(){return _initialVertex;}
public Vertex getFinalVertex(){return _finalVertex;}
 
public Enumeration getEnumAllIntermediaryPoint(){return _allIntermediaryPoint.elements();}
public Vector getAllIntermediaryPoint(){return _allIntermediaryPoint;}
 
public Point2D getLastIntermediaryPoint()
{
if(_allIntermediaryPoint.size() == 0){
return null;
}
return (Point2D)_allIntermediaryPoint.elementAt(_allIntermediaryPoint.size() - 1);
}
 
public boolean isIntermediaryPointEquals(Vector allIntermediaryPointToCompare)
{
if(allIntermediaryPointToCompare.size() != _allIntermediaryPoint.size()){
return false;
}
for(int i=0;i< _allIntermediaryPoint.size(); i++){
Point2D point2D = (Point2D)_allIntermediaryPoint.elementAt(i);
Point2D point2DToCompare = (Point2D)allIntermediaryPointToCompare.elementAt(i);
if(!point2D.isSameXY(point2DToCompare)){
return false;
}
}
return true;
}
 
synchronized public void reverse()
{
Vertex oldFinalVertex = _finalVertex;
_finalVertex = _initialVertex;
_initialVertex = oldFinalVertex;
 
ContainerTools.reverseAllElement(_allIntermediaryPoint);
}
 
 
public Rectangle getBoundingRectangle()
{
if(_boundingRectangle != null){
return _boundingRectangle;
}
Vertex initialVertex = getInitialVertex();
Vertex finalVertex = getFinalVertex();
 
double xMin = Math.min(initialVertex.getX(), finalVertex.getX());
double yMin = Math.min(initialVertex.getY(), finalVertex.getY());
double xMax = Math.max(initialVertex.getX(), finalVertex.getX());
double yMax = Math.max(initialVertex.getY(), finalVertex.getY());
 
for(int i=0;i<_allIntermediaryPoint.size();i++){
Point2D point2D = (Point2D)_allIntermediaryPoint.elementAt(i);
xMin = Math.min(xMin, point2D.getX());
yMin = Math.min(yMin, point2D.getY());
xMax = Math.max(xMax, point2D.getX());
yMax = Math.max(yMax, point2D.getY());
}
_boundingRectangle = new Rectangle(xMin, yMin, xMax, yMax);
return _boundingRectangle;
}
 
public Arc getArcMoreAtLeftSuccessor(boolean isFindInArcDirection)
{
Segment lastSegmentOfArc;
Vertex lastVertex;
if(isFindInArcDirection){
lastSegmentOfArc = getFinalSegment();
lastVertex = getFinalVertex();
}
else{
lastSegmentOfArc = getInitialSegment();
lastSegmentOfArc.reverse();
lastVertex = getInitialVertex();
}
 
return getArcMoreAtLeftSuccessor(lastSegmentOfArc, lastVertex, lastVertex.getEnumAllArcGoInOut(this));
}
 
public Segment getInitialSegment()
{
Segment segment = new Segment();
 
Vertex initialVertex = getInitialVertex();
segment.setXInitial(initialVertex.getX());
segment.setYInitial(initialVertex.getY());
 
if(_allIntermediaryPoint.size() != 0){
Point2D point2D = (Point2D)_allIntermediaryPoint.elementAt(0);
segment.setXFinal(point2D.getX());
segment.setYFinal(point2D.getY());
}else{
Vertex finalVertex = getFinalVertex();
segment.setXFinal(finalVertex.getX());
segment.setYFinal(finalVertex.getY());
}
return segment;
}
 
public Segment getFinalSegment()
{
Segment segment = new Segment();
 
Vertex finalVertex = getFinalVertex();
segment.setXFinal(finalVertex.getX());
segment.setYFinal(finalVertex.getY());
 
if(_allIntermediaryPoint.size() != 0){
Point2D point2D = (Point2D)_allIntermediaryPoint.lastElement();
segment.setXInitial(point2D.getX());
segment.setYInitial(point2D.getY());
}else{
Vertex initialVertex = getInitialVertex();
segment.setXInitial(initialVertex.getX());
segment.setYInitial(initialVertex.getY());
}
return segment;
}
 
public boolean isSameDirectionAsArcPredecessor(Arc arcPredecessor)
{
/*
double xFinalPred = arcPredecessor.getFinalVertex().getX();
double yFinalPred = arcPredecessor.getFinalVertex().getY();
double xInitial = getInitialVertex().getX();
double yInitial = getInitialVertex().getY();
 
return ((xFinalPred == xInitial) && (yFinalPred == yInitial)) ;
*/
return (arcPredecessor.getFinalVertex().equals(this.getInitialVertex()));
}
 
public boolean isPointOnArc(double x, double y)
{
Vertex initialVertex = getInitialVertex();
double xInitialSegment = initialVertex.getX();
double yInitialSegment = initialVertex.getY();
 
Enumeration enumAllIntermediaryPoint = getEnumAllIntermediaryPoint();
while(enumAllIntermediaryPoint.hasMoreElements()){
Point2D intermediaryPoint = (Point2D)enumAllIntermediaryPoint.nextElement();
double xFinalSegment = intermediaryPoint.getX();
double yFinalSegment = intermediaryPoint.getY();
if(Segment.isPointOnSegment(x, y, xInitialSegment, yInitialSegment,
xFinalSegment, yFinalSegment)){
return true;
}
xInitialSegment = xFinalSegment;
yInitialSegment = yFinalSegment;
}
 
Vertex finalVertex = getFinalVertex();
double xFinalSegment = finalVertex.getX();
double yFinalSegment = finalVertex.getY();
if(Segment.isPointOnSegment(x, y, xInitialSegment, yInitialSegment,
xFinalSegment, yFinalSegment)){
return true;
}
 
return false;
}
 
private Arc getArcMoreAtLeftSuccessor(Segment lastSegmentOfArc, Vertex lastVertex, Enumeration enumAllArc)
{
if(!enumAllArc.hasMoreElements()){
return null;
}
Arc arcSuccessor = (Arc)enumAllArc.nextElement();
while(enumAllArc.hasMoreElements()){
Arc arc = (Arc)enumAllArc.nextElement();
arcSuccessor = getArcMoreAtLeftSuccessor(lastSegmentOfArc, lastVertex, arcSuccessor, arc);
}
return arcSuccessor;
}
 
/**
* le signe du produit vectoriel est trouver en plaçant le pouce dans la direction
* du premier segment, l'index dans la direction du second, le majeur donne alors
* le signe qui est positif s'il pointe vers soi, negatif dans le cas contraire
*/
private Arc getArcMoreAtLeftSuccessor(Segment lastSegmentOfArc, Vertex lastVertex,
Arc arcSuccessor1, Arc arcSuccessor2)
 
{
//System.out.println("arcSuccessor1 = " + arcSuccessor1.toString());
//System.out.println("arcSuccessor2 = " + arcSuccessor2.toString());
 
//il faut dans tous les cas prendre le segment oriente allant vers
//la gauche.
 
//
Segment segmentArcSuccessor1;
if(arcSuccessor1.getInitialVertex().equals(lastVertex)){
//parcour de l'arc dans son sens
segmentArcSuccessor1 = arcSuccessor1.getInitialSegment();
}
else{
//parcour de l'arc en sens inverse
//On recupere le segment final que l'on retourne
segmentArcSuccessor1 = arcSuccessor1.getFinalSegment();
segmentArcSuccessor1.reverse();
}
boolean isSuccessor1AtLeft = false;
if(OFCMath.getVectorialProduct(lastSegmentOfArc, segmentArcSuccessor1)>0){
// Point Final of segment Successor is At Left Of last Segment Of Arc
isSuccessor1AtLeft = true;
}
 
//
Segment segmentArcSuccessor2;
if(arcSuccessor2.getInitialVertex().equals(lastVertex)){
//parcour de l'arc dans sons sens
segmentArcSuccessor2 = arcSuccessor2.getInitialSegment();
}
else{
//parcour de l'arc en sens inverse
//On recupere le segment final que l'on retourne
segmentArcSuccessor2 = arcSuccessor2.getFinalSegment();
segmentArcSuccessor2.reverse();
}
boolean isSuccessor2AtLeft = false;
if(OFCMath.getVectorialProduct(lastSegmentOfArc, segmentArcSuccessor2)>0){
// Point Final of segment Successor is At Left Of last Segment Of Arc
isSuccessor2AtLeft = true;
}
 
//
if( ((isSuccessor1AtLeft)&&(isSuccessor2AtLeft)) || ((!isSuccessor1AtLeft)&&(!isSuccessor2AtLeft)) ){
//il faut savoir lequel est le plus a gauche
if(OFCMath.getVectorialProduct(segmentArcSuccessor1, segmentArcSuccessor2)<0){
return arcSuccessor1;
}
else{
return arcSuccessor2;
}
}
else{
if(isSuccessor2AtLeft){
return arcSuccessor2;
}
else{
return arcSuccessor1;
}
}
}
 
 
public String toString()
{
 
String ptIntermedaireInfo = "";
for(int i=0; i< _allIntermediaryPoint.size(); i++){
Point2D point = (Point2D)_allIntermediaryPoint.elementAt(i);
ptIntermedaireInfo += " - PT" + i + ": X = " + point.getX() + " Y = " + point.getY();
}
 
 
return "xInitialVertex = " + getInitialVertex().getX() + " - yInitialVertex = " + getInitialVertex().getY() +
" | xFinalVertex = " + getFinalVertex().getX() + " - yFinalVertex = " + getFinalVertex().getY() +
" - Nb Point = " + _allIntermediaryPoint.size() + " - value = " + _value +
" - isValueDefined = " + _isValueDefined + ptIntermedaireInfo;
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/ChartWithAxisXYY.java
New file
0,0 → 1,176
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.Graphics2D;
import java.util.Vector;
import java.util.Enumeration;
 
//ofc
import com.oxymel.ofc.charts.series.Point2DSeries;
import com.oxymel.ofc.charts.exception.OFCChartsException;
import com.oxymel.ofc.charts.series.SeriesContainer;
 
 
/**
* This class is the abstract superclass for all char with one axis X and two axis Y.
*/
abstract class ChartWithAxisXYY extends ChartWithAxisXY
{
protected ChartWithAxisXYY(int chartWidth, int chartHeight)
{
super(chartWidth, chartHeight);
}
 
//tmp on ne gere pas le 3d sur les graphics complex avec 2 axes des Y
public void set3dEffectValue(int coeff3dEffect)
{
}
 
 
protected void doDrawChart(Graphics2D graphics2D) throws OFCChartsException
{
setAxisParameters();
 
Axis axisX = getAxisX();
Axis axisY = getAxisY();
Axis axisYRight = getAxisYRight();
 
int xTopLeftGraphic = getXTopLeftGraphic(graphics2D);
int yTopLeftGraphic = getYTopLeftGraphic(graphics2D);
int graphicWidth = getGraphicWidth(graphics2D);
axisX.setNbPixelSize(graphicWidth);
int graphicHeight = getGraphicHeight(graphics2D);
axisY.setNbPixelSize(graphicHeight);
axisYRight.setNbPixelSize(graphicHeight);
 
int sizeOfGapOnY = graphicHeight / axisY.getNbGap();
int sizeOfGapOnYRight = graphicHeight / axisYRight.getNbGap();
int sizeOfGapOnX = graphicWidth / axisX.getNbGap();
 
int decalageOrigineToIncludeNegativeValueOnY = sizeOfGapOnY * axisY.getNbNegativeGapToIncludeMinValue();
int decalageOrigineToIncludeNegativeValueOnYRight = sizeOfGapOnYRight * axisYRight.getNbNegativeGapToIncludeMinValue();
 
int yOrigine;
if(decalageOrigineToIncludeNegativeValueOnY > decalageOrigineToIncludeNegativeValueOnYRight){
yOrigine = (yTopLeftGraphic + graphicHeight) - decalageOrigineToIncludeNegativeValueOnY;
}else{
yOrigine = (yTopLeftGraphic + graphicHeight) - decalageOrigineToIncludeNegativeValueOnYRight;
}
 
int xOrigine = xTopLeftGraphic +
(sizeOfGapOnX * axisX.getNbNegativeGapToIncludeMinValue());
 
drawGraphicBackground(xTopLeftGraphic, yTopLeftGraphic,
graphicWidth, graphicHeight, graphics2D);
 
 
 
//axisY.drawInternalGrid(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
// xOrigine, yOrigine, graphics2D);
//axisX.drawInternalGrid(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
// xOrigine, yOrigine, graphics2D);
 
//drawInternalGrid(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
// xOrigine, yOrigine, graphics2D);
 
axisY.draw(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
axisYRight.draw(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
 
drawGraphic(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight,
xOrigine, yOrigine, graphics2D);
 
axisX.draw(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
 
//pas de legend affichée
_legend.drawLegend(getXTopLeftLegend(graphics2D), getYTopLeftLegend(graphics2D),
getSeriesContainer().getAllSeriesOrderByDisplayNumber(), graphics2D);
 
/* bug à voir plus tard
_legend.drawLegend(
getXTopLeftLegend(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D),
getYTopLeftLegend(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D),
getSeriesContainer().getAllSeriesOrderByDisplayNumber(), graphics2D);
*/
}
 
 
//template pattern used by doDrawChart :
abstract protected Axis getAxisYRight();
 
protected int getYTopLeftGraphic(Graphics2D graphics2D)
{
Axis axisY = getAxisY();
Axis axisYRight = getAxisYRight();
 
int yTopLeftGraphic = super.getYTopLeftGraphic(graphics2D);
int nbPixelUsedAtTopByAxisYRight = axisYRight.getNbPixelUsedAtTop(graphics2D);
int nbPixelUsedAtTopByAxisYLeft = axisY.getNbPixelUsedAtTop(graphics2D);
if( nbPixelUsedAtTopByAxisYRight > nbPixelUsedAtTopByAxisYLeft)
yTopLeftGraphic += nbPixelUsedAtTopByAxisYRight - nbPixelUsedAtTopByAxisYLeft;
return yTopLeftGraphic;
}
 
protected int getGraphicWidth(Graphics2D graphics2D)
{
Axis axisYRight = getAxisYRight();
int graphicWidth = super.getGraphicWidth(graphics2D);
graphicWidth -= (axisYRight.getNbPixelUsedAtLeft(graphics2D) +
axisYRight.getNbPixelUsedAtRight(graphics2D));
return graphicWidth;
}
 
protected int getGraphicHeight(Graphics2D graphics2D) throws OFCChartsException
{
Axis axisYRight = getAxisYRight();
Axis axisY = getAxisY();
 
int graphicHeight = super.getGraphicHeight(graphics2D);
 
int nbPixelUsedAtTopByAxisYRight = axisYRight.getNbPixelUsedAtTop(graphics2D);
int nbPixelUsedAtTopByAxisYLeft = axisY.getNbPixelUsedAtTop(graphics2D);
if(nbPixelUsedAtTopByAxisYRight > nbPixelUsedAtTopByAxisYLeft){
graphicHeight -= nbPixelUsedAtTopByAxisYRight - nbPixelUsedAtTopByAxisYLeft;
}
 
int nbPixelUsedAtBottomByAxisYRight = axisYRight.getNbPixelUsedAtBottom(graphics2D);
int nbPixelUsedAtBottomByAxisYLeft = axisY.getNbPixelUsedAtBottom(graphics2D);
if(nbPixelUsedAtBottomByAxisYRight > nbPixelUsedAtBottomByAxisYLeft){
graphicHeight -= nbPixelUsedAtBottomByAxisYRight - nbPixelUsedAtBottomByAxisYLeft;
}
 
return graphicHeight;
}
 
protected int getXTopLeftLegend(Graphics2D graphics2D) throws OFCChartsException
{
int xTopLeftLegend = super.getXTopLeftLegend(graphics2D);
switch(_legend.getLegendDisplayMode()){
case Legend.LEGEND_DISPLAY_MODE_RIGHT:
Axis axisX = getAxisX();
Axis axisYRight = getAxisYRight();
 
int nbPixelUsedAtRightByAxisX = axisX.getNbPixelUsedAtRight(graphics2D);
int nbPixelUsedByAxisYRight = axisYRight.getNbPixelUsedAtRight(graphics2D) +
axisYRight.getNbPixelUsedAtLeft(graphics2D);
if(nbPixelUsedByAxisYRight > nbPixelUsedAtRightByAxisX){
xTopLeftLegend += (nbPixelUsedByAxisYRight - nbPixelUsedAtRightByAxisX);
}
break;
}
return xTopLeftLegend;
}
 
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/VerticalAxisRight.java
New file
0,0 → 1,130
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.Graphics2D;
import java.awt.Font;
import java.awt.geom.AffineTransform;
import java.awt.RenderingHints;
//ofc
import com.oxymel.ofc.charts.util.Graphics2DTools;
import com.oxymel.ofc.charts.exception.OFCChartsRuntimeException;
 
abstract class VerticalAxisRight extends VerticalAxisCommon
{
protected VerticalAxisRight(String label)
{
super(label);
}
 
 
int getNbPixelUsedAtLeft(Graphics2D graphics2D){return 0;}
int getNbPixelUsedAtRight(Graphics2D graphics2D)
{
int nbPixelUsedForWriteYValues = getNbPixelUsedForWriteYValues(graphics2D) +
_nbPixelBetweenValueAndGapIndicator +_nbPixelOfGapIndicator;
 
switch(_labelPosition){
case LABEL_POSITION_HORIZONTAL_TOP :
int nbPixelUsedForLabel = (getNbPixelWidthOfLabel(graphics2D)/2);
return (nbPixelUsedForWriteYValues > nbPixelUsedForLabel)? nbPixelUsedForWriteYValues : nbPixelUsedForLabel;
case LABEL_POSITION_VERTICAL_RIGHT_CENTER :
return nbPixelUsedForWriteYValues + _nbPixelFreeBeforeLabel +
Graphics2DTools.getNbPixelHeightOfTxt(graphics2D, getLabel());
default:
throw new OFCChartsRuntimeException("Invalid label position = " + _labelPosition);
}
 
}
 
int getNbPixelUsedAtTop(Graphics2D graphics2D)
{
Font font = graphics2D.getFont();
graphics2D.setFont(getFont(graphics2D));
int nbPixelUsedToWriteLabel = getNbPixelUsedToDrawLabel(graphics2D);
graphics2D.setFont(font);
return getArrowLength() + nbPixelUsedToWriteLabel;
}
int getNbPixelUsedAtBottom(Graphics2D graphics2D){return 0;}
 
 
protected void drawAxisLine(int graphicWidth, int graphicHeight, int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine, int yOrigine, Graphics2D graphics2D)
{
int xAxisRight = xTopLeftGraphic + graphicWidth;
graphics2D.drawLine(xAxisRight, yTopLeftGraphic, xAxisRight, yTopLeftGraphic + graphicHeight);
}
 
protected void drawArrow(int graphicWidth, int graphicHeight, int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine, int yOrigine, Graphics2D graphics2D)
{
Graphics2DTools.drawSouthNorthArrow(getArrowLength(), xTopLeftGraphic + graphicWidth,
yTopLeftGraphic, graphics2D);
}
 
protected void drawGapIndicator(int graphicWidth, int graphicHeight, int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine, int yOrigine, Graphics2D graphics2D)
{
int xAxisRight = xTopLeftGraphic + graphicWidth;
int nbGapOnY = getNbGap();
int sizeOfGapOnY = graphicHeight / nbGapOnY;
int yOfGap = yTopLeftGraphic + graphicHeight;
graphics2D.setColor(getGapIndicatorColor());
for(int i=0; i<nbGapOnY + 1; i++){
graphics2D.drawLine(xAxisRight - _nbPixelOfGapIndicator, yOfGap, xAxisRight + _nbPixelOfGapIndicator, yOfGap);
yOfGap -= sizeOfGapOnY;
}
}
 
protected void drawLabel(int graphicWidth, int graphicHeight, int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine, int yOrigine, Graphics2D graphics2D)
{
int xAxisRight = xTopLeftGraphic + graphicWidth;
 
switch(_labelPosition){
case LABEL_POSITION_HORIZONTAL_TOP :
graphics2D.drawString(getLabel(), Graphics2DTools.getXToAlignTxt(graphics2D, xAxisRight, getLabel()),
yTopLeftGraphic - getArrowLength() - _nbPixelFreeBeforeLabel);
break;
case LABEL_POSITION_VERTICAL_RIGHT_CENTER:
RenderingHints render = graphics2D.getRenderingHints();
render.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
render.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
 
AffineTransform saveXform = graphics2D.getTransform();
AffineTransform at = new AffineTransform();
 
int nbPixelUsedForWriteYValues = getNbPixelUsedForWriteYValues(graphics2D) +
_nbPixelBetweenValueAndGapIndicator +_nbPixelOfGapIndicator;
 
int xToAlignTxt = xAxisRight + nbPixelUsedForWriteYValues + _nbPixelFreeBeforeLabel +
(Graphics2DTools.getNbPixelHeightOfTxt(graphics2D, getLabel())/2);
int yToWriteLine = yTopLeftGraphic + (graphicHeight/2);
at.rotate(Math.toRadians(-90), xToAlignTxt, yToWriteLine);
graphics2D.transform(at);
 
graphics2D.drawString(getLabel(), xToAlignTxt - Graphics2DTools.getNbPixelHeightOfTxt(graphics2D, getLabel()) , yToWriteLine);
 
 
graphics2D.setTransform(saveXform);
 
render.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
render.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
 
break;
default:
throw new OFCChartsRuntimeException("Invalid label position = " + _labelPosition);
}
 
}
 
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/ColorPalette.java
New file
0,0 → 1,298
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.Color;
import java.util.Vector;
 
/**
* ColorPalette class allows to customize the colors used in a given graphic.
* It contains a set of colors, and it provides methods to manage the colors.
* The colors belonging to the Palette are ordered, and the first one is at the position 0.
*/
public class ColorPalette {
private Vector _allColor = new Vector();
 
/**
* Constructor
* The Color palette is initialized with default colors
*/
public ColorPalette() {
initPalette();
}
 
/**
* Gets the number of colors contained in palette.
* @return number The color's count
*/
public int size() {
return _allColor.size();
}
 
/**
* Reset the color palette so that it becomes empty.
*/
public void clear() {
_allColor.clear();
}
 
/**
* Adds a new color to the palette.
* The color is given as an instance of the Color class. It is stored at the last position in the palette.
* @param color new color to add
*/
public void addColor(Color color) {
_allColor.addElement(color);
}
 
/**
* Gets the color located at the given position;
* @param colorPosition The color position in the palette
* @return Color asked, if position is greater than the number of existing colors the last color is returned.
*/
public Color getColorAt(int colorPosition) {
//int numColor = numColorInPalette - 1;
int numColor = colorPosition;
if (numColor < 0) {
return (Color) _allColor.firstElement();
}
if (numColor >= _allColor.size()) {
return (Color) _allColor.lastElement();
}
return (Color) _allColor.elementAt(numColor);
}
 
/**
* Sets or replaces the color at the given position by the one passed as argument (color).
* If the given position does not exists in the palette, nothing is done.
* @param color New color to set at the colorPosition in the palette
* @param colorPosition color position in palette, it must corresponds to an existing position
*/
public void setColorAt(Color color, int colorPosition) {
//int numColor = numColorInPalette - 1;
int numColor = colorPosition;
if ( (numColor < 0) || (numColor >= _allColor.size())) {
return;
}
_allColor.setElementAt(color, numColor);
}
 
/**
* Sets or replaces the color at the given position by the one passed as argument as a RGB color.
* If the given position does not exists in the palette, nothing is done.
* @param R Red part of color
* @param G Green part of color
* @param B Blue part of color
* @param colorPosition The color position in the palette, it must corresponds to an existing position
*/
public void setColorAt(int R, int G, int B, int colorPosition) {
//int numColor = numColorInPalette - 1;
int numColor = colorPosition;
if ( (numColor < 0) || (numColor >= _allColor.size())) {
return;
}
_allColor.setElementAt(getColor(R, G, B), numColor);
}
 
/**
* Builds a Color instance from its RGB representation
* @param R Red part of color
* @param G Green part of color
* @param B Blue part of color
* @return Color The Color instance corresponding to the RGB color definition
*/
static public Color getColor(int R, int G, int B) {
return new Color( (float) R / 256, (float) G / 256, (float) B / 256);
}
 
/**
* Initializes the ColorPalette with the defaults values, it contains 12 different colors
*/
public void initPalette() {
_allColor.clear();
 
//classic color
_allColor.addElement(Color.blue);// #0000FE
_allColor.addElement(getColor(0, 192, 192));// #00C0C0
_allColor.addElement(Color.cyan);// #00FFFF
_allColor.addElement(Color.green);
_allColor.addElement(Color.red);
_allColor.addElement(Color.magenta);
_allColor.addElement(Color.pink);
_allColor.addElement(Color.orange);
_allColor.addElement(Color.yellow);
_allColor.addElement(Color.lightGray);
_allColor.addElement(Color.gray);
_allColor.addElement(Color.darkGray);
}
 
/**
* Initializes the ColorPalette as blue gradient, it contains 5 colors
*/
public void initPaletteAsBlueGradient() {
_allColor.clear();
_allColor.addElement(getColor(0, 4, 182));
_allColor.addElement(getColor(0, 0, 255));
_allColor.addElement(getColor(68, 72, 255));
_allColor.addElement(getColor(122, 125, 255));
_allColor.addElement(getColor(193, 194, 255));
}
 
/**
* Initializes the ColorPalette as cold to hot effect with the given number of data
* @param nbOfData int
*/
private void initPaletteAsHotToColdEffect(int nbOfData) {
_allColor.clear();
int pas = 50;
if (20 < nbOfData && nbOfData <= 30) {
pas = 35;
}
if (30 < nbOfData && nbOfData <= 40) {
pas = 25;
}
if (40 < nbOfData && nbOfData <= 50) {
pas = 15;
}
if (50 < nbOfData && nbOfData <= 100) {
pas = 10;
}
if (100 < nbOfData && nbOfData <= 150) {
pas = 8;
}
if (150 < nbOfData) {
pas = 5;
}
int factor = 8;
 
for (int i = 150; i <= 255; i += pas * factor) { //dégradé de bleu
_allColor.addElement(getColor(0, 0, i));
}
for (int i = pas; i <= 255; i += pas) { //bleu -> cyan
_allColor.addElement(getColor(0, i, 255));
}
for (int i = pas; i <= 255; i += pas) { //cyan -> vert
_allColor.addElement(getColor(0, 255, 255 - i));
}
for (int i = pas; i <= 255; i += pas) { //vert -> jaune
_allColor.addElement(getColor(i, 255, 0));
}
for (int i = pas; i <= 255; i += pas) { //jaune -> rouge
_allColor.addElement(getColor(255, 255 - i, 0));
}
for (int i = pas; i < 155; i += pas * factor) { //dégradé de rouge
_allColor.addElement(getColor(255 - i, 0, 0));
}
}
 
/**
* Initializes the ColorPalette as cold to hot effect, it contains 22 colors
*/
public void initPaletteAsHotToColdEffect() {
_allColor.clear();
 
_allColor.addElement(getColor(0, 0, 120)); //bleu
_allColor.addElement(getColor(0, 0, 175));
_allColor.addElement(getColor(0, 19, 255));
_allColor.addElement(getColor(0, 115, 255));
_allColor.addElement(getColor(0, 156, 255));
_allColor.addElement(getColor(0, 198, 255));
_allColor.addElement(getColor(0, 255, 255));
_allColor.addElement(getColor(0, 255, 198));
_allColor.addElement(getColor(0, 255, 140));
_allColor.addElement(getColor(0, 255, 82));
_allColor.addElement(getColor(0, 255, 33));
_allColor.addElement(getColor(33, 255, 0));
_allColor.addElement(getColor(90, 255, 0));
_allColor.addElement(getColor(140, 255, 0));
_allColor.addElement(getColor(198, 255, 0));
_allColor.addElement(getColor(255, 255, 0));
_allColor.addElement(getColor(255, 206, 0));
_allColor.addElement(getColor(255, 148, 0));
_allColor.addElement(getColor(255, 90, 0));
_allColor.addElement(getColor(255, 33, 0));
_allColor.addElement(getColor(220, 0, 0));
_allColor.addElement(getColor(160, 0, 0)); //rouge
 
}
 
/**
* Initializes the ColorPaletteSets as an excel color palette, it contains 8 colors
*/
public void initPaletteAsExcelColor() {
_allColor.clear();
_allColor.addElement(getColor(153, 153, 255));
_allColor.addElement(getColor(153, 153, 255));
_allColor.addElement(getColor(153, 51, 102));
_allColor.addElement(getColor(255, 255, 204));
_allColor.addElement(getColor(204, 255, 255));
_allColor.addElement(getColor(102, 0, 102));
_allColor.addElement(getColor(255, 128, 128));
_allColor.addElement(getColor(0, 102, 204));
}
 
/**
* Initializes the ColorPalette as cold to hot effect with the given number of data
* @param nbOfData int
*/
public void initPaletteHotToColdFromData(int nbOfData) {
initPaletteAsHotToColdEffect(nbOfData);
 
if (nbOfData < _allColor.size()) {
Vector tmp_allColor = new Vector();
java.util.List elementsToRemove = new java.util.ArrayList();
int nbToRemove = 0;
 
//calcul du nombre d'elements à enlever à la palette
nbToRemove = (_allColor.size() - nbOfData);
//recherche de l'intervalle à utiliser pour oter des elements
//pour une répartition homogene sur l'ensemble de la palette
double interval = new Double(_allColor.size()).doubleValue() /
new Double( (nbToRemove + 1)).doubleValue();
//enregistrement des numeros des elements à enlever de la palette
for (int j = 1; j <= nbToRemove; j++) {
int t = new Long(Math.round(interval * j)).intValue();
elementsToRemove.add(t + "");
}
for (int i = 0; i < _allColor.size(); i++) {
boolean toRemove = false;
for (int n = 0; n < elementsToRemove.size() && !toRemove; n++) {
toRemove = (i == Integer.parseInt( (String) elementsToRemove.get(n)));
}
//si l'element n'est pas à enlever, écriture dans la palette
if (!toRemove) {
tmp_allColor.add(_allColor.get(i));
}
}
_allColor = tmp_allColor;
}
}
 
/**
* Initializes the ColorPalette with 42 differents colors
*/
public void initPaletteWith42Colors() {
// _allColor.clear();
initPalette();
String[] colors = {
"9090E0", "D07C7C", "15E015", "8A2BE2", "008B8B", "8B0000",
"FFAA28", "A0D0D0", "DC143C", "B8860B", "228B22", "00008B", "BDB76B",
"8B008B", "6495ED", "FF7F50", "A9A9A9",
"DAA520", "00BFFF", "FF1493", "00FA9A", "800000", "66CDAA", "0000CD",
"FF4500", "BA55D3", "3CB371", "7B68EE", "C71585", "FF0000", "DEB887",
"D2691E", "006400", "E9967A", "8FBC8F", "483D8B", "FF8C00", "9400D3",
"556B2F", "696969", "1E90FF", "000000"};
for (int i = 0; i < colors.length; i++) {
_allColor.add(new Color(Integer.parseInt(colors[i].trim(), 16)));
}
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/util/ValueCursor.java
New file
0,0 → 1,73
package com.oxymel.ofc.charts.util;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
public class ValueCursor
{
private double _value;
private double _step;
private double _currentValue = 0;
 
public ValueCursor(double valueStart, double step, double valueEnd)
{
_value = valueEnd;
_step = step;
_currentValue = valueStart;
 
//System.out.println("_value = " + _value + "_step = " + _step + "_currentValue = " + _currentValue );
}
 
 
public boolean hasMoreValue()
{
if(_step > 0){
return (_currentValue <= _value);
}else{
return (_currentValue >= _value);
}
}
 
public double nextValue()
{
if(!hasMoreValue()){
return _currentValue - _step;
}
if(_step == 0){
_currentValue--;
return _value;
}
if(_currentValue == _value){
_currentValue += _step;
return _value;
}
_currentValue = ((_step<0)?getNextValueWithNegativeStep(_currentValue):getNextValueWithPositiveStep(_currentValue));
//System.out.println("_currentValue = " + _currentValue);
return _currentValue;
}
 
private double getNextValueWithPositiveStep(double currentValue)
{
currentValue += _step;
//System.out.println("getNextValueWithPositiveStep currentValue = " + currentValue);
if(currentValue > _value){
currentValue = _value;
}
return currentValue;
}
 
private double getNextValueWithNegativeStep(double currentValue)
{
currentValue += _step;
if(currentValue < _value){
currentValue = _value;
}
return currentValue;
}
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/util/OFCMath.java
New file
0,0 → 1,63
package com.oxymel.ofc.charts.util;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
public class OFCMath
{
public static final double SQRT_2 = 1.4142135623730950488016887242097;
 
private OFCMath()
{
}
 
 
//produit vectoriel utilise dans isoline = 1Pt (x1,y1) + 1Pt pivot(x2,y2) + 2ème Pt (x3,y3)
//=produit vectoriel avec un point en commun
static public double getVectorialProduct(double x1, double y1, double x2, double y2,
double x3, double y3 ){return(((x2 - x1)*(y3 - y2)) - ((y2 - y1)*(x3 - x2)));};
 
 
 
//produit vectoriel standart avec 2 vecteurs defini et oriente par les segments
//qu'ils portent :
//regle de la main droite
//le signe du produit vectoriel est trouver en plaçant le pouce dans la direction
//du premier segment, l'index dans la direction du second, le majeur donne alors
//le signe qui est positif s'il pointe vers soi, negatif dans le cas contraire
static public double getVectorialProduct(Segment seg1, Segment seg2){return(
((seg1.getXFinal() - seg1.getXInitial()) * (seg2.getYFinal() - seg2.getYInitial())) -
((seg2.getXFinal() - seg2.getXInitial()) * (seg1.getYFinal() - seg1.getYInitial())) );}
 
 
static public int getValueFromPercentage(int percentageValue, int valueFor100Percent)
{
return ((percentageValue * valueFor100Percent) / 100);
}
 
 
static public double computeDistanceSquare(double fXFirstPt_I, double fYFirstPt_I,
double fXSecondPt_I, double fYSecondPt_I){
return( ((fXFirstPt_I - fXSecondPt_I)*(fXFirstPt_I - fXSecondPt_I)) +
((fYFirstPt_I - fYSecondPt_I)*(fYFirstPt_I - fYSecondPt_I)) );};
 
static public double computeDistance(double fXFirstPt_I, double fYFirstPt_I,
double fXSecondPt_I, double fYSecondPt_I){
return(Math.sqrt(computeDistanceSquare(fXFirstPt_I, fYFirstPt_I, fXSecondPt_I, fYSecondPt_I)));};
 
static public int getNbDigitAfterDot(double val)
{
String str = Double.toString(val);
int dotPosition = str.indexOf(".");
if(dotPosition == -1){
return 0;
}
return str.length() - dotPosition - 1;
}
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/util/Segment.java
New file
0,0 → 1,117
package com.oxymel.ofc.charts.util;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
 
public class Segment
{
private double _xInitial = 0;
private double _yInitial =0;
private double _xFinal = 0;
private double _yFinal = 0;
 
 
public Segment()
{
}
 
static public boolean isPointOnSegment(double xOfPoint, double yOfPoint,
double xInitial, double yInitial, double xFinal, double yFinal)
{
double xMax = Math.max(xInitial, xFinal);
double yMax = Math.max(yInitial, yFinal);
double xMin = Math.min(xInitial, xFinal);
double yMin = Math.min(yInitial, yFinal);
return ((xMin <= xOfPoint)&&(yMin <= yOfPoint)&&(xMax >= xOfPoint)&&(yMax >= yOfPoint));
}
 
/**
* Constructor
* @param x X of point
* @param y Y of Point
*/
public Segment(double xInitial, double yInitial, double xFinal, double yFinal)
{
_xInitial = xInitial;
_yInitial = yInitial;
_xFinal = xFinal;
_yFinal = yFinal;
}
 
/**
* Get X of point
* @return X of point
*/
public double getXInitial()
{
return _xInitial;
}
 
/**
* Get Y of point
* @return Y of point
*/
public double getYInitial()
{
return _yInitial;
}
 
 
/**
* Get X of point
* @return X of point
*/
public double getXFinal()
{
return _xFinal;
}
 
/**
* Get Y of point
* @return Y of point
*/
public double getYFinal()
{
return _yFinal;
}
 
public void setXInitial(double xInitial)
{
_xInitial = xInitial;
}
 
public void setYInitial(double yInitial)
{
_yInitial = yInitial;
}
 
public void setXFinal(double xFinal)
{
_xFinal = xFinal;
}
 
public void setYFinal(double yFinal)
{
_yFinal = yFinal;
}
 
public void reverse()
{
double oldXInitial = _xInitial;
double oldYInitial = _yInitial;
 
_xInitial = _xFinal;
_yInitial = _yFinal;
_xFinal = oldXInitial;
_yFinal = oldYInitial;
}
 
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/util/ContainerTools.java
New file
0,0 → 1,33
package com.oxymel.ofc.charts.util;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.util.Vector;
 
public class ContainerTools
{
private ContainerTools()
{
}
 
 
static public void reverseAllElement(Vector allElement)
{
int lastElementPosition = allElement.size() -1;
for(int i=0; i< (int)(allElement.size()/2);i++){
Object oldElementTMP = allElement.elementAt(i);
allElement.setElementAt(allElement.elementAt(lastElementPosition), i);
allElement.setElementAt(oldElementTMP, lastElementPosition);
lastElementPosition --;
}
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/util/Interval.java
New file
0,0 → 1,78
package com.oxymel.ofc.charts.util;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//ofc
import com.oxymel.ofc.charts.exception.OFCChartsRuntimeException;
 
 
public class Interval
{
public static final int COMPARISON_TYPE_LOWER_STRICT = 0;
public static final int COMPARISON_TYPE_LOWER_OR_EGAL = 1;
public static final int COMPARISON_TYPE_GREATER_STRICT = 2;
public static final int COMPARISON_TYPE_GREATER_OR_EGAL = 3;
 
 
private double _startInterval;
private int _startIntervalComparisonType;
private double _endInterval;
private int _endIntervalComparisonType;
 
public Interval(double startInterval, int startIntervalComparisonType, double endInterval, int endIntervalComparisonType)
{
_startInterval = startInterval;
_startIntervalComparisonType = startIntervalComparisonType;
_endInterval = endInterval;
_endIntervalComparisonType = endIntervalComparisonType;
}
 
public double getStartValue(){return _startInterval;}
public double getEndValue(){return _endInterval;}
 
public boolean isContains(double startInterval, double endInterval)
{
if(!isContains(startInterval)){
return false;
}
if(!isContains(endInterval)){
return false;
}
return true;
}
 
public boolean isContains(double value)
{
if(!isValueRespectIntervalComparison(value, _startInterval, _startIntervalComparisonType)){
return false;
}
if(!isValueRespectIntervalComparison(value, _endInterval, _endIntervalComparisonType)){
return false;
}
return true;
}
 
private boolean isValueRespectIntervalComparison(double value, double interval, int intervalComparisonType)
{
switch(intervalComparisonType){
case COMPARISON_TYPE_LOWER_STRICT:
return (value < interval);
case COMPARISON_TYPE_LOWER_OR_EGAL:
return (value <= interval);
case COMPARISON_TYPE_GREATER_STRICT:
return (value > interval);
case COMPARISON_TYPE_GREATER_OR_EGAL:
return (value >= interval);
default:
throw new OFCChartsRuntimeException("Invalid interval comparaison type");
}
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/util/Graphics2DTools.java
New file
0,0 → 1,276
package com.oxymel.ofc.charts.util;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.Graphics2D;
import java.awt.Font;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Arc2D;
import java.util.StringTokenizer;
 
 
public class Graphics2DTools
{
private Graphics2DTools()
{
}
 
//Text
public static int getXToAlignTxt(Graphics2D graphics2D, int xCenter, String txt)
{
return xCenter - (getNbPixelWidthOfTxt(graphics2D, txt)/2);
}
public static int getYToAlignTxt(Graphics2D graphics2D, int yCenter, String txt)
{
return yCenter + (getNbPixelHeightOfTxt(graphics2D, txt)/2) - 1;
}
public static int getNbPixelWidthOfTxt(Graphics2D graphics2D, String txt)
{
Rectangle2D rectangle = graphics2D.getFont().getStringBounds(txt, graphics2D.getFontRenderContext());
return (int)rectangle.getWidth();
}
public static int getNbPixelHeightOfTxt(Graphics2D graphics2D, String txt)
{
Rectangle2D rectangle = graphics2D.getFont().getStringBounds(txt, graphics2D.getFontRenderContext());
return (int)rectangle.getHeight();
}
 
//Arrow
public static void drawSouthNorthArrow(int arrowLength, int xBottom, int yBottom, Graphics2D graphics2D)
{
int yTop = yBottom - arrowLength;
graphics2D.drawLine(xBottom, yBottom, xBottom, yTop);
graphics2D.drawLine(xBottom, yTop, xBottom - 5, yTop + 5);
graphics2D.drawLine(xBottom, yTop, xBottom + 5, yTop + 5);
}
public static void drawEastWestArrow(int arrowLength, int xRight, int yRight, Graphics2D graphics2D)
{
int xLeft = xRight + arrowLength;
graphics2D.drawLine(xRight, yRight, xLeft, yRight);
graphics2D.drawLine(xLeft, yRight, xLeft - 5, yRight - 5);
graphics2D.drawLine(xLeft, yRight, xLeft - 5, yRight + 5);
}
 
//value
static public int getRelativeSizeOfValue(double value, int templateValue, int sizeTemplateValue)
{
return( (int)(sizeTemplateValue*value)/templateValue);
}
static public double getValueAsPercentage(double value, double sumAllValues)
{
return ((value * 100) / sumAllValues);
}
static public double getIntervalValue(double firstValue, double secondValue)
{
if(((firstValue < 0) && (secondValue > 0)) ||
((firstValue > 0) && (secondValue < 0))){
return Math.abs(firstValue) + Math.abs(secondValue);
}
return Math.abs(Math.abs(firstValue) - Math.abs(secondValue));
}
 
 
//Arc
static public Arc2D getArcPercentageToAnother(Arc2D arc2d, int percentageNewArc)
{
double newWith = (arc2d.getWidth() * percentageNewArc)/100;
double newHeight = (arc2d.getHeight() * percentageNewArc)/100;
 
return new Arc2D.Double(arc2d.getX() + ((arc2d.getWidth() - newWith)/2),
arc2d.getY() + ((arc2d.getHeight() - newHeight)/2),
newWith, newHeight, arc2d.getAngleStart(), arc2d.getAngleExtent(), Arc2D.PIE);
}
static public Arc2D getClone(Arc2D arcToClone)
{
return getArcPercentageToAnother(arcToClone, 100);
}
 
//Font
static public Font getFont(Graphics2D graphics2D, int sizeFont)
{
Font font = graphics2D.getFont();
if(sizeFont > 0){
return new Font(font.getName(), font.getStyle(), sizeFont);
}
else{
return font;
}
}
 
// Start get Lines To Write
static public String[] getLinesToWrite(Graphics2D graphics2D, int sizeWidthToWrite, String valuesOnX, int nbLineMaxForValuesOnX)
{
StringTokenizer st = new StringTokenizer(valuesOnX, " ");
String words[] = new String[st.countTokens()];
int nbWords = 0;
while(st.hasMoreTokens()) {
words[nbWords] = st.nextToken();
nbWords++;
}
StringContainer lines = getLinesToWrite(graphics2D, sizeWidthToWrite, words);
boolean isValuesOnXTroncated = (nbLineMaxForValuesOnX < lines.getNbElement());
String result[] = null;
if(isValuesOnXTroncated){
result = new String[nbLineMaxForValuesOnX];
}
else{
result = new String[lines.getNbElement()];
}
for(int i=0; ((i<lines.getNbElement())&&(i < nbLineMaxForValuesOnX)); i++){
if(i+1 < nbLineMaxForValuesOnX){
result[i] = lines.getElementAt(i);
}
else{
if(isValuesOnXTroncated){
result[i] = getValueTroncated(graphics2D, lines.getElementAt(i), sizeWidthToWrite);
}
else{
result[i] = lines.getElementAt(i);
}
}
}
return result;
}
 
static private String getValueTroncated(Graphics2D graphics2D, String value, int sizeWidthToWrite)
{
if(value == null){
return null;
}
 
String valueTroncatedTest = value + "...";
if(Graphics2DTools.getNbPixelWidthOfTxt(graphics2D, valueTroncatedTest) < sizeWidthToWrite){
return valueTroncatedTest;
}
valueTroncatedTest = value + "..";
if(Graphics2DTools.getNbPixelWidthOfTxt(graphics2D, valueTroncatedTest) < sizeWidthToWrite){
return valueTroncatedTest;
}
 
int valueLength = value.length();
int nbPoint = 0;
if(valueLength > 7){
nbPoint = 3;
}
else if (valueLength > 4){
nbPoint = 2;
} else if (valueLength > 1){
nbPoint = 1;
}
else{
return value;
}
 
String valueTroncated = value.substring(0, value.length() - nbPoint);
String nbPointToAdd = "";
for(int i=0; i<nbPoint; i++){
nbPointToAdd += ".";
}
return valueTroncated + nbPointToAdd;
}
 
static private StringContainer getLinesToWrite(Graphics2D graphics2D, int sizeWidthToWrite, String[] words)
{
StringContainer allFormatedWords = getAllFormatedWordsForSizeMax(graphics2D, sizeWidthToWrite, words);
 
StringContainer allWords = new StringContainer();
for(int i=0; i<allFormatedWords.getNbElement();i++){
String currentWord = allFormatedWords.getElementAt(i);
StringTokenizer st = new StringTokenizer(currentWord, "\n");
while(st.hasMoreTokens()) {
String newWord = st.nextToken();
allWords.addElement(newWord);
if(st.hasMoreTokens()){
allWords.addElement("\n");
}
}
}
 
StringContainer linesResult = new StringContainer();
String currentLine = "";
for(int i=0; i<allWords.getNbElement();i++){
String currentWord = allWords.getElementAt(i);
if(currentWord.equals("\n")){
linesResult.addElement(currentLine);
currentLine = "";
}
else{
String testLine = currentLine + currentWord;
if(Graphics2DTools.getNbPixelWidthOfTxt(graphics2D, testLine) <= sizeWidthToWrite){
currentLine += currentWord;
}
else{
linesResult.addElement(currentLine);
currentLine = currentWord;
}
if(i+1 < allWords.getNbElement()){
currentLine += " ";
}
}
}
if(!currentLine.equals("")){
linesResult.addElement(currentLine);
}
return linesResult;
}
 
static private StringContainer getAllFormatedWordsForSizeMax(Graphics2D graphics2D, int sizeWidthToWrite, String[] words)
{
StringContainer allWords = new StringContainer();
for(int i=0; i<words.length;i++){
String currentWord = words[i];
if(Graphics2DTools.getNbPixelWidthOfTxt(graphics2D, currentWord) <= sizeWidthToWrite){
allWords.addElement(currentWord);
}
else{
//mot trop grand il faut le couper
StringContainer partOfWord = new StringContainer();
String currentPartOfWord = "";
for(int j=0; j< currentWord.length(); j++){
currentPartOfWord += currentWord.charAt(j);
String newWordPart = currentPartOfWord + "-";
if(Graphics2DTools.getNbPixelWidthOfTxt(graphics2D, newWordPart) < sizeWidthToWrite){
if(j+1 < currentWord.length()){
String nextWordPart = currentPartOfWord + currentWord.charAt(j+1);
if(Graphics2DTools.getNbPixelWidthOfTxt(graphics2D, nextWordPart+"-") >= sizeWidthToWrite){
partOfWord.addElement(newWordPart+'\n');
currentPartOfWord = "";
}
}
}
}
partOfWord.addElement(currentPartOfWord);
String newWord = "";
for(int j=0; j<partOfWord.getNbElement(); j++){
newWord += partOfWord.getElementAt(j);
}
allWords.addElement(newWord);
}
}
return allWords;
}
 
static public int getSizeMaxLineToWrite(String[] linesToWrite, Graphics2D graphics2D)
{
int sizeMax = 0;
for(int i=0; i<linesToWrite.length; i++){
String line = linesToWrite[i];
int currentSize = Graphics2DTools.getNbPixelWidthOfTxt(graphics2D, line);
if(currentSize > sizeMax){
sizeMax = currentSize;
}
}
return sizeMax;
}
 
// End get Lines To Write
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/util/DateUtilities.java
New file
0,0 → 1,101
package com.oxymel.ofc.charts.util;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
public class DateUtilities {
 
public DateUtilities() {
}
 
public static String getFormattedDate(String format, int unit, String date)
{
return getFormattedDate(format, unit, Long.parseLong(date));
}
 
public static String getFormattedDate(String _format, int _typeUnits, long date)
{
long milliseconds = (date*_typeUnits);//on ramène le temps en millisecondes
long hour = 0;
long min = 0;
long seconds = 0;
 
if(_format.indexOf("H")!=-1)
{
hour = milliseconds / 3600000;
milliseconds -= hour * 3600000;
}
if(_format.indexOf("M")!= -1)
{
min = milliseconds / 60000;
milliseconds -= min * 60000;
}
if(_format.indexOf("S")!=-1)
{
seconds = milliseconds/1000;
milliseconds -= seconds * 1000;
}
 
String hours = null;
if(hour <10)
hours = "0"+Long.toString(hour);
else
hours = Long.toString(hour);
 
String mins = null;
if(min <10)
mins = "0"+Long.toString(min);
else
mins = Long.toString(min);
 
String secs = null;
if(seconds < 10)
secs = "0"+Long.toString(seconds);
else
secs = Long.toString(seconds);
 
String millisecs = null;
if(milliseconds < 10)
millisecs = "0"+Long.toString(milliseconds);
else
millisecs = Long.toString(milliseconds);
 
String formattedString = _format;
if(formattedString.indexOf("H")!=-1)
formattedString = replace(formattedString, "H", hours);
 
if(formattedString.indexOf("M")!=-1)
formattedString = replace(formattedString, "M", mins);
 
if(formattedString.indexOf("S")!=-1)
formattedString = replace(formattedString, "S", secs);
 
if(formattedString.indexOf("ms")!=-1)
formattedString = replace(formattedString, "ms", millisecs);
 
return formattedString;
}
 
private static String replace(String src, String oldString, String newString)
{
String srcSave = src;
if(src.indexOf(oldString)!=-1)
{
src = src.substring(0,src.indexOf(oldString));
src = src.concat(" "+newString);
if(srcSave.indexOf(oldString)+oldString.length()+1 == srcSave.length())
return src;
if(srcSave.indexOf(oldString)+oldString.length()+1 > srcSave.length())
src = src.concat(srcSave.substring(srcSave.indexOf(oldString)+oldString.length(), srcSave.length()));
else
src = src.concat(srcSave.substring(srcSave.indexOf(oldString)+oldString.length()+1, srcSave.length()));
}
return src;
}
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/util/StringContainer.java
New file
0,0 → 1,87
package com.oxymel.ofc.charts.util;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import java.util.Vector;
 
public class StringContainer
{
private Vector _objectContainer;
 
public StringContainer()
{
_objectContainer = new Vector();
}
 
public StringContainer(String[] strA)
{
this();
if (strA != null){
for (int i = 0; i < strA.length; i++) {
_objectContainer.addElement(strA[i]);
}
}
}
 
public final int getNbElement()
{
return _objectContainer.size();
}
 
public final synchronized void addElement(String stringToAdd)
{
_objectContainer.addElement(stringToAdd);
}
 
public final synchronized String getElementAt(int index)
{
return ((String) _objectContainer.elementAt(index));
}
 
public final synchronized void setElementAt(String string, int index)
{
_objectContainer.setElementAt(string, index);
}
 
public final synchronized void removeElementAt(int index)
{
_objectContainer.removeElementAt(index);
}
 
public final synchronized String[] toArray()
{
String returnArray[] = new String[_objectContainer.size()];
for (int i = 0; i < returnArray.length; i++) {
returnArray[i] = (String)_objectContainer.elementAt(i);
}
return returnArray;
}
 
public String toString()
{
String returnValue = new String();
returnValue += "StringContainer: \n[";
for (int i = 0; i < _objectContainer.size(); i ++) {
returnValue += " " + i + " = " + _objectContainer.elementAt(i);
}
returnValue += "]\n";
return returnValue;
}
 
public boolean isExist(String stringToFindInCotainer)
{
for (int i = 0; i < _objectContainer.size(); i ++) {
if(_objectContainer.elementAt(i).equals(stringToFindInCotainer)){
return true;
}
}
return false;
}
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/VerticalAxis.java
New file
0,0 → 1,137
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.Graphics2D;
import java.awt.Font;
import java.awt.geom.AffineTransform;
import java.awt.RenderingHints;
 
 
//ofc
import com.oxymel.ofc.charts.util.Graphics2DTools;
import com.oxymel.ofc.charts.exception.OFCChartsRuntimeException;
 
abstract public class VerticalAxis extends VerticalAxisCommon
{
protected VerticalAxis(String label)
{
super(label);
}
 
int getNbPixelUsedAtLeft(Graphics2D graphics2D)
{
int nbPixelUsedForWriteYValues = getNbPixelUsedForWriteYValues(graphics2D) +
_nbPixelBetweenValueAndGapIndicator +_nbPixelOfGapIndicator;
int nbPixelUsedForLabel = 0;
 
switch(_labelPosition){
case LABEL_POSITION_HORIZONTAL_TOP :
nbPixelUsedForLabel = (getNbPixelWidthOfLabel(graphics2D)/2);
return (nbPixelUsedForWriteYValues > nbPixelUsedForLabel)? nbPixelUsedForWriteYValues : nbPixelUsedForLabel;
case LABEL_POSITION_VERTICAL_LEFT_CENTER :
return nbPixelUsedForWriteYValues + _nbPixelFreeBeforeLabel +
Graphics2DTools.getNbPixelHeightOfTxt(graphics2D, getLabel());
default:
throw new OFCChartsRuntimeException("Invalid label position = " + _labelPosition);
}
 
}
int getNbPixelUsedAtRight(Graphics2D graphics2D)
{
return 0;
}
 
int getNbPixelUsedAtTop(Graphics2D graphics2D)
{
Font font = graphics2D.getFont();
graphics2D.setFont(getFont(graphics2D));
int nbPixelUsedToWriteLabel = getNbPixelUsedToDrawLabel(graphics2D);
graphics2D.setFont(font);
return getArrowLength() + nbPixelUsedToWriteLabel;
}
int getNbPixelUsedAtBottom(Graphics2D graphics2D){return 0;}
 
 
protected void drawAxisLine(int graphicWidth, int graphicHeight, int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine, int yOrigine, Graphics2D graphics2D)
{
graphics2D.drawLine(xOrigine, yTopLeftGraphic, xOrigine, yTopLeftGraphic + graphicHeight);
}
 
protected void drawArrow(int graphicWidth, int graphicHeight, int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine, int yOrigine, Graphics2D graphics2D)
{
Graphics2DTools.drawSouthNorthArrow(getArrowLength(), xOrigine,
yTopLeftGraphic, graphics2D);
}
 
protected void drawGapIndicator(int graphicWidth, int graphicHeight, int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine, int yOrigine, Graphics2D graphics2D)
{
int nbGapOnY = getNbGap();
int sizeOfGapOnY = graphicHeight / nbGapOnY;
int yOfGap = yTopLeftGraphic + graphicHeight;
graphics2D.setColor(getGapIndicatorColor());
for(int i=0; i<nbGapOnY + 1; i++){
graphics2D.drawLine(xOrigine - _nbPixelOfGapIndicator, yOfGap, xOrigine + _nbPixelOfGapIndicator, yOfGap);
yOfGap -= sizeOfGapOnY;
}
}
 
protected void drawLabel(int graphicWidth, int graphicHeight, int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine, int yOrigine, Graphics2D graphics2D)
{
switch(_labelPosition){
case LABEL_POSITION_HORIZONTAL_TOP :
graphics2D.drawString(getLabel(), Graphics2DTools.getXToAlignTxt(graphics2D, xOrigine, getLabel()),
yTopLeftGraphic - getArrowLength() - _nbPixelFreeBeforeLabel);
break;
case LABEL_POSITION_VERTICAL_LEFT_CENTER:
RenderingHints render = graphics2D.getRenderingHints();
render.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
render.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
 
AffineTransform saveXform = graphics2D.getTransform();
AffineTransform at = new AffineTransform();
 
int nbPixelUsedForWriteYValues = getNbPixelUsedForWriteYValues(graphics2D) +
_nbPixelBetweenValueAndGapIndicator +_nbPixelOfGapIndicator;
 
int xToAlignTxt = xOrigine - nbPixelUsedForWriteYValues - _nbPixelFreeBeforeLabel;
int yToWriteLine = yTopLeftGraphic + (graphicHeight/2);
at.rotate(Math.toRadians(-90), xToAlignTxt, yToWriteLine);
//at.translate(xOfGap + (getSizeOfGap()/2), yOrigine + _nbPixelOfGapIndicator + _nbPixelBetweenValueAndGapIndicator + (Graphics2DTools.getNbPixelHeightOfTxt(graphics2D, linesToWrite[j])/2));
graphics2D.transform(at);
 
//graphics2D.drawString(linesToWrite[j],
// Graphics2DTools.getXToAlignTxt(graphics2D, xToAlignTxt, linesToWrite[j]), yToWriteLine);
 
//graphics2D.drawString(getLabel(), Graphics2DTools.getXToAlignTxt(graphics2D, xToAlignTxt, getLabel()), yToWriteLine);
graphics2D.drawString(getLabel(), xToAlignTxt - Graphics2DTools.getNbPixelHeightOfTxt(graphics2D, getLabel()) , yToWriteLine);
 
 
graphics2D.setTransform(saveXform);
 
render.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
render.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
 
/*
graphics2D.drawString(getLabel(), Graphics2DTools.getXToAlignTxt(graphics2D, xTopLeftGraphic + (graphicWidth/2), getLabel()),
Graphics2DTools.getYToAlignTxt(graphics2D, yOrigine + _nbPixelOfGapIndicator + getMaxNbPixelHeigthValues(graphics2D) + _nbPixelFreeBeforeLabel, getLabel()));
*/
break;
default:
throw new OFCChartsRuntimeException("Invalid label position = " + _labelPosition);
}
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/PieChart.java
New file
0,0 → 1,166
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.*;
import java.util.Vector;
import java.awt.Graphics2D;
 
//ofc
import com.oxymel.ofc.charts.series.ValueSeries;
import com.oxymel.ofc.charts.series.ValueSeriesContainer;
import com.oxymel.ofc.charts.exception.OFCChartsException;
import com.oxymel.ofc.charts.series.SeriesContainer;
 
/**
* PieChart is a subclass of the Chart class dedicated to the pie graphics
*/
 
public class PieChart extends Chart
{
private ValueSeriesContainer _valueSeriesContainer;
 
/**
* Constructor.
* Replaces the data used to draw the pie by another data container
* @param chartWidth
* @param chartHeight
* @param categoryValueSeriesContainer All series of couple category-value
*/
public PieChart(int chartWidth, int chartHeight,
ValueSeriesContainer valueSeriesContainer)
{
super(chartWidth, chartHeight);
setCategoryValueSeriesContainer(valueSeriesContainer);
}
 
/**
* Replaces the data used to draw the pie by another data container
* @param categoryValueSeriesContainer All series of couple category-value
*/
public void setCategoryValueSeriesContainer(ValueSeriesContainer valueSeriesContainer)
{
_valueSeriesContainer = valueSeriesContainer;
setAllSeriesColorFromPalette(valueSeriesContainer);
}
 
protected SeriesContainer getSeriesContainer(){return _valueSeriesContainer;}
 
protected void doDrawChart(Graphics2D graphics2D) throws OFCChartsException
{
int xTopLeftGraphic = getXTopLeftGraphic(graphics2D);
int yTopLeftGraphic = getYTopLeftGraphic(graphics2D);
int graphicWidth = getGraphicWidth(graphics2D);
int graphicHeight = getGraphicHeight(graphics2D);
 
drawGraphicBackground(xTopLeftGraphic, yTopLeftGraphic,
graphicWidth, graphicHeight, graphics2D);
 
_legend.drawLegend(getXTopLeftLegend(graphics2D), getYTopLeftLegend(graphics2D),
getSeriesContainer().getAllSeriesOrderByDisplayNumber(), graphics2D);
 
/*bug à voir plus tard
_legend.drawLegend(
getXTopLeftLegend(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D),
getYTopLeftLegend(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D),
getSeriesContainer().getAllSeriesOrderByDisplayNumber(), graphics2D);
*/
 
drawGraphic(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D);
}
 
 
 
private void drawGraphic(int xTopLeftGraphic, int yTopLeftGraphic, int graphicWidth, int graphicHeight,
Graphics2D graphics2D)
{
Vector allValueSeries = _valueSeriesContainer.getAllSeriesOrderByDisplayNumber();
 
double sumAllValues = _valueSeriesContainer.getSumAllValues();
 
int startAngle = 0;
int arcAngle = 0;
for(int i= 0; i<allValueSeries.size(); i++){
ValueSeries valueSeries = (ValueSeries)allValueSeries.elementAt(i);
if(valueSeries.isVisible()){
double value = valueSeries.getValue();
if(i + 1 <allValueSeries.size()){
arcAngle = (int)((getValueAsPercentage(value, sumAllValues) * 360f)/100);
}else{
arcAngle = 360 - startAngle;
}
graphics2D.setColor(valueSeries.getColor());
/*
if(startAngle < 180){
graphics2D.translate(-10,0);
}else{
graphics2D.translate(10,0);
}
*/
graphics2D.fillArc(xTopLeftGraphic, yTopLeftGraphic,
graphicWidth, graphicHeight, startAngle, arcAngle);
 
/*
try{
FileInputStream image = new FileInputStream("D:/jfselber/dve/ofccharts/image_result/bouteille.jpg");
byte[] array = new byte[image.available()];
image.read(array);
ImageIcon iconImage = new ImageIcon(array);
 
//graphics2D.setClip(new Arc2D.Double((double)xTopLeftGraphic, (double)yTopLeftGraphic,
// (double)graphicWidth, (double)graphicHeight, (double)startAngle, (double)arcAngle, Arc2D.PIE));
graphics2D.drawImage(iconImage.getImage(), null, null);
 
System.out.println("clip ");
}catch(Exception e){
 
throw new OFCChartsRuntimeException("error");
}
 
*/
 
startAngle += arcAngle;
}
 
}
 
/*
int colorNum = 0;
int startAngle = 0;
int arcAngle = 0;
for(int i=0; i<_valuesOnY.length; i++){
if(i + 1 <_valuesOnY.length){
arcAngle = (int)((_valuesOnY[i] * 360f)/100); //_valuesOnY est en pourcentage
}else{
arcAngle = 360 - startAngle;
}
graphics2D.setColor(_paletteColor[colorNum]);
colorNum = nextNumColorInPalette(colorNum, _paletteColor);
graphics2D.fillArc(xTopLeftGraphic, yTopLeftGraphic,
graphicWidth, graphicHeight, startAngle, arcAngle);
startAngle += arcAngle;
}
*/
}
 
 
private double getValueAsPercentage(double value, double sumAllValues)
{
return ((value * 100) / sumAllValues);
}
 
/*
public static void main(String[] argv) throws Exception
{
}
*/
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/animation/SVGAnimationContext.java
New file
0,0 → 1,187
package com.oxymel.ofc.charts.animation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//ofc
import com.oxymel.ofc.charts.exception.OFCChartsRuntimeException;
 
/**
* This class gives the context of the SVG animation according
* to its constructors.
*/
public class SVGAnimationContext
{
/**
* Indefinite repeat value
*/
static final public int INDEFINITE_REPEAT = 0;
 
/**
* total time of the animation
*/
private String _time=30+"s";
 
private String _externalAnimationURL = null;
 
/**
* number of animation repeat
*/
private int _numberOfRepeat= INDEFINITE_REPEAT;
 
private int _nbImage = 1;
 
private int _nbMilliSecondForUpdateExternalAnimation = 1000;
 
 
/**
* constructor
*/
public SVGAnimationContext()
{
setTime(3);
}
 
/**
* constructor
* @param numberOfSecond number of second of the animation
*/
public SVGAnimationContext(int numberOfSecond)
{
setTime(numberOfSecond);
}
 
/**
* constructor
* @param numberOfSecond number of second of the animation
* @param numberOfRepeat number of repeat of the animation
*/
public SVGAnimationContext(int numberOfSecond, int numberOfRepeat)
{
this(numberOfSecond);
setNumberOfRepeat(numberOfRepeat);
}
 
/**
* constructor
* @param numberOfSecond number of second of the animation
* @param numberOfRepeat number of repeat of the animation
* @param nbImage number of image of the animation
*/
public SVGAnimationContext(int numberOfSecond, int numberOfRepeat, int nbImage)
{
this(numberOfSecond);
setNumberOfRepeat(numberOfRepeat);
_nbImage = nbImage;
}
 
 
 
/**
* Sets the repeat number of the animation
* @param numberOfRepeat
*/
public void setNumberOfRepeat(int numberOfRepeat)
{
if (numberOfRepeat< 0)
throw new OFCChartsRuntimeException("Bad number of repeat");
_numberOfRepeat=numberOfRepeat;
}
 
 
/**
* Sets the second number of the animation
* @param numberOfSecond
*/
public void setTime(double numberOfSecond)
{
setTime(0,0,numberOfSecond);
}
 
/**
* Sets the total time of the animation
* @param hour
* @param minute
* @param second
*/
public void setTime(int hour, int minute, double second)
{
if ((hour<0)||(hour>24)||(minute<0)||(minute>59)||(second < 0)||(second>59))
throw new OFCChartsRuntimeException("incorrect time for animation: " + hour + "h " + minute + "m " + second + "s");
_time=hour+":"+minute+":"+second;
}
 
 
/**
* Get SVG "dur" attribut value
* @return SVG "dur" attribut value as String
*/
public String getDurAttributValue()
{
return _time;
}
 
/**
* Get SVG "repeatCount" attribut value
* @return SVG "repeatCount" attribut value as String
*/
public String getRepeatCountAttributValue()
{
return (_numberOfRepeat == INDEFINITE_REPEAT)?"indefinite":""+_numberOfRepeat;
}
 
/**
* Get number image of the animation
* @return number image of the animation
*/
public int getNbImage(){return _nbImage;}
 
 
///// External animation context:
 
/**
* Tests if the animation is external
* @return true if the animation is external
*/
public boolean isExternalAnimation(){return (_externalAnimationURL != null);};
 
/**
* Get URL of external animation
* @return URL of external animation
*/
public String getExternalAnimationURL(){return _externalAnimationURL ;};
 
/**
* Sets URL of external animation
* @param externalAnimationURL New url of external animation
*/
public void setExternalAnimationURL(String externalAnimationURL)
{
_externalAnimationURL = externalAnimationURL;
}
 
/**
* Remove external animation
*/
public void removeExternalAnimation(){_externalAnimationURL = null;}
 
/**
* Get number of millisecond for update external animation
* @return number of millisecond for update external animation
*/
public int getNbMilliSecondForUpdateExternalAnimation(){return _nbMilliSecondForUpdateExternalAnimation;}
 
/**
* Sets number of millisecond for update external animation
* @param nbMilliSecondForUpdateExternalAnimation Number of millisecond for update external animation
*/
public void setNbMilliSecondForUpdateExternalAnimation(int nbMilliSecondForUpdateExternalAnimation){
_nbMilliSecondForUpdateExternalAnimation = nbMilliSecondForUpdateExternalAnimation;}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/animation/Contour2DAnimator.java
New file
0,0 → 1,74
package com.oxymel.ofc.charts.animation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//ofc
import com.oxymel.ofc.charts.*;
import com.oxymel.ofc.charts.exception.*;
 
/**
*
* Animation for the Contour2D graphs (SVG)
*
*/
public class Contour2DAnimator extends AbstractAnimator
{
 
/**
* Constructor
*/
public Contour2DAnimator()
{
super();
}
 
 
/**
* add a new Contour2D to animate
* @param contour2D
*/
public void add(Contour2D contour2D)
{
getAllCharts().add(contour2D);
}
 
/**
* get a Specific Contour2D
* @param pos
* @return Contour2D
*/
public Contour2D get(int pos)
{
return (Contour2D) getAllCharts().get(pos);
}
 
 
 
protected String getSVG(int minute,int second,int nbOfrepeat) throws OFCChartsException
{
if (getAllCharts().size()==0)
return "";
 
SVGAnimateCreator animator = new SVGAnimateCreator();
 
if ((second == 0)&&((minute == 0)))
return animator.drawSVG();
 
for(int i=0;i<getAllCharts().size();i++){
animator.add(get(i).drawSVG());
}
 
animator.setTime(0,minute,second);
animator.setNumberOfRepeat(nbOfrepeat);
return animator.drawSVG();
 
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/animation/SVGGraphics2DAnimateMgr.java
New file
0,0 → 1,85
package com.oxymel.ofc.charts.animation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
// batik (for svg)
import org.apache.batik.svggen.SVGGraphics2D;
import org.w3c.dom.*;
 
 
public class SVGGraphics2DAnimateMgr
{
 
public void generateAnimation(SVGGraphics2D svgGraphics2D,
SVGAnimationContext svgAnimationContext, AnimationInterface animationInterface)
{
Document document = svgGraphics2D.getDOMFactory();
 
SVGGraphics2D g1 = (SVGGraphics2D)svgGraphics2D.create();
Element topLevelGroup1 = g1.getTopLevelGroup();
Element defsElement = document.createElement("defs");
topLevelGroup1.appendChild(defsElement);
 
int nbImage = 0;
 
while(animationInterface.hasNextImage()){
nbImage ++;
// Spawn a new Graphics2D for this component
SVGGraphics2D g = (SVGGraphics2D)svgGraphics2D.create();
Element topLevelGroup = g.getTopLevelGroup();
 
animationInterface.drawImage(svgGraphics2D);
 
Element cmpGroup = g.getTopLevelGroup();
//cmpGroup.setAttributeNS(null, "id", "ofc_internal_animation_id_" + nbImage);
cmpGroup.setAttributeNS(null, "id", "ofc_" + nbImage);
defsElement.appendChild(cmpGroup);
 
g.dispose();
}
 
/*
<use xlink:href="#toto1">
<animate dur="0:0:1.0" repeatCount="indefinite" attributeName="xlink:href"
values="#toto1;#toto2"/>
</use>
*/
 
Element useElement = document.createElement("use");
//useElement.setAttribute("xlink:href", "#ofc_internal_animation_id_" + nbImage);
useElement.setAttribute("xlink:href", "#ofc_" + nbImage);
 
Element animateElement = document.createElement("animate");
animateElement.setAttribute("dur", svgAnimationContext.getDurAttributValue());
//animateElement.setAttribute("fill", "freeze");
//animateElement.setAttribute("accumulate", "sum");
animateElement.setAttribute("repeatCount", svgAnimationContext.getRepeatCountAttributValue());
animateElement.setAttribute("attributeName", "xlink:href");
StringBuffer animationValues = new StringBuffer();
for(int i=1; i<= nbImage; i++){
animationValues.append("#");
//animationValues.append("ofc_internal_animation_id_");
animationValues.append("ofc_");
animationValues.append(i);
if(i != nbImage){
animationValues.append(";");
}
}
animateElement.setAttribute("values", animationValues.toString());
 
useElement.appendChild(animateElement);
 
topLevelGroup1.appendChild(defsElement);
topLevelGroup1.appendChild(useElement);
svgGraphics2D.setTopLevelGroup(topLevelGroup1);
g1.dispose();
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/animation/ChartAnimator.java
New file
0,0 → 1,69
package com.oxymel.ofc.charts.animation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
 
import java.util.*;
 
import com.oxymel.ofc.charts.*;
import com.oxymel.ofc.charts.exception.*;
import com.oxymel.ofc.charts.series.*;
 
/**
*
* This class allows to animate graphics (SVG)
*
*/
public class ChartAnimator extends AbstractAnimator
{
private Chart _chart;
 
/**
* Constructor
* @param chart Chart to animate (series visiblility animation)
*/
public ChartAnimator(Chart chart)
{
super();
_chart = chart;
}
 
protected String getSVG(int minute,int second,int nbOfrepeat) throws OFCChartsException
{
Vector allSeries = _chart.getAllSeriesOrderByDisplayNumber();
 
if (allSeries.size()==0)
return "";
 
SVGAnimateCreator animator = new SVGAnimateCreator();
 
if ((second == 0)&&((minute == 0)))
return animator.drawSVG();
 
for(int i=0;i<allSeries.size();i++){
Series series = (Series) allSeries.elementAt(i);
series.setVisible(false);
}
 
animator.add(_chart.drawSVG());
 
for(int i=0;i<allSeries.size();i++){
Series series = (Series) allSeries.elementAt(i);
series.setVisible(true);
animator.add(_chart.drawSVG());
}
 
animator.setTime(0,minute,second);
animator.setNumberOfRepeat(nbOfrepeat);
return animator.drawSVG();
 
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/animation/AbstractAnimator.java
New file
0,0 → 1,118
package com.oxymel.ofc.charts.animation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.util.List;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.Writer;
import java.io.IOException;
//ofc
import com.oxymel.ofc.charts.exception.OFCChartsException;
 
/**
*
*/
abstract class AbstractAnimator
{
 
 
/**
* the list of all the chart to animate
*/
private List _allCharts;
 
AbstractAnimator()
{
_allCharts = new ArrayList();
}
 
/**
* Clear all the prepared charts
*/
public void clear()
{
_allCharts.clear();
}
 
 
/**
* Draw animate SVG
* @param out OutputStream to write svg
* @param minute Minute number of animation
* @param second Second number of animation
* @param nbOfrepeat Repeat number of animation
* @throws OFCChartsException write error
*/
public void drawSVG(OutputStream out,int minute,int second,int nbOfrepeat) throws OFCChartsException
{
//probleme codage UTF-8:
//drawSVG(new OutputStreamWriter(out, "UTF-8") , minute, second, nbOfrepeat) ;
try{
out.write(getSVG( minute, second, nbOfrepeat).getBytes());
out.flush();
out.close();
}catch(IOException e){
throw new OFCChartsException(e.getMessage());
}
 
}
 
 
/**
* Draw animate SVG
* @param w Writer to write svg
* @param minute Minute number of animation
* @param second Second number of animation
* @param nbOfrepeat Repeat number of animation
* @throws OFCChartsException write error
*/
// cette methode est mise en privée car elle ne marche peut etre pas avec tous les caracteres. probleme codage UTF-8
private void drawSVG(Writer w,int minute,int second,int nbOfrepeat) throws OFCChartsException
{
try{
w.write(getSVG(minute, second, nbOfrepeat));
w.flush();
w.close();
}catch(IOException e){
throw new OFCChartsException(e.getMessage());
}
}
 
/**
* Draw animate SVG in String
* @param minute Minute number of animation
* @param second Second number of animation
* @param nbOfrepeat Repeat number of animation
* @throws OFCChartsException write error
* @return animate svg as String
*/
public String drawSVG(int minute,int second,int nbOfrepeat) throws OFCChartsException
{
//probleme codage UTF-8:
/*
ByteArrayOutputStream out = new ByteArrayOutputStream();
drawSVG(out, minute, second, nbOfrepeat);
return out.toString();
*/
return getSVG(minute, second, nbOfrepeat);
}
 
 
protected List getAllCharts()
{
return _allCharts;
}
 
 
protected abstract String getSVG(int minute,int second,int nbOfrepeat) throws OFCChartsException;
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/animation/SVGAnimateCreator.java
New file
0,0 → 1,206
package com.oxymel.ofc.charts.animation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import com.oxymel.ofc.charts.exception.OFCChartsRuntimeException;
 
/**
*
*/
class SVGAnimateCreator
{
/**
* all the svg chart parsed
* ( the headers has been removed and
*/
private StringBuffer _listOfImage;
 
/**
* number of charts to animate
*/
private int _compteur=0;
 
private SVGAnimationContext _svgAnimationContext = new SVGAnimationContext();
 
 
/**
* constructor
*/
public SVGAnimateCreator()
{
_listOfImage=new StringBuffer();
_compteur=0;
}
 
/**
* constructor
* @param numberOfSecond number of second of the animation
*/
public SVGAnimateCreator(int numberOfSecond)
{
this();
setTime(numberOfSecond);
}
 
/**
* constructor
* @param numberOfSecond number of second of the animation
* @param numberOfRepeat number of repeat of the animation
*/
public SVGAnimateCreator(int numberOfSecond,int numberOfRepeat)
{
this(numberOfSecond);
setNumberOfRepeat(numberOfRepeat);
 
}
 
/**
* setter of the number of repeat of the animation
* @param numberOfRepeat
*/
public void setNumberOfRepeat(int numberOfRepeat)
{
_svgAnimationContext.setNumberOfRepeat(numberOfRepeat);
}
 
 
/**
* setter of the number of second of the animation
* @param numberOfSecond
*/
public void setTime(double numberOfSecond)
{
_svgAnimationContext.setTime(numberOfSecond);
}
 
/**
* setter of the total time of the animation
* @param hour
* @param minute
* @param second
*/
public void setTime(int hour, int minute, double second)
{
_svgAnimationContext.setTime(hour, minute, second);
}
 
 
 
/**
* add a new chart
* @param svgImage
*/
public void add(String svgImage)
{
_listOfImage.append(parseSVG(_compteur+1,svgImage)+"\n");
_compteur++;
 
}
 
/**
* method which parse the generate svg of ofc charts
* 1) remove the svg header
* 2) add the id
* @param id the number of the chart
* @param svgImage the generated svg
* @return string
*/
private static String parseSVG(int id,String svgImage)
{
// remove header
int afterDocType = svgImage.indexOf("<svg ");
String tmp = svgImage.substring(afterDocType);
// add the id
if (tmp.startsWith("<svg ")){
return "<svg id=\"id"+id+"\" "+tmp.substring(5);
}
 
throw new OFCChartsRuntimeException("error during parsing file !!!");
}
 
 
/**
* create the animated SVG
* @return string
*/
private StringBuffer createAnimateSVG()
{
StringBuffer out = new StringBuffer();
out.append(getHeader());
// if the number chart is null
// don't animate
if (_compteur > 0){
out.append(" <defs>\n");
 
out.append(_listOfImage.toString());
 
out.append(" </defs>\n");
out.append("<use xlink:href=\"#id1\">\n");
out.append("\t<animate dur=\"");
out.append(_svgAnimationContext.getDurAttributValue());
out.append("\" repeatCount=\"");
 
out.append(_svgAnimationContext.getRepeatCountAttributValue());
out.append("\" attributeName=\"xlink:href\"\n");
out.append("\t\tvalues=\"");
for(int i=0;i<_compteur;i++){
String tmp = "#id"+(i+1);
if (i>0){
tmp=";"+tmp;
}
out.append(tmp);
 
}
out.append("\"/>\n");
out.append("</use>\n");
}
 
out.append(getFooter());
return out;
}
 
/* public void drawSVG(Writer w) throws IOException {
w.write(createAnimateSVG().toString());
}*/
 
/**
* get the generated svg
* @return SVG as String
*/
public String drawSVG()
{
return createAnimateSVG().toString();
}
 
 
/**
* methods which create the header of the animate SVG
* @return string
*/
private StringBuffer getHeader()
{
StringBuffer out = new StringBuffer();
out.append("<?xml version=\"1.0\" standalone=\"no\"?>\n");
out.append("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\"\n");
out.append(" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n");
out.append("<svg xmlns=\"http://www.w3.org/2000/svg\">\n");
return out;
}
 
/**
* get the footer of the SVG
* @return string
*/
private StringBuffer getFooter()
{
return new StringBuffer("</svg>\n");
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/animation/AnimationInterface.java
New file
0,0 → 1,22
package com.oxymel.ofc.charts.animation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
// batik (for svg)
import org.apache.batik.svggen.SVGGraphics2D;
 
 
public interface AnimationInterface
{
//selector:
public boolean hasNextImage();
public void drawImage(SVGGraphics2D svgGraphics2D);
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/animation/MultiCharAnimator.java
New file
0,0 → 1,71
package com.oxymel.ofc.charts.animation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import com.oxymel.ofc.charts.*;
import com.oxymel.ofc.charts.exception.*;
 
/**
* This class allows to animate graphics (SVG)
*/
public class MultiCharAnimator extends AbstractAnimator
{
 
/**
* Constructor
*/
public MultiCharAnimator()
{
super();
}
 
 
/**
* add a new Chart to animate
* @param chart New chart to animate
*/
public void add(Chart chart)
{
getAllCharts().add(chart);
}
 
/**
* get a Specific Chart
* @param pos
* @return Chart
*/
public Chart get(int pos)
{
return (Chart) getAllCharts().get(pos);
}
 
 
 
protected String getSVG(int minute,int second,int nbOfrepeat) throws OFCChartsException
{
if (getAllCharts().size()==0)
return "";
 
SVGAnimateCreator animator = new SVGAnimateCreator();
 
if ((second == 0)&&((minute == 0)))
return animator.drawSVG();
 
for(int i=0;i<getAllCharts().size();i++){
animator.add(get(i).drawSVG());
}
 
animator.setTime(0,minute,second);
animator.setNumberOfRepeat(nbOfrepeat);
return animator.drawSVG();
 
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/Chart.java
New file
0,0 → 1,1398
package com.oxymel.ofc.charts;
 
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.util.Vector;
import java.util.Enumeration;
import java.util.Hashtable;
 
import java.io.OutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.ByteArrayOutputStream;
 
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.RenderingHints;
import java.awt.Dimension;
 
//
import org.w3c.dom.*;
 
//sun
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
 
//ofc
import com.oxymel.ofc.charts.encoder.PngEncoderB;
import com.oxymel.ofc.charts.version.ChartsVersion;
import com.oxymel.ofc.charts.animation.SVGAnimationContext;
import com.oxymel.ofc.charts.series.Series;
import com.oxymel.ofc.charts.exception.OFCChartsException;
import com.oxymel.ofc.charts.series.SeriesContainer;
import com.oxymel.ofc.charts.util.OFCMath;
 
// batik (for svg)
import org.apache.batik.dom.GenericDOMImplementation;
import org.apache.batik.svggen.SVGGraphics2D;
import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;
import java.io.Writer;
import java.io.OutputStreamWriter;
import org.apache.batik.svggen.SVGGeneratorContext;
 
/**
* This abstract class is the superclass of all classes implementing graphics.
* It provides a set of methods allowing to draw charts in different
* resulting formats, such as SVG or JPEG for instance.
* The resulting drawn chart can be stored in a file or an OutputStream, or returned as a string.
* @author unascribed jfselber
* @version 1.0
*/
abstract public class Chart {
//javascript independant of svg viewer but they are problem of client server synchronized:
//il faut que le server soit plus rapide que la demande du client pour que cela marche correctement:
//static private String JAVASCRIPT_EXTERN_ANIMATION = "var nb=1;var id=0;var img1;var img2;var use;var imageURI; function init(evt){var svgdoc= evt.getTarget().getOwnerDocument();img1 = svgdoc.getElementById('ofc_extern_image1');img2 = svgdoc.getElementById('ofc_extern_image2');use = svgdoc.getElementById('ofc_extern_use');imageURI = img1.getAttribute('xlink:href');infiniteAnimation();} function infiniteAnimation(){if(nb == 1){use.setAttribute('xlink:href', '#ofc_extern_g2');img1.setAttribute('xlink:href', imageURI + '&id=' + id);}else{use.setAttribute('xlink:href', '#ofc_extern_g1');img2.setAttribute('xlink:href', imageURI + '&id=' + id);}if (nb==1){nb++;}else{nb--;}id ++;setTimeout('infiniteAnimation()',";
//static private String END_EXTERN_ANIMATION = ");}";
 
///* ok comment for test
/*
static private String JAVASCRIPT_EXTERN_ANIMATION = "var dateStartGetURL;var nb=1;var id=0;var img1;var img2;var use;var imageURI;function init(evt){changeMenu(); var svgdoc= evt.getTarget().getOwnerDocument();img1 = svgdoc.getElementById('ofc_extern_image1');img2 = svgdoc.getElementById('ofc_extern_image2');use = svgdoc.getElementById('ofc_extern_use');imageURI = img1.getAttribute('xlink:href');infiniteAnimation();} function infiniteAnimation(){dateStartGetURL = new Date();if(nb == 1){getURL(imageURI + '&id=' + id, callBackImg1);}else{getURL(imageURI + '&id=' + id, callBackImg2);}if (nb==1){nb++;}else{nb--;}id ++;} function callBackImg1(){use.setAttribute('xlink:href', '#ofc_extern_g2');img1.setAttribute('xlink:href', imageURI + '&id=' + id);setTimeout('infiniteAnimation()', getNbMillisecondToWait());} function callBackImg2(){use.setAttribute('xlink:href', '#ofc_extern_g1');img2.setAttribute('xlink:href', imageURI + '&id=' + id);setTimeout('infiniteAnimation()', getNbMillisecondToWait());}";
//probleme saut de ligne et tabulation mis par batik:
//static private String JAVASCRIPT_EXTERN_ANIMATION_2 = "function changeMenu(){var newMenuRoot = parseXML(printNode(document.getElementById('OFC_Charts_Menu')), contextMenu);contextMenu.replaceChild( newMenuRoot, contextMenu.firstChild );} function getNbMillisecondToWait(){return ";
//pour resoudre le probleme:
static private String JAVASCRIPT_EXTERN_ANIMATION_2 = "function changeMenu(){var myCustomMenu = document.getElementById('OFC_Charts_Menu');var allItemElements = myCustomMenu.getElementsByTagName('item');for ( i = 0; i < allItemElements.getLength(); i++) {var text = allItemElements.item(i).getFirstChild();if(text != null){var nodeValue = text.getNodeValue();var newNodeValue='';for(j=0; j< nodeValue.length; j++){if((nodeValue.charAt(j) != '\\n') && (nodeValue.charAt(j) != '\\t')){newNodeValue += nodeValue.charAt(j);}}text.setNodeValue(newNodeValue);}}var newMenuRoot = parseXML(printNode(myCustomMenu), contextMenu);contextMenu.replaceChild( newMenuRoot, contextMenu.firstChild );}function getNbMillisecondToWait(){var dateCurrent = new Date();var nbMillisecondToGetUrl = dateCurrent - dateStartGetURL;var nbMillisecondUserChooseToWait = getNbMillisecondUserChooseToWait();if(nbMillisecondToGetUrl > nbMillisecondUserChooseToWait){return 500;}else{return nbMillisecondUserChooseToWait - nbMillisecondToGetUrl;}}function getNbMillisecondUserChooseToWait(){return ";
static private String END_EXTERN_ANIMATION = ";}";
*/
//end ok comment for test*/
 
///////// start TMP test
/*
static private String JAVASCRIPT_EXTERN_ANIMATION = "var dateStartGetURL;var nb=1;var id=0;var img1;var img2;var use;var imageURI;function init(evt){changeMenu(); var svgdoc= evt.getTarget().getOwnerDocument();img1 = svgdoc.getElementById('ofc_extern_image1');img2 = svgdoc.getElementById('ofc_extern_image2');use = svgdoc.getElementById('ofc_extern_use');imageURI = img1.getAttribute('xlink:href');infiniteAnimation();} function infiniteAnimation(){dateStartGetURL = new Date();if(nb == 1){alert('av url_1 = ' + id);getURL(imageURI + '&id=' + id, callBackImg1);alert('ap url_1 = ' + id);}else{alert('av url_2 = ' + id);getURL(imageURI + '&id=' + id, callBackImg2);alert('ap url_2 = ' + id);}if (nb==1){nb++;}else{nb--;}} function callBackImg1(){use.setAttribute('xlink:href', '#ofc_extern_g2');alert('av cb_1 = ' + id);img1.setAttribute('xlink:href', imageURI + '&id=' + id);id ++;setTimeout('infiniteAnimation()', getNbMillisecondToWait());} function cb3(){alert('COUCOU cb_3')};function callBackImg2(){use.setAttribute('xlink:href', '#ofc_extern_g1');alert('av cb_2 = ' + id);img2.setAttribute('xlink:href', imageURI + '&id=' + id);id ++;setTimeout('infiniteAnimation()', getNbMillisecondToWait());}";
static private String JAVASCRIPT_EXTERN_ANIMATION_2 = "function changeMenu(){var myCustomMenu = document.getElementById('OFC_Charts_Menu');var allItemElements = myCustomMenu.getElementsByTagName('item');for ( i = 0; i < allItemElements.getLength(); i++) {var text = allItemElements.item(i).getFirstChild();if(text != null){var nodeValue = text.getNodeValue();var newNodeValue='';for(j=0; j< nodeValue.length; j++){if((nodeValue.charAt(j) != '\\n') && (nodeValue.charAt(j) != '\\t')){newNodeValue += nodeValue.charAt(j);}}text.setNodeValue(newNodeValue);}}var newMenuRoot = parseXML(printNode(myCustomMenu), contextMenu);contextMenu.replaceChild( newMenuRoot, contextMenu.firstChild );}function getNbMillisecondToWait(){var dateCurrent = new Date();var nbMillisecondToGetUrl = dateCurrent - dateStartGetURL;var nbMillisecondUserChooseToWait = getNbMillisecondUserChooseToWait();if(nbMillisecondToGetUrl > nbMillisecondUserChooseToWait){return 500;}else{return nbMillisecondUserChooseToWait - nbMillisecondToGetUrl;}}function getNbMillisecondUserChooseToWait(){return ";
static private String END_EXTERN_ANIMATION = ";}";
*/
 
/*
static private String JAVASCRIPT_EXTERN_ANIMATION ="var dateStartGetURL;var currentImage=1;var id=0;var img1;var img2;var use;var imageURI;function init(evt){changeMenu();var svgdoc= evt.getTarget().getOwnerDocument();img1 = svgdoc.getElementById('ofc_extern_image1');img2 = svgdoc.getElementById('ofc_extern_image2');use = svgdoc.getElementById('ofc_extern_use');imageURI = img1.getAttribute('xlink:href');infiniteAnimation();}function infiniteAnimation(){dateStartGetURL = new Date();if(currentImage == 1){img2.setAttribute('xlink:href', getURL(imageURI + '&id=' + id, callBackImg2));}else{img1.setAttribute('xlink:href', getURL(imageURI + '&id=' + id, callBackImg1));}if (currentImage==1){currentImage++;}else{currentImage--;}}function callBackImg1(){alert('cb 1');use.setAttribute('xlink:href', '#ofc_extern_g1');i++;setTimeout('infiniteAnimation()', getNbMillisecondToWait());}function callBackImg2(){alert('cb 1');use.setAttribute('xlink:href', '#ofc_extern_g2');i++;setTimeout('infiniteAnimation()', getNbMillisecondToWait());}";
static private String JAVASCRIPT_EXTERN_ANIMATION_2 = "function changeMenu(){var myCustomMenu = document.getElementById('OFC_Charts_Menu');var allItemElements = myCustomMenu.getElementsByTagName('item');for ( i = 0; i < allItemElements.getLength(); i++) {var text = allItemElements.item(i).getFirstChild();if(text != null){var nodeValue = text.getNodeValue();var newNodeValue='';for(j=0; j< nodeValue.length; j++){if((nodeValue.charAt(j) != '\\n') && (nodeValue.charAt(j) != '\\t')){newNodeValue += nodeValue.charAt(j);}}text.setNodeValue(newNodeValue);}}var newMenuRoot = parseXML(printNode(myCustomMenu), contextMenu);contextMenu.replaceChild( newMenuRoot, contextMenu.firstChild );}function getNbMillisecondToWait(){var dateCurrent = new Date();var nbMillisecondToGetUrl = dateCurrent - dateStartGetURL;var nbMillisecondUserChooseToWait = getNbMillisecondUserChooseToWait();if(nbMillisecondToGetUrl > nbMillisecondUserChooseToWait){return 0;}else{return nbMillisecondUserChooseToWait - nbMillisecondToGetUrl;}}function getNbMillisecondUserChooseToWait(){return ";
static private String END_EXTERN_ANIMATION = ";}";
*/
 
/*
static private String JAVASCRIPT_EXTERN_ANIMATION_1 = "var dateStartGetURL;var nb=1;var id=0;var g1;var g2;var use;var imageURI;var svgdoc;function init(evt){changeMenu();svgdoc= evt.getTarget().getOwnerDocument();g1 = svgdoc.getElementById('ofc_extern_g1');g2 = svgdoc.getElementById('ofc_extern_g2');use = svgdoc.getElementById('ofc_extern_use');var img1 = svgdoc.getElementById('ofc_extern_image1');imageURI = img1.getAttribute('xlink:href');infiniteAnimation();}function infiniteAnimation(){dateStartGetURL = new Date();if(nb == 1){getURL(imageURI + '&id=' + id, callBackImg2);}else{getURL(imageURI + '&id=' + id, callBackImg1);}if (nb==1){nb++;}else{nb--;}}";
static private String JAVASCRIPT_EXTERN_ANIMATION_2 ="function callBackImg1(data){var rootNode = parseXML(data.content, svgdoc);var firstChild = g1.getFirstChild();if(firstChild != null){g1.removeChild(firstChild);}g1.appendChild(rootNode);use.setAttribute('xlink:href', '#ofc_extern_g1');id ++;setTimeout('infiniteAnimation()', getNbMillisecondToWait());}function callBackImg2(data){var rootNode = parseXML(data.content, svgdoc);var firstChild = g2.getFirstChild();if(firstChild != null){g2.removeChild(firstChild);}g2.appendChild(rootNode);use.setAttribute('xlink:href', '#ofc_extern_g2');id ++;setTimeout('infiniteAnimation()', getNbMillisecondToWait());}";
static private String JAVASCRIPT_EXTERN_ANIMATION_3 = "function changeMenu(){var myCustomMenu = document.getElementById('OFC_Charts_Menu');var allItemElements = myCustomMenu.getElementsByTagName('item');for ( i = 0; i < allItemElements.getLength(); i++) {var text = allItemElements.item(i).getFirstChild();if(text != null){var nodeValue = text.getNodeValue();var newNodeValue='';for(j=0; j< nodeValue.length; j++){if((nodeValue.charAt(j) != '\\n') && (nodeValue.charAt(j) != '\\t')){newNodeValue += nodeValue.charAt(j);}}text.setNodeValue(newNodeValue);}}var newMenuRoot = parseXML(printNode(myCustomMenu), contextMenu);contextMenu.replaceChild( newMenuRoot, contextMenu.firstChild );}function getNbMillisecondToWait(){var dateCurrent = new Date();var nbMillisecondToGetUrl = dateCurrent - dateStartGetURL;var nbMillisecondUserChooseToWait = getNbMillisecondUserChooseToWait();if(nbMillisecondToGetUrl > nbMillisecondUserChooseToWait){return 0;}else{return nbMillisecondUserChooseToWait - nbMillisecondToGetUrl;}}function getNbMillisecondUserChooseToWait(){return ";
static private String END_EXTERN_ANIMATION = ";}";
*/
///////// END TMP test
 
///dernier 06 02 2003 17h30:
/*
static private String JAVASCRIPT_EXTERN_ANIMATION_1 = "var animContext='forward';var dateStartGetURL;var id=0;var defs;var use;var externSvgUrl;var svgdoc;var currentDefNumber = 1;var predDefNumber = 0;function init(evt){changeMenu();svgdoc= evt.getTarget().getOwnerDocument();use = svgdoc.getElementById('ofc_extern_use');defs = svgdoc.getElementById('ofc_extern_defs');var svgExternInfo = svgdoc.getElementById('ofc_extern_svg_info');externSvgUrl = svgExternInfo.getAttribute('url');infiniteAnimation();}function infiniteAnimation(){dateStartGetURL = new Date();getURL(externSvgUrl + '&id=' + id+'&animContext=' + animContext, callBack);id ++;}";
static private String JAVASCRIPT_EXTERN_ANIMATION_2 = "function callBack(data){var rootNode = parseXML(data.content, svgdoc);var g = svgdoc.createElement('g');g.setAttribute('id', 'ofc_extern_g'+currentDefNumber);g.appendChild(rootNode);defs.appendChild(g);use.setAttribute('xlink:href', '#ofc_extern_g'+currentDefNumber);var defToRemove = svgdoc.getElementById('ofc_extern_g'+predDefNumber);if(defToRemove != null){defs.removeChild(defToRemove);}predDefNumber = currentDefNumber;currentDefNumber++;if(currentDefNumber > 20){currentDefNumber = 1;}setTimeout('infiniteAnimation()', getNbMillisecondToWait());}";
static private String JAVASCRIPT_EXTERN_ANIMATION_3 = "function changeMenu(){var myCustomMenu = document.getElementById('OFC_Charts_Menu');var allItemElements = myCustomMenu.getElementsByTagName('item');for ( i = 0; i < allItemElements.getLength(); i++) {var text = allItemElements.item(i).getFirstChild();if(text != null){var nodeValue = text.getNodeValue();var newNodeValue='';for(j=0; j< nodeValue.length; j++){if((nodeValue.charAt(j) != '\\n') && (nodeValue.charAt(j) != '\\t')){newNodeValue += nodeValue.charAt(j);}}text.setNodeValue(newNodeValue);}}var newMenuRoot = parseXML(printNode(myCustomMenu), contextMenu);contextMenu.replaceChild( newMenuRoot, contextMenu.firstChild );}function getNbMillisecondToWait(){var dateCurrent = new Date();var nbMillisecondToGetUrl = dateCurrent - dateStartGetURL;var nbMillisecondUserChooseToWait = getNbMillisecondUserChooseToWait();if(nbMillisecondToGetUrl > nbMillisecondUserChooseToWait){return 0;}else{return nbMillisecondUserChooseToWait - nbMillisecondToGetUrl;}}function getNbMillisecondUserChooseToWait(){return ";
static private String END_EXTERN_ANIMATION = ";}function setBackAnimation(){alert('back');animContext='back';}function setForwardAnimation(){alert('Forward');animContext='forward';}function setStopAnimation(){animContext='stop';}";
*/
//dernier 06 02 2003 17h30:*/
 
 
///dernier 10 02 2003 17h30:
//context passé par arbre dom
/*
static private String JAVASCRIPT_EXTERN_ANIMATION_1 = "var svgExternInfo;var dateStartGetURL;id=0;var defs;var use;var externSvgUrl;var svgdoc;var currentDefNumber = 1;var predDefNumber = 0;function init(evt){changeMenu();svgdoc= evt.getTarget().getOwnerDocument();use = svgdoc.getElementById('ofc_extern_use');defs = svgdoc.getElementById('ofc_extern_defs');svgExternInfo = svgdoc.getElementById('ofc_extern_svg_info');externSvgUrl = svgExternInfo.getAttribute('url');infiniteAnimation();}function infiniteAnimation(){dateStartGetURL = new Date();if(isAnimationCanBeStop()){if(top.context='stop'){setTimeout('infiniteAnimation()', getNbMillisecondToWait());} return;};getURL(externSvgUrl + '&id=' + id+'&animContext=' + getAnimationContext(), callBack);id ++;}";
static private String JAVASCRIPT_EXTERN_ANIMATION_2 = "function callBack(data){var rootNode = parseXML(data.content, svgdoc);var g = svgdoc.createElement('g');g.setAttribute('id', 'ofc_extern_g'+currentDefNumber);g.appendChild(rootNode);defs.appendChild(g);use.setAttribute('xlink:href', '#ofc_extern_g'+currentDefNumber);var defToRemove = svgdoc.getElementById('ofc_extern_g'+predDefNumber);if(defToRemove != null){defs.removeChild(defToRemove);}predDefNumber = currentDefNumber;currentDefNumber++;if(currentDefNumber > 20){currentDefNumber = 1;}setTimeout('infiniteAnimation()', getNbMillisecondToWait());}";
static private String JAVASCRIPT_EXTERN_ANIMATION_3 = "function changeMenu(){var myCustomMenu = document.getElementById('OFC_Charts_Menu');var allItemElements = myCustomMenu.getElementsByTagName('item');for ( i = 0; i < allItemElements.getLength(); i++) {var text = allItemElements.item(i).getFirstChild();if(text != null){var nodeValue = text.getNodeValue();var newNodeValue='';for(j=0; j< nodeValue.length; j++){if((nodeValue.charAt(j) != '\\n') && (nodeValue.charAt(j) != '\\t')){newNodeValue += nodeValue.charAt(j);}}text.setNodeValue(newNodeValue);}}var newMenuRoot = parseXML(printNode(myCustomMenu), contextMenu);contextMenu.replaceChild( newMenuRoot, contextMenu.firstChild );}function getNbMillisecondToWait(){var dateCurrent = new Date();var nbMillisecondToGetUrl = dateCurrent - dateStartGetURL;var nbMillisecondUserChooseToWait = getNbMillisecondUserChooseToWait();if(nbMillisecondToGetUrl > nbMillisecondUserChooseToWait){return 0;}else{return nbMillisecondUserChooseToWait - nbMillisecondToGetUrl;}}function getNbMillisecondUserChooseToWait(){return ";
static private String END_EXTERN_ANIMATION = ";}function getAnimationContext(){if(top.context != null){return top.context;} return 'none';}function isAnimationCanBeStop(){return false;}";
*/
//static private String END_EXTERN_ANIMATION = ";}function setBackAnimation(){svgExternInfo.setAttribute('context', 'back')};function setForwardAnimation(){svgExternInfo.setAttribute('context', 'forward')};function setStopAnimation(){svgExternInfo.setAttribute('context', 'stop')};function getAnimationContext(){/*return svgExternInfo.getAttribute('context')*/ return top.context;}";
 
static private String JAVASCRIPT_EXTERN_ANIMATION_1 = "var dateStartGetURL;var id=0;var defs;var use;var externSvgUrl;var svgdoc;var currentDefNumber = 1;var predDefNumber = 0;function init(evt){changeMenu();svgdoc= evt.getTarget().getOwnerDocument();use = svgdoc.getElementById('ofc_extern_use');defs = svgdoc.getElementById('ofc_extern_defs');var svgExternInfo = svgdoc.getElementById('ofc_extern_svg_info');externSvgUrl = svgExternInfo.getAttribute('url');infiniteAnimation();}function infiniteAnimation(){dateStartGetURL = new Date();getURL(externSvgUrl + '&id=' + id, callBack);id ++;}";
static private String JAVASCRIPT_EXTERN_ANIMATION_2 = "function callBack(data){var rootNode = parseXML(data.content, svgdoc);var g = svgdoc.createElement('g');g.setAttribute('id', 'ofc_extern_g'+currentDefNumber);g.appendChild(rootNode);defs.appendChild(g);use.setAttribute('xlink:href', '#ofc_extern_g'+currentDefNumber);var defToRemove = svgdoc.getElementById('ofc_extern_g'+predDefNumber);if(defToRemove != null){defs.removeChild(defToRemove);}predDefNumber = currentDefNumber;currentDefNumber++;if(currentDefNumber > 20){currentDefNumber = 1;}setTimeout('infiniteAnimation()', getNbMillisecondToWait());}";
static private String JAVASCRIPT_EXTERN_ANIMATION_3 = "function changeMenu(){var myCustomMenu = document.getElementById('OFC_Charts_Menu');var allItemElements = myCustomMenu.getElementsByTagName('item');for ( i = 0; i < allItemElements.getLength(); i++) {var text = allItemElements.item(i).getFirstChild();if(text != null){var nodeValue = text.getNodeValue();var newNodeValue='';for(j=0; j< nodeValue.length; j++){if((nodeValue.charAt(j) != '\\n') && (nodeValue.charAt(j) != '\\t')){newNodeValue += nodeValue.charAt(j);}}text.setNodeValue(newNodeValue);}}var newMenuRoot = parseXML(printNode(myCustomMenu), contextMenu);contextMenu.replaceChild( newMenuRoot, contextMenu.firstChild );}function getNbMillisecondToWait(){var dateCurrent = new Date();var nbMillisecondToGetUrl = dateCurrent - dateStartGetURL;var nbMillisecondUserChooseToWait = getNbMillisecondUserChooseToWait();if(nbMillisecondToGetUrl > nbMillisecondUserChooseToWait){return 0;}else{return nbMillisecondUserChooseToWait - nbMillisecondToGetUrl;}}function getNbMillisecondUserChooseToWait(){return ";
static private String END_EXTERN_ANIMATION = ";}";
 
//dernier 10 02 2003 17h30:*/
 
 
//BEGIN_BLOCKER_CHART_ROTATION
/**
* Default rotation value, no rotation is applied to the graphic
*/
static public final int ROTATE_NONE = 0;
 
/**
* A 90 degrees rotation is applied to the graphic
*/
static public final int ROTATE_90_DEGREE = 1;
 
/**
* A 180 degrees rotation is applied to the graphic
*/
static public final int ROTATE_180_DEGREE = 2;
 
/**
* A 270 degrees rotation is applied to the graphic
*/
static public final int ROTATE_270_DEGREE = 3;
private int _rotateValue = ROTATE_NONE;
 
//END_BLOCKER_CHART_ROTATION
 
//presentation
private int _nbPixelFreeArroundImageForPresentation = 5;
private final int _nbPixelBetweenGraphicAndLegend = 10;
private Color _imageBagroundColor = Color.black;
private Color _graphicBackgroundColor = Color.white;
 
//
private int _width;
private int _height;
protected Legend _legend = new Legend();
protected ColorPalette _colorPalette = new ColorPalette();
 
private int _coeff3dEffect = 0;
 
private boolean _isBackgroundColorVisible = true;
 
protected Chart(int width, int height) {
_width = width;
_height = height;
 
_imageBagroundColor = Color.white;
_graphicBackgroundColor = Color.white;
}
 
public void setLegend(Legend legend){
_legend = legend;
}
/**
* Sets the background color visibility according to the parameter value.
* @param isBackGroundColorVisible If true the background color is visible
*/
public void setBackgroundColorVisible(boolean isBackGroundColorVisible) {
_isBackgroundColorVisible = isBackGroundColorVisible;
}
 
/**
* Get the 3d effect value previously set (default value is 0)
* @return 3d effect value
*/
public int get3dEffectValue() {
return _coeff3dEffect;
}
 
/**
* Sets the 3d effect value.
* The default value is 0 it corresponds to a 2D presentation.
* As an exemple, for a bar chart this value is used to compute the depth of the bars.
* @param coeff3dEffect 3d effect value to be set, a positive int value
*/
public void set3dEffectValue(int coeff3dEffect) {
if (coeff3dEffect > 0) {
_coeff3dEffect = coeff3dEffect;
}
}
 
/**
* Sets the image background color
* @param color The image background color to be set
*/
public void setImageBackgroundColor(Color color) {
_imageBagroundColor = color;
}
 
/**
* Sets the graphic background color
* @param color The graphic background color to be set
*/
public void setGraphicBackgroundColor(Color color) {
_graphicBackgroundColor = color;
}
 
/**
* Sets font size to be used for the legend
* @param size The legend font size to be set
*/
public void setLegendFontSize(int size) {
_legend.setFontSize(size);
}
 
//BEGIN_BLOCKER_CHART_ROTATION
/**
* Sets a rotation value for the chart.
* @param rotationValue Values allowed for the rotation value are:
*
* <li> ROTATE_NONE: no rotation (default value) </li>
* <li> ROTATE_90_DEGREE: 90 degrees rotation </li>
* <li> ROTATE_180_DEGREE: 180 degrees rotation </li>
* <li> ROTATE_270_DEGREE: 270 degrees rotation </li>
* <br>
* any other value is replaced by the default value.
*/
public void setRotateValue(int rotationValue) {
if ( (rotationValue != ROTATE_NONE) && (rotationValue != ROTATE_90_DEGREE) &&
(rotationValue != ROTATE_180_DEGREE) &&
(rotationValue != ROTATE_270_DEGREE)) {
return;
}
_rotateValue = rotationValue;
}
 
//END_BLOCKER_CHART_ROTATION
 
/**
* Draws a chart and produce a PNG result in a file
* @param pathFileName Resulting file name to store the generated JPEG
* @throws OFCChartsException
*/
public void drawPNG(String pathFileName) throws OFCChartsException {
try {
drawJPEG(new FileOutputStream(pathFileName));
}
catch (FileNotFoundException e) {
throw new OFCChartsException(e.getMessage());
}
}
 
/**
* Draws a chart and produce a PNG result in an OutputStream
* @param out OutputStream The Output Stream to write chart
* @throws OFCChartsException
*/
public void drawPNG(OutputStream out) throws OFCChartsException {
BufferedImage image = getBufferedImage();
if (image == null) {
// System.out.println("histo : _valuesOnY == null or _valuesOnX == null");
return;
 
}
 
try {
PngEncoderB png = new PngEncoderB(image);
png.setCompressionLevel(5);
out.write(png.pngEncode());
out.flush();
out.close();
}
catch (IOException e) {
e.printStackTrace();
throw new OFCChartsException(e.getMessage());
}
}
 
/**
* Draws a chart and produce a JPEG result in a file
* @param pathFileName Resulting file name to store the generated JPEG
* @throws OFCChartsException
*/
public void drawJPEG(String pathFileName) throws OFCChartsException {
try {
drawJPEG(new FileOutputStream(pathFileName));
}
catch (FileNotFoundException e) {
throw new OFCChartsException(e.getMessage());
}
}
 
/**
* Draws a chart and produce a JPEG result in an OutputStream
* @param out OutputStream The Output Stream to write chart
* @throws OFCChartsException
*/
public void drawJPEG(OutputStream out) throws OFCChartsException {
BufferedImage image = getBufferedImage();
if (image == null) {
// System.out.println("histo : _valuesOnY == null or _valuesOnX == null");
return;
 
}
try {
JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(out);
 
JPEGEncodeParam jep = jpeg.getDefaultJPEGEncodeParam(image);
jep.setDensityUnit(JPEGEncodeParam.DENSITY_UNIT_DOTS_INCH);
jep.setYDensity(1200);
jep.setXDensity(1200);
jep.setQuality(1.0f, false);
jpeg.encode(image, jep);
 
//jpeg.encode(image);
out.flush();
out.close();
}
catch (java.io.IOException e) {
e.printStackTrace();
throw new OFCChartsException(e.getMessage());
}
}
 
/**
* Sets color Palette.
* This Palette replaces the default one.
* @param colorPalette Palette of colors to be set
*/
public void setColorPalette(ColorPalette colorPalette) {
_colorPalette = colorPalette;
setAllSeriesColorForceFromPalette(getSeriesContainer());
}
 
ColorPalette getColorPalette() {
return _colorPalette;
}
 
/**
* Get buffered image
* @return Buffered image of chart
* @throws OFCChartsException
*/
public BufferedImage getBufferedImage() throws OFCChartsException {
if (getNbSeries() == 0) {
//System.out.println("histo : _valuesOnY == null or _valuesOnX == null");
return null;
}
 
BufferedImage image;
//BEGIN_BLOCKER_CHART_ROTATION
switch (_rotateValue) {
case ROTATE_NONE:
case ROTATE_180_DEGREE:
 
//END_BLOCKER_CHART_ROTATION
image = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_RGB);
//BEGIN_BLOCKER_CHART_ROTATION
break;
case ROTATE_90_DEGREE:
case ROTATE_270_DEGREE:
image = new BufferedImage(_height, _width, BufferedImage.TYPE_INT_RGB);
break;
default:
throw new OFCChartsException("Invalid rotate value");
}
//END_BLOCKER_CHART_ROTATION
 
Graphics2D graphics2D = image.createGraphics();
drawChart(graphics2D);
graphics2D.dispose();
return image;
}
 
/**
* Draws a chart and produces the result as a SVG file
* @param pathFileName Resulting file name to store the generated SVG
* @throws OFCChartsException
*/
public void drawSVG(String pathFileName) throws OFCChartsException {
try {
drawSVG(new FileOutputStream(pathFileName));
}
catch (FileNotFoundException e) {
throw new OFCChartsException(e.getMessage());
}
}
 
/**
* Draws a chart within a given SVG context and produces the result as a SVG file
* @param pathFileName Resulting file name to store the generated SVG
* @param svgContext Contains information defining the SVG context
* @throws OFCChartsException
*/
public void drawSVG(String pathFileName, SVGContext svgContext) throws
OFCChartsException {
try {
drawSVG(new FileOutputStream(pathFileName), svgContext);
}
catch (FileNotFoundException e) {
throw new OFCChartsException(e.getMessage());
}
}
 
/**
* Draws a chart and produces the result as a SVG stored in an OuputStream
* @param out OutputStream The OutputStream to write chart
* @throws OFCChartsException
*/
public void drawSVG(OutputStream out) throws OFCChartsException {
try {
drawSVG(new OutputStreamWriter(out, "UTF-8"), null);
}
catch (IOException e) {
throw new OFCChartsException(e.getMessage());
}
}
 
/**
* Draws a chart within a given SVG context and produces the result as a SVGstored in an OuputStream
* @param out OutputStream The OutputStream to write chart
* @param svgContext Contains information defining the SVG context
* @throws OFCChartsException
*/
public void drawSVG(OutputStream out, SVGContext svgContext) throws
OFCChartsException {
try {
drawSVG(new OutputStreamWriter(out, "UTF-8"), svgContext);
}
catch (IOException e) {
throw new OFCChartsException(e.getMessage());
}
}
 
/**
* Draw char as SVG with particular context
* @param out Writer to write chart
* @param svgContext SVG Informations
* @throws OFCChartsException
*/
// cette methode est mise en privée car elle ne marche peut etre pas avec tous les caracteres. probleme codage UTF-8
private void drawSVG(Writer out, SVGContext svgContext) throws
OFCChartsException {
try {
// Get a DOMImplementation
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
 
// Create an instance of org.w3c.dom.Document
Document document = domImpl.createDocument(null, "svg", null);
//new
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
// Create an instance of the SVG Generator
//SVGGraphics2D svgGraphics2D = new SVGGraphics2D(document);
SVGGraphics2D svgGraphics2D = new SVGGraphics2D(ctx, false);
svgGraphics2D.setSVGCanvasSize(new Dimension(_width, _height));
//end new
 
// Ask the test to render into the SVG Graphics2D implementation
drawChart(svgGraphics2D);
 
modifySvg(svgGraphics2D, svgContext);
 
// Finally, stream out SVG to the standard output using UTF-8
// character to byte encoding
boolean useCSS = true; // we want to use CSS style attribute
//Writer wout = new OutputStreamWriter(out, "UTF-8");
svgGraphics2D.stream(out, useCSS);
svgGraphics2D.dispose();
}
catch (IOException e) {
throw new OFCChartsException(e.getMessage());
}
}
 
/**
* Draws a chart and returns the SVG as a String
* @return String It contains the SVG result
* @throws OFCChartsException
*/
public String drawSVG() throws OFCChartsException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
drawSVG(out, null);
return out.toString();
 
//ci apres ne marche pas pour certaian caractere comme '°' par exemple. sans doute pb UTF-8
//StringWriter stringWriter = new StringWriter();
//drawSVG(stringWriter);
//return stringWriter.toString();
}
 
/**
* Draws a chart within a given SVG context and returns the SVG as a String
* @param svgContext Contains information defining the SVG context
* @return String It contains the SVG result
* @throws OFCChartsException
*/
public String drawSVG(SVGContext svgContext) throws OFCChartsException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
drawSVG(out, svgContext);
return out.toString();
 
//ci apres ne marche pas pour certaian caractere comme '°' par exemple. sans doute pb UTF-8
//StringWriter stringWriter = new StringWriter();
//drawSVG(stringWriter);
//return stringWriter.toString();
}
 
//BEGIN_BLOCKER_CHART_ANIMATION
/**
* Draws an animated chart and produces the result as a SVG file
* @param pathFileName Resulting file name to store the generated SVG
* @param svgAnimationContext Contains the information related to the animation
* @throws OFCChartsException
*/
public void drawAnimateSVG(String pathFileName,
SVGAnimationContext svgAnimationContext) throws
OFCChartsException {
try {
drawAnimateSVG(new FileOutputStream(pathFileName), svgAnimationContext);
}
catch (FileNotFoundException e) {
throw new OFCChartsException(e.getMessage());
}
}
 
/**
* Draws an animated chart within a given SGV context and produces the result as a SVG file
* @param pathFileName Resulting file name to store the generated SVG
* @param svgAnimationContext Contains the information related to the animation
* @param svgContext Contains information defining the SVG context
* @throws OFCChartsException
*/
public void drawAnimateSVG(String pathFileName,
SVGAnimationContext svgAnimationContext,
SVGContext svgContext) throws OFCChartsException {
try {
drawAnimateSVG(new FileOutputStream(pathFileName), svgAnimationContext,
svgContext);
}
catch (FileNotFoundException e) {
throw new OFCChartsException(e.getMessage());
}
}
 
/**
* Draws an animated chart and produces the result as an OutputStream
* @param out OutputStream The OutputStream to write the chart
* @param svgAnimationContext Contains the information related to the animation
* @throws OFCChartsException
*/
public void drawAnimateSVG(OutputStream out,
SVGAnimationContext svgAnimationContext) throws
OFCChartsException {
try {
drawAnimateSVG(new OutputStreamWriter(out, "UTF-8"), svgAnimationContext, null);
}
catch (IOException e) {
throw new OFCChartsException(e.getMessage());
}
}
 
/**
* Draws an animated chart within a given SVG context and produces the result as an OutputStream
* @param out The OutputStream to write the chart
* @param svgAnimationContext Contains the information related to the animation
* @param svgContext Contains information defining the SVG context
* @throws OFCChartsException
*/
public void drawAnimateSVG(OutputStream out,
SVGAnimationContext svgAnimationContext,
SVGContext svgContext) throws OFCChartsException {
try {
drawAnimateSVG(new OutputStreamWriter(out, "UTF-8"), svgAnimationContext,
svgContext);
}
catch (IOException e) {
throw new OFCChartsException(e.getMessage());
}
}
 
private void modifySvg(SVGGraphics2D svgGraphics2D, SVGContext svgContext) {
if (svgContext == null) {
return;
}
if (svgContext.getRootTransformValue() != null) {
Document docSvg = svgGraphics2D.getDOMFactory();
SVGGraphics2D g1 = (SVGGraphics2D) svgGraphics2D.create();
Element topLevelGroup1 = g1.getTopLevelGroup();
topLevelGroup1.setAttributeNS(null, "transform",
svgContext.getRootTransformValue());
svgGraphics2D.setTopLevelGroup(topLevelGroup1);
g1.dispose();
}
}
 
/**
* Draw animate char as SVG with particular context
* @param out Writer to write chart
* @param svgAnimationContext Animation Informations
* @param svgContext SVG Informations
* @throws OFCChartsException
*/
// cette methode est mise en privée car elle ne marche peut etre pas avec tous les caracteres. probleme codage UTF-8
private void drawAnimateSVG(Writer out,
SVGAnimationContext svgAnimationContext,
SVGContext svgContext) throws OFCChartsException {
try {
// Get a DOMImplementation
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
 
// Create an instance of org.w3c.dom.Document
Document document = domImpl.createDocument(null, "svg", null);
 
// Create an instance of the SVG Generator
SVGGraphics2D svgGraphics2D = new SVGGraphics2D(document);
 
// Ask the test to render into the SVG Graphics2D implementation
drawAnimateSVGChart(svgGraphics2D, svgAnimationContext);
 
modifySvg(svgGraphics2D, svgContext);
 
if (svgAnimationContext.isExternalAnimation()) {
Document docSvg = svgGraphics2D.getDOMFactory();
SVGGraphics2D g1 = (SVGGraphics2D) svgGraphics2D.create();
Element topLevelGroup1 = g1.getTopLevelGroup();
 
////start 2ème essai javascript intégré
 
//menu
appendMenu(docSvg, topLevelGroup1);
 
//javascript animation and dynamic menu
topLevelGroup1.setAttributeNS(null, "onload", "init(evt)");
Element scriptElement = docSvg.createElement("script");
topLevelGroup1.insertBefore(scriptElement, topLevelGroup1.getFirstChild());
scriptElement.appendChild(docSvg.createCDATASection(
getJavascriptToManageExternalAnimation(svgAnimationContext)));
 
//struct for javascript animation
//<defs id="ofc_extern_defs">
Element defsElement = docSvg.createElement("defs");
defsElement.setAttributeNS(null, "id", "ofc_extern_defs");
topLevelGroup1.appendChild(defsElement);
 
//<ofccharts id="ofc_extern_svg_info" url="anim"/>
Element ofcChartsElement = docSvg.createElement("ofccharts");
ofcChartsElement.setAttributeNS(null, "id", "ofc_extern_svg_info");
ofcChartsElement.setAttributeNS(null, "url",
svgAnimationContext.
getExternalAnimationURL());
//ofcChartsElement.setAttributeNS(null, "context", "back");
defsElement.appendChild(ofcChartsElement);
 
//<g id="ofc_extern_init"/>
Element gElement = docSvg.createElement("g");
gElement.setAttributeNS(null, "id", "ofc_extern_init");
defsElement.appendChild(gElement);
 
//<use xlink:href="#ofc_extern_init" id="ofc_extern_use" />
Element useElement = docSvg.createElement("use");
useElement.setAttributeNS(null, "id", "ofc_extern_use");
useElement.setAttributeNS(null, "xlink:href", "#ofc_extern_init");
topLevelGroup1.appendChild(useElement);
 
//end 2ème essai javascript intégré
 
//essai javascrip integré premier essai
/*
appendMenu(docSvg, topLevelGroup1);
 
Element defsElement = docSvg.createElement("defs");
topLevelGroup1.appendChild(defsElement);
 
//new
//svgGraphics2D.getRoot().setAttributeNS(null, "onload", "toto(evt)");
topLevelGroup1.setAttributeNS(null, "onload", "init(evt)");
 
Element scriptElement = docSvg.createElement("script");
topLevelGroup1.insertBefore(scriptElement, topLevelGroup1.getFirstChild());
scriptElement.appendChild(docSvg.createCDATASection(getJavascriptToManageExternalAnimation(svgAnimationContext)));
//end new
 
Element gElement = docSvg.createElement("g");
gElement.setAttributeNS(null, "id", "ofc_extern_g1");
defsElement.appendChild(gElement);
 
Element imageElement = docSvg.createElement("image");
imageElement.setAttributeNS(null, "id", "ofc_extern_image1");
imageElement.setAttributeNS(null, "x", "0");
imageElement.setAttributeNS(null, "y", "0");
imageElement.setAttributeNS(null, "width", ""+_width);
imageElement.setAttributeNS(null, "height", ""+_height);
imageElement.setAttributeNS(null, "xlink:href", svgAnimationContext.getURIExternalAnimation());
gElement.appendChild(imageElement);
 
 
gElement = docSvg.createElement("g");
gElement.setAttributeNS(null, "id", "ofc_extern_g2");
defsElement.appendChild(gElement);
 
imageElement = docSvg.createElement("image");
imageElement.setAttributeNS(null, "id", "ofc_extern_image2");
imageElement.setAttributeNS(null, "x", "0");
imageElement.setAttributeNS(null, "y", "0");
imageElement.setAttributeNS(null, "width", ""+_width);
imageElement.setAttributeNS(null, "height", ""+_height);
imageElement.setAttributeNS(null, "xlink:href", svgAnimationContext.getURIExternalAnimation());
gElement.appendChild(imageElement);
 
Element useElement = docSvg.createElement("use");
useElement.setAttributeNS(null, "id", "ofc_extern_use");
useElement.setAttributeNS(null, "xlink:href", "#ofc_extern_g1");
topLevelGroup1.appendChild(useElement);
*/
//end premier essai javascrip integré
 
/* first essai ok
Element defsElement = docSvg.createElement("defs");
topLevelGroup1.appendChild(defsElement);
 
Element gElement = docSvg.createElement("g");
gElement.setAttributeNS(null, "id", "ofc_extern_g1");
defsElement.appendChild(gElement);
 
Element imageElement = docSvg.createElement("image");
imageElement.setAttributeNS(null, "id", "ofc_extern_image1");
imageElement.setAttributeNS(null, "x", "0");
imageElement.setAttributeNS(null, "y", "0");
imageElement.setAttributeNS(null, "width", ""+_width);
imageElement.setAttributeNS(null, "height", ""+_height);
imageElement.setAttributeNS(null, "xlink:href", svgAnimationContext.getURIExternalAnimation());
gElement.appendChild(imageElement);
 
 
gElement = docSvg.createElement("g");
gElement.setAttributeNS(null, "id", "ofc_extern_g2");
defsElement.appendChild(gElement);
 
imageElement = docSvg.createElement("image");
imageElement.setAttributeNS(null, "id", "ofc_extern_image2");
imageElement.setAttributeNS(null, "x", "0");
imageElement.setAttributeNS(null, "y", "0");
imageElement.setAttributeNS(null, "width", ""+_width);
imageElement.setAttributeNS(null, "height", ""+_height);
imageElement.setAttributeNS(null, "xlink:href", svgAnimationContext.getURIExternalAnimation());
gElement.appendChild(imageElement);
 
Element useElement = docSvg.createElement("use");
useElement.setAttributeNS(null, "id", "ofc_extern_use");
useElement.setAttributeNS(null, "xlink:href", "#ofc_extern_g1");
topLevelGroup1.appendChild(useElement);
 
 
first essai ok*/
 
/* old ok mais clignote
Element gElement = docSvg.createElement("g");
gElement.setAttributeNS(null, "id", "ofc_extern_animation");
topLevelGroup1.appendChild(gElement);
//gElement.setAttributeNS(null, "ofc_extern_animation", svgAnimationContext.getURIExternalAnimation());
 
Element imageElement = docSvg.createElement("image");
imageElement.setAttributeNS(null, "x", "0");
imageElement.setAttributeNS(null, "y", "0");
imageElement.setAttributeNS(null, "width", ""+_width);
imageElement.setAttributeNS(null, "height", ""+_height);
imageElement.setAttributeNS(null, "xlink:href", svgAnimationContext.getURIExternalAnimation());
gElement.appendChild(imageElement);
old ok mais clignote*/
 
/* old essai
//<animate dur="0:0:2.0" attributeName="xlink:href" repeatCount="indefinite" values="anim1.svg;anim2.svg;anim3.svg;anim4.svg;anim5.svg"/>
Element animateElement = docSvg.createElement("animate");
animateElement.setAttributeNS(null, "dur", "0:1:40.0");
animateElement.setAttributeNS(null, "attributeName", "xlink:href");
animateElement.setAttributeNS(null, "repeatCount", "indefinite");
String str = svgAnimationContext.getURIExternalAnimation();
for(int i=0; i<100; i++){
str +=";";
str += svgAnimationContext.getURIExternalAnimation() + "&img=" + i;
}
 
animateElement.setAttributeNS(null, "values", str);
imageElement.appendChild(animateElement);
old essai */
 
svgGraphics2D.setTopLevelGroup(topLevelGroup1);
g1.dispose();
}
 
// Finally, stream out SVG to the standard output using UTF-8
// character to byte encoding
boolean useCSS = true; // we want to use CSS style attribute
//Writer wout = new OutputStreamWriter(out, "UTF-8");
svgGraphics2D.stream(out, useCSS);
 
/*tmp test
if(svgAnimationContext.isExternalAnimation()){
Document docSvg = svgGraphics2D.getDOMFactory();
SVGGraphics2D g1 = (SVGGraphics2D)svgGraphics2D.create();
Element topLevelGroup1 = g1.getTopLevelGroup();
appendMenu(docSvg, topLevelGroup1);
svgGraphics2D.setTopLevelGroup(topLevelGroup1);
g1.dispose();
}
end tmp test*/
 
svgGraphics2D.dispose();
}
catch (IOException e) {
throw new OFCChartsException(e.getMessage());
}
}
 
/**
* Draws an animated chart and return the SVG as a String
* @param svgAnimationContext Contains the information related to the animation
* @return String contains the SVG chart
* @throws OFCChartsException
*/
public String drawAnimateSVG(SVGAnimationContext svgAnimationContext) throws
OFCChartsException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
drawAnimateSVG(out, svgAnimationContext);
return out.toString();
 
//ci apres ne marche pas pour certaian caractere comme '°' par exemple. sans doute pb UTF-8
//StringWriter stringWriter = new StringWriter();
//drawSVG(stringWriter);
//return stringWriter.toString();
}
 
//END_BLOCKER_CHART_ANIMATION
 
/**
* Get a Vector containing all the Series (data) defining the chart.
* The order in the Vector reflects the order in which the Series have been added. The real class of the series depends on the chart subclass implied.
* @return Vector which contains all series
*/
public Vector getAllSeriesOrderByDisplayNumber() {
return getSeriesContainer().getAllSeriesOrderByDisplayNumber();
}
 
/**
* Sets the legend display mode. <br>
* <em> Restriction: The legend couldn't look like a table.</em>
* @param legendDisplayMode The legend display mode to set.
* @see Legend
*/
public void setLegendDisplayMode(int legendDisplayMode) {
_legend.setLegendDisplayMode(legendDisplayMode);
}
 
/**
* Sets the legend align mode
* @param legendAlignMode The legend align mode to set.
* @see Legend
*/
public void setLegendAlignMode(int legendAlignMode) {
_legend.setLegendAlignMode(legendAlignMode);
}
 
protected void setAllSeriesColorFromPalette(SeriesContainer allSeries) {
//setAllSeriesColorFromPalette(1, allSeries);
setAllSeriesColorFromPalette(0, allSeries);
}
 
protected void setAllSeriesColorFromPalette(int numFirstColorInPalette,
SeriesContainer allSeries) {
setAllSeriesColorFromPalette(numFirstColorInPalette, allSeries, false);
}
 
protected void setAllSeriesColorForceFromPalette(SeriesContainer allSeries) {
//setAllSeriesColorFromPalette(1, allSeries, true);
setAllSeriesColorFromPalette(0, allSeries, true);
}
 
protected void setAllSeriesColorForceFromPalette(int numFirstColorInPalette,
SeriesContainer allSeries) {
setAllSeriesColorFromPalette(numFirstColorInPalette, allSeries, true);
}
 
private void setAllSeriesColorFromPalette(int numFirstColorInPalette,
SeriesContainer allSeries,
boolean isForce) {
int numCurrentColorInPalette = numFirstColorInPalette;
Enumeration enumAllSeries = allSeries.getEnumAllSeriesOrderByDisplayNumber();
while (enumAllSeries.hasMoreElements()) {
Series series = (Series) enumAllSeries.nextElement();
if ( (series.getColor() == null) || (isForce)) {
series.setColor(_colorPalette.getColorAt(numCurrentColorInPalette));
numCurrentColorInPalette++;
}
}
}
 
protected int getNbPixelFreeArroundGraphic() {
return 0;
}
 
protected int getXTopLeftGraphic(Graphics2D graphics2D) {
return _nbPixelFreeArroundImageForPresentation +
getNbPixelFreeArroundGraphic();
}
 
protected int getYTopLeftGraphic(Graphics2D graphics2D) {
int yTopLeftGraphic = _nbPixelFreeArroundImageForPresentation +
getNbPixelFreeArroundGraphic();
yTopLeftGraphic += _coeff3dEffect;
if (_legend.getLegendDisplayMode() == Legend.LEGEND_DISPLAY_MODE_TOP) {
yTopLeftGraphic +=
_legend.getSizeHeightOfLegendAtBottom(graphics2D,
getAllSeriesOrderByDisplayNumber());
}
return yTopLeftGraphic;
}
 
protected int getGraphicWidth(Graphics2D graphics2D) {
int graphicWidth = getChartWidth() -
(_nbPixelFreeArroundImageForPresentation * 2) -
_legend.getSizeWidthOfLegendAtLeft(graphics2D, getEnumAllSeries()) -
(getNbPixelFreeArroundGraphic() * 2);
if (_legend.getLegendDisplayMode() == Legend.LEGEND_DISPLAY_MODE_RIGHT) {
graphicWidth -= _nbPixelBetweenGraphicAndLegend;
}
graphicWidth -= _coeff3dEffect;
return graphicWidth;
}
 
protected int getGraphicHeight(Graphics2D graphics2D) throws
OFCChartsException {
int graphicHeight = getChartHeight() -
(_nbPixelFreeArroundImageForPresentation * 2) -
_legend.getSizeHeightOfLegendAtBottom(graphics2D,
getAllSeriesOrderByDisplayNumber()) -
(getNbPixelFreeArroundGraphic() * 2);
 
graphicHeight -= _coeff3dEffect;
 
if ( (_legend.getLegendDisplayMode() == Legend.LEGEND_DISPLAY_MODE_BOTTOM) ||
(_legend.getLegendDisplayMode() == Legend.LEGEND_DISPLAY_MODE_TOP)) {
graphicHeight -= _nbPixelBetweenGraphicAndLegend;
}
return graphicHeight;
}
 
protected int getXTopLeftLegend(Graphics2D graphics2D) throws
OFCChartsException {
return getXTopLeftLegend(getXTopLeftGraphic(graphics2D),
getYTopLeftGraphic(graphics2D),
getGraphicWidth(graphics2D),
getGraphicHeight(graphics2D), graphics2D);
}
 
protected int getXTopLeftLegend(int xTopLeftGraphic, int yTopLeftGraphic,
int graphicWidth, int graphicHeight,
Graphics2D graphics2D) {
int xTopLeftLegend = 0;
switch (_legend.getLegendDisplayMode()) {
case Legend.LEGEND_DISPLAY_MODE_RIGHT:
xTopLeftLegend = xTopLeftGraphic + graphicWidth +
_nbPixelBetweenGraphicAndLegend;
break;
case Legend.LEGEND_DISPLAY_MODE_BOTTOM:
case Legend.LEGEND_DISPLAY_MODE_TOP:
xTopLeftLegend = (xTopLeftGraphic + (graphicWidth / 2)) -
(_legend.getSizeWidthOfLegendAtBottom(graphics2D, getEnumAllSeries()) /
2);
break;
}
xTopLeftLegend += _coeff3dEffect;
return xTopLeftLegend;
}
 
protected int getYTopLeftLegend(Graphics2D graphics2D) throws
OFCChartsException {
return getYTopLeftLegend(getXTopLeftGraphic(graphics2D),
getYTopLeftGraphic(graphics2D),
getGraphicWidth(graphics2D),
getGraphicHeight(graphics2D), graphics2D);
}
 
protected int getYTopLeftLegend(int xTopLeftGraphic, int yTopLeftGraphic,
int graphicWidth, int graphicHeight,
Graphics2D graphics2D) throws
OFCChartsException {
int yTopLeftLegend = 0;
switch (_legend.getLegendDisplayMode()) {
case Legend.LEGEND_DISPLAY_MODE_RIGHT:
yTopLeftLegend = yTopLeftGraphic;
break;
case Legend.LEGEND_DISPLAY_MODE_BOTTOM:
yTopLeftLegend = yTopLeftGraphic + graphicHeight +
_nbPixelBetweenGraphicAndLegend;
break;
case Legend.LEGEND_DISPLAY_MODE_TOP:
yTopLeftLegend = yTopLeftGraphic -
_legend.
getSizeHeightOfLegendAtBottom(graphics2D,
getAllSeriesOrderByDisplayNumber());
break;
}
return yTopLeftLegend;
}
 
protected int getChartWidth() {
return _width;
}
 
protected int getChartHeight() {
return _height;
}
 
protected void drawGraphicBackground(int xTopLeftGraphic, int yTopLeftGraphic,
int graphicWidth, int graphicHeight,
Graphics2D graphics2D) {
graphics2D.setColor(_graphicBackgroundColor);
graphics2D.drawRect(xTopLeftGraphic, yTopLeftGraphic, graphicWidth,
graphicHeight);
graphics2D.fillRect(xTopLeftGraphic, yTopLeftGraphic, graphicWidth,
graphicHeight);
}
 
abstract protected SeriesContainer getSeriesContainer();
 
private void drawChart(Graphics2D graphics2D) throws OFCChartsException {
setGraphics2dQuality(graphics2D);
//add rotation if necessary
//BEGIN_BLOCKER_CHART_ROTATION
rotateGraphic(graphics2D);
//END_BLOCKER_CHART_ROTATION
drawCommonPartOfChart(graphics2D);
doDrawChart(graphics2D);
}
 
private void drawChart(SVGGraphics2D svgGraphics2D) throws OFCChartsException {
setSvgGraphics2dQuality(svgGraphics2D);
//add rotation if necessary
//BEGIN_BLOCKER_CHART_ROTATION
rotateGraphic(svgGraphics2D);
//END_BLOCKER_CHART_ROTATION
drawCommonPartOfChart(svgGraphics2D);
doDrawChart(svgGraphics2D);
}
 
abstract protected void doDrawChart(Graphics2D graphics2D) throws
OFCChartsException;
 
//BEGIN_BLOCKER_CHART_ANIMATION
private void drawAnimateSVGChart(SVGGraphics2D graphics2D,
SVGAnimationContext svgAnimationContext) throws
OFCChartsException {
setSvgGraphics2dQuality(graphics2D);
//add rotation if necessary
//BEGIN_BLOCKER_CHART_ROTATION
rotateGraphic(graphics2D);
//END_BLOCKER_CHART_ROTATION
drawCommonPartOfChart(graphics2D);
doDrawAnimateSVGChart(graphics2D, svgAnimationContext);
}
 
protected void doDrawAnimateSVGChart(SVGGraphics2D graphics2D,
SVGAnimationContext svgAnimationContext) throws
OFCChartsException {
doDrawChart(graphics2D);
}
 
//END_BLOCKER_CHART_ANIMATION
 
private void setSvgGraphics2dQuality(SVGGraphics2D svgGraphics2D) {
setGraphics2dQuality(svgGraphics2D);
if (_rotateValue != ROTATE_NONE) {
//must be force for bug rotation svg in plugin adobe:
RenderingHints render = svgGraphics2D.getRenderingHints();
render.put(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
render.put(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
}
}
 
private void setGraphics2dQuality(Graphics2D graphics2D) {
RenderingHints render = graphics2D.getRenderingHints();
render.put(RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
//
render.put(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
render.put(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
render.put(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_DISABLE);
render.put(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
render.put(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
//
render.put(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
render.put(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
 
graphics2D.setRenderingHints(render);
}
 
private void drawCommonPartOfChart(Graphics2D graphics2D) {
//_legend.setLegendWidth((_width * 3)/4);
_legend.setLegendWidth(OFCMath.getValueFromPercentage(95, _width));
if (_isBackgroundColorVisible) {
graphics2D.setColor(_imageBagroundColor);
graphics2D.fillRect(0, 0, _width, _height);
}
}
 
private Enumeration getEnumAllSeries() {
return getSeriesContainer().getEnumAllSeries();
}
 
protected int getNbSeries() {
return getSeriesContainer().getNbSeries();
}
 
 
//BEGIN_BLOCKER_CHART_ROTATION
private void rotateGraphic(Graphics2D graphics2D) throws OFCChartsException {
switch (_rotateValue) {
case ROTATE_NONE:
break;
case ROTATE_90_DEGREE:
//90 degree = 1.57 radian
//graphics2D.rotate(1.57, _height/2, _height/2);
graphics2D.rotate(Math.toRadians(90), _height / 2, _height / 2);
break;
case ROTATE_180_DEGREE:
//180 degree = 3.14 radian
//graphics2D.rotate(3.14, _width/2, _height/2);
graphics2D.rotate(Math.toRadians(180), _width / 2, _height / 2);
break;
case ROTATE_270_DEGREE:
//270 degree = 4.71 radian
//graphics2D.rotate(4.71, _width/2, _width/2);
graphics2D.rotate(Math.toRadians(270), _width / 2, _width / 2);
break;
default:
throw new OFCChartsException("Invalid rotate value : use ROTATE_90_DEGREE, ROTATE_180_DEGREE, ROTATE_270_DEGREE ");
}
}
 
//END_BLOCKER_CHART_ROTATION
 
private void appendMenu(Document docSvg, Element svgElementWitchIncludMenu) {
Element defsElement = docSvg.createElement("defs");
svgElementWitchIncludMenu.appendChild(defsElement);
 
//<menu>
//start adobe menu
Element menuElement = docSvg.createElement("menu");
menuElement.setAttributeNS(null, "id", "OFC_Charts_Menu");
defsElement.appendChild(menuElement);
 
//<header>Adobe SVG Viewer</header>
Element headerElement = docSvg.createElement("header");
Text text = docSvg.createTextNode("Adobe SVG Viewer");
headerElement.appendChild(text);
//headerElement.setData("Adobe SVG Viewer");
menuElement.appendChild(headerElement);
 
//<item action="Open" id="Open">Open</item>
Element itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "Open");
itemElement.setAttributeNS(null, "id", "Open");
text = docSvg.createTextNode("Open");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<item action="OpenNew" id="OpenNew">Open in New Window</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "OpenNew");
itemElement.setAttributeNS(null, "id", "OpenNew");
text = docSvg.createTextNode("Open in New Window");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<separator/>
Element separatorElement = docSvg.createElement("separator");
menuElement.appendChild(separatorElement);
 
//<item action="ZoomIn" id="ZoomIn">Zoom In</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "ZoomIn");
itemElement.setAttributeNS(null, "id", "ZoomIn");
text = docSvg.createTextNode("Zoom In");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<item action="ZoomOut" id="ZoomOut">Zoom Out</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "ZoomOut");
itemElement.setAttributeNS(null, "id", "ZoomOut");
text = docSvg.createTextNode("Zoom Out");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<item action="OriginalView" id="OriginalView">Original View</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "OriginalView");
itemElement.setAttributeNS(null, "id", "OriginalView");
text = docSvg.createTextNode("Original View");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<separator/>
separatorElement = docSvg.createElement("separator");
menuElement.appendChild(separatorElement);
 
//<item action="Quality" id="Quality">Higher Quality</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "Quality");
itemElement.setAttributeNS(null, "id", "Quality");
text = docSvg.createTextNode("Higher Quality");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<item action="Pause" id="Pause">Pause</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "Pause");
itemElement.setAttributeNS(null, "id", "Pause");
text = docSvg.createTextNode("Pause");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<item action="Mute" id="Mute">Mute</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "Mute");
itemElement.setAttributeNS(null, "id", "Mute");
text = docSvg.createTextNode("Mute");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<separator/>
separatorElement = docSvg.createElement("separator");
menuElement.appendChild(separatorElement);
 
//<item action="Find" id="Find">Find...</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "Find");
itemElement.setAttributeNS(null, "id", "Find");
text = docSvg.createTextNode("Find...");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<item action="FindAgain" id="FindAgain">Find Again</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "FindAgain");
itemElement.setAttributeNS(null, "id", "FindAgain");
text = docSvg.createTextNode("Find Again");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<separator/>
separatorElement = docSvg.createElement("separator");
menuElement.appendChild(separatorElement);
 
//<item action="Copy" id="Copy">Copy Selected Text</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "Copy");
itemElement.setAttributeNS(null, "id", "Copy");
text = docSvg.createTextNode("Copy Selected Text");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<item action="CopySVG" id="CopySVG">Copy SVG</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "CopySVG");
itemElement.setAttributeNS(null, "id", "CopySVG");
text = docSvg.createTextNode("Copy SVG");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<item action="ViewSVG" id="ViewSVG">View SVG</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "ViewSVG");
itemElement.setAttributeNS(null, "id", "ViewSVG");
text = docSvg.createTextNode("View SVG");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<item action="ViewSource" id="ViewSource">View Source</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "ViewSource");
itemElement.setAttributeNS(null, "id", "ViewSource");
text = docSvg.createTextNode("View Source");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<item action="SaveAs" id="SaveAs">Save SVG As...</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "SaveAs");
itemElement.setAttributeNS(null, "id", "SaveAs");
text = docSvg.createTextNode("Save SVG As...");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<separator/>
separatorElement = docSvg.createElement("separator");
menuElement.appendChild(separatorElement);
 
//<item action="Help" id="Help">Help</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "Help");
itemElement.setAttributeNS(null, "id", "Help");
text = docSvg.createTextNode("Help");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
//<item action="About" id="About">About Adobe SVG Viewer...</item>
itemElement = docSvg.createElement("item");
itemElement.setAttributeNS(null, "action", "About");
itemElement.setAttributeNS(null, "id", "About");
text = docSvg.createTextNode("About Adobe SVG Viewer...");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
//end adobe menu
 
//start oxymel menu
//<separator/>
separatorElement = docSvg.createElement("separator");
menuElement.appendChild(separatorElement);
 
//<item onactivate="alert('OFC Charts 1.0.1 \n \n Copyright Oxymel \n http:\\www.owymel.com ')">About Oxymel OFC Charts ...</item>
itemElement = docSvg.createElement("item");
String aboutAction = "alert('OFC Charts " + ChartsVersion.getVersionLabel() +
" - Copyright Oxymel - www.oxymel.com')";
itemElement.setAttributeNS(null, "onactivate", aboutAction);
itemElement.setAttributeNS(null, "id", "AboutOxymel");
text = docSvg.createTextNode("About Oxymel OFC Charts ...");
itemElement.appendChild(text);
menuElement.appendChild(itemElement);
 
}
 
private String getJavascriptToManageExternalAnimation(SVGAnimationContext
svgAnimationContext) {
//javascript independant of svg viewer but they are problem of client server synchronized:
//il faut que le server soit plus rapide que la demande du client pour que cela marche correctement:
//StringBuffer javascipt = new StringBuffer(JAVASCRIPT_EXTERN_ANIMATION);
//javascipt.append(svgAnimationContext.getNbMilliSecondForUpdateExternalAnimation());
//javascipt.append(END_EXTERN_ANIMATION);
 
/*
StringBuffer javascipt = new StringBuffer(JAVASCRIPT_EXTERN_ANIMATION);
javascipt.append(JAVASCRIPT_EXTERN_ANIMATION_2);
javascipt.append(svgAnimationContext.getNbMilliSecondForUpdateExternalAnimation());
javascipt.append(END_EXTERN_ANIMATION);
return javascipt.toString();
*/
 
StringBuffer javascipt = new StringBuffer(JAVASCRIPT_EXTERN_ANIMATION_1);
javascipt.append(JAVASCRIPT_EXTERN_ANIMATION_2);
javascipt.append(JAVASCRIPT_EXTERN_ANIMATION_3);
javascipt.append(svgAnimationContext.
getNbMilliSecondForUpdateExternalAnimation());
javascipt.append(END_EXTERN_ANIMATION);
return javascipt.toString();
 
}
 
/**
* Sets the number of pixels between the plot area and the edge of the image.
* The defaults value is 5 pixels
*
* @param _nbPixelFreeArroundImageForPresentation int : number of pixels
*/
public void setNbPixelFreeArroundImageForPresentation(int
_nbPixelFreeArroundImageForPresentation) {
this._nbPixelFreeArroundImageForPresentation =
_nbPixelFreeArroundImageForPresentation;
}
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/CombinedVerticalBarChartXY.java
New file
0,0 → 1,311
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;
import java.io.OutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileOutputStream;
import java.util.StringTokenizer;
 
import java.awt.Graphics2D;
import java.awt.Font;
 
//ofc
import com.oxymel.ofc.charts.exception.OFCChartsRuntimeException;
import com.oxymel.ofc.charts.series.CategoryValueSeries;
import com.oxymel.ofc.charts.exception.OFCChartsException;
import com.oxymel.ofc.charts.data.CategoryValue;
import com.oxymel.ofc.charts.data.Category;
import com.oxymel.ofc.charts.util.Graphics2DTools;
import com.oxymel.ofc.charts.series.CategoryValueSeriesContainer;
import com.oxymel.ofc.charts.series.SeriesContainer;
import com.oxymel.ofc.charts.series.Series;
 
 
/**
* CombinedVerticalBarChartXY allows to manage combined vertical bar charts having the same Y axis.
* It is used to manage several bar charts sharing the same X and Y axis, same graduation on the Y axis.
*/
public class CombinedVerticalBarChartXY extends ChartWithAxisXY
{
private HorizontalCategoryAxis _axisX;
private VerticalNumberAxis _axisY;
private Vector _allRenderer = new Vector();
 
/**
* Constructor
* @param chartWidth Width of vertical bar chart
* @param chartHeight Height of vertical bar chart
* @param axisX Horizontal axis dedicated to the presentation of bar charts
* @param axisY Vertical graduated axis
*/
public CombinedVerticalBarChartXY(int chartWidth, int chartHeight,
HorizontalCategoryAxis axisX, VerticalNumberAxis axisY)
{
super(chartWidth, chartHeight);
_axisX = axisX;
_axisY = axisY;
//setLegendDisplayMode(Legend.LEGEND_DISPLAY_MODE_NONE);
}
 
/**
* Add a vertical bar chart renderer
* @param verticalBarChartRenderer The vertical bar chart renderer to add
*/
public void addVerticalBarChartRenderer(VerticalBarChartRenderer verticalBarChartRenderer)
{
verticalBarChartRenderer.set3dEffectValue(get3dEffectValue());
int nbSeries = getNbSeries();
_allRenderer.addElement(verticalBarChartRenderer);
//setAllSeriesColorFromPalette(nbSeries+1, verticalBarChartRenderer.getCategoryValueSeriesContainer());
setAllSeriesColorFromPalette(nbSeries, verticalBarChartRenderer.getCategoryValueSeriesContainer());
 
//rapide integration en force (sale) a changer
if(_legend instanceof LegendTable){
_legend = new LegendTable(getCategoryValueSeriesContainer());
}
//fin rapide integration
}
 
/**
* Sets the legend display mode. The legend may look like a table.
* @param legendDisplayMode The legend display mode to set.
* @see Legend
*/
public void setLegendDisplayMode(int legendDisplayMode)
{
if((_legend.getLegendDisplayMode() == Legend.LEGEND_DISPLAY_MODE_TABLE) &&
(legendDisplayMode != Legend.LEGEND_DISPLAY_MODE_TABLE)){
_legend = new Legend();
}
 
if(legendDisplayMode == Legend.LEGEND_DISPLAY_MODE_TABLE){
_legend = new LegendTable(getCategoryValueSeriesContainer());
return;
}
super.setLegendDisplayMode(legendDisplayMode);
}
 
 
protected int getNbSeries()
{
int nbSeries = 0;
Vector allRenderer = new Vector();
Enumeration enumAllRenderer = _allRenderer.elements();
while(enumAllRenderer.hasMoreElements()){
VerticalBarChartRenderer renderer =
(VerticalBarChartRenderer)enumAllRenderer.nextElement();
CategoryValueSeriesContainer categoryValueSeriesContainer =
renderer.getCategoryValueSeriesContainer();
nbSeries += categoryValueSeriesContainer.getNbSeries();
}
return nbSeries;
}
 
 
// protected SeriesContainer getSeriesContainer()
// {
/*
Enumeration enumAllRenderer = _allRenderer.elements();
if(enumAllRenderer.hasMoreElements()){
VerticalBarChartRenderer renderer =
(VerticalBarChartRenderer)enumAllRenderer.nextElement();
CategoryValueSeriesContainer categoryValueSeriesContainer = renderer.getCategoryValueSeriesContainer();
return categoryValueSeriesContainer;
}else{
throw new OFCChartsRuntimeException("No renderer add");
}
*/
/*
CategoryValueSeriesContainer allSeries = new CategoryValueSeriesContainer();
Enumeration enumAllRenderer = _allRenderer.elements();
while(enumAllRenderer.hasMoreElements()){
VerticalBarChartRenderer renderer =
(VerticalBarChartRenderer)enumAllRenderer.nextElement();
CategoryValueSeriesContainer categoryValueSeriesContainer = renderer.getCategoryValueSeriesContainer();
Enumeration enumAllSeries = categoryValueSeriesContainer.getEnumAllSeriesOrderByDisplayNumber();
while(enumAllSeries.hasMoreElements()){
allSeries.addCategoryValueSeries((CategoryValueSeries)enumAllSeries.nextElement());
}
}
return allSeries;
 
}
*/
 
protected SeriesContainer getSeriesContainer()
{
return getCategoryValueSeriesContainer();
}
 
private CategoryValueSeriesContainer getCategoryValueSeriesContainer()
{
/*
Enumeration enumAllRenderer = _allRenderer.elements();
if(enumAllRenderer.hasMoreElements()){
VerticalBarChartRenderer renderer =
(VerticalBarChartRenderer)enumAllRenderer.nextElement();
CategoryValueSeriesContainer categoryValueSeriesContainer = renderer.getCategoryValueSeriesContainer();
//_axisX.setAllCategoriesOrderByDisplayNumber(categoryValueSeriesContainer.getAllCategoriesOrderByDisplayNumber());
return categoryValueSeriesContainer;
}else{
throw new OFCChartsRuntimeException("No renderer add");
}
*/
 
CategoryValueSeriesContainer allSeries = new CategoryValueSeriesContainer();
Enumeration enumAllRenderer = _allRenderer.elements();
while(enumAllRenderer.hasMoreElements()){
VerticalBarChartRenderer renderer =
(VerticalBarChartRenderer)enumAllRenderer.nextElement();
CategoryValueSeriesContainer categoryValueSeriesContainer = renderer.getCategoryValueSeriesContainer();
Enumeration enumAllSeries = categoryValueSeriesContainer.getEnumAllSeriesOrderByDisplayNumber();
while(enumAllSeries.hasMoreElements()){
allSeries.addCategoryValueSeries((CategoryValueSeries)enumAllSeries.nextElement());
}
Enumeration enumAllCategories = categoryValueSeriesContainer.getAllCategoriesOrderByDisplayNumber().elements();
while(enumAllCategories.hasMoreElements()){
allSeries.addCategory((Category)enumAllCategories.nextElement());
}
}
return allSeries;
 
}
 
protected Axis getAxisX(){return _axisX;}
protected Axis getAxisY(){return _axisY;}
 
protected void setAxisParameters() throws OFCChartsException
{
_axisY.setMaxValue(getMaxValueAllRenderer());
_axisY.setMinValue(getMinValueAllRenderer());
 
 
Enumeration enumAllRenderer = _allRenderer.elements();
if(enumAllRenderer.hasMoreElements()){
VerticalBarChartRenderer renderer =
(VerticalBarChartRenderer)enumAllRenderer.nextElement();
CategoryValueSeriesContainer categoryValueSeriesContainer = renderer.getCategoryValueSeriesContainer();
_axisX.setAllCategoriesOrderByDisplayNumber(categoryValueSeriesContainer.getAllCategoriesOrderByDisplayNumber());
}else{
throw new OFCChartsException("No renderer add");
}
 
/* fait au moment du draw graphic. a supprimer si ok
enumAllRenderer = _allRenderer.elements();
while(enumAllRenderer.hasMoreElements()){
VerticalBarChartRenderer renderer =
(VerticalBarChartRenderer)enumAllRenderer.nextElement();
renderer.setNbGapOnX(_axisX.getNbGap());
renderer.setNbGapOnY(_axisY.getNbGap());
renderer.setGapValueOnY(_axisY.getGapValue());
}
*/
 
}
 
protected void setAxisXDrawingInfo()
{
_axisX.setNbPixelDecalYToStartWriteValues(
_axisY.getNbNegativeGapToIncludeMinValue() * _axisY.getSizeOfGap());
}
 
 
protected void drawGraphic(int xTopLeftGraphic, int yTopLeftGraphic, int graphicWidth, int graphicHeight,
int xOrigine, int yOrigine, Graphics2D graphics2D)
{
//rapide integration en force (sale) a changer
if(_legend instanceof LegendTable){
((LegendTable)_legend).setNbPixelColumnWidth(_axisX.getSizeOfGap());
((LegendTable)_legend).setXOrigine(xOrigine);
((LegendTable)_legend).setYOrigine(yOrigine);
}
//fin rapide integration
 
int nbGapOnX = _axisX.getNbGap();
int nbGapOnY = _axisY.getNbGap();
int gapValueOnY = _axisY.getGapValue();
 
Enumeration enumAllRenderer = _allRenderer.elements();
while(enumAllRenderer.hasMoreElements()){
VerticalBarChartRenderer renderer =
(VerticalBarChartRenderer)enumAllRenderer.nextElement();
renderer.setNbGapOnX(nbGapOnX);
renderer.setNbGapOnY(nbGapOnY);
renderer.setGapValueOnY(gapValueOnY);
renderer.drawGraphic(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight,
xOrigine, yOrigine, graphics2D);
}
}
 
 
private double getMaxValueAllRenderer() throws OFCChartsException
{
double maxValue;
Enumeration enumAllRenderer = _allRenderer.elements();
if(enumAllRenderer.hasMoreElements()){
VerticalBarChartRenderer renderer = (VerticalBarChartRenderer)enumAllRenderer.nextElement();
//CategoryValueSeriesContainer categoryValueSeriesContainer = renderer.getCategoryValueSeriesContainer();
//maxValue = categoryValueSeriesContainer.getMaxValueOfAllSeries();
maxValue = renderer.getMaxValueSetOnAxis();
}else{
throw new OFCChartsException("No renderer add");
}
 
enumAllRenderer = _allRenderer.elements();
while(enumAllRenderer.hasMoreElements()){
VerticalBarChartRenderer renderer = (VerticalBarChartRenderer)enumAllRenderer.nextElement();
//CategoryValueSeriesContainer categoryValueSeriesContainer = renderer.getCategoryValueSeriesContainer();
//maxValue = Math.max(maxValue, categoryValueSeriesContainer.getMaxValueOfAllSeries());
maxValue = Math.max(maxValue, renderer.getMaxValueSetOnAxis());
}
 
//System.out.println("maxValue = " + maxValue);
return maxValue;
}
 
private double getMinValueAllRenderer() throws OFCChartsException
{
double minValue;
Enumeration enumAllRenderer = _allRenderer.elements();
if(enumAllRenderer.hasMoreElements()){
VerticalBarChartRenderer renderer = (VerticalBarChartRenderer)enumAllRenderer.nextElement();
//CategoryValueSeriesContainer categoryValueSeriesContainer = renderer.getCategoryValueSeriesContainer();
//minValue = categoryValueSeriesContainer.getMinValueOfAllSeries();
minValue = renderer.getMinValueSetOnAxis();
}else{
throw new OFCChartsException("No renderer add");
}
 
enumAllRenderer = _allRenderer.elements();
while(enumAllRenderer.hasMoreElements()){
VerticalBarChartRenderer renderer = (VerticalBarChartRenderer)enumAllRenderer.nextElement();
//CategoryValueSeriesContainer categoryValueSeriesContainer = renderer.getCategoryValueSeriesContainer();
//minValue = Math.min(minValue, categoryValueSeriesContainer.getMinValueOfAllSeries());
minValue = Math.min(minValue, renderer.getMinValueSetOnAxis());
}
 
//System.out.println("minValue = " + minValue);
return minValue;
}
 
 
/*
public static void main(String[] argv) throws Exception
{
}
*/
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/CategoryAxis.java
New file
0,0 → 1,34
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.util.Vector;
import java.util.Enumeration;
 
class CategoryAxis
{
private Vector _allCategoriesOrderByDisplayNumber = new Vector();
 
public CategoryAxis()
{
}
 
int getNbGap()
{
return _allCategoriesOrderByDisplayNumber.size();
}
 
void setAllCategoriesOrderByDisplayNumber(Vector allCategories){
_allCategoriesOrderByDisplayNumber = allCategories;}
 
 
Enumeration getEnumAllCategoriesOrderByDisplayNumber(){return _allCategoriesOrderByDisplayNumber.elements();}
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/VerticalLineChart.java
New file
0,0 → 1,108
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.*;
//ofc
import com.oxymel.ofc.charts.series.*;
 
/**
* This class allows to draw bar charts as lines.
* In such a presentation the tops of the bars within a given series are
* joined together to build a line.
*/
public class VerticalLineChart extends VerticalBarChart
{
private VerticalLineChartRenderer _renderer;
 
/**
* Constructor
* @param chartWidth Width of vertical bar chart
* @param chartHeight Height of vertical bar chart
* @param axisX Horizontal axis to display categories
* @param axisY Vertical number axis
* @param categoryValueSeriesContainer All series of couple category-value
*/
public VerticalLineChart(int chartWidth, int chartHeight,
HorizontalCategoryAxis axisX, VerticalNumberAxis axisY,
CategoryValueSeriesContainer categoryValueSeriesContainer)
{
super(chartWidth, chartHeight, axisX, axisY, categoryValueSeriesContainer);
_renderer = new VerticalLineChartRenderer(categoryValueSeriesContainer);
}
 
protected VerticalBarChartRenderer getChartRenderer(){return _renderer;};
 
protected void drawGraphic(int xTopLeftGraphic, int yTopLeftGraphic, int graphicWidth, int graphicHeight,
int xOrigine, int yOrigine, Graphics2D graphics2D)
{
_renderer.setNbGapOnX(_axisX.getNbGap());
_renderer.setNbGapOnY(_axisY.getNbGap());
_renderer.setGapValueOnY(_axisY.getGapValue());
_renderer.drawGraphic( xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight,
xOrigine, yOrigine, graphics2D);
/*
int sizeOfGapOnY = graphicHeight / _axisY.getNbGap();
int sizeOfGapOnX = graphicWidth / _axisX.getNbGap();
 
Vector allCategories = _categoryValueSeriesContainer.getAllCategoriesOrderByDisplayNumber();
 
for(int i= 0; i<allCategories.size(); i++){
Category category = (Category)allCategories.elementAt(i);
int xCurrent = xOrigine + (sizeOfGapOnX * i) + (sizeOfGapOnX/2);
 
if(i <allCategories.size()-1){
Enumeration enumAllSeries = _categoryValueSeriesContainer.getEnumAllSeriesOrderByDisplayNumber();
while(enumAllSeries.hasMoreElements()){
CategoryValueSeries categoryValueSeries = (CategoryValueSeries)enumAllSeries.nextElement();
if(categoryValueSeries.isVisible()){
double value = categoryValueSeries.getCategoryValueAsDouble(category.getId());
Category nextCategory = (Category) allCategories.elementAt(i+1);
double nextValue = categoryValueSeries.getCategoryValueAsDouble(nextCategory.getId());
//
drawLine(xCurrent, yOrigine, sizeOfGapOnX,
Graphics2DTools.getRelativeSizeOfValue(value, _axisY.getGapValue(), sizeOfGapOnY),
Graphics2DTools.getRelativeSizeOfValue(nextValue, _axisY.getGapValue(), sizeOfGapOnY),
categoryValueSeries, graphics2D);
}
}
}
}
*/
}
/*
private void drawLine(int xCurrent, int yOrigine, int sizeOfGapOnX, int relativeSizeOfValue,
int relativeSizeOfNextValue, CategoryValueSeries series, Graphics2D graphics2D)
{
int x1 = xCurrent;
int x2 = x1 + sizeOfGapOnX;
 
int y1 = yOrigine - relativeSizeOfValue;
int y2 = yOrigine - relativeSizeOfNextValue;
graphics2D.setColor(series.getColor());
 
Stroke initialStroke = graphics2D.getStroke();
graphics2D.setStroke(new BasicStroke(2.0f));
graphics2D.drawLine(x1, y1, x2, y2);
graphics2D.setStroke(initialStroke);
series.drawIndicator(x1, y1, graphics2D);
series.drawIndicator(x2, y2, graphics2D);
}
*/
 
/*
public static void main(String[] argv) throws Exception
{
 
}
*/
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/ChartWithAxisXY.java
New file
0,0 → 1,549
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.Graphics2D;
import java.util.Vector;
import java.util.Enumeration;
import java.awt.Color;
 
// batik (for svg)
import org.apache.batik.svggen.SVGGraphics2D;
 
//ofc
import com.oxymel.ofc.charts.exception.OFCChartsException;
import com.oxymel.ofc.charts.animation.SVGAnimationContext;
import java.awt.geom.AffineTransform;
 
/**
* This class is the abstract superclass for all char with one axis X and Y.
*/
public abstract class ChartWithAxisXY
extends Chart {
 
private Color _internalGridColor = Color.black;
private boolean _isInternalGridVisible = true;
private boolean _isGraphicVisible = true;
private Color _IGOrigineAxisColor = null;
 
protected ChartWithAxisXY(int chartWidth, int chartHeight) {
super(chartWidth, chartHeight);
setInternalGridColor(Color.lightGray);
}
 
Color getInternalGridColor() {
return _internalGridColor;
}
 
void setInternalGridColor(Color color) {
_internalGridColor = color;
}
 
/**
* Sets the internal grid visibility according to the parameter
* @param isInternalGridVisible If true then the internal grid is visible otherwise it is not visible.
*/
public void setInternalGridVisible(boolean isInternalGridVisible) {
_isInternalGridVisible = isInternalGridVisible;
}
 
/**
* Sets the internal graphic visibility according to the parameter
* @param isGraphicVisible If true then the internal graphic is visible otherwise it is not visible.
*/
public void setGraphicVisible(boolean isGraphicVisible) {
_isGraphicVisible = isGraphicVisible;
}
 
protected void doDrawAnimateSVGChart(SVGGraphics2D graphics2D,
SVGAnimationContext svgAnimationContext) throws
OFCChartsException {
setAxisParametersForAnimation();
 
Axis axisX = getAxisX();
Axis axisY = getAxisY();
 
int xTopLeftGraphic = getXTopLeftGraphic(graphics2D);
int yTopLeftGraphic = getYTopLeftGraphic(graphics2D);
int graphicWidth = getGraphicWidth(graphics2D);
axisX.setNbPixelSize(graphicWidth);
int graphicHeight = getGraphicHeight(graphics2D);
axisY.setNbPixelSize(graphicHeight);
axisY.setNbGapMax(graphics2D);
 
int sizeOfGapOnY = graphicHeight / axisY.getNbGap();
int sizeOfGapOnX = graphicWidth / axisX.getNbGap();
 
int yOrigine = (yTopLeftGraphic + graphicHeight) -
(sizeOfGapOnY * axisY.getNbNegativeGapToIncludeMinValue());
int xOrigine = xTopLeftGraphic +
(sizeOfGapOnX * axisX.getNbNegativeGapToIncludeMinValue());
 
if (_isInternalGridVisible) {
 
drawGraphicBackground(xTopLeftGraphic, yTopLeftGraphic,
graphicWidth, graphicHeight, graphics2D);
 
drawInternalGrid(graphicWidth, graphicHeight, xTopLeftGraphic,
yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
}
 
axisY.draw(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
 
if (_isGraphicVisible) {
drawAnimateGraphic(xTopLeftGraphic, yTopLeftGraphic, graphicWidth,
graphicHeight,
xOrigine, yOrigine, graphics2D, svgAnimationContext);
}
 
setAxisXDrawingInfo();
axisX.draw(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
 
_legend.drawLegend(getXTopLeftLegend(graphics2D),
getYTopLeftLegend(graphics2D),
getSeriesContainer().getAllSeriesOrderByDisplayNumber(),
graphics2D);
 
/* bug à voir plus tard
_legend.drawLegend(
getXTopLeftLegend(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D),
getYTopLeftLegend(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D),
getSeriesContainer().getAllSeriesOrderByDisplayNumber(), graphics2D);
*/
}
 
protected void doDrawChart(Graphics2D graphics2D) throws OFCChartsException {
setAxisParameters();
 
Axis axisX = getAxisX();
Axis axisY = getAxisY();
 
int xTopLeftGraphic = getXTopLeftGraphic(graphics2D);
int yTopLeftGraphic = getYTopLeftGraphic(graphics2D);
int graphicWidth = getGraphicWidth(graphics2D);
axisX.setNbPixelSize(graphicWidth);
int graphicHeight = getGraphicHeight(graphics2D);
axisY.setNbPixelSize(graphicHeight);
axisY.setNbGapMax(graphics2D);
 
int sizeOfGapOnY = graphicHeight / axisY.getNbGap();
int sizeOfGapOnX = graphicWidth / axisX.getNbGap();
 
int yOrigine = (yTopLeftGraphic + graphicHeight) -
(sizeOfGapOnY * axisY.getNbNegativeGapToIncludeMinValue());
int xOrigine = xTopLeftGraphic +
(sizeOfGapOnX * axisX.getNbNegativeGapToIncludeMinValue());
_isInternalGridVisible = true;
if (_isInternalGridVisible) {
drawGraphicBackground(xTopLeftGraphic, yTopLeftGraphic,
graphicWidth, graphicHeight, graphics2D);
 
drawInternalGrid(graphicWidth, graphicHeight, xTopLeftGraphic,
yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
}
 
/* Integre spécialement pour les VerticalLinePlot.
Positionnement d'un axe Y à gauche ou à droite (au milieu par défaut)*/
if (axisY instanceof VerticalNumberAxis) {
VerticalNumberAxis nbaxisY = (VerticalNumberAxis) axisY;
if (nbaxisY.getAxisPosition() == VerticalNumberAxis.AXIS_POSITION_CENTER &&
axisX.getNbGap() < axisX.getNbNegativeGapToIncludeMinValue()) {
nbaxisY.setAxisPosition(VerticalNumberAxis.AXIS_POSITION_RIGHT);
}
 
if (nbaxisY.getAxisPosition() == VerticalNumberAxis.AXIS_POSITION_RIGHT) {
nbaxisY.setPositionOnXAxis(sizeOfGapOnX *
(axisX.getNbGap() -
axisX.getNbNegativeGapToIncludeMinValue()));
}
else if (nbaxisY.getAxisPosition() ==
VerticalNumberAxis.AXIS_POSITION_LEFT) {
nbaxisY.setPositionOnXAxis( -sizeOfGapOnX *
axisX.getNbNegativeGapToIncludeMinValue());
}
}
// Fin
axisY.draw(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
if (_isGraphicVisible) {
drawGraphic(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight,
xOrigine, yOrigine, graphics2D);
}
 
setAxisXDrawingInfo();
/* Integre spécialement pour les VerticalLinePlot.
Positionnement d'un axe X en Haut ou en Bas (au milieu par défaut)*/
if (axisX instanceof HorizontalNumberAxis) {
HorizontalNumberAxis nbaxisX = (HorizontalNumberAxis) axisX;
if (nbaxisX.getAxisPosition() ==
HorizontalNumberAxis.AXIS_POSITION_CENTER &&
axisY.getNbGap() < axisY.getNbNegativeGapToIncludeMinValue()) {
nbaxisX.setAxisPosition(HorizontalNumberAxis.AXIS_POSITION_TOP);
}
 
if (nbaxisX.getAxisPosition() == HorizontalNumberAxis.AXIS_POSITION_TOP) {
nbaxisX.setPositionOnYAxis( -sizeOfGapOnY *
(axisY.getNbGap() -
axisY.getNbNegativeGapToIncludeMinValue()));
}
else if (nbaxisX.getAxisPosition() ==
HorizontalNumberAxis.AXIS_POSITION_BOTTOM) {
nbaxisX.setPositionOnYAxis(sizeOfGapOnY *
axisY.getNbNegativeGapToIncludeMinValue());
}
}
// Fin
axisX.draw(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
 
_legend.drawLegend(getXTopLeftLegend(graphics2D),
getYTopLeftLegend(graphics2D),
getSeriesContainer().getAllSeriesOrderByDisplayNumber(),
graphics2D);
 
/* bug à voir plus tard
_legend.drawLegend(
getXTopLeftLegend(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D),
getYTopLeftLegend(xTopLeftGraphic, yTopLeftGraphic, graphicWidth, graphicHeight, graphics2D),
getSeriesContainer().getAllSeriesOrderByDisplayNumber(), graphics2D);
*/
}
 
protected void drawInternalGrid(int graphicWidth, int graphicHeight,
int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine,
int yOrigine, Graphics2D graphics2D) {
if (get3dEffectValue() == 0) { //EXCLUDE_CHART_3D
drawInternalGrid2D(graphicWidth, graphicHeight, xTopLeftGraphic,
yTopLeftGraphic, xOrigine, yOrigine, graphics2D);
}
else { //EXCLUDE_CHART_3D
//BEGIN_BLOCKER_CHART_3D
drawInternalGrid3D(graphicWidth, graphicHeight, xTopLeftGraphic,
yTopLeftGraphic, xOrigine, yOrigine, graphics2D);
//END_BLOCKER_CHART_3D
} //EXCLUDE_CHART_3D
}
 
private void drawInternalGrid2D(int graphicWidth, int graphicHeight,
int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine,
int yOrigine, Graphics2D graphics2D) {
drawHorizontalInternalGrid2D(graphicWidth, graphicHeight, xTopLeftGraphic,
yTopLeftGraphic, xOrigine, yOrigine,
graphics2D, getAxisY());
drawVerticalInternalGrid2D(graphicWidth, graphicHeight, xTopLeftGraphic,
yTopLeftGraphic, xOrigine, yOrigine, graphics2D,
getAxisX());
}
 
//BEGIN_BLOCKER_CHART_3D
private void drawInternalGrid3D(int graphicWidth, int graphicHeight,
int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine,
int yOrigine, Graphics2D graphics2D) {
drawHorizontalInternalGrid3D(graphicWidth, graphicHeight, xTopLeftGraphic,
yTopLeftGraphic, xOrigine, yOrigine,
graphics2D, getAxisY(), get3dEffectValue());
drawVerticalInternalGrid3D(graphicWidth, graphicHeight, xTopLeftGraphic,
yTopLeftGraphic, xOrigine, yOrigine, graphics2D,
getAxisX(), get3dEffectValue());
}
 
private void drawHorizontalInternalGrid3D(int graphicWidth, int graphicHeight,
int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine,
int yOrigine, Graphics2D graphics2D,
Axis axisY, int coeff3dEffect) {
graphics2D.setColor(getInternalGridColor());
int nbGapOnY = axisY.getNbGap();
int sizeOfGapOnY = graphicHeight / nbGapOnY;
int yOfGap = yTopLeftGraphic + graphicHeight;
int xTopRightGraphic = xTopLeftGraphic + graphicWidth;
 
int nbGapOnX = getAxisX().getNbGap();
int sizeOfGapOnX = graphicWidth / nbGapOnX;
 
for (int i = 0; i < nbGapOnY + 1; i++) {
if (_IGOrigineAxisColor != null && yOfGap == yOrigine) {
graphics2D.setColor(_IGOrigineAxisColor);
}
graphics2D.drawLine(xTopLeftGraphic, yOfGap,
xTopLeftGraphic + coeff3dEffect,
yOfGap - coeff3dEffect);
//graphics2D.drawLine(xTopLeftGraphic + coeff3dEffect, yOfGap - coeff3dEffect, xTopRightGraphic + coeff3dEffect, yOfGap - coeff3dEffect);
graphics2D.drawLine(xTopLeftGraphic + coeff3dEffect,
yOfGap - coeff3dEffect,
xTopLeftGraphic + (sizeOfGapOnX * nbGapOnX) +
coeff3dEffect, yOfGap - coeff3dEffect);
graphics2D.setColor(getInternalGridColor());
yOfGap -= sizeOfGapOnY;
}
 
//encadre haut
//graphics2D.drawLine(xTopLeftGraphic, yTopLeftGraphic , xTopLeftGraphic + coeff3dEffect, yTopLeftGraphic - coeff3dEffect);
//graphics2D.drawLine(xTopLeftGraphic + coeff3dEffect, yTopLeftGraphic - coeff3dEffect, xTopRightGraphic, yTopLeftGraphic - coeff3dEffect);
 
//encadre droite
//graphics2D.drawLine(xTopRightGraphic, yTopLeftGraphic + graphicHeight - coeff3dEffect,
// xTopRightGraphic, yTopLeftGraphic - coeff3dEffect);
 
//angle
graphics2D.drawLine(xTopLeftGraphic + coeff3dEffect,
yTopLeftGraphic + graphicHeight - coeff3dEffect,
xTopLeftGraphic + coeff3dEffect,
yTopLeftGraphic + graphicHeight -
(sizeOfGapOnY * nbGapOnY) - coeff3dEffect);
 
//encadre bas
//graphics2D.drawLine(xTopRightGraphic - coeff3dEffect, yTopLeftGraphic + graphicHeight,
// xTopRightGraphic, yTopLeftGraphic + graphicHeight - coeff3dEffect);
 
// int nbGapOnX = getAxisX().getNbGap();
// int sizeOfGapOnX = graphicWidth / nbGapOnX;
int yBottomGraphic = yTopLeftGraphic + graphicHeight;
int xOfGap = xTopLeftGraphic + sizeOfGapOnX + (sizeOfGapOnX * (nbGapOnX - 1));
graphics2D.drawLine(xTopLeftGraphic, yTopLeftGraphic + graphicHeight,
xOfGap, yTopLeftGraphic + graphicHeight);
graphics2D.drawLine(xOfGap + coeff3dEffect, yBottomGraphic - coeff3dEffect,
xOfGap, yBottomGraphic);
 
//encadre droite
graphics2D.drawLine(xOfGap + coeff3dEffect,
yTopLeftGraphic + graphicHeight - coeff3dEffect,
xOfGap + coeff3dEffect,
yTopLeftGraphic + graphicHeight -
(sizeOfGapOnY * nbGapOnY) - coeff3dEffect);
 
}
 
private void drawVerticalInternalGrid3D(int graphicWidth, int graphicHeight,
int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine,
int yOrigine, Graphics2D graphics2D,
Axis axisX, int coeff3dEffect) {
graphics2D.setColor(getInternalGridColor());
 
int nbGapOnY = getAxisY().getNbGap();
int sizeOfGapOnY = graphicHeight / nbGapOnY;
 
int nbGapOnX = axisX.getNbGap();
int sizeOfGapOnX = graphicWidth / nbGapOnX;
int xOfGap = xTopLeftGraphic + sizeOfGapOnX;
int yBottomGraphic = yTopLeftGraphic + graphicHeight;
for (int i = 0; i < nbGapOnX; i++) {
if (_IGOrigineAxisColor != null && xOfGap == xOrigine) {
graphics2D.setColor(_IGOrigineAxisColor);
}
graphics2D.drawLine(xOfGap + coeff3dEffect,
yBottomGraphic - (sizeOfGapOnY * nbGapOnY) -
coeff3dEffect,
xOfGap + coeff3dEffect,
yBottomGraphic - coeff3dEffect);
graphics2D.drawLine(xOfGap + coeff3dEffect,
yBottomGraphic - coeff3dEffect, xOfGap,
yBottomGraphic);
graphics2D.setColor(getInternalGridColor());
//graphics2D.drawLine(xOfGap + coeff3dEffect, yOrigine - coeff3dEffect,
// xOfGap , yOrigine);
//graphics2D.drawLine(xOfGap , yOrigine, xOfGap, yBottomGraphic - coeff3dEffect);
//graphics2D.drawLine(xOfGap, yBottomGraphic - coeff3dEffect, xOfGap - coeff3dEffect, yBottomGraphic);
 
/*
int nbGapOnY = getAxisY().getNbGap();
int yOfGap = yTopLeftGraphic + graphicHeight;
int sizeOfGapOnY = graphicHeight / nbGapOnY;
int xTopRightGraphic = xTopLeftGraphic + graphicWidth;
for(int j=0; j<nbGapOnY + 1; j++){
graphics2D.drawLine(xOfGap + coeff3dEffect, yOfGap - coeff3dEffect, xOfGap, yOfGap);
yOfGap -= sizeOfGapOnY;
}
*/
 
xOfGap += sizeOfGapOnX;
}
}
 
//END_BLOCKER_CHART_3D
 
private void drawHorizontalInternalGrid2D(int graphicWidth, int graphicHeight,
int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine,
int yOrigine, Graphics2D graphics2D,
Axis axisY) {
graphics2D.setColor(getInternalGridColor());
int nbGapOnY = axisY.getNbGap();
int sizeOfGapOnY = graphicHeight / nbGapOnY;
int yOfGap = yTopLeftGraphic + graphicHeight;
int xTopRightGraphic = xTopLeftGraphic + graphicWidth;
for (int i = 0; i < nbGapOnY + 1; i++) {
if (_IGOrigineAxisColor != null && yOfGap == yOrigine) {
graphics2D.setColor(_IGOrigineAxisColor);
}
graphics2D.drawLine(xTopLeftGraphic, yOfGap, xTopRightGraphic, yOfGap);
graphics2D.setColor(getInternalGridColor());
yOfGap -= sizeOfGapOnY;
}
}
 
private void drawVerticalInternalGrid2D(int graphicWidth, int graphicHeight,
int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine,
int yOrigine, Graphics2D graphics2D,
Axis axisX) {
graphics2D.setColor(getInternalGridColor());
int nbGapOnX = axisX.getNbGap();
int sizeOfGapOnX = graphicWidth / nbGapOnX;
int xOfGap = xTopLeftGraphic;
int yBottomGraphic = yTopLeftGraphic + graphicHeight;
for (int i = 0; i < nbGapOnX + 1; i++) {
if (_IGOrigineAxisColor != null && xOfGap == xOrigine) {
graphics2D.setColor(_IGOrigineAxisColor);
}
graphics2D.drawLine(xOfGap, yTopLeftGraphic, xOfGap, yBottomGraphic);
graphics2D.setColor(getInternalGridColor());
xOfGap += sizeOfGapOnX;
}
}
 
//template pattern used by doDrawChart :
protected void setAxisXDrawingInfo() {};
abstract protected Axis getAxisX();
 
abstract protected Axis getAxisY();
 
abstract protected void setAxisParameters() throws OFCChartsException;
 
protected void setAxisParametersForAnimation() throws OFCChartsException {
setAxisParameters();
}
 
abstract protected void drawGraphic(int xTopLeftGraphic, int yTopLeftGraphic,
int graphicWidth, int graphicHeight,
int xOrigine, int yOrigine,
Graphics2D graphics2D);
 
protected void drawAnimateGraphic(int xTopLeftGraphic, int yTopLeftGraphic,
int graphicWidth, int graphicHeight,
int xOrigine, int yOrigine,
SVGGraphics2D graphics2D,
SVGAnimationContext svgAnimationContext) {
drawGraphic(xTopLeftGraphic, yTopLeftGraphic,
graphicWidth, graphicHeight, xOrigine, yOrigine, graphics2D);
}
 
protected int getXTopLeftGraphic(Graphics2D graphics2D) {
Axis axisX = getAxisX();
Axis axisY = getAxisY();
 
int xTopLeftGraphic = super.getXTopLeftGraphic(graphics2D);
 
//rapide integration en force (sale) a changer
if (_legend instanceof LegendTable) {
xTopLeftGraphic +=
( (LegendTable) _legend).getNbPixelUsedAtLeftOfAxis(graphics2D);
return xTopLeftGraphic;
}
//fin rapide integration
 
if (!axisX.isContainsNegativeValue()) {
xTopLeftGraphic += axisY.getNbPixelUsedAtLeft(graphics2D);
}
else {
xTopLeftGraphic += axisX.getNbPixelUsedAtLeft(graphics2D);
 
}
return xTopLeftGraphic;
}
 
protected int getYTopLeftGraphic(Graphics2D graphics2D) {
Axis axisY = getAxisY();
int yTopLeftGraphic = super.getYTopLeftGraphic(graphics2D);
yTopLeftGraphic += axisY.getNbPixelUsedAtTop(graphics2D);
return yTopLeftGraphic;
}
 
protected int getGraphicWidth(Graphics2D graphics2D) {
Axis axisX = getAxisX();
Axis axisY = getAxisY();
int graphicWidth = super.getGraphicWidth(graphics2D);
 
//rapide integration en force (sale) a changer
if (_legend instanceof LegendTable) {
graphicWidth -=
( ( (LegendTable) _legend).getNbPixelUsedAtLeftOfAxis(graphics2D) +
axisX.getNbPixelUsedAtRight(graphics2D));
return graphicWidth;
}
//fin rapide integration
 
if (!axisX.isContainsNegativeValue()) {
graphicWidth -= (axisY.getNbPixelUsedAtLeft(graphics2D) +
axisX.getNbPixelUsedAtRight(graphics2D));
}
else {
graphicWidth -= (axisX.getNbPixelUsedAtLeft(graphics2D) +
axisX.getNbPixelUsedAtRight(graphics2D));
}
return graphicWidth;
}
 
protected int getGraphicHeight(Graphics2D graphics2D) throws
OFCChartsException {
Axis axisX = getAxisX();
Axis axisY = getAxisY();
int graphicHeight = super.getGraphicHeight(graphics2D);
graphicHeight -= (axisY.getNbPixelUsedAtTop(graphics2D) +
axisX.getNbPixelUsedAtBottom(graphics2D));
return graphicHeight;
}
 
protected int getXTopLeftLegend(Graphics2D graphics2D) throws
OFCChartsException {
int xTopLeftLegend = super.getXTopLeftLegend(graphics2D);
switch (_legend.getLegendDisplayMode()) {
case Legend.LEGEND_DISPLAY_MODE_RIGHT:
Axis axisX = getAxisX();
xTopLeftLegend += axisX.getNbPixelUsedAtRight(graphics2D);
break;
}
return xTopLeftLegend;
}
 
protected int getYTopLeftLegend(Graphics2D graphics2D) throws
OFCChartsException {
int yTopLeftLegend = super.getYTopLeftLegend(graphics2D);
switch (_legend.getLegendDisplayMode()) {
case Legend.LEGEND_DISPLAY_MODE_BOTTOM:
Axis axisX = getAxisX();
yTopLeftLegend += axisX.getNbPixelUsedAtBottom(graphics2D);
break;
}
return yTopLeftLegend;
}
 
/**
* Allows to indicate the color used to draw horizontal and vertical
* axis at the origine. Set this value to null (default value)
* in order to use the same color as the one used to draw the grid.
*
* @param axisColor Color
*/
 
public void setIGOriginAxisColor(Color axisColor) {
_IGOrigineAxisColor = axisColor;
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/LegendInterval.java
New file
0,0 → 1,315
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.Graphics2D;
import java.awt.Font;
import java.awt.Color;
 
import java.util.Enumeration;
import java.util.Vector;
 
//ofc
import com.oxymel.ofc.charts.util.OFCMath;
import com.oxymel.ofc.charts.util.Graphics2DTools;
import com.oxymel.ofc.charts.util.Interval;
 
public class LegendInterval extends Legend
{
//private double _max;
//private double _min;
//private double _step;
 
//taille maximale de la légende (90% de la taille de l'image)
private int _maxHeight;
 
private int _nbDigitAfterDotPrecision = 0;
 
private Vector _allInterval = new Vector();
private ColorPalette _colorPalette;
 
public LegendInterval(double min,
double max,
double step,
ColorPalette colorPalette,
int chartHeight)
{
this(min,max,step,colorPalette);
_maxHeight = (chartHeight*90)/100;
}
 
public LegendInterval(double min, double max, double step, ColorPalette colorPalette)
{
super();
double minIntervalValue = Math.min(min, max);
double maxIntervalValue = Math.max(min, max);
step = Math.abs(step);
 
//_max = maxIntervalValue;
//_min = minIntervalValue;
//_step = step;
 
_nbDigitAfterDotPrecision = Math.max(OFCMath.getNbDigitAfterDot(min), OFCMath.getNbDigitAfterDot(step));
 
Interval firstInterval = new Interval(minIntervalValue,
Interval.COMPARISON_TYPE_LOWER_OR_EGAL,
minIntervalValue,
Interval.COMPARISON_TYPE_LOWER_OR_EGAL);
_allInterval.addElement(firstInterval);
 
double currentMinIntervalValue = minIntervalValue;
while(currentMinIntervalValue < maxIntervalValue){
 
double currentMaxIntervalValue = currentMinIntervalValue + step;
if(currentMaxIntervalValue > maxIntervalValue){
currentMaxIntervalValue = maxIntervalValue;
}
Interval interval = new Interval(currentMinIntervalValue,
Interval.COMPARISON_TYPE_GREATER_OR_EGAL,
currentMaxIntervalValue,
Interval.COMPARISON_TYPE_LOWER_OR_EGAL);
_allInterval.addElement(interval);
currentMinIntervalValue = currentMaxIntervalValue;
 
}
 
Interval lastInterval = new Interval(maxIntervalValue,
Interval.COMPARISON_TYPE_GREATER_OR_EGAL,
maxIntervalValue,
Interval.COMPARISON_TYPE_GREATER_OR_EGAL);
_allInterval.addElement(lastInterval);
 
_colorPalette = colorPalette;
_nbPixelHeightOfLegendIndicator = 15;
_nbPixelWidthOfLegendIndicator = 20;
_sizeFontOnX = 11;
}
 
void setColorPalette(ColorPalette colorPalette)
{
_colorPalette = colorPalette;
}
 
Color getColor(double startInterval, double endInterval)
{
for(int i= 0; i < _allInterval.size() ; i++){
Interval interval = (Interval)_allInterval.elementAt(i);
if(interval.isContains(startInterval, endInterval)){
if(startInterval == endInterval){
//return _colorPalette.getColor(i + 2);
return _colorPalette.getColorAt(i + 1);
}else{
//return _colorPalette.getColor(i + 1);
return _colorPalette.getColorAt(i);
}
}
}
return Color.black;
}
 
public void drawLegend(int xTopLeftLegend, int yTopLeftLegend, Vector allSeries, Graphics2D graphics2D)
{
drawLegendAtLeft(graphics2D, xTopLeftLegend, yTopLeftLegend, allSeries);
}
 
int getSizeWidthOfLegendAtBottom(Graphics2D graphics2D, Enumeration enumAllSeries)
{
return 0;
}
 
int getSizeWidthOfLegendAtLeft(Graphics2D graphics2D, Enumeration enumAllSeries)
{
if(_legendDisplayMode != LEGEND_DISPLAY_MODE_RIGHT){
return 0;
}
 
Font font = graphics2D.getFont();
graphics2D.setFont(getFontOnX(graphics2D));
 
 
//String firstLabel = " > " + getValueAsString(_max, _nbDigitAfterDotPrecision);
//int sizeMaxWithOfLegendTxt = Graphics2DTools.getNbPixelWidthOfTxt(graphics2D, firstLabel);
//String lastLabel = " > " + getValueAsString(_min, _nbDigitAfterDotPrecision);
//sizeMaxWithOfLegendTxt = Math.max(sizeMaxWithOfLegendTxt, Graphics2DTools.getNbPixelWidthOfTxt(graphics2D, lastLabel));
 
/*
double currentValue = _max + _step;
while(currentValue >= _min){
String currentLabel = "" + getValueAsString(currentValue, _nbDigitAfterDotPrecision);
int currentSize = Graphics2DTools.getNbPixelWidthOfTxt(graphics2D, currentLabel);
if ( currentSize > sizeMaxWithOfLegendTxt){
sizeMaxWithOfLegendTxt = currentSize;
}
currentValue -= _step;
}
*/
 
int sizeMaxWithOfLegendTxt = 0;
for(int i=_allInterval.size() - 1; i > 0 ; i--){
Interval interval = (Interval)_allInterval.elementAt(i);
 
String currentLabel = "" + getValueAsString(interval.getStartValue(), _nbDigitAfterDotPrecision);
sizeMaxWithOfLegendTxt = Math.max(sizeMaxWithOfLegendTxt, Graphics2DTools.getNbPixelWidthOfTxt(graphics2D, currentLabel));
 
}
 
graphics2D.setFont(font);
 
return sizeMaxWithOfLegendTxt +
_nbPixelWidthOfLegendIndicator + _nbPixelBetweenTxtLegendAndColorAssociate +
(2 * _nbPixelFreeArroundLegendForPresentation);
}
 
int getSizeHeightOfLegendAtLeft(Graphics2D graphics2D, Enumeration enumAllSeries)
{
Font font = graphics2D.getFont();
graphics2D.setFont(getFontOnX(graphics2D));
 
int size = 0;
//double currentValue = _max + _step + _step;
//while(currentValue >= _min){
for(int i=_allInterval.size() - 1; i > 0 ; i--){
Interval interval = (Interval)_allInterval.elementAt(i);
String currentLabel = "" + getValueAsString(interval.getStartValue(), _nbDigitAfterDotPrecision);
 
//String currentLabel = "" + getValueAsString(currentValue, _nbDigitAfterDotPrecision);
int currentSize = Graphics2DTools.getNbPixelHeightOfTxt(graphics2D, currentLabel);
if(currentSize > _nbPixelHeightOfLegendIndicator){
size += currentSize;
}
else{
size += _nbPixelHeightOfLegendIndicator;
}
if(enumAllSeries.hasMoreElements()){
size += _nbPixelBetweenEachLegendLine;
}
//currentValue -= _step;
}
size += _nbPixelHeightOfLegendIndicator;
size += 2 * _nbPixelFreeArroundLegendForPresentation;
// size += Graphics2DTools.getNbPixelHeightOfTxt(graphics2D, "" + _max);
graphics2D.setFont(font);
//on verifie que le cadre de la legende rentre dans l'image
if (size > _maxHeight ) size = _maxHeight;
return size;
}
 
 
private void drawLegendAtLeft(Graphics2D graphics2D, int xTopLeftLegend, int yTopLeftLegend, Vector allSeries)
{
if(_legendDisplayMode != LEGEND_DISPLAY_MODE_RIGHT){
return;
}
 
Font font = graphics2D.getFont();
Font fontOnX = getFontOnX(graphics2D);
 
graphics2D.setFont(fontOnX);
int sizeWidthOfLegend = getSizeWidthOfLegendAtLeft(graphics2D, allSeries.elements());
int sizeHeightOfLegend = getSizeHeightOfLegendAtLeft(graphics2D, allSeries.elements());
graphics2D.setColor(_legendBackgroundColor);
graphics2D.fillRect(xTopLeftLegend, yTopLeftLegend, sizeWidthOfLegend, sizeHeightOfLegend);
graphics2D.setColor(_legendCadreColor);
graphics2D.drawRect(xTopLeftLegend, yTopLeftLegend, sizeWidthOfLegend, sizeHeightOfLegend);
 
//
int yOfGap = yTopLeftLegend + _nbPixelFreeArroundLegendForPresentation;
int xCurrent = xTopLeftLegend + _nbPixelFreeArroundLegendForPresentation;
 
int nbToRemove = 1;
java.util.List elementsToRemove = new java.util.ArrayList();
//on verifie que la legende n'est pas plus grande que l'image
int size = _allInterval.size()*_nbPixelHeightOfLegendIndicator;
size += 2 * _nbPixelFreeArroundLegendForPresentation;
if (size > _maxHeight ) {
//calcul du nombre d'elements à enlever pour que la legende rentre dans l'image
nbToRemove = (size - _maxHeight) / _nbPixelHeightOfLegendIndicator + 1;
//recherche de l'intervalle à utiliser pour oter des elements
//pour une répartition homogene sur l'ensemble de la légende
double interval = new Double(_allInterval.size()).doubleValue()/new Double((nbToRemove+1)).doubleValue();
 
//enregistrement des numeros des elements à enlever de la légende
for (int j = 1; j <= nbToRemove; j++) {
int t = new Long(Math.round(interval*j)).intValue();
elementsToRemove.add(t + "");
}
}
 
for(int i=_allInterval.size() - 1; i >= 0 ; i--){
boolean toRemove = false;
for (int n=0; n<elementsToRemove.size() && !toRemove; n++){
toRemove = (i == Integer.parseInt((String)elementsToRemove.get(n)));
}
//si l'element n'est pas à enlever, écriture dans la legende
if (!toRemove){
Interval interval = (Interval) _allInterval.elementAt(i);
 
graphics2D.setColor(_colorPalette.getColorAt(i));
graphics2D.fillRect(xCurrent, yOfGap, _nbPixelWidthOfLegendIndicator,
_nbPixelHeightOfLegendIndicator);
 
graphics2D.setColor(Color.black);
graphics2D.drawRect(xCurrent, yOfGap, _nbPixelWidthOfLegendIndicator,
_nbPixelHeightOfLegendIndicator);
 
if (i != 0) {//on n'écrit pas le dernier texte
graphics2D.setColor(_legendWriteTxtColor);
String currentLabel = "" +
getValueAsString(interval.getStartValue(),
_nbDigitAfterDotPrecision);
 
graphics2D.drawString(currentLabel,
xCurrent + _nbPixelWidthOfLegendIndicator +
_nbPixelBetweenTxtLegendAndColorAssociate,
Graphics2DTools.getYToAlignTxt(graphics2D,
yOfGap + _nbPixelHeightOfLegendIndicator, currentLabel));
}
yOfGap += _nbPixelHeightOfLegendIndicator;
}
}
 
graphics2D.setFont(font);
}
 
 
int getSizeHeightOfLegendAtBottom(Graphics2D graphics2D, Vector allSeries)
{
return 0;
}
 
/*private int getColorPosition(double z)
{
//int colorPosition = (int)((z - _min) / _step) + 1;
int colorPosition = (int)((z - _min) / _step);
return colorPosition;
}*/
 
/*private String getValueAsString(double currentValue)
{
int valueAsInt = (int)currentValue;
return (currentValue == valueAsInt)? ""+valueAsInt: "" +currentValue;
}*/
 
private String getValueAsString(double currentValue, int nbDigitAfterDotPrecision)
{
if(nbDigitAfterDotPrecision > 0){
int power = 1;
for(int i=0; i< nbDigitAfterDotPrecision; i++){
power *= 10;
}
currentValue = (int)(currentValue * power);
currentValue = currentValue / power;
}
int valueAsInt = (int)currentValue;
return (currentValue == valueAsInt)? ""+valueAsInt: "" +currentValue;
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/Axis.java
New file
0,0 → 1,266
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.Graphics2D;
import java.awt.Font;
import java.awt.Color;
import java.awt.Stroke;
import java.awt.BasicStroke;
 
//ofc
import com.oxymel.ofc.charts.exception.OFCChartsException;
import com.oxymel.ofc.charts.util.Graphics2DTools;
 
/**
* This class is the abstract superclass for all axis
*/
abstract class Axis
{
/**
* The graduations are written vertically
*/
public static final int VALUES_WRITE_MODE_VERTICAL_ALIGN = 0;
 
/**
* The graduations are written horizontally
*/
public static final int VALUES_WRITE_MODE_HORIZONTAL_ALIGN = 1;
 
 
/**
* The label is centered and written horizontally, it is located under
* the axis (horizontal axis) or on the right (vertical axis).
*/
final static public int LABEL_POSITION_HORIZONTAL_RIGHT_CENTER = 3;
 
/**
* The label is written horizontally on top of the axis
*/
final static public int LABEL_POSITION_HORIZONTAL_TOP = 0;
/**
* The label is centered and written vertically, it is located on top of
* the axis (horizontal axis) or on the left (vertical axis).
*/
final static public int LABEL_POSITION_VERTICAL_LEFT_CENTER = 1;
/**
* The label is centered and written vertically, it is located under
* the axis (horizontal axis) or on the right (vertical axis).
*/
final static public int LABEL_POSITION_VERTICAL_RIGHT_CENTER = 2;
 
//data past during draw
private int _nbPixelSize;
 
//presentation (user parameters)
private boolean _isVisible = true;
private boolean _isValuesDisplay = true;
private boolean _isDrawGapIndicator = true;
private String _suffixAllValues = null;
private int _arrowLength = 30;
private int _nbGapMax = 20;
protected int _nbPixelOfGapIndicator = 3;
//protected int _nbPixelBetweenValueAndGapIndicatorX = 0;
//protected int _nbPixelBetweenValueAndGapIndicatorY = 3;
protected int _nbPixelBetweenValueAndGapIndicator = 3;
protected int _nbPixelFreeBeforeLabel = 5;
protected int _nbPixelBeetweenLineToWriteValues = 0;
protected int _labelPosition = LABEL_POSITION_HORIZONTAL_TOP;
 
//font:
private int _sizeFont = 9;
//color
private Color _axisColor = Color.white;
private Color _gapIndicatorColor = Color.black;
private Color _colorOfValueWrite = Color.white;
 
//user data
private String _label;
 
 
protected Axis(String label)
{
_label = label;
 
setAxisColor(Color.black);
setGapIndicatorColor(Color.black);
setValueWriteColor(Color.black);
}
 
/**
* Gets the axis label
* @return Axis Label
*/
public String getLabel(){return _label;}
 
/**
* Sets the label position
* @param labelPosition defined the label position
*/
public void setLabelPosition(int labelPosition){_labelPosition = labelPosition;}
 
//presentation (user parameters)
String getSuffixAllValues(){return _suffixAllValues;}
int getNbGapMax(){return _nbGapMax;} //number of delimiters
void setNbGapMax(int nbGapMax){_nbGapMax = nbGapMax;} //number of delimiters
void setNbGapMax(Graphics2D graphics2D){};
int getArrowLength(){return _arrowLength;}
 
/**
* Sets the length of the axis arrow.
* The arrow length must be greater than or equal to zero.
* @param arrowLength arrow lenght to be sets
*/
public void setArrowLength(int arrowLength){_arrowLength = arrowLength;}
 
/**
* Disables arrow.
* Axis is displayed as a line not terminated by an arrow.
*/
public void disableArrow(){_arrowLength = 0;}
 
/**
* Sets the axis visibility.
* @param isVisible If true the axis is visible otherwise it is not.
*/
public void setVisible(boolean isVisible){_isVisible = isVisible;}
 
void setNbPixelBetweenValueAndGapIndicator(int nbPixelBetweenValueAndGapIndicator)
{
_nbPixelBetweenValueAndGapIndicator = nbPixelBetweenValueAndGapIndicator;
}
 
//font:
public void setFontSize(int fontSize){_sizeFont = fontSize;}
//color:
Color getAxisColor(){return _axisColor;}
void setAxisColor(Color color)
{
_axisColor = color;
}
 
/**
* Sets the color for the whole axis.
* It fixes the color for the axis itself, the graduations on the axis (graduation marks and associated texts)
* @param color the axis color
*/
public void setFullAxisColor(Color color)
{
_axisColor = color;
setGapIndicatorColor(color);
setValueWriteColor(color);
}
 
Color getGapIndicatorColor(){return _gapIndicatorColor;}
void setGapIndicatorColor(Color color){_gapIndicatorColor = color;}
Color getValueWriteColor(){return _colorOfValueWrite;}
void setValueWriteColor(Color color){_colorOfValueWrite = color;}
 
//interface used for generic draw chart
void setNbPixelSize(int nbPixelSize){_nbPixelSize = nbPixelSize;} //data past during draw
int getNbPixelSize(){return _nbPixelSize;}
int getSizeOfGap(){return _nbPixelSize/getNbGap();}
abstract int getNbNegativeGapToIncludeMinValue();
boolean isContainsNegativeValue(){return (getNbNegativeGapToIncludeMinValue() > 0);}
abstract int getNbPixelUsedAtLeft(Graphics2D graphics2D);
abstract int getNbPixelUsedAtRight(Graphics2D graphics2D);
abstract int getNbPixelUsedAtTop(Graphics2D graphics2D);
abstract int getNbPixelUsedAtBottom(Graphics2D graphics2D) throws OFCChartsException;
abstract int getNbGap();
void draw(int graphicWidth, int graphicHeight, int xTopLeftGraphic, int yTopLeftGraphic,
int xOrigine, int yOrigine, Graphics2D graphics2D)
{
if(!_isVisible){
return;
}
 
Font font = graphics2D.getFont();
int nbGap = getNbGap();
 
Stroke initialStroke = graphics2D.getStroke();
graphics2D.setStroke(new BasicStroke(2.0f));
graphics2D.setColor(getAxisColor());
drawAxisLine(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
if(_arrowLength > 0){
drawArrow(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
}
graphics2D.setStroke(initialStroke);
//
if((_label != null) && (!_label.equals(""))){
graphics2D.setFont(getFont(graphics2D));
drawLabel(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
graphics2D.setFont(font);
}
//
if(_isDrawGapIndicator){
drawGapIndicator(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
}
//
if(_isValuesDisplay){
graphics2D.setFont(getFont(graphics2D));
drawValues(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
graphics2D.setFont(font);
}
}
//draw template pattern:
abstract protected void drawAxisLine(int graphicWidth, int graphicHeight, int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine, int yOrigine, Graphics2D graphics2D);
abstract protected void drawArrow(int graphicWidth, int graphicHeight, int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine, int yOrigine, Graphics2D graphics2D);
abstract protected void drawLabel(int graphicWidth, int graphicHeight, int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine, int yOrigine, Graphics2D graphics2D);
abstract int getNbPixelUsedByLabel(Graphics2D graphics2D);
abstract protected void drawGapIndicator(int graphicWidth, int graphicHeight, int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine, int yOrigine, Graphics2D graphics2D);
abstract protected void drawValues(int graphicWidth, int graphicHeight, int xTopLeftGraphic,
int yTopLeftGraphic, int xOrigine, int yOrigine, Graphics2D graphics2D);
 
 
int getNbPixelWidthOfLabel(Graphics2D graphics2D)
{
Font font = graphics2D.getFont();
graphics2D.setFont(getFont(graphics2D));
int nbPixelWidthOfLabel = Graphics2DTools.getNbPixelWidthOfTxt(graphics2D, _label);
graphics2D.setFont(font);
return nbPixelWidthOfLabel;
}
 
protected Font getFont(Graphics2D graphics2D)
{
Font font = graphics2D.getFont();
if(_sizeFont > 0){
return new Font(font.getName(), font.getStyle(), _sizeFont);
//return new Font("Arial", font.PLAIN, _sizeFont);
//return new Font("Sans-Serif", font.PLAIN, _sizeFont);
// return new Font("Lucida Sans Typewriter", font.PLAIN, _sizeFont);
}
else{
return font;
}
}
 
protected int getNbPixelUsedToDrawLabel(Graphics2D graphics2D)
{
int nbPixelUsedForDrawLabel = 0;
if((getLabel() != null) && (!getLabel().equals(""))){
nbPixelUsedForDrawLabel = _nbPixelFreeBeforeLabel +
getNbPixelUsedByLabel(graphics2D);
}
return nbPixelUsedForDrawLabel;
}
 
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/LegendTable.java
New file
0,0 → 1,182
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.Graphics2D;
import java.awt.Font;
import java.awt.Color;
 
import java.util.Enumeration;
import java.util.Vector;
 
//ofc
import com.oxymel.ofc.charts.data.Category;
import com.oxymel.ofc.charts.series.Series;
import com.oxymel.ofc.charts.series.CategoryValueSeries;
import com.oxymel.ofc.charts.series.CategoryValueSeriesContainer;
import com.oxymel.ofc.charts.util.Graphics2DTools;
import com.oxymel.ofc.charts.exception.OFCChartsRuntimeException;
 
class LegendTable extends Legend
{
private int _nbPixelColumnWidth;
private int _nbPixelLineHeight = 15;
private CategoryValueSeriesContainer _categoryValueSeriesContainer;
 
private Legend _legend;
 
private int _xOrigine;
private int _yOrigine;
 
 
public LegendTable(CategoryValueSeriesContainer categoryValueSeriesContainer)
{
super();
 
_categoryValueSeriesContainer = categoryValueSeriesContainer;
_legend = new Legend();
_legend.setIsLegendInTable(true);
_legend.setCadreColor(Color.white);
setLegendDisplayMode(Legend.LEGEND_DISPLAY_MODE_BOTTOM);
setNbPixelHeightOfLegendIndicator(15);
}
 
public void setFontSize(int size)
{
super.setFontSize(size);
_legend.setFontSize(size);
}
 
public void setNbPixelHeightOfLegendIndicator(int nbPixelHeightOfLegendIndicator)
{
super.setNbPixelHeightOfLegendIndicator(nbPixelHeightOfLegendIndicator);
_legend.setNbPixelHeightOfLegendIndicator(nbPixelHeightOfLegendIndicator);
}
 
void setNbPixelColumnWidth(int nbPixelColumnWidth)
{
_nbPixelColumnWidth = nbPixelColumnWidth;
}
 
void setXOrigine(int xOrigine){_xOrigine = xOrigine;}
void setYOrigine(int yOrigine){_yOrigine = yOrigine;}
 
public void drawLegend(int xTopLeftLegend, int yTopLeftLegend, Vector allSeries, Graphics2D graphics2D)
{
drawLegendAtBottom(graphics2D, xTopLeftLegend, yTopLeftLegend, allSeries);
}
 
int getSizeWidthOfLegendAtLeft(Graphics2D graphics2D, Enumeration enumAllSeries)
{
return 0;
}
 
int getSizeWidthOfLegendAtBottom(Graphics2D graphics2D, Enumeration enumAllSeries)
{
int sizeWithLegendAtLeftOfAxis = _legend.getSizeWidthOfLegendAtLeft(graphics2D, enumAllSeries);
int sizeDataArray = _nbPixelColumnWidth * _categoryValueSeriesContainer.getNbCategories();
return sizeWithLegendAtLeftOfAxis + sizeDataArray;
}
 
int getSizeHeightOfLegendAtBottom(Graphics2D graphics2D, Vector enumAllSeries)
{
int sizeHeightLegend = _legend.getSizeHeightOfLegendAtLeft(graphics2D, enumAllSeries.elements());
return sizeHeightLegend;
}
 
 
int getNbPixelUsedAtLeftOfAxis(Graphics2D graphics2D)
{
//return _sizeWithLegendAtLeftOfAxis;
return _legend.getSizeWidthOfLegendAtLeft(graphics2D,
_categoryValueSeriesContainer.getEnumAllSeriesOrderByDisplayNumber());
}
 
private void drawLegendAtBottom(Graphics2D graphics2D, int xTopLeftLegend, int yTopLeftLegend, Vector allSeries)
{
/*
if(_legendDisplayMode != LEGEND_DISPLAY_MODE_BOTTOM){
return;
}
*/
 
Font font = graphics2D.getFont();
Font fontOnX = getFontOnX(graphics2D);
 
graphics2D.setFont(fontOnX);
int sizeWidthOfLegend = getSizeWidthOfLegendAtLeft(graphics2D, allSeries.elements());
int sizeHeightOfLegend = getSizeHeightOfLegendAtLeft(graphics2D, allSeries.elements());
graphics2D.setColor(_legendBackgroundColor);
graphics2D.fillRect(xTopLeftLegend, yTopLeftLegend, sizeWidthOfLegend, sizeHeightOfLegend);
graphics2D.setColor(_legendCadreColor);
graphics2D.drawRect(xTopLeftLegend, yTopLeftLegend, sizeWidthOfLegend, sizeHeightOfLegend);
 
//_legend.drawLegend(xTopLeftLegend, yTopLeftLegend, allSeries, graphics2D);
_legend.drawLegend(_xOrigine -
_legend.getSizeWidthOfLegendAtLeft(graphics2D, allSeries.elements()), yTopLeftLegend, allSeries, graphics2D);
 
 
//
Vector allCategories = _categoryValueSeriesContainer.getAllCategoriesOrderByDisplayNumber();
//int xCurrent = xTopLeftLegend + _legend.getSizeWidthOfLegendAtLeft(graphics2D, allSeries.elements());
//int xCurrent = _xOrigine;
 
//int xCurrentCenter = xCurrent + (_nbPixelColumnWidth / 2);
 
int xCurrent = _xOrigine;
for(int i= 0; i<allCategories.size(); i++){
Category category = (Category)allCategories.elementAt(i);
int yOfGap = yTopLeftLegend + _nbPixelFreeArroundLegendForPresentation;
 
Enumeration enumAllSeries = _categoryValueSeriesContainer.getEnumAllSeriesOrderByDisplayNumber();
while(enumAllSeries.hasMoreElements()){
CategoryValueSeries categoryValueSeries = (CategoryValueSeries)enumAllSeries.nextElement();
if(categoryValueSeries.isVisible()){
double value = categoryValueSeries.getCategoryValueAsDouble(category.getId());
int valueArroundWith2Decimal = (int)(value * 100);
value = (double)(valueArroundWith2Decimal / 100);
String str = "" + value;
//graphics2D.drawString(str, Graphics2DTools.getXToAlignTxt(graphics2D, xCurrentCenter, str),
// Graphics2DTools.getYToAlignTxt(graphics2D, yCurrentCenter, str));
 
//graphics2D.drawString(str, Graphics2DTools.getXToAlignTxt(graphics2D, xCurrentCenter, str),
// Graphics2DTools.getYToAlignTxt(graphics2D, yCurrentCenter, str));
 
graphics2D.drawString(str,
Graphics2DTools.getXToAlignTxt(graphics2D, xCurrent + (_nbPixelColumnWidth/2), str),
Graphics2DTools.getYToAlignTxt(graphics2D, yOfGap + (_nbPixelHeightOfLegendIndicator/2), str));
 
graphics2D.drawRect(xCurrent, yOfGap, _nbPixelColumnWidth, _nbPixelHeightOfLegendIndicator);
 
//yCurrentCenter += _nbPixelLineHeight;
 
int gap = Graphics2DTools.getNbPixelHeightOfTxt(graphics2D, str);
if(gap > _nbPixelHeightOfLegendIndicator){
yOfGap += gap;
}
else{
yOfGap += _nbPixelHeightOfLegendIndicator;
}
}
}
xCurrent += _nbPixelColumnWidth;
}
 
graphics2D.setFont(font);
}
 
 
int getSizeHeightOfLegendAtLeft(Graphics2D graphics2D, Vector allSeries)
{
return 0;
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/interpolation/NearestInterpolation.java
New file
0,0 → 1,29
package com.oxymel.ofc.charts.interpolation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import java.util.Vector;
 
public class NearestInterpolation extends InvertDistanceSquareInterpolation
{
public NearestInterpolation(int nbPointUsedToInterpolate)
{
super(nbPointUsedToInterpolate, 2);
}
 
public double getValue(double xPointToInterpolate, double yPointToInterpolate,
Vector allPointDistantUsedToInterpolate, int nbPointUsedToInterpolate)
{
computeAllDistance(xPointToInterpolate, yPointToInterpolate, allPointDistantUsedToInterpolate);
doHeapSort(allPointDistantUsedToInterpolate);
PointDistant nearestPointDistant = (PointDistant)allPointDistantUsedToInterpolate.elementAt(0);
return nearestPointDistant.getZ();
}
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/interpolation/InvertDistanceInterpolation.java
New file
0,0 → 1,80
package com.oxymel.ofc.charts.interpolation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import java.util.Vector;
 
public class InvertDistanceInterpolation extends InterpolationMethod
{
private double _weight;
private boolean _isDistanceMaxUsed = false;
private double _distanceMax;
 
public InvertDistanceInterpolation(int nbPointUsedToInterpolate, double weight)
{
super(nbPointUsedToInterpolate);
_weight = weight;
}
 
public InvertDistanceInterpolation(int nbPointUsedToInterpolate, double weight, double distanceMax)
{
this(nbPointUsedToInterpolate, weight);
_isDistanceMaxUsed = true;
_distanceMax = distanceMax;
}
 
 
public double getValue(double xPointToInterpolate, double yPointToInterpolate,
Vector allPointDistantUsedToInterpolate, int nbPointUsedToInterpolate)
{
double totalWeight = 0;
double totalThiessen = 0;
 
computeAllDistance(xPointToInterpolate, yPointToInterpolate, allPointDistantUsedToInterpolate);
doHeapSort(allPointDistantUsedToInterpolate);
 
//System.out.println("allPointDistantUsedToInterpolate.size() = " + allPointDistantUsedToInterpolate.size());
//System.out.println("nbPointUsedToInterpolate = " + nbPointUsedToInterpolate);
 
if(nbPointUsedToInterpolate > allPointDistantUsedToInterpolate.size()){
System.out.println("Find point Exception");
nbPointUsedToInterpolate = allPointDistantUsedToInterpolate.size();
}
for(int i=0; i<nbPointUsedToInterpolate; i++){
PointDistant pointDistant = (PointDistant)allPointDistantUsedToInterpolate.elementAt(i);
double currentDistance = pointDistant.getDistance();
if(_isDistanceMaxUsed){
if((currentDistance > _distanceMax)&&(i!=0)){//il faut au moins 1 point
break;
}
}
double currentDistanceWeightBalanced = getDistanceWeightBalanced(currentDistance);
if(currentDistanceWeightBalanced == 0){
return pointDistant.getZ();
}
double currentWeight = 1/currentDistanceWeightBalanced;
totalThiessen += currentWeight * pointDistant.getZ();
totalWeight += currentWeight;
}
if(totalWeight!=0){
return(totalThiessen/totalWeight );
}
else{
return 0;
}
 
}
 
protected double getDistanceWeightBalanced(double distance)
{
return Math.pow(distance, _weight);
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/interpolation/ThiessenInterpolation.java
New file
0,0 → 1,24
package com.oxymel.ofc.charts.interpolation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
public class ThiessenInterpolation extends InvertDistanceInterpolation
{
public ThiessenInterpolation(int nbPointUsedToInterpolate)
{
super(nbPointUsedToInterpolate, 25);
}
 
public ThiessenInterpolation(int nbPointUsedToInterpolate, double distanceMax)
{
super(nbPointUsedToInterpolate, 25, distanceMax);
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/interpolation/InvertDistanceSquareInterpolation.java
New file
0,0 → 1,46
package com.oxymel.ofc.charts.interpolation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import java.util.Vector;
 
//ofc
import com.oxymel.ofc.charts.util.OFCMath;
 
 
public class InvertDistanceSquareInterpolation extends InvertDistanceInterpolation
{
public InvertDistanceSquareInterpolation(int nbPointUsedToInterpolate)
{
super(nbPointUsedToInterpolate, 2);
}
 
public InvertDistanceSquareInterpolation(int nbPointUsedToInterpolate, double distanceMax)
{
super(nbPointUsedToInterpolate, 2, distanceMax);
}
 
 
protected void computeAllDistance(double xPointToInterpolate, double yPointToInterpolate,
Vector allPointDistantUsedToInterpolate)
{
for(int i=0; i<allPointDistantUsedToInterpolate.size(); i++){
PointDistant pointDistant = (PointDistant)allPointDistantUsedToInterpolate.elementAt(i);
pointDistant.setDistance(OFCMath.computeDistanceSquare(xPointToInterpolate, yPointToInterpolate,
pointDistant.getX(), pointDistant.getY()));
}
}
 
protected double getDistanceWeightBalanced(double distance)
{
return distance;
}
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/interpolation/PointContainer.java
New file
0,0 → 1,159
package com.oxymel.ofc.charts.interpolation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import java.util.Vector;
import java.io.LineNumberReader;
import java.io.FileReader;
import java.util.StringTokenizer;
 
//ofc
import com.oxymel.ofc.charts.data.Point2D;
 
public class PointContainer
{
public static final int LINE_Z_LINE_X_LINE_Y_FORMAT = 1;
public static final int LINE_XYZ_FORMAT = 2;
 
 
private Vector _allPoint = new Vector();
private double _xMax;
private double _yMax;
private double _xMin;
private double _yMin;
private boolean _isXYMaxMinOk = false;
 
public PointContainer()
{
}
 
 
public void setAllPointDistant(String fileName, int format) throws Exception
{
switch(format){
case LINE_Z_LINE_X_LINE_Y_FORMAT:
setAllPointDistantLineZLineXLineY(fileName);
break;
case LINE_XYZ_FORMAT:
setAllPointDistantLineXYZ(fileName);
break;
default:
throw new RuntimeException("Bad file format");
}
}
 
 
private void setAllPointDistantLineZLineXLineY(String fileName) throws Exception
{
_isXYMaxMinOk = false;
_allPoint.clear();
LineNumberReader lineNumberReader = new LineNumberReader(new FileReader(fileName));
String strZ = lineNumberReader.readLine(); //saute le nombre de point
strZ = lineNumberReader.readLine();
while(strZ != null){
String strX = lineNumberReader.readLine();
String strY = lineNumberReader.readLine();
double x = Double.parseDouble(strX);
//x = (x / 1000) - 200;
double y = Double.parseDouble(strY);
//y = (y / 10000) + 360;
PointDistant pointDistant = new PointDistant(x, y, Double.parseDouble(strZ));
//System.out.println("pointDistant = " + pointDistant.toString());
_allPoint.addElement(pointDistant);
strZ = lineNumberReader.readLine();
}
setXYMaxMin();
}
 
 
private void setAllPointDistantLineXYZ(String fileName) throws Exception
{
_isXYMaxMinOk = false;
_allPoint.clear();
LineNumberReader lineNumberReader = new LineNumberReader(new FileReader(fileName));
String line = lineNumberReader.readLine(); //saute info
line = lineNumberReader.readLine(); //saute info
line = lineNumberReader.readLine();
while(line != null){
StringTokenizer stringTokenizer = new StringTokenizer(line, "\t");
String strX = stringTokenizer.nextToken();
String strY = stringTokenizer.nextToken();
String strZ = stringTokenizer.nextToken();
 
// System.out.println("strX = " + strX + " - strY = " + strY + " - strZ = " + strZ );
 
double x = Double.parseDouble(strX);
double y = Double.parseDouble(strY);
 
PointDistant pointDistant = new PointDistant(x, y, Double.parseDouble(strZ));
//System.out.println("pointDistant = " + pointDistant.toString());
_allPoint.addElement(pointDistant);
line = lineNumberReader.readLine();
}
setXYMaxMin();
}
 
 
public Vector getAllPoint(){return _allPoint;}
 
public double getXMax(){return _xMax;}
public double getYMax(){return _yMax;}
public double getXMin(){return _xMin;}
public double getYMin(){return _yMin;}
 
public double getStepXOfGridContainsAllPoint(int nbColumn)
{
if(nbColumn < 2){
return 0;
}
return (_xMax - _xMin)/(nbColumn - 1);
}
 
public double getStepYOfGridContainsAllPoint(int nbLine)
{
if(nbLine < 2){
return 0;
}
return (_yMax - _yMin)/(nbLine - 1);
}
 
public int getNbColumnsOfGridContainsAllPoint(double xStep)
{
return (int)(((_xMax - _xMin)/xStep)+ 1);
}
 
public int getNbLineOfGridContainsAllPoint(double yStep)
{
return (int)(((_yMax - _yMin)/yStep)+ 1);
}
 
 
private void setXYMaxMin()
{
if(_allPoint.size() == 0){
return;
}
Point2D point = (Point2D)_allPoint.elementAt(0);
_xMax = point.getX();
_yMax = point.getY();
_xMin = point.getX();
_yMin = point.getY();
for(int i=0; i<_allPoint.size(); i++){
point = (Point2D)_allPoint.elementAt(i);
_xMax = Math.max(point.getX(), _xMax);
_yMax = Math.max(point.getY(), _yMax);
_xMin = Math.min(point.getX(), _xMin);
_yMin = Math.min(point.getY(), _yMin);
}
_isXYMaxMinOk = true;
}
 
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/interpolation/LaporteInterpolation.java
New file
0,0 → 1,137
package com.oxymel.ofc.charts.interpolation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import java.util.Vector;
 
public class LaporteInterpolation extends InterpolationMethod
{
public LaporteInterpolation(int nbPointUsedToInterpolate)
{
super(nbPointUsedToInterpolate);
if(_nbPointUsedToInterpolate < 6){
_nbPointUsedToInterpolate = 6;
}
}
 
public void setNbPointUsedToInterpolate(int nbPointUsedToInterpolate)
{
if(nbPointUsedToInterpolate > 6){
_nbPointUsedToInterpolate = nbPointUsedToInterpolate;
}
}
 
public double getValue(double xPointToInterpolate, double yPointToInterpolate,
Vector allPointDistantUsedToInterpolate, int nbPointUsedToInterpolate)
{
int nbPointUsed = nbPointUsedToInterpolate;
//si on voulait utiliser le nombre "dwNbPtUsedToInterpol_I" reel choisi par l'utilisateur, il faudrait
//calculer les distances et les classer par ordre decroissant avec la methode du Heap Sort
//Pour le moment on a choisi de ne pas le faire car trop lent pour rien donc:
nbPointUsed = allPointDistantUsedToInterpolate.size();
if(nbPointUsed < 6){
return 0;
}
 
double BR[] = new double[43];
//initialisation
double B[] = new double[43];
for(int i=0; i<43;i++){
B[i] = 0;
}
 
double V2 = ((xPointToInterpolate*xPointToInterpolate)+
(yPointToInterpolate*yPointToInterpolate))*1E-20F; //FLT_MIN dans "float.h" = 1.17549435E-38F
 
for(int i=0; i<nbPointUsed;i++){
PointDistant pointdistant = (PointDistant)allPointDistantUsedToInterpolate.elementAt(i);
double XR = pointdistant.getX() - xPointToInterpolate;
double YR = pointdistant.getY() - yPointToInterpolate;
double ZR = pointdistant.getZ();
double D2 = (XR*XR)+(YR*YR);
if(D2<=V2){
return pointdistant.getZ();
}
double P = 1/(D2*D2);
double W1=P*XR;
double W2=P*YR;
double W3=W1*XR;
double W4=W1*YR;
double W5=W2*YR;
double W6=W3*XR;
double W7=W5*XR;
double W8=W5*YR;
B[1]=B[1]+W6*XR;
B[2]=B[2]+W6*YR;
B[3]=B[3]+W7*XR;
B[4]=B[4]+W6;
B[5]=B[5]+W4*XR;
B[6]=B[6]+W3;
B[7]=B[7]+W3*ZR;
B[10]=B[10]+W8*XR;
B[12]=B[12]+W5*XR;
B[13]=B[13]+W4;
B[14]=B[14]+W4*ZR;
B[17]=B[17]+W8*YR;
B[19]=B[19]+W8;
B[20]=B[20]+W5;
B[21]=B[21]+W5*ZR;
B[27]=B[27]+W1;
B[28]=B[28]+W1*ZR;
B[34]=B[34]+W2;
B[35]=B[35]+W2*ZR;
B[41]=B[41]+P;
B[42]=B[42]+P*ZR;
}
B[9] = B[3];
B[11] = B[5];
B[18] = B[12];
B[25] = B[6];
B[26] = B[13];
B[33] = B[20];
 
// Résolution du système
if(B[1]==0){
return 0;
}
 
for(int i1=2; i1<=7;i1++){
BR[i1]=B[i1]/B[1];
}
int L7=0;
for(int L=2; L<=6;L++){
int KL;
int LM1=L-1;
L7=L7+7;
for(int JJ=L; JJ<=7;JJ++){
int J7=L7+JJ;
KL=L-7;
int KJ=JJ-7;
for(int K1=1; K1<=LM1;K1++){
KL=KL+7;
KJ=KJ+7;
B[J7]=B[J7]-B[KL]*BR[KJ];
}
}
KL=L7+L;
if(B[KL]==0){
return 0;
}
int J1X=KL+1;
int J2X=L7+7;
for(int J3=J1X; J3<=J2X;J3++){
BR[J3]=B[J3]/B[KL];
}
}
return BR[42];
}
 
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/interpolation/PointDistant.java
New file
0,0 → 1,52
package com.oxymel.ofc.charts.interpolation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import com.oxymel.ofc.charts.geographic.Point3D;
 
public class PointDistant extends Point3D
{
private double _distance;
 
/**
* Constructor
* @param x X of point
* @param y Y of Point
*/
public PointDistant(double x, double y, double z)
{
super(x, y, z);
}
 
public PointDistant(double x, double y, double z, double distance)
{
super(x, y, z);
_distance = distance;
}
 
public double getDistance()
{
return _distance;
}
 
public void setDistance(double distance)
{
_distance = distance;
}
 
 
public String toString()
{
return super.toString() + " - distance = " + getDistance();
}
 
 
}
 
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/interpolation/InterpolationMethod.java
New file
0,0 → 1,95
package com.oxymel.ofc.charts.interpolation;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
import java.util.Vector;
 
//ofc
import com.oxymel.ofc.charts.util.OFCMath;
 
abstract public class InterpolationMethod
{
protected int _nbPointUsedToInterpolate = 1;
 
public InterpolationMethod(int nbPointUsedToInterpolate)
{
if(nbPointUsedToInterpolate > 1){
_nbPointUsedToInterpolate = nbPointUsedToInterpolate;
}
}
 
public int getNbPointUsedToInterpolate(){return _nbPointUsedToInterpolate;}
public void setNbPointUsedToInterpolate(int nbPointUsedToInterpolate)
{
if(nbPointUsedToInterpolate > 1){
_nbPointUsedToInterpolate = nbPointUsedToInterpolate;
}
}
 
abstract public double getValue(double xPointToInterpolate, double yPointToInterpolate,
Vector allPointDistantUsedToInterpolate, int nbPointUsedToInterpolate);
 
protected void computeAllDistance(double xPointToInterpolate, double yPointToInterpolate,
Vector allPointDistantUsedToInterpolate)
{
for(int i=0; i<allPointDistantUsedToInterpolate.size(); i++){
PointDistant pointDistant = (PointDistant)allPointDistantUsedToInterpolate.elementAt(i);
pointDistant.setDistance(OFCMath.computeDistance(xPointToInterpolate, yPointToInterpolate,
pointDistant.getX(), pointDistant.getY()));
}
}
 
public void doHeapSort(Vector allPointDistantToSort)
{
int nbPointToSort = allPointDistantToSort.size();
 
/* Construction du tas */
for (int i=nbPointToSort/2; i>=1; i--){
verifTas(nbPointToSort, i, allPointDistantToSort);
}
 
/* 2eme phase : extraction des plus grands elements */
while (nbPointToSort>1){
PointDistant tmpPointToMove = (PointDistant)allPointDistantToSort.elementAt(0);
allPointDistantToSort.setElementAt(allPointDistantToSort.elementAt(nbPointToSort-1), 0);
allPointDistantToSort.setElementAt(tmpPointToMove, nbPointToSort-1);
nbPointToSort--;
verifTas(nbPointToSort, 1, allPointDistantToSort);
}
}
 
 
private void verifTas(int nbPointToSort, int index, Vector allPointDistantToSort)
{
PointDistant currentPointToSort = (PointDistant)allPointDistantToSort.elementAt(index-1);
 
while(index<=nbPointToSort/2){
int j = index+index;
if( (j<nbPointToSort) &&
(((PointDistant) allPointDistantToSort.elementAt(j-1)).getDistance() <
((PointDistant) allPointDistantToSort.elementAt(j)).getDistance()) ){
j++; /** COMPARE LES VALEURS **/
}
 
if (currentPointToSort.getDistance() >=
((PointDistant) allPointDistantToSort.elementAt(j-1)).getDistance()){
break; /** COMPARE LES VALEURS **/
}
 
allPointDistantToSort.setElementAt(allPointDistantToSort.elementAt(j-1), index-1);
 
index = j;
}
 
allPointDistantToSort.setElementAt(currentPointToSort, index-1);
}
 
 
}
/trunk/project/ofccharts/src/com/oxymel/ofc/charts/VerticalNumberAxis.java
New file
0,0 → 1,356
package com.oxymel.ofc.charts;
/*
* Copyright (c) 2006 Oxymel SA.
* All rights reserved.
*
* This software is the confidential and proprietary information of Oxymel SA
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oxymel SA.
*/
 
//java
import java.awt.Graphics2D;
//ofc
import com.oxymel.ofc.charts.util.Graphics2DTools;
import java.awt.geom.AffineTransform;
 
/**
* This class manages vertical graduated axis. The graduations are numbers and
* there is a possibility to make the intermediary graduation marks visible,
* by default they are not.
*/
public class VerticalNumberAxis
extends VerticalAxis {
 
/**
* Axis position "center" indicates that <code>VerticalNumberAxis</code> is
* positioned at the "0" of the <code>HorizontalNumberAxis</code> (value = 0).
*/
public static int AXIS_POSITION_CENTER = 0;
/**
* Axis position "left" indicates that <code>VerticalNumberAxis</code> is
* positioned at the "lowest point" of the <code>HorizontalNumberAxis</code> (value = 1).
*/
public static int AXIS_POSITION_LEFT = 1;
/**
* Axis position "right" indicates that <code>VerticalNumberAxis</code> is
* positioned at the "highest point" of the <code>HorizontalNumberAxis</code> (value = 2).
*/
public static int AXIS_POSITION_RIGHT = 2;
 
private int axisPosition = AXIS_POSITION_CENTER;
 
/* Emplacement de l'axe des X sur l'axe des Y. sera calculé selon axisPosition*/
 
private int positionOnXAxis = 0;
 
private int valueToMove = 0;
 
private NumberAxis _numberAxis = new NumberAxis(this);
private boolean _isIntermediaryGapIndicatorVisible = false;
 
private int _nbPixelMinBetweenValues = 0;
 
/**
* Constructor
* @param label Axis Label
*/
public VerticalNumberAxis(String label) {
super(label);
}
 
/**
* Sets the intermediary gap indicator visibility, not visible by default
* @param isIntermediaryGapIndicatorVisible If true intermediary gap indicator are visible
*/
public void setIntermediaryGapIndicatorVisible(boolean
isIntermediaryGapIndicatorVisible) {
_isIntermediaryGapIndicatorVisible = isIntermediaryGapIndicatorVisible;
}
 
/**
* Sets a given minimum and maximum graduation value for the axis. <br>
* These settings are not mandatory, by default the OFC-Charts component
* computes these values according to the input data, in order to produce a
* graphic which
* occupies the maximum of the reserved space. <br>
* But sometimes it makes sense to fix the scale in order to produces
* several graphics, corresponding to different sets of input data,
* respecting the same scale. In such case -several graphics-,
* the minimum and maximum
* can be respectively, the minimum and maximum of all the input data.
* To get a proper result it is recommended to give the min and max so that none
* of the input data are out of these bounds.
* @param minValue minimum value
* @param maxValue maximum value
*/
public void setMinMaxValue(int minValue, int maxValue) {
_numberAxis.setExternalMinMaxValue(minValue, maxValue);
}
 
//interface NumberAxis
void setMinValue(double minValue) {
_numberAxis.setMinValue(minValue);
}
 
void setMaxValue(double maxValue) {
_numberAxis.setMaxValue(maxValue);
}
 
int getGapValue() {
return _numberAxis.getGapValue();
}
 
//
void getMinValue() {
_numberAxis.getMinValue();
}
 
void getMaxValue() {
_numberAxis.getMaxValue();
}
 
double getFirstValueOnAxis() {
return _numberAxis.getFirstValueOnAxis();
}
 
double getLastValueOnAxis() {
return _numberAxis.getLastValueOnAxis();
}
 
//axis drawing interface
int getNbGap() {
return _numberAxis.getNbGap();
}
 
int getNbNegativeGapToIncludeMinValue() {
return _numberAxis.getNbNegativeGapToIncludeMinValue();
}
 
void draw(int graphicWidth, int graphicHeight, int xTopLeftGraphic,
int yTopLeftGraphic,
int xOrigine, int yOrigine, Graphics2D graphics2D) {
 
AffineTransform initialTranform = graphics2D.getTransform();
AffineTransform trasform = new AffineTransform();
trasform.translate(positionOnXAxis, 0);
graphics2D.setTransform(trasform);
super.draw(graphicWidth, graphicHeight, xTopLeftGraphic, yTopLeftGraphic,
xOrigine, yOrigine, graphics2D);
graphics2D.setTransform(initialTranform);
 
}
 
protected void drawValues(int graphicWidth, int graphicHeight,
int xTopLeftGraphic, int yTopLeftGraphic,
int xOrigine, int yOrigine, Graphics2D graphics2D) {
 
int nbGapOnY = getNbGap();
int sizeOfGapOnY = graphicHeight / nbGapOnY;
int yBottompPsition = sizeOfGapOnY * getNbNegativeGapToIncludeMinValue();
 
AffineTransform initialTranform = graphics2D.getTransform();
AffineTransform trasform = new AffineTransform();
int gapValueOnY = getGapValue();
int currentGap = _numberAxis.getFirstValueOnAxis();
trasform.translate(xOrigine + positionOnXAxis, yOrigine + yBottompPsition);
 
int nbPixelsBetweenTextAndAxis = _nbPixelOfGapIndicator +
_nbPixelBetweenValueAndGapIndicator;
if (axisPosition == AXIS_POSITION_RIGHT) {
nbPixelsBetweenTextAndAxis = -nbPixelsBetweenTextAndAxis;
}
trasform.translate( -nbPixelsBetweenTextAndAxis, 0);
graphics2D.setTransform(trasform);
 
int valueToMove = _numberAxis.getValueToMove();
int nbPixelsOfMove = _numberAxis.getNbPixelsOfMove();
 
for (int i = 0; i < nbGapOnY + 1; i++) {
String szCurrentGap = "" + currentGap;
if (getSuffixAllValues() != null) {
szCurrentGap += getSuffixAllValues();
}
AffineTransform trasform2 = (AffineTransform) trasform.clone();
if ( (valueToMove == 1 && currentGap == _numberAxis.getFirstValueOnAxis())
|| (valueToMove == 0 && currentGap == 0) ||
(valueToMove == 2 && currentGap == _numberAxis.getLastValueOnAxis())) {
trasform2.translate(0, - nbPixelsOfMove);
}
 
trasform2.translate(0, -i * sizeOfGapOnY);
if (axisPosition != AXIS_POSITION_RIGHT) {
trasform2.translate( -Graphics2DTools.getNbPixelWidthOfTxt(graphics2D,
szCurrentGap), 0);
}
trasform2.translate(0,
Graphics2DTools.getYToAlignTxt(graphics2D, 0, szCurrentGap));
graphics2D.setTransform(trasform2);
graphics2D.drawString(szCurrentGap, 0, 0);
currentGap += gapValueOnY;
}
graphics2D.setTransform(initialTranform);
}
 
protected void old_drawValues(int graphicWidth, int graphicHeight,
int xTopLeftGraphic, int yTopLeftGraphic,
int xOrigine, int yOrigine,
Graphics2D graphics2D) {
int nbGapOnY = getNbGap();
int sizeOfGapOnY = graphicHeight / nbGapOnY;
int yOfGap = yTopLeftGraphic + graphicHeight;
graphics2D.setColor(getValueWriteColor());