private static void configureBarRenderer(
      BarRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) {
    StandardBarPainter barPainter = new StandardBarPainter();
    renderer.setBarPainter(barPainter);
    renderer.setGradientPaintTransformer(null);

    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    int seriesCount = valueSourceData.getSeriesCount();
    DimensionConfig domainConfig = valueSource.getDomainConfig();
    DimensionConfig colorDimensionConfig =
        plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.COLOR);
    SeriesFormat seriesFormat = valueSource.getSeriesFormat();

    // Loop all series and set series format.
    // Format based on dimension configs will be set later on in initFormatDelegate().
    for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
      // configure series paint if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) {
        renderer.setSeriesPaint(seriesIdx, seriesFormat.getAreaFillPaint());
      }

      // configure general style of the bars
      renderer.setShadowVisible(false);
      renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT);
    }
    renderer.setDrawBarOutline(true);
  }
  public static DefaultStatisticalCategoryDataset createDefaultStatisticalCategoryDataset(
      ValueSource valueSource, PlotInstance plotInstance) throws ChartPlottimeException {
    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    assertMaxValueCountNotExceededOrThrowException(valueSourceData);
    GroupCellSeriesData dataForAllGroupCells = valueSourceData.getSeriesDataForAllGroupCells();
    DefaultStatisticalCategoryDataset dataset = new DefaultStatisticalCategoryDataset();
    DefaultDimensionConfig domainConfig = valueSource.getDomainConfig();
    DimensionConfigData domainConfigData =
        plotInstance.getPlotData().getDimensionConfigData(domainConfig);

    // Loop all group cells and add data to dataset
    for (GroupCellKeyAndData groupCellKeyAndData : dataForAllGroupCells) {
      GroupCellKey groupCellKey = groupCellKeyAndData.getKey();
      GroupCellData groupCellData = groupCellKeyAndData.getData();
      String seriesName =
          generateSeriesName(
              valueSource, groupCellKey, plotInstance.getCurrentPlotConfigurationClone());

      Map<PlotDimension, double[]> mainSeriesData =
          groupCellData.getDataForUsageType(SeriesUsageType.MAIN_SERIES);
      double[] xValues = mainSeriesData.get(PlotDimension.DOMAIN);
      double[] yValues = mainSeriesData.get(PlotDimension.VALUE);
      double[] yErrorValues = valueSourceData.getAbsoluteUtilityValues(groupCellKeyAndData, true);
      if (yErrorValues == null) {
        throw new ChartPlottimeException(
            "undefined_series", valueSource.toString(), SeriesUsageType.INDICATOR_1);
      }

      // this dataset does not support unsymmetric errors
      if (groupCellData.getDataForUsageType(SeriesUsageType.INDICATOR_2) != null) {
        throw new ChartPlottimeException(
            "unsymmetric_utility_not_supported", valueSource.toString());
      }

      int rowCount = xValues.length;

      // Loop all rows and add data to series
      double xValue;
      double yValue;
      double yErrorValue;
      String xString;
      for (int row = 0; row < rowCount; ++row) {
        xValue = xValues[row];
        xString = domainConfigData.getStringForValue(xValue);
        yValue = yValues[row];
        yErrorValue = yErrorValues[row] - yValue;

        dataset.add(yValue, yErrorValue, seriesName, xString);
      }
    }
    return dataset;
  }
  private static void configureXYDifferenceRenderer(
      FormattedXYDifferenceRenderer renderer,
      ValueSource valueSource,
      PlotConfiguration plotConfiguration) {
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    SeriesFormat seriesFormat = valueSource.getSeriesFormat();
    DimensionConfig domainConfig = valueSource.getDomainConfig();
    DimensionConfig colorDimensionConfig =
        plotConfiguration.getDimensionConfig(PlotDimension.COLOR);
    DimensionConfig shapeDimensionConfig =
        plotConfiguration.getDimensionConfig(PlotDimension.SHAPE);

    int seriesCount = 1; // valueSource.getSeriesDataForAllGroupCells().groupCellCount();

    // Loop all series and set series format.
    // Format based on dimension configs will be set later on in initFormatDelegate().
    for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
      // configure linestyle
      if (seriesFormat.getLineStyle() == LineStyle.NONE) {
      } else {
        renderer.setSeriesStroke(seriesIdx, seriesFormat.getStroke(), false);
      }

      // configure series shape if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) {
        if (seriesFormat.getItemShape() != ItemShape.NONE) {
          renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape());
        } else {
        }
      }

      // configure series color if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) {
        Color itemColor = seriesFormat.getItemColor();
        Color halfTransparentPaint =
            DataStructureUtils.setColorAlpha(itemColor, itemColor.getAlpha() / 2);

        renderer.setSeriesPaint(0, halfTransparentPaint);
        renderer.setSeriesFillPaint(0, halfTransparentPaint);
        renderer.setPositivePaint(halfTransparentPaint);
        renderer.setNegativePaint(
            new Color(
                255 - itemColor.getRed(),
                255 - itemColor.getGreen(),
                255 - itemColor.getBlue(),
                itemColor.getAlpha() / 2));
      }
      renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT);
    }
  }
