Skip to content

Commit

Permalink
added option to toggle between linear and logarithmic scaling in demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Schwiebert committed Feb 8, 2012
1 parent eabe119 commit 249a26a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,27 @@ private void createSideTab(SashForm form) {
protected Group addLayoutButtons(Composite parent) {
Group buttons = super.addLayoutButtons(parent);


Label l = new Label(buttons, SWT.NONE);
l.setText("Scale");
final Combo scale = new Combo(buttons, SWT.DROP_DOWN | SWT.READ_ONLY);
scale.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
scale.setItems(new String[] {"linear", "logarithmic"});
scale.select(1);
scale.addSelectionListener(new SelectionListener() {

@Override
public void widgetSelected(SelectionEvent e) {
switch(scale.getSelectionIndex()) {
case 0 : labelProvider.setScale(TypeLabelProvider.Scaling.LINEAR); break;
case 1 : labelProvider.setScale(TypeLabelProvider.Scaling.LOGARITHMIC); break;
default: break;
}
}

@Override
public void widgetDefaultSelected(SelectionEvent e) {}
});
l = new Label(buttons, SWT.NONE);
l.setText("X Axis Variation");
final Combo xAxis = new Combo(buttons, SWT.DROP_DOWN | SWT.READ_ONLY);
xAxis.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.zest.cloudio.IEditableCloudLabelProvider;
import org.eclipse.zest.examples.cloudio.application.data.Type;
import org.eclipse.zest.examples.cloudio.application.ui.TypeLabelProvider.Scaling;

/**
*
Expand All @@ -34,12 +35,18 @@ public class TypeLabelProvider extends BaseLabelProvider implements
private double maxOccurrences;
private double minOccurrences;

public enum Scaling {

LINEAR, LOGARITHMIC;
}

private Map<Object, Color> colors = new HashMap<Object, Color>();
private Map<Object, FontData[]> fonts = new HashMap<Object, FontData[]>();
private Random random = new Random();
protected List<Color> colorList;
protected List<Font> fontList;
protected List<Float> angles;
private Scaling scaling = Scaling.LOGARITHMIC;

public TypeLabelProvider() {
colorList = new ArrayList<Color>();
Expand All @@ -55,9 +62,16 @@ public String getLabel(Object element) {

@Override
public double getWeight(Object element) {
double count = Math.log(((Type)element).getOccurrences() - minOccurrences+1);
count /=(Math.log(maxOccurrences));
return count;
switch(scaling) {
case LINEAR: return ((Type)element).getOccurrences()/maxOccurrences;
case LOGARITHMIC: {
double count = Math.log(((Type)element).getOccurrences() - minOccurrences+1);
count /=(Math.log(maxOccurrences));
return count;
}
default: return 1;
}

}

@Override
Expand Down Expand Up @@ -137,6 +151,10 @@ public void setFonts(List<FontData> newFonts) {
public String getToolTip(Object element) {
return getLabel(element);
}

public void setScale(Scaling scaling) {
this.scaling = scaling;
}



Expand Down

0 comments on commit 249a26a

Please sign in to comment.