mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 15:10:44 +01:00
Add dynamic spacing in offer book for price and volume columns (amount is hardly going to change > 9 BTC)
This commit is contained in:
parent
6ab21f1066
commit
cd623af1c3
6 changed files with 146 additions and 17 deletions
|
@ -324,7 +324,7 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
|
|||
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
|
||||
if (offer != null && offer.getPrice() != null) {
|
||||
setText("");
|
||||
setGraphic(new ColoredDecimalPlacesWithZerosText(formatter.formatPrice(offer.getPrice(), true),
|
||||
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getPrice(offer),
|
||||
model.getZeroDecimalsForPrice(offer)));
|
||||
model.priceFeedService.updateCounterProperty().removeListener(listener);
|
||||
}
|
||||
|
@ -335,13 +335,15 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
|
|||
public void updateItem(final OfferListItem offerListItem, boolean empty) {
|
||||
super.updateItem(offerListItem, empty);
|
||||
if (offerListItem != null && !empty) {
|
||||
if (offerListItem.offer.getPrice() == null) {
|
||||
this.offer = offerListItem.offer;
|
||||
|
||||
final Offer offer = offerListItem.offer;
|
||||
if (offer.getPrice() == null) {
|
||||
this.offer = offer;
|
||||
model.priceFeedService.updateCounterProperty().addListener(listener);
|
||||
setText(Res.get("shared.na"));
|
||||
} else {
|
||||
setGraphic(new ColoredDecimalPlacesWithZerosText(formatter.formatPrice(offerListItem.offer.getPrice(), true),
|
||||
model.getZeroDecimalsForPrice(offerListItem.offer)));
|
||||
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getPrice(offer),
|
||||
model.getZeroDecimalsForPrice(offer)));
|
||||
}
|
||||
} else {
|
||||
if (listener != null)
|
||||
|
@ -373,7 +375,7 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
|
|||
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
|
||||
if (offer != null && offer.getPrice() != null) {
|
||||
setText("");
|
||||
setGraphic(new ColoredDecimalPlacesWithZerosText(formatter.formatVolume(offer.getVolume(), true),
|
||||
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(offer),
|
||||
model.getMaxNumberOfPriceZeroDecimalsToColorize(offer)));
|
||||
model.priceFeedService.updateCounterProperty().removeListener(listener);
|
||||
}
|
||||
|
@ -391,7 +393,7 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
|
|||
setText(Res.get("shared.na"));
|
||||
} else {
|
||||
setText("");
|
||||
setGraphic(new ColoredDecimalPlacesWithZerosText(formatter.formatVolume(offer.getVolume(), true),
|
||||
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(offer),
|
||||
model.getMaxNumberOfPriceZeroDecimalsToColorize(offer)));
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -23,6 +23,7 @@ import io.bisq.common.GlobalSettings;
|
|||
import io.bisq.common.locale.CurrencyUtil;
|
||||
import io.bisq.common.locale.TradeCurrency;
|
||||
import io.bisq.common.monetary.Price;
|
||||
import io.bisq.common.monetary.Volume;
|
||||
import io.bisq.core.offer.Offer;
|
||||
import io.bisq.core.offer.OfferPayload;
|
||||
import io.bisq.core.provider.price.PriceFeedService;
|
||||
|
@ -34,10 +35,13 @@ import io.bisq.gui.main.offer.offerbook.OfferBook;
|
|||
import io.bisq.gui.main.offer.offerbook.OfferBookListItem;
|
||||
import io.bisq.gui.main.settings.SettingsView;
|
||||
import io.bisq.gui.main.settings.preferences.PreferencesView;
|
||||
import io.bisq.gui.util.BSFormatter;
|
||||
import io.bisq.gui.util.CurrencyList;
|
||||
import io.bisq.gui.util.CurrencyListItem;
|
||||
import io.bisq.gui.util.GUIUtil;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
|
@ -45,12 +49,8 @@ import javafx.collections.FXCollections;
|
|||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.chart.XYChart;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class OfferBookChartViewModel extends ActivatableViewModel {
|
||||
|
@ -70,8 +70,10 @@ class OfferBookChartViewModel extends ActivatableViewModel {
|
|||
private final ObservableList<OfferListItem> topBuyOfferList = FXCollections.observableArrayList();
|
||||
private final ObservableList<OfferListItem> topSellOfferList = FXCollections.observableArrayList();
|
||||
private final ChangeListener<Number> currenciesUpdatedListener;
|
||||
private final BSFormatter formatter;
|
||||
private int selectedTabIndex;
|
||||
|
||||
public final IntegerProperty maxPlacesForPrice = new SimpleIntegerProperty();
|
||||
public final IntegerProperty maxPlacesForVolume = new SimpleIntegerProperty();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor, lifecycle
|
||||
|
@ -79,11 +81,13 @@ class OfferBookChartViewModel extends ActivatableViewModel {
|
|||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
@Inject
|
||||
public OfferBookChartViewModel(OfferBook offerBook, Preferences preferences, PriceFeedService priceFeedService, Navigation navigation) {
|
||||
public OfferBookChartViewModel(OfferBook offerBook, Preferences preferences, PriceFeedService priceFeedService,
|
||||
Navigation navigation, BSFormatter formatter) {
|
||||
this.offerBook = offerBook;
|
||||
this.preferences = preferences;
|
||||
this.priceFeedService = priceFeedService;
|
||||
this.navigation = navigation;
|
||||
this.formatter = formatter;
|
||||
|
||||
Optional<TradeCurrency> tradeCurrencyOptional = CurrencyUtil.getTradeCurrency(preferences.getOfferBookChartScreenCurrencyCode());
|
||||
if (tradeCurrencyOptional.isPresent())
|
||||
|
@ -233,6 +237,23 @@ class OfferBookChartViewModel extends ActivatableViewModel {
|
|||
return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? GUIUtil.FIAT_PRICE_DECIMALS_WITH_ZEROS : GUIUtil.ALTCOINS_DECIMALS_WITH_ZEROS;
|
||||
}
|
||||
|
||||
public String getPrice(Offer offer) {
|
||||
return formatPrice(offer.getPrice(), true);
|
||||
}
|
||||
|
||||
private String formatPrice(Price price, boolean decimalAligned) {
|
||||
return formatter.formatPrice(price, decimalAligned, maxPlacesForPrice.get());
|
||||
}
|
||||
|
||||
public String getVolume(Offer offer) {
|
||||
return formatVolume(offer.getVolume(), true);
|
||||
}
|
||||
|
||||
private String formatVolume(Volume volume, boolean decimalAligned) {
|
||||
return formatter.formatVolume(volume, decimalAligned, maxPlacesForVolume.get());
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -266,6 +287,23 @@ class OfferBookChartViewModel extends ActivatableViewModel {
|
|||
.collect(Collectors.toList());
|
||||
|
||||
allBuyOffers = filterOffersWithRelevantPrices(allBuyOffers);
|
||||
|
||||
final Optional<Offer> highestPriceOffer = allBuyOffers.stream()
|
||||
.max(Comparator.comparingLong(o -> o.getPrice().getValue()));
|
||||
|
||||
if (highestPriceOffer.isPresent()) {
|
||||
final Offer offer = highestPriceOffer.get();
|
||||
maxPlacesForPrice.set(formatPrice(offer.getPrice(), false).length());
|
||||
}
|
||||
|
||||
final Optional<Offer> highestVolumeOffer = allBuyOffers.stream()
|
||||
.max(Comparator.comparingLong(o -> o.getVolume().getValue()));
|
||||
|
||||
if (highestVolumeOffer.isPresent()) {
|
||||
final Offer offer = highestVolumeOffer.get();
|
||||
maxPlacesForVolume.set(formatVolume(offer.getVolume(), false).length());
|
||||
}
|
||||
|
||||
buildChartAndTableEntries(allBuyOffers, OfferPayload.Direction.BUY, buyData, topBuyOfferList);
|
||||
|
||||
List<Offer> allSellOffers = offerBookListItems.stream()
|
||||
|
|
|
@ -267,10 +267,14 @@ public class BSFormatter {
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String formatVolume(Volume volume, Boolean decimalAligned) {
|
||||
return formatVolume(volume, decimalAligned, 8);
|
||||
}
|
||||
|
||||
public String formatVolume(Volume volume, Boolean decimalAligned, int maxNumberOfDigits) {
|
||||
String formattedVolume = formatVolume(volume);
|
||||
|
||||
if(decimalAligned) {
|
||||
formattedVolume = fillUpPlacesWithEmptyStrings(formattedVolume, 8);
|
||||
formattedVolume = fillUpPlacesWithEmptyStrings(formattedVolume, maxNumberOfDigits);
|
||||
}
|
||||
return formattedVolume;
|
||||
}
|
||||
|
@ -395,10 +399,14 @@ public class BSFormatter {
|
|||
}
|
||||
|
||||
public String formatPrice(Price price, Boolean decimalAligned) {
|
||||
return formatPrice(price, decimalAligned, 10);
|
||||
}
|
||||
|
||||
public String formatPrice(Price price, Boolean decimalAligned, int maxPlaces) {
|
||||
String formattedPrice = formatPrice(price);
|
||||
|
||||
if(decimalAligned) {
|
||||
formattedPrice = fillUpPlacesWithEmptyStrings(formattedPrice, 10);
|
||||
formattedPrice = fillUpPlacesWithEmptyStrings(formattedPrice, maxPlaces);
|
||||
}
|
||||
return formattedPrice;
|
||||
}
|
||||
|
@ -410,7 +418,7 @@ public class BSFormatter {
|
|||
else {
|
||||
return formatAltcoinWithCode((Altcoin) monetary);
|
||||
}
|
||||
//return formatPrice(fiat) + " " + getCurrencyPair(fiat.getCurrencyCode());
|
||||
//return getPrice(fiat) + " " + getCurrencyPair(fiat.getCurrencyCode());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.natpryce.makeiteasy.Property;
|
|||
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.a;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.make;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.with;
|
||||
|
||||
public class TradeCurrencyMakers {
|
||||
|
||||
|
@ -19,5 +20,6 @@ public class TradeCurrencyMakers {
|
|||
|
||||
public static final CryptoCurrency bitcoin = make(a(CryptoCurrency));
|
||||
public static final FiatCurrency euro = make(a(FiatCurrency));
|
||||
public static final FiatCurrency usd = make(a(FiatCurrency).but(with(currencyCode,"USD")));
|
||||
}
|
||||
|
||||
|
|
55
gui/src/test/java/io/bisq/core/offer/OfferMaker.java
Normal file
55
gui/src/test/java/io/bisq/core/offer/OfferMaker.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
package io.bisq.core.offer;
|
||||
|
||||
import com.natpryce.makeiteasy.Instantiator;
|
||||
import com.natpryce.makeiteasy.Maker;
|
||||
import com.natpryce.makeiteasy.Property;
|
||||
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.a;
|
||||
|
||||
public class OfferMaker {
|
||||
|
||||
public static final Property<Offer, Long> price = new Property<>();
|
||||
public static final Property<Offer, Long> volume = new Property<>();
|
||||
|
||||
public static final Instantiator<Offer> Offer = lookup -> new Offer(
|
||||
new OfferPayload("",
|
||||
0L,
|
||||
null,
|
||||
null,
|
||||
OfferPayload.Direction.BUY,
|
||||
lookup.valueOf(price, 100000L),
|
||||
0,
|
||||
false,
|
||||
lookup.valueOf(volume, 100000L),
|
||||
lookup.valueOf(volume, 100000L),
|
||||
"BTC",
|
||||
"USD",
|
||||
null,
|
||||
null,
|
||||
"SEPA",
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
"",
|
||||
0L,
|
||||
0L,
|
||||
0L,
|
||||
false,
|
||||
0L,
|
||||
0L,
|
||||
0L,
|
||||
0L,
|
||||
false,
|
||||
false,
|
||||
0L,
|
||||
0L,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
0));
|
||||
|
||||
public static final Maker<Offer> btcOffer = a(Offer);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package io.bisq.gui.main.offer.offerbook;
|
||||
|
||||
import com.natpryce.makeiteasy.Instantiator;
|
||||
import com.natpryce.makeiteasy.Maker;
|
||||
import com.natpryce.makeiteasy.Property;
|
||||
import io.bisq.core.offer.OfferMaker;
|
||||
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.a;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.make;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.with;
|
||||
import static io.bisq.core.offer.OfferMaker.btcOffer;
|
||||
|
||||
public class OfferBookListItemMaker {
|
||||
|
||||
public static final Property<OfferBookListItem, Long> price = new Property<>();
|
||||
public static final Property<OfferBookListItem, Long> volume = new Property<>();
|
||||
|
||||
public static final Instantiator<OfferBookListItem> OfferBookListItem = lookup ->
|
||||
new OfferBookListItem(make(btcOffer.but(
|
||||
with(OfferMaker.price, lookup.valueOf(price, 100000L)),
|
||||
with(OfferMaker.volume, lookup.valueOf(volume, 100000L)))));
|
||||
|
||||
public static final Maker<OfferBookListItem> btcItem = a(OfferBookListItem);
|
||||
}
|
Loading…
Add table
Reference in a new issue