예제 #4
0
 public ValueSourceData getValueSourceData(ValueSource valueSource) {
   if (valueSource != null) {
     int id = valueSource.getId();
     return valueSourceDataMap.get(id);
   }
   return null;
 }
  private static void addSeriesToDefaultXYDataset(
      ValueSource valueSource, int seriesIdx, PlotInstance plotInstance, DefaultXYDataset dataset)
      throws ChartPlottimeException {
    final int xIdx = 0;
    final int yIdx = 1;

    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    assertMaxValueCountNotExceededOrThrowException(valueSourceData);

    GroupCellSeriesData dataForAllGroupCells = valueSourceData.getSeriesDataForAllGroupCells();
    GroupCellKeyAndData groupCellKeyAndData =
        dataForAllGroupCells.getGroupCellKeyAndData(seriesIdx);

    GroupCellKey groupCellKey = groupCellKeyAndData.getKey();
    GroupCellData groupCellData = groupCellKeyAndData.getData();

    // create series name
    GroupCellKey groupCellKeyClone = (GroupCellKey) groupCellKey.clone();
    String seriesName =
        generateSeriesName(
            valueSource, groupCellKeyClone, plotInstance.getCurrentPlotConfigurationClone());
    String differenceName = "__&%" + seriesName + "%&__";

    Map<PlotDimension, double[]> mainData =
        groupCellData.getDataForUsageType(SeriesUsageType.MAIN_SERIES);
    double[] xValues = mainData.get(PlotDimension.DOMAIN);
    double[] yValues = mainData.get(PlotDimension.VALUE);

    double[][] mainSeries = new double[2][xValues.length];
    mainSeries[xIdx] = xValues;
    mainSeries[yIdx] = yValues;
    dataset.addSeries(seriesName, mainSeries);

    if (valueSource.getSeriesFormat().getUtilityUsage() == IndicatorType.DIFFERENCE) {
      double[] differenceValues =
          valueSourceData.getAbsoluteUtilityValues(groupCellKeyAndData, true);
      if (differenceValues == null) {
        throw new ChartPlottimeException(
            "undefined_series", valueSource.toString(), SeriesUsageType.INDICATOR_1);
      }
      double[][] differenceSeries = new double[2][xValues.length];
      differenceSeries[xIdx] = xValues;
      differenceSeries[yIdx] = differenceValues;
      dataset.addSeries(differenceName, differenceSeries);
    }
  }
 public static XYItemRenderer createDeviationRenderer(
     ValueSource valueSource, PlotInstance plotInstance) {
   FormattedDeviationRenderer renderer = new FormattedDeviationRenderer();
   configureXYLineAndShapeRenderer(renderer, valueSource, plotInstance);
   renderer.setAlpha(0.5f * valueSource.getSeriesFormat().getOpacity() / 255f);
   initFormatDelegate(valueSource, renderer, plotInstance);
   return renderer;
 }
  /**
   * @param valueSource
   * @param plotInstance
   * @param autoWidthFraction If this value is greater than 0, an auto width for the intervals is
   *     calculated such that the intervals nearest to each other touch. This value is then
   *     multiplied with the value of autoWidthFtraction. If unset, the intervals have width 0.
   * @param allowDuplicates
   * @param sortByDomain if true, the data is sorted by domain values (useful for bar and area
   *     charts)
   * @return
   * @throws ChartPlottimeException
   */
  public static XYSeriesCollection createXYSeriesCollection(
      ValueSource valueSource,
      PlotInstance plotInstance,
      double autoWidthFraction,
      boolean allowDuplicates,
      boolean sortByDomain)
      throws ChartPlottimeException {
    XYSeriesCollection xyDataset = new XYSeriesCollection();
    if (autoWidthFraction > 0) {
      xyDataset.setAutoWidth(true);
    } else {
      xyDataset.setAutoWidth(false);
      xyDataset.setIntervalWidth(0);
    }

    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    assertMaxValueCountNotExceededOrThrowException(valueSourceData);
    GroupCellSeriesData dataForAllGroupCells = valueSourceData.getSeriesDataForAllGroupCells();

    // Loop over group cells and add data to dataset
    for (GroupCellKeyAndData groupCellKeyAndData : dataForAllGroupCells) {
      GroupCellKey groupCellKey = groupCellKeyAndData.getKey();
      GroupCellData groupCellData = groupCellKeyAndData.getData();

      String seriesName =
          generateSeriesName(
              valueSource, groupCellKey, plotInstance.getCurrentPlotConfigurationClone());

      XYSeries series = new XYSeries(seriesName, sortByDomain, allowDuplicates);
      Map<PlotDimension, double[]> dataForUsageType =
          groupCellData.getDataForUsageType(SeriesUsageType.MAIN_SERIES);
      int rowCount = dataForUsageType.get(PlotDimension.DOMAIN).length;
      double[] xValues = dataForUsageType.get(PlotDimension.DOMAIN);
      double[] yValues = dataForUsageType.get(PlotDimension.VALUE);

      try {
        // Loop over rows and add data to series
        for (int row = 0; row < rowCount; ++row) {
          double x = xValues[row];
          double y = yValues[row];
          if (!Double.isNaN(x)) {
            series.add(x, y);
          }
        }
      } catch (SeriesException e) {
        throw new ChartPlottimeException(
            "duplicate_value", valueSource.toString(), PlotDimension.DOMAIN.getName());
      }

      xyDataset.addSeries(series);
    }
    // intervals should not touch each other, so decrease auto width.
    if (xyDataset.getIntervalWidth() > 0) {
      xyDataset.setIntervalWidth(xyDataset.getIntervalWidth() * autoWidthFraction);
    }
    return xyDataset;
  }
  private static void configureXYLineAndShapeRenderer(
      XYLineAndShapeRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) {
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    SeriesFormat seriesFormat = valueSource.getSeriesFormat();
    DimensionConfig domainConfig = valueSource.getDomainConfig();
    DimensionConfig colorDimensionConfig =
        plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.COLOR);
    DimensionConfig shapeDimensionConfig =
        plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.SHAPE);
    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);

    int seriesCount = valueSourceData.getSeriesDataForAllGroupCells().groupCellCount();

    // Loop all series and set series format.
    // Format based on dimension configs will be set later on in initFormatDelegate().
    for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
      // configure linestyle
      if (seriesFormat.getLineStyle() == LineStyle.NONE) {
        renderer.setSeriesLinesVisible(seriesIdx, false);
      } else {
        renderer.setSeriesLinesVisible(seriesIdx, true);
        renderer.setSeriesStroke(seriesIdx, seriesFormat.getStroke(), false);
      }

      // configure series shape if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) {
        if (seriesFormat.getItemShape() != ItemShape.NONE) {
          renderer.setSeriesShapesVisible(seriesIdx, true);
          renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape());
        } else {
          renderer.setSeriesShapesVisible(seriesIdx, false);
        }
      }

      // configure series color if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) {
        Color itemColor = seriesFormat.getItemColor();
        renderer.setSeriesPaint(seriesIdx, itemColor);
        renderer.setSeriesFillPaint(seriesIdx, itemColor);
      }
      renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT);
      renderer.setUseOutlinePaint(true);
    }
  }
  private static void configureLineAndShapeRenderer(
      LineAndShapeRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) {
    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    int seriesCount = valueSourceData.getSeriesCount();
    SeriesFormat seriesFormat = valueSource.getSeriesFormat();
    DimensionConfig domainConfig = valueSource.getDomainConfig();
    DimensionConfig colorDimensionConfig =
        plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.COLOR);
    DimensionConfig shapeDimensionConfig =
        plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.SHAPE);

    renderer.setDefaultEntityRadius(4);

    // loop all series and set series format
    for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
      // configure linestyle
      if (seriesFormat.getLineStyle() != LineStyle.NONE) {
        renderer.setSeriesLinesVisible(seriesIdx, true);
        renderer.setSeriesStroke(seriesIdx, seriesFormat.getStroke(), false);
      } else {
        renderer.setSeriesLinesVisible(seriesIdx, false);
      }

      // configure series shape if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) {
        if (seriesFormat.getItemShape() != ItemShape.NONE) {
          renderer.setSeriesShapesVisible(seriesIdx, true);
          renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape());
        } else {
          renderer.setSeriesShapesVisible(seriesIdx, false);
        }
      }

      // configure series color if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) {
        Color itemColor = seriesFormat.getItemColor();
        renderer.setSeriesPaint(seriesIdx, itemColor);
      }
      renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT);
      renderer.setUseOutlinePaint(true);
    }
  }
  private static void configureAreaRenderer(
      AreaRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) {
    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    int seriesCount = valueSourceData.getSeriesCount();
    SeriesFormat seriesFormat = valueSource.getSeriesFormat();

    // Loop all series and set series format.
    // Format based on dimension configs will be set later on in initFormatDelegate().
    for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
      renderer.setSeriesPaint(seriesIdx, seriesFormat.getAreaFillPaint());
    }
  }
  private static void configureScatterRenderer(
      ScatterRenderer renderer, ValueSource valueSource, PlotInstance plotInstance)
      throws ChartPlottimeException {
    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    int seriesCount = valueSourceData.getSeriesCount();
    SeriesFormat seriesFormat = valueSource.getSeriesFormat();
    DimensionConfig domainConfig = valueSource.getDomainConfig();
    DimensionConfig colorDimensionConfig =
        plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.COLOR);
    DimensionConfig shapeDimensionConfig =
        plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.SHAPE);

    renderer.setDefaultEntityRadius(4);

    // loop all series and set series format
    for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
      // lines are not supported in a ScatterRenderer, but this is already checked in
      // JFreeChartPlotEngine.getWarnings().

      // configure series shape if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) {
        //				if(seriesFormat.getItemShape() != ItemShape.NONE) {
        renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape());
        //				} else {
        //					throw new ChartPlottimeException("unsupported_item_shape", valueSource.toString(),
        // seriesFormat.getItemShape());
        //				}
      }

      // configure series color if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) {
        Color itemColor = seriesFormat.getItemColor();
        renderer.setSeriesPaint(seriesIdx, itemColor);
      }
      renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT);
      renderer.setUseOutlinePaint(true);
      renderer.setDrawOutlines(true);
      renderer.setUseSeriesOffset(false);
    }
  }
  /**
   * Same as {@link #createDefaultMultiValueCategoryDataset(ValueSource, PlotConfiguration)}, but
   * instead of storing only the values it stores pairs in the lists, where the first value is the
   * data value, and the second value holds the index of the value in the series in valueSource.
   *
   * <p>Must be used for the FormattedScatterRenderer.
   *
   * @throws ChartPlottimeException
   */
  public static DefaultMultiValueCategoryDataset createAnnotatedDefaultMultiValueCategoryDataset(
      ValueSource valueSource, PlotInstance plotInstance) throws ChartPlottimeException {
    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    assertMaxValueCountNotExceededOrThrowException(valueSourceData);
    GroupCellSeriesData dataForAllGroupCells = valueSourceData.getSeriesDataForAllGroupCells();
    DefaultMultiValueCategoryDataset dataset = new DefaultMultiValueCategoryDataset();
    DefaultDimensionConfig domainConfig = valueSource.getDomainConfig();
    DimensionConfigData domainConfigData =
        plotInstance.getPlotData().getDimensionConfigData(domainConfig);

    // Loop all group cells and add data to dataset
    for (GroupCellKeyAndData groupCellKeyAndData : dataForAllGroupCells) {
      // the DefaultMultiValueCategoryDataset expects a List of values for each domain value. This
      // map
      // maps domain values to lists and is filled while we iterate through all data value below.
      Map<Double, List<Pair<Double, Integer>>> valueListsForDomainValues =
          new HashMap<Double, List<Pair<Double, Integer>>>();
      for (Double value : domainConfigData.getDistinctValues()) {
        valueListsForDomainValues.put(value, new LinkedList<Pair<Double, Integer>>());
      }

      GroupCellKey groupCellKey = groupCellKeyAndData.getKey();
      GroupCellData groupCellData = groupCellKeyAndData.getData();
      String seriesName =
          generateSeriesName(
              valueSource, groupCellKey, plotInstance.getCurrentPlotConfigurationClone());

      Map<PlotDimension, double[]> mainSeriesData =
          groupCellData.getDataForUsageType(SeriesUsageType.MAIN_SERIES);
      double[] xValues = mainSeriesData.get(PlotDimension.DOMAIN);
      double[] yValues = mainSeriesData.get(PlotDimension.VALUE);
      int rowCount = xValues.length;

      // Loop all rows and add data into map
      double xValue;
      double yValue;
      String xString;
      for (int row = 0; row < rowCount; ++row) {
        xValue = xValues[row];
        yValue = yValues[row];
        Pair<Double, Integer> valueRowNumberPair = new Pair<Double, Integer>(yValue, row);
        valueListsForDomainValues.get(xValue).add(valueRowNumberPair);
      }

      for (Double value : domainConfigData.getDistinctValues()) {
        xString = domainConfigData.getStringForValue(value);
        dataset.add(valueListsForDomainValues.get(value), seriesName, xString);
      }
    }
    return dataset;
  }
  public static DefaultTableXYDataset createDefaultTableXYDataset(
      ValueSource valueSource, PlotInstance plotInstance) throws ChartPlottimeException {
    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    assertMaxValueCountNotExceededOrThrowException(valueSourceData);
    GroupCellSeriesData dataForAllGroupCells = valueSourceData.getSeriesDataForAllGroupCells();
    DefaultTableXYDataset dataset = new DefaultTableXYDataset();

    // Loop all group cells and add data to dataset
    for (GroupCellKeyAndData groupCellKeyAndData : dataForAllGroupCells) {
      GroupCellKey groupCellKey = groupCellKeyAndData.getKey();
      GroupCellData groupCellData = groupCellKeyAndData.getData();

      Map<PlotDimension, double[]> dataForUsageType =
          groupCellData.getDataForUsageType(SeriesUsageType.MAIN_SERIES);
      double[] xValues = dataForUsageType.get(PlotDimension.DOMAIN);
      double[] yValues = dataForUsageType.get(PlotDimension.VALUE);
      int rowCount = xValues.length;

      String seriesName =
          generateSeriesName(
              valueSource, groupCellKey, plotInstance.getCurrentPlotConfigurationClone());

      XYSeries series = new XYSeries(seriesName, false, false);

      // Loop all rows and add data to series
      double x;
      double y;
      for (int row = 0; row < rowCount; ++row) {
        x = xValues[row];
        y = yValues[row];
        try {
          if (!Double.isNaN(x)) {
            series.add(
                x, y,
                false); // false means: do not notify. Since we are currently initializing, this is
                        // not necessary and saves us some fractions of a second
          }
        } catch (SeriesException e) {
          throw new ChartPlottimeException(
              "duplicate_value", valueSource.toString(), PlotDimension.DOMAIN.getName());
        }
      }
      dataset.addSeries(series);
    }
    dataset.setAutoWidth(true);
    return dataset;
  }
 public static String generateSeriesName(
     ValueSource valueSource, GroupCellKey groupCellKey, PlotConfiguration plotConfiguration) {
   //		groupCellKey.removeRangeForDimension(Dimension.X);	// legend does not need X-group
   String filterName = groupCellKey.getNiceString(plotConfiguration);
   String seriesName = valueSource.getLabel();
   StringBuilder builder = new StringBuilder();
   if (seriesName == null) {
     seriesName = I18N.getGUILabel("plotter.unnamed_value_label");
   }
   builder.append(seriesName);
   if (filterName.length() != 0) {
     builder.append(" [");
     builder.append(filterName);
     builder.append("]");
   }
   return builder.toString();
 }
  private List<Set<PlotDimension>> findCompatibleDimensions(
      PlotConfiguration plotConfiguration, List<ValueSource> allValueSources) {
    Map<PlotDimension, DefaultDimensionConfig> dimensionConfigMap =
        plotConfiguration.getDefaultDimensionConfigs();

    // find all Dimensions for which we create a legend item
    List<Set<PlotDimension>> dimensionsWithLegend = new LinkedList<Set<PlotDimension>>();
    for (Entry<PlotDimension, DefaultDimensionConfig> dimensionEntry :
        dimensionConfigMap.entrySet()) {
      PlotDimension dimension = dimensionEntry.getKey();
      DefaultDimensionConfig dimensionConfig = dimensionEntry.getValue();

      boolean createLegend = false;
      if (dimensionConfig.isGrouping()) {
        createLegend = true;
      } else {
        for (ValueSource valueSource : allValueSources) {
          if (!valueSource.isUsingDomainGrouping()) {
            createLegend = true;
            break;
          }
        }
      }

      if (createLegend) {
        if (!dimensionConfig.isNominal()) {
          Set<PlotDimension> newSet = new HashSet<DimensionConfig.PlotDimension>();
          newSet.add(dimension);
          dimensionsWithLegend.add(newSet);
        } else {
          // iterate over list and find dimensions with compatible properties
          boolean compatibleToSomething = false;
          for (Set<PlotDimension> dimensionSet : dimensionsWithLegend) {
            boolean compatible = true;
            for (PlotDimension comparedDimension : dimensionSet) {
              DefaultDimensionConfig comparedDimensionConfig =
                  (DefaultDimensionConfig) plotConfiguration.getDimensionConfig(comparedDimension);
              if (!comparedDimensionConfig.isNominal()) {
                compatible = false;
                break;
              }
              if (!dimensionConfig
                  .getDataTableColumn()
                  .equals(comparedDimensionConfig.getDataTableColumn())) {
                compatible = false;
                break;
              } else if (comparedDimensionConfig.isGrouping()
                  && comparedDimensionConfig.getGrouping() instanceof DistinctValueGrouping
                  && !dimensionConfig.isGrouping()
                  && dimensionConfig.isNominal()) {
                compatible = true;
              } else if (dimensionConfig.isGrouping()
                  && dimensionConfig.getGrouping() instanceof DistinctValueGrouping
                  && !comparedDimensionConfig.isGrouping()
                  && comparedDimensionConfig.isNominal()) {
                compatible = true;
              } else if (dimensionConfig.isGrouping() != comparedDimensionConfig.isGrouping()) {
                compatible = false;
                break;
              } else if (!dimensionConfig.isGrouping()) {
                compatible = true;
              } else if (dimensionConfig
                  .getGrouping()
                  .equals(comparedDimensionConfig.getGrouping())) {
                compatible = true;
              } else {
                compatible = false;
                break;
              }
            }
            if (compatible) {
              dimensionSet.add(dimension);
              compatibleToSomething = true;
              break;
            }
          }
          if (!compatibleToSomething) {
            Set<PlotDimension> newSet = new HashSet<DimensionConfig.PlotDimension>();
            newSet.add(dimension);
            dimensionsWithLegend.add(newSet);
          }
        }
      }
    }
    return dimensionsWithLegend;
  }
  private void createDimensionConfigLegendItem(
      PlotInstance plotInstance,
      DefaultDimensionConfig dimensionConfig,
      Set<PlotDimension> dimensionSet,
      LegendItemCollection legendItemCollection) {
    PlotConfiguration plotConfiguration = plotInstance.getCurrentPlotConfigurationClone();
    DimensionConfigData dimensionConfigData =
        plotInstance.getPlotData().getDimensionConfigData(dimensionConfig);
    if (dimensionConfig.isGrouping()) {
      // create legend entry based on the grouping
      if (dimensionConfig.isNominal()) {
        // create categorical legend --> one item for each category
        createCategoricalLegendItems(
            plotInstance,
            dimensionSet,
            legendItemCollection,
            dimensionConfigData.getDistinctValues());
      } else if (dimensionConfig.isNumerical() || dimensionConfig.isDate()) {
        createDimensionTitleLegendItem(plotInstance, dimensionSet, legendItemCollection);

        // create one continuous legend item
        double minValue = dimensionConfigData.getMinValue();
        double maxValue = dimensionConfigData.getMaxValue();

        LegendItem legendItem =
            createContinuousLegendItem(
                plotInstance,
                dimensionSet,
                minValue,
                maxValue,
                dimensionConfig.isDate() ? dimensionConfig.getDateFormat() : null);
        if (legendItem != null) {
          legendItemCollection.add(legendItem);
        }
      } else {
        throw new RuntimeException(
            "unknown data type during legend creation - this should not happen");
      }
    } else {
      // dimension config not grouping --> create legend item only, if there exists
      // at least one non-aggregated value source (otherwise the dimension config is
      // not used at all in the plot and thus we also don't need a legend item for it).
      boolean createLegend = false;
      for (ValueSource valueSource : plotConfiguration.getAllValueSources()) {
        if (!valueSource.isUsingDomainGrouping()) {
          createLegend = true;
          break;
        }
      }
      if (createLegend) {
        // create legend based on the attribute values on the dimension config
        if (dimensionConfig.isNominal()) {
          // create one legend item for each nominal value
          List<Double> values = dimensionConfigData.getDistinctValues();
          createCategoricalLegendItems(plotInstance, dimensionSet, legendItemCollection, values);
        } else if (dimensionConfig.isNumerical() || dimensionConfig.isDate()) {
          createDimensionTitleLegendItem(plotInstance, dimensionSet, legendItemCollection);

          // create one continuous legend item for the value range
          double minValue = dimensionConfigData.getMinValue();
          double maxValue = dimensionConfigData.getMaxValue();

          LegendItem legendItem =
              createContinuousLegendItem(
                  plotInstance,
                  dimensionSet,
                  minValue,
                  maxValue,
                  dimensionConfig.isDate() ? dimensionConfig.getDateFormat() : null);
          if (legendItem != null) {
            legendItemCollection.add(legendItem);
          }
        } else {
          throw new RuntimeException(
              "unknown data type during legend creation - this should not happen");
        }
      }
    }
  }
  public static CategoryDataset createDefaultCategoryDataset(
      ValueSource valueSource,
      PlotInstance plotInstance,
      boolean fillWithZero,
      boolean allowValuesLessThanZero)
      throws ChartPlottimeException {
    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    assertMaxValueCountNotExceededOrThrowException(valueSourceData);
    GroupCellSeriesData dataForAllGroupCells = valueSourceData.getSeriesDataForAllGroupCells();
    DefaultDimensionConfig domainConfig = valueSource.getDomainConfig();
    DimensionConfigData domainConfigData =
        plotInstance.getPlotData().getDimensionConfigData(domainConfig);
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (GroupCellKeyAndData groupCellKeyAndData : dataForAllGroupCells) {

      GroupCellKey groupCellKey = groupCellKeyAndData.getKey();
      GroupCellData groupCellData = groupCellKeyAndData.getData();

      // create series name
      GroupCellKey groupCellKeyClone = (GroupCellKey) groupCellKey.clone();
      String seriesName =
          generateSeriesName(
              valueSource, groupCellKeyClone, plotInstance.getCurrentPlotConfigurationClone());

      Map<PlotDimension, double[]> dataForUsageType =
          groupCellData.getDataForUsageType(SeriesUsageType.MAIN_SERIES);
      double[] xValues = dataForUsageType.get(PlotDimension.DOMAIN);
      double[] yValues = dataForUsageType.get(PlotDimension.VALUE);

      int rowCount = xValues.length;
      for (int row = 0; row < rowCount; ++row) {
        double xValue = xValues[row];

        String xString = null;
        xString = domainConfigData.getStringForValue(xValue);
        Double y = yValues[row];
        if (!allowValuesLessThanZero && y < 0) {
          throw new ChartPlottimeException("illegal_zero_value", valueSource.toString());
        }

        if (xString != null) {
          dataset.addValue(y, seriesName, xString);
        }
      }
      if (fillWithZero) {
        for (int row = 0; row < rowCount; ++row) {
          double xValue = xValues[row];

          String xString = null;
          xString = domainConfigData.getStringForValue(xValue);
          Number value = dataset.getValue(seriesName, xString);
          if (value == null || Double.isNaN(value.doubleValue())) {
            dataset.addValue(0, seriesName, xString);
          }
        }
      }
    }

    return dataset;
  }
  /**
   * Creates a dataset which supports custom intervals on both axes.
   *
   * <p>Expects a grouping on the domain axis.
   *
   * @throws ChartPlottimeException
   */
  public static DefaultIntervalXYDataset createDefaultIntervalXYDataset(
      ValueSource valueSource, PlotInstance plotInstance, boolean createRangeIntervals)
      throws ChartPlottimeException {
    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    assertMaxValueCountNotExceededOrThrowException(valueSourceData);

    GroupCellSeriesData dataForAllGroupCells = valueSourceData.getSeriesDataForAllGroupCells();

    DefaultIntervalXYDataset intervalDataset = new DefaultIntervalXYDataset();

    DefaultDimensionConfig domainConfig = valueSource.getDomainConfig();
    DimensionConfigData domainConfigData =
        plotInstance.getPlotData().getDimensionConfigData(domainConfig);

    // Loop all group cells and add data to dataset
    for (GroupCellKeyAndData groupCellKeyAndData : dataForAllGroupCells) {

      GroupCellKey groupCellKey = groupCellKeyAndData.getKey();
      GroupCellData groupCellData = groupCellKeyAndData.getData();

      // create series name
      GroupCellKey groupCellKeyClone = (GroupCellKey) groupCellKey.clone();
      groupCellKeyClone.removeRangeForDimension(
          PlotDimension.DOMAIN); // legend does not need X-group
      String seriesName =
          generateSeriesName(
              valueSource, groupCellKeyClone, plotInstance.getCurrentPlotConfigurationClone());

      List<ValueRange> domainValueGroups = domainConfigData.getGroupingModel();

      // Loop all rows and add data to series.
      // Remember that by definition one row in the groupCellData corresponds
      // to one group in xValueGroups (if the x-axis is grouped, which should
      // always be the case in this function).
      final int domainValueIdx = 0;
      final int domainLowerIdx = 1;
      final int domainUpperIdx = 2;
      final int rangeValueIdx = 3;
      final int rangeLowerIdx = 4;
      final int rangeUpperIdx = 5;
      Map<PlotDimension, double[]> dataForMainSeries =
          groupCellData.getDataForUsageType(SeriesUsageType.MAIN_SERIES);

      int rowCount = dataForMainSeries.get(PlotDimension.DOMAIN).length;
      double[] domainValues = dataForMainSeries.get(PlotDimension.DOMAIN);
      double[] rangeValues = dataForMainSeries.get(PlotDimension.VALUE);
      double[] upperErrorValues = null;
      double[] lowerErrorValues = null;

      upperErrorValues = valueSourceData.getAbsoluteUtilityValues(groupCellKeyAndData, true);
      lowerErrorValues = valueSourceData.getAbsoluteUtilityValues(groupCellKeyAndData, false);
      if (createRangeIntervals && upperErrorValues == null) {
        throw new ChartPlottimeException(
            "undefined_series", valueSource.toString(), SeriesUsageType.INDICATOR_1);
      }

      double[][] series = new double[6][rowCount];
      Iterator<ValueRange> domainGroupIterator = null;
      if (domainValueGroups != null) {
        domainGroupIterator = domainValueGroups.iterator();
      }

      double domainLower;
      double domainUpper;
      double domainValue;
      double rangeValue;
      double rangeUpper;
      double rangeLower;
      for (int row = 0; row < rowCount; ++row) {
        domainValue = domainValues[row];
        domainLower = domainValue;
        domainUpper = domainValue;
        if (domainGroupIterator != null) {
          ValueRange currentDomainGroup = domainGroupIterator.next();
          if (currentDomainGroup.definesUpperLowerBound()) {
            domainLower = currentDomainGroup.getLowerBound();
            domainUpper = currentDomainGroup.getUpperBound();
          }
        }
        rangeValue = rangeValues[row];
        rangeUpper = upperErrorValues != null ? upperErrorValues[row] : Double.NaN;
        rangeLower = lowerErrorValues != null ? lowerErrorValues[row] : Double.NaN;

        series[domainValueIdx][row] = domainValue;
        series[domainLowerIdx][row] = domainLower;
        series[domainUpperIdx][row] = domainUpper;
        series[rangeValueIdx][row] = rangeValue;
        series[rangeLowerIdx][row] = rangeLower;
        series[rangeUpperIdx][row] = rangeUpper;
      }

      intervalDataset.addSeries(seriesName, series);
    }
    return intervalDataset;
  }
