Skip to content

Commit

Permalink
Made Diff View more compact
Browse files Browse the repository at this point in the history
Now the "Profile Nrs" are used in the column headers for visual clarity,
and to avoid confusing terminology ("new" isn't the best term since that
profile may actually be "older").

Also, the columns now are resized to their title (Not that easy in FX
actually).
  • Loading branch information
rx committed Dec 29, 2016
1 parent 96da273 commit 02d63fa
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 85 deletions.
Expand Up @@ -21,6 +21,8 @@
import static com.insightfullogic.honest_profiler.ports.javafx.model.filter.FilterType.STRING; import static com.insightfullogic.honest_profiler.ports.javafx.model.filter.FilterType.STRING;
import static com.insightfullogic.honest_profiler.ports.javafx.util.DialogUtil.FILTER; import static com.insightfullogic.honest_profiler.ports.javafx.util.DialogUtil.FILTER;
import static com.insightfullogic.honest_profiler.ports.javafx.util.DialogUtil.showExportDialog; import static com.insightfullogic.honest_profiler.ports.javafx.util.DialogUtil.showExportDialog;
import static com.insightfullogic.honest_profiler.ports.javafx.util.FxUtil.addProfileNr;
import static com.insightfullogic.honest_profiler.ports.javafx.util.FxUtil.createColoredLabelContainer;
import static com.insightfullogic.honest_profiler.ports.javafx.util.FxUtil.refreshTable; import static com.insightfullogic.honest_profiler.ports.javafx.util.FxUtil.refreshTable;
import static com.insightfullogic.honest_profiler.ports.javafx.util.StyleUtil.doubleDiffStyler; import static com.insightfullogic.honest_profiler.ports.javafx.util.StyleUtil.doubleDiffStyler;
import static com.insightfullogic.honest_profiler.ports.javafx.util.StyleUtil.intDiffStyler; import static com.insightfullogic.honest_profiler.ports.javafx.util.StyleUtil.intDiffStyler;
Expand All @@ -29,6 +31,7 @@
import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.FUNNEL_16; import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.FUNNEL_16;
import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.FUNNEL_ACTIVE_16; import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.FUNNEL_ACTIVE_16;
import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.viewFor; import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.viewFor;
import static javafx.geometry.Pos.CENTER;


import java.util.function.Function; import java.util.function.Function;


Expand All @@ -52,13 +55,16 @@
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellDataFeatures; import javafx.scene.control.TableColumn.CellDataFeatures;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
import javafx.scene.control.Tooltip; import javafx.scene.control.Tooltip;
import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.util.Callback; import javafx.util.Callback;


public class FlatDiffViewController extends AbstractController public class FlatDiffViewController extends AbstractController
Expand Down Expand Up @@ -160,59 +166,63 @@ private void initialize()
.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getFullName())); .setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getFullName()));
method.setCellFactory(col -> new MethodNameTableCell<FlatEntryDiff>()); method.setCellFactory(col -> new MethodNameTableCell<FlatEntryDiff>());


configureTimeShareColumn(baseSelfTime, "baseSelfTimeShare", null); }
configureTimeShareColumn(newSelfTime, "newSelfTimeShare", null);


configureTimeShareColumn(baseTotalTime, "baseTotalTimeShare", null); @Override
configureTimeShareColumn(newTotalTime, "newTotalTimeShare", null); public void setApplicationContext(ApplicationContext applicationContext)
{
super.setApplicationContext(applicationContext);
filterDialogController.setApplicationContext(appCtx());
}


