com.github.mikephil.charting.utils.Utils类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(233)

本文整理了Java中com.github.mikephil.charting.utils.Utils类的一些代码示例,展示了Utils类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils类的具体详情如下:
包路径:com.github.mikephil.charting.utils.Utils
类名称:Utils

Utils介绍

[英]Utilities class that has some helper methods. Needs to be initialized by calling Utils.init(...) before usage. Inside the Chart.init() method, this is done, if the Utils are used before that, Utils.init(...) needs to be called manually.
[中]实用程序类,该类具有一些帮助程序方法。需要通过调用Utils来初始化。init(…)使用前。在图表中。init()方法,这就完成了,如果在此之前使用了Utils,则使用Utils。init(…)需要手动调用。

代码示例

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Formats the given number to the given number of decimals, and returns the
 * number as a string, maximum 35 characters. If thousands are separated, the separating
 * character is a dot (".").
 *
 * @param number
 * @param digitCount
 * @param separateThousands set this to true to separate thousands values
 * @return
 */
public static String formatNumber(float number, int digitCount, boolean separateThousands) {
  return formatNumber(number, digitCount, separateThousands, '.');
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
   * Clip path with hardware acceleration only working properly on API level 18 and above.
   *
   * @return
   */
  private boolean clipPathSupported() {
    return Utils.getSDKInt() >= 18;
  }
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * initialize all paints and stuff
 */
protected void init() {
  setWillNotDraw(false);
  // setLayerType(View.LAYER_TYPE_HARDWARE, null);
  mAnimator = new ChartAnimator(new AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
      // ViewCompat.postInvalidateOnAnimation(Chart.this);
      postInvalidate();
    }
  });
  // initialize the utils
  Utils.init(getContext());
  mMaxHighlightDistance = Utils.convertDpToPixel(500f);
  mDescription = new Description();
  mLegend = new Legend();
  mLegendRenderer = new LegendRenderer(mViewPortHandler, mLegend);
  mXAxis = new XAxis();
  mDescPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  mInfoPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  mInfoPaint.setColor(Color.rgb(247, 189, 51)); // orange
  mInfoPaint.setTextAlign(Align.CENTER);
  mInfoPaint.setTextSize(Utils.convertDpToPixel(12f));
  if (mLogEnabled)
    Log.i("", "Chart.init()");
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * returns the maximum length in pixels across all legend labels + formsize
 * + formtotextspace
 *
 * @param p the paint object used for rendering the text
 * @return
 */
public float getMaximumEntryWidth(Paint p) {
  float max = 0f;
  float maxFormSize = 0f;
  float formToTextSpace = Utils.convertDpToPixel(mFormToTextSpace);
  for (LegendEntry entry : mEntries) {
    final float formSize = Utils.convertDpToPixel(
        Float.isNaN(entry.formSize)
        ? mFormSize : entry.formSize);
    if (formSize > maxFormSize)
      maxFormSize = formSize;
    String label = entry.label;
    if (label == null) continue;
    float length = (float) Utils.calcTextWidth(p, label);
    if (length > max)
      max = length;
  }
  return max + maxFormSize + formToTextSpace;
}

代码示例来源:origin: PhilJay/MPAndroidChart

protected void computeSize() {
  String longest = mXAxis.getLongestLabel();
  mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
  mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
  final FSize labelSize = Utils.calcTextSize(mAxisLabelPaint, longest);
  final float labelWidth = labelSize.width;
  final float labelHeight = Utils.calcTextHeight(mAxisLabelPaint, "Q");
  final FSize labelRotatedSize = Utils.getSizeOfRotatedRectangleByDegrees(
      labelWidth,
      labelHeight,
      mXAxis.getLabelRotationAngle());
  mXAxis.mLabelWidth = Math.round(labelWidth);
  mXAxis.mLabelHeight = Math.round(labelHeight);
  mXAxis.mLabelRotatedWidth = Math.round(labelRotatedSize.width);
  mXAxis.mLabelRotatedHeight = Math.round(labelRotatedSize.height);
  FSize.recycleInstance(labelRotatedSize);
  FSize.recycleInstance(labelSize);
}

代码示例来源:origin: PhilJay/MPAndroidChart

