Search in sources :

Example 56 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class IncomeExpensePayeePieChartDialogController method updateCharts.

private void updateCharts() {
    final Account account = accountComboBox.getValue();
    if (account != null) {
        final ObservableList<PieChart.Data>[] chartData = createPieDataSet(account);
        creditPieChart.setData(chartData[CREDIT]);
        debitPieChart.setData(chartData[DEBIT]);
        final NumberFormat numberFormat = CommodityFormat.getFullNumberFormat(account.getCurrencyNode());
        // Calculate the totals for percentage value
        final double creditTotal = chartData[CREDIT].parallelStream().mapToDouble(PieChart.Data::getPieValue).sum();
        final double debitTotal = chartData[DEBIT].parallelStream().mapToDouble(PieChart.Data::getPieValue).sum();
        final NumberFormat percentFormat = NumberFormat.getPercentInstance();
        percentFormat.setMaximumFractionDigits(1);
        percentFormat.setMinimumFractionDigits(1);
        // Install tooltips on the data after it has been added to the chart
        creditPieChart.getData().forEach(data -> Tooltip.install(data.getNode(), new Tooltip((data.getNode().getUserData() + "\n" + numberFormat.format(data.getPieValue()) + "(" + percentFormat.format(data.getPieValue() / creditTotal)) + ")")));
        // Install tooltips on the data after it has been added to the chart
        debitPieChart.getData().forEach(data -> Tooltip.install(data.getNode(), new Tooltip(((data.getNode().getUserData()) + "\n" + numberFormat.format(data.getPieValue()) + "(" + percentFormat.format(data.getPieValue() / debitTotal)) + ")")));
        creditPieChart.centerSubTitleProperty().set(numberFormat.format(creditTotal));
        debitPieChart.centerSubTitleProperty().set(numberFormat.format(debitTotal));
    } else {
        creditPieChart.setData(FXCollections.emptyObservableList());
        creditPieChart.setTitle("No Data");
        debitPieChart.setData(FXCollections.emptyObservableList());
        debitPieChart.setTitle("No Data");
    }
}
Also used : Account(jgnash.engine.Account) PieChart(javafx.scene.chart.PieChart) ObservableList(javafx.collections.ObservableList) Tooltip(javafx.scene.control.Tooltip) NumberFormat(java.text.NumberFormat)

Example 57 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class IncomeExpensePayeePieChartDialogController method getTransactions.

private List<TranTuple> getTransactions(final Account account, final List<TranTuple> transactions, final LocalDate startDate, final LocalDate endDate) {
    for (final Transaction transaction : account.getTransactions(startDate, endDate)) {
        TranTuple tuple = new TranTuple(account, transaction);
        transactions.add(tuple);
    }
    for (final Account child : account.getChildren(Comparators.getAccountByCode())) {
        getTransactions(child, transactions, startDate, endDate);
    }
    return transactions;
}
Also used : Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction)

Example 58 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class IncomeExpensePieChartDialogController method setParameters.

void setParameters(final AccountType accountType, final LocalDate startDate, final LocalDate endDate) {
    //PK: dates can be directly set
    startDatePicker.setValue(startDate);
    endDatePicker.setValue(endDate);
    //PK: We assume that the root of all income or expense accounts is one account under the root. Select that
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    for (final Account comboAccount : accountComboBox.getItems()) {
        if ((accountType == comboAccount.getAccountType()) && (comboAccount.getParent() == engine.getRootAccount())) {
            accountComboBox.setValue(comboAccount);
            break;
        }
    }
}
Also used : Account(jgnash.engine.Account) Engine(jgnash.engine.Engine)

Example 59 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class IncomeExpensePieChartDialogController method updateChart.

private void updateChart() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    final Account a = accountComboBox.getValue();
    if (a != null) {
        final CurrencyNode defaultCurrency = a.getCurrencyNode();
        final NumberFormat numberFormat = CommodityFormat.getFullNumberFormat(defaultCurrency);
        final ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList();
        double total = a.getTreeBalance(startDatePicker.getValue(), endDatePicker.getValue(), defaultCurrency).doubleValue();
        for (final Account child : a.getChildren()) {
            double balance = child.getTreeBalance(startDatePicker.getValue(), endDatePicker.getValue(), defaultCurrency).doubleValue();
            if (balance > 0 || balance < 0) {
                final String label = child.getName() + " - " + numberFormat.format(balance);
                final PieChart.Data data = new PieChart.Data(label, balance / total * 100);
                // nodes are created lazily.  Set the user data (Account) after the node is created
                data.nodeProperty().addListener((observable, oldValue, newValue) -> newValue.setUserData(child));
                pieChartData.add(data);
            }
        }
        pieChart.setData(pieChartData);
        final NumberFormat percentFormat = NumberFormat.getPercentInstance();
        percentFormat.setMaximumFractionDigits(1);
        percentFormat.setMinimumFractionDigits(1);
        // Install tooltips on the data after it has been added to the chart
        pieChart.getData().forEach(data -> Tooltip.install(data.getNode(), new Tooltip((((Account) data.getNode().getUserData()).getName() + " - " + percentFormat.format(data.getPieValue() / 100d)))));
        // Indicate the node can be clicked on to zoom into the next account level
        for (final PieChart.Data data : pieChart.getData()) {
            data.getNode().setOnMouseEntered(event -> {
                final Account account = (Account) data.getNode().getUserData();
                if (account.isParent()) {
                    data.getNode().setCursor(CustomCursor.getZoomInCursor());
                } else {
                    data.getNode().setCursor(Cursor.DEFAULT);
                }
                nodeFocused = true;
            });
            data.getNode().setOnMouseExited(event -> nodeFocused = false);
            // zoom in on click if this is a parent account
            data.getNode().setOnMouseClicked(event -> {
                if (data.getNode().getUserData() != null) {
                    if (((Account) data.getNode().getUserData()).isParent()) {
                        accountComboBox.setValue((Account) data.getNode().getUserData());
                    }
                }
            });
        }
        final String title;
        // pick an appropriate title
        if (a.getAccountType() == AccountType.EXPENSE) {
            title = resources.getString("Title.PercentExpense");
        } else if (a.getAccountType() == AccountType.INCOME) {
            title = resources.getString("Title.PercentIncome");
        } else {
            title = resources.getString("Title.PercentDist");
        }
        pieChart.setTitle(title);
        pieChart.centerTitleProperty().set(accountComboBox.getValue().getName());
        pieChart.centerSubTitleProperty().set(numberFormat.format(total));
    // abs() on all values won't work if children aren't of uniform sign,
    // then again, this chart is not right to display those trees
    //boolean negate = total != null && total.signum() < 0;
    } else {
        pieChart.setData(FXCollections.emptyObservableList());
        pieChart.setTitle("No Data");
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) PieChart(javafx.scene.chart.PieChart) Tooltip(javafx.scene.control.Tooltip) Engine(jgnash.engine.Engine) NumberFormat(java.text.NumberFormat)

Example 60 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class IncomeExpensePieChartDialogController method initialize.

@FXML
public void initialize() {
    // Respect animation preference
    pieChart.animatedProperty().set(Options.animationsEnabledProperty().get());
    accountComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null && newValue.getParent().getAccountType() != AccountType.ROOT) {
            pieChart.setCursor(CustomCursor.getZoomOutCursor());
        } else {
            pieChart.setCursor(Cursor.DEFAULT);
        }
    });
    final Preferences preferences = Preferences.userNodeForPackage(IncomeExpensePieChartDialogController.class).node("IncomeExpensePieChart");
    accountComboBox.setPredicate(new ParentAccountPredicate());
    if (preferences.get(LAST_ACCOUNT, null) != null) {
        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
        Objects.requireNonNull(engine);
        final Account account = engine.getAccountByUuid(preferences.get(LAST_ACCOUNT, null));
        if (account != null) {
            accountComboBox.setValue(account);
        }
    }
    startDatePicker.setValue(endDatePicker.getValue().minusYears(1));
    final ChangeListener<Object> listener = (observable, oldValue, newValue) -> {
        if (newValue != null) {
            updateChart();
            preferences.put(LAST_ACCOUNT, accountComboBox.getValue().getUuid());
        }
    };
    accountComboBox.valueProperty().addListener(listener);
    startDatePicker.valueProperty().addListener(listener);
    endDatePicker.valueProperty().addListener(listener);
    pieChart.setLegendSide(Side.BOTTOM);
    // zoom out
    pieChart.setOnMouseClicked(event -> {
        if (!nodeFocused && accountComboBox.getValue().getParent().getAccountType() != AccountType.ROOT) {
            accountComboBox.setValue(accountComboBox.getValue().getParent());
        }
    });
    // Push the initial load to the end of the platform thread for better startup and nicer visual effect
    Platform.runLater(this::updateChart);
}
Also used : DoughnutChart(jgnash.uifx.control.DoughnutChart) Scene(javafx.scene.Scene) Engine(jgnash.engine.Engine) EngineFactory(jgnash.engine.EngineFactory) FXCollections(javafx.collections.FXCollections) StackPane(javafx.scene.layout.StackPane) ParentAccountPredicate(jgnash.util.function.ParentAccountPredicate) Side(javafx.geometry.Side) AccountComboBox(jgnash.uifx.control.AccountComboBox) NumberFormat(java.text.NumberFormat) ResourceBundle(java.util.ResourceBundle) AccountType(jgnash.engine.AccountType) Tooltip(javafx.scene.control.Tooltip) CurrencyNode(jgnash.engine.CurrencyNode) ObjectProperty(javafx.beans.property.ObjectProperty) InjectFXML(jgnash.uifx.util.InjectFXML) Preferences(java.util.prefs.Preferences) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Cursor(javafx.scene.Cursor) PieChart(javafx.scene.chart.PieChart) CommodityFormat(jgnash.text.CommodityFormat) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) LocalDate(java.time.LocalDate) CustomCursor(jgnash.resource.cursor.CustomCursor) Account(jgnash.engine.Account) ObservableList(javafx.collections.ObservableList) ChangeListener(javafx.beans.value.ChangeListener) DatePickerEx(jgnash.uifx.control.DatePickerEx) Options(jgnash.uifx.Options) Account(jgnash.engine.Account) ParentAccountPredicate(jgnash.util.function.ParentAccountPredicate) Preferences(java.util.prefs.Preferences) Engine(jgnash.engine.Engine) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Aggregations

Account (jgnash.engine.Account)132 Engine (jgnash.engine.Engine)44 BigDecimal (java.math.BigDecimal)40 CurrencyNode (jgnash.engine.CurrencyNode)28 Transaction (jgnash.engine.Transaction)27 ArrayList (java.util.ArrayList)22 LocalDate (java.time.LocalDate)21 ResourceBundle (java.util.ResourceBundle)19 RootAccount (jgnash.engine.RootAccount)18 List (java.util.List)15 AccountType (jgnash.engine.AccountType)15 NumberFormat (java.text.NumberFormat)14 FXML (javafx.fxml.FXML)13 EngineFactory (jgnash.engine.EngineFactory)13 Objects (java.util.Objects)12 Collections (java.util.Collections)11 InvestmentTransaction (jgnash.engine.InvestmentTransaction)11 Tooltip (javafx.scene.control.Tooltip)10 Preferences (java.util.prefs.Preferences)9 Platform (javafx.application.Platform)9