예제 #19
0
  public PlotData(PlotInstance plotInstance, DataTable dataTable) {
    if (plotInstance == null) {
      throw new IllegalArgumentException("null not allowed for plotInstance");
    }
    this.plotInstance = plotInstance;
    plotInstance.setPlotData(this);
    PlotConfiguration plotConfiguration = plotInstance.getMasterPlotConfiguration();
    //		if (plotConfiguration.getPrioritizedListenerCount() > 0) {
    //			plotConfiguration.clearPrioritizedListeners();
    //		}
    plotConfiguration.addPlotConfigurationListener(this, true);

    this.originalDataTable = dataTable;
    originalDataTable.addDataTableListener(this, true);

    valueMappingDataTable = new ValueMappingDataTableView(originalDataTable);
    for (int i = 0; i < valueMappingDataTable.getColumnNumber(); ++i) {
      if (valueMappingDataTable.isNominal(i)) {
        valueMappingDataTable.setMappingProvider(
            i, new NominalSortingDataTableMapping(valueMappingDataTable, i, true));
      }
    }

    // add filtered data table view to view stack
    filteredDataTableView = new FilteredDataTable(valueMappingDataTable);

    // add sorted data table view on view stack (without sort provider for now)
    sortedDataTableView = new SortedDataTableView(filteredDataTableView, null);
    sortedDataTableView.addDataTableListener(this, true);

    // init valueSourceDataMap
    for (ValueSource valueSource : plotConfiguration.getAllValueSources()) {
      ValueSourceData valueSourceData = new ValueSourceData(valueSource, plotInstance);
      valueSourceDataMap.put(valueSource.getId(), valueSourceData);
    }

    // init dimensionConfigDataMap
    for (DefaultDimensionConfig dimensionConfig :
        plotConfiguration.getDefaultDimensionConfigs().values()) {
      DimensionConfigData dimensionConfigData =
          new DimensionConfigData(plotInstance, dimensionConfig);
      dimensionConfigDataMap.put(dimensionConfig.getId(), dimensionConfigData);
    }
    DefaultDimensionConfig domainConfig;
    domainConfig = plotConfiguration.getDomainConfigManager().getDomainConfig(true);
    dimensionConfigDataMap.put(
        domainConfig.getId(), new DimensionConfigData(plotInstance, domainConfig));
    domainConfig = plotConfiguration.getDomainConfigManager().getDomainConfig(false);
    dimensionConfigDataMap.put(
        domainConfig.getId(), new DimensionConfigData(plotInstance, domainConfig));

    // init DomainConfigManagerData
    domainConfigManagerData = new DomainConfigManagerData(plotInstance);

    // init RangeAxisDataMap
    for (RangeAxisConfig rangeAxisConfig : plotConfiguration.getRangeAxisConfigs()) {
      RangeAxisData rangeAxisData = new RangeAxisData(rangeAxisConfig, plotInstance);
      rangeAxisDataMap.put(rangeAxisConfig.getId(), rangeAxisData);
    }

    clearCache();
  }
