[chronojump] Cairo calculatePaintX-Y methods cleaner
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Cairo calculatePaintX-Y methods cleaner
- Date: Tue, 14 Jan 2020 12:35:28 +0000 (UTC)
commit 8daad6267d7cb83788cf5df3830e32a7e72e22a9
Author: Xavier de Blas <xaviblas gmail com>
Date: Tue Jan 14 13:35:15 2020 +0100
Cairo calculatePaintX-Y methods cleaner
src/gui/cairo/jumpsEvolution.cs | 12 ++++++------
src/gui/cairo/xy.cs | 35 +++++++++++++----------------------
2 files changed, 19 insertions(+), 28 deletions(-)
---
diff --git a/src/gui/cairo/jumpsEvolution.cs b/src/gui/cairo/jumpsEvolution.cs
index 020de266..446c8ea7 100644
--- a/src/gui/cairo/jumpsEvolution.cs
+++ b/src/gui/cairo/jumpsEvolution.cs
@@ -99,8 +99,8 @@ public class JumpsEvolutionGraph : CairoXY
if(! paintMonths)
{
int year = Convert.ToInt32(Math.Floor(minX)) -1;
- int xtemp1 = Convert.ToInt32(calculatePaintX(year, graphWidth, maxX, minX,
outerMargins + innerMargins, outerMargins + innerMargins));
- int xtemp2 = Convert.ToInt32(calculatePaintX(year + 1, graphWidth, maxX, minX,
outerMargins + innerMargins, outerMargins + innerMargins));
+ int xtemp1 = Convert.ToInt32(calculatePaintX(year));
+ int xtemp2 = Convert.ToInt32(calculatePaintX(year + 1));
if(xtemp2 - xtemp1 > 500)
paintMonths = true;
@@ -109,7 +109,7 @@ public class JumpsEvolutionGraph : CairoXY
//-1 to start on previous year to see last months (if fit into graph)
for(int year = Convert.ToInt32(Math.Floor(minX)) -1; year <=
Convert.ToInt32(Math.Floor(maxX)); year ++)
{
- int xtemp = Convert.ToInt32(calculatePaintX(year, graphWidth, maxX, minX,
outerMargins + innerMargins, outerMargins + innerMargins));
+ int xtemp = Convert.ToInt32(calculatePaintX(year));
if( ! (xtemp < outerMargins || xtemp > graphWidth - outerMargins) )
{
if(paintMonths)
@@ -123,15 +123,15 @@ public class JumpsEvolutionGraph : CairoXY
int monthStep = 3;
//1 get de distance between 1 month and the next one
- int xtemp1 = Convert.ToInt32(calculatePaintX(year + 1/12.0, graphWidth, maxX, minX,
outerMargins + innerMargins, outerMargins + innerMargins));
- int xtemp2 = Convert.ToInt32(calculatePaintX(year + 2/12.0, graphWidth, maxX, minX,
outerMargins + innerMargins, outerMargins + innerMargins));
+ int xtemp1 = Convert.ToInt32(calculatePaintX(year + 1/12.0));
+ int xtemp2 = Convert.ToInt32(calculatePaintX(year + 2/12.0));
if(xtemp2 - xtemp1 > 100)
monthStep = 1;
for(int month = monthStep; month <= 12-monthStep; month += monthStep)
{
LogB.Information(string.Format("year-month: {0}-{1}", year, month));
- xtemp = Convert.ToInt32(calculatePaintX(year + month/12.0, graphWidth, maxX,
minX, outerMargins + innerMargins, outerMargins + innerMargins));
+ xtemp = Convert.ToInt32(calculatePaintX(year + month/12.0));
if(xtemp < outerMargins || xtemp > graphWidth - outerMargins)
continue;
diff --git a/src/gui/cairo/xy.cs b/src/gui/cairo/xy.cs
index 74675a8e..ff042d2b 100644
--- a/src/gui/cairo/xy.cs
+++ b/src/gui/cairo/xy.cs
@@ -204,9 +204,7 @@ public abstract class CairoXY
for(double x = xStart; x < xEnd; x += (xEnd - xStart)/1000)
{
- double xgraph = calculatePaintX(
- ( x ),
- graphWidth, absoluteMaxX, minX, totalMargins, totalMargins);
+ double xgraph = calculatePaintX(x);
//do not plot two times the same x point
if(xgraph == xgraphOld)
@@ -216,12 +214,9 @@ public abstract class CairoXY
double ygraph = 0;
if(plt == predictedLineTypes.STRAIGHT)
- ygraph = calculatePaintY(slope * x + intercept,
- graphHeight, absoluteMaxY, minY, totalMargins, totalMargins);
+ ygraph = calculatePaintY(slope * x + intercept);
else //(plt == predictedLineTypes.PARABOLE)
- ygraph = calculatePaintY(
- ( coefs[0] + coefs[1]*x + coefs[2]*Math.Pow(x,2) ),
- graphHeight, absoluteMaxY, minY, totalMargins, totalMargins);
+ ygraph = calculatePaintY(coefs[0] + coefs[1]*x + coefs[2]*Math.Pow(x,2));
//do not plot line outer the axis
if(
@@ -251,12 +246,8 @@ public abstract class CairoXY
foreach(Point p in point_l)
{
LogB.Information(string.Format("point: {0}", p));
- double xgraph = calculatePaintX(
- ( p.X ),
- graphWidth, absoluteMaxX, minX, totalMargins, totalMargins);
- double ygraph = calculatePaintY(
- ( p.Y ),
- graphHeight, absoluteMaxY, minY, totalMargins, totalMargins);
+ double xgraph = calculatePaintX(p.X);
+ double ygraph = calculatePaintY(p.Y);
LogB.Information(string.Format("{0}, {1}", xgraph, ygraph));
g.MoveTo(xgraph+6, ygraph);
g.Arc(xgraph, ygraph, 6.0, 0.0, 2.0 * Math.PI); //full circle
@@ -281,8 +272,8 @@ public abstract class CairoXY
protected void plotPredictedMaxPoint()
{
- double xgraph = calculatePaintX(xAtMMaxY, graphWidth, absoluteMaxX, minX, totalMargins,
totalMargins);
- double ygraph = calculatePaintY(yAtMMaxY, graphHeight, absoluteMaxY, minY, totalMargins,
totalMargins);
+ double xgraph = calculatePaintX(xAtMMaxY);
+ double ygraph = calculatePaintY(yAtMMaxY);
//print X, Y of maxY
//at axis
@@ -427,7 +418,7 @@ public abstract class CairoXY
if(gridType != gridTypes.HORIZONTALLINES)
for(double i = gridXTuple.Item1; i <= gridXTuple.Item2 ; i += gridXTuple.Item3)
{
- int xtemp = Convert.ToInt32(calculatePaintX(i, graphWidth, maxX, minX,
totalMargins, totalMargins));
+ int xtemp = Convert.ToInt32(calculatePaintX(i));
if(xtemp < outerMargins || xtemp > graphWidth - outerMargins)
continue;
@@ -437,7 +428,7 @@ public abstract class CairoXY
if(gridType != gridTypes.VERTICALLINES)
for(double i = gridYTuple.Item1; i <= gridYTuple.Item2 ; i += gridYTuple.Item3)
{
- int ytemp = Convert.ToInt32(calculatePaintY(i, graphHeight, maxY, minY,
totalMargins, totalMargins));
+ int ytemp = Convert.ToInt32(calculatePaintY(i));
if(ytemp < outerMargins || ytemp > graphHeight - outerMargins)
continue;
@@ -548,13 +539,13 @@ public abstract class CairoXY
}
*/
- protected double calculatePaintX (double realX, int ancho, double maxValue, double minValue, int
rightMargin, int leftMargin)
+ protected double calculatePaintX (double realX)
{
- return leftMargin + (realX - minValue) * (ancho - rightMargin - leftMargin) / (maxValue -
minValue);
+ return totalMargins + (realX - minX) * (graphWidth - totalMargins - totalMargins) /
(absoluteMaxX - minX);
}
- protected double calculatePaintY (double realY, int alto, double maxValue, double minValue, int
topMargin, int bottomMargin)
+ protected double calculatePaintY (double realY)
{
- return alto - bottomMargin - ((realY - minValue) * (alto - topMargin - bottomMargin) /
(maxValue - minValue));
+ return graphHeight - totalMargins - ((realY - minY) * (graphHeight - totalMargins -
totalMargins) / (absoluteMaxY - minY));
}
private double calculateRealX (double graphX)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]