Vert. rulers, subrange, zoom & protected

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
wwwclaes
Posts: 7
Joined: Mon Feb 09, 2004 3:58 pm

Vert. rulers, subrange, zoom & protected

Post by wwwclaes » Mon Feb 09, 2004 4:34 pm

Hi, I have been using JFreeChart for a couple of weeks now and I must say it´s a GREAT implementation! Now on to a couple of questions...

1. What do you think about changing several of your private class member vars to protected? Sometimes functionality needs to be added to your classes and I think inheritance is a good means not to mess with your core. Right now, I have extended eg JFreeChart, ChartPanel, XYPlot and StandardXYItemRenderer. But I couldn't do it without changing many of the member vars in those classes from private to protected.

2. One of the things I've added is two vertical rulers (no, crosshairs didn't do what the customer wanted) that snap onto actual item values in series while being moved. During zoom they hold on to their item value. If they get out of zoom they reappear at the closest visible value (hence they're always there). If anyone would be interested in this, let me know and I'll try to send it to you... (it required quite a few changes hence it's a bit messy and probably not suitable as a patch for this forum)

3. A number of functions should be calculated based on the values within these rulers. Is there an easy way to extract the ruler subrange from a TimeSeriesCollection (that always only contains one Series) based on the ruler range values (as doubles)?

4. If anyone would happen to have a zoom rectangle that can be drawn in either direction it would probably save me a couple of minutes... I can trade you with "zoom when rectangle is clicked" :-)

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Vert. rulers, subrange, zoom & protected

Post by david.gilbert » Mon Feb 09, 2004 4:59 pm

wwwclaes wrote:1. What do you think about changing several of your private class member vars to protected? Sometimes functionality needs to be added to your classes and I think inheritance is a good means not to mess with your core. Right now, I have extended eg JFreeChart, ChartPanel, XYPlot and StandardXYItemRenderer. But I couldn't do it without changing many of the member vars in those classes from private to protected.
In general, I don't want to change them. But if you make a good case for specific cases, I'll look at them.
wwwclaes wrote:2. One of the things I've added is two vertical rulers (no, crosshairs didn't do what the customer wanted) that snap onto actual item values in series while being moved. During zoom they hold on to their item value. If they get out of zoom they reappear at the closest visible value (hence they're always there). If anyone would be interested in this, let me know and I'll try to send it to you... (it required quite a few changes hence it's a bit messy and probably not suitable as a patch for this forum)
Can you explain what these are used for? I'd like to understand the requirement so I can keep it in mind for future changes.
wwwclaes wrote:3. A number of functions should be calculated based on the values within these rulers. Is there an easy way to extract the ruler subrange from a TimeSeriesCollection (that always only contains one Series) based on the ruler range values (as doubles)?
The only thing I can suggest is the createCopy() methods in the TimeSeries class.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

wwwclaes
Posts: 7
Joined: Mon Feb 09, 2004 3:58 pm

Re: Vert. rulers, subrange, zoom & protected

Post by wwwclaes » Mon Feb 09, 2004 7:25 pm

david.gilbert wrote:
wwwclaes wrote:1. What do you think about changing several of your private class member vars to protected? Sometimes functionality needs to be added to your classes and I think inheritance is a good means not to mess with your core. Right now, I have extended eg JFreeChart, ChartPanel, XYPlot and StandardXYItemRenderer. But I couldn't do it without changing many of the member vars in those classes from private to protected.
In general, I don't want to change them. But if you make a good case for specific cases, I'll look at them.
The problem is, they are so many (29 of them as of yet I think). For instance, I override draw(...) and drawItem(...) to implement the rulers. I want to keep original behaviour but add some additional in the middle of it so it's a copy'n paste with slight modifications. But I can't implement those in my subclass unless I change all member variables (and methods) they use from private to protected. (However, this is not a big issue for us, we will ship with JFreeChart included and can modify it as needed.)
david.gilbert wrote:
wwwclaes wrote:2. One of the things I've added is two vertical rulers (no, crosshairs didn't do what the customer wanted) that snap onto actual item values in series while being moved. During zoom they hold on to their item value. If they get out of zoom they reappear at the closest visible value (hence they're always there). If anyone would be interested in this, let me know and I'll try to send it to you... (it required quite a few changes hence it's a bit messy and probably not suitable as a patch for this forum)
Can you explain what these are used for? I'd like to understand the requirement so I can keep it in mind for future changes.
Well, they want two rulers that can be moved along the X-axis to display values from the series which are being displayed in legends (not the JFreeChart ones) below the chart. Suppose there are 8 series, then they can see all 2*8 values at the same time (two ruler values, both X and Y, for each series). They also want to see rulers diffs for each series.

Operations such as trend lines should be displayed in the range of the rulers rather than over the entire display. For other ruler behaviour, see my description above. If you want code samples, I would be glad to send it to you.
david.gilbert wrote:
wwwclaes wrote:3. A number of functions should be calculated based on the values within these rulers. Is there an easy way to extract the ruler subrange from a TimeSeriesCollection (that always only contains one Series) based on the ruler range values (as doubles)?
The only thing I can suggest is the createCopy() methods in the TimeSeries class.
Whoops, look like I may have missed that one... Thanks!

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Vert. rulers, subrange, zoom & protected

Post by david.gilbert » Tue Feb 10, 2004 10:45 am

wwwclaes wrote:For instance, I override draw(...) and drawItem(...) to implement the rulers. I want to keep original behaviour but add some additional in the middle of it so it's a copy'n paste with slight modifications. But I can't implement those in my subclass unless I change all member variables (and methods) they use from private to protected. (However, this is not a big issue for us, we will ship with JFreeChart included and can modify it as needed.)
I just told someone else to copy and paste the drawItem() method in the BarRenderer class, so I'll go and try that myself right now and see what problems I run into.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

wwwclaes
Posts: 7
Joined: Mon Feb 09, 2004 3:58 pm

Re: Vert. rulers, subrange, zoom & protected

Post by wwwclaes » Thu Feb 12, 2004 10:31 am

david.gilbert wrote:
wwwclaes wrote:For instance, I override draw(...) and drawItem(...) to implement the rulers. I want to keep original behaviour but add some additional in the middle of it so it's a copy'n paste with slight modifications. But I can't implement those in my subclass unless I change all member variables (and methods) they use from private to protected. (However, this is not a big issue for us, we will ship with JFreeChart included and can modify it as needed.)
I just told someone else to copy and paste the drawItem() method in the BarRenderer class, so I'll go and try that myself right now and see what problems I run into.
Just curious... did you run into any problems? As for me, the list of...

Code: Select all

// Patch: Changed from private to protected
...just keeps on growing - there seems to be 33 of them by now ;-) I'm thinking that a reasonable principle would be that all vars that are needed for the implementation of protected methods should be set to protected as well. This would ease method inheritance for the purpose of slight adjustments. (If that is awkward to change, all of them is better than none in my humble opinion...)

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Feb 12, 2004 11:18 am

With the BarRenderer class I got three compile time errors which were easily resolved by replacing the direct reference to the private field with the corresponding getXXX() method. I've checked the drawItem() method for all renderers and updated (most of) them to make this kind of cut-and-paste overriding more straightforward.

If you give me details of other methods you are trying to override that cause similar problems, I'll look at those also.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

wwwclaes
Posts: 7
Joined: Mon Feb 09, 2004 3:58 pm

Post by wwwclaes » Thu Feb 12, 2004 1:17 pm

david.gilbert wrote:With the BarRenderer class I got three compile time errors which were easily resolved by replacing the direct reference to the private field with the corresponding getXXX() method. I've checked the drawItem() method for all renderers and updated (most of) them to make this kind of cut-and-paste overriding more straightforward.

If you give me details of other methods you are trying to override that cause similar problems, I'll look at those also.
Right now it's:

In ChartPanel...

setHorizontalZoom()
setVerticalZoom()
mouse...() event handlers

...in XYPlot...

calculateRangeAxisSpace()
draw()
drawAxes()
render2()
drawRangeGridlines()
getLegendItems()

...in StandardXYItemRenderer...

drawItem()

...in StandardLegend...

draw()

...in TimeSeriesToolTipGenerator...

generateToolTip()

There will probably be a few more in the near future...

Locked