configureTimeShareColumn(selfTimeDiff, "pctSelfChange", doubleDiffStyler); public void setProfileContexts(ProfileContext baseContext, ProfileContext newContext)
configureTimeShareColumn(totalTimeDiff, "pctTotalChange", doubleDiffStyler); {
baseProfileContext = baseContext;
newProfileContext = newContext;


configureCountColumn(baseSelfCount, "baseSelfCount", null); baseSourceLabel.setText(baseContext.getName());
configureCountColumn(newSelfCount, "newSelfCount", null); newSourceLabel.setText(newContext.getName());


configureCountColumn(baseTotalCount, "baseTotalCount", null); configurePercentColumn(baseSelfTime, "baseSelfTimeShare", baseProfileContext, "Self %");
configureCountColumn(newTotalCount, "newTotalCount", null); configurePercentColumn(newSelfTime, "newSelfTimeShare", newProfileContext, "Self %");
configurePercentColumn(selfTimeDiff, "pctSelfChange", doubleDiffStyler, "Self % Diff");


configureCountColumn(baseTraceCount, "baseTraceCount", null); configurePercentColumn(baseTotalTime, "baseTotalTimeShare", baseProfileContext, "Total %");
configureCountColumn(newTraceCount, "newTraceCount", null); configurePercentColumn(newTotalTime, "newTotalTimeShare", newProfileContext, "Total %");
configurePercentColumn(totalTimeDiff, "pctTotalChange", doubleDiffStyler, "Total % Diff");


configureCountColumn(baseSelfCount, "baseSelfCount", baseProfileContext, "Self #");
configureCountColumn(newSelfCount, "newSelfCount", newProfileContext, "Self #");
configureCountDiffColumn( configureCountDiffColumn(
selfCountDiff, selfCountDiff,
data -> new ReadOnlyIntegerWrapper( data -> new ReadOnlyIntegerWrapper(
data.getValue().getNewSelfCount() - data.getValue().getBaseSelfCount()), data.getValue().getNewSelfCount() - data.getValue().getBaseSelfCount()),
intDiffStyler); intDiffStyler,
"Self # Diff");

configureCountColumn(baseTotalCount, "baseTotalCount", baseProfileContext, "Total #");
configureCountColumn(newTotalCount, "newTotalCount", newProfileContext, "Total #");
configureCountDiffColumn( configureCountDiffColumn(
totalCountDiff, totalCountDiff,
data -> new ReadOnlyIntegerWrapper( data -> new ReadOnlyIntegerWrapper(
data.getValue().getNewTotalCount() - data.getValue().getBaseTotalCount()), data.getValue().getNewTotalCount() - data.getValue().getBaseTotalCount()),
intDiffStyler); intDiffStyler,
"Total # Diff");

configureCountColumn(baseTraceCount, "baseTraceCount", baseProfileContext, "Trace #");
configureCountColumn(newTraceCount, "newTraceCount", baseProfileContext, "Trace #");
configureCountDiffColumn( configureCountDiffColumn(
traceCountDiff, traceCountDiff,
data -> new ReadOnlyIntegerWrapper( data -> new ReadOnlyIntegerWrapper(
data.getValue().getNewTraceCount() - data.getValue().getBaseTraceCount()), data.getValue().getNewTraceCount() - data.getValue().getBaseTraceCount()),
intDiffStyler); intDiffStyler,
} "Trace # Diff");

@Override
public void setApplicationContext(ApplicationContext applicationContext)
{
super.setApplicationContext(applicationContext);
filterDialogController.setApplicationContext(appCtx());
}

public void setProfileContexts(ProfileContext baseContext, ProfileContext newContext)
{
baseProfileContext = baseContext;
newProfileContext = newContext;

baseSourceLabel.setText(baseContext.getName());
newSourceLabel.setText(newContext.getName());


updateDiff(baseContext.getProfile(), true); updateDiff(baseContext.getProfile(), true);
updateDiff(newContext.getProfile(), false); updateDiff(newContext.getProfile(), false);


// diffTable.refresh();

baseProfileContext.profileProperty() baseProfileContext.profileProperty()
.addListener((property, oldValue, newValue) -> updateDiff(newValue, true)); .addListener((property, oldValue, newValue) -> updateDiff(newValue, true));


Expand All @@ -236,25 +246,72 @@ private void updateDiff(Profile profile, boolean base)
refreshTable(diffTable); refreshTable(diffTable);
} }


private void configureTimeShareColumn(TableColumn<FlatEntryDiff, Number> column, private void configurePercentColumn(TableColumn<FlatEntryDiff, Number> column,
String propertyName, Function<Number, String> styler) String propertyName, ProfileContext profileContext, String title)
{
column.setCellValueFactory(new PropertyValueFactory<>(propertyName));
column.setCellFactory(col -> new PercentageTableCell<>());
setColumnHeader(column, title, profileContext);
}

private void configurePercentColumn(TableColumn<FlatEntryDiff, Number> column,
String propertyName, Function<Number, String> styler, String title)
{ {
column.setCellValueFactory(new PropertyValueFactory<>(propertyName)); column.setCellValueFactory(new PropertyValueFactory<>(propertyName));
column.setCellFactory(col -> new PercentageTableCell<FlatEntryDiff>(styler)); column.setCellFactory(col -> new PercentageTableCell<FlatEntryDiff>(styler));
setColumnHeader(column, title, null);
} }


