Autoadjust vertial axis after zoom

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
dunabur
Posts: 19
Joined: Sat Jun 24, 2017 12:05 pm
antibot: No, of course not.

Autoadjust vertial axis after zoom

Post by dunabur » Wed Aug 16, 2017 1:18 pm

I`m trying to find out how to trigger the code that starts when doing rightclick-autoadjust-vertical axis (translated my me, might be called differently) after I have zoomed into the chart.

Basically, after using mouse zoom, I want rightclick->autoadjust->vertical axis to be executed automatically.

I assume that a simple rangeAxis.configure(); would be sufficient. However, I could not find out where to place the code. This is what I have tried:

Code: Select all

chartPanel.addMouseListener(new MouseListener() {

            @Override
            public void mouseReleased(MouseEvent e) {
                // process before
            	chartPanel.mouseReleased(e);
            	System.out.println("triggered");
                rangeAxis.configure();
                // process after
            }

			@Override
			public void mouseClicked(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
        });
And indeed, when releasing my mouse, it gets triggered, but there are two problems:
1. it gets triggered after every release, which is too broad, and
2. other then recognizing that the mouse has been released, it does nothing.

Then I've tried this:

Code: Select all

ChartPanel chartPanel = new ChartPanel(chart) {
        	
        @Override
        public void mouseReleased(MouseEvent e){
        	super.mouseReleased(e);
        	super.actionPerformed(org.jfree.chart.ChartPanel.actionPerformed.ZOOM_IN_RANGE_COMMAND);
        	rangeAxis.configure();
        	
        }
        	
        };
but rangeAxis.configure(); does again nothing after zooming, and I fail to find the right way to start the dropdown menu function myself.

I think I am really off in my coding efforts so far.
I`d really appreciate any help!

dunabur
Posts: 19
Joined: Sat Jun 24, 2017 12:05 pm
antibot: No, of course not.

Re: Autoadjust vertial axis after zoom

Post by dunabur » Wed Aug 16, 2017 7:51 pm

I was dead wrong, however now I`ve managed to get it working. This is the code to make the mouse zoom autoadjust to the Y (rangeAxis) axis:

Code: Select all

ChartPanel chartPanel = new ChartPanel(chart){
        	
        	// makes the zoom from rightclick dropdown menu autoadjust the y axis
            @Override
            public void zoomInRange(double x, double y) {
            	super.zoomInRange(x,y);
            	System.out.println("triggered now");
            	restoreAutoRangeBounds();
            }
        	//makes the left click zoom autoadjust the y axis
                @Override
        	public void zoom(Rectangle2D selection) {
        		super.zoom(selection);
        		restoreAutoRangeBounds();
        		System.out.println(" zoom triggered now");
        		//rangeAxis.configure();
        	}
        };

Locked