Skip to content

Commit

Permalink
Added new (optional) Y axis with percentage
Browse files Browse the repository at this point in the history
* chart options to show/hide horizontal lines for both axis

Issue: portfolio-performance#3006
Signed-off-by: OnkelDok <[email protected]>
[squashed commits; rebased to master]
Signed-off-by: Andreas Buchen <[email protected]>
  • Loading branch information
OnkelDok authored and christen90 committed Aug 2, 2023
1 parent 014282a commit 13fa370
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ public class Messages extends NLS
public static String LabelChartDetailMovingAverage_100days;
public static String LabelChartDetailMovingAverage_200days;
public static String LabelChartDetailSettings;
public static String LabelChartDetailSettingsShowHorizontalLinesMain;
public static String LabelChartDetailSettingsShowHorizontalLinesPercentage;
public static String LabelChartDetailSettingsShowLimits;
public static String LabelChartDetailSettingsShowMarkerLines;
public static String LabelChartDetailSettingsShowDataLabel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,10 @@ LabelChartDetailMovingAverage_90days = 90 days

LabelChartDetailSettings = Settings

LabelChartDetailSettingsShowHorizontalLinesMain = Horizontal lines (Value axis)

LabelChartDetailSettingsShowHorizontalLinesPercentage = Horizontal lines (Percentage axis)

LabelChartDetailSettingsShowDataLabel = Show data labels

LabelChartDetailSettingsShowLimits = Show limits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,10 @@ LabelChartDetailMovingAverage_90days = 90 dn\u016F

LabelChartDetailSettings = Nastaven\u00ED

LabelChartDetailSettingsShowHorizontalLinesMain = Vodorovn\u00E9 \u010D\u00E1ry (osa hodnot)

LabelChartDetailSettingsShowHorizontalLinesPercentage = Vodorovné \u010D\u00E1ry (procentu\u00E1ln\u00ED osa)

LabelChartDetailSettingsShowDataLabel = Zobrazit popisky dat

LabelChartDetailSettingsShowLimits = Zobrazit limity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,10 @@ LabelChartDetailMovingAverage_90days = 90 Tage

LabelChartDetailSettings = Einstellungen

LabelChartDetailSettingsShowHorizontalLinesMain = Horizontale Linien (Werte-Achse)

LabelChartDetailSettingsShowHorizontalLinesPercentage = Horizontale Linien (Prozent-Achse)

LabelChartDetailSettingsShowDataLabel = Zahlenwerte anzeigen

LabelChartDetailSettingsShowLimits = Zeige Limits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,10 @@ LabelChartDetailMovingAverage_90days = 90 d\u00EDas

LabelChartDetailSettings = Opini\u00F3n

LabelChartDetailSettingsShowHorizontalLinesMain = L\u00EDneas horizontales (eje del valor)

LabelChartDetailSettingsShowHorizontalLinesPercentage = L\u00EDneas horizontales (eje porcentual)

LabelChartDetailSettingsShowDataLabel = Mostrar etiquetas de datos

LabelChartDetailSettingsShowLimits = Mostrar l\u00EDmites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,10 @@ LabelChartDetailMovingAverage_90days = 90 jours

LabelChartDetailSettings = Param\u00E8tres

LabelChartDetailSettingsShowHorizontalLinesMain = Lignes horizontales (axe des valeurs)

LabelChartDetailSettingsShowHorizontalLinesPercentage = Lignes horizontales (axe des pourcentages)

LabelChartDetailSettingsShowDataLabel = Afficher \u00E9tiquettes de donn\u00E9es

LabelChartDetailSettingsShowLimits = = Afficher les limites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,10 @@ LabelChartDetailMovingAverage_90days = 90 giorni

LabelChartDetailSettings = Impostazioni

LabelChartDetailSettingsShowHorizontalLinesMain = Linee orizzontali (asse del valore)

LabelChartDetailSettingsShowHorizontalLinesPercentage = Linee orizzontali (asse percentuale)

LabelChartDetailSettingsShowDataLabel = Mostra etichette dati

LabelChartDetailSettingsShowLimits = Mostra limiti
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,10 @@ LabelChartDetailMovingAverage_90days = 90 dagen
LabelChartDetailSettings = Instelling
LabelChartDetailSettingsShowHorizontalLinesMain = Horizontale lijnen (waarde-as)
LabelChartDetailSettingsShowHorizontalLinesPercentage = Horizontale lijnen (percentage-as)
LabelChartDetailSettingsShowDataLabel = Toon datalabels
LabelChartDetailSettingsShowLimits = = Toon Grenzen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,10 @@ LabelChartDetailMovingAverage_90days = 90 dias

