Skip to content

Commit

Permalink
Improve the dark and light theme and move the values in the css handler
Browse files Browse the repository at this point in the history
Issue: #3621 #3614
Signed-off-by: Nirus2000 <webmaster@nirus-online.de>
[removed unnecessary changes due to format changes; rebased to master]
Signed-off-by: Andreas Buchen <andreas.buchen@gmail.com>
  • Loading branch information
Nirus2000 authored and buchen committed Nov 1, 2023
1 parent 5f51ef0 commit 9f44ee6
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 22 deletions.
11 changes: 11 additions & 0 deletions name.abuchen.portfolio.ui/css/shared/dark.css
Expand Up @@ -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;
}

* {
Expand Down
11 changes: 11 additions & 0 deletions name.abuchen.portfolio.ui/css/shared/light.css
Expand Up @@ -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;
}

* {
Expand Down
24 changes: 24 additions & 0 deletions name.abuchen.portfolio.ui/plugin.xml
Expand Up @@ -122,6 +122,30 @@
<property-name
name="quote-color">
</property-name>
<property-name
name="quote-area-positive-color">
</property-name>
<property-name
name="quote-area-negative-color">
</property-name>
<property-name
name="purchase-event-color">
</property-name>
<property-name
name="sale-event-color">
</property-name>
<property-name
name="dividend-event-color">
</property-name>
<property-name
name="extreme-marker-high-color">
</property-name>
<property-name
name="extreme-marker-low-color">
</property-name>
<property-name
name="non-trading-color">
</property-name>
</handler>
</extension>
<extension
Expand Down
@@ -1,34 +1,79 @@
package name.abuchen.portfolio.ui.theme;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper;
import org.eclipse.swt.graphics.Color;
import org.w3c.dom.css.CSSValue;

import name.abuchen.portfolio.ui.util.Colors;
import name.abuchen.portfolio.ui.views.SecuritiesChart;

/**
* The SecuritiesChartCSSHandler class is responsible for customizing the visual
* appearance of SecuritiesChart elements using CSS properties. It uses a
* mapping of CSS properties to color setters to apply the specified colors to
* corresponding elements within the chart.
*/
@SuppressWarnings("restriction")
public class SecuritiesChartCSSHandler implements ICSSPropertyHandler
{
private interface ColorSetter
{
/**
* Sets the color on the SecuritiesChart element.
*/
void setColor(SecuritiesChart chart, CSSValue value);
}

private final Map<String, ColorSetter> 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
{
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);
}

}
Expand Up @@ -346,13 +346,17 @@ public static ChartRange createFor(List<SecurityPrice> 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
Expand All @@ -375,11 +379,6 @@ public static ChartRange createFor(List<SecurityPrice> 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$
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 9f44ee6

Please sign in to comment.