float defaultFormSize = Utils.convertDpToPixel(mFormSize);
float stackSpace = Utils.convertDpToPixel(mStackSpace);
float formToTextSpace = Utils.convertDpToPixel(mFormToTextSpace);
float xEntrySpace = Utils.convertDpToPixel(mXEntrySpace);
float yEntrySpace = Utils.convertDpToPixel(mYEntrySpace);
boolean wordWrapEnabled = mWordWrapEnabled;
LegendEntry[] entries = mEntries;
    float labelLineHeight = Utils.getLineHeight(labelpaint);
    boolean wasStacked = false;
      float formSize = Float.isNaN(e.formSize)
          ? defaultFormSize
          : Utils.convertDpToPixel(e.formSize);
      String label = e.label;
        width += Utils.calcTextWidth(labelpaint, label);
    float labelLineHeight = Utils.getLineHeight(labelpaint);
    float labelLineSpacing = Utils.getLineSpacing(labelpaint) + yEntrySpace;
    float contentWidth = viewPortHandler.contentWidth() * mMaxSizePercent;
      float formSize = Float.isNaN(e.formSize)
          ? defaultFormSize
          : Utils.convertDpToPixel(e.formSize);
      String label = e.label;
        mCalculatedLabelSizes.add(Utils.calcTextSize(labelpaint, label));
        requiredWidth += drawingForm ? formToTextSpace + formSize : 0.f;

代码示例来源:origin: PhilJay/MPAndroidChart

mLegendLabelPaint.setColor(mLegend.getTextColor());
float labelLineHeight = Utils.getLineHeight(mLegendLabelPaint, legendFontMetrics);
float labelLineSpacing = Utils.getLineSpacing(mLegendLabelPaint, legendFontMetrics)
    + Utils.convertDpToPixel(mLegend.getYEntrySpace());
float formYOffset = labelLineHeight - Utils.calcTextHeight(mLegendLabelPaint, "ABC") / 2.f;
float formToTextSpace = Utils.convertDpToPixel(mLegend.getFormToTextSpace());
float xEntrySpace = Utils.convertDpToPixel(mLegend.getXEntrySpace());
Legend.LegendOrientation orientation = mLegend.getOrientation();
Legend.LegendHorizontalAlignment horizontalAlignment = mLegend.getHorizontalAlignment();
Legend.LegendVerticalAlignment verticalAlignment = mLegend.getVerticalAlignment();
Legend.LegendDirection direction = mLegend.getDirection();
float defaultFormSize = Utils.convertDpToPixel(mLegend.getFormSize());
float stackSpace = Utils.convertDpToPixel(mLegend.getStackSpace());
      float formSize = Float.isNaN(e.formSize) ? defaultFormSize : Utils.convertDpToPixel(e.formSize);
      float formSize = Float.isNaN(e.formSize) ? defaultFormSize : Utils.convertDpToPixel(e.formSize);
          posX -= Utils.calcTextWidth(mLegendLabelPaint, e.label);

代码示例来源:origin: PhilJay/MPAndroidChart

