mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Add half-year and quarter periods
This commit is contained in:
parent
5f2a430e4e
commit
492182a97d
@ -3336,6 +3336,8 @@ BTC_DAO_REGTEST=Bitcoin DAO Regtest
|
||||
|
||||
time.year=Year
|
||||
time.month=Month
|
||||
time.halfYear=Half-year
|
||||
time.quarter=Quarter
|
||||
time.week=Week
|
||||
time.day=Day
|
||||
time.hour=Hour
|
||||
|
@ -291,6 +291,10 @@ public abstract class ChartView<T extends ChartViewModel<? extends ChartDataMode
|
||||
protected HBox getTimeIntervalBox() {
|
||||
ToggleButton year = getTimeIntervalToggleButton(Res.get("time.year"), TemporalAdjusterModel.Interval.YEAR,
|
||||
timeIntervalToggleGroup, "toggle-left");
|
||||
ToggleButton halfYear = getTimeIntervalToggleButton(Res.get("time.halfYear"), TemporalAdjusterModel.Interval.HALF_YEAR,
|
||||
timeIntervalToggleGroup, "toggle-center");
|
||||
ToggleButton quarter = getTimeIntervalToggleButton(Res.get("time.quarter"), TemporalAdjusterModel.Interval.QUARTER,
|
||||
timeIntervalToggleGroup, "toggle-center");
|
||||
ToggleButton month = getTimeIntervalToggleButton(Res.get("time.month"), TemporalAdjusterModel.Interval.MONTH,
|
||||
timeIntervalToggleGroup, "toggle-center");
|
||||
ToggleButton week = getTimeIntervalToggleButton(Res.get("time.week"), TemporalAdjusterModel.Interval.WEEK,
|
||||
@ -302,7 +306,7 @@ public abstract class ChartView<T extends ChartViewModel<? extends ChartDataMode
|
||||
toggleBox.setAlignment(Pos.CENTER_LEFT);
|
||||
Region spacer = new Region();
|
||||
HBox.setHgrow(spacer, Priority.ALWAYS);
|
||||
toggleBox.getChildren().addAll(spacer, year, month, week, day);
|
||||
toggleBox.getChildren().addAll(spacer, year, halfYear, quarter, month, week, day);
|
||||
return toggleBox;
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,8 @@ public abstract class ChartViewModel<T extends ChartDataModel> extends Activatab
|
||||
case YEAR:
|
||||
dateFormatPatters = "yyyy";
|
||||
break;
|
||||
case HALF_YEAR:
|
||||
case QUARTER:
|
||||
case MONTH:
|
||||
dateFormatPatters = "MMM\nyyyy";
|
||||
break;
|
||||
|
@ -17,21 +17,58 @@
|
||||
|
||||
package bisq.desktop.components.chart;
|
||||
|
||||
import bisq.common.util.MathUtils;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.temporal.TemporalAdjuster;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static java.time.temporal.ChronoField.DAY_OF_YEAR;
|
||||
|
||||
@Slf4j
|
||||
public class TemporalAdjusterModel {
|
||||
private static final ZoneId ZONE_ID = ZoneId.systemDefault();
|
||||
|
||||
public enum Interval {
|
||||
YEAR(TemporalAdjusters.firstDayOfYear()),
|
||||
HALF_YEAR(temporal -> {
|
||||
long halfYear = temporal.range(DAY_OF_YEAR).getMaximum() / 2;
|
||||
int dayOfYear = 0;
|
||||
if (temporal instanceof LocalDate) {
|
||||
dayOfYear = ((LocalDate) temporal).getDayOfYear(); // getDayOfYear delivers 1-365 (366 in leap years)
|
||||
}
|
||||
if (dayOfYear <= halfYear) {
|
||||
return temporal.with(DAY_OF_YEAR, 1);
|
||||
} else {
|
||||
return temporal.with(DAY_OF_YEAR, halfYear + 1);
|
||||
}
|
||||
}),
|
||||
QUARTER(temporal -> {
|
||||
long quarter1 = temporal.range(DAY_OF_YEAR).getMaximum() / 4;
|
||||
long halfYear = temporal.range(DAY_OF_YEAR).getMaximum() / 2;
|
||||
long quarter3 = MathUtils.roundDoubleToLong(temporal.range(DAY_OF_YEAR).getMaximum() * 0.75, RoundingMode.FLOOR);
|
||||
int dayOfYear = 0;
|
||||
if (temporal instanceof LocalDate) {
|
||||
dayOfYear = ((LocalDate) temporal).getDayOfYear();
|
||||
}
|
||||
if (dayOfYear <= quarter1) {
|
||||
return temporal.with(DAY_OF_YEAR, 1);
|
||||
} else if (dayOfYear <= halfYear) {
|
||||
return temporal.with(DAY_OF_YEAR, quarter1 + 1);
|
||||
} else if (dayOfYear <= quarter3) {
|
||||
return temporal.with(DAY_OF_YEAR, halfYear + 1);
|
||||
} else {
|
||||
return temporal.with(DAY_OF_YEAR, quarter3 + 1);
|
||||
}
|
||||
}),
|
||||
MONTH(TemporalAdjusters.firstDayOfMonth()),
|
||||
WEEK(TemporalAdjusters.next(DayOfWeek.MONDAY)),
|
||||
DAY(TemporalAdjusters.ofDateAdjuster(d -> d));
|
||||
|
@ -125,7 +125,6 @@ public class DaoChartDataModel extends ChartDataModel {
|
||||
daoStateService.getBsqSupplyChanges(),
|
||||
getDateFilter()
|
||||
);
|
||||
|
||||
return totalSupplyByInterval;
|
||||
}
|
||||
|
||||
@ -137,10 +136,6 @@ public class DaoChartDataModel extends ChartDataModel {
|
||||
Map<Long, Long> burnedMap = getTotalBurnedByInterval();
|
||||
Map<Long, Long> reimbursementMap = getReimbursementByInterval();
|
||||
revenueByInterval = getMergedMap(burnedMap, reimbursementMap, (a, b) -> a - b);
|
||||
log.error("burnedMap {}", burnedMap);
|
||||
log.error("reimbursementMap {}", reimbursementMap);
|
||||
log.error("revenueByInterval {}", revenueByInterval);
|
||||
|
||||
return revenueByInterval;
|
||||
}
|
||||
|
||||
|
@ -112,8 +112,8 @@
|
||||
-bs-chart-dao-line4: -bs-turquoise-light;
|
||||
-bs-chart-dao-line5: -bs-yellow;
|
||||
-bs-chart-dao-line6: -bs-soft-red;
|
||||
-bs-chart-dao-line7: #fe01f1;
|
||||
-bs-chart-dao-line8: #d25800;
|
||||
-bs-chart-dao-line7: #ff6c00;
|
||||
-bs-chart-dao-line8: #fe01f1;
|
||||
|
||||
/* Monero orange color code */
|
||||
-xmr-orange: #f26822;
|
||||
|
Loading…
Reference in New Issue
Block a user