From 23927af6a70092e9b04bb0c4575674c0bc0c3ac1 Mon Sep 17 00:00:00 2001 From: sqrrm Date: Fri, 14 Jun 2019 14:08:49 +0200 Subject: [PATCH 1/4] Add checkbox to hide extreme offers in chart --- .../resources/i18n/displayStrings.properties | 1 + .../market/offerbook/OfferBookChartView.java | 43 ++++++++++++++++--- .../java/bisq/desktop/util/FormBuilder.java | 5 +++ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 44443f9b156..5775b09143f 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -53,6 +53,7 @@ shared.oneOffer=offer shared.multipleOffers=offers shared.Offer=Offer shared.openOffers=open offers +shared.hideExtremes=Hide extremes shared.trade=trade shared.trades=trades shared.openTrades=open trades diff --git a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java index 0f0f6330567..5b92d5e47a8 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java +++ b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java @@ -53,6 +53,7 @@ import javafx.scene.chart.NumberAxis; import javafx.scene.chart.XYChart; import javafx.scene.control.Button; +import javafx.scene.control.CheckBox; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.control.SingleSelectionModel; @@ -62,11 +63,14 @@ import javafx.scene.control.TableView; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.ColumnConstraints; +import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.Region; import javafx.scene.layout.VBox; +import javafx.geometry.HPos; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.geometry.Side; @@ -93,6 +97,7 @@ import java.util.function.Function; import java.util.function.Supplier; +import static bisq.desktop.util.FormBuilder.addCheckBox; import static bisq.desktop.util.FormBuilder.addTopLabelComboBox; import static bisq.desktop.util.Layout.INITIAL_WINDOW_HEIGHT; @@ -128,6 +133,7 @@ public class OfferBookChartView extends ActivatableViewAndModel bisqWindowVerticalSizeListener; + private CheckBox hideExtremes; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor, lifecycle @@ -146,6 +152,10 @@ public OfferBookChartView(OfferBookChartViewModel model, Navigation navigation, public void initialize() { createListener(); + // Header with currency combobox and checkbox to show extreme values + GridPane topGrid = new GridPane(); + + // Currency combobox final Tuple3> currencyComboBoxTuple = addTopLabelComboBox(Res.get("shared.currency"), Res.get("list.currency.select"), 0); this.currencyComboBox = currencyComboBoxTuple.third; @@ -153,7 +163,18 @@ public void initialize() { Res.get("shared.multipleOffers"), model.preferences)); this.currencyComboBox.setCellFactory(GUIUtil.getCurrencyListItemCellFactory(Res.get("shared.oneOffer"), Res.get("shared.multipleOffers"), model.preferences)); - + topGrid.getChildren().add(currencyComboBoxTuple.first); + + // Extreme value checkbox + hideExtremes = addCheckBox(topGrid, 0, 1, Res.get("shared.hideExtremes"), 35); + GridPane.setHalignment(hideExtremes, HPos.RIGHT); + ColumnConstraints column1 = new ColumnConstraints(); + column1.setPercentWidth(50); + ColumnConstraints column2 = new ColumnConstraints(); + column2.setPercentWidth(50); + topGrid.getColumnConstraints().addAll(column1, column2); + + // Chart createChart(); VBox.setMargin(chartPane, new Insets(0, 0, 5, 0)); @@ -179,8 +200,7 @@ public void initialize() { tupleSell.second.setUserData(OfferPayload.Direction.SELL.name()); bottomHBox.getChildren().addAll(tupleBuy.second, tupleSell.second); - - root.getChildren().addAll(currencyComboBoxTuple.first, chartPane, bottomHBox); + root.getChildren().addAll(topGrid, chartPane, bottomHBox); } @Override @@ -206,6 +226,8 @@ protected void activate() { } }); + hideExtremes.setOnAction(e -> updateChartData()); + model.currencyListItems.getObservableList().addListener(currencyListItemsListener); model.getOfferBookListItems().addListener(changeListener); @@ -215,6 +237,7 @@ protected void activate() { volumeColumnLabel.set(Res.get("shared.amountWithCur", code)); xAxis.setTickLabelFormatter(new StringConverter<>() { int cryptoPrecision = 3; + @Override public String toString(Number object) { final double doubleValue = (double) object; @@ -314,6 +337,7 @@ protected void deactivate() { model.currencyListItems.getObservableList().removeListener(currencyListItemsListener); tradeCurrencySubscriber.unsubscribe(); currencyComboBox.setOnAction(null); + hideExtremes.setOnAction(null); buyOfferTableView.getSelectionModel().selectedItemProperty().removeListener(buyTableRowSelectionListener); sellOfferTableView.getSelectionModel().selectedItemProperty().removeListener(sellTableRowSelectionListener); } @@ -374,18 +398,23 @@ private void updateChartData() { final Supplier> optionalMinSupplier = () -> Optional.of(new XYChart.Data<>(Double.MIN_VALUE, Double.MIN_VALUE)); + // Hide buy offers that are more than a factor 5 higher than the lowest buy offer final Optional buyMaxOptional = model.getBuyData().stream() + .filter(o -> !hideExtremes.isSelected() || + (double) o.getXValue() < (double) buyMinOptional.get().getXValue() * 3) .max(Comparator.comparingDouble(o -> (double) o.getXValue())) .or(optionalMinSupplier); - final Optional sellMinOptional = model.getSellData().stream() - .min(Comparator.comparingDouble(o -> (double) o.getXValue())) - .or(optionalMaxSupplier); - final Optional sellMaxOptional = model.getSellData().stream() .max(Comparator.comparingDouble(o -> (double) o.getXValue())) .or(optionalMinSupplier); + final Optional sellMinOptional = model.getSellData().stream() + .filter(o -> !hideExtremes.isSelected() || + (double) o.getXValue() > (double) sellMaxOptional.get().getXValue() / 3) + .min(Comparator.comparingDouble(o -> (double) o.getXValue())) + .or(optionalMaxSupplier); + final double minValue = Double.min((double) buyMinOptional.get().getXValue(), (double) sellMinOptional.get().getXValue()); final double maxValue = Double.max((double) buyMaxOptional.get().getXValue(), (double) sellMaxOptional.get().getXValue()); diff --git a/desktop/src/main/java/bisq/desktop/util/FormBuilder.java b/desktop/src/main/java/bisq/desktop/util/FormBuilder.java index 767590ee0f7..09ce2e8eb56 100644 --- a/desktop/src/main/java/bisq/desktop/util/FormBuilder.java +++ b/desktop/src/main/java/bisq/desktop/util/FormBuilder.java @@ -745,9 +745,14 @@ public static CheckBox addCheckBox(GridPane gridPane, int rowIndex, String check } public static CheckBox addCheckBox(GridPane gridPane, int rowIndex, String checkBoxTitle, double top) { + return addCheckBox(gridPane, rowIndex, 0, checkBoxTitle, 0); + } + + public static CheckBox addCheckBox(GridPane gridPane, int rowIndex, int colIndex, String checkBoxTitle, double top) { CheckBox checkBox = new AutoTooltipCheckBox(checkBoxTitle); GridPane.setMargin(checkBox, new Insets(top, 0, 0, 0)); GridPane.setRowIndex(checkBox, rowIndex); + GridPane.setColumnIndex(checkBox, colIndex); gridPane.getChildren().add(checkBox); return checkBox; } From fcfd302f626c108d68087453b6514db277b223ea Mon Sep 17 00:00:00 2001 From: sqrrm Date: Sat, 15 Jun 2019 11:29:47 +0200 Subject: [PATCH 2/4] Use proper vertical alignment for checkbox --- .../desktop/main/market/offerbook/OfferBookChartView.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java index 5b92d5e47a8..38443e1fab9 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java +++ b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java @@ -74,6 +74,7 @@ import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.geometry.Side; +import javafx.geometry.VPos; import org.fxmisc.easybind.EasyBind; import org.fxmisc.easybind.Subscription; @@ -166,7 +167,8 @@ public void initialize() { topGrid.getChildren().add(currencyComboBoxTuple.first); // Extreme value checkbox - hideExtremes = addCheckBox(topGrid, 0, 1, Res.get("shared.hideExtremes"), 35); + hideExtremes = addCheckBox(topGrid, 0, 1, Res.get("shared.hideExtremes"),0); + GridPane.setValignment(hideExtremes, VPos.BOTTOM); GridPane.setHalignment(hideExtremes, HPos.RIGHT); ColumnConstraints column1 = new ColumnConstraints(); column1.setPercentWidth(50); From 7a66febd521467949e3e94cbe6eaa826ae5cf752 Mon Sep 17 00:00:00 2001 From: sqrrm Date: Thu, 20 Jun 2019 12:07:58 +0200 Subject: [PATCH 3/4] Remove checkbox for hiding extremes --- .../market/offerbook/OfferBookChartView.java | 25 ++----------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java index 38443e1fab9..517216a0c31 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java +++ b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java @@ -53,7 +53,6 @@ import javafx.scene.chart.NumberAxis; import javafx.scene.chart.XYChart; import javafx.scene.control.Button; -import javafx.scene.control.CheckBox; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.control.SingleSelectionModel; @@ -63,18 +62,15 @@ import javafx.scene.control.TableView; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.Region; import javafx.scene.layout.VBox; -import javafx.geometry.HPos; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.geometry.Side; -import javafx.geometry.VPos; import org.fxmisc.easybind.EasyBind; import org.fxmisc.easybind.Subscription; @@ -98,7 +94,6 @@ import java.util.function.Function; import java.util.function.Supplier; -import static bisq.desktop.util.FormBuilder.addCheckBox; import static bisq.desktop.util.FormBuilder.addTopLabelComboBox; import static bisq.desktop.util.Layout.INITIAL_WINDOW_HEIGHT; @@ -134,7 +129,6 @@ public class OfferBookChartView extends ActivatableViewAndModel bisqWindowVerticalSizeListener; - private CheckBox hideExtremes; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor, lifecycle @@ -166,16 +160,6 @@ public void initialize() { Res.get("shared.multipleOffers"), model.preferences)); topGrid.getChildren().add(currencyComboBoxTuple.first); - // Extreme value checkbox - hideExtremes = addCheckBox(topGrid, 0, 1, Res.get("shared.hideExtremes"),0); - GridPane.setValignment(hideExtremes, VPos.BOTTOM); - GridPane.setHalignment(hideExtremes, HPos.RIGHT); - ColumnConstraints column1 = new ColumnConstraints(); - column1.setPercentWidth(50); - ColumnConstraints column2 = new ColumnConstraints(); - column2.setPercentWidth(50); - topGrid.getColumnConstraints().addAll(column1, column2); - // Chart createChart(); @@ -228,8 +212,6 @@ protected void activate() { } }); - hideExtremes.setOnAction(e -> updateChartData()); - model.currencyListItems.getObservableList().addListener(currencyListItemsListener); model.getOfferBookListItems().addListener(changeListener); @@ -339,7 +321,6 @@ protected void deactivate() { model.currencyListItems.getObservableList().removeListener(currencyListItemsListener); tradeCurrencySubscriber.unsubscribe(); currencyComboBox.setOnAction(null); - hideExtremes.setOnAction(null); buyOfferTableView.getSelectionModel().selectedItemProperty().removeListener(buyTableRowSelectionListener); sellOfferTableView.getSelectionModel().selectedItemProperty().removeListener(sellTableRowSelectionListener); } @@ -402,8 +383,7 @@ private void updateChartData() { // Hide buy offers that are more than a factor 5 higher than the lowest buy offer final Optional buyMaxOptional = model.getBuyData().stream() - .filter(o -> !hideExtremes.isSelected() || - (double) o.getXValue() < (double) buyMinOptional.get().getXValue() * 3) + .filter(o -> (double) o.getXValue() < (double) buyMinOptional.get().getXValue() * 3) .max(Comparator.comparingDouble(o -> (double) o.getXValue())) .or(optionalMinSupplier); @@ -412,8 +392,7 @@ private void updateChartData() { .or(optionalMinSupplier); final Optional sellMinOptional = model.getSellData().stream() - .filter(o -> !hideExtremes.isSelected() || - (double) o.getXValue() > (double) sellMaxOptional.get().getXValue() / 3) + .filter(o -> (double) o.getXValue() > (double) sellMaxOptional.get().getXValue() / 3) .min(Comparator.comparingDouble(o -> (double) o.getXValue())) .or(optionalMaxSupplier); From 664c7c6f876567958d15064552bb9271fe2a43d8 Mon Sep 17 00:00:00 2001 From: sqrrm Date: Fri, 21 Jun 2019 11:20:45 +0200 Subject: [PATCH 4/4] Remove extra UI element and text string --- core/src/main/resources/i18n/displayStrings.properties | 1 - .../main/market/offerbook/OfferBookChartView.java | 9 +-------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 5775b09143f..44443f9b156 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -53,7 +53,6 @@ shared.oneOffer=offer shared.multipleOffers=offers shared.Offer=Offer shared.openOffers=open offers -shared.hideExtremes=Hide extremes shared.trade=trade shared.trades=trades shared.openTrades=open trades diff --git a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java index 517216a0c31..66392ab4967 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java +++ b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java @@ -62,7 +62,6 @@ import javafx.scene.control.TableView; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.Region; @@ -147,10 +146,6 @@ public OfferBookChartView(OfferBookChartViewModel model, Navigation navigation, public void initialize() { createListener(); - // Header with currency combobox and checkbox to show extreme values - GridPane topGrid = new GridPane(); - - // Currency combobox final Tuple3> currencyComboBoxTuple = addTopLabelComboBox(Res.get("shared.currency"), Res.get("list.currency.select"), 0); this.currencyComboBox = currencyComboBoxTuple.third; @@ -158,9 +153,7 @@ public void initialize() { Res.get("shared.multipleOffers"), model.preferences)); this.currencyComboBox.setCellFactory(GUIUtil.getCurrencyListItemCellFactory(Res.get("shared.oneOffer"), Res.get("shared.multipleOffers"), model.preferences)); - topGrid.getChildren().add(currencyComboBoxTuple.first); - // Chart createChart(); VBox.setMargin(chartPane, new Insets(0, 0, 5, 0)); @@ -186,7 +179,7 @@ public void initialize() { tupleSell.second.setUserData(OfferPayload.Direction.SELL.name()); bottomHBox.getChildren().addAll(tupleBuy.second, tupleSell.second); - root.getChildren().addAll(topGrid, chartPane, bottomHBox); + root.getChildren().addAll(currencyComboBoxTuple.first, chartPane, bottomHBox); } @Override