wxFreeChart - Request for Opinions

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

wxFreeChart - Request for Opinions

Post by iwbnwif »

I am working on some updates to a cloned version of wxFreeChart (the original is on wxCode).

This isn’t going to be a too major overhaul as I will be ‘time boxing’ :), but I hope to fix some bugs and make some significant improvements.

My main aims are:
  • Improve the Doxygen documentation
  • 'Modernise’ the chart presentation to be more akin to charts produced by current office software
  • Improve drawing speed for dynamic charts (30fps for 500 datapoints on average hardware)
  • Make charts interactive, showing tooltips when hovering over data points and issuing events
For this last point, I have been thinking about a couple of things which I would welcome opinions on.

1: Dataset / Serie(s) / Axis Classes

Currently there is quite a large number of Dataset derivatives most of which are a subtle subclassing of XYDataset.
My thought is to rationalize this to have 3 Dataset subclasses as follows:
  1. SingletonDataset
  2. PairDataset
  3. TupleDataset
A dataset is a container for data Series, and these have related Axis and Renderer. So a SingletonDataset can only sensibly contain a SingletonSeries and so on.

A SingletonSeries is a series where the datapoints are singletons, say the ‘Y’ value, whilst the ‘X’ value is a fixed category set defined by the dataset. A singleton could sensibly be plotted as a line, a moving average, bars, even a pie-chart with no categories. The existing CategorySimpleDataset / CategorySerie would be replaced by this.

A PairSeries would contain an ‘X’ and a ‘Y’ value. These make more sense to plot as a XY Scatter Chart or a histogram. The existing series for XYSimpleDataset, VectorDataset, XYDynamicDataset and others would be replaced by this.

A TupleSeries would be for data that has more than just X and Y values. Probably, it would derive from PairSeries but with a vector member that can store 1 or more additional dimensions, so XYZSeries and a new OHLCSeries would fit here.

I was thinking about using wxAny for the series, but maybe it would be better just to be vectors. So, a PairSeries would basically be wxVector<T1,T2>. The advantage of wxAny is that I think any wxAny value can be output as a string, which obviously makes labeling easier.

2: Event Mechanism

Currently the library has its own sort of event mechanism. I am not yet sure exactly how this works, but there are a range of ‘FIRE’ macros and methods. I think that this could be entirely replaced using wxWidget’s normal event mechanism, with the advantage that appropriate events can be exposed and therefore custom handlers added.

This could be a major piece of work or it could be straightforward.

Both of these 2 changes are highly likely to break the library for existing applications and TBH I can’t really be bothered to write a compatibility layer.

I would welcome any thoughts on the above - and any other suggestions for that matter! Really, my time is quite limited for this, but it is a valuable learning exercise so I am happy to give it a go.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
psychegr
Knows some wx things
Knows some wx things
Posts: 26
Joined: Wed Mar 05, 2014 1:19 pm

Re: wxFreeChart - Request for Opinions

Post by psychegr »

I am joining in as i would really like to participate in adding features and modernizing it.
The "FIRE" events do really bother me and honestly i dont understand how they work or why they are there since wxWidgets offers a better event mechanism that we could implement there. As you know i have made some changes in wxFreeChart and i am willing to offer my thoughts, code and my experience that i gained from doing that. There are lots to fix in my version here but i think that some stuff are really usable like the "connection" with wxGrid that i coded.
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: wxFreeChart - Request for Opinions

Post by iwbnwif »

I am joining in as i would really like to participate in adding features and modernizing it.
That's great, thanks!

Code: Select all

The "FIRE" events do really bother me and honestly i dont understand how they work or why they are there since wxWidgets offers a better event mechanism that we could implement there.
It looks to me that there is some sort of 'subscriber' mechanism (observable / observer?), and the fire events are just supposed to notify subscribers that a particular change has occurred.

I can see the principle is good for a MVC model, but I think having such a complicated logic is of diminishing use. It isn't the end of the world to just redraw the chart when something like a once-in-a-while pen change is made.

As an experiment, I have deleted all the event code and it makes no difference to any of the demos with the exception of the dynamic XY demo. My thought is therefore to completely remove all the observable / observer code as well and implement just a "DatasetUpdated" -> "Redraw" event chain. This would be the starting point for any further event implementation.

I will try to create a sandbox branch in Github with this new starting point.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
psychegr
Knows some wx things
Knows some wx things
Posts: 26
Joined: Wed Mar 05, 2014 1:19 pm

