From cb3fa50f22593af40e778e1194289bd906672797 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Thu, 24 Jan 2019 15:45:07 +0100 Subject: [PATCH] Improve resizing of buy and sell tables --- .../market/offerbook/OfferBookChartView.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 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 d6aa92ffa3b..a7bbe1eb242 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 @@ -90,6 +90,7 @@ import java.util.Comparator; import java.util.Optional; import java.util.function.Function; +import java.util.function.Supplier; import static bisq.desktop.util.FormBuilder.addTopLabelComboBox; import static bisq.desktop.util.Layout.INITIAL_WINDOW_HEIGHT; @@ -118,18 +119,17 @@ public class OfferBookChartView extends ActivatableViewAndModel changeListener; private ListChangeListener currencyListItemsListener; - private final double initialOfferTableViewHeight = 109; - private final double pixelsPerOfferTableRow = (initialOfferTableViewHeight / 4.0) + 10.0; // initial visible row count=4 + private final double initialOfferTableViewHeight = 121; + private final double pixelsPerOfferTableRow = (initialOfferTableViewHeight - 30) / 5.0; // initial visible row count=5, header height=30 private final Function offerTableViewHeight = (screenSize) -> { int extraRows = screenSize <= INITIAL_WINDOW_HEIGHT ? 0 : (int) ((screenSize - INITIAL_WINDOW_HEIGHT) / pixelsPerOfferTableRow); - return extraRows == 0 ? initialOfferTableViewHeight : Math.ceil(initialOfferTableViewHeight + (extraRows * pixelsPerOfferTableRow)); + return extraRows == 0 ? initialOfferTableViewHeight : Math.ceil(initialOfferTableViewHeight + ((extraRows + 1) * pixelsPerOfferTableRow)); }; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor, lifecycle /////////////////////////////////////////////////////////////////////////////////////////// - @SuppressWarnings("WeakerAccess") @Inject public OfferBookChartView(OfferBookChartViewModel model, Navigation navigation, BSFormatter formatter, @Named(AppOptionKeys.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys) { @@ -338,21 +338,27 @@ private void updateChartData() { seriesSell.getData().clear(); areaChart.getData().clear(); + final Supplier> optionalMaxSupplier = () -> + Optional.of(new XYChart.Data<>(Double.MAX_VALUE, Double.MAX_VALUE)); + final Optional buyMinOptional = model.getBuyData().stream() .min(Comparator.comparingDouble(o -> (double) o.getXValue())) - .or(() -> Optional.of(new XYChart.Data<>(Double.MAX_VALUE, Double.MAX_VALUE))); + .or(optionalMaxSupplier); + + final Supplier> optionalMinSupplier = () -> + Optional.of(new XYChart.Data<>(Double.MIN_VALUE, Double.MIN_VALUE)); final Optional buyMaxOptional = model.getBuyData().stream() .max(Comparator.comparingDouble(o -> (double) o.getXValue())) - .or(() -> Optional.of(new XYChart.Data<>(Double.MIN_VALUE, Double.MIN_VALUE))); + .or(optionalMinSupplier); final Optional sellMinOptional = model.getSellData().stream() .min(Comparator.comparingDouble(o -> (double) o.getXValue())) - .or(() -> Optional.of(new XYChart.Data<>(Double.MAX_VALUE, Double.MAX_VALUE))); + .or(optionalMaxSupplier); final Optional sellMaxOptional = model.getSellData().stream() .max(Comparator.comparingDouble(o -> (double) o.getXValue())) - .or(() -> Optional.of(new XYChart.Data<>(Double.MIN_VALUE, Double.MIN_VALUE))); + .or(optionalMinSupplier); 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()); @@ -376,7 +382,7 @@ private void updateChartData() { private Tuple4, VBox, Button, Label> getOfferTable(OfferPayload.Direction direction) { TableView tableView = new TableView<>(); tableView.setMinHeight(initialOfferTableViewHeight); - tableView.setPrefHeight(121); + tableView.setPrefHeight(initialOfferTableViewHeight); tableView.setMinWidth(480); tableView.getStyleClass().add("offer-table");