### Eclipse Workspace Patch 1.0 #P org.eclipse.ohf.stem.ui.reports Index: src/org/eclipse/ohf/stem/ui/reports/views/RelativeValueHistoryPlotter.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.ohf/plugins/org.eclipse.ohf.stem.ui.reports/src/org/eclipse/ohf/stem/ui/reports/views/RelativeValueHistoryPlotter.java,v retrieving revision 1.3 diff -u -r1.3 RelativeValueHistoryPlotter.java --- src/org/eclipse/ohf/stem/ui/reports/views/RelativeValueHistoryPlotter.java 27 Sep 2007 21:39:36 -0000 1.3 +++ src/org/eclipse/ohf/stem/ui/reports/views/RelativeValueHistoryPlotter.java 12 Oct 2007 17:36:33 -0000 @@ -16,20 +16,28 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; import org.eclipse.ohf.stem.core.common.Identifiable; import org.eclipse.ohf.stem.core.graph.DynamicLabel; import org.eclipse.ohf.stem.core.graph.DynamicNodeLabel; +import org.eclipse.ohf.stem.core.graph.Graph; import org.eclipse.ohf.stem.core.graph.Node; import org.eclipse.ohf.stem.core.graph.NodeLabel; import org.eclipse.ohf.stem.core.model.Decorator; +import org.eclipse.ohf.stem.definitions.adapters.relativevalue.RelativeValueProvider; +import org.eclipse.ohf.stem.definitions.adapters.relativevalue.RelativeValueProviderAdapter; +import org.eclipse.ohf.stem.definitions.adapters.relativevalue.RelativeValueProviderAdapterFactory; import org.eclipse.ohf.stem.definitions.adapters.relativevalue.history.RelativeValueHistoryExtendedListener; import org.eclipse.ohf.stem.definitions.adapters.relativevalue.history.RelativeValueHistoryProvider; import org.eclipse.ohf.stem.definitions.adapters.relativevalue.history.RelativeValueHistoryProviderAdapter; import org.eclipse.ohf.stem.definitions.adapters.relativevalue.history.RelativeValueHistoryProviderAdapterFactory; +import org.eclipse.ohf.stem.jobs.simulation.Simulation; +import org.eclipse.ohf.stem.ui.preferences.VisualizationPreferencePage; import org.eclipse.ohf.stem.ui.widgets.PropertySelector; import org.eclipse.ohf.stem.ui.widgets.PropertySelector.PropertySelectionEvent; +import org.eclipse.ohf.stem.ui.widgets.PropertySelector.PropertySieve; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; @@ -54,9 +62,51 @@ private DynamicLabel selectedDynamicLabel; - ItemPropertyDescriptor selectedProperty; + List selectedProperties; private Map decoratorToLabelMap; + + /** + * This interface is implemented by classes that select out the properties + * to be displayed. + */ + public interface PropertySieve { + /** + * @param dynamicLabel + * the label that contains the candidate properties to be + * displayed. + * @return a List of the properties that should be + * displayed in the order that they should be displayed. + */ + List sieve(final DynamicLabel dynamicLabel); + } // PropertySieve + + + /** + * This sieve selects all of those properties that have relative values. + */ + private PropertySieve propertySieve = new PropertySieve() { + /** + * @see org.eclipse.ohf.stem.ui.widgets.PropertySelector.PropertySieve#sieve(org.eclipse.ohf.stem.core.graph.DynamicLabel) + */ + public List sieve(DynamicLabel dynamicLabel) { + final List retValue = new ArrayList(); + final RelativeValueProviderAdapter rvp = (RelativeValueProviderAdapter) RelativeValueProviderAdapterFactory.INSTANCE + .adapt(dynamicLabel, RelativeValueProvider.class); + + // Does the label have relative values? + if (rvp != null) { + // Yes + rvp.setTarget(dynamicLabel); + + for (final Object element : rvp.getProperties()) { + final ItemPropertyDescriptor property = (ItemPropertyDescriptor) element; + retValue.add(property); + } // for each property + } // if the label has relative values + return retValue; + } // sieve + }; /** * @param parent @@ -107,8 +157,8 @@ final PropertySelectionEvent propertySelectionEvent) { selectedDecorator = propertySelectionEvent .getDecorator(); - selectedProperty = propertySelectionEvent.getProperty(); - + + selectedProperties = getPropertiesToDisplay(selectedDecorator); selectedDynamicLabel = decoratorToLabelMap .get(selectedDecorator); switchToRVHP((RelativeValueHistoryProviderAdapter) RelativeValueHistoryProviderAdapterFactory.INSTANCE @@ -155,6 +205,9 @@ } // if Node propertySelector.setDecorators(decorators); } // setIdentifiable + + + private void switchToRVHP(RelativeValueHistoryProviderAdapter rvhp) { // Is there an existing RVHP to stop listening to? @@ -187,7 +240,7 @@ display.asyncExec(new Runnable() { public void run() { chartCanvas.setDataSourceAndRedraw(rvhp, - selectedProperty); + selectedProperties); } // run }); // display.asyncExec } // try @@ -200,6 +253,34 @@ }// relativeValueHistoryExtended /** + * @param decorator + * a {@link Decorator} that modifies the state of the canonical + * {@link Graph} in the {@link Simulation}. + * @param simulation + * the {@link Simulation} + * @return a {@link List} of the properties of the {@link Decorator} that + * can should be displayed. + */ + List getPropertiesToDisplay( + final Decorator decorator) { + final List retValue = new ArrayList(); + // Got Decorator? + if (decorator != null) { + // Yes + // Are there any labels to update? + if (!decorator.getLabelsToUpdate().isEmpty()) { + // Yes + // The first one is good enough + retValue.addAll(propertySieve.sieve(decorator + .getLabelsToUpdate().get(0))); + } // if labels to update + } // if got decorator + return retValue; + } // getPropertiesToDisplay + + + + /** * @see org.eclipse.swt.widgets.Widget#dispose() */ @Override Index: src/org/eclipse/ohf/stem/ui/reports/views/ChartCanvas.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.ohf/plugins/org.eclipse.ohf.stem.ui.reports/src/org/eclipse/ohf/stem/ui/reports/views/ChartCanvas.java,v retrieving revision 1.9 diff -u -r1.9 ChartCanvas.java --- src/org/eclipse/ohf/stem/ui/reports/views/ChartCanvas.java 14 Sep 2007 22:19:49 -0000 1.9 +++ src/org/eclipse/ohf/stem/ui/reports/views/ChartCanvas.java 12 Oct 2007 17:36:33 -0000 @@ -11,8 +11,11 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ +import java.awt.Color; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Set; import org.eclipse.birt.chart.device.IDeviceRenderer; import org.eclipse.birt.chart.exception.ChartException; @@ -22,6 +25,7 @@ import org.eclipse.birt.chart.model.attribute.Anchor; import org.eclipse.birt.chart.model.attribute.AxisType; import org.eclipse.birt.chart.model.attribute.Bounds; +import org.eclipse.birt.chart.model.attribute.ColorDefinition; import org.eclipse.birt.chart.model.attribute.IntersectionType; import org.eclipse.birt.chart.model.attribute.LineAttributes; import org.eclipse.birt.chart.model.attribute.LineStyle; @@ -47,6 +51,7 @@ import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; import org.eclipse.ohf.stem.definitions.adapters.relativevalue.history.RelativeValueHistoryProvider; import org.eclipse.ohf.stem.definitions.adapters.relativevalue.history.RelativeValueHistoryProviderAdapter; +import org.eclipse.ohf.stem.ui.preferences.VisualizationPreferencePage; import org.eclipse.ohf.stem.ui.reports.Activator; import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; @@ -77,15 +82,17 @@ * This is the property of the label updated by the selected decorator whose * relative value will be plotted */ - private ItemPropertyDescriptor propertyToPlot; + private List propertiesToPlot = new ArrayList(); /** * These are the values that will be plotted * * @see #cycleNumbers */ - private List relativeValues = new ArrayList(); + private List> listedRelativeValues = new ArrayList>(); + // for now we will set a max number lines to display + // private static final int MAX_LINES = 6; /** * These are the cycle numbers that match the relative values that will be * plotted @@ -98,6 +105,9 @@ * Chart generator instance (reference to a singleton) */ Generator gr; + + private List lineSeriesList = new ArrayList(); + Axis yAxisPrimary; /** * Constructor. @@ -118,7 +128,7 @@ } resetData(); - cm = createSimpleLineChart(relativeValues, cycleNumbers, Messages + cm = createSimpleLineChart(listedRelativeValues, cycleNumbers, Messages .getString("CC.title")); //$NON-NLS-1$ addPaintListener(new PaintListener() { @@ -158,26 +168,64 @@ */ public void draw() { // Has a relative value provider been provided? + + int numLines = propertiesToPlot.size(); + int maxLines = lineSeriesList.size(); + + // we may have more lines currently displayed than data + // or we may have more data than we have so far defined lines + // we must process the max of the two + int loopMax = numLines; + if (maxLines > numLines) loopMax = maxLines; + if (rvhp != null) { // Yes + // clear + clearData(); + setColorDefs(propertiesToPlot, lineSeriesList); + boolean setCycles = false; // Get the values for the property to be plotted - final double[] relativeValues = rvhp - .getAllHistoricRelativeValues(propertyToPlot); - // Any values? - if (relativeValues.length > 0) { - // Yes - clearData(); - final int earliestCycleNumber = rvhp.getEarliestCycleNumber(); + int maxPoints = 0; + for (int i = 0; i < loopMax ; i ++) { + // do we have enough line series defined? + if (i >= maxLines) { + List values = new ArrayList(); + //values.add(new Double(0.0)); + listedRelativeValues.add(values); + addLineSeries(values); + maxLines ++; + } + // we should have data + ItemPropertyDescriptor nextProperty = propertiesToPlot.get(i); + final double[] doubleValues = rvhp.getAllHistoricRelativeValues(nextProperty); - for (int cycleNumber = 0; cycleNumber < relativeValues.length; cycleNumber++) { - this.relativeValues.add(new Double(relativeValues[cycleNumber])); - this.cycleNumbers.add(new Integer(earliestCycleNumber +cycleNumber)); - } // for - } // if - else { - resetData(); - } + if (i < numLines) { + // Any values? + if (doubleValues.length > 0) { + if (maxPointsChart */ @SuppressWarnings("deprecation") //$NON-NLS-1$ - public static final Chart createSimpleLineChart( - List relativeValues, List cycleNumbers, + public final Chart createSimpleLineChart( + List> listedRelativeValues, List cycleNumbers, final String seriesIdentifier) { final ChartWithAxes retValue = ChartWithAxesImpl.create(); - + + // for now get ready to create only one line - we have no data yet. + // we will add more lines as we need them + List values = new ArrayList(); + values.add(new Double(0.0)); + listedRelativeValues.add(values); + + // Plot retValue.getBlock().setBackground(ColorDefinitionImpl.WHITE()); final Plot p = retValue.getPlot(); @@ -222,6 +277,7 @@ // cwaLine.getLegend( ).getText().getFont().setSize(16);; // cwaLine.getLegend( ).setVisible( true ); + /////////// // X-Axis final Axis xAxisPrimary = retValue.getPrimaryBaseAxes()[0]; xAxisPrimary.setType(AxisType.TEXT_LITERAL); @@ -229,37 +285,27 @@ xAxisPrimary.getOrigin().setType(IntersectionType.VALUE_LITERAL); xAxisPrimary.getTitle().setVisible(false); - // Y-Axis - final Axis yAxisPrimary = retValue - .getPrimaryOrthogonalAxis(xAxisPrimary); - yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITERAL); - - final NumberDataSet categoryValues = NumberDataSetImpl - .create(cycleNumbers); - final NumberDataSet orthoValues = NumberDataSetImpl - .create(relativeValues); - - // X-Series final Series seCategory = SeriesImpl.create(); + final NumberDataSet categoryValues = NumberDataSetImpl.create(cycleNumbers); seCategory.setDataSet(categoryValues); final SeriesDefinition sdX = SeriesDefinitionImpl.create(); xAxisPrimary.getSeriesDefinitions().add(sdX); sdX.getSeries().add(seCategory); - // Y-Series - final LineSeries ls = (ScatterSeries) ScatterSeriesImpl.create(); - ls.setDataSet(orthoValues); - ls.getLineAttributes().setVisible(true); - ls.getLineAttributes().setColor(ColorDefinitionImpl.BLUE()); - ls.setSeriesIdentifier(seriesIdentifier); - ls.getMarker().setVisible(false); - - final SeriesDefinition sdY = SeriesDefinitionImpl.create(); - sdY.getSeriesPalette().update(-2); - yAxisPrimary.getSeriesDefinitions().add(sdY); - sdY.getSeries().add(ls); + ////////// + // Y-Axis + this.yAxisPrimary = retValue.getPrimaryOrthogonalAxis(xAxisPrimary); + yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITERAL); + //NumberDataSet[] orthoValues = new NumberDataSet[MAX_LINES]; + //SeriesDefinition[] sdY = new SeriesDefinition[MAX_LINES]; + + // add only one line series for now + LineSeries ls = addLineSeries(listedRelativeValues.get(0)) ; + + // end Y-Series + xAxisPrimary.getScale().setMin(NumberDataElementImpl.create(0.0)); // xAxisPrimary.getScale( ).setMax( NumberDataElementImpl.create( 10.0 ) // ); @@ -268,11 +314,30 @@ yAxisPrimary.getScale().setMin(NumberDataElementImpl.create(0.0)); yAxisPrimary.getScale().setMax(NumberDataElementImpl.create(1.0)); - yAxisPrimary.getScale().setStep(0.1); + yAxisPrimary.getScale().setStep(0.25); yAxisPrimary.getLabel().getCaption().getFont().setSize(9); - + return retValue; } // createSimpleLineChart + + public LineSeries addLineSeries(List relativeValues) { + NumberDataSet orthoValues = NumberDataSetImpl.create(relativeValues); + LineSeries ls = (ScatterSeries) ScatterSeriesImpl.create(); + ls.setDataSet(orthoValues); + ls.getLineAttributes().setVisible(true); + ls.getMarker().setVisible(false); + // Assign the line color + // based on selected property. Default is Blue + setColorDefs(propertiesToPlot, lineSeriesList); + ls.getMarker().setVisible(false); + lineSeriesList.add(ls); + // the series def + SeriesDefinition sdY= SeriesDefinitionImpl.create(); + sdY.getSeriesPalette().update(-2); + sdY.getSeries().add(ls); + yAxisPrimary.getSeriesDefinitions().add(sdY); + return ls; + } /** * @param rvhp @@ -280,11 +345,32 @@ */ public void setDataSourceAndRedraw( final RelativeValueHistoryProviderAdapter rvhp, - final ItemPropertyDescriptor propertyToPlot) { + final List propertiesToPlot) { this.rvhp = rvhp; - this.propertyToPlot = propertyToPlot; + this.propertiesToPlot= filterPreferredProperties(propertiesToPlot); draw(); } // setDataSourceAndRedraw + + /** + * Filters a list of ItemPropertyDescriptors to show + * preferred properties if at least one exists. If not, just returns + * the entire list. + * @param fullList + * @return filteredList + */ + protected List filterPreferredProperties( List fullList) { + List propertyList = new ArrayList(); + // Are any of the labels in the preference set? + Set prefSet = VisualizationPreferencePage.getPreferenceSet(); + + for (int i = 0; i < fullList.size(); i ++) { + ItemPropertyDescriptor property = fullList.get(i); + if(prefSet.contains(property.getDisplayName(property))) propertyList.add(property); + } + // if we didn't find any in the preferences then just add them all + if(propertyList.size()==0) propertyList.addAll(fullList); + return propertyList; + } /** * Set the provider of relative values. It will be consulted to produce a @@ -302,7 +388,7 @@ * @return the propertyToPlot */ public final ItemPropertyDescriptor getPropertyToPlot() { - return propertyToPlot; + return propertiesToPlot.get(0); } /** @@ -311,10 +397,47 @@ */ public final void setPropertyToPlot( final ItemPropertyDescriptor propertyToPlot) { - this.propertyToPlot = propertyToPlot; + this.propertiesToPlot.set(0, propertyToPlot); } /** + * Sets the colors for a n array of LineSeries + * given the property to Plot for each. + * Try to set color from the preferences + * (if specified for that property) + * otherwise sets line color to blue. + * @param propertyToPlot + */ + public static void setColorDefs(List propertiesToPlot, List lsList) { + // the default line color + + // if possible get color from preferences + Map colorMap = VisualizationPreferencePage.getColorMapping(); + for (int i =0; i < lsList.size(); i ++) { + ColorDefinition color = ColorDefinitionImpl.BLUE(); + + if ((propertiesToPlot!= null)&&(propertiesToPlot.size()>i)) { + String key = propertiesToPlot.get(i).getDisplayName(propertiesToPlot.get(i)); + // look or the preference color by name + if (colorMap.containsKey(key)) { + Color c = colorMap.get(key); + color = ColorDefinitionImpl.create(c.getRed(), c.getGreen(), c.getBlue()); + } + lsList.get(i).setSeriesIdentifier(key); + lsList.get(i).getLineAttributes().setColor(color); + } else { + + if (lsList.get(i)!= null) { + lsList.get(i).setSeriesIdentifier(" "); + lsList.get(i).getLineAttributes().setColor(color); + } + } + } + return; + }// getColorDef + + + /** * Disposes the Color objects */ @Override @@ -333,12 +456,16 @@ private void resetData() { clearData(); - relativeValues.add(new Double(0.0)); + for (int i = 0; i < listedRelativeValues.size(); i ++) { + listedRelativeValues.get(i).add(new Double(0.0)); + } cycleNumbers.add(new Integer(0)); } private void clearData() { - relativeValues.clear(); + for (int i = 0; i < listedRelativeValues.size(); i ++) { + listedRelativeValues.get(i).clear(); + } cycleNumbers.clear(); } } // ChartCanvas