Page 1 of 1
TDownSamplingFunction question
Posted: Wed Dec 10, 2014 1:09 pm
by 16558670
I have a problem using TDownSamplingFunction. The attachment is an application to demonstrate it.
What I basically want to do is display a chart with 10.000 points. When my form is only 1.000 pixels wide the chart can easily be reduced, speeding up the display of the chart:
Code: Select all
DownSampleFun.Tolerance := BarSeries1.Count / ClientWidth;
DownSampleFun.DisplayedPointCount := ClientWidth * 4;
This works 90% of the time, but there are situations where the downsampled chart has less points than visible pixels (on the x-axis), which looks like this:
- sshot-2.png (3.11 KiB) Viewed 10876 times
instead of:
- sshot-3.png (2 KiB) Viewed 10872 times
If you resize the form from narrow to wide, the effect can be seen. In my real application the problem is even more visible.
How would I have to modify the application so the vertical 'white' lines will never be visible?
Re: TDownSamplingFunction question
Posted: Mon Dec 15, 2014 11:12 am
by yeray
Hello,
Excuse us for the delayed reply here.
I've been able to reproduce the problem and found the change seems to be between v2013.08 and v2013.09.
I've added it to the public tracker here:
http://bugs.teechart.net/show_bug.cgi?id=1046
Re: TDownSamplingFunction question
Posted: Tue Dec 16, 2014 9:25 am
by 16558670
Hello,
I copied an older version of TeeDownSampling.pas (dated 30-8-2011) in my project and verified that this file was compiled into the excutable, but that doesn't make any difference. Either downsampling has never been working correct or the change was made much earlier than you wrote.
Best regards,
Bert
Re: TDownSamplingFunction question
Posted: Tue Dec 16, 2014 10:50 am
by yeray
Hi Bert,
I modified your example a bit, removing the Timer that only seems to be used to reset the function and the labels when the form is resized.
I've also added OnZoom and UndoZoom events for 2 reasons:
1. I very rarely could reproduce the problem resizing the form. I've been able to do so a pair of times, but never with consistency (and I've ran the project many times). However, I can always reproduce the problem when zooming.
2. The fix works when the source series (BarSeries1 at Chart1) is zoomed and drawn (*) before recalculating the function. So I'm using the events to keep both charts synchronized when zooming and unzooming.
(*) I've also added a checkbox you can activate to force the source series to be redrawn when any chart has been zoomed/unzoomed.
However, since I can't reproduce the problem when resizing the form consistently, I check this part is solved, but since both problems look the same, I'd assume both problems should have been solved with the same modifications.
Bert B. wrote:I copied an older version of TeeDownSampling.pas (dated 30-8-2011) in my project and verified that this file was compiled into the excutable, but that doesn't make any difference. Either downsampling has never been working correct or the change was made much earlier than you wrote.
Try changing this condition at TDownSamplingFunction.AddPoints in TeeDownSampling.pas:
Code: Select all
if (Assigned(ParentChart) and (not IsRectEmpty(ParentChart.ChartRect))) then
For this:
Code: Select all
if Assigned(ParentChart) and IsRectEmpty(ParentChart.ChartRect)
// Avoid Parent Window exception when drawing onto bitmap
and Assigned(ParentChart.Parent) then
Re: TDownSamplingFunction question
Posted: Tue Dec 16, 2014 2:43 pm
by 16558670
Hello Yeray,
Unfortunately that doesn't solve the problem.
When resizing the form there are still lots of situations where there are more pixels visible on the screen than samples in the chart:
Code: Select all
if ClientWidth > BarSeries2.Count then
GroupBoxForm.Color := clRed
else
GroupBoxForm.Color := clBtnFace;
(The GroupBox will color red)
This isn't always visible in the sample application because the barwidth is more than 1 pixel. In my application the barwidth is 1 pixels.
Do you know how to change the width of the bar to 1 pixel? I managed to do that in my own application but am unable to find the correct property right now.
Best regards,
Bert
Re: TDownSamplingFunction question
Posted: Tue Dec 16, 2014 3:48 pm
by yeray
Hi Bert,
Bert B. wrote:This isn't always visible in the sample application because the barwidth is more than 1 pixel. In my application the barwidth is 1 pixels.
Do you know how to change the width of the bar to 1 pixel? I managed to do that in my own application but am unable to find the correct property right now.
This should do it:
Code: Select all
BarSeries1.CustomBarWidth:=1;
BarSeries2.CustomBarWidth:=1;
I could see the problem now consistently resizing the application I sent you to more than 1800 pixels width:
- 2014-12-16_1639.png (19.64 KiB) Viewed 10789 times
I've seen it can be fixed if you recalculate and reset the function Tolerance and DisplayedPointCount properties according to the current width (activating the new checkbox in the revision of the test application):
- 2014-12-16_1640.png (19.96 KiB) Viewed 10794 times
Now, I can see the box is still red for some widths, but the series always seems to look good:
- 2014-12-16_1640_001.png (21.73 KiB) Viewed 10787 times
Did you find a different behaviour in a previous version of TeeChart where you found that was the behaviour to expect?
Re: TDownSamplingFunction question
Posted: Wed Dec 17, 2014 8:41 am
by 16558670
Hello Yeray,
Yeray wrote:This should do it:
Code: Select all
BarSeries1.CustomBarWidth:=1;
BarSeries2.CustomBarWidth:=1;
I saw that you added these lines to the sample project, but the bars are still 3 pixels wide. You can also see that in the screenshots you posted.
Yeray wrote:Did you find a different behaviour in a previous version of TeeChart where you found that was the behaviour to expect?
There is no difference between the 2011 version and the 23-09-2014 version, they are both incorrect. (Using Delphi XE7 Professional)
When resizing the form BarSeries2.Count jumps from 589 to 625, etc. Take a look at the table below:
Code: Select all
BarSeries2.Count ClientWidth Status
589 579 - 589 OK
590 - 606 not OK
625 607 - 625 OK
626 - 645 not OK
667 646 - 667 OK
668 - 689 not OK
715 690 - 715 OK
716 - 740 not OK
770 741 - 770 OK
771 - 799 not OK
834 800 - 834 OK
835 - 869 not OK
910 870 - 910 OK
911 - 952 not OK
As you can see the function to downsample only works for roughly 50% of the time.
Regards,
Bert
Re: TDownSamplingFunction question
Posted: Wed Dec 17, 2014 9:52 am
by 16558670
After further studying the table above I discovered the following:
Code: Select all
589 = 10000 / 17
625 = 10000 / 16
667 = 10000 / 15
715 = 10000 / 14
770 = 10000 / 13
834 = 10000 / 12
910 = 10000 / 11
So it only makes sense to specify integer values for the tolerance.
Changing the procedure SetFunctions as follows makes it work:
Code: Select all
procedure TForm1.SetFunction;
var
NewTolerance : Integer;
begin
NewTolerance := Round(BarSeries1.Count / ClientWidth);
if (BarSeries1.Count div NewTolerance) < ClientWidth then
Dec(NewTolerance);
DownSampleFun.Tolerance := NewTolerance;
DownSampleFun.DisplayedPointCount := (BarSeries1.Count div NewTolerance) * 4;
end;
This should do for now, but a real fix is appreciated.
Best regards,
Bert
Re: TDownSamplingFunction question
Posted: Thu Dec 18, 2014 4:03 pm
by yeray
Heelo Bert,
Bert B. wrote:
I saw that you added these lines to the sample project, but the bars are still 3 pixels wide. You can also see that in the screenshots you posted.
Right. I'm afraid the minimum bar width is 3 pixels wide for the TBarSeries. You can try changing it for a TVolumeSeries.
Bert B. wrote:This should do for now, but a real fix is appreciated.
I'm glad to see you found a satisfactory workaround.
Yes, we'll investigate it further when the ticket mentioned before will be revised:
http://bugs.teechart.net/show_bug.cgi?id=1046