Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [swtchart-dev] Buffering Chart Data via a Bitmap

Hi,
Seems like there is a bug when using getPlotArea().getControl().setBackgroundImage(image) for SWTChart-
https://sourceforge.net/p/swt-chart/bugs/20/
it states here that the image painted with org.eclipse.swt.widgets.Control.setBackgroundImage(Image) will be overlaid and hidden,
I have attached the file given to work around the bug
Best,
Yash


On Tue, 31 Mar 2020 at 11:14, Philip Wenig <philip.wenig@xxxxxxxxxxxxx> wrote:
Hi Yash,

via the chart settings, event processors can be defined. This makes it possible to completely changes the events of a chart. Three default actions are required to make the user selection:

org.eclipse.swtchart.extensions.core.ChartSettings

handledEventProcessors.add(new MouseDownEvent());
handledEventProcessors.add(new MouseMoveSelectionEvent());
handledEventProcessors.add(new MouseUpEvent());

The user selection is handled after mouse up event here:

org.eclipse.swtchart.extensions.core.BaseChart

private void handleUserSelectionXY(Event event) {

/*
 * Track the selection before the new range is
 * selected by the user.
 */
trackUndoSelection();
int xStart = userSelection.getStartX();
int xStop = userSelection.getStopX();
int yStart = userSelection.getStartY();
int yStop = userSelection.getStopY();
setSelectionXY(xStart, xStop, yStart, yStop);
trackRedoSelection();
/*
 * Inform all registered handlers.
 * Reset the current selection and redraw the chart.
 */
fireUpdateCustomRangeSelectionHandlers(event);
}


Best,
Philip


Am 31.03.20 um 07:32 schrieb Yash Bharatiya:
Hi,
I tried implementing the above mentioned idea and looked into the code base,
I used suspendUpdate() to lock the chart and the series plotting ,but I am having difficulty in understanding how the scrollable chart handles various events.
Could you briefly explain how event handling is done in the scrollable chart.

Thanks,
Yash


On Sat, 28 Mar 2020 at 10:27, Philip Wenig <philip.wenig@xxxxxxxxxxxxx> wrote:
Hi Yash,

yep, that's idea. I have the following workflow in mind:

1) start zoom action
2) lock the chart and disable series plotting
3) convert current chart (BaseChart) to an image (png) via the image supplier)
4) set the image: getPlotArea().getControl().setBackgroundImage(image)
5) let the user select the range
6) stop zoom action
7) clear the image: getPlotArea().getControl().setBackgroundImage(null);
8) enable series plotting
9) unlock the chart
10) redraw

Creating the image should be relatively fast as the plot is drawn already and thus the display is available. We should give this idea a try.


Best,
Philip



Am 28.03.20 um 05:09 schrieb Yash Bharatiya:
Hi,
Currently SWTChart redraws everytime the user zooms in or out causing performance issues,

Does that mean the chart will be converted into a graphic image and then scaled or resized whenever zoomed in or out instead of redrawing?
The chart can be converted into an image using ImageSupplier class,
ImageSupplier imageSupplier = new ImageSupplier();
ImageData imageData = imageSupplier.getImageData(scrollableChart.getBaseChart());
Image image=new Image(display,imageData);
Thanks,
Yash

_______________________________________________
swtchart-dev mailing list
swtchart-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/swtchart-dev

-- 
~~~~~~~~~~~~~~~~~~~~~~~~
OpenChrom - the open source alternative for chromatography / mass spectrometry
Dr. Philip Wenig » Founder » philip.wenig@xxxxxxxxxxxxx » http://www.openchrom.net
~~~~~~~~~~~~~~~~~~~~~~~~
_______________________________________________
swtchart-dev mailing list
swtchart-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/swtchart-dev

_______________________________________________
swtchart-dev mailing list
swtchart-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/swtchart-dev

-- 
~~~~~~~~~~~~~~~~~~~~~~~~
OpenChrom - the open source alternative for chromatography / mass spectrometry
Dr. Philip Wenig » Founder » philip.wenig@xxxxxxxxxxxxx » http://www.openchrom.net
~~~~~~~~~~~~~~~~~~~~~~~~
_______________________________________________
swtchart-dev mailing list
swtchart-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/swtchart-dev
package org.swtchart.examples;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.swtchart.Chart;
import org.swtchart.ICustomPaintListener;
import org.swtchart.IPlotArea;
import org.swtchart.ISeries;
import org.swtchart.ISeries.SeriesType;

public class BUG2947412 {

	private static Image image;

	private static final double[] ySeries = { 0.1, 0.38, 0.41, 0.92, 1.0 };

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setSize(500, 400);
		shell.setLayout(new FillLayout());

		image = new Image(display, "image.gif");

		// create a chart
		Chart chart = new Chart(shell, SWT.NONE);

		ISeries lineSeries = chart.getSeriesSet().createSeries(SeriesType.LINE,
				"line series");
		lineSeries.setYSeries(ySeries);

		// add paint listener
		IPlotArea plotArea = (IPlotArea) chart.getPlotArea();
		plotArea.addCustomPaintListener(new CustomPaintListener());

		// adjust the axis range
		chart.getAxisSet().adjustRange();

		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		image.dispose();
		display.dispose();
	}

	private static class CustomPaintListener implements ICustomPaintListener {
		@Override
		public void paintControl(PaintEvent e) {
			e.gc.drawImage(image, e.width / 2, e.height / 2);
		}

		@Override
		public boolean drawBehindSeries() {
			return true;
		}
	}
}

Back to the top