Package com.sencha.gxt.chart.client.draw.sprite

Examples of com.sencha.gxt.chart.client.draw.sprite.TextSprite


      if (sprite != null) {
        sprite.remove();
      }
    }
    while (labels.size() > 0) {
      TextSprite sprite = labels.remove(labels.size() - 1);
      if (sprite != null) {
        sprite.remove();
      }
    }
    if (titleSprite != null) {
      titleSprite.remove();
      titleSprite = null;
View Full Code Here


      }
      if (path.isMiterLimitDirty()) {
        setAttribute(element, "stroke-miterlimit", path.getMiterLimit());
      }
    } else if (sprite instanceof TextSprite) {
      TextSprite text = (TextSprite) sprite;
      if (text.isTextDirty() || text.isXDirty()) {
        tuneText(text);
      }
      if (text.isFontSizeDirty()) {
        if (text.getFontSize() > 0) {
          element.getStyle().setFontSize(text.getFontSize(), Unit.PX);
        } else {
          element.getStyle().clearFontSize();
        }
      }
      if (text.isFontStyleDirty()) {
        if (text.getFontStyle() != null) {
          element.getStyle().setFontStyle(text.getFontStyle());
        } else {
          element.getStyle().clearFontStyle();
        }
      }
      if (text.isFontWeightDirty()) {
        if (text.getFontWeight() != null) {
          element.getStyle().setFontWeight(text.getFontWeight());
        } else {
          element.getStyle().clearFontWeight();
        }
      }
      if (text.isFontDirty()) {
        setAttribute(element, "font-family", text.getFont());
      }
      if (text.isTextAnchorDirty()) {
        if (text.getTextAnchor() == TextAnchor.START) {
          element.setAttribute("text-anchor", "start");
        } else if (text.getTextAnchor() == TextAnchor.MIDDLE) {
          element.setAttribute("text-anchor", "middle");
        } else if (text.getTextAnchor() == TextAnchor.END) {
          element.setAttribute("text-anchor", "end");
        } else {
          element.removeAttribute("text-anchor");
        }
      }
      if (text.isXDirty()) {
        setAttribute(element, "x", text.getX());
      }
      if (text.isYDirty()) {
        setAttribute(element, "y", text.getY());
      }
    } else if (sprite instanceof RectangleSprite) {
      RectangleSprite rect = (RectangleSprite) sprite;
      if (rect.isXDirty()) {
        setAttribute(element, "x", rect.getX());
View Full Code Here

              sprite = labelConfig.getSpriteConfig().copy();
              labels.put(i * values.length + j, sprite);
              chart.addSprite(sprite);
            }
            if (sprite instanceof TextSprite) {
              TextSprite text = (TextSprite) sprite;
              if (labelConfig.getLabelProvider() != null) {
                text.setText(labelConfig.getLabelProvider().getLabel(chart.getCurrentStore().get(j),
                    getValueProvider(j)));
              }
              text.redraw();
            }
            double offsetY = sprite.getBBox().getHeight() / 2.0;
            PrecisePoint point = getPointFromCommand(areasCommands.get(j).get(i));
            if (chart.isAnimated() && sprite.getTranslation() != null) {
              DrawFx.createTranslationAnimator(sprite, point.getX(), point.getY() - offsetY).run(
View Full Code Here

    center.setY(chartBBox.getY() + chartBBox.getHeight());
    double rho = Math.min(chartBBox.getWidth(), chartBBox.getHeight()) + 2.0 * margin;

    // draw scale
    for (double i = 0; i <= gaugeSteps; i++) {
      final TextSprite label;
      if (i >= labels.size()) {
        label = labelConfig.copy();
        chart.addSprite(label);
        labels.add(label);
      } else {
        label = labels.get((int) i);
      }
      label.setText(labelProvider.getLabel((Math.round(i / gaugeSteps * maximum))));
      label.redraw();
      double height = label.getBBox().getHeight() / 2.0;
      label.setX(center.getX() + rho * Math.cos(i / gaugeSteps * Math.PI - Math.PI));
      label.setY(center.getY() + rho * Math.sin(i / gaugeSteps * Math.PI - Math.PI) - height);
      label.redraw();
    }

  }
View Full Code Here

      if (sprite != null) {
        sprite.remove();
      }
    }
    while (scales.size() > 0) {
      TextSprite sprite = scales.remove(scales.size() - 1);
      if (sprite != null) {
        sprite.remove();
      }
    }
  }
