Skip to content

Commit

Permalink
Merge pull request codinguser#426 from aint/bar_chart_legend_crash_fix
Browse files Browse the repository at this point in the history
Fix BarChart legend crash
  • Loading branch information
codinguser committed Nov 18, 2015
2 parents 0a82713 + 7e36bd9 commit 5411b4b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,22 @@ private BarData getData() {
double balance = mAccountsDbAdapter.getAccountsBalance(
Collections.singletonList(account.getUID()), start, end).asDouble();
if (balance != 0) {
stack.add((float) balance);

String accountName = account.getName();
while (labels.contains(accountName)) {
if (!accountToColorMap.containsKey(account.getUID())) {
for (String label : labels) {
if (label.equals(accountName)) {
accountName += " ";
}
}
} else {
break;
}
}
labels.add(accountName);

if (!accountToColorMap.containsKey(account.getUID())) {
Integer color;
if (mUseAccountColor) {
Expand All @@ -221,10 +237,8 @@ private BarData getData() {
}
accountToColorMap.put(account.getUID(), color);
}

stack.add((float) balance);
labels.add(account.getName());
colors.add(accountToColorMap.get(account.getUID()));

Log.d(TAG, mAccountType + tmpDate.toString(" MMMM yyyy ") + account.getName() + " = " + stack.get(stack.size() - 1));
}
}
Expand Down Expand Up @@ -439,7 +453,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
Legend legend = mChart.getLegend();
if (!legend.isLegendCustom()) {
Toast.makeText(getActivity(), R.string.toast_legend_too_long, Toast.LENGTH_LONG).show();
item.setChecked(false);
} else {
item.setChecked(!mChart.getLegend().isEnabled());
legend.setEnabled(!mChart.getLegend().isEnabled());
mChart.invalidate();
}
Expand Down Expand Up @@ -474,8 +490,7 @@ public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
} else {
sum = entry.getNegativeSum() + entry.getPositiveSum();
}
Log.w(TAG, "sum2 = " + sum);
selectedValueTextView.setText(String.format(SELECTED_VALUE_PATTERN, label, value, value / sum * 100));
selectedValueTextView.setText(String.format(SELECTED_VALUE_PATTERN, label.trim(), value, value / sum * 100));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {

mChart.setCenterTextSize(PieChartFragment.CENTER_TEXT_SIZE);
mChart.setDescription("");
mChart.setDrawSliceText(false);
mChart.getLegend().setEnabled(true);
mChart.getLegend().setWordWrapEnabled(true);
mChart.getLegend().setForm(LegendForm.CIRCLE);
Expand Down

0 comments on commit 5411b4b

Please sign in to comment.