View unanswered posts | View active topics It is currently Sat Apr 27, 2024 3:36 pm



Reply to topic  [ 2 posts ] 
drawScatterBestFit() bug 
Author Message
New pChart user
New pChart user

Joined: Tue Jul 26, 2011 10:00 pm
Posts: 2
Post drawScatterBestFit() bug
Hi, jean-damien.

In using the best fit functionality of the scatter chart, I've come across a bug in which the best fit line isn't properly truncated if it extends beyond the top and bottom boundaries of the graph area. It turns out the calculations to manipulate the X coordinates aren't properly taking into account the slope of the plotted line in the graph coordinate system.

Ive modified my pScatter.class.php at approximately line 829 as follows:

if ((($n*$Sxx) == ($Sx*$Sx))) {
$X1 = $this->getPosArray($Data["Axis"][$SerieXAxis]["ScaleMin"],$SerieXAxis);
$X2 = $X1;
$Y1 = $this->pChartObject->GraphAreaY1;
$Y2 = $this->pChartObject->GraphAreaY2;
} else {
$M = (($n*$Sxy)-($Sx*$Sy)) / (($n*$Sxx)-($Sx*$Sx));
$B = (($Sy)-($M*$Sx))/($n);

$X1 = $this->getPosArray($Data["Axis"][$SerieXAxis]["ScaleMin"],$SerieXAxis);
$Y1 = $this->getPosArray($M * $Data["Axis"][$SerieXAxis]["ScaleMin"] + $B,$SerieYAxis);
$X2 = $this->getPosArray($Data["Axis"][$SerieXAxis]["ScaleMax"],$SerieXAxis);
$Y2 = $this->getPosArray($M * $Data["Axis"][$SerieXAxis]["ScaleMax"] + $B,$SerieYAxis);

$RealM = -($Y2-$Y1)/($X2-$X1);

if ( $Y1 < $this->pChartObject->GraphAreaY1 ) { $X1 = $X1 + ($this->pChartObject->GraphAreaY1-$Y1/$RealM); $Y1 = $this->pChartObject->GraphAreaY1; }
if ( $Y1 > $this->pChartObject->GraphAreaY2 ) { $X1 = $X1 + ($Y1-$this->pChartObject->GraphAreaY2)/$RealM; $Y1 = $this->pChartObject->GraphAreaY2; }
if ( $Y2 < $this->pChartObject->GraphAreaY1 ) { $X2 = $X2 - ($this->pChartObject->GraphAreaY1-$Y2)/$RealM; $Y2 = $this->pChartObject->GraphAreaY1; }
if ( $Y2 > $this->pChartObject->GraphAreaY2 ) { $X2 = $X2 - ($Y2-$this->pChartObject->GraphAreaY2)/$RealM; $Y2 = $this->pChartObject->GraphAreaY2; }
}


in lieu of the original set of if statements there. It also takes into consideration if the best fit line ends up being vertical.

Please feel free to incorporate this into your code base.


Tue Jul 26, 2011 10:17 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Thu Dec 02, 2010 2:31 pm
Posts: 409
Location: France
Post Re: drawScatterBestFit() bug
Hi,

I've merged this modification in the next release code. Thank you ;o)

JD.


Wed Aug 03, 2011 12:09 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron