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

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


   *
   * @param relativeX the relative x-coordinate
   * @param relativeY the relative y-coordinate
   */
  public void updatePosition(double relativeX, double relativeY) {
    PrecisePoint relative = new PrecisePoint(relativeX, relativeY);
    if (label != null) {
      label.setX(20 + relative.getX() + x);
      label.setY(relative.getY() + y - (label.getBBox().getHeight() / 2.0));
      if (legend.getLabelRenderer() != null) {
        legend.getLabelRenderer().spriteRenderer(label, yFieldIndex, legend.getChart().getCurrentStore());
      }
      label.redraw();
    }
    if (mask != null) {
      mask.setTranslation(relative.getX() + x + 1, relative.getY() + y - 1);
      mask.redraw();
    }
    if (marker != null) {
      double width = marker.getBBox().getWidth();
      marker.setTranslation(relative.getX() + x + width / 2.0, relative.getY() + y);
      if (legend.getMarkerRenderer() != null) {
        legend.getMarkerRenderer().spriteRenderer(marker, yFieldIndex, legend.getChart().getCurrentStore());
      }
      marker.redraw();
    }
    if (line != null) {
      line.setTranslation(relative.getX() + x, relative.getY() + y);
      if (legend.getLineRenderer() != null) {
        legend.getLineRenderer().spriteRenderer(line, yFieldIndex, legend.getChart().getCurrentStore());
      }
      line.redraw();
    }
View Full Code Here


          for (int i = 1; i < dashesY; i++) {
            commands.add(new MoveTo(currentX + dashSize, Math.floor(currentY + delta * i / dashesY) + 0.5));
            commands.add(new LineTo(dashSize + 1, 0, true));
          }
        }
        ticks.add(new PrecisePoint(Math.floor(x), Math.floor(currentY)));
        currentY -= delta;
        if (delta == 0) {
          break;
        }
      }
      if (Math.round(currentY + delta - (y - gutterY - trueLength)) != 0) {
        commands.add(new MoveTo(currentX, Math.floor(y - length + gutterY) + 0.5));
        commands.add(new LineTo(dashSize * 2 + 1, 0, true));
        for (int i = 1; i < dashesY; i++) {
          commands.add(new MoveTo(currentX + dashSize, Math.floor(currentY + delta * i / dashesY) + 0.5));
          commands.add(new LineTo(dashSize + 1, 0, true));
        }
        ticks.add(new PrecisePoint(Math.floor(x), Math.floor(currentY)));
      }
    } else {
      currentX = x + gutterX;
      if (position == Position.BOTTOM) {
        currentY = y - dashSize * 2;
      } else {
        currentY = y - dashSize * 4;
      }
      while (currentX <= x + gutterX + trueLength) {
        commands.add(new MoveTo(Math.floor(currentX) + 0.5, currentY + 6));
        commands.add(new LineTo(0, dashSize * 2 + 1, true));
        if (currentX != x + gutterX) {
          for (int i = 1; i < dashesX; i++) {
            commands.add(new MoveTo(Math.floor(currentX - delta * i / dashesX) + 0.5, currentY + 6));
            commands.add(new LineTo(0, dashSize + 1, true));
          }
        }
        ticks.add(new PrecisePoint(Math.floor(currentX), Math.floor(y)));
        currentX += delta;
        if (delta == 0) {
          break;
        }
      }
      if (Math.round(currentX - delta - (x + gutterX + trueLength)) != 0) {
        commands.add(new MoveTo(Math.floor(x + length - gutterX) + 0.5, currentY + 6));
        commands.add(new LineTo(0, dashSize * 2 + 1, true));
        for (int i = 1; i < dashesX; i++) {
          commands.add(new MoveTo(Math.floor(x + length - gutterX - delta * i / dashesX) + 0.5, currentY + 6));
          commands.add(new LineTo(0, dashSize + 1, true));
        }
        ticks.add(new PrecisePoint(Math.floor(currentX), Math.floor(y)));
      }
    }

    createLabels();