Re: wxFreeChart - Request for Opinions

Post by psychegr »

iwbnwif wrote: As an experiment, I have deleted all the event code and it makes no difference to any of the demos with the exception of the dynamic XY demo. My thought is therefore to completely remove all the observable / observer code as well and implement just a "DatasetUpdated" -> "Redraw" event chain. This would be the starting point for any further event implementation.
That is exactly what i did when i added "interaction" with wxGrid. Let me know when you are ready to start working with that. I hope that others will join also to extend/modernize the wxFreeChart. It is a charting component that has almost everything, except a 3d surface plot, but i could provide some code for that as i already done that in openGL. Shouldnt be hard to transform it to wxGCDC or something. ;)
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: wxFreeChart - Request for Opinions

Post by iwbnwif »

I have created a branch in Github https://github.com/iwbnwif/wxFreeChart/tree/remove_fire for getting rid of the Fire mechanism.

The aim is to restore the functionality of the demos only using wxEvent. AFAIK that is only:
  • Dynamic data
  • Scrolling windows
That is exactly what i did when i added "interaction" with wxGrid.
I would be really interested to see how and what you did.
...except a 3d surface plot, but i could provide some code for that as i already done that in openGL.
One of my further off TODO's is to look into OpenGL as a charting surface. GnuRadio https://github.com/gnuradio/gnuradio has a wxWidgets form builder and can create charts (actually spectrum analyser / waterfall graph) using what seems to be a wxGLCanvas.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
psychegr
Knows some wx things
Knows some wx things
Posts: 26
Joined: Wed Mar 05, 2014 1:19 pm

Re: wxFreeChart - Request for Opinions

Post by psychegr »

iwbnwif wrote:I have created a branch in Github https://github.com/iwbnwif/wxFreeChart/tree/remove_fire for getting rid of the Fire mechanism.

The aim is to restore the functionality of the demos only using wxEvent. AFAIK that is only:
  • Dynamic data
  • Scrolling windows
That is exactly what i did when i added "interaction" with wxGrid.
I would be really interested to see how and what you did.
...except a 3d surface plot, but i could provide some code for that as i already done that in openGL.
One of my further off TODO's is to look into OpenGL as a charting surface. GnuRadio https://github.com/gnuradio/gnuradio has a wxWidgets form builder and can create charts (actually spectrum analyser / waterfall graph) using what seems to be a wxGLCanvas.
Really nice.

What i did with wxGrid is to create a new type of dataset which i called gridTableDataSet. As a serie it takes a gridTable from your wxGrid from there you can get cells, cellvalues, rowheader names, columnheader names and so on. At least this is the idea that i had in mind when i started with that. I wanted to update both the chart and/or the grid at the same time. For example if i changed one value in the grid, the chart updates and if i update a point in the chart, the value in the grid updates also. Been working on that for a few days back then and finally i made it but it is really complex. At one point i had to handle the gridTableChanged event but also i had to create a datasetChanged event which i had to catch in my main frame to update grid cell coloring. The result is this but it certainly needs lots of work.
chartTest.png
chartTest.png (22.74 KiB) Viewed 9807 times
The idea has to remain and kept simple, at least this is the way that i always think. Also a "nice labels" kind of thing should be there as an option. What i mean with that is that the points in horizontal axis should be evenly spaced if the user wants, or spaced according to their real values. For my application the points should be evenly spaced. And this is what i was working on the last time.

My time is really limited but the wxFreeChart is a component that i need in my applications and i am willing to spend time to modernize it. Of course this is not a job for 2 guys only but i hope that more will join the team and make this component an even better one if not the best one.
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: wxFreeChart - Request for Opinions

Post by iwbnwif »