예제 #20
0
  private void rangeAxisConfigChanged(RangeAxisConfigChangeEvent rangeAxisConfigChange) {

    PlotConfiguration currentPlotConfig =
        plotInstance.getCurrentPlotConfigurationClone(); // get current plot config
    int id = rangeAxisConfigChange.getSource().getId(); // fetch id
    RangeAxisConfig currentRangeAxisConfig =
        currentPlotConfig.getRangeAxisConfigById(id); // look up range axis config

    if (currentRangeAxisConfig == null) {
      // if current range axis config is null it has been deleted afterwards in a meta change event
      debug(
          "#### CAUTION #### RANGE AXIS CONFIG CHANGE: current range axis config "
              + rangeAxisConfigChange.getSource().getLabel()
              + " with id "
              + rangeAxisConfigChange.getSource().getId()
              + " is null! Meta change event?");
      return;
    }

    // inform range axis data
    RangeAxisData rangeAxisData = getRangeAxisData(currentRangeAxisConfig);
    rangeAxisData.rangeAxisConfigChanged(rangeAxisConfigChange);

    // and also process event here
    ValueSource changeValueSource = rangeAxisConfigChange.getValueSource();
    ValueSource currentValueSource = null;
    if (changeValueSource != null) {
      id = changeValueSource.getId(); // fetch id from value source add/remove event
      currentValueSource =
          currentRangeAxisConfig.getValueSourceById(id); // look up current value source
    }
    //		else {
    //			return; // nothing to be done
    //		}

    switch (rangeAxisConfigChange.getType()) {
      case VALUE_SOURCE_ADDED:
        if (currentValueSource != null) {
          debug(
              "value source ADDED - "
                  + currentValueSource.getLabel()
                  + " ## ID: "
                  + currentValueSource.getId());
          valueSourceDataMap.put(
              currentValueSource.getId(), new ValueSourceData(currentValueSource, plotInstance));
          clearCache();
        } else {
          // if current value source is null it has been deleted afterwards in a meta change event
          debug(
              "#### CAUTION #### VALUE SOURCE ADDED: current value source"
                  + changeValueSource.getLabel()
                  + " with id "
                  + changeValueSource.getId()
                  + " is null! Meta change event?");
          return; // nothing to be done
        }
        break;
      case VALUE_SOURCE_CHANGED:
        ValueSourceChangeEvent valueSourceChange = rangeAxisConfigChange.getValueSourceChange();
        changeValueSource = valueSourceChange.getSource(); // get source
        id = changeValueSource.getId(); // fetch id from changed value source
        currentValueSource =
            currentRangeAxisConfig.getValueSourceById(id); // look up current value source

        if (currentValueSource != null) {
          debug("value source CHANGED - " + currentValueSource.getLabel() + " ## ID: " + id);
          getValueSourceData(currentValueSource)
              .valueSourceChanged(valueSourceChange, currentValueSource);
        } else {
          // if current value source is null it has been deleted afterwards in a meta change event
          debug(
              "#### CAUTION #### VALUE SOURCE CHANGED: current value source"
                  + changeValueSource.getLabel()
                  + " with id "
                  + changeValueSource.getId()
                  + " is null! Meta change event?");
          return; // nothing to be done
        }
        break;
      case VALUE_SOURCE_REMOVED:
        debug(
            "value source REMOVED - "
                + changeValueSource.getLabel()
                + " ## ID: "
                + changeValueSource.getId());
        valueSourceDataMap.remove(changeValueSource.getId());
        clearCache();
        break;
    }
  }