View Full Code Here

    if (gridOddConfig != null || gridEvenConfig != null) {
      i = 1;
    }

    for (; i < ln; i++) {
      PrecisePoint point = ticks.get(i);
      PrecisePoint prevPoint;
      if (i > 0) {
        prevPoint = ticks.get(i - 1);
      } else {
        prevPoint = new PrecisePoint();
      }
      if (gridOddConfig != null || gridEvenConfig != null) {
        styles = ((i % 2 != 0) ? gridOddConfig : gridEvenConfig);
        if (styles != null) {
          lineWidth = styles.getStrokeWidth() / 2;
        } else {
          lineWidth = 0;
        }
        commands = (i % 2 == 0 ? evenCommands : oddCommands);
        if (position == Position.LEFT) {
          commands.add(new MoveTo(prevPoint.getX() + 1 + lineWidth, prevPoint.getY() + 0.5 - lineWidth));
          commands.add(new LineTo(prevPoint.getX() + 1 + width - lineWidth, prevPoint.getY() + 0.5 - lineWidth));
          commands.add(new LineTo(point.getX() + 1 + width - lineWidth, point.getY() + 0.5 + lineWidth));
          commands.add(new LineTo(point.getX() + 1 + lineWidth, point.getY() + 0.5 + lineWidth));
          commands.add(new ClosePath());

        } else if (position == Position.RIGHT) {
          commands.add(new MoveTo(prevPoint.getX() - lineWidth, prevPoint.getY() + 0.5 - lineWidth));
          commands.add(new LineTo(prevPoint.getX() - width + lineWidth, prevPoint.getY() + 0.5 - lineWidth));
          commands.add(new LineTo(point.getX() - width + lineWidth, point.getY() + 0.5 + lineWidth));
          commands.add(new LineTo(point.getX() - lineWidth, point.getY() + 0.5 + lineWidth));
          commands.add(new ClosePath());
        } else if (position == Position.TOP) {
          commands.add(new MoveTo(prevPoint.getX() + 0.5 + lineWidth, prevPoint.getY() + 0.5 - lineWidth));
          commands.add(new LineTo(prevPoint.getX() + 0.5 + lineWidth, prevPoint.getY() + 1 + width - lineWidth));
          commands.add(new LineTo(point.getX() + 0.5 - lineWidth, point.getY() + 1 + width - lineWidth));
          commands.add(new LineTo(point.getX() + 0.5 - lineWidth, point.getY() + 1 + lineWidth));
          commands.add(new ClosePath());
        } else {
          commands.add(new MoveTo(prevPoint.getX() + 0.5 + lineWidth, prevPoint.getY() + 1 + lineWidth));
          commands.add(new LineTo(prevPoint.getX() + 0.5 + lineWidth, prevPoint.getY() - width + lineWidth));
          commands.add(new LineTo(point.getX() + 0.5 - lineWidth, point.getY() - width + lineWidth));
          commands.add(new LineTo(point.getX() + 0.5 - lineWidth, point.getY() - lineWidth));
          commands.add(new ClosePath());
        }
      } else if (defaultGridConfig != null) {
View Full Code Here

   * Renders labels on a horizontal axis and returns the height
   *
   * @return the height
   */
  private double drawHorizontalLabels() {
    PrecisePoint point;
    PreciseRectangle bbox = new PreciseRectangle();
    PreciseRectangle previousBBox = null;
    TextSprite textLabel = null;
    double x = 0;
    double y = 0;
    double maxHeight = height;
    boolean vertical = false;
    double furthestLabel = 0;
    int horizontalLabelPadding = textLabelPadding;
    Rotation labelRotation = labelConfig.getRotation();

    if (labelRotation != null) {
      vertical = (Math.floor((labelRotation.getDegrees() - 90) % 180) == 0);
    }

    for (int i = 0; i < ticks.size() / labelStepRatio; i++) {
      point = ticks.get(i * labelStepRatio);
      textLabel = getOrCreateLabel(i);

      bbox = textLabel.getBBox();

      maxHeight = Math.max(maxHeight, bbox.getHeight() + dashSize + horizontalLabelPadding);

      if (!vertical) {
        x = Math.floor(point.getX() - (bbox.getHeight() / 2.0));
      } else {
        x = Math.floor(point.getX() - (bbox.getWidth() / 2.0));
      }

      if (position == Position.TOP) {
        y = Math.floor(point.getY() - dashSize - horizontalLabelPadding - bbox.getHeight());
      } else {
        y = Math.floor(point.getY() + dashSize + horizontalLabelPadding);
        if (labelRotation != null) {
          y += bbox.getHeight();
        }
      }

View Full Code Here

   * Renders labels on a vertical axis and returns the width.
   *
   * @return the width
   */
  private double drawVerticalLabels() {
    PrecisePoint point;
    PreciseRectangle bbox = new PreciseRectangle();
    PreciseRectangle previousBBox = null;
    TextSprite textLabel = null;
    double x = 0;
    double y = 0;
    double maxWidth = width;
    double furthestLabel = chart.getBBox().getHeight();
    for (int i = 0; i < ticks.size() / labelStepRatio; i++) {

      point = ticks.get(i * labelStepRatio);
      textLabel = getOrCreateLabel(i);

      bbox = textLabel.getBBox();
      maxWidth = Math.max(maxWidth, bbox.getWidth() + dashSize + textLabelPadding);

      y = point.getY() - (bbox.getHeight() / 2.0);
      if (position == Position.LEFT) {
        x = point.getX() - bbox.getWidth() - dashSize - textLabelPadding;
      } else {
        x = point.getX() + dashSize + textLabelPadding;
      }

      textLabel.setHidden(false);
      textLabel.setX(x);
      textLabel.setY(y);
View Full Code Here

    double x = 0;
    double y = 0;
    boolean gap = false;
    for (int i = 0; i < store.size(); i++) {
      PrecisePoint point = coordinates.get(i);
      if (point != null) {
        x = point.getX();
        y = point.getY();
      } else {
        x = y = Double.NaN;
      }
      if (!Double.isNaN(x) && !Double.isNaN(y)) {
        if (onbreak) {
          onbreak = false;
        }
        if (lineCommands.size() > 0 && !gap) {
          lineCommands.add(new LineTo(x, y));
        } else {
          lineCommands.add(new MoveTo(x, y));
          gap = false;
        }
        gapPosition.put(String.valueOf(lineCommands.size() - 1), i);
      } else if (!gapless) {
        gap = true;
      }

      if (Double.isNaN(firstY) && !Double.isNaN(y)) {
        firstY = y;
      }
    }

    List<PathCommand> renderCommands;

    if (smooth && lineCommands.size() > 0) {
      PathSprite smooth = new PathSprite();
      smooth.setCommands(lineCommands);
      renderCommands = smooth.copy().toSmooth(segments).getCommands();
    } else {
      renderCommands = PathSprite.copyCommands(lineCommands);
    }

    // Correct path if we're animating timeAxis intervals
    if (markerIndex > 0 && previousCommands != null && previousCommands.size() > 1) {
      previousCommands.remove(1);
      line.setCommands(previousCommands);
      if (chart.hasShadows()) {
        for (int i = 0; i < lineShadows.size(); i++) {
          PathSprite shadow = lineShadows.get(i);
          shadow.setCommands(previousCommands);
        }
      }
    }

    List<PathCommand> dummyCommands = new ArrayList<PathCommand>();
    dummyCommands.add(new MoveTo(bbox.getX(), bbox.getY() + bbox.getHeight() / 2.0));
    for (int k = 1; k < lineCommands.size(); k++) {
      dummyCommands.add(new LineTo(bbox.getX() + bbox.getWidth() / k, bbox.getY() + bbox.getHeight() / 2.0));
    }

    // Only create a line if one doesn't exist.
    if (line == null) {
      line = new PathSprite();
      line.setStroke(stroke);
      chart.addSprite(line);
      line.setCommands(dummyCommands);

      if (chart.hasShadows()) {
        // create shadows
        for (int i = 0; i < shadowGroups.size(); i++) {
          PathSprite shadow = new PathSprite();
          Sprite shadowAttr = shadowAttributes.get(i);
          shadow.setStrokeWidth(shadowAttr.getStrokeWidth());
          shadow.setStrokeOpacity(shadowAttr.getStrokeOpacity());
          shadow.setStroke(shadowAttr.getStroke());
          shadow.setTranslation(new Translation(shadowAttr.getTranslation()));
          shadow.setFill(Color.NONE);
          shadow.setCommands(line.getCommands());
          chart.addSprite(shadow);
          lineShadows.add(shadow);
        }
      }
    }
    if (stroke != null) {
      line.setStroke(stroke);
    }
    if (!Double.isNaN(strokeWidth)) {
      line.setStrokeWidth(strokeWidth);
    }
    line.setFill(Color.NONE);

    if (chart.isAnimated() && line.size() > 0) {
      if (markerIndex > 0) {
        if (smooth) {
          renderCommands.remove(1);
        } else {
          MoveTo move = (MoveTo) renderCommands.get(0);
          renderCommands.add(1, new LineTo(move.getX(), move.getY()));
        }
        previousCommands = renderCommands;
      }
      DrawFx.createCommandsAnimator(line, renderCommands).run(500);
    } else {
      line.setCommands(renderCommands);
      line.redraw();
    }

    if (lineRenderer != null) {
      lineRenderer.spriteRenderer(line, 0, chart.getStore());
    }

    if (fill != Color.NONE && fill != null) {
      fillCommands.addAll(renderCommands);
      fillCommands.add(new LineTo(x, bbox.getY() + bbox.getHeight()));
      fillCommands.add(new LineTo(bbox.getX(), bbox.getY() + bbox.getHeight()));
      fillCommands.add(new LineTo(bbox.getX(), firstY));

      if (fillSprite == null) {
        fillSprite = new PathSprite();
        fillSprite.setOpacity(0.3);
        fillSprite.setFill(fill);
        fillSprite.setCommands(dummyCommands);
        chart.addSprite(fillSprite);
      }
      if (chart.isAnimated() && fillSprite.size() > 0) {
        DrawFx.createCommandsAnimator(fillSprite, fillCommands).run(chart.getAnimationDuration(),
            chart.getAnimationEasing());
      } else {
        fillSprite.setCommands(fillCommands);
        fillSprite.redraw();
      }
      if (fillRenderer != null) {
        fillRenderer.spriteRenderer(fillSprite, 0, chart.getStore());
      }
    }

    if (chart.hasShadows()) {
      for (int i = 0; i < lineShadows.size(); i++) {
        PathSprite shadow = lineShadows.get(i);
        if (!hidden) {
          shadow.setHidden(false);
        }
        if (chart.isAnimated()) {
          DrawFx.createCommandsAnimator(shadow, renderCommands).run(chart.getAnimationDuration(),
              chart.getAnimationEasing());
        } else {
          shadow.setCommands(renderCommands);
          shadow.redraw();
        }
        if (shadowRenderer != null) {
          shadowRenderer.spriteRenderer(shadow, i, chart.getCurrentStore());
        }
      }
      shadowed = true;
    } else {
      hideShadows();
    }

    if (showMarkers) {
      for (int i = 0; i < lineCommands.size(); i++) {
        int index = i;
        PrecisePoint point = getPointFromCommand(lineCommands.get(index));
        if (index < sprites.size()) {
          marker = sprites.get(index);
          marker.setHidden(false);
        } else {
          marker = markerConfig.copy();
          if (i == 0) {
            marker.setTranslation(bbox.getX(), bbox.getY() + bbox.getHeight() / 2.0);
          } else {
            marker.setTranslation(bbox.getX() + bbox.getWidth() / i, bbox.getY() + bbox.getHeight() / 2.0);
          }
          sprites.add(marker);
          chart.addSprite(marker);
        }
        if (hidden) {
          marker.setHidden(true);
        }
        if (chart.isAnimated() && marker.getTranslation() != null
            && ((markerIndex <= 0) || (markerIndex > 0 && index != sprites.size() - 1))) {
          DrawFx.createTranslationAnimator(marker, point.getX(), point.getY()).run(chart.getAnimationDuration(),
              chart.getAnimationEasing());
        } else {
          marker.setTranslation(point.getX(), point.getY());
          marker.redraw();
        }
        if (renderer != null) {
          renderer.spriteRenderer(marker, index, store);
        }
View Full Code Here

            });
          } else {
            setLabelContrast(sprite, labelConfig, back);
          }
        }
        PrecisePoint point = getPointFromCommand(lineCommands.get(i));
        double x = point.getX();
        double y = point.getY();
        if (showMarkers) {
          PreciseRectangle textBox = sprite.getBBox();

          y -= textBox.getHeight() / 2.0;
        }
View Full Code Here

  }

  @Override
  protected int getIndex(PrecisePoint point) {
    for (int i = 0; i < lineCommands.size(); i++) {
      PrecisePoint pointCommand = getPointFromCommand(lineCommands.get(i));
      if (point.equalsNoPrecision(new PrecisePoint(pointCommand.getX(), pointCommand.getY()), selectionTolerance)) {
        return gapPosition.get(String.valueOf(i));
      }
    }
    return -1;
  }
View Full Code Here

        double width = TextMetrics.get().getWidth(split.get(i));
        bbox.setWidth(Math.max(bbox.getWidth(), width));
      }
      bbox.setHeight(sprite.getFontSize() * split.length());

      PrecisePoint point = textRenderedPoints.get(sprite);
      TextBaseline baseline = textRenderedBaseline.get(sprite);
      bbox.setX(point.getX());
      bbox.setY(point.getY());
      if (baseline == TextBaseline.MIDDLE) {
        bbox.setY(point.getY() - (bbox.getHeight() / 2.0));
      } else if (baseline == TextBaseline.BOTTOM) {
        bbox.setY(point.getY() - bbox.getHeight());
      }
      textBBoxCache.put(sprite, bbox);
    }
    return bbox;
  }
View Full Code Here

      element.appendChild(textPath);
      element.appendChild(path);
      Style textStyle = textPath.getStyle();
      textStyle.setProperty("lineHeight", "normal");
      textStyle.setProperty("fontVariant", "normal");
      textRenderedPoints.put(sprite, new PrecisePoint());
    }

    this.surfaceElement.appendChild(element);
    setElement(sprite, element);
    return element;
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.