[XYShapeRenderer/LookupPaintScale]Crosshair not locking data

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
NaggingDaivy
Posts: 21
Joined: Mon Jan 09, 2017 2:04 pm
antibot: No, of course not.

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by NaggingDaivy » Thu Feb 16, 2017 10:00 am

Hello David, I can confirm that the fix is OK for XYShapeRenderer, but not for XYBlockRenderer, which I am using right now and I need it... My code for testing is the same as before.

EDIT : I fixed that directly in your code (XYBlockRenderer.java), it was the same issue as for XYShapeRenderer :

Code: Select all

   @Override
    public void drawItem(Graphics2D g2, XYItemRendererState state,
            Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
            ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
            int series, int item, CrosshairState crosshairState, int pass) {

        double x = dataset.getXValue(series, item);
        double y = dataset.getYValue(series, item);
        double z = 0.0;

        //DAIVY

        double transX = domainAxis.valueToJava2D(x, dataArea,
                plot.getDomainAxisEdge());
        double transY = rangeAxis.valueToJava2D(y, dataArea,
                plot.getRangeAxisEdge());

        //DAIVY END

        if (dataset instanceof XYZDataset) {
            z = ((XYZDataset) dataset).getZValue(series, item);
        }
        Paint p = this.paintScale.getPaint(z);
        double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea,
                plot.getDomainAxisEdge());
        double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea,
                plot.getRangeAxisEdge());
        double xx1 = domainAxis.valueToJava2D(x + this.blockWidth
                + this.xOffset, dataArea, plot.getDomainAxisEdge());
        double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight
                + this.yOffset, dataArea, plot.getRangeAxisEdge());
        Rectangle2D block;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation.equals(PlotOrientation.HORIZONTAL)) {
            block = new Rectangle2D.Double(Math.min(yy0, yy1),
                    Math.min(xx0, xx1), Math.abs(yy1 - yy0),
                    Math.abs(xx0 - xx1));
        }
        else {
            block = new Rectangle2D.Double(Math.min(xx0, xx1),
                    Math.min(yy0, yy1), Math.abs(xx1 - xx0),
                    Math.abs(yy1 - yy0));
        }
        g2.setPaint(p);
        g2.fill(block);
        g2.setStroke(new BasicStroke(1.0f));
        g2.draw(block);

        //DAIVY
        int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        
        updateCrosshairValues(crosshairState, x, y, domainAxisIndex,
                    rangeAxisIndex, transX, transY, orientation);

        //DAIVY END

        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            //addEntity(entities, block, dataset, series, item, 0.0, 0.0); // ORIGINAL
               addEntity(entities, block, dataset, series, item, transX, transY); // DME
        }

    }

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by david.gilbert » Mon Feb 20, 2017 9:42 pm

Thanks for the report. I committed this fix (more or less the same as yours):

https://github.com/jfree/jfreechart/com ... 2398c6b250

Then I had a follow up commit to fix the typo :-)
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by david.gilbert » Mon Feb 20, 2017 9:43 pm

Oh wait...my fix is wrong and yours was better. I'll change that.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by david.gilbert » Mon Feb 20, 2017 9:50 pm

Done
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

NaggingDaivy
Posts: 21
Joined: Mon Jan 09, 2017 2:04 pm
antibot: No, of course not.

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by NaggingDaivy » Tue Feb 21, 2017 3:21 pm

david.gilbert wrote:Done
Don't you forget the entities ?

Code: Select all

        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            //addEntity(entities, block, dataset, series, item, 0.0, 0.0); // ORIGINAL
               addEntity(entities, block, dataset, series, item, transX, transY); // DME
        }

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by david.gilbert » Wed Feb 22, 2017 6:23 pm

Indeed I did miss it. It makes no difference, since those parameters are only used if the entity shape is not specified. But I'll update the code anyway since it looks more sensible to have the transX and transY in there.

Thanks for the feedback.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

NaggingDaivy
Posts: 21
Joined: Mon Jan 09, 2017 2:04 pm
antibot: No, of course not.

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by NaggingDaivy » Thu Feb 23, 2017 2:23 pm

david.gilbert wrote:Indeed I did miss it. It makes no difference, since those parameters are only used if the entity shape is not specified. But I'll update the code anyway since it looks more sensible to have the transX and transY in there.

Thanks for the feedback.
By the way David, I am loading data from a 17Mo file; each line of this file contains values for x,y and z (the RAM amount used by JFreeChart is huge, around 1500Mo)
When using a XYBlockRenderer, when I click on the graph, the wait is a few seconds to actually show the crosshairs in X and Y. (http://imgur.com/a/stly3)
However, when using XYDotRenderer, it is much more fast, but I can't use my paintscale (http://imgur.com/a/utN75)
So my question is : how to use a paintscale with a XYDotRenderer ? (setPaintScale method does not exist for it).

Locked