예제 #21
0
  @Override
  public synchronized boolean plotConfigurationChanged(PlotConfigurationChangeEvent change) {
    if (change == null || change == lastProcessedEvent) {
      return true;
    }
    lastProcessedEvent = change;

    PlotConfiguration currentPlotConfig =
        plotInstance.getCurrentPlotConfigurationClone(); // get current plot config

    // prepare temp variables
    int id = -1;
    DimensionConfig currentDimensionConfig = null;
    RangeAxisConfig currentRangeAxis = null;

    DimensionConfig changeDimensionConfig = change.getDimensionConfig();
    if (changeDimensionConfig != null) {
      // if event is a dimension config add/remove event, get current dimension config
      // (may be null if meta event is processed and it has been deleted afterwards)
      id = changeDimensionConfig.getId();
      currentDimensionConfig = currentPlotConfig.getDefaultDimensionConfigById(id);
    }

    RangeAxisConfig changeRangeAxis = change.getRangeAxisConfig();
    if (changeRangeAxis != null) {
      // if event is a range axis config add/remove event, get current range axis config
      // (may be null if meta event is processed and it has been deleted afterwards)
      id = changeRangeAxis.getId();
      currentRangeAxis = currentPlotConfig.getRangeAxisConfigById(id);
    }

    switch (change.getType()) {
      case TRIGGER_REPLOT:
        clearCache();
        break;
      case AXES_FONT:
        break;
      case AXIS_LINE_COLOR:
        break;
      case AXIS_LINE_WIDTH:
        break;
      case FRAME_BACKGROUND_COLOR:
        break;
      case CHART_TITLE:
        break;
      case COLOR_SCHEME:
        break;
      case DATA_TABLE_EXCHANGED:
        break;
      case DIMENSION_CONFIG_ADDED:
        // if current plot configuration still contains item..
        if (currentDimensionConfig != null && id != -1) {
          // add new dimension config data to map
          dimensionConfigDataMap.put(
              id,
              new DimensionConfigData(
                  plotInstance, (DefaultDimensionConfig) currentDimensionConfig));
          debug(
              "ADDED dimension "
                  + currentDimensionConfig.getDimension().getName()
                  + " ## ID: "
                  + id);
          clearCache();
        } else {
          debug(
              "#### CAUTION ###### ADD DIMENSION CONFIG: CURRENT DIMENSIONCONFIG "
                  + changeDimensionConfig.getLabel()
                  + " with id "
                  + changeDimensionConfig.getId()
                  + " IS NULL! Processing meta event?");
        }
        break;
      case DIMENSION_CONFIG_CHANGED:
        dimensionConfigChanged(change.getDimensionChange());
        break;
      case DIMENSION_CONFIG_REMOVED:
        debug(
            "REMOVED dimension "
                + changeDimensionConfig.getDimension().getName()
                + " ## ID: "
                + changeDimensionConfig.getId());
        dimensionConfigDataMap.remove(
            changeDimensionConfig.getId()); // remove dimension config data from map
        clearCache();
        break;
      case LEGEND_CHANGED:
        break;
      case PLOT_BACKGROUND_COLOR:
        break;
      case PLOT_ORIENTATION:
        break;
      case RANGE_AXIS_CONFIG_ADDED:
        // if current plot configuration still contains item..
        if (currentRangeAxis != null && id != -1) {
          // add new range axis data to map
          debug("range axis ADDED - " + currentRangeAxis.getLabel() + " ## ID: " + id);
          rangeAxisDataMap.put(id, new RangeAxisData(currentRangeAxis, plotInstance));
          for (ValueSource valueSource :
              currentRangeAxis.getValueSources()) { // also add containing value sources data to map
            debug(
                "value source ADDED - "
                    + valueSource.getLabel()
                    + " ## ID: "
                    + valueSource.getId());
            valueSourceDataMap.put(
                valueSource.getId(), new ValueSourceData(valueSource, plotInstance));
          }
        } else {
          debug(
              "#### CAUTION ###### ADD RANGE AXIS CONFIG: CURRENT RANGEAXISCONFIG "
                  + changeRangeAxis.getLabel()
                  + " with id "
                  + changeRangeAxis.getId()
                  + " IS NULL! Processing meta event?");
        }
        break;
      case RANGE_AXIS_CONFIG_CHANGED:
        RangeAxisConfigChangeEvent rangeAxisConfigChange = change.getRangeAxisConfigChange();
        debug(
            "range axis CHANGED - "
                + rangeAxisConfigChange.getSource().getLabel()
                + " ## ID: "
                + rangeAxisConfigChange.getSource().getId());
        rangeAxisConfigChanged(rangeAxisConfigChange);
        break;
      case RANGE_AXIS_CONFIG_MOVED:
        break;
      case RANGE_AXIS_CONFIG_REMOVED:
        RangeAxisConfig rangeAxis = change.getRangeAxisConfig();
        debug("range axis REMOVED - " + rangeAxis.getLabel() + " ## ID: " + rangeAxis.getId());
        rangeAxisDataMap.remove(rangeAxis.getId()); // remove range axis config from map
        for (ValueSource valueSource :
            rangeAxis.getValueSources()) { // also remove all containing value sources from data map
          valueSourceDataMap.remove(valueSource.getId());
        }
        clearCache();
        break;
      case LINK_AND_BRUSH_SELECTION:
        break;
      case META_CHANGE:
        for (PlotConfigurationChangeEvent e : change.getPlotConfigChangeEvents()) {
          plotConfigurationChanged(e);
        }
        break;
    }

    return true;
  }
  private CustomLegendItem createValueSourceLegendItem(
      PlotConfiguration plotConfig, ValueSource valueSource) {

    Set<PlotDimension> dimensions = new HashSet<PlotDimension>();
    for (PlotDimension dimension : PlotDimension.values()) {
      switch (dimension) {
        case DOMAIN:
        case VALUE:
          break;
        default:
          if (valueSource.useSeriesFormatForDimension(plotConfig, dimension)) {
            dimensions.add(dimension);
          }
      }
    }
    if (dimensions.isEmpty()) {
      return null;
    }

    SeriesFormat format = valueSource.getSeriesFormat();
    String description = "";
    String toolTipText = "";
    String urlText = "";
    boolean shapeVisible = true;
    Shape shape;
    boolean shapeFilled = true;
    Paint fillPaint = UNDEFINED_COLOR_PAINT;
    boolean shapeOutlineVisible = true;
    Paint outlinePaint = PlotConfiguration.DEFAULT_OUTLINE_COLOR;
    Stroke outlineStroke = DEFAULT_OUTLINE_STROKE;
    boolean lineVisible =
        format.getLineStyle() != LineStyle.NONE
            && format.getSeriesType() == SeriesFormat.VisualizationType.LINES_AND_SHAPES;

    // configure fill paint and line paint
    Paint linePaint;
    String label = valueSource.toString();
    if (label == null) {
      label = "";
    }
    if (dimensions.contains(PlotDimension.COLOR)) {
      Color color = format.getItemColor();
      fillPaint = format.getAreaFillPaint(color);
      linePaint = fillPaint;
    } else {
      if (format.getAreaFillStyle() == FillStyle.NONE) {
        fillPaint = new Color(0, 0, 0, 0);
        linePaint = fillPaint;
      } else if (format.getAreaFillStyle() == FillStyle.SOLID) {
        fillPaint = UNDEFINED_COLOR_PAINT;
        linePaint = UNDEFINED_LINE_COLOR;
      } else {
        fillPaint = format.getAreaFillPaint(UNDEFINED_COLOR);
        linePaint = fillPaint;
      }
    }

    VisualizationType seriesType = valueSource.getSeriesFormat().getSeriesType();
    if (seriesType == VisualizationType.LINES_AND_SHAPES) {
      if (dimensions.contains(PlotDimension.SHAPE)) {
        shape = format.getItemShape().getShape();
      } else if (dimensions.contains(PlotDimension.COLOR)) {
        shape = UNDEFINED_SHAPE;
      } else {
        shape = UNDEFINED_SHAPE_AND_COLOR;
      }

      if (dimensions.contains(PlotDimension.SIZE)) {
        AffineTransform transformation = new AffineTransform();
        double scalingFactor = format.getItemSize();
        transformation.scale(scalingFactor, scalingFactor);
        shape = transformation.createTransformedShape(shape);
      }
    } else if (seriesType == VisualizationType.BARS) {
      shape = BAR_SHAPE;
    } else if (seriesType == VisualizationType.AREA) {
      shape = AREA_SHAPE;
    } else {
      throw new RuntimeException("Unknown SeriesType. This should not happen.");
    }

    // configure line shape
    float lineLength = 0;
    if (lineVisible) {
      lineLength = format.getLineWidth();
      if (lineLength < 1) {
        lineLength = 1;
      }
      if (lineLength > 1) {
        lineLength = 1 + (float) Math.log(lineLength) / 2;
      }

      // line at least 30 pixels long, and show at least 2 iterations of stroke
      lineLength = Math.max(lineLength * 30, format.getStrokeLength() * 2);

      // line at least 2x longer than shape width
      if (shape != null) {
        lineLength = Math.max(lineLength, (float) shape.getBounds().getWidth() * 2f);
      }
    }

    // now create line shape and stroke
    Shape line = new Line2D.Float(0, 0, lineLength, 0);
    BasicStroke lineStroke = format.getStroke();
    if (lineStroke == null) {
      lineStroke = new BasicStroke();
    }

    // unset line ending decoration to prevent drawing errors in legend
    {
      BasicStroke s = lineStroke;
      lineStroke =
          new BasicStroke(
              s.getLineWidth(),
              BasicStroke.CAP_BUTT,
              BasicStroke.JOIN_ROUND,
              s.getMiterLimit(),
              s.getDashArray(),
              s.getDashPhase());
    }

    return new CustomLegendItem(
        label,
        description,
        toolTipText,
        urlText,
        shapeVisible,
        shape,
        shapeFilled,
        fillPaint,
        shapeOutlineVisible,
        outlinePaint,
        outlineStroke,
        lineVisible,
        line,
        lineStroke,
        linePaint);
  }
