Skip to content

Commit

Permalink
Fixed issue concerning Activity attribute 'screenSize|orientation' (i…
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilJay committed Oct 13, 2014
1 parent 2297afc commit 254a16f
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected void onCreate(Bundle savedInstanceState) {
// mChart.setDrawBarShadow(true);

mChart.setUnit(" €");

// mChart.setDrawXLabels(false);

mChart.setDrawGridBackground(false);
Expand Down Expand Up @@ -265,7 +265,7 @@ private void setData(int count, float range) {

for (int i = 0; i < count; i++) {
float mult = (range + 1);
float val = (float) (Math.random() * mult) - 50;
float val = (float) (Math.random() * mult);
yVals1.add(new BarEntry(val, i));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,45 @@
package com.xxmassdeveloper.mpchartexample;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.utils.MarkerView;
import com.github.mikephil.charting.utils.Utils;

public class MyMarkerView extends MarkerView {
public class MyMarkerView extends MarkerView implements OnClickListener {

private TextView tvContent;

public MyMarkerView(Context context, int layoutResource) {
super(context, layoutResource);

tvContent = (TextView) findViewById(R.id.tvContent);
setOnClickListener(this);
}

// callbacks everytime the MarkerView is redrawn, can be used to update the
// content
@Override
public void refreshContent(Entry e, int dataSetIndex) {
if(e instanceof CandleEntry) {

if (e instanceof CandleEntry) {

CandleEntry ce = (CandleEntry) e;

tvContent.setText("" + Utils.formatNumber(ce.getHigh(), 0, true));
} else {

tvContent.setText("" + Utils.formatNumber(e.getVal(), 0, true));
}
}

@Override
public void onClick(View v) {
Toast.makeText(getContext(), "Marker clicked!", Toast.LENGTH_SHORT).show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@ protected boolean isOffContentBottom(float p) {

@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);

if (mListener == null || mDataNotSet)
return false;
Expand Down
10 changes: 9 additions & 1 deletion MPChartLib/src/com/github/mikephil/charting/charts/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ protected void onDraw(Canvas canvas) {

if (mDrawBitmap == null || mDrawCanvas == null) {

// use RGB_565 for best performance
mDrawBitmap = Bitmap.createBitmap(getWidth(), getHeight(),
Bitmap.Config.ARGB_4444);
mDrawCanvas = new Canvas(mDrawBitmap);
Expand Down Expand Up @@ -2238,6 +2237,15 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {

// create a new bitmap with the new dimensions
mDrawBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444);
mDrawCanvas = new Canvas(mDrawBitmap);

// prepare content rect and matrices
prepareContentRect();
prepare();

super.onSizeChanged(w, h, oldw, oldh);
}

Expand Down
29 changes: 15 additions & 14 deletions MPChartLib/src/com/github/mikephil/charting/charts/PieChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,16 @@ protected void calcMinMax(boolean fixedValues) {
@Override
protected void calculateOffsets() {

// setup offsets for legend
if (mDrawLegend) {
float legendRight = 0f, legendBottom = 0f;

float legendRight = 0f, legendBottom = 0f;
if (mDrawLegend) {

if (mLegend == null)
return;

if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART
if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART
|| mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART_CENTER) {

// this is the space between the legend and the chart
float spacing = Utils.convertDpToPixel(13f);

Expand All @@ -202,21 +201,23 @@ protected void calculateOffsets() {

legendBottom = mLegendLabelPaint.getTextSize() * 4f;
}

mLegend.setOffsetBottom(legendBottom);
mLegend.setOffsetRight(legendRight);
}

float min = Utils.convertDpToPixel(11f);
float min = Utils.convertDpToPixel(11f);

mLegend.setOffsetTop(min);
mLegend.setOffsetLeft(min);
mLegend.setOffsetTop(min);
mLegend.setOffsetLeft(min);

mOffsetTop = min;
mOffsetRight = Math.max(min, legendRight);
mOffsetBottom = Math.max(min, legendBottom);
mOffsetLeft = min;
mOffsetTop = min;
mOffsetRight = Math.max(min, legendRight);
mOffsetBottom = Math.max(min, legendBottom);

applyCalculatedOffsets();

applyCalculatedOffsets();
}
}

/**
Expand Down
32 changes: 17 additions & 15 deletions MPChartLib/src/com/github/mikephil/charting/charts/RadarChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ public void prepare() {
@Override
protected void calculateOffsets() {

float legendRight = 0f, legendBottom = 0f;

// setup offsets for legend
if (mDrawLegend) {

float legendRight = 0f, legendBottom = 0f;

if (mLegend == null)
return;

Expand All @@ -124,7 +124,8 @@ protected void calculateOffsets() {
float spacing = Utils.convertDpToPixel(8f);

legendRight = mLegend.getMaximumEntryLength(mLegendLabelPaint)
+ mLegend.getFormSize() + mLegend.getFormToTextSpace() + spacing + mXLabels.mLabelWidth;
+ mLegend.getFormSize() + mLegend.getFormToTextSpace() + spacing
+ mXLabels.mLabelWidth;

mLegendLabelPaint.setTextAlign(Align.LEFT);

Expand All @@ -137,23 +138,24 @@ protected void calculateOffsets() {

mLegend.setOffsetBottom(legendBottom);
mLegend.setOffsetRight(legendRight);
}

// all required offsets are calculated, now find largest and apply
float min = Utils.convertDpToPixel(11f);
// all required offsets are calculated, now find largest and apply
float min = Utils.convertDpToPixel(11f);

mOffsetBottom = Math.max(mXLabels.mLabelWidth, min);
mOffsetTop = Math.max(mXLabels.mLabelWidth, min);
mOffsetRight = Math.max(legendRight, min);
mOffsetLeft = Math.max(mXLabels.mLabelWidth, min);
mOffsetBottom = Math.max(mXLabels.mLabelWidth, min);
mOffsetTop = Math.max(mXLabels.mLabelWidth, min);
mOffsetRight = Math.max(legendRight, min);
mOffsetLeft = Math.max(mXLabels.mLabelWidth, min);

mOffsetBottom = Math.max(mOffsetBottom, legendBottom);
mOffsetRight = Math.max(mOffsetRight, legendRight / 3f * 2f);
mOffsetBottom = Math.max(mOffsetBottom, legendBottom);
mOffsetRight = Math.max(mOffsetRight, legendRight / 3f * 2f);

mLegend.setOffsetTop(min);
mLegend.setOffsetLeft(min);
mLegend.setOffsetTop(min);
mLegend.setOffsetLeft(min);

applyCalculatedOffsets();

applyCalculatedOffsets();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public boolean onSingleTapUp(MotionEvent e) {
mChart.highlightTouch(h);
}

return true;
return super.onSingleTapUp(e);
}

@Override
Expand Down

0 comments on commit 254a16f

Please sign in to comment.