Package com.sencha.gxt.core.client.util

Examples of com.sencha.gxt.core.client.util.PrecisePoint


        || (curve.getY2() < curve.getY() && control2Y > curve.getY())) {
      control2X -= Math.abs(curve.getY() - control2Y) * (control2X - curve.getX2()) / (control2Y - curve.getY2());
      control2Y = curve.getY();
    }

    PrecisePoint[] points = {new PrecisePoint(control1X, control1Y), new PrecisePoint(control2X, control2Y)};
    return points;
  }
View Full Code Here


   *
   * @param event the mouse event
   */
  public void onMouseDown(Event event) {
    if (handlerManager != null && handlerManager.getHandlerCount(SpriteSelectionEvent.getType()) > 0) {
      PrecisePoint point = getEventXY(event);
      SpriteList<Sprite> sprites = surface.sprites;
      for (int i = sprites.size() - 1; i >= 0; i--) {
        Sprite sprite = sprites.get(i);
        if (sprite.getBBox().contains(point)) {
          ensureHandler().fireEvent(new SpriteSelectionEvent(sprite, event));
View Full Code Here

   *
   * @param event the mouse event
   */
  public void onMouseMove(Event event) {
    if (handlerManager != null && handlerManager.getHandlerCount(SpriteOverEvent.getType()) > 0) {
      PrecisePoint point = getEventXY(event);
      SpriteList<Sprite> sprites = surface.sprites;
      for (int i = sprites.size() - 1; i >= 0; i--) {
        Sprite sprite = sprites.get(i);
        if (sprite.getBBox().contains(point)) {
          ensureHandler().fireEvent(new SpriteOverEvent(sprite, event));
View Full Code Here

   *
   * @param event the event
   * @return the adjusted point
   */
  protected PrecisePoint getEventXY(Event event) {
    return new PrecisePoint(event.getClientX() - this.getAbsoluteLeft(), event.getClientY() - this.getAbsoluteTop());
  }
View Full Code Here

      slice.setMargin(popOutMargin);
      double labelX = 0;
      double labelY = 0;
      if (labels.size() > yFieldIndex && calloutBoxes.size() == 0) {
        double middle = Math.toRadians((slice.startAngle + slice.endAngle) / 2.0);
        PrecisePoint trans = labelPoints.get(yFieldIndex);
        labelX = popOutMargin * Math.cos(middle) + trans.getX();
        labelY = popOutMargin * Math.sin(middle) + trans.getY();
        if (Math.abs(labelX) < 1e-10) {
          labelX = 0;
        }
        if (Math.abs(labelY) < 1e-10) {
          labelY = 0;
View Full Code Here

    double a1 = Math.toRadians(Math.min(slice.getStartAngle(), slice.getEndAngle()));
    double a2 = Math.toRadians(Math.max(slice.getStartAngle(), slice.getEndAngle()));
    double midAngle = -(a1 + (a2 - a1) / 2.0);
    double xm = center.getX() + (slice.getEndRho() + slice.getStartRho()) / 2.0 * Math.cos(midAngle);
    double ym = center.getY() - (slice.getEndRho() + slice.getStartRho()) / 2.0 * Math.sin(midAngle);
    middlePoints.put(index, new PrecisePoint(xm, ym));
  }
View Full Code Here

          sprite = labelConfig.getSpriteConfig().copy();
          labels.put(i, sprite);
          chart.addSprite(sprite);
        }
        setLabelText(sprite, i);
        PrecisePoint middle = middlePoints.get(i);
        double x = middle.getX() - center.getX();
        double y = middle.getY() - center.getY();
        double rho = 1;
        double theta = Math.atan2(y, x == 0 ? 1 : x);
        double degrees = Math.toDegrees(theta);
        LabelPosition labelPosition = labelConfig.getLabelPosition();
        if (labelPosition == LabelPosition.OUTSIDE) {
          Slice slice = slices.get(i);
          rho = slice.getEndRho() + 20;
          double rhoCenter = (slice.endRho + slice.startRho) / 2.0 + (slice.endRho - slice.startRho) / 3.0;
          PrecisePoint calloutPoint = new PrecisePoint(rho * Math.cos(theta) + center.getX(), rho * Math.sin(theta)
              + center.getY());
          x = rhoCenter * Math.cos(theta);
          y = rhoCenter * Math.sin(theta);

          final PathSprite line;
          if (calloutLines.get(i) != null) {
            line = calloutLines.get(i);
            line.setHidden(false);
          } else {
            line = new PathSprite();
            line.setStrokeWidth(1);
            line.setStroke(RGB.BLACK);
            line.setFill(Color.NONE);
            calloutLines.put(i, line);
            chart.addSprite(line);
          }

          final RectangleSprite box;
          if (calloutBoxes.get(i) != null) {
            box = calloutBoxes.get(i);
            box.setHidden(false);
          } else {
            box = new RectangleSprite();
            box.setStroke(RGB.BLACK);
            box.setStrokeWidth(1);
            box.setFill(Color.NONE);
            calloutBoxes.put(i, box);
            chart.addSprite(box);
          }

          sprite.redraw();
          PreciseRectangle bbox = sprite.getBBox();

          List<PathCommand> commands = new ArrayList<PathCommand>();
          commands.add(new MoveTo(x + center.getX(), y + center.getY()));
          commands.add(new LineTo(calloutPoint.getX(), calloutPoint.getY()));
          commands.add(new LineTo(x > 0 ? 10 : -10, 0, true));

          PreciseRectangle rect = new PreciseRectangle(calloutPoint.getX() + (x > 0 ? 10 : -(bbox.getWidth() + 30)),
              calloutPoint.getY() + (y > 0 ? (-(bbox.getHeight() - 5)) : (-(bbox.getHeight() - 5))),
              bbox.getWidth() + 20, bbox.getHeight() + 20);

          PrecisePoint labelPoint = new PrecisePoint(calloutPoint.getX() + (x > 0 ? 20 : -(20 + bbox.getWidth())),
              calloutPoint.getY() + (y > 0 ? -bbox.getHeight() / 4.0 : -bbox.getHeight() / 4.0));

          if (chart.isAnimated() && line.size() > 0 && !Double.isNaN(box.getX()) && sprite.getTranslation() != null) {
            DrawFx.createCommandsAnimator(line, commands).run(chart.getAnimationDuration(), chart.getAnimationEasing());
            DrawFx.createRectangleAnimator(box, rect).run(chart.getAnimationDuration(), chart.getAnimationEasing());
            DrawFx.createTranslationAnimator(sprite, labelPoint.getX(), labelPoint.getY()).run(
                chart.getAnimationDuration(), chart.getAnimationEasing());
          } else {
            line.setCommands(commands);
            line.redraw();
            box.setX(rect.getX());
            box.setY(rect.getY());
            box.setWidth(rect.getWidth());
            box.setHeight(rect.getHeight());
            box.redraw();
            sprite.setTranslation(labelPoint.getX(), labelPoint.getY());
            sprite.redraw();
          }
        } else if (labelPosition == LabelPosition.END) {
          rho = Math.sqrt(x * x + y * y) * 2.0;
          x = rho * Math.cos(theta) + center.getX();
          y = rho * Math.sin(theta) + center.getY();
          if (chart.isAnimated() && sprite.getTranslation() != null) {
            DrawFx.createTranslationAnimator(sprite, x, y).run(chart.getAnimationDuration(), chart.getAnimationEasing());
          } else {
            sprite.setTranslation(x, y);
          }
          labelPoints.put(i, new PrecisePoint(x, y));
        } else if (labelPosition == LabelPosition.START) {
          degrees = fixAngle(degrees);
          if (degrees > 90 && degrees < 270) {
            degrees += 180;
          }
          if (!Double.isNaN(previousDegrees) && Math.abs(previousDegrees - degrees) > 180) {
            if (degrees > previousDegrees) {
              degrees -= 360;
            } else {
              degrees += 360;
            }
            degrees %= 360;
          } else {
            degrees = fixAngle(degrees);
          }
          if (labelConfig.isLabelContrast()) {
            final Sprite back = sprites.get(i);
            if (chart.isAnimated()) {
              Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                @Override
                public void execute() {
                  setLabelContrast(sprite, labelConfig, back);
                }
              });
            } else {
              setLabelContrast(sprite, labelConfig, back);
            }
          }
          labelPoints.put(i, new PrecisePoint(middle));
          if (chart.isAnimated() && sprite.getTranslation() != null) {
            DrawFx.createTranslationAnimator(sprite, middle.getX(), middle.getY()).run(chart.getAnimationDuration(),
                chart.getAnimationEasing());
            DrawFx.createRotationAnimator(sprite, 0, 0, degrees).run(chart.getAnimationDuration(),
                chart.getAnimationEasing());
View Full Code Here

      int largeArcFlag, int sweepFlag, double x2, double y2, double[] recursive) {
    double cx, cy, f1, f2;
    double rad = Math.toRadians(angle);
    List<PathCommand> res = new ArrayList<PathCommand>();
    if (recursive == null) {
      PrecisePoint xy = rotate(x1, y1, -rad);
      x1 = xy.getX();
      y1 = xy.getY();
      xy = rotate(x2, y2, -rad);
      x2 = xy.getX();
      y2 = xy.getY();
      double x = (x1 - x2) / 2.0;
      double y = (y1 - y2) / 2.0;
      double h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
      if (h > 1) {
        h = Math.sqrt(h);
        rx = h * rx;
        ry = h * ry;
      }
      double rx2 = rx * rx;
      double ry2 = ry * ry;
      double k = (largeArcFlag == sweepFlag ? -1 : 1)
          * Math.sqrt(Math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x)));
      cx = k * rx * y / ry + (x1 + x2) / 2;
      cy = k * -ry * x / rx + (y1 + y2) / 2;
      f1 = Math.asin((y1 - cy) / ry);
      f2 = Math.asin((y2 - cy) / ry);

      f1 = x1 < cx ? Math.PI - f1 : f1;
      f2 = x2 < cx ? Math.PI - f2 : f2;
      if (f1 < 0) {
        f1 = Math.PI * 2 + f1;
      }
      if (f2 < 0) {
        f2 = Math.PI * 2 + f2;
      }
      if (sweepFlag == 1 && f1 > f2) {
        f1 = f1 - Math.PI * 2;
      }
      if (sweepFlag == 0 && f2 > f1) {
        f2 = f2 - Math.PI * 2;
      }
    } else {
      f1 = recursive[0];
      f2 = recursive[1];
      cx = recursive[2];
      cy = recursive[3];
    }
    double constant = Math.PI * 120 / 180;
    if (Math.abs(f2 - f1) > constant) {
      double f2Old = f2;
      double x2Old = x2;
      double y2Old = y2;
      f2 = f1 + constant * (sweepFlag == 1 && f2 > f1 ? 1 : -1);
      x2 = cx + rx * Math.cos(f2);
      y2 = cy + ry * Math.sin(f2);
      res = arc2curveRecursive(x2, y2, rx, ry, angle, 0, sweepFlag, x2Old, y2Old, new double[] {f2, f2Old, cx, cy});
    }
    double c1 = Math.cos(f1);
    double s1 = Math.sin(f1);
    double c2 = Math.cos(f2);
    double s2 = Math.sin(f2);
    double df = f2 - f1;
    double t = Math.tan(df / 4.0);
    double hx = 4.0 / 3.0 * rx * t;
    double hy = 4.0 / 3.0 * ry * t;
    PrecisePoint m1 = new PrecisePoint(x1, y1);
    PrecisePoint m2 = new PrecisePoint(x1 + hx * s1, y1 - hy * c1);
    PrecisePoint m3 = new PrecisePoint(x2 + hx * s2, y2 - hy * c2);
    PrecisePoint m4 = new PrecisePoint(x2, y2);
    m2.setX(2 * m1.getX() - m2.getX());
    m2.setY(2 * m1.getY() - m2.getY());
    if (res.size() > 0) {
      res.add(0, new CurveTo(m2.getX(), m2.getY(), m3.getX(), m3.getY(), m4.getX(), m4.getY()));
    } else {
      res.add(new CurveTo(m2.getX(), m2.getY(), m3.getX(), m3.getY(), m4.getX(), m4.getY()));
    }
    if (recursive == null) {
      for (int k = 0; k < res.size(); k++) {
        CurveTo curve = (CurveTo) res.get(k);
        PrecisePoint current = rotate(curve.getX1(), curve.getY1(), rad);
        curve.setX1(current.getX());
        curve.setY1(current.getY());
        current = rotate(curve.getX2(), curve.getY2(), rad);
        curve.setX2(current.getX());
        curve.setY2(current.getY());
        current = rotate(curve.getX(), curve.getY(), rad);
        curve.setX(current.getX());
        curve.setY(current.getY());
      }
    }
    return res;
  }
View Full Code Here

  }

  private PrecisePoint rotate(double x, double y, double rad) {
    double cos = Math.cos(rad);
    double sin = Math.sin(rad);
    return new PrecisePoint(x * cos - y * sin, x * sin + y * cos);
  }
View Full Code Here

   * @return the end point of the command
   */
  protected PrecisePoint getPointFromCommand(PathCommand command) {
    if (command instanceof EndPointCommand) {
      EndPointCommand end = (EndPointCommand) command;
      return new PrecisePoint(end.getX(), end.getY());
    } else {
      return new PrecisePoint();
    }
  }
View Full Code Here

TOP

Related Classes of com.sencha.gxt.core.client.util.PrecisePoint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.