r388 - in trunk: coser-business/src/main/java/fr/ifremer/coser/services coser-business/src/main/resources/i18n coser-ui/src/main/java/fr/ifremer/coser/ui/common
Author: chatellier Date: 2010-12-10 10:34:00 +0000 (Fri, 10 Dec 2010) New Revision: 388 Log: Add custom matrix renderer for length structure (displaying missing data on graph : null) Removed: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixDataset.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java trunk/coser-business/src/main/resources/i18n/coser-business_en_GB.properties trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/DataHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixRenderer.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2010-12-10 09:58:50 UTC (rev 387) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2010-12-10 10:34:00 UTC (rev 388) @@ -60,6 +60,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.math.util.MathUtils; +import org.nuiton.math.matrix.DoubleVector; import org.nuiton.math.matrix.MatrixFactory; import org.nuiton.math.matrix.MatrixND; @@ -2215,12 +2216,10 @@ // map lengthstep, species , strata , year > count Map<Double, Map<String, Map<String, Map<String, Double>>>> countForLengthSpeciesStrataYear = new HashMap<Double, Map<String, Map<String, Map<String, Double>>>>(); + Set<Double> lengthSet = new HashSet<Double>(); Set<String> speciesSet = new HashSet<String>(); Set<String> strataSet = new HashSet<String>(); Set<String> yearsSet = new HashSet<String>(); - double minLength = Double.MAX_VALUE; - double maxLength = Double.MIN_VALUE; - boolean halfStep = false; Iterator<String[]> itData = dataContainer.getLength().iterator(); itData.next(); // skip header @@ -2254,7 +2253,8 @@ // get length step to use double ceil = Math.ceil(length); double floor = Math.floor(length); - double round = Math.round(length); + // ne pas prendre 0.5 car 10.0 serait arrondit à 10.5 + double round = Math.floor(length + 0.499999); // on prend le pas ou demi pas le plus proche if (ceil == round) { @@ -2263,17 +2263,9 @@ else { length = floor; } + + lengthSet.add(length); - if (length < minLength) { - minLength = length; - } - if (length > maxLength) { - maxLength = length; - } - if (length - Math.floor(length) != 0.0) { - halfStep = true; - } - try { double number = Double.parseDouble(numberAsString); @@ -2318,11 +2310,6 @@ } } - Set<Double> lengthSet = new HashSet<Double>(); - for (double length = minLength ; length <= maxLength ; length += (halfStep) ? 0.5 : 1) { - lengthSet.add(length); - } - // convert map to matrixND List<Double> lengthSem = new ArrayList<Double>(lengthSet); Collections.sort(lengthSem); @@ -2332,7 +2319,11 @@ Collections.sort(strataSem); List<String> yearsSem = new ArrayList<String>(yearsSet); Collections.sort(yearsSem); - + + if (log.isDebugEnabled()) { + log.debug(_("Creating matrix : %d*%d*%d*%d", lengthSem.size(), speciesSem.size(), strataSem.size(), yearsSem.size())); + } + MatrixND matrix = MatrixFactory.getInstance().create(n_("coser.business.matrix.lengthstructure"), new List<?>[] { lengthSem , speciesSem, strataSem, yearsSem}); matrix.setDimensionName(0, n_("coser.business.common.length")); @@ -2340,7 +2331,7 @@ matrix.setDimensionName(2, n_("coser.business.common.strata")); matrix.setDimensionName(3, n_("coser.business.common.years")); - /*for (Map.Entry<Double, Map<String, Map<String, Map<String, Double>>>> lengthTuple : countForLengthSpeciesStrataYear.entrySet()) { + for (Map.Entry<Double, Map<String, Map<String, Map<String, Double>>>> lengthTuple : countForLengthSpeciesStrataYear.entrySet()) { Double length = lengthTuple.getKey(); for (Map.Entry<String, Map<String, Map<String, Double>>> speciesTuple : lengthTuple.getValue().entrySet()) { String species = speciesTuple.getKey(); @@ -2352,9 +2343,9 @@ } } } - }*/ + } - for (double length = minLength ; length <= maxLength ; length += (halfStep) ? 0.5 : 1) { + /*for (double length = minLength ; length <= maxLength ; length += (halfStep) ? 0.5 : 1) { for (String species : speciesSem) { for (String strata : strataSem) { for (String year : yearsSem) { @@ -2377,7 +2368,7 @@ } } } - } + }*/ return matrix; } Modified: trunk/coser-business/src/main/resources/i18n/coser-business_en_GB.properties =================================================================== --- trunk/coser-business/src/main/resources/i18n/coser-business_en_GB.properties 2010-12-10 09:58:50 UTC (rev 387) +++ trunk/coser-business/src/main/resources/i18n/coser-business_en_GB.properties 2010-12-10 10:34:00 UTC (rev 388) @@ -4,6 +4,7 @@ Can't\ read\ file\ %s\ for\ category\ %s= Can't\ read\ file\ '%s'.\ Check\ CSV\ file\ separator= Can't\ replace\ data\ value.\ Expected\ %s\ but\ was\ %s= +Creating\ matrix\ \:\ %d*%d*%d*%d= Missing\ file\ %s= Missing\ haul\ name= Missing\ maturity\ attribute= Modified: trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties =================================================================== --- trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties 2010-12-10 09:58:50 UTC (rev 387) +++ trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties 2010-12-10 10:34:00 UTC (rev 388) @@ -4,6 +4,7 @@ Can't\ read\ file\ %s\ for\ category\ %s=Impossible de lire le fichier %s pour la cat\u00E9gorie %s \! Can't\ read\ file\ '%s'.\ Check\ CSV\ file\ separator=Impossible de lire le fichier '%s'.\nMerci de v\u00E9rifier le s\u00E9parateur utilis\u00E9 est bien un point-virgule ';' Can't\ replace\ data\ value.\ Expected\ %s\ but\ was\ %s= +Creating\ matrix\ \:\ %d*%d*%d*%d= Missing\ file\ %s=Fichier manquant \: %s Missing\ haul\ name=Nom de trait manquant Missing\ maturity\ attribute=Attribut maturit\u00E9 manquant Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/DataHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/DataHandler.java 2010-12-10 09:58:50 UTC (rev 387) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/DataHandler.java 2010-12-10 10:34:00 UTC (rev 388) @@ -36,14 +36,12 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.math.matrix.MatrixND; import org.nuiton.math.matrix.viewer.MatrixViewerPanel; -import org.nuiton.math.matrix.viewer.renderer.MatrixChartRenderer; import org.nuiton.math.matrix.viewer.renderer.MatrixInfoTableRenderer; import org.nuiton.widget.SwingSession; import fr.ifremer.coser.bean.AbstractDataContainer; import fr.ifremer.coser.bean.Project; import fr.ifremer.coser.services.ProjectService; -import fr.ifremer.coser.ui.control.ControlHandler; /** * Data application handler. @@ -81,8 +79,8 @@ JFrame matrixViewerFrame = new JFrame(_("coser.ui.graph.lengthStructure")); matrixViewerFrame.setName("lengthstructureframe"); MatrixViewerPanel panel = new MatrixViewerPanel(); + panel.addMatrixRenderer(new LengthStructureMatrixRenderer()); panel.addMatrixRenderer(new MatrixInfoTableRenderer()); - panel.addMatrixRenderer(new MatrixChartRenderer()); panel.addMatrix(matrix); matrixViewerFrame.add(panel); matrixViewerFrame.pack(); Deleted: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixDataset.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixDataset.java 2010-12-10 09:58:50 UTC (rev 387) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixDataset.java 2010-12-10 10:34:00 UTC (rev 388) @@ -1,66 +0,0 @@ -/* - * #%L - * - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 Ifremer, CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-2.0.html>. - * #L% - */ - -package fr.ifremer.coser.ui.common; - -import java.util.List; - -import org.nuiton.math.matrix.MatrixND; -import org.nuiton.math.matrix.viewer.renderer.jfreechart.GraphMatrixNDDataset; - -/** - * LengthStructureMatrixDataset - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class LengthStructureMatrixDataset extends GraphMatrixNDDataset { - - /** serialVersionUID. */ - private static final long serialVersionUID = 6859245574029509304L; - - protected List<Double> categoryKeys; - - public LengthStructureMatrixDataset(MatrixND mat) { - this(mat.getSemantic(1), mat.getSemantic(0), mat); - } - - public LengthStructureMatrixDataset(List<?> seriesNames, List<?> categories, MatrixND mat) { - super(seriesNames, categories, mat); - } - - /*@Override - public Number getValue(int row, int column) { - Number number = super.getValue(row, column); - if (number.doubleValue() < 0.1) { - number = null; - } - return number; - }*/ - -} // GraphMatrixNDDataset Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixRenderer.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixRenderer.java 2010-12-10 09:58:50 UTC (rev 387) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixRenderer.java 2010-12-10 10:34:00 UTC (rev 388) @@ -25,10 +25,19 @@ package fr.ifremer.coser.ui.common; +import static org.nuiton.i18n.I18n._; +import static org.nuiton.i18n.I18n.n_; + +import java.util.List; + import org.jfree.data.category.CategoryDataset; +import org.jfree.data.category.DefaultCategoryDataset; import org.nuiton.math.matrix.MatrixND; import org.nuiton.math.matrix.viewer.renderer.MatrixChartRenderer; +import org.nuiton.math.matrix.viewer.renderer.jfreechart.GraphMatrixNDDataset; +import fr.ifremer.coser.CoserConstants.Category; + /** * JFreeChart matrix panel renderer. * @@ -45,7 +54,45 @@ @Override protected CategoryDataset getCategoryDataset(MatrixND matrix) { - return new LengthStructureMatrixDataset(matrix); + return getLengthStructureDataSet(matrix); } + + protected CategoryDataset getLengthStructureDataSet(MatrixND matrix) { + CategoryDataset dataset = null; + String semantic0Name = matrix.getDimensionName(0); + if ("coser.business.common.length".equals(semantic0Name)) { + DefaultCategoryDataset defaultDataset = new DefaultCategoryDataset(); + List<?> semantic0 = matrix.getSemantic(0); + double first = (Double)semantic0.get(0); + double last = (Double)semantic0.get(semantic0.size() - 1); + boolean haltStep = false; + + for (Object number : semantic0) { + double dNumber = (Double)number; + if (dNumber - Math.floor(dNumber) > 0) { + haltStep = true; + break; + } + } + + for (double index = first ; index <= last ; index += (haltStep) ? 0.5 : 1) { + + for (Object serieSem : matrix.getSemantic(1)) { + Double value = null; + + if (semantic0.contains(index)) { + value = matrix.getValue(new Object[] { index, serieSem }); + } + + defaultDataset.setValue((Number)value, (Comparable)serieSem, (Comparable)index); + } + } + dataset = defaultDataset; + } + else { + dataset = new GraphMatrixNDDataset(matrix); + } + return dataset; + } }
participants (1)
-
chatellier@users.labs.libre-entreprise.org