Fix chart colors
This commit is contained in:
@@ -21,6 +21,7 @@ import java.time.LocalDate;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.format.DateTimeParseException;
|
import java.time.format.DateTimeParseException;
|
||||||
import javafx.util.StringConverter;
|
import javafx.util.StringConverter;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -62,6 +63,12 @@ public class AnalyticsController {
|
|||||||
@FXML
|
@FXML
|
||||||
private BarChart<String, Number> chartEmployeePerformance;
|
private BarChart<String, Number> chartEmployeePerformance;
|
||||||
|
|
||||||
|
private static final String SALES_COLOR = "#ff6b35";
|
||||||
|
private static final String REVENUE_COLOR = "#4ecdc4";
|
||||||
|
private static final String QUANTITY_COLOR = "#ff9f1c";
|
||||||
|
private static final String EMPLOYEE_COLOR = "#1a759f";
|
||||||
|
private static final List<String> PIE_COLORS = List.of("#ff6b35", "#4ecdc4", "#1a759f", "#ff9f1c", "#577590", "#90be6d");
|
||||||
|
|
||||||
private final NumberFormat currency = NumberFormat.getCurrencyInstance(Locale.CANADA);
|
private final NumberFormat currency = NumberFormat.getCurrencyInstance(Locale.CANADA);
|
||||||
private final NumberFormat wholeNumber = NumberFormat.getIntegerInstance();
|
private final NumberFormat wholeNumber = NumberFormat.getIntegerInstance();
|
||||||
private final DateTimeFormatter chartDateFormatter = DateTimeFormatter.ofPattern("MMM d", Locale.CANADA);
|
private final DateTimeFormatter chartDateFormatter = DateTimeFormatter.ofPattern("MMM d", Locale.CANADA);
|
||||||
@@ -191,6 +198,7 @@ public class AnalyticsController {
|
|||||||
axisSalesDate.setUpperBound(upperBound);
|
axisSalesDate.setUpperBound(upperBound);
|
||||||
chartSalesOverTime.getData().clear();
|
chartSalesOverTime.getData().clear();
|
||||||
chartSalesOverTime.getData().add(series);
|
chartSalesOverTime.getData().add(series);
|
||||||
|
applyLineChartColor(chartSalesOverTime, SALES_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatChartDate(String date) {
|
private String formatChartDate(String date) {
|
||||||
@@ -217,6 +225,7 @@ public class AnalyticsController {
|
|||||||
|
|
||||||
chartTopRevenue.getData().clear();
|
chartTopRevenue.getData().clear();
|
||||||
chartTopRevenue.getData().add(series);
|
chartTopRevenue.getData().add(series);
|
||||||
|
applyBarChartColor(chartTopRevenue, REVENUE_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadTopProductsByQuantity(DashboardResponse dashboard) throws Exception {
|
private void loadTopProductsByQuantity(DashboardResponse dashboard) throws Exception {
|
||||||
@@ -231,6 +240,7 @@ public class AnalyticsController {
|
|||||||
|
|
||||||
chartTopQuantity.getData().clear();
|
chartTopQuantity.getData().clear();
|
||||||
chartTopQuantity.getData().add(series);
|
chartTopQuantity.getData().add(series);
|
||||||
|
applyBarChartColor(chartTopQuantity, QUANTITY_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadPaymentMethodDistribution(List<SaleResponse> sales) throws Exception {
|
private void loadPaymentMethodDistribution(List<SaleResponse> sales) throws Exception {
|
||||||
@@ -243,7 +253,11 @@ public class AnalyticsController {
|
|||||||
|
|
||||||
chartPaymentMethods.getData().clear();
|
chartPaymentMethods.getData().clear();
|
||||||
|
|
||||||
for (Map.Entry<String, Long> entry : paymentMethodCount.entrySet()) {
|
List<Map.Entry<String, Long>> paymentEntries = paymentMethodCount.entrySet().stream()
|
||||||
|
.sorted(Map.Entry.comparingByKey())
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Long> entry : paymentEntries) {
|
||||||
PieChart.Data slice = new PieChart.Data(
|
PieChart.Data slice = new PieChart.Data(
|
||||||
entry.getKey() + " (" + entry.getValue() + ")",
|
entry.getKey() + " (" + entry.getValue() + ")",
|
||||||
entry.getValue()
|
entry.getValue()
|
||||||
@@ -252,6 +266,7 @@ public class AnalyticsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
chartPaymentMethods.setLabelsVisible(false);
|
chartPaymentMethods.setLabelsVisible(false);
|
||||||
|
applyPieChartColors();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadEmployeePerformance(List<SaleResponse> sales) throws Exception {
|
private void loadEmployeePerformance(List<SaleResponse> sales) throws Exception {
|
||||||
@@ -266,12 +281,55 @@ public class AnalyticsController {
|
|||||||
XYChart.Series<String, Number> series = new XYChart.Series<>();
|
XYChart.Series<String, Number> series = new XYChart.Series<>();
|
||||||
series.setName("Revenue");
|
series.setName("Revenue");
|
||||||
|
|
||||||
for (Map.Entry<String, Double> entry : employeeRevenue.entrySet()) {
|
List<Map.Entry<String, Double>> employeeEntries = employeeRevenue.entrySet().stream()
|
||||||
|
.sorted(Map.Entry.comparingByKey())
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Double> entry : employeeEntries) {
|
||||||
series.getData().add(new XYChart.Data<>(entry.getKey(), entry.getValue()));
|
series.getData().add(new XYChart.Data<>(entry.getKey(), entry.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
chartEmployeePerformance.getData().clear();
|
chartEmployeePerformance.getData().clear();
|
||||||
chartEmployeePerformance.getData().add(series);
|
chartEmployeePerformance.getData().add(series);
|
||||||
|
applyBarChartColor(chartEmployeePerformance, EMPLOYEE_COLOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyLineChartColor(LineChart<Number, Number> chart, String color) {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
for (XYChart.Series<Number, Number> series : chart.getData()) {
|
||||||
|
if (series.getNode() != null) {
|
||||||
|
series.getNode().setStyle("-fx-stroke: " + color + ";");
|
||||||
|
}
|
||||||
|
for (XYChart.Data<Number, Number> data : series.getData()) {
|
||||||
|
if (data.getNode() != null) {
|
||||||
|
data.getNode().setStyle("-fx-background-color: white, " + color + ";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private <X, Y> void applyBarChartColor(XYChart<X, Y> chart, String color) {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
for (XYChart.Series<X, Y> series : chart.getData()) {
|
||||||
|
for (XYChart.Data<X, Y> data : series.getData()) {
|
||||||
|
if (data.getNode() != null) {
|
||||||
|
data.getNode().setStyle("-fx-bar-fill: " + color + ";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyPieChartColors() {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
for (int i = 0; i < chartPaymentMethods.getData().size(); i++) {
|
||||||
|
PieChart.Data slice = chartPaymentMethods.getData().get(i);
|
||||||
|
if (slice.getNode() != null) {
|
||||||
|
slice.getNode().setStyle("-fx-pie-color: " + PIE_COLORS.get(i % PIE_COLORS.size()) + ";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
|||||||
Reference in New Issue
Block a user