private void configureCountColumn(TableColumn<FlatEntryDiff, Number> column, private void configureCountColumn(TableColumn<FlatEntryDiff, Number> column,
String propertyName, Function<Number, String> styler) String propertyName,
ProfileContext profileContext, String title)
{ {
column.setCellValueFactory(new PropertyValueFactory<>(propertyName)); column.setCellValueFactory(new PropertyValueFactory<>(propertyName));
column.setCellFactory(col -> new CountTableCell<FlatEntryDiff>(styler)); column.setCellFactory(col -> new CountTableCell<FlatEntryDiff>());
setColumnHeader(column, title, profileContext);
} }


private void configureCountDiffColumn(TableColumn<FlatEntryDiff, Number> column, private void configureCountDiffColumn(TableColumn<FlatEntryDiff, Number> column,
Callback<CellDataFeatures<FlatEntryDiff, Number>, ObservableValue<Number>> callback, Callback<CellDataFeatures<FlatEntryDiff, Number>, ObservableValue<Number>> callback,
Function<Number, String> styler) Function<Number, String> styler, String title)
{ {
column.setCellValueFactory(callback); column.setCellValueFactory(callback);
column.setCellFactory(col -> new CountTableCell<FlatEntryDiff>(styler)); column.setCellFactory(col -> new CountTableCell<FlatEntryDiff>(styler));
setColumnHeader(column, title, null);
}

private void setColumnHeader(TableColumn<?, ?> column, String title,
ProfileContext profileContext)
{
HBox header = createColoredLabelContainer(CENTER);

column.setText(null);
column.setGraphic(header);

if (profileContext != null)
{
addProfileNr(header, profileContext);
}

header.getChildren().add(new Text(title));

// Somehow it's hard to get a TableColumn to resize properly.
// Therefore, we calculate a fair width ourselves.
double newWidth = calculateWidth(header);
column.setMinWidth(newWidth);
column.setPrefWidth(newWidth + 5); // some extra margin
diffTable.refresh();
}

private double calculateWidth(HBox box)
{
double width = 0;
for (Node node : box.getChildren())
{
width += node.getBoundsInLocal().getWidth();
}
width += box.getSpacing() * (box.getChildren().size() - 1);
width += box.getPadding().getLeft() + box.getPadding().getRight();
return width;
} }
} }
Expand Up @@ -4,24 +4,14 @@
import static com.insightfullogic.honest_profiler.ports.javafx.util.DialogUtil.selectLogFile; import static com.insightfullogic.honest_profiler.ports.javafx.util.DialogUtil.selectLogFile;
import static com.insightfullogic.honest_profiler.ports.javafx.util.FxUtil.FXML_FLAT_DIFF_VIEW; import static com.insightfullogic.honest_profiler.ports.javafx.util.FxUtil.FXML_FLAT_DIFF_VIEW;
import static com.insightfullogic.honest_profiler.ports.javafx.util.FxUtil.FXML_PROFILE_ROOT; import static com.insightfullogic.honest_profiler.ports.javafx.util.FxUtil.FXML_PROFILE_ROOT;
import static com.insightfullogic.honest_profiler.ports.javafx.util.FxUtil.addColoredLabel; import static com.insightfullogic.honest_profiler.ports.javafx.util.FxUtil.addProfileNr;
import static com.insightfullogic.honest_profiler.ports.javafx.util.FxUtil.createColoredLabelContainer;
import static com.insightfullogic.honest_profiler.ports.javafx.util.FxUtil.loaderFor; import static com.insightfullogic.honest_profiler.ports.javafx.util.FxUtil.loaderFor;
import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.LIVE_16; import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.LIVE_16;
import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.LOG_16; import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.LOG_16;
import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.viewFor; import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.viewFor;
import static javafx.application.Platform.exit; import static javafx.application.Platform.exit;
import static javafx.application.Platform.runLater; import static javafx.application.Platform.runLater;
import static javafx.geometry.Pos.CENTER_LEFT;
import static javafx.scene.paint.Color.BEIGE;
import static javafx.scene.paint.Color.CHARTREUSE;
import static javafx.scene.paint.Color.CYAN;
import static javafx.scene.paint.Color.GOLD;
import static javafx.scene.paint.Color.LIGHTBLUE;
import static javafx.scene.paint.Color.LIGHTGREEN;
import static javafx.scene.paint.Color.LIGHTGREY;
import static javafx.scene.paint.Color.LIGHTPINK;
import static javafx.scene.paint.Color.LIGHTSTEELBLUE;
import static javafx.scene.paint.Color.ORANGE;
import static org.slf4j.LoggerFactory.getLogger; import static org.slf4j.LoggerFactory.getLogger;


