/** * Returns a new transcaler that combines this transcaler with projectors. * The returned transcaler includes the transforms of the projectors. * Does not change this transcaler. * @param xp the projector for x coordinates. * @param yp the projector for y coordinates. * @return the new transcaler. */ public Transcaler combineWith(Projector xp, Projector yp) { AxisScale xsc = xp.getScale(); AxisScale ysc = yp.getScale(); double x1v = (xsc==AxisScale.LOG10)?log10(xp.v(_x1u)):xp.v(_x1u); double x2v = (xsc==AxisScale.LOG10)?log10(xp.v(_x2u)):xp.v(_x2u); double y1v = (ysc==AxisScale.LOG10)?log10(yp.v(_y1u)):yp.v(_y1u); double y2v = (ysc==AxisScale.LOG10)?log10(yp.v(_y2u)):yp.v(_y2u); return new Transcaler(x1v,y1v,x2v,y2v,_x1d,_y1d,_x2d,_y2d, xsc, ysc); }
private static void assertVeryClose (Projector expected, Projector actual) { boolean success = true; success &= Math.abs(expected.u0()-actual.u0()) <= eps; success &= Math.abs(expected.u1()-actual.u1()) <= eps; success &= Math.abs(expected.v0()-actual.v0()) <= eps; success &= Math.abs(expected.v1()-actual.v1()) <= eps; if (!success) fail("Expected: <"+expected+"> but was:<"+actual+">"); }
/** * Sets the best projectors for this tiled view. Classes that extend * this class call this method when their best projectors change. * @param bhp a horizontal projector. * @param bvp a vertical projector. */ protected void setBestProjectors(Projector bhp, Projector bvp) { if (!equal(_bhp,bhp) || !equal(_bvp,bvp)) { _bhp = (bhp!=null)?new Projector(bhp):null; _bvp = (bvp!=null)?new Projector(bvp):null; // protect against setting unsupported TiledViews to non-linear scales if(setScales(bhp.getScale(),bvp.getScale())==null){ _bhp.setScale(AxisScale.LINEAR); _bvp.setScale(AxisScale.LINEAR); } if (_tile!=null) _tile.alignProjectors(_bhp.getScale(),_bvp.getScale()); } }
/** * Sets limits for the vertical axis. * By default, limits are computed automatically by tiled graphical views. * This method can be used to override those default limits. * @param vmin the minimum value. * @param vmax the maximum value. */ public void setVLimits(double vmin, double vmax) { Check.argument(vmin<vmax,"vmin<vmax"); if(_bvp!=null && _bvp.isLog()) Check.argument(vmin>0,"vmin>0 for LOG scales"); if(_bvp.v0()<_bvp.v1()) _svp = new Projector(vmin,vmax); else _svp = new Projector(vmax,vmin); alignProjectors(); }
double umin = p.u0(); double umax = p.u1(); double vmin = min(p.v0(),p.v1()); double vmax = max(p.v0(),p.v1()); double v0 = max(vmin,min(vmax,p.v(u0))); double v1 = max(vmin,min(vmax,p.v(u1))); double dv = abs(p.v(u0+du)-p.v(u0)); if(p.getScale() == AxisScale.LINEAR) _axisTics = new AxisTics(v0,v1,dtic); else if (p.getScale()==AxisScale.LOG10) { double v0a = min(v0,v1); double v1a = max(v0,v1);
public void testProjectionLog () { Projector p = new Projector(0.1, 100, 0.0, 1.0, AxisScale.LOG10); assertVeryClose(0.1, p.v(p.u(0.1))); assertVeryClose(2, p.v(p.u(2))); assertVeryClose(56.7785, p.v(p.u(56.7785))); assertVeryClose(0.0, p.u(p.v(0.0))); assertVeryClose(0.25, p.u(p.v(0.25))); assertVeryClose(0.6173, p.u(p.v(0.6173))); }
private void computeXY( Projector hp, Projector vp, Transcaler ts, int n, float[] x1, float[] x2, int[] x, int[] y) { ts = ts.combineWith(hp,vp); float[] xv = null; float[] yv = null; if (_orientation==Orientation.X1RIGHT_X2UP) { xv = x1; yv = x2; } else if (_orientation==Orientation.X1DOWN_X2RIGHT) { xv = x2; yv = x1; } double hLeft = Math.min(hp.v0(),hp.v1()); double vBot = Math.min(vp.v0(),vp.v1()); for (int i=0; i<n; ++i) { x[i] = ts.x((xv[i]<=0 && hp.getScale()==AxisScale.LOG10)?hLeft:xv[i]); y[i] = ts.y((yv[i]<=0 && vp.getScale()==AxisScale.LOG10)?vBot:yv[i]); } }
TiledView tv = _tvs.get(itv); if(tv.getBestHorizontalProjector()!=null) bhp = new Projector(tv.getBestHorizontalProjector()); bhp.merge(tv.getBestHorizontalProjector()); _shp.setScale(hscale); TiledView tv = _tvs.get(itv); if(tv.getBestVerticalProjector()!=null) bvp = new Projector(tv.getBestVerticalProjector()); bvp.merge(tv.getBestVerticalProjector()); _svp.setScale(vscale); _bhp.setScale(AxisScale.LINEAR); if(!checkScales[1]) _bvp.setScale(AxisScale.LINEAR);
/** * Called when we might new realignment. */ private void updateBestProjectors() { // Assume mark sizes and line widths less than 2% of plot dimensions. // The goal is to avoid clipping big marks and wide lines. The problem // is that mark sizes and line widths are specified in screen pixels // (or points), but margins u0 and u1 are specified in normalized // coordinates, fractions of our tile's width and height. Here, we do // not know those dimensions. double u0 = 0.0; double u1 = 1.0; if ((_drawNodes && _markWidth>1.0f) || _lineWidth>1.0f) { u0 = 0.01; u1 = 0.99; } // Best projectors. Projector bhp = null; Projector bvp = null; if (_orientation==Orientation.XRIGHT_YUP) { bhp = (_xmin<_xmax)?new Projector(_xmin,_xmax,u0,u1):null; bvp = (_ymin<_ymax)?new Projector(_ymax,_ymin,u0,u1):null; } else if (_orientation==Orientation.XDOWN_YRIGHT) { bhp = (_ymin<_ymax)?new Projector(_ymin,_ymax,u0,u1):null; bvp = (_xmin<_xmax)?new Projector(_xmin,_xmax,u0,u1):null; } setBestProjectors(bhp,bvp); }
double vy0 = _fy-0.5*_dy; double vy1 = _fy+_dy*(_ny-0.5); double ux0 = hp.u(vx0); double ux1 = hp.u(vx1); double uy0 = vp.u(vy0); double uy1 = vp.u(vy1); double uxmin = min(ux0,ux1); double uxmax = max(ux0,ux1); double wu = ts.width(wc); double hu = ts.height(hc); double x0 = hp.v(xu); double y0 = vp.v(yu); double x1 = hp.v(xu+wu); double y1 = vp.v(yu+hu);
/** * Transforms a pixel x coordinate to a horizontal world coordinate. * @param x the pixel x coordinate. * @return the horizontal world coordinate. */ public double pixelToWorldHorizontal(int x) { return _hp.v(_ts.x(x)); }
boolean isLeft = isLeft(); boolean isVerticalRotated = isVerticalRotated(); boolean isLogScale = (p.getScale().isLog()); double utic = p.u(vtic); if (isHorizontal) { x = t.x(utic); double vtic = isLogScale?fticMajor*Math.pow(10, itic) :fticMajor+itic*dticMajor; double utic = p.u(vtic); if (abs(vtic)<tiny) vtic = 0.0;
/** * Gets the Vertical axis scaling. * @return the Scale; null, if none. */ public AxisScale getVScale() { return (_bvp!=null)?_bvp.getScale():AxisScale.LINEAR; }
double rbx = ballRadiusX()*hp.getScaleRatio(bhp); double rby = ballRadiusY()*vp.getScaleRatio(bvp); int xf = ts.x(hp.u(fx)); int xl = ts.x(hp.u(lx)); int x1 = min(xf,xl)-rb; int x2 = max(xf,xl)+rb; int y0 = ts.y(vp.u(0.0)); g2d.drawLine(x1,y0,x2,y0); double xi = fx+ix*dx; double fi = _f[ix]; int x = ts.x(hp.u(xi)); int y = ts.y(vp.u(fi)); g2d.drawLine(x,y0,x,y); g2d.fillOval(x-rb,y-rb,1+2*rb,1+2*rb);
/** * Sets limits for the horizontal axis. * By default, limits are computed automatically by tiled graphical views. * This method can be used to override those default limits. * @param hmin the minimum value. * @param hmax the maximum value. */ public void setHLimits(double hmin, double hmax) { Check.argument(hmin<hmax,"hmin<hmax"); if(_bhp!=null &&_bhp.isLog()) Check.argument(hmin>0,"hmin>0 for LOG scales"); _shp = new Projector(hmin,hmax); alignProjectors(); }
Projector bhp = tile.getBestHorizontalProjector(); if (bhp!=null) { bhp = new Projector(bhp); for (int irow=0; irow<_nrow; ++irow) { if (irow!=jrow) bhp.merge(_tiles[irow][jcol].getBestHorizontalProjector()); bvp = new Projector(bvp); for (int icol=0; icol<_ncol; ++icol) { if (icol!=jcol) bvp.merge(_tiles[jrow][icol].getBestVerticalProjector()); bhp.setScale(AxisScale.LINEAR); if(!checkScales[1] && bvp!=null) bvp.setScale(AxisScale.LINEAR);