Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import name.abuchen.portfolio.model.Security;
import name.abuchen.portfolio.model.SecurityPrice;
import name.abuchen.portfolio.money.Values;
import name.abuchen.portfolio.ui.util.chart.TimelineChart;

class CsvTestDataLoader
{
Expand Down Expand Up @@ -48,7 +47,7 @@ static ChartLineSeriesAxes loadChartLineSeriesAxes(List<CSVRecord> records, Date
}
}
ChartLineSeriesAxes result = new ChartLineSeriesAxes();
result.setDates(TimelineChart.toJavaUtilDate(dates.toArray(new LocalDate[0])));
result.setDates(dates.toArray(new LocalDate[0]));
result.setValues(Doubles.toArray(values));
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;

import org.hamcrest.core.IsNull;
Expand Down Expand Up @@ -131,11 +130,10 @@ public void testSufficientPriceDataStartDate()
date = date.plusDays(1);
}
LocalDate startDate = LocalDate.parse("2016-06-01");
Date isStartDate = java.sql.Date.valueOf(startDate);
ChartLineSeriesAxes sma = new SimpleMovingAverage(10, security, new ChartInterval(startDate, LocalDate.now()))
.getSMA();
assertThat(sma, is(IsNull.notNullValue()));
assertThat(sma.getDates()[0], is(isStartDate));
assertThat(sma.getDates()[0], is(startDate));
}

}
4 changes: 2 additions & 2 deletions name.abuchen.portfolio.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Import-Package: com.google.common.base,
org.eclipse.swt.program,
org.eclipse.swt.widgets,
org.eclipse.swtchart,
org.eclipse.swtchart.internal,
org.eclipse.swtchart.model,
org.json.simple,
org.json.simple.parser,
Expand All @@ -114,8 +115,7 @@ Import-Package: com.google.common.base,
org.osgi.framework,
org.osgi.service.component.annotations,
org.osgi.service.event,
org.osgi.service.prefs,
org.swtchart
org.osgi.service.prefs
Require-Bundle: name.abuchen.portfolio;bundle-version="0.71.3",
org.eclipse.nebula.cwt,
org.eclipse.ui.forms,
Expand Down
2 changes: 1 addition & 1 deletion name.abuchen.portfolio.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
class="name.abuchen.portfolio.ui.editor.Sidebar">
</widget>
<widget
class="org.swtchart.Chart">
class="org.eclipse.swtchart.Chart">
</widget>
<widget
class="name.abuchen.portfolio.ui.util.Colors$Theme">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.swtchart.Chart;
import org.swtchart.IAxis;
import org.swtchart.ILegend;
import org.swtchart.ITitle;
import org.eclipse.swtchart.Chart;
import org.eclipse.swtchart.IAxis;
import org.eclipse.swtchart.ILegend;
import org.eclipse.swtchart.IPlotArea;
import org.eclipse.swtchart.ITitle;
import org.w3c.dom.css.CSSValue;