Nice chart!
Also a "nice labels" kind of thing should be there as an option.
I have implemented a 'nice' label numbering (as per the algorithm in this discussion http://stackoverflow.com/questions/8506 ... imum-ticks), but not sure if this is what you mean.

P.S. Did you get my response to your PM? It still shows as in my outbox, but it is also showing sent!
Last edited by iwbnwif on Sat Apr 29, 2017 9:45 pm, edited 1 time in total.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: wxFreeChart - Request for Opinions

Post by iwbnwif »

Well stripping out the "Fire" code and "Observable" was rather easier than I was expecting.

Also implementing some simple events is not to bad. What is harder is deciding a good way to propagate them.

My current thoughts are that every object which can change is derived from wxEvtHandler and posts an event to its own queue when something has changed. Classes which relate to that object, can 'subscribe' (Bind) to the event and behave accordingly.

I would like to put the Plot base class at the centre of this (i.e. it is the controller in the MVC paradigm). The Plot would then raise a "Needs Redraw" event, that would cause a refresh from wxChartPanel. Or maybe that is unnecessary, and Plot can initiate a redraw on its own.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
psychegr
Knows some wx things
Knows some wx things
Posts: 26
Joined: Wed Mar 05, 2014 1:19 pm

Re: wxFreeChart - Request for Opinions

Post by psychegr »

iwbnwif wrote:Well stripping out the "Fire" code and "Observable" was rather easier than I was expecting.

Also implementing some simple events is not to bad. What is harder is deciding a good way to propagate them.

My current thoughts are that every object which can change is derived from wxEvtHandler and posts an event to its own queue when something has changed. Classes which relate to that object, can 'subscribe' (Bind) to the event and behave accordingly.

I would like to put the Plot base class at the centre of this (i.e. it is the controller in the MVC paradigm). The Plot would then raise a "Needs Redraw" event, that would cause a refresh from wxChartPanel. Or maybe that is unnecessary, and Plot can initiate a redraw on its own.
Yes i received your pm!

I think that you are correct. The main area of the chart is the plot area and i think that this is where all the "magic" should happen. Mouse events should be started from there, i mean you click on a specific point in the plot which is probably a point in the chart line or bar. Or you drag that point, or you drag the mouse wheel (zoom), or you click at another point except the line and drag the mouse (pan). The plot should "decide" what kind of event it is and then post it to the related objects that are subscribed to that kind of event.
Or i totally lost it? Dont know :P !

Regarding my "nice" thing, in my application i already know the horizontal axis values/points and i want to spread them evenly in the plot and not at their related position that the plot calculates. For example if i have values like, 1, 2, 3, 8, 9, 12, i have 6 points which i want to spread evenly on the plot.
psychegr
Knows some wx things
Knows some wx things
Posts: 26
Joined: Wed Mar 05, 2014 1:19 pm

Re: wxFreeChart - Request for Opinions

Post by psychegr »

Screenshot_5.png
Screenshot_5.png (58.6 KiB) Viewed 5557 times
I spent some time adding functions for displaying surface plots. I have also started working on the mouse events.
Still i havent finished anything, but it looks promising.

Regarding the mouse events, i chose a different logic. I catch the mouse event in chartpanel class. On each "Plot" class i added a "OnMouseEvent" function and from the main ChartPanel i call
"m_chart->GetPlot()->OnMouseEvents(ev);"

The result is that i can handle the mouse event in every single plot class differently. I believe that it is simple.

The surface plot works nice but it has some performance issues. It flickers a bit while rotating or zooming it with the mouse and stuff like that. I need to spend more time on it but for now it works nice.
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

Re: wxFreeChart - Request for Opinions

Post by ollydbg23 »

psychegr wrote: Tue Mar 22, 2022 6:48 pm Screenshot_5.png

I spent some time adding functions for displaying surface plots. I have also started working on the mouse events.
Still i havent finished anything, but it looks promising.

Regarding the mouse events, i chose a different logic. I catch the mouse event in chartpanel class. On each "Plot" class i added a "OnMouseEvent" function and from the main ChartPanel i call
"m_chart->GetPlot()->OnMouseEvents(ev);"

The result is that i can handle the mouse event in every single plot class differently. I believe that it is simple.

The surface plot works nice but it has some performance issues. It flickers a bit while rotating or zooming it with the mouse and stuff like that. I need to spend more time on it but for now it works nice.
Looks nice, but for 3D image, maybe using OpenGL is better.
Do you have any public code repo to share with us? Thanks.
psychegr
Knows some wx things
Knows some wx things
Posts: 26
Joined: Wed Mar 05, 2014 1:19 pm

Re: wxFreeChart - Request for Opinions

Post by psychegr »

Hi,

i spent the last few days trying to make it function without issues and by issues i mean that when moving the graph with the mouse or zoom in/out with the mouse wheel it lags. It is like it stops responding for a couple milliseconds and then it comes back again.
I know that OpenGL is best for this kind of application and i am trying to figure out how to implement wxGLCanvas in the wxFreechart.
I dont have a public repo so that you can see the code but when it is done, i will talk with iwbnwif to review and merge my code with his git.
Post Reply