Java Code Examples for com.github.mikephil.charting.utils.Utils#convertDpToPixel()
The following examples show how to use
com.github.mikephil.charting.utils.Utils#convertDpToPixel() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LimitLine.java From android-kline with Apache License 2.0 | 5 votes |
/** * set the line width of the chart (min = 0.2f, max = 12f); default 2f NOTE: * thinner line == better performance, thicker line == worse performance * * @param width */ public void setLineWidth(float width) { if (width < 0.2f) width = 0.2f; if (width > 12.0f) width = 12.0f; mLineWidth = Utils.convertDpToPixel(width); }
Example 2
Source File: RadarChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
@Override protected void init() { super.init(); mYAxis = new YAxis(AxisDependency.LEFT); mWebLineWidth = Utils.convertDpToPixel(1.5f); mInnerWebLineWidth = Utils.convertDpToPixel(0.75f); mRenderer = new RadarChartRenderer(this, mAnimator, mViewPortHandler); mYAxisRenderer = new YAxisRendererRadarChart(mViewPortHandler, mYAxis, this); mXAxisRenderer = new XAxisRendererRadarChart(mViewPortHandler, mXAxis, this); mHighlighter = new RadarHighlighter(this); }
Example 3
Source File: ComponentBase.java From Stayfit with Apache License 2.0 | 5 votes |
/** * sets the size of the label text in pixels min = 6f, max = 24f, default * 10f * * @param size */ public void setTextSize(float size) { if (size > 24f) size = 24f; if (size < 6f) size = 6f; mTextSize = Utils.convertDpToPixel(size); }
Example 4
Source File: Legend.java From iMoney with Apache License 2.0 | 5 votes |
/** default constructor */ public Legend() { mFormSize = Utils.convertDpToPixel(8f); mXEntrySpace = Utils.convertDpToPixel(6f); mYEntrySpace = Utils.convertDpToPixel(0f); mFormToTextSpace = Utils.convertDpToPixel(5f); mTextSize = Utils.convertDpToPixel(10f); mStackSpace = Utils.convertDpToPixel(3f); this.mXOffset = Utils.convertDpToPixel(5f); this.mYOffset = Utils.convertDpToPixel(7f); }
Example 5
Source File: Chart.java From android-kline with Apache License 2.0 | 4 votes |
/** * Set an extra offset to be appended to the viewport's bottom */ public void setExtraBottomOffset(float offset) { mExtraBottomOffset = Utils.convertDpToPixel(offset); }
Example 6
Source File: ScatterChartRenderer.java From android-kline with Apache License 2.0 | 4 votes |
@Override public void drawValues(Canvas c) { // if values are drawn if (isDrawingValuesAllowed(mChart)) { List<IScatterDataSet> dataSets = mChart.getScatterData().getDataSets(); for (int i = 0; i < mChart.getScatterData().getDataSetCount(); i++) { IScatterDataSet dataSet = dataSets.get(i); if (!shouldDrawValues(dataSet)) continue; // apply the text-styling defined by the DataSet applyValueTextStyle(dataSet); mXBounds.set(mChart, dataSet); float[] positions = mChart.getTransformer(dataSet.getAxisDependency()) .generateTransformedValuesScatter(dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max); float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize()); MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset()); iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x); iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y); for (int j = 0; j < positions.length; j += 2) { if (!mViewPortHandler.isInBoundsRight(positions[j])) break; // make sure the lines don't do shitty things outside bounds if ((!mViewPortHandler.isInBoundsLeft(positions[j]) || !mViewPortHandler.isInBoundsY(positions[j + 1]))) continue; Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min); if (dataSet.isDrawValuesEnabled()) { drawValue(c, dataSet.getValueFormatter(), entry.getY(), entry, i, positions[j], positions[j + 1] - shapeSize, dataSet.getValueTextColor(j / 2 + mXBounds.min)); } if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) { Drawable icon = entry.getIcon(); Utils.drawImage( c, icon, (int)(positions[j] + iconsOffset.x), (int)(positions[j + 1] + iconsOffset.y), icon.getIntrinsicWidth(), icon.getIntrinsicHeight()); } } MPPointF.recycleInstance(iconsOffset); } } }
Example 7
Source File: BaseDataSet.java From Stayfit with Apache License 2.0 | 4 votes |
@Override public void setValueTextSize(float size) { mValueTextSize = Utils.convertDpToPixel(size); }
Example 8
Source File: PieRadarChartTouchListener.java From NetKnight with Apache License 2.0 | 4 votes |
@SuppressLint("ClickableViewAccessibility") @Override public boolean onTouch(View v, MotionEvent event) { if (mGestureDetector.onTouchEvent(event)) return true; // if rotation by touch is enabled if (mChart.isRotationEnabled()) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: startAction(event); stopDeceleration(); resetVelocity(); if (mChart.isDragDecelerationEnabled()) sampleVelocity(x, y); setGestureStartAngle(x, y); mTouchStartPoint.x = x; mTouchStartPoint.y = y; break; case MotionEvent.ACTION_MOVE: if (mChart.isDragDecelerationEnabled()) sampleVelocity(x, y); if (mTouchMode == NONE && distance(x, mTouchStartPoint.x, y, mTouchStartPoint.y) > Utils.convertDpToPixel(8f)) { mLastGesture = ChartGesture.ROTATE; mTouchMode = ROTATE; mChart.disableScroll(); } else if (mTouchMode == ROTATE) { updateGestureRotation(x, y); mChart.invalidate(); } endAction(event); break; case MotionEvent.ACTION_UP: if (mChart.isDragDecelerationEnabled()) { stopDeceleration(); sampleVelocity(x, y); mDecelerationAngularVelocity = calculateVelocity(); if (mDecelerationAngularVelocity != 0.f) { mDecelerationLastTime = AnimationUtils.currentAnimationTimeMillis(); Utils.postInvalidateOnAnimation(mChart); // This causes computeScroll to fire, recommended for this by Google } } mChart.enableScroll(); mTouchMode = NONE; endAction(event); break; } } return true; }
Example 9
Source File: XAxisRendererHorizontalBarChart.java From StockChart-MPAndroidChart with MIT License | 4 votes |
/** * Draws the LimitLines associated with this axis to the screen. * This is the standard YAxis renderer using the XAxis limit lines. * * @param c */ @Override public void renderLimitLines(Canvas c) { List<LimitLine> limitLines = mXAxis.getLimitLines(); if (limitLines == null || limitLines.size() <= 0) { return; } float[] pts = mRenderLimitLinesBuffer; pts[0] = 0; pts[1] = 0; Path limitLinePath = mRenderLimitLinesPathBuffer; limitLinePath.reset(); for (int i = 0; i < limitLines.size(); i++) { LimitLine l = limitLines.get(i); if (!l.isEnabled()) { continue; } int clipRestoreCount = c.save(); mLimitLineClippingRect.set(mViewPortHandler.getContentRect()); mLimitLineClippingRect.inset(0.f, -l.getLineWidth()); c.clipRect(mLimitLineClippingRect); mLimitLinePaint.setStyle(Paint.Style.STROKE); mLimitLinePaint.setColor(l.getLineColor()); mLimitLinePaint.setStrokeWidth(l.getLineWidth()); mLimitLinePaint.setPathEffect(l.getDashPathEffect()); pts[1] = l.getLimit(); mTrans.pointValuesToPixel(pts); limitLinePath.moveTo(mViewPortHandler.contentLeft(), pts[1]); limitLinePath.lineTo(mViewPortHandler.contentRight(), pts[1]); c.drawPath(limitLinePath, mLimitLinePaint); limitLinePath.reset(); // c.drawLines(pts, mLimitLinePaint); String label = l.getLabel(); // if drawing the limit-value label is enabled if (label != null && !label.equals("")) { mLimitLinePaint.setStyle(l.getTextStyle()); mLimitLinePaint.setPathEffect(null); mLimitLinePaint.setColor(l.getTextColor()); mLimitLinePaint.setStrokeWidth(0.5f); mLimitLinePaint.setTextSize(l.getTextSize()); final float labelLineHeight = Utils.calcTextHeight(mLimitLinePaint, label); float xOffset = Utils.convertDpToPixel(4f) + l.getXOffset(); float yOffset = l.getLineWidth() + labelLineHeight + l.getYOffset(); final LimitLine.LimitLabelPosition position = l.getLabelPosition(); if (position == LimitLine.LimitLabelPosition.RIGHT_TOP) { mLimitLinePaint.setTextAlign(Align.RIGHT); c.drawText(label, mViewPortHandler.contentRight() - xOffset, pts[1] - yOffset + labelLineHeight, mLimitLinePaint); } else if (position == LimitLine.LimitLabelPosition.RIGHT_BOTTOM) { mLimitLinePaint.setTextAlign(Align.RIGHT); c.drawText(label, mViewPortHandler.contentRight() - xOffset, pts[1] + yOffset, mLimitLinePaint); } else if (position == LimitLine.LimitLabelPosition.LEFT_TOP) { mLimitLinePaint.setTextAlign(Align.LEFT); c.drawText(label, mViewPortHandler.contentLeft() + xOffset, pts[1] - yOffset + labelLineHeight, mLimitLinePaint); } else { mLimitLinePaint.setTextAlign(Align.LEFT); c.drawText(label, mViewPortHandler.offsetLeft() + xOffset, pts[1] + yOffset, mLimitLinePaint); } } c.restoreToCount(clipRestoreCount); } }
Example 10
Source File: BubbleDataSet.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public void setHighlightCircleWidth(float width) { mHighlightCircleWidth = Utils.convertDpToPixel(width); }
Example 11
Source File: BarLineChartBase.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public void calculateOffsets() { if (!mCustomViewPortEnabled) { float offsetLeft = 0f, offsetRight = 0f, offsetTop = 0f, offsetBottom = 0f; calculateLegendOffsets(mOffsetsBuffer); offsetLeft += mOffsetsBuffer.left; offsetTop += mOffsetsBuffer.top; offsetRight += mOffsetsBuffer.right; offsetBottom += mOffsetsBuffer.bottom; // offsets for y-labels if (mAxisLeft.needsOffset()) { offsetLeft += mAxisLeft.getRequiredWidthSpace(mAxisRendererLeft .getPaintAxisLabels()); } if (mAxisRight.needsOffset()) { offsetRight += mAxisRight.getRequiredWidthSpace(mAxisRendererRight .getPaintAxisLabels()); } if (mXAxis.isEnabled() && mXAxis.isDrawLabelsEnabled()) { float xlabelheight = mXAxis.mLabelRotatedHeight + mXAxis.getYOffset(); // offsets for x-labels if (mXAxis.getPosition() == XAxisPosition.BOTTOM) { offsetBottom += xlabelheight; } else if (mXAxis.getPosition() == XAxisPosition.TOP) { offsetTop += xlabelheight; } else if (mXAxis.getPosition() == XAxisPosition.BOTH_SIDED) { offsetBottom += xlabelheight; offsetTop += xlabelheight; } } offsetTop += getExtraTopOffset(); offsetRight += getExtraRightOffset(); offsetBottom += getExtraBottomOffset(); offsetLeft += getExtraLeftOffset(); float minOffset = Utils.convertDpToPixel(mMinOffset); mViewPortHandler.restrainViewPort( Math.max(minOffset, offsetLeft), Math.max(minOffset, offsetTop), Math.max(minOffset, offsetRight), Math.max(minOffset, offsetBottom)); if (mLogEnabled) { Log.i(LOG_TAG, "offsetLeft: " + offsetLeft + ", offsetTop: " + offsetTop + ", offsetRight: " + offsetRight + ", offsetBottom: " + offsetBottom); Log.i(LOG_TAG, "Content: " + mViewPortHandler.getContentRect().toString()); } } prepareOffsetMatrix(); prepareValuePxMatrix(); }
Example 12
Source File: Chart.java From android-kline with Apache License 2.0 | 4 votes |
/** * Set an extra offset to be appended to the viewport's right */ public void setExtraRightOffset(float offset) { mExtraRightOffset = Utils.convertDpToPixel(offset); }
Example 13
Source File: ChartMeasurementView.java From openScale with GNU General Public License v3.0 | 4 votes |
private void setCustomViewPortOffsets() { float offsetLeft = 0f, offsetRight = 0f, offsetTop = 0f, offsetBottom = 0f; RectF mOffsetsBuffer = new RectF(); calculateLegendOffsets(mOffsetsBuffer); offsetLeft += mOffsetsBuffer.left; offsetTop += mOffsetsBuffer.top; offsetRight += mOffsetsBuffer.right; offsetBottom += Math.max(70f, mOffsetsBuffer.bottom); // offsets for y-labels if (mAxisLeft.needsOffset()) { offsetLeft += mAxisLeft.getRequiredWidthSpace(mAxisRendererLeft .getPaintAxisLabels()); } if (mAxisRight.needsOffset()) { offsetRight += mAxisRight.getRequiredWidthSpace(mAxisRendererRight .getPaintAxisLabels()); } if (mXAxis.isEnabled() && mXAxis.isDrawLabelsEnabled()) { float xLabelHeight = mXAxis.mLabelRotatedHeight + mXAxis.getYOffset(); // offsets for x-labels if (mXAxis.getPosition() == XAxis.XAxisPosition.BOTTOM) { offsetBottom += xLabelHeight; } else if (mXAxis.getPosition() == XAxis.XAxisPosition.TOP) { offsetTop += xLabelHeight; } else if (mXAxis.getPosition() == XAxis.XAxisPosition.BOTH_SIDED) { offsetBottom += xLabelHeight; offsetTop += xLabelHeight; } } offsetTop += getExtraTopOffset(); offsetRight += getExtraRightOffset(); offsetBottom += getExtraBottomOffset(); offsetLeft += getExtraLeftOffset(); float minOffset = Utils.convertDpToPixel(mMinOffset); setViewPortOffsets( Math.max(minOffset, offsetLeft), Math.max(minOffset, offsetTop), Math.max(minOffset, offsetRight), Math.max(minOffset, offsetBottom)); }
Example 14
Source File: RadarChart.java From android-kline with Apache License 2.0 | 2 votes |
/** * Sets the width of the web lines that are in between the lines coming from * the center. * * @param width */ public void setWebLineWidthInner(float width) { mInnerWebLineWidth = Utils.convertDpToPixel(width); }
Example 15
Source File: ComponentBase.java From StockChart-MPAndroidChart with MIT License | 2 votes |
/** * Sets the used x-axis offset for the labels on this axis. * * @param xOffset */ public void setXOffset(float xOffset) { mXOffset = Utils.convertDpToPixel(xOffset); }
Example 16
Source File: RealmLineScatterCandleRadarDataSet.java From MPAndroidChart-Realm with Apache License 2.0 | 2 votes |
/** * Sets the width of the highlight line in dp. * @param width */ public void setHighlightLineWidth(float width) { mHighlightLineWidth = Utils.convertDpToPixel(width); }
Example 17
Source File: CandleStickChartRenderer.java From iMoney with Apache License 2.0 | 2 votes |
@Override public void drawValues(Canvas c) { // if values are drawn if (mChart.getCandleData().getYValCount() < mChart.getMaxVisibleCount() * mViewPortHandler.getScaleX()) { List<CandleDataSet> dataSets = mChart.getCandleData().getDataSets(); for (int i = 0; i < dataSets.size(); i++) { CandleDataSet dataSet = dataSets.get(i); if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0) continue; // apply the text-styling defined by the DataSet applyValueTextStyle(dataSet); Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); List<CandleEntry> entries = dataSet.getYVals(); int minx = Math.max(mMinX, 0); int maxx = Math.min(mMaxX + 1, entries.size()); float[] positions = trans.generateTransformedValuesCandle( entries, mAnimator.getPhaseX(), mAnimator.getPhaseY(), minx, maxx); float yOffset = Utils.convertDpToPixel(5f); 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; CandleEntry entry = entries.get(j / 2 + minx); drawValue(c, dataSet.getValueFormatter(), entry.getHigh(), entry, i, x, y - yOffset); } } } }
Example 18
Source File: LineDataSet.java From Stayfit with Apache License 2.0 | 2 votes |
/** * sets the radius of the drawn circles. * Default radius = 4f * * @param radius */ public void setCircleRadius(float radius) { mCircleRadius = Utils.convertDpToPixel(radius); }
Example 19
Source File: ComponentBase.java From StockChart-MPAndroidChart with MIT License | 2 votes |
/** * Sets the used y-axis offset for the labels on this axis. For the legend, * higher offset means the legend as a whole will be placed further away * from the top. * * @param yOffset */ public void setYOffset(float yOffset) { mYOffset = Utils.convertDpToPixel(yOffset); }
Example 20
Source File: Legend.java From iMoney with Apache License 2.0 | 2 votes |
/** * sets the space between the form and the actual label/text, converts to dp * internally * * @param mFormToTextSpace */ public void setFormToTextSpace(float space) { this.mFormToTextSpace = Utils.convertDpToPixel(space); }