예제 #23
0
  @Override
  protected void updatePlotConfiguration() {
    // don't do anything if updates are suspended due to batch updating
    if (suspendUpdates) {
      return;
    }

    PlotConfiguration plotConfiguration = plotInstance.getMasterPlotConfiguration();

    // value when "None" is selected
    String noSelection =
        I18N.getMessage(I18N.getGUIBundle(), "gui.plotter.column.empty_selection.label");

    // stop event processing
    boolean plotConfigurationProcessedEvents = plotConfiguration.isProcessingEvents();
    plotConfiguration.setProcessEvents(false);

    // restore crosshairs
    List<AxisParallelLineConfiguration> clonedListOfDomainLines =
        new LinkedList<AxisParallelLineConfiguration>(listOfDomainLines);
    for (AxisParallelLineConfiguration lineConfig : clonedListOfDomainLines) {
      plotConfiguration.getDomainConfigManager().getCrosshairLines().addLine(lineConfig);
    }

    // x axis column selection
    if (!xAxisColumn.equals(noSelection)) {
      plotConfiguration
          .getDimensionConfig(PlotDimension.DOMAIN)
          .setDataTableColumn(
              new DataTableColumn(currentDataTable, currentDataTable.getColumnIndex(xAxisColumn)));
      plotConfiguration.getDimensionConfig(PlotDimension.DOMAIN).setLogarithmic(xAxisLogarithmic);
    } else {
      // remove config
      if (currentRangeAxisConfig != null) {
        currentRangeAxisConfig.removeRangeAxisConfigListener(rangeAxisConfigListener);
        plotConfiguration.removeRangeAxisConfig(currentRangeAxisConfig);
        currentRangeAxisConfig = null;
      }
      plotConfiguration.setProcessEvents(plotConfigurationProcessedEvents);
      return;
    }

    // y axis column selection
    if (!yAxisColumn.equals(noSelection)) {
      RangeAxisConfig newRangeAxisConfig = new RangeAxisConfig(yAxisColumn, plotConfiguration);
      newRangeAxisConfig.addRangeAxisConfigListener(rangeAxisConfigListener);
      ValueSource valueSource;
      valueSource =
          new ValueSource(
              plotConfiguration,
              new DataTableColumn(currentDataTable, currentDataTable.getColumnIndex(yAxisColumn)),
              AggregationFunctionType.count,
              false);
      SeriesFormat sFormat = new SeriesFormat();
      valueSource.setSeriesFormat(sFormat);
      newRangeAxisConfig.addValueSource(valueSource, null);
      newRangeAxisConfig.setLogarithmicAxis(yAxisLogarithmic);

      // remove old config
      if (currentRangeAxisConfig != null) {
        currentRangeAxisConfig.removeRangeAxisConfigListener(rangeAxisConfigListener);
        plotConfiguration.removeRangeAxisConfig(currentRangeAxisConfig);
      }
      currentRangeAxisConfig = newRangeAxisConfig;
      // add new config and restore crosshairs
      List<AxisParallelLineConfiguration> clonedRangeAxisLineList =
          rangeAxisCrosshairLinesMap.get(newRangeAxisConfig.getLabel());
      if (clonedRangeAxisLineList != null) {
        for (AxisParallelLineConfiguration lineConfig : clonedRangeAxisLineList) {
          newRangeAxisConfig.getCrossHairLines().addLine(lineConfig);
        }
      }
      plotConfiguration.addRangeAxisConfig(newRangeAxisConfig);
      // remember the new config so we can remove it later again
    } else {
      // remove config
      if (currentRangeAxisConfig != null) {
        currentRangeAxisConfig.removeRangeAxisConfigListener(rangeAxisConfigListener);
        plotConfiguration.removeRangeAxisConfig(currentRangeAxisConfig);
        currentRangeAxisConfig = null;
      }
    }

    // color column selection
    if (!colorColumn.equals(noSelection)) {
      plotConfiguration.setDimensionConfig(PlotDimension.COLOR, null);
      DefaultDimensionConfig dimConfig =
          new DefaultDimensionConfig(
              plotConfiguration,
              new DataTableColumn(currentDataTable, currentDataTable.getColumnIndex(colorColumn)),
              PlotDimension.COLOR);
      dimConfig.setLogarithmic(colorLogarithmic);
      plotConfiguration.setDimensionConfig(PlotDimension.COLOR, dimConfig);
    } else {
      plotConfiguration.setDimensionConfig(PlotDimension.COLOR, null);
    }

    // general settings
    plotConfiguration.setAxesFont(styleProvider.getAxesFont());
    plotConfiguration.setTitleFont(styleProvider.getTitleFont());
    plotConfiguration.getLegendConfiguration().setLegendFont(styleProvider.getLegendFont());
    plotConfiguration.addColorSchemeAndSetActive(styleProvider.getColorScheme());
    if (styleProvider.isShowLegend()) {
      plotConfiguration.getLegendConfiguration().setLegendPosition(LegendPosition.BOTTOM);
    } else {
      plotConfiguration.getLegendConfiguration().setLegendPosition(LegendPosition.NONE);
    }
    plotConfiguration.setFrameBackgroundColor(
        ColorRGB.convertToColor(styleProvider.getFrameBackgroundColor()));
    plotConfiguration.setPlotBackgroundColor(
        ColorRGB.convertToColor(styleProvider.getPlotBackgroundColor()));
    plotConfiguration.setTitleText(styleProvider.getTitleText());

    // continue event processing
    plotConfiguration.setProcessEvents(plotConfigurationProcessedEvents);
  }