Skip to content

Commit fef8499

Browse files
change zoom & rotate behaviour to not reset axis and angle when zooming.
1 parent 8fe5edc commit fef8499

File tree

6 files changed

+498
-445
lines changed

6 files changed

+498
-445
lines changed

jmathplot/src/org/math/plot/render/AWTDrawer.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
public abstract class AWTDrawer extends AbstractDrawer {
1515

16-
protected Projection projection;
16+
public Projection projection;
1717

1818
public AWTDrawer(PlotCanvas _canvas) {
1919
super(_canvas);
@@ -25,7 +25,7 @@ public AWTDrawer(PlotCanvas _canvas) {
2525
* @see org.math.plot.render.AbstractDrawer#resetProjection()
2626
*/
2727
public void resetBaseProjection() {
28-
projection.initBaseCoordsProjection();
28+
projection.initBaseCoordsProjection(true);
2929
}
3030

3131
/*
@@ -90,7 +90,7 @@ public int[] project(double... pC) {
9090
* @see org.math.plot.render.AbstractDrawer#projectRatio(double[])
9191
*/
9292
public int[] projectBase(double... rC) {
93-
return projection.screenProjectionBaseRatio(rC);
93+
return projection.screenProjectionBase(rC);
9494
}
9595

9696
/*
@@ -134,7 +134,11 @@ public void drawText(String label, double... pC) {
134134
comp2D.rotate(text_angle, x + w / 2, y - h / 2);
135135
}
136136

137-
comp2D.drawString(label, x, y);
137+
String[] lines = label.split("\n");
138+
for (int i = 0; i < lines.length; i++) {
139+
comp2D.drawString(lines[i], x, y);
140+
y += h;
141+
}
138142

139143
if (text_angle != 0) {
140144
comp2D.rotate(-text_angle, x + w / 2, y - h / 2);
@@ -148,7 +152,7 @@ public void drawText(String label, double... pC) {
148152
* double[], double, double, double)
149153
*/
150154
public void drawTextBase(String label, double... rC) {
151-
int[] sC = projection.screenProjectionBaseRatio(rC);
155+
int[] sC = projection.screenProjectionBase(rC);
152156

153157
// Corner offset adjustment : Text Offset is used Here
154158
FontRenderContext frc = comp2D.getFontRenderContext();
@@ -164,7 +168,12 @@ public void drawTextBase(String label, double... rC) {
164168
comp2D.rotate(text_angle, x + w / 2, y - h / 2);
165169
}
166170

167-
comp2D.drawString(label, x, y);
171+
String[] lines = label.split("\n");
172+
for (int i = 0; i < lines.length; i++) {
173+
comp2D.drawString(lines[i], x, y);
174+
y += h;
175+
}
176+
//comp2D.drawString(label, x, y);
168177

169178
if (text_angle != 0) {
170179
comp2D.rotate(-text_angle, x + w / 2, y - h / 2);
@@ -180,7 +189,7 @@ public void drawTextBase(String label, double... rC) {
180189
public void drawLineBase(double[]... rC) {
181190
int[][] sC = new int[rC.length][];
182191
for (int i = 0; i < sC.length; i++) {
183-
sC[i] = projection.screenProjectionBaseRatio(rC[i]);
192+
sC[i] = projection.screenProjectionBase(rC[i]);
184193
}
185194
drawLine(sC);
186195
}
@@ -383,27 +392,27 @@ public AffineTransform getAffineTransform(int width, int height, double[] _xyzSW
383392
/*double[] _cornerSW_tr = new double[2];
384393
double[] _cornerSW = { 0, img.getHeight(canvas) };
385394
t.transform(_cornerSW, 0, _cornerSW_tr, 0, 1);
386-
395+
387396
if (isDiff(_cornerSW_tr, cornerSW)) {
388397
double[] vectSW_NW_1 = { (double) cornerNW[0] - (double) cornerSW[0], (double) cornerNW[1] - (double) cornerSW[1] };
389398
double[] vectSW_NW_2 = { (double) cornerNW[0] - (double) _cornerSW_tr[0], (double) cornerNW[1] - (double) _cornerSW_tr[1] };
390-
399+
391400
double normvect_1 = sqrt(sqr(vectSW_NW_1[0]) + sqr(vectSW_NW_1[1]));
392401
double normvect_2 = sqrt(sqr(vectSW_NW_1[0]) + sqr(vectSW_NW_1[1]));
393-
402+
394403
double cos_angle = (((vectSW_NW_1[0] * vectSW_NW_2[0] + vectSW_NW_1[1] * vectSW_NW_2[1]) / (normvect_1 * normvect_2)));
395404
double vect = (vectSW_NW_1[0] * vectSW_NW_2[1] - vectSW_NW_1[1] * vectSW_NW_2[0]);
396-
405+
397406
System.out.println(cos_angle + " " + vect + " -> " + toDegrees(acos(cos_angle)));
398-
407+
399408
//System.out.println(" "+vectSE_NW_1[0]+","+vectSE_NW_1[1]+" "+vectSE_NW_2[0]+","+vectSE_NW_2[1]);
400409
AffineTransform t2 = new AffineTransform();
401410
if (vect > 0)
402411
t2.rotate(acos(cos_angle), cornerNW[0], cornerNW[1]);
403412
else
404413
t2.rotate(-acos(cos_angle), cornerNW[0], cornerNW[1]);
405414
t.preConcatenate(t2);
406-
415+
407416
}*/
408417

409418
return t;

jmathplot/src/org/math/plot/render/AWTDrawer3D.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,24 @@
44

55
public class AWTDrawer3D extends AWTDrawer {
66

7-
public AWTDrawer3D(PlotCanvas _canvas) {
8-
super(_canvas);
9-
projection = new Projection3D(this);
10-
}
7+
public AWTDrawer3D(PlotCanvas _canvas) {
8+
super(_canvas);
9+
projection = new Projection3D(this);
10+
}
1111

12-
public void rotate(int[] t, int[] panelSize) {
13-
((Projection3D) projection).rotate(t, panelSize);
14-
}
12+
public void rotate(int[] t, int[] panelSize) {
13+
((Projection3D) projection).rotate(t, panelSize);
14+
}
1515

16+
public void dilate(int[] screenOrigin, double[] screenRatio) {
17+
super.dilate(screenOrigin, screenRatio);
18+
((Projection3D) projection).updateCoordsCenterScreen();
19+
canvas.repaint();
20+
}
21+
22+
public void translate(int... t) {
23+
super.translate(t);
24+
((Projection3D) projection).updateCoordsCenterScreen();
25+
canvas.repaint();
26+
}
1627
}

0 commit comments

Comments
 (0)