new plotter
This commit is contained in:
@@ -83,4 +83,8 @@ public abstract class CalculatorFragment extends SherlockFragment {
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
}
|
||||
|
||||
public boolean isPaneFragment() {
|
||||
return fragmentHelper.isPane(this);
|
||||
}
|
||||
}
|
||||
|
@@ -106,9 +106,7 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
|
||||
public void onCreate(Bundle in) {
|
||||
super.onCreate(in);
|
||||
|
||||
// todo serso: init variable properly
|
||||
boolean paneFragment = true;
|
||||
if (paneFragment) {
|
||||
if (isPaneFragment()) {
|
||||
this.bgColor = getResources().getColor(R.color.cpp_pane_background);
|
||||
} else {
|
||||
this.bgColor = getResources().getColor(android.R.color.transparent);
|
||||
|
@@ -243,7 +243,6 @@ public class CalculatorGraph2dView extends View implements GraphView {
|
||||
if (lastTouchXPxs != NO_TOUCH && lastTouchYPxs != NO_TOUCH) {
|
||||
|
||||
paint.setColor(graphViewHelper.getPlotViewDef().getGridColor());
|
||||
paint.setAlpha(100);
|
||||
|
||||
canvas.drawLine(lastTouchXPxs, 0, lastTouchXPxs, heightPxs, paint);
|
||||
canvas.drawLine(0, lastTouchYPxs, widthPxs, lastTouchYPxs, paint);
|
||||
@@ -251,9 +250,6 @@ public class CalculatorGraph2dView extends View implements GraphView {
|
||||
final Point2d lastTouch = dimensions.toGraphCoordinates(lastTouchXPxs, lastTouchYPxs);
|
||||
final String touchLabel = "[" + formatTick(lastTouch.getX(), tickDigits + 1) + ", " + formatTick(lastTouch.getY(), tickDigits + 1) + "]";
|
||||
canvas.drawText(touchLabel, 0, touchLabel.length(), lastTouchXPxs - 40, lastTouchYPxs - 40, textPaint);
|
||||
|
||||
// restore alpha
|
||||
paint.setAlpha(255);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -11,6 +11,34 @@ import org.solovyev.common.math.Point2d;
|
||||
*/
|
||||
public class Graph2dDimensions {
|
||||
|
||||
// |<--------------gWidth-------------->|
|
||||
// xMin xMax
|
||||
// -------------------|------------------------------------|--------------------
|
||||
// |<-------------vWidthPs------------->|
|
||||
//
|
||||
/*
|
||||
*
|
||||
*
|
||||
* 0------------------------------------|--> xPxs
|
||||
* |
|
||||
* |
|
||||
* | y
|
||||
* | ^
|
||||
* | |
|
||||
* | |
|
||||
* | |
|
||||
* |------------------0-----------------|--> x
|
||||
* | |
|
||||
* | |
|
||||
* | |
|
||||
* | |
|
||||
* | |
|
||||
* v
|
||||
* yPxs
|
||||
*
|
||||
* */
|
||||
|
||||
|
||||
@NotNull
|
||||
private GraphView graphView;
|
||||
|
||||
@@ -39,7 +67,11 @@ public class Graph2dDimensions {
|
||||
|
||||
@NotNull
|
||||
Point2d toGraphCoordinates(float xPxs, float yPxs) {
|
||||
return new Point2d(xPxs * getGraphToViewRatio() + getXMin(), - (yPxs * getGraphToViewRatio() + getYMin()));
|
||||
return new Point2d( scalePxs(xPxs) + getXMin(), (getGraphHeight() - scalePxs(yPxs)) + getYMin() );
|
||||
}
|
||||
|
||||
private float scalePxs(float pxs) {
|
||||
return pxs * getGraphToViewRatio();
|
||||
}
|
||||
|
||||
// X
|
||||
@@ -82,9 +114,9 @@ public class Graph2dDimensions {
|
||||
|
||||
float getGraphToViewRatio() {
|
||||
if (vWidthPxs != 0) {
|
||||
return gWidth / vWidthPxs;
|
||||
return gWidth / ((float)vWidthPxs);
|
||||
} else {
|
||||
return 0;
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +124,7 @@ public class Graph2dDimensions {
|
||||
if (vWidthPxs != 0) {
|
||||
return ((float) vHeightPxs) / vWidthPxs;
|
||||
} else {
|
||||
return 0;
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user