Skip to content

Commit

Permalink
allow first level only for donut chart in taxonomy
Browse files Browse the repository at this point in the history
  • Loading branch information
mierin12 committed Jan 5, 2025
1 parent ab4bc39 commit 88f035a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,29 @@ public List<Pair<TaxonomyNode, TaxonomyNode>> computeNodeList(TaxonomyModel mode

// classified nodes
TaxonomyNode node = model.getClassificationRootNode();
addChildren(answer, node, node.getChildren());
addChildren(answer, node, node.getChildren(), model.isSecuritiesInPieChartExcluded());

// add unclassified if included
if (!model.isUnassignedCategoryInChartsExcluded())
{
TaxonomyNode unassigned = model.getUnassignedNode();
List<TaxonomyNode> children = new ArrayList<>(unassigned.getChildren());
Collections.sort(children, (r, l) -> l.getActual().compareTo(r.getActual()));
addChildren(answer, unassigned, children);
if (model.isSecuritiesInPieChartExcluded())
{
answer.add(new Pair<>(unassigned, unassigned));
}
else
{
List<TaxonomyNode> children = new ArrayList<>(unassigned.getChildren());
Collections.sort(children, (r, l) -> l.getActual().compareTo(r.getActual()));
addChildren(answer, unassigned, children, model.isSecuritiesInPieChartExcluded());
}
}

return answer;
}

private void addChildren(List<Pair<TaxonomyNode, TaxonomyNode>> answer, TaxonomyNode parent,
List<TaxonomyNode> children)
List<TaxonomyNode> children, boolean firstLevelOnly)
{
for (TaxonomyNode child : children)
{
Expand All @@ -100,6 +107,10 @@ private void addChildren(List<Pair<TaxonomyNode, TaxonomyNode>> answer, Taxonomy
{
answer.add(new Pair<>(parent, child));
}
else if (child.isClassification() && firstLevelOnly)
{
answer.add(new Pair<>(child, child));
}
else if (child.isClassification())
{
List<TaxonomyNode> grandchildren = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import jakarta.inject.Inject;

import org.eclipse.e4.core.di.extensions.Preference;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

import name.abuchen.portfolio.ui.Messages;
import name.abuchen.portfolio.ui.UIConstants;
import name.abuchen.portfolio.ui.editor.AbstractFinanceView;
import name.abuchen.portfolio.ui.util.EmbeddedBrowser;
import name.abuchen.portfolio.ui.util.SimpleAction;
import name.abuchen.portfolio.ui.views.IPieChart;

/* package */class DonutViewer extends AbstractChartPage
Expand All @@ -28,6 +32,20 @@ public DonutViewer(AbstractFinanceView view, TaxonomyModel model, TaxonomyNodeRe
this.view = view;
}

@Override
public void configMenuAboutToShow(IMenuManager manager)
{
super.configMenuAboutToShow(manager);

Action action = new SimpleAction(Messages.LabelIncludeSecuritiesInPieChart, a -> {
getModel().setExcludeSecuritiesInPieChart(!getModel().isSecuritiesInPieChartExcluded());
getModel().fireTaxonomyModelChange(getModel().getVirtualRootNode());
chart.refresh(null);
});
action.setChecked(!getModel().isSecuritiesInPieChartExcluded());
manager.add(action);
}

@Override
public Control createControl(Composite container)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void configMenuAboutToShow(IMenuManager manager)

Action action = new SimpleAction(Messages.LabelIncludeSecuritiesInPieChart, a -> {
getModel().setExcludeSecuritiesInPieChart(!getModel().isSecuritiesInPieChartExcluded());
getModel().fireTaxonomyModelChange(getModel().getVirtualRootNode());
chart.refresh(null);
});
action.setChecked(!getModel().isSecuritiesInPieChartExcluded());
Expand Down

0 comments on commit 88f035a

Please sign in to comment.