float lineHeight = Utils.calcTextHeight(mValuePaint, "1");
  iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
  iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);
      Utils.drawImage(
          c,
          icon,

代码示例来源:origin: PhilJay/MPAndroidChart

dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max);
float yOffset = Utils.convertDpToPixel(5f);
iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);
    Utils.drawImage(
        c,
        icon,

代码示例来源:origin: PhilJay/MPAndroidChart

final float valueOffsetPlus = Utils.convertDpToPixel(5f);
float posOffset = 0f;
float negOffset = 0f;
  final float halfTextHeight = Utils.calcTextHeight(mValuePaint, "10") / 2f;
  iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
  iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);
      float valueTextWidth = Utils.calcTextWidth(mValuePaint, formattedValue);
      posOffset = (drawValueAboveBar ? valueOffsetPlus : -(valueTextWidth + valueOffsetPlus));
      negOffset = (drawValueAboveBar ? -(valueTextWidth + valueOffsetPlus) : valueOffsetPlus);
        Utils.drawImage(
            c,
            icon,
        float valueTextWidth = Utils.calcTextWidth(mValuePaint, formattedValue);
        posOffset = (drawValueAboveBar ? valueOffsetPlus : -(valueTextWidth + valueOffsetPlus));
        negOffset = (drawValueAboveBar ? -(valueTextWidth + valueOffsetPlus) : valueOffsetPlus);
          Utils.drawImage(
              c,
              icon,
          float valueTextWidth = Utils.calcTextWidth(mValuePaint, formattedValue);
          posOffset = (drawValueAboveBar ? valueOffsetPlus : -(valueTextWidth + valueOffsetPlus));
          negOffset = (drawValueAboveBar ? -(valueTextWidth + valueOffsetPlus) : valueOffsetPlus);

代码示例来源:origin: PhilJay/MPAndroidChart

float yOffset = Utils.convertDpToPixel(2f) + l.getYOffset();
  final float labelLineHeight = Utils.calcTextHeight(mLimitLinePaint, label);
  mLimitLinePaint.setTextAlign(Align.LEFT);
  c.drawText(label, pts[0] + xOffset, mViewPortHandler.contentTop() + yOffset + labelLineHeight, mLimitLinePaint);
  final float labelLineHeight = Utils.calcTextHeight(mLimitLinePaint, label);
  c.drawText(label, pts[0] - xOffset, mViewPortHandler.contentTop() + yOffset + labelLineHeight, mLimitLinePaint);
} else {

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Sets the used x-axis offset for the labels on this axis.
 *
 * @param xOffset
 */
public void setXOffset(float xOffset) {
  mXOffset = Utils.convertDpToPixel(xOffset);
}

代码示例来源:origin: PhilJay/MPAndroidChart

MPPointF pIcon = MPPointF.getInstance(0,0);
float yoffset = Utils.convertDpToPixel(5f);
  iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
  iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);
     Utils.getPosition(
         center,
         (entry.getY() - mChart.getYChartMin()) * factor * phaseY,
      Utils.getPosition(
          center,
          (entry.getY()) * factor * phaseY + iconsOffset.y,
      Utils.drawImage(
          c,
          icon,

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
protected void computeSize() {
  mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
  mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
  String longest = mXAxis.getLongestLabel();
  final FSize labelSize = Utils.calcTextSize(mAxisLabelPaint, longest);
  final float labelWidth = (int)(labelSize.width + mXAxis.getXOffset() * 3.5f);
  final float labelHeight = labelSize.height;
  final FSize labelRotatedSize = Utils.getSizeOfRotatedRectangleByDegrees(
      labelSize.width,
      labelHeight,
      mXAxis.getLabelRotationAngle());
  mXAxis.mLabelWidth = Math.round(labelWidth);
  mXAxis.mLabelHeight = Math.round(labelHeight);
  mXAxis.mLabelRotatedWidth = (int)(labelRotatedSize.width + mXAxis.getXOffset() * 3.5f);
  mXAxis.mLabelRotatedHeight = Math.round(labelRotatedSize.height);
  FSize.recycleInstance(labelRotatedSize);
}

代码示例来源:origin: PhilJay/MPAndroidChart

protected void drawLabel(Canvas c, String formattedLabel, float x, float y, MPPointF anchor, float angleDegrees) {
  Utils.drawXAxisValue(c, formattedLabel, x, y, mAxisLabelPaint, anchor, angleDegrees);
}
protected Path mRenderGridLinesPath = new Path();

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Converts the provided Integer List to an int array.
 *
 * @param integers
 * @return
 */
public static int[] convertIntegers(List<Integer> integers) {
  int[] ret = new int[integers.size()];
  copyIntegers(integers, ret);
  return ret;
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Returns a recyclable FSize instance.
 * calculates the approximate size of a text, depending on a demo text
 * avoid repeated calls (e.g. inside drawing methods)
 *
 * @param paint
 * @param demoText
 * @return A Recyclable FSize instance
 */
public static FSize calcTextSize(Paint paint, String demoText) {
  FSize result = FSize.getInstance(0,0);
  calcTextSize(paint, demoText, result);
  return result;
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * returns the maximum height in pixels across all legend labels
 *
 * @param p the paint object used for rendering the text
 * @return
 */
public float getMaximumEntryHeight(Paint p) {
  float max = 0f;
  for (LegendEntry entry : mEntries) {
    String label = entry.label;
    if (label == null) continue;
    float length = (float) Utils.calcTextHeight(p, label);
    if (length > max)
      max = length;
  }
  return max;
}

代码示例来源:origin: PhilJay/MPAndroidChart

Utils.init(this);

代码示例来源:origin: PhilJay/MPAndroidChart

float width = Utils.calcTextWidth(mAxisLabelPaint, label);
float width = Utils.calcTextWidth(mAxisLabelPaint, label);
x += width / 2;

相关文章