import java.io.IOException; import java.io.IOException;
Expand All @@ -41,19 +31,11 @@
import javafx.scene.control.MenuItem; import javafx.scene.control.MenuItem;
import javafx.scene.control.Tab; import javafx.scene.control.Tab;
import javafx.scene.control.TabPane; import javafx.scene.control.TabPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;


public class RootController extends AbstractController implements MachineListener public class RootController extends AbstractController implements MachineListener
{ {


private static final Color[] LABEL_PALETTE = new Color[]
{
LIGHTSTEELBLUE, LIGHTGREEN, ORANGE, LIGHTBLUE, BEIGE, GOLD, LIGHTGREY, LIGHTPINK, CYAN,
CHARTREUSE
};

@FXML @FXML
private MenuBar menuBar; private MenuBar menuBar;
@FXML @FXML
Expand Down Expand Up @@ -162,16 +144,13 @@ private void generateProfileTab(Object source, boolean live)


ProfileContext profileContext = controller.initializeProfile(appCtx(), source, live); ProfileContext profileContext = controller.initializeProfile(appCtx(), source, live);


Pane tabInfo = createTabInfoPane(); Pane tabInfo = createColoredLabelContainer();
tab.setGraphic(tabInfo); tab.setGraphic(tabInfo);
info(tab, "Shows profile " + profileContext.getName()); addProfileNr(tabInfo, profileContext);

addColoredLabel(
tabInfo,
Integer.toString(profileContext.getId()),
LABEL_PALETTE[profileContext.getId() % LABEL_PALETTE.length]);
tabInfo.getChildren().add(viewFor(profileContext.getMode() == LOG ? LOG_16 : LIVE_16)); tabInfo.getChildren().add(viewFor(profileContext.getMode() == LOG ? LOG_16 : LIVE_16));
tabInfo.getChildren().add(new Label(profileContext.getName())); tabInfo.getChildren().add(new Label(profileContext.getName()));

info(tab, "Shows profile " + profileContext.getName());
} }


public void generateDiffTab(String baseName, String newName) public void generateDiffTab(String baseName, String newName)
Expand All @@ -183,29 +162,15 @@ public void generateDiffTab(String baseName, String newName)
ProfileContext newCtx = appCtx().getProfileContext(newName); ProfileContext newCtx = appCtx().getProfileContext(newName);
controller.setProfileContexts(baseCtx, newCtx); controller.setProfileContexts(baseCtx, newCtx);


Pane tabInfo = createTabInfoPane(); Pane tabInfo = createColoredLabelContainer();
tab.setGraphic(tabInfo); tab.setGraphic(tabInfo);
info(tab, "Shows the difference between profiles " + baseName + " and " + newName); info(tab, "Shows the difference between profiles " + baseName + " and " + newName);


profileTabs.getTabs().add(tab); profileTabs.getTabs().add(tab);


addColoredLabel( addProfileNr(tabInfo, baseCtx);
tabInfo,
Integer.toString(baseCtx.getId()),
LABEL_PALETTE[baseCtx.getId() % LABEL_PALETTE.length]);
tabInfo.getChildren().add(new Label("<->")); tabInfo.getChildren().add(new Label("<->"));
addColoredLabel( addProfileNr(tabInfo, newCtx);
tabInfo,
Integer.toString(newCtx.getId()),
LABEL_PALETTE[newCtx.getId() % LABEL_PALETTE.length]);
}

private Pane createTabInfoPane()
{
HBox tabInfo = new HBox();
tabInfo.setAlignment(CENTER_LEFT);
tabInfo.setSpacing(5);
return tabInfo;
} }


private <T extends AbstractController> T loadViewIntoTab(String fxml, Tab tab) private <T extends AbstractController> T loadViewIntoTab(String fxml, Tab tab)
Expand Down

0 comments on commit 02d63fa

Please sign in to comment.