View Full Code Here

    }

    // draw scale
    if (display != Display.CATEGORIES) {
      for (int i = 0; i < radialSteps; i++) {
        final TextSprite scale;
        if (i < scales.size()) {
          scale = scales.get(i);
        } else {
          scale = scaleConfig.copy();
          chart.addSprite(scale);
          scales.add(scale);
        }
        scale.setText(scaleLabelProvider.getLabel((Math.round((i + 1) / (double) radialSteps * maxValue))));
        scale.setX(centerX);
        scale.setY(centerY - rho * (i + 1) / radialSteps);
        scale.redraw();
      }
    }

    for (int j = labelNames.size(); j < labels.size(); j++) {
      labels.get(j).setHidden(true);
    }
    // draw text
    if (display != Display.SCALE && labelNames.size() > 0) {
      double size = labelNames.size();
      for (int i = 0; i < size; i++) {
        final TextSprite label;
        if (i < labels.size()) {
          label = labels.get(i);
          label.setHidden(false);
        } else {
          label = labelConfig.copy();
          chart.addSprite(label);
          labels.add(label);
        }
        double dx = Math.cos(i / size * pi2) * (rho + margin);
        double dy = Math.sin(i / size * pi2) * (rho + margin);
        label.setText(labelProvider.getLabel((labelNames.get(i))));
        label.redraw();
        label.setX(centerX + dx);
        label.setY(centerY + dy - (label.getBBox().getHeight() / 2.0));
        if (dx * dx <= 0.001) {
          label.setTextAnchor(TextAnchor.MIDDLE);
        } else {
          if (dx < 0) {
            label.setTextAnchor(TextAnchor.END);
          } else {
            label.setTextAnchor(TextAnchor.START);
          }
        }
        label.redraw();
      }
    }
  }
View Full Code Here

   * @param sprite the sprite to be set
   * @param index the index of the label data
   */
  protected void setLabelText(Sprite sprite, int index) {
    if (sprite instanceof TextSprite) {
      TextSprite text = (TextSprite) sprite;
      if (labelConfig.getLabelProvider() != null) {
        text.setText(labelConfig.getLabelProvider().getLabel(chart.getCurrentStore().get(index),
            getValueProvider(index)));
      }
    }
  }
View Full Code Here

  private void createLegend() {
    String name = legend.getCurrentLegendTitles().get(yFieldIndex);
    Chart<M> chart = legend.getChart();
    setSurface(chart.getSurface());

    label = new TextSprite();
    add(label);
    chart.addSprite(label);
    label.setText(name);
    label.setX(20);
    label.setY(0);
View Full Code Here

   */
  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();
        }
      }

      textLabel.setHidden(false);
      textLabel.setX(x);
      textLabel.setY(y);
      if (labelRotation != null) {
        textLabel.setRotation(new Rotation(x, y, labelRotation.getDegrees()));
      }
      textLabel.redraw();
      bbox = textLabel.getBBox();

      // Skip label if there isn't available minimum space
      if (labelOverlapHiding && previousBBox != null) {
        furthestLabel = Math.max(furthestLabel, previousBBox.getX() + previousBBox.getWidth());
        if (bbox.getX() <= furthestLabel - labelTolerance) {
          textLabel.setHidden(true);
          textLabel.redraw();
          continue;
        }
      }
      previousBBox = bbox;
    }
View Full Code Here

   */
  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);
      textLabel.redraw();
      bbox = textLabel.getBBox();

      // Skip label if there isn't available minimum space
      if (labelOverlapHiding) {
        if (previousBBox != null) {
          furthestLabel = Math.min(furthestLabel, previousBBox.getY());
          if (bbox.getY() + bbox.getHeight() >= furthestLabel + labelTolerance) {
            textLabel.setHidden(true);
            textLabel.redraw();
            continue;
          }
        } else {
          furthestLabel = bbox.getY();
        }
View Full Code Here

TOP

Related Classes of com.sencha.gxt.chart.client.draw.sprite.TextSprite

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.