From 3c2ecf963267d5ad3f0e91b8b3b4983fe623c611 Mon Sep 17 00:00:00 2001 From: luukkainen Date: Fri, 14 Feb 2014 13:43:48 +0000 Subject: [PATCH] Handle negative values properly when filtering values refs #4716 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28851 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../chart/FilteringCategoryDataset.java | 19 ++++++++++++------- .../jfreechart/chart/FilteringPieDataset.java | 1 - 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringCategoryDataset.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringCategoryDataset.java index ec719f95..fb5ec1a7 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringCategoryDataset.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringCategoryDataset.java @@ -3,6 +3,10 @@ package org.simantics.jfreechart.chart; /** * Filters CategoryDataset by creating "Other" item for filtered data. * + * Filtering uses sum of absolute values as a comparison point and compares absolute values. + * If negative values are filtered, their absolute value is added to the others category. + * + * * @author Marko Luukkainen * */ @@ -10,7 +14,6 @@ import java.util.List; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.general.AbstractDataset; -import org.jfree.data.general.DatasetChangeEvent; @SuppressWarnings("rawtypes") public class FilteringCategoryDataset extends AbstractDataset implements org.jfree.data.category.CategoryDataset, FilteredDataset{ @@ -78,17 +81,18 @@ public class FilteringCategoryDataset extends AbstractDataset implements org.jfr for (Object row : original.getRowKeys()) { Number value = original.getValue((Comparable) row, (Comparable)column); if (value != null) - total+=value.doubleValue(); + total+=Math.abs(value.doubleValue()); } total *= filterFraction; for (Object row : original.getRowKeys()) { Number value = original.getValue((Comparable) row, (Comparable)column); if (value == null) continue; - if (value.doubleValue() > total) { + if (Math.abs(value.doubleValue()) > total) { filtered.addValue(value, (Comparable) row, (Comparable)column); } else { - other += value.doubleValue(); + // TODO : what is proper way to handle negative values? + other += Math.abs(value.doubleValue()); } } if (other > 0.0) { @@ -102,17 +106,18 @@ public class FilteringCategoryDataset extends AbstractDataset implements org.jfr for (Object column : original.getColumnKeys()) { Number value = original.getValue((Comparable) row, (Comparable)column); if (value != null) - total += value.doubleValue(); + total += Math.abs(value.doubleValue()); } total *= filterFraction; for (Object column : original.getColumnKeys()) { Number value = original.getValue((Comparable) row, (Comparable)column); if (value == null) continue; - if (value.doubleValue() > total) { + if (Math.abs(value.doubleValue()) > total) { filtered.addValue(value, (Comparable) row, (Comparable)column); } else { - other += value.doubleValue(); + // TODO : what is proper way to handle negative values? + other += Math.abs(value.doubleValue()); } } if (other > 0.0) { diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringPieDataset.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringPieDataset.java index 249c2aa6..dacef528 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringPieDataset.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringPieDataset.java @@ -3,7 +3,6 @@ package org.simantics.jfreechart.chart; import java.util.List; import org.jfree.data.general.AbstractDataset; -import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; -- 2.47.1