From 9f44ee6a75ca7624d75615877d5d520da8ff8e52 Mon Sep 17 00:00:00 2001 From: Nirus2000 Date: Tue, 31 Oct 2023 11:59:51 +0100 Subject: [PATCH] Improve the dark and light theme and move the values in the css handler Issue: #3621 #3614 Signed-off-by: Nirus2000 [removed unnecessary changes due to format changes; rebased to master] Signed-off-by: Andreas Buchen --- name.abuchen.portfolio.ui/css/shared/dark.css | 11 +++ .../css/shared/light.css | 11 +++ name.abuchen.portfolio.ui/plugin.xml | 24 ++++++ .../ui/theme/SecuritiesChartCSSHandler.java | 55 ++++++++++++-- .../portfolio/ui/views/SecuritiesChart.java | 73 ++++++++++++++----- 5 files changed, 152 insertions(+), 22 deletions(-) diff --git a/name.abuchen.portfolio.ui/css/shared/dark.css b/name.abuchen.portfolio.ui/css/shared/dark.css index a0ebeba2ab..b6cceee0d1 100644 --- a/name.abuchen.portfolio.ui/css/shared/dark.css +++ b/name.abuchen.portfolio.ui/css/shared/dark.css @@ -57,6 +57,17 @@ CustomColors { SecuritiesChart { quote-color: #4DDAFF; + quote-area-positive-color: #23b0d7; + quote-area-negative-color: #ff9d4d; + + purchase-event-color: #1FD127; + sale-event-color: #FF2B30; + dividend-event-color: #8063A8; + + extreme-marker-high-color: #1AAD21; + extreme-marker-low-color: #A8272A; + + non-trading-color: #542E1F; } * { diff --git a/name.abuchen.portfolio.ui/css/shared/light.css b/name.abuchen.portfolio.ui/css/shared/light.css index 1f21edf1a3..658cb1ae2b 100644 --- a/name.abuchen.portfolio.ui/css/shared/light.css +++ b/name.abuchen.portfolio.ui/css/shared/light.css @@ -92,6 +92,17 @@ CustomColors { SecuritiesChart { quote-color: #4D34EB; + quote-area-positive-color: #5A72E2; + quote-area-negative-color: #E25B5A; + + purchase-event-color: #1AAD21; + sale-event-color: #FF2B30; + dividend-event-color: #800080; + + extreme-marker-high-color: #00930F; + extreme-marker-low-color: #800000; + + non-trading-color: #FF8959; } * { diff --git a/name.abuchen.portfolio.ui/plugin.xml b/name.abuchen.portfolio.ui/plugin.xml index 24cdd7e8e1..b73995bb2d 100644 --- a/name.abuchen.portfolio.ui/plugin.xml +++ b/name.abuchen.portfolio.ui/plugin.xml @@ -122,6 +122,30 @@ + + + + + + + + + + + + + + + + propertyMap = new HashMap<>(); + + public SecuritiesChartCSSHandler() + { + initializePropertyMap(); + } + + private void initializePropertyMap() + { + propertyMap.put("quote-color", (chart, value) -> chart.setQuoteColor(getColor(value))); //$NON-NLS-1$ + propertyMap.put("quote-area-positive-color", (chart, value) -> chart.setQuoteAreaPositive(getColor(value))); //$NON-NLS-1$ + propertyMap.put("quote-area-negative-color", (chart, value) -> chart.setQuoteAreaNegative(getColor(value))); //$NON-NLS-1$ + propertyMap.put("purchase-event-color", (chart, value) -> chart.setPurchaseColor(getColor(value))); //$NON-NLS-1$ + propertyMap.put("sale-event-color", (chart, value) -> chart.setSaleColor(getColor(value))); //$NON-NLS-1$ + propertyMap.put("dividend-event-color", (chart, value) -> chart.setDividendColor(getColor(value))); //$NON-NLS-1$ + propertyMap.put("extreme-marker-high-color", //$NON-NLS-1$ + (chart, value) -> chart.setExtremeMarkerHighColor(getColor(value))); + propertyMap.put("extreme-marker-low-color", (chart, value) -> chart.setExtremeMarkerLowColor(getColor(value))); //$NON-NLS-1$ + propertyMap.put("non-trading-color", (chart, value) -> chart.setNonTradingColor(getColor(value))); //$NON-NLS-1$ + } + @Override public boolean applyCSSProperty(Object element, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception @@ -18,17 +57,23 @@ public boolean applyCSSProperty(Object element, String property, CSSValue value, if (element instanceof SecuritiesChartElementAdapter adapter) { SecuritiesChart chart = adapter.getSecuritiesChart(); + ColorSetter colorSetter = propertyMap.get(property); - switch (property) + if (colorSetter != null) { - case "quote-color": //$NON-NLS-1$ - chart.setQuoteColor(Colors.getColor(CSSSWTColorHelper.getRGBA(value).rgb)); - break; - default: + colorSetter.setColor(chart, value); } } return false; } + /** + * Converts a CSSValue to a Color. + */ + private Color getColor(CSSValue value) + { + return Colors.getColor(CSSSWTColorHelper.getRGBA(value).rgb); + } + } diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java index c636d14694..a522ab8024 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java @@ -346,13 +346,17 @@ public static ChartRange createFor(List prices, ChartInterval cha } private Color colorQuote; + private Color colorQuoteAreaPositive; + private Color colorQuoteAreaNegative; - private static final Color colorEventPurchase = Colors.getColor(26, 173, 33); // #1AAD21 - private static final Color colorEventSale = Colors.getColor(255, 43, 48); // #FF2B30 - private static final Color colorEventDividend = Colors.getColor(128, 99, 168); // #8063A8 + private Color colorEventPurchase; + private Color colorEventSale; + private Color colorEventDividend; - private static final Color colorHigh = Colors.getColor(0, 147, 15); // #00930F - private static final Color colorLow = Colors.getColor(168, 39, 42); // #A8272A + private Color colorExtremeMarkerHigh; + private Color colorExtremeMarkerLow; + + private Color colorNonTradingDay; private static final Color colorFifoPurchasePrice = Colors.getColor(226, 122, 121); // #E27A79 private static final Color colorMovingAveragePurchasePrice = Colors.getColor(150, 82, 81); // #965251 @@ -375,11 +379,6 @@ public static ChartRange createFor(List prices, ChartInterval cha private static final Color colorEMA6 = Colors.getColor(119, 107, 200); // #776BC8 private static final Color colorEMA7 = Colors.getColor(200, 107, 200); // #C86BB3 - private static final Color colorAreaPositive = Colors.getColor(90, 114, 226); // #5A72E2 - private static final Color colorAreaNegative = Colors.getColor(226, 91, 90); // #E25B5A - - private static final Color colorNonTradingDay = Colors.getColor(255, 137, 89); // #FF8959 - private static final String PREF_KEY = "security-chart-details"; //$NON-NLS-1$ private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("d LLL"); //$NON-NLS-1$ @@ -450,6 +449,46 @@ public void setQuoteColor(Color color) this.colorQuote = color; } + public void setQuoteAreaNegative(Color color) + { + this.colorQuoteAreaNegative = color; + } + + public void setQuoteAreaPositive(Color color) + { + this.colorQuoteAreaPositive = color; + } + + public void setPurchaseColor(Color color) + { + this.colorEventPurchase = color; + } + + public void setSaleColor(Color color) + { + this.colorEventSale = color; + } + + public void setDividendColor(Color color) + { + this.colorEventDividend = color; + } + + public void setExtremeMarkerHighColor(Color color) + { + this.colorExtremeMarkerHigh = color; + } + + public void setExtremeMarkerLowColor(Color color) + { + this.colorExtremeMarkerLow = color; + } + + public void setNonTradingColor(Color color) + { + this.colorNonTradingDay = color; + } + private void setupTooltip() { TimelineChartToolTip toolTip = chart.getToolTip(); @@ -875,15 +914,15 @@ private void updateChart() Messages.LabelChartDetailChartDevelopmentClosing + "Negative"); //$NON-NLS-1$ lineSeries2ndNegative.setSymbolType(PlotSymbolType.NONE); lineSeries2ndNegative.setYAxisId(1); - configureSeriesPainter(lineSeries2ndNegative, javaDates, valuesRelativeNegative, colorAreaNegative, 1, - LineStyle.SOLID, true, false); + configureSeriesPainter(lineSeries2ndNegative, javaDates, valuesRelativeNegative, colorQuoteAreaNegative, + 1, LineStyle.SOLID, true, false); ILineSeries lineSeries2ndPositive = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, Messages.LabelChartDetailChartDevelopmentClosing + "Positive"); //$NON-NLS-1$ lineSeries2ndPositive.setSymbolType(PlotSymbolType.NONE); lineSeries2ndPositive.setYAxisId(1); - configureSeriesPainter(lineSeries2ndPositive, javaDates, valuesRelativePositive, colorAreaPositive, 1, - LineStyle.SOLID, true, false); + configureSeriesPainter(lineSeries2ndPositive, javaDates, valuesRelativePositive, colorQuoteAreaPositive, + 1, LineStyle.SOLID, true, false); } ILineSeries lineSeries = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, @@ -1386,9 +1425,9 @@ private void addExtremesMarkerLines(ChartInterval chartInterval) .min(Comparator.comparing(SecurityPrice::getValue)); max.ifPresent(high -> addExtremeMarker(high, PlotSymbolType.DIAMOND, // - Messages.LabelChartDetailMarkerHigh, colorHigh)); + Messages.LabelChartDetailMarkerHigh, colorExtremeMarkerHigh)); min.ifPresent(low -> addExtremeMarker(low, PlotSymbolType.DIAMOND, // - Messages.LabelChartDetailMarkerLow, colorLow)); + Messages.LabelChartDetailMarkerLow, colorExtremeMarkerLow)); } private void addExtremeMarker(SecurityPrice price, PlotSymbolType plotSymbolType, String seriesLabel, Color color) @@ -1425,7 +1464,7 @@ private void addExtremeMarker(SecurityPrice price, PlotSymbolType plotSymbolType event.gc.setForeground(Colors.theme().defaultForeground()); - if (inner.getSymbolColor() == colorHigh) + if (inner.getSymbolColor() == colorExtremeMarkerHigh) y = y - textExtent.y - inner.getSymbolSize(); else y = y + inner.getSymbolSize();