import name.abuchen.portfolio.ui.util.chart.ScatterChart;
Expand Down Expand Up @@ -70,7 +70,7 @@ else if (BACKGROUND_COLOR.equalsIgnoreCase(property)

chart.setBackground(newColor);

Composite plotArea = chart.getPlotArea();
IPlotArea plotArea = chart.getPlotArea();
if (plotArea != null)
plotArea.setBackground(newColor);
ILegend legend = chart.getLegend();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
import org.swtchart.Chart;
import org.eclipse.swtchart.Chart;

@SuppressWarnings("restriction")
public class ChartElementAdapter extends CompositeElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.eclipse.e4.ui.internal.css.swt.definition.IThemesExtension;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Tree;
import org.swtchart.Chart;
import org.eclipse.swtchart.Chart;
import org.w3c.dom.Element;

import name.abuchen.portfolio.ui.editor.Sidebar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swtchart.Chart;

import name.abuchen.portfolio.ui.UIConstants;

public abstract class AbstractChartToolTip implements Listener
{
public static final int PADDING = 5;

private org.swtchart.Chart chartV10 = null;
private org.eclipse.swtchart.Chart chartV13 = null;
private Chart chart = null;

private Shell tip = null;
private Object focus = null;
Expand All @@ -29,20 +29,9 @@ public abstract class AbstractChartToolTip implements Listener
private boolean showToolTip = false;
private boolean isAltPressed = false;

protected AbstractChartToolTip(org.swtchart.Chart chart)
protected AbstractChartToolTip(Chart chart)
{
this(chart, null);
}

protected AbstractChartToolTip(org.eclipse.swtchart.Chart chart)
{
this(null, chart);
}

private AbstractChartToolTip(org.swtchart.Chart chartV10, org.eclipse.swtchart.Chart chartV13)
{
this.chartV10 = chartV10;
this.chartV13 = chartV13;
this.chart = chart;

Composite plotArea = getPlotArea();
plotArea.addListener(SWT.MouseDown, this);
Expand All @@ -60,14 +49,9 @@ public void setActive(boolean isActive)

protected abstract void createComposite(Composite parent);

protected org.swtchart.Chart getChart()
{
return chartV10;
}

protected org.eclipse.swtchart.Chart getSWTChart()
protected Chart getChart()
{
return chartV13;
return chart;
}

protected Object getFocusedObject()
Expand Down Expand Up @@ -202,10 +186,8 @@ private Rectangle calculateBounds(Event event, Point size)

protected final Composite getPlotArea()
{
if (chartV10 != null)
return chartV10.getPlotArea();
else if (chartV13 != null)
return (Composite) chartV13.getPlotArea();
if (chart != null)
return (Composite) chart.getPlotArea();
else
throw new IllegalArgumentException("no plot area found"); //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Menu;
import org.swtchart.Chart;
import org.swtchart.IAxis;
import org.eclipse.swtchart.Chart;
import org.eclipse.swtchart.IAxis;

import name.abuchen.portfolio.ui.Messages;
import name.abuchen.portfolio.ui.PortfolioPlugin;
Expand All @@ -39,9 +39,9 @@ public ChartContextMenu(Chart chart)
menuMgr.addMenuListener(manager -> configMenuAboutToShow(manager));

contextMenu = menuMgr.createContextMenu(chart);
chart.getPlotArea().setMenu(contextMenu);
chart.getPlotArea().getControl().setMenu(contextMenu);

chart.getPlotArea().addDisposeListener(e -> dispose());
chart.getPlotArea().getControl().addDisposeListener(e -> dispose());
}

private void configMenuAboutToShow(IMenuManager manager)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package name.abuchen.portfolio.ui.util.chart;

import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -82,7 +80,7 @@ record Spot(int time, LocalDate date, double xCoordinate, double valueYLeftAxis,
public static Spot from(Event e, TimelineChart chart)
{
double xCoordinate = chart.getAxisSet().getXAxis(0).getDataCoordinate(e.x);
LocalDate date = Instant.ofEpochMilli((long) xCoordinate).atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate date = LocalDate.ofEpochDay((long) xCoordinate);
double valueYLeftAxis = chart.getAxisSet().getYAxis(2).getDataCoordinate(e.y);
double valueYRightAxis = chart.getAxisSet().getYAxis(0).getDataCoordinate(e.y);

Expand All @@ -106,11 +104,11 @@ public Point toPoint(TimelineChart chart)
public ChartToolsManager(TimelineChart chart)
{
this.chart = chart;
chart.getPlotArea().addListener(SWT.MouseDown, this::onMouseDown);
chart.getPlotArea().addListener(SWT.MouseMove, this::onMouseMove);
chart.getPlotArea().addListener(SWT.MouseUp, this::onMouseUp);
chart.getPlotArea().getControl().addListener(SWT.MouseDown, this::onMouseDown);
chart.getPlotArea().getControl().addListener(SWT.MouseMove, this::onMouseMove);
chart.getPlotArea().getControl().addListener(SWT.MouseUp, this::onMouseUp);

chart.getPlotArea().addPaintListener(this::paintControl);
chart.getPlotArea().getControl().addPaintListener(this::paintControl);
}

private void onMouseDown(Event e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.Point;
import org.swtchart.Chart;
import org.swtchart.IAxis;
import org.swtchart.Range;
import org.eclipse.swtchart.Chart;
import org.eclipse.swtchart.IAxis;
import org.eclipse.swtchart.Range;

public final class ChartUtil
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.swtchart.ICustomPaintListener;
import org.eclipse.swtchart.ISeries;
import org.eclipse.swtchart.ISeries.SeriesType;
import org.eclipse.swtchart.internal.PlotArea;
import org.eclipse.swtchart.model.Node;

import name.abuchen.portfolio.money.Values;
Expand Down Expand Up @@ -270,9 +271,17 @@ public CircularChart(Composite parent, SeriesType chartType)
this(parent, chartType, node -> Values.Percent2.format(node.getValue() / node.getParent().getValue()));
}

@SuppressWarnings("restriction")
public CircularChart(Composite parent, SeriesType chartType, ILabelProvider labelProvider)
{
super(parent, SWT.NONE);
super(parent, SWT.NONE, null);

// we must use the secondary constructor that is not creating the
// PlotArea because the default constructor adds a mouse move listener
// that is redrawing the chart on every mouse move. That leads to janky
// UI when the tooltip is shown.
new PlotArea(this, SWT.NONE);

this.chartType = chartType;
this.labelProvider = labelProvider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void setToolTipBuilder(IToolTipBuilder builder)
@Override
protected Object getFocusObjectAt(Event event)
{
Optional<Node> node = ((CircularChart) getSWTChart()).getNodeAt(event.x, event.y);
Optional<Node> node = ((CircularChart) getChart()).getNodeAt(event.x, event.y);
return node.isPresent() ? node.get() : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Event;
import org.swtchart.IAxis;
import org.eclipse.swtchart.IAxis;

import name.abuchen.portfolio.money.Values;
import name.abuchen.portfolio.ui.util.Colors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;

import name.abuchen.portfolio.money.Values;
Expand Down Expand Up @@ -119,7 +120,7 @@ public void paintControl(PaintEvent e)
var text = buffer.toString();

Point txtExtend = e.gc.textExtent(text);
Rectangle plotArea = chart.getPlotArea().getClientArea();
Rectangle plotArea = ((Composite) chart.getPlotArea().getControl()).getClientArea();

e.gc.setBackground(Colors.brighter(color));
e.gc.setForeground(Colors.getTextColor(color));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.swtchart.Chart;
import org.swtchart.IAxis;
import org.eclipse.swtchart.Chart;
import org.eclipse.swtchart.IAxis;

public class MovePlotKeyListener implements Listener
{
Expand All @@ -18,7 +18,7 @@ private MovePlotKeyListener(Chart chart)
public static void attachTo(Chart chart)
{
Listener listener = new MovePlotKeyListener(chart);
chart.getPlotArea().addListener(SWT.KeyDown, listener);
chart.getPlotArea().getControl().addListener(SWT.KeyDown, listener);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package name.abuchen.portfolio.ui.util.chart;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.swtchart.Chart;
import org.eclipse.swtchart.Chart;
import org.eclipse.swtchart.internal.PlotArea;

public class PlainChart extends Chart // NOSONAR
{
@SuppressWarnings("restriction")
public PlainChart(Composite parent, int style)
{
super(parent, style);
super(parent, style, null);

// we must use the secondary constructor that is not creating the
// PlotArea because the default constructor adds a mouse move listener
// that is redrawing the chart on every mouse move. That leads to janky
// UI when the tooltip is shown.
new PlotArea(this, SWT.NONE);
}

@Override
Expand All @@ -21,6 +30,6 @@ public boolean setFocus()

// fix: never force focus on the legend but focus the plot area instead

return getPlotArea().setFocus();
return getPlotArea().getControl().setFocus();
}
}
Loading