LabelChartDetailSettings = Defini\u00E7\u00F5es

LabelChartDetailSettingsShowHorizontalLinesMain = Linhas horizontais (Eixo de valor)

LabelChartDetailSettingsShowHorizontalLinesPercentage = Linhas horizontais (Eixo percentual)

LabelChartDetailSettingsShowDataLabel = Mostrar r\u00F3tulos de dados

LabelChartDetailSettingsShowLimits = = Mostrar limites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,10 @@ LabelChartDetailMovingAverage_90days = 90 \u0434\u043D\u0435\u0439

LabelChartDetailSettings = \u041D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0438

LabelChartDetailSettingsShowHorizontalLinesMain = \u0413\u043E\u0440\u0438\u0437\u043E\u043D\u0442\u0430\u043B\u044C\u043D\u044B\u0435 \u043B\u0438\u043D\u0438\u0438 (\u043E\u0441\u044C \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0439)

LabelChartDetailSettingsShowHorizontalLinesPercentage = \u0413\u043E\u0440\u0438\u0437\u043E\u043D\u0442\u0430\u043B\u044C\u043D\u044B\u0435 \u043B\u0438\u043D\u0438\u0438 (\u043E\u0441\u044C \u043F\u0440\u043E\u0446\u0435\u043D\u0442\u043E\u0432)

LabelChartDetailSettingsShowDataLabel = \u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u043C\u0435\u0442\u043A\u0438 \u0434\u0430\u043D\u043D\u044B\u0445

LabelChartDetailSettingsShowLimits = \u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u043E\u0433\u0440\u0430\u043D\u0438\u0447\u0435\u043D\u0438\u044F
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,10 @@ LabelChartDetailMovingAverage_90days = 90 dn\u00ED
LabelChartDetailSettings = Nastavenia
LabelChartDetailSettingsShowHorizontalLinesMain = Vodorovn\u00E9 \u010Diary (hodnotov\u00E1 os)
LabelChartDetailSettingsShowHorizontalLinesPercentage = Vodorovn\u00E9 \u010Diary (percentu\u00E1lna os)
LabelChartDetailSettingsShowDataLabel = Zobrazi\u0165 popisky d\u00E1t
LabelChartDetailSettingsShowLimits = Zobrazi\u0165 limity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package name.abuchen.portfolio.ui.util.chart;

import java.text.DecimalFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
Expand Down Expand Up @@ -105,6 +106,15 @@ public TimelineChart(Composite parent)
y2Axis.getTick().setVisible(false);
y2Axis.getGrid().setStyle(LineStyle.NONE);
y2Axis.setPosition(Position.Primary);

// 3rd y axis (percentage)
int axisId3rd = getAxisSet().createYAxis();
IAxis y3Axis = getAxisSet().getYAxis(axisId3rd);
y3Axis.getTitle().setVisible(false);
y3Axis.getTick().setVisible(false);
y3Axis.getTick().setFormat(new DecimalFormat("+#.##%;-#.##%")); //$NON-NLS-1$
y3Axis.getGrid().setStyle(LineStyle.NONE);
y3Axis.setPosition(Position.Primary);

((IPlotArea) getPlotArea()).addCustomPaintListener(new ICustomPaintListener()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ private enum ChartDetails
SHOW_MARKER_LINES(Messages.LabelChartDetailSettingsShowMarkerLines), //
SHOW_DATA_LABELS(Messages.LabelChartDetailSettingsShowDataLabel), //
SHOW_MISSING_TRADING_DAYS(Messages.LabelChartDetailSettingsShowMissingTradingDays), //
SHOW_LIMITS(Messages.LabelChartDetailSettingsShowLimits);
SHOW_LIMITS(Messages.LabelChartDetailSettingsShowLimits), //
SHOW_MAIN_HORIZONTAL_LINES(Messages.LabelChartDetailSettingsShowHorizontalLinesMain), //
SHOW_PERCENTAGE_HORIZONTAL_LINES(Messages.LabelChartDetailSettingsShowHorizontalLinesPercentage);

private final String label;

Expand Down Expand Up @@ -391,7 +393,7 @@ public static ChartRange createFor(List<SecurityPrice> prices, ChartInterval cha
private IntervalOption intervalOption = IntervalOption.Y2;

private EnumSet<ChartDetails> chartConfig = EnumSet.of(ChartDetails.INVESTMENT, ChartDetails.EVENTS,
ChartDetails.SCALING_LINEAR);
ChartDetails.SCALING_LINEAR, ChartDetails.SHOW_MAIN_HORIZONTAL_LINES);

private List<PaintListener> customPaintListeners = new ArrayList<>();
private List<Transaction> customTooltipEvents = new ArrayList<>();
Expand Down Expand Up @@ -669,6 +671,9 @@ private void chartConfigAboutToShow(IMenuManager manager)
subMenuChartSettings.add(addMenuAction(ChartDetails.SHOW_MARKER_LINES));
subMenuChartSettings.add(addMenuAction(ChartDetails.SHOW_DATA_LABELS));
subMenuChartSettings.add(addMenuAction(ChartDetails.SHOW_MISSING_TRADING_DAYS));
subMenuChartSettings.add(new Separator());
subMenuChartSettings.add(addMenuAction(ChartDetails.SHOW_MAIN_HORIZONTAL_LINES));
subMenuChartSettings.add(addMenuAction(ChartDetails.SHOW_PERCENTAGE_HORIZONTAL_LINES));
manager.add(subMenuChartScaling);
manager.add(subMenuChartDevelopment);
manager.add(subMenuChartMarker);
Expand Down Expand Up @@ -798,7 +803,7 @@ private void updateChart()
double[] valuesRelativePositive = new double[range.size];
double[] valuesRelativeNegative = new double[range.size];
double[] valuesZeroLine = new double[range.size];
double firstQuote = 0;
Double firstQuote = null;

// Disable SWT antialias for more than 1000 records due to SWT
// performance issue in Drawing
Expand Down Expand Up @@ -879,14 +884,37 @@ private void updateChart()

IAxis yAxis1st = chart.getAxisSet().getYAxis(0);
IAxis yAxis2nd = chart.getAxisSet().getYAxis(1);
IAxis yAxis3rd = chart.getAxisSet().getYAxis(2);

if (firstQuote == null)
firstQuote = (prices.get(range.start).getValue() / Values.Quote.divider());

yAxis2nd.setRange(
new Range(yAxis1st.getRange().lower - firstQuote, yAxis1st.getRange().upper - firstQuote));

if (firstQuote != 0)
{
yAxis3rd.setRange(new Range(yAxis1st.getRange().lower / firstQuote - 1,
yAxis1st.getRange().upper / firstQuote - 1));
// hide percentage axis in logarithmic mode
yAxis3rd.getTick().setVisible(!chartConfig.contains(ChartDetails.SCALING_LOG));
}

yAxis1st.enableLogScale(chartConfig.contains(ChartDetails.SCALING_LOG));
yAxis2nd.enableLogScale(chartConfig.contains(ChartDetails.SCALING_LOG));

yAxis1st.getTick().setVisible(true);

if (chartConfig.contains(ChartDetails.SHOW_MAIN_HORIZONTAL_LINES) || !yAxis3rd.getTick().isVisible())
yAxis1st.getGrid().setStyle(LineStyle.DOT);
else
yAxis1st.getGrid().setStyle(LineStyle.NONE);

if (chartConfig.contains(ChartDetails.SHOW_PERCENTAGE_HORIZONTAL_LINES) && yAxis3rd.getTick().isVisible())
yAxis3rd.getGrid().setStyle(LineStyle.DOT);
else
yAxis3rd.getGrid().setStyle(LineStyle.NONE);

if (chartConfig.contains(ChartDetails.SHOW_MISSING_TRADING_DAYS))
{
TradeCalendar tradeCalendar = TradeCalendarManager.getInstance(security);
Expand Down Expand Up @@ -1017,6 +1045,7 @@ private void addLimitLines(ChartRange range)
// attributes
Optional<AttributeType> attributeName = ReadOnlyClient.unwrap(client).getSettings().getAttributeTypes()
.filter(attr -> attr.getId().equals(key)).findFirst();

// could not find name of limit attribute --> don't draw
if (attributeName.isEmpty())
return;
Expand Down

0 comments on commit 13fa370

Please sign in to comment.