本文整理汇总了Java中com.github.mikephil.charting.utils.Utils.calcTextHeight方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.calcTextHeight方法的具体用法?Java Utils.calcTextHeight怎么用?Java Utils.calcTextHeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.mikephil.charting.utils.Utils
的用法示例。
在下文中一共展示了Utils.calcTextHeight方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeSize
import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
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);
}
示例2: getMaximumEntryHeight
import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
/**
* 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;
}
示例3: getRequiredHeightSpace
import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
/**
* This is for HorizontalBarChart vertical spacing.
*
* @param p
* @return
*/
public float getRequiredHeightSpace(Paint p) {
p.setTextSize(mTextSize);
String label = getLongestLabel();
return (float) Utils.calcTextHeight(p, label) + getYOffset() * 2f;
}
示例4: onDraw
import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
// super.onDraw(canvas);
if (mData == null) {
boolean hasText = !TextUtils.isEmpty(mNoDataText);
boolean hasDescription = !TextUtils.isEmpty(mNoDataTextDescription);
float line1height = hasText ? Utils.calcTextHeight(mInfoPaint, mNoDataText) : 0.f;
float line2height = hasDescription ? Utils.calcTextHeight(mInfoPaint, mNoDataTextDescription) : 0.f;
float lineSpacing = (hasText && hasDescription) ?
(mInfoPaint.getFontSpacing() - line1height) : 0.f;
// if no data, inform the user
float y = (getHeight() -
(line1height + lineSpacing + line2height)) / 2.f
+ line1height;
if (hasText) {
canvas.drawText(mNoDataText, getWidth() / 2, y, mInfoPaint);
if (hasDescription) {
y = y + line1height + lineSpacing;
}
}
if (hasDescription) {
canvas.drawText(mNoDataTextDescription, getWidth() / 2, y, mInfoPaint);
}
return;
}
if (!mOffsetsCalculated) {
calculateOffsets();
mOffsetsCalculated = true;
}
}
示例5: computeAxis
import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
public void computeAxis(float xValMaximumLength, List<String> xValues) {
mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
StringBuilder widthText = new StringBuilder();
int xValChars = Math.round(xValMaximumLength);
for (int i = 0; i < xValChars; i++) {
widthText.append('h');
}
final FSize labelSize = Utils.calcTextSize(mAxisLabelPaint, widthText.toString());
final float labelWidth = labelSize.width;
final float labelHeight = Utils.calcTextHeight(mAxisLabelPaint, "Q");
final FSize labelRotatedSize = Utils.getSizeOfRotatedRectangleByDegrees(
labelWidth,
labelHeight,
mXAxis.getLabelRotationAngle());
StringBuilder space = new StringBuilder();
int xValSpaceChars = mXAxis.getSpaceBetweenLabels();
for (int i = 0; i < xValSpaceChars; i++) {
space.append('h');
}
final FSize spaceSize = Utils.calcTextSize(mAxisLabelPaint, space.toString());
mXAxis.mLabelWidth = Math.round(labelWidth + spaceSize.width);
mXAxis.mLabelHeight = Math.round(labelHeight);
mXAxis.mLabelRotatedWidth = Math.round(labelRotatedSize.width + spaceSize.width);
mXAxis.mLabelRotatedHeight = Math.round(labelRotatedSize.height);
mXAxis.setValues(xValues);
}
示例6: renderAxisLabels
import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
/**
* draws the y-axis labels to the screen
*/
@Override
public void renderAxisLabels(Canvas c) {
if (!mYAxis.isEnabled() || !mYAxis.isDrawLabelsEnabled())
return;
float[] positions = getTransformedPositions();
mAxisLabelPaint.setTypeface(mYAxis.getTypeface());
mAxisLabelPaint.setTextSize(mYAxis.getTextSize());
mAxisLabelPaint.setColor(mYAxis.getTextColor());
float xoffset = mYAxis.getXOffset();
float yoffset = Utils.calcTextHeight(mAxisLabelPaint, "A") / 2.5f + mYAxis.getYOffset();
AxisDependency dependency = mYAxis.getAxisDependency();
YAxisLabelPosition labelPosition = mYAxis.getLabelPosition();
float xPos = 0f;
if (dependency == AxisDependency.LEFT) {
if (labelPosition == YAxisLabelPosition.OUTSIDE_CHART) {
mAxisLabelPaint.setTextAlign(Align.RIGHT);
xPos = mViewPortHandler.offsetLeft() - xoffset;
} else {
mAxisLabelPaint.setTextAlign(Align.LEFT);
xPos = mViewPortHandler.offsetLeft() + xoffset;
}
} else {
if (labelPosition == YAxisLabelPosition.OUTSIDE_CHART) {
mAxisLabelPaint.setTextAlign(Align.LEFT);
xPos = mViewPortHandler.contentRight() + xoffset;
} else {
mAxisLabelPaint.setTextAlign(Align.RIGHT);
xPos = mViewPortHandler.contentRight() - xoffset;
}
}
drawYLabels(c, xPos, positions, yoffset);
}
示例7: renderAxisLabels
import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
/**
* draws the y-axis labels to the screen
*/
@Override
public void renderAxisLabels(Canvas c) {
if (!mYAxis.isEnabled() || !mYAxis.isDrawLabelsEnabled())
return;
float[] positions = getTransformedPositions();
mAxisLabelPaint.setTypeface(mYAxis.getTypeface());
mAxisLabelPaint.setTextSize(mYAxis.getTextSize());
mAxisLabelPaint.setColor(mYAxis.getTextColor());
mAxisLabelPaint.setTextAlign(Align.CENTER);
float baseYOffset = Utils.convertDpToPixel(2.5f);
float textHeight = Utils.calcTextHeight(mAxisLabelPaint, "Q");
AxisDependency dependency = mYAxis.getAxisDependency();
YAxisLabelPosition labelPosition = mYAxis.getLabelPosition();
float yPos = 0f;
if (dependency == AxisDependency.LEFT) {
if (labelPosition == YAxisLabelPosition.OUTSIDE_CHART) {
yPos = mViewPortHandler.contentTop() - baseYOffset;
} else {
yPos = mViewPortHandler.contentTop() - baseYOffset;
}
} else {
if (labelPosition == YAxisLabelPosition.OUTSIDE_CHART) {
yPos = mViewPortHandler.contentBottom() + textHeight + baseYOffset;
} else {
yPos = mViewPortHandler.contentBottom() + textHeight + baseYOffset;
}
}
drawYLabels(c, yPos, positions, mYAxis.getYOffset());
}
示例8: renderAxisLabels
import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
/**
* draws the y-axis labels to the screen
*/
@Override
public void renderAxisLabels(Canvas c) {
if (!mYAxis.isEnabled() || !mYAxis.isDrawLabelsEnabled())
return;
float[] positions = new float[mYAxis.mEntryCount * 2];
for (int i = 0; i < positions.length; i += 2) {
// only fill y values, x values are not needed since the y-labels
// are
// static on the x-axis
positions[i] = mYAxis.mEntries[i / 2];
}
mTrans.pointValuesToPixel(positions);
mAxisLabelPaint.setTypeface(mYAxis.getTypeface());
mAxisLabelPaint.setTextSize(mYAxis.getTextSize());
mAxisLabelPaint.setColor(mYAxis.getTextColor());
mAxisLabelPaint.setTextAlign(Align.CENTER);
float baseYOffset = Utils.convertDpToPixel(2.5f);
float textHeight = Utils.calcTextHeight(mAxisLabelPaint, "Q");
YAxis.AxisDependency dependency = mYAxis.getAxisDependency();
YAxis.YAxisLabelPosition labelPosition = mYAxis.getLabelPosition();
float yPos = 0f;
if (dependency == YAxis.AxisDependency.LEFT) {
if (labelPosition == YAxis.YAxisLabelPosition.OUTSIDE_CHART) {
yPos = mViewPortHandler.contentTop() - baseYOffset;
} else {
yPos = mViewPortHandler.contentTop() - baseYOffset;
}
} else {
if (labelPosition == YAxis.YAxisLabelPosition.OUTSIDE_CHART) {
yPos = mViewPortHandler.contentBottom() + textHeight + baseYOffset;
} else {
yPos = mViewPortHandler.contentBottom() + textHeight + baseYOffset;
}
}
drawYLabels(c, yPos, positions, mYAxis.getYOffset());
}
示例9: getFullHeight
import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
/**
* Calculates the full height of the drawn legend.
*
* @param mLegendLabelPaint
* @return
*/
public float getFullHeight(Paint labelpaint) {
float height = 0f;
for (int i = 0; i < mLabels.length; i++) {
// grouped forms have null labels
if (mLabels[i] != null) {
height += Utils.calcTextHeight(labelpaint, mLabels[i]);
if (i < mLabels.length - 1)
height += mYEntrySpace;
}
}
return height;
}
示例10: renderAxisLabels
import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
/**
* draws the y-axis labels to the screen
*/
@Override
public void renderAxisLabels(Canvas c) {
if (!mYAxis.isEnabled() || !mYAxis.isDrawLabelsEnabled())
return;
float[] positions = new float[mYAxis.mEntryCount * 2];
for (int i = 0; i < positions.length; i += 2) {
// only fill y values, x values are not needed since the y-labels
// are
// static on the x-axis
positions[i + 1] = mYAxis.mEntries[i / 2];
}
mTrans.pointValuesToPixel(positions);
mAxisLabelPaint.setTypeface(mYAxis.getTypeface());
mAxisLabelPaint.setTextSize(mYAxis.getTextSize());
mAxisLabelPaint.setColor(mYAxis.getTextColor());
float xoffset = mYAxis.getXOffset();
float yoffset = Utils.calcTextHeight(mAxisLabelPaint, "A") / 2.5f + mYAxis.getYOffset();
AxisDependency dependency = mYAxis.getAxisDependency();
YAxisLabelPosition labelPosition = mYAxis.getLabelPosition();
float xPos = 0f;
if (dependency == AxisDependency.LEFT) {
if (labelPosition == YAxisLabelPosition.OUTSIDE_CHART) {
mAxisLabelPaint.setTextAlign(Align.RIGHT);
xPos = mViewPortHandler.offsetLeft() - xoffset;
} else {
mAxisLabelPaint.setTextAlign(Align.LEFT);
xPos = mViewPortHandler.offsetLeft() + xoffset;
}
} else {
if (labelPosition == YAxisLabelPosition.OUTSIDE_CHART) {
mAxisLabelPaint.setTextAlign(Align.LEFT);
xPos = mViewPortHandler.contentRight() + xoffset;
} else {
mAxisLabelPaint.setTextAlign(Align.RIGHT);
xPos = mViewPortHandler.contentRight() - xoffset;
}
}
drawYLabels(c, xPos, positions, yoffset);
}
示例11: renderAxisLabels
import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
/**
* draws the y-axis labels to the screen
*/
@Override
public void renderAxisLabels(Canvas c) {
if (!mYAxis.isEnabled() || !mYAxis.isDrawLabelsEnabled())
return;
float[] positions = new float[mYAxis.mEntryCount * 2];
for (int i = 0; i < positions.length; i += 2) {
// only fill y values, x values are not needed since the y-labels
// are
// static on the x-axis
positions[i] = mYAxis.mEntries[i / 2];
}
mTrans.pointValuesToPixel(positions);
mAxisLabelPaint.setTypeface(mYAxis.getTypeface());
mAxisLabelPaint.setTextSize(mYAxis.getTextSize());
mAxisLabelPaint.setColor(mYAxis.getTextColor());
mAxisLabelPaint.setTextAlign(Align.CENTER);
float baseYOffset = Utils.convertDpToPixel(2.5f);
float textHeight = Utils.calcTextHeight(mAxisLabelPaint, "Q");
AxisDependency dependency = mYAxis.getAxisDependency();
YAxisLabelPosition labelPosition = mYAxis.getLabelPosition();
float yPos = 0f;
if (dependency == AxisDependency.LEFT) {
if (labelPosition == YAxisLabelPosition.OUTSIDE_CHART) {
yPos = mViewPortHandler.contentTop() - baseYOffset;
} else {
yPos = mViewPortHandler.contentTop() - baseYOffset;
}
} else {
if (labelPosition == YAxisLabelPosition.OUTSIDE_CHART) {
yPos = mViewPortHandler.contentBottom() + textHeight + baseYOffset;
} else {
yPos = mViewPortHandler.contentBottom() + textHeight + baseYOffset;
}
}
drawYLabels(c, yPos, positions, mYAxis.getYOffset());
}
示例12: renderAxisLabels
import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
/**
* draws the y-axis labels to the screen
*/
@Override
public void renderAxisLabels(Canvas c) {
if (!mYAxis.isEnabled() || !mYAxis.isDrawLabelsEnabled())
return;
float[] positions = new float[mYAxis.mEntryCount * 2];
for (int i = 0; i < positions.length; i += 2) {
// only fill y values, x values are not needed since the y-labels
// are
// static on the x-axis
positions[i + 1] = mYAxis.mEntries[i / 2];
}
mTrans.pointValuesToPixel(positions);
mAxisLabelPaint.setTypeface(mYAxis.getTypeface());
mAxisLabelPaint.setTextSize(mYAxis.getTextSize());
mAxisLabelPaint.setColor(mYAxis.getTextColor());
float xoffset = mYAxis.getXOffset();
float yoffset = Utils.calcTextHeight(mAxisLabelPaint, "A") / 2.5f + mYAxis.getYOffset();
YAxis.AxisDependency dependency = mYAxis.getAxisDependency();
YAxis.YAxisLabelPosition labelPosition = mYAxis.getLabelPosition();
float xPos = 0f;
if (dependency == YAxis.AxisDependency.LEFT) {
if (labelPosition == YAxis.YAxisLabelPosition.OUTSIDE_CHART) {
mAxisLabelPaint.setTextAlign(Align.RIGHT);
xPos = mViewPortHandler.offsetLeft() - xoffset;
} else {
mAxisLabelPaint.setTextAlign(Align.LEFT);
xPos = mViewPortHandler.offsetLeft() + xoffset;
}
} else {
if (labelPosition == YAxis.YAxisLabelPosition.OUTSIDE_CHART) {
mAxisLabelPaint.setTextAlign(Align.LEFT);
xPos = mViewPortHandler.contentRight() + xoffset;
} else {
mAxisLabelPaint.setTextAlign(Align.RIGHT);
xPos = mViewPortHandler.contentRight() - xoffset;
}
}
drawYLabels(c, xPos, positions, yoffset);
}
示例13: drawValues
import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
@Override
public void drawValues(Canvas c) {
BubbleData bubbleData = mChart.getBubbleData();
if (bubbleData == null)
return;
// if values are drawn
if (bubbleData.getYValCount() < (int) (Math.ceil((float) (mChart.getMaxVisibleCount())
* mViewPortHandler.getScaleX()))) {
final List<IBubbleDataSet> dataSets = bubbleData.getDataSets();
float lineHeight = Utils.calcTextHeight(mValuePaint, "1");
for (int i = 0; i < dataSets.size(); i++) {
IBubbleDataSet dataSet = dataSets.get(i);
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
continue;
// apply the text-styling defined by the DataSet
applyValueTextStyle(dataSet);
final float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
final float phaseY = mAnimator.getPhaseY();
BubbleEntry entryFrom = dataSet.getEntryForXIndex(mMinX);
BubbleEntry entryTo = dataSet.getEntryForXIndex(mMaxX);
int minx = dataSet.getEntryIndex(entryFrom);
int maxx = Math.min(dataSet.getEntryIndex(entryTo) + 1, dataSet.getEntryCount());
final float[] positions = mChart.getTransformer(dataSet.getAxisDependency())
.generateTransformedValuesBubble(dataSet, phaseX, phaseY, minx, maxx);
final float alpha = phaseX == 1 ? phaseY : phaseX;
for (int j = 0; j < positions.length; j += 2) {
int valueTextColor = dataSet.getValueTextColor(j / 2 + minx);
valueTextColor = Color.argb(Math.round(255.f * alpha), Color.red(valueTextColor),
Color.green(valueTextColor), Color.blue(valueTextColor));
float x = positions[j];
float y = positions[j + 1];
if (!mViewPortHandler.isInBoundsRight(x))
break;
if ((!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y)))
continue;
BubbleEntry entry = dataSet.getEntryForIndex(j / 2 + minx);
drawValue(c, dataSet.getValueFormatter(), entry.getSize(), entry, i, x,
y + (0.5f * lineHeight), valueTextColor);
}
}
}
}
示例14: drawValues
import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
@Override
public void drawValues(Canvas c) {
BubbleData bubbleData = mChart.getBubbleData();
if (bubbleData == null)
return;
// if values are drawn
if (isDrawingValuesAllowed(mChart)) {
final List<IBubbleDataSet> dataSets = bubbleData.getDataSets();
float lineHeight = Utils.calcTextHeight(mValuePaint, "1");
for (int i = 0; i < dataSets.size(); i++) {
IBubbleDataSet dataSet = dataSets.get(i);
if (!shouldDrawValues(dataSet))
continue;
// apply the text-styling defined by the DataSet
applyValueTextStyle(dataSet);
final float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
final float phaseY = mAnimator.getPhaseY();
mXBounds.set(mChart, dataSet);
final float[] positions = mChart.getTransformer(dataSet.getAxisDependency())
.generateTransformedValuesBubble(dataSet, phaseY, mXBounds.min, mXBounds.max);
final float alpha = phaseX == 1 ? phaseY : phaseX;
for (int j = 0; j < positions.length; j += 2) {
int valueTextColor = dataSet.getValueTextColor(j / 2 + mXBounds.min);
valueTextColor = Color.argb(Math.round(255.f * alpha), Color.red(valueTextColor),
Color.green(valueTextColor), Color.blue(valueTextColor));
float x = positions[j];
float y = positions[j + 1];
if (!mViewPortHandler.isInBoundsRight(x))
break;
if ((!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y)))
continue;
BubbleEntry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
drawValue(c, dataSet.getValueFormatter(), entry.getSize(), entry, i, x,
y + (0.5f * lineHeight), valueTextColor);
}
}
}
}
示例15: drawValues
import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
@Override
public void drawValues(Canvas c) {
BubbleData bubbleData = mChart.getBubbleData();
if (bubbleData == null)
return;
// if values are drawn
if (bubbleData.getYValCount() < (int) (Math.ceil((float) (mChart.getMaxVisibleCount())
* mViewPortHandler.getScaleX()))) {
final List<BubbleDataSet> dataSets = bubbleData.getDataSets();
float lineHeight = Utils.calcTextHeight(mValuePaint, "1");
for (int i = 0; i < dataSets.size(); i++) {
BubbleDataSet dataSet = dataSets.get(i);
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
continue;
// apply the text-styling defined by the DataSet
applyValueTextStyle(dataSet);
final float phaseX = mAnimator.getPhaseX();
final float phaseY = mAnimator.getPhaseY();
final float alpha = phaseX == 1 ? phaseY : phaseX;
int valueTextColor = dataSet.getValueTextColor();
valueTextColor = Color.argb(Math.round(255.f * alpha), Color.red(valueTextColor),
Color.green(valueTextColor), Color.blue(valueTextColor));
mValuePaint.setColor(valueTextColor);
final List<BubbleEntry> entries = dataSet.getYVals();
Entry entryFrom = dataSet.getEntryForXIndex(mMinX);
Entry entryTo = dataSet.getEntryForXIndex(mMaxX);
int minx = dataSet.getEntryPosition(entryFrom);
int maxx = Math.min(dataSet.getEntryPosition(entryTo) + 1, dataSet.getEntryCount());
final float[] positions = mChart.getTransformer(dataSet.getAxisDependency())
.generateTransformedValuesBubble(entries, phaseX, phaseY, minx, maxx);
for (int j = 0; j < positions.length; j += 2) {
float x = positions[j];
float y = positions[j + 1];
if (!mViewPortHandler.isInBoundsRight(x))
break;
if ((!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y)))
continue;
BubbleEntry entry = entries.get(j / 2 + minx);
drawValue(c, dataSet.getValueFormatter(), entry.getSize(), entry, i, x,
y + (0.5f * lineHeight));
}
}
}
}