From 7a848406af8aab95d484b95d5d06639dd020ec3b Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sat, 27 Aug 2016 22:12:44 +0200 Subject: [PATCH] Flip offer book table if altcoin, use ascending price for altcoin chart --- .../market/offerbook/OfferBookChartView.fxml | 2 +- .../market/offerbook/OfferBookChartView.java | 99 ++++++++++++------- .../offerbook/OfferBookChartViewModel.java | 18 +++- 3 files changed, 76 insertions(+), 43 deletions(-) diff --git a/gui/src/main/java/io/bitsquare/gui/main/market/offerbook/OfferBookChartView.fxml b/gui/src/main/java/io/bitsquare/gui/main/market/offerbook/OfferBookChartView.fxml index 8e3ad701dc..1d5ab83f0b 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/market/offerbook/OfferBookChartView.fxml +++ b/gui/src/main/java/io/bitsquare/gui/main/market/offerbook/OfferBookChartView.fxml @@ -21,7 +21,7 @@ diff --git a/gui/src/main/java/io/bitsquare/gui/main/market/offerbook/OfferBookChartView.java b/gui/src/main/java/io/bitsquare/gui/main/market/offerbook/OfferBookChartView.java index e740b5a23e..e2e0b4eaef 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/market/offerbook/OfferBookChartView.java +++ b/gui/src/main/java/io/bitsquare/gui/main/market/offerbook/OfferBookChartView.java @@ -37,7 +37,9 @@ import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.chart.AreaChart; @@ -55,6 +57,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.inject.Inject; +import java.util.Collections; @FxmlView public class OfferBookChartView extends ActivatableViewAndModel { @@ -78,6 +81,7 @@ public class OfferBookChartView extends ActivatableViewAndModel tabPaneSelectionModel; private Label buyOfferHeaderLabel, sellOfferHeaderLabel; private ChangeListener sellTableRowSelectionListener, buyTableRowSelectionListener; + private HBox bottomHBox; /////////////////////////////////////////////////////////////////////////////////////////// @@ -102,7 +106,7 @@ public class OfferBookChartView extends ActivatableViewAndModel { String code = tradeCurrency.getCode(); - String tradeCurrencyName = tradeCurrency.getName(); areaChart.setTitle("Offer book for " + formatter.getCurrencyNameAndCurrencyPair(code)); volumeColumnLabel.set("Amount in " + code); xAxis.setTickLabelFormatter(new StringConverter() { @@ -157,10 +162,9 @@ public class OfferBookChartView extends ActivatableViewAndModel(xAxis, yAxis); + areaChart.setLegendVisible(false); + areaChart.setAnimated(false); + areaChart.setId("charts"); + areaChart.setMinHeight(300); + areaChart.setPadding(new Insets(0, 30, 0, 0)); + areaChart.getData().addAll(seriesBuy, seriesSell); + } + + private void updateChartData() { + seriesBuy.getData().clear(); + seriesSell.getData().clear(); + + seriesBuy.getData().addAll(model.getBuyData()); + seriesSell.getData().addAll(model.getSellData()); + } private Tuple4, VBox, Button, Label> getOfferTable(Offer.Direction direction) { TableView tableView = new TableView<>(); @@ -414,33 +457,15 @@ public class OfferBookChartView extends ActivatableViewAndModel(tableView, vBox, button, titleLabel); } - private void createChart() { - xAxis = new NumberAxis(); - xAxis.setForceZeroInRange(false); - xAxis.setAutoRanging(true); + private void reverseTableColumns() { + ObservableList> columns = FXCollections.observableArrayList(buyOfferTableView.getColumns()); + buyOfferTableView.getColumns().clear(); + Collections.reverse(columns); + buyOfferTableView.getColumns().addAll(columns); - yAxis = new NumberAxis(); - yAxis.setForceZeroInRange(false); - yAxis.setAutoRanging(true); - yAxis.setLabel("Amount in BTC"); - yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis, "", "")); - - seriesBuy = new XYChart.Series(); - seriesSell = new XYChart.Series(); - - areaChart = new AreaChart<>(xAxis, yAxis); - areaChart.setAnimated(false); - areaChart.setId("charts"); - areaChart.setMinHeight(300); - areaChart.setPadding(new Insets(0, 30, 0, 0)); - areaChart.getData().addAll(seriesBuy, seriesSell); - } - - private void updateChartData() { - seriesBuy.getData().clear(); - seriesSell.getData().clear(); - - seriesBuy.getData().addAll(model.getBuyData()); - seriesSell.getData().addAll(model.getSellData()); + columns = FXCollections.observableArrayList(sellOfferTableView.getColumns()); + sellOfferTableView.getColumns().clear(); + Collections.reverse(columns); + sellOfferTableView.getColumns().addAll(columns); } } diff --git a/gui/src/main/java/io/bitsquare/gui/main/market/offerbook/OfferBookChartViewModel.java b/gui/src/main/java/io/bitsquare/gui/main/market/offerbook/OfferBookChartViewModel.java index 0692074347..f8f8ef6211 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/market/offerbook/OfferBookChartViewModel.java +++ b/gui/src/main/java/io/bitsquare/gui/main/market/offerbook/OfferBookChartViewModel.java @@ -254,13 +254,21 @@ class OfferBookChartViewModel extends ActivatableViewModel { for (Offer offer : sortedList) { Fiat priceAsFiat = offer.getPrice(); if (priceAsFiat != null) { - double price = (double) priceAsFiat.value / LongMath.pow(10, priceAsFiat.smallestUnitExponent()); double amount = (double) offer.getAmount().value / LongMath.pow(10, offer.getAmount().smallestUnitExponent()); accumulatedAmount += amount; - if (direction.equals(Offer.Direction.BUY)) - data.add(0, new XYChart.Data(price, accumulatedAmount)); - else - data.add(new XYChart.Data(price, accumulatedAmount)); + double price = (double) priceAsFiat.value / LongMath.pow(10, priceAsFiat.smallestUnitExponent()); + if (CurrencyUtil.isCryptoCurrency(getCurrencyCode())) { + price = price != 0 ? 1d / price : 0; + if (direction.equals(Offer.Direction.SELL)) + data.add(0, new XYChart.Data(price, accumulatedAmount)); + else + data.add(new XYChart.Data(price, accumulatedAmount)); + } else { + if (direction.equals(Offer.Direction.BUY)) + data.add(0, new XYChart.Data(price, accumulatedAmount)); + else + data.add(new XYChart.Data(price, accumulatedAmount)); + } } } }