How to preserve the zoom state with JFreeChart? - java

I am using JFreeChart to draw a graph based on some input values. Once the graph is drawn, I zoom the graph by dragging the mouse. Now, I change the input values and draw the graph again based on the new input values supplied by me. I want the graph should come in the last zoom state which I zoomed earlier.
I have used the following, but is always coming to center and some other zoom position.
double zoomX = chartPanel.getScaleX();
double zoomX = chartPanel.getScaleX();
chartPanel.zoomInBoth(zoomX, zoomY);
Can anyone help me in this, how to achieve this ? Thanks in advance.

Related

How to zoom in and move a map of multiple squares?

I have 10x10 sqares that are forming a map. The variable zoom, xPos and yPos are defining how deep I am scolling in the map and the position of the camera.
Each tile has a x and y - coordinate (0-9).
How can I display this map?
I've tried to do this:
rect(xzoom+xPos, yzoom+xPos, zoom, zoom); //the function rect makes a rectangle with the center at the first 2 inputs)
The problem is that I'm always zooming in the upper left corner;
I've also tried this:
rect((x-5.5)*zoom+xPos, (y-5.5)*zoom+yPos);
but this zooms always in the center in the map while I want it to zoom in the center of the screen.
Please help me
I really suggest sitting down with some graph paper and a pencil. Draw out a bunch of example grids with their coordinates and sizes. Then draw out what they look like at different zoom level until you notice a pattern. If you can't get that pattern to work, please post an MCVE and we'll go from there.
Also note that Processing has a scale() function that might come in handy. More info is available in the reference.

Tracing a position in a circle if the view is a square

So, I am making a cutom PieChartView and now I want to hilight the piece of the chart I clicked on, however I don't know how to detect which piece of the pie chart I clicked on since the whole View is actually a square. Could anyone point me in the right direction?
Use atan2 to convert the vector with respect to the center of the chart into an angle. Turning that angle into a piece of the pie should be simple, but depends on how you represent your pie.

Putting an angle on image view

I'd like to set an angle on an image view and have that angle be generated randomly, and set the ancho point of the image view to the center of the android screen. After that I'd like the computer to generate a spot from a certain distance of the middle to the end of the screen on that angle and set a button to appear there. I'm not sure if eclipse has a quick automatic way to do that.
Thanks.
I've added a picture to help. I'd like the arrow to point to a random angle and then a button to appear on that angle but outside of the circle (the circle is imaginary just showing that it needs to appear outside of a certain distance from the center.
You can use setRotation method for rotate a view in android.
image.setRotation(90); // instead of 90 you can give your generated value.
// But make sure the value should be float.
image.setRotationX(90); // if you want rotate depends x axis
image.setRotationY(90); // if you want rotate depends y axis
also take a look on here
I hope this will help you.

Object relative to the image while zooming in or out

I have a map that is being drawn on the screen inside a VisualizationView. I am able to zoom in and out on this map, depending on where I focused inside this view using the touch functionality.
I also toggle between zooming in and drawing on this map. When I draw an arrow on the map and switch back to zooming in. I want the arrow I drawed on the map to stay at the same spot relative to the map I am zooming in and out on. Meaning the x and y pos of this arrow have to be adjusted.
I have all the variables needed I just dont know how to solve this since its math related.
Can someone explain to me how I can solve this math wise. I tried looking on the internet but I could not find a good explanation. Also the map resolution on the Tablet is always 576 x 576.
public void onZoom(final double focusX, final double focusY,
final double factor) {
//pseudocode
Triangle.x = ..
Triangle.y = ..
Triangle.repaint();
//peusocode
}
The code for the zooming is as following straight from the Library.
public void zoom(double focusX, double focusY, double factor) {
synchronized (mutex) {
Transform focus = Transform.translation(toMetricCoordinates((int) focusX, (int) focusY));
double zoom = RosMath.clamp(getZoom() * factor, MINIMUM_ZOOM, MAXIMUM_ZOOM) / getZoom();
transform = transform.multiply(focus).scale(zoom).multiply(focus.invert());
}
}
I hope someone can explain the math behind solving this.
I'm not directly familiar with the library you're using, but to move the location of the arrow (triangle) to its new location you should apply the same transform to it as you do to the map.
Think of it this way: Before zooming, the location of the arrow (the center or head of the arrow, however you define "location") and the point on the map it's pointing to have the same coordinates. After zooming, the point on the map will have moved to a new location and you want the arrow to move to that same new location, thus you need to use the same transform. Like I said, I'm not familiar with the library you're using so I can't tell you exactly how to do that, but that's where you want to be.
Note, however, that you only want to transform one point of the arrow/triangle and draw the other points relative to it. If you transform all 3 you'll end up with the arrow getting larger and smaller as you zoom in and out (which I assume you don't want).

How to change the center of the trackball in its regular implementation?

I have successfully implemented a trackball in java using the below two tutorials:
http://nehe.gamedev.net/tutorial/arcball_rotation/19003
http://www.java-tips.org/other-api-tips/jogl/arcball-rotation-nehe-tutorial-jogl-port.html
This trackball is centered at the screen center. Now, I wish to center it at any point on the screen. How can I incorporate the center logic in the existing code? How the normalization of mouse coordinates change due to introduction of center?
This can be easily achieved by transforming the mouse coordinates. When you transform the mouse coordinates as you do at the start of the first tutorial, instead of just transforming them as specified to the range -1..1, first subtract the offset from the centre of the screen where you want to make your trackball centre. So to make the trackball centre 50 pixels to the right and 20 pixels above the centre, use
MousePt.X = ((MousePt.X-50) /Width)*2)-1;
MousePt.Y = ((MousePt.X-20) /Height)*2)-1;

Categories

Resources