text stringlengths 9 39.2M | dir stringlengths 26 295 | lang stringclasses 185
values | created_date timestamp[us] | updated_date timestamp[us] | repo_name stringlengths 1 97 | repo_full_name stringlengths 7 106 | star int64 1k 183k | len_tokens int64 1 13.8M |
|---|---|---|---|---|---|---|---|---|
```java
package com.example.yanjiang.stockchart.inject.component;
import android.app.Service;
import com.example.yanjiang.stockchart.inject.modules.ServiceModule;
import com.example.yanjiang.stockchart.inject.others.PerService;
import com.example.yanjiang.stockchart.service.DownLoadService;
import dagger.Component;
/**
* authorajiang
* mail1025065158@qq.com
* blogpath_to_url
*/
@PerService
@Component(dependencies = AppComponent.class, modules = ServiceModule.class)
public interface ServiceComponent {
Service getService();
void inject(DownLoadService downLoadService);
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/inject/component/ServiceComponent.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 121 |
```java
package com.example.yanjiang.stockchart.inject.others;
import javax.inject.Qualifier;
/**
* Created by yanjiang on 2016/3/28.
*/
@Qualifier
public @interface StringQuali {
String value() default "";
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/inject/others/StringQuali.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 52 |
```java
package com.example.yanjiang.stockchart.inject.others;
import javax.inject.Scope;
@Scope
public @interface ApplicationScope {
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/inject/others/ApplicationScope.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 28 |
```java
package com.example.yanjiang.stockchart.inject.others;
import java.lang.annotation.Retention;
import javax.inject.Scope;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Scope
@Retention(RUNTIME)
public @interface PerService {
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/inject/others/PerService.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 51 |
```java
package com.example.yanjiang.stockchart.inject.others;
import java.lang.annotation.Retention;
import javax.inject.Scope;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Scope
@Retention(RUNTIME)
public @interface PerActivity {
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/inject/others/PerActivity.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 51 |
```java
package com.example.yanjiang.stockchart.inject.modules;
import android.content.Context;
import com.example.yanjiang.stockchart.application.App;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
@Module
public class AppModule {
App application;
public AppModule(App application) {
this.application = application;
}
@Provides
@Singleton
public Context provideContext() {
return application;
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/inject/modules/AppModule.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 89 |
```java
package com.example.yanjiang.stockchart.inject.modules;
import android.app.Service;
import com.example.yanjiang.stockchart.inject.others.PerService;
import com.example.yanjiang.stockchart.service.DownLoadService;
import dagger.Module;
import dagger.Provides;
/**
* authorajiang
* mail1025065158@qq.com
* blogpath_to_url
*/
@Module
public class ServiceModule {
private DownLoadService m_service;
public ServiceModule(DownLoadService service) {
m_service = service;
}
@Provides
@PerService
public Service provideService() {
return m_service;
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/inject/modules/ServiceModule.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 133 |
```java
package com.example.yanjiang.stockchart.inject.modules;
import android.app.Activity;
import com.example.yanjiang.stockchart.inject.others.PerActivity;
import dagger.Module;
import dagger.Provides;
@Module
public class ActivityModule {
private Activity mActivity;
public ActivityModule(Activity mActivity) {
this.mActivity = mActivity;
}
@Provides
@PerActivity
public Activity provideActivity() {
return mActivity;
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/inject/modules/ActivityModule.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 92 |
```java
package com.example.yanjiang.stockchart.inject.modules;
import android.app.Activity;
import android.support.v4.app.Fragment;
import com.example.yanjiang.stockchart.inject.others.PerFragment;
import dagger.Module;
import dagger.Provides;
@Module
public class FragmentModule {
private Fragment mFragment;
public FragmentModule(Fragment fragment) {
mFragment = fragment;
}
@Provides
@PerFragment
public Activity provideActivity() {
return mFragment.getActivity();
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/inject/modules/FragmentModule.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 103 |
```java
package com.example.yanjiang.stockchart.inject.modules;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.example.yanjiang.stockchart.BuildConfig;
import com.example.yanjiang.stockchart.api.ClientApi;
import com.example.yanjiang.stockchart.api.Constant;
import com.example.yanjiang.stockchart.api.DownLoadApi;
import java.util.concurrent.TimeUnit;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
/**
* Created by yanjiang on 2016/3/25.
*/
@Module
public class ClientApiModule {
@Provides
@Singleton
public DownLoadApi provideDownLoadApi(OkHttpClient client) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constant.HTTP_BASE)
.client(client)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
return retrofit.create(DownLoadApi.class);
}
@Provides
@Singleton
public ClientApi provideClientApi(OkHttpClient client, GsonConverterFactory gsonConverterFactory) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constant.MINUTESURL)
.client(client)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
return retrofit.create(ClientApi.class);
}
@Provides
@Singleton
public GsonConverterFactory provideGsonConverterFactory() {
return GsonConverterFactory.create();
}
@Provides
@Singleton
public OkHttpClient provideOkHttpClient(Context context, HttpLoggingInterceptor httpLoggingInterceptor) {
return new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.addInterceptor(httpLoggingInterceptor)
.build();
}
@Provides
@Singleton
public HttpLoggingInterceptor provideHttpLoggingInterceptor() {
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
if (BuildConfig.DEBUG) {
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
} else {
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.NONE);
}
return httpLoggingInterceptor;
}
@Provides
@Singleton
public SharedPreferences providesSharedPreferences(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context);
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/inject/modules/ClientApiModule.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 516 |
```java
package com.example.yanjiang.stockchart.mychart;
import android.content.Context;
import android.widget.TextView;
import com.example.yanjiang.stockchart.R;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import java.text.DecimalFormat;
/**
* authorajiang
* mail1025065158@qq.com
* blogpath_to_url
*/
public class MyBottomMarkerView extends MarkerView {
/**
* Constructor. Sets up the MarkerView with a custom layout resource.
*
* @param context
* @param layoutResource the layout resource to use for the MarkerView
*/
private TextView markerTv;
private String time;
public MyBottomMarkerView(Context context, int layoutResource) {
super(context, layoutResource);
markerTv = (TextView) findViewById(R.id.marker_tv);
markerTv.setTextSize(10);
}
public void setData(String time){
this.time=time;
}
@Override
public void refreshContent(Entry e, Highlight highlight) {
markerTv.setText(time);
}
@Override
public int getXOffset(float xpos) {
return 0;
}
@Override
public int getYOffset(float ypos) {
return 0;
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/mychart/MyBottomMarkerView.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 282 |
```java
package com.example.yanjiang.stockchart.mychart;
import android.graphics.Matrix;
import android.view.MotionEvent;
import android.view.View;
import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.listener.ChartTouchListener;
import com.github.mikephil.charting.listener.OnChartGestureListener;
/**
* path_to_url
*/
public class CoupleChartGestureListener implements OnChartGestureListener {
private static final String TAG = CoupleChartGestureListener.class.getSimpleName();
private Chart srcChart;
private Chart[] dstCharts;
public CoupleChartGestureListener(Chart srcChart, Chart[] dstCharts) {
this.srcChart = srcChart;
this.dstCharts = dstCharts;
}
@Override
public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
syncCharts();
}
@Override
public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
syncCharts();
}
@Override
public void onChartLongPressed(MotionEvent me) {
syncCharts();
}
@Override
public void onChartDoubleTapped(MotionEvent me) {
syncCharts();
}
@Override
public void onChartSingleTapped(MotionEvent me) {
syncCharts();
}
@Override
public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
syncCharts();
}
@Override
public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
// Log.d(TAG, "onChartScale " + scaleX + "/" + scaleY + " X=" + me.getX() + "Y=" + me.getY());
syncCharts();
}
@Override
public void onChartTranslate(MotionEvent me, float dX, float dY) {
// Log.d(TAG, "onChartTranslate " + dX + "/" + dY + " X=" + me.getX() + "Y=" + me.getY());
syncCharts();
}
public void syncCharts() {
Matrix srcMatrix;
float[] srcVals = new float[9];
Matrix dstMatrix;
float[] dstVals = new float[9];
// get src chart translation matrix:
srcMatrix = srcChart.getViewPortHandler().getMatrixTouch();
srcMatrix.getValues(srcVals);
// apply X axis scaling and position to dst charts:
for (Chart dstChart : dstCharts) {
if (dstChart.getVisibility() == View.VISIBLE) {
dstMatrix = dstChart.getViewPortHandler().getMatrixTouch();
dstMatrix.getValues(dstVals);
dstVals[Matrix.MSCALE_X] = srcVals[Matrix.MSCALE_X];
dstVals[Matrix.MSKEW_X] = srcVals[Matrix.MSKEW_X];
dstVals[Matrix.MTRANS_X] = srcVals[Matrix.MTRANS_X];
dstVals[Matrix.MSKEW_Y] = srcVals[Matrix.MSKEW_Y];
dstVals[Matrix.MSCALE_Y] = srcVals[Matrix.MSCALE_Y];
dstVals[Matrix.MTRANS_Y] = srcVals[Matrix.MTRANS_Y];
dstVals[Matrix.MPERSP_0] = srcVals[Matrix.MPERSP_0];
dstVals[Matrix.MPERSP_1] = srcVals[Matrix.MPERSP_1];
dstVals[Matrix.MPERSP_2] = srcVals[Matrix.MPERSP_2];
dstMatrix.setValues(dstVals);
dstChart.getViewPortHandler().refresh(dstMatrix, dstChart, true);
}
}
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/mychart/CoupleChartGestureListener.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 781 |
```java
package com.example.yanjiang.stockchart.mychart;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.PointF;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.renderer.XAxisRenderer;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* authorajiang
* mail1025065158@qq.com
* blogpath_to_url
*/
public class MyXAxisRenderer extends XAxisRenderer {
private final BarLineChartBase mChart;
protected MyXAxis mXAxis;
public MyXAxisRenderer(ViewPortHandler viewPortHandler, MyXAxis xAxis, Transformer trans, BarLineChartBase chart) {
super(viewPortHandler, xAxis, trans);
mXAxis = xAxis;
mChart = chart;
}
@Override
protected void drawLabels(Canvas c, float pos, PointF anchor) {
float[] position = new float[]{
0f, 0f
};
int count = mXAxis.getXLabels().size();
for (int i = 0; i < count; i ++) {
/*labelkeyx0,60,121,182,242*/
int ix = mXAxis.getXLabels().keyAt(i);
position[0] = ix;
/*xtext*/
mTrans.pointValuesToPixel(position);
/*x*/
if (mViewPortHandler.isInBoundsX(position[0])) {
String label = mXAxis.getXLabels().valueAt(i);
/**/
int labelWidth = Utils.calcTextWidth(mAxisLabelPaint, label);
/**/
if ((labelWidth / 2 + position[0]) > mChart.getViewPortHandler().contentRight()) {
position[0] = mChart.getViewPortHandler().contentRight() - labelWidth / 2;
} else if ((position[0] - labelWidth / 2) < mChart.getViewPortHandler().contentLeft()) {//
position[0] = mChart.getViewPortHandler().contentLeft() + labelWidth / 2;
}
c.drawText(label, position[0],
pos+ Utils.convertPixelsToDp(mChart.getViewPortHandler().offsetBottom()),
mAxisLabelPaint);
}
}
}
protected Path mRenderGridLinesPath = new Path();
/*x*/
@Override
public void renderGridLines(Canvas c) {
if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled())
return;
float[] position = new float[]{
0f, 0f
};
mGridPaint.setColor(mXAxis.getGridColor());
mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth());
mGridPaint.setPathEffect(mXAxis.getGridDashPathEffect());
Path gridLinePath = mRenderGridLinesPath;
gridLinePath.reset();
int count = mXAxis.getXLabels().size();
if (!mChart.isScaleXEnabled()) {
count -= 1;
}
for (int i = 0; i <= count; i ++) {
int ix = mXAxis.getXLabels().keyAt(i);
position[0] = ix;
mTrans.pointValuesToPixel(position);
if (position[0] >= mViewPortHandler.offsetLeft()
&& position[0] <= mViewPortHandler.getChartWidth()) {
gridLinePath.moveTo(position[0], mViewPortHandler.contentBottom());
gridLinePath.lineTo(position[0], mViewPortHandler.contentTop());
// draw a path because lines don't support dashing on lower android versions
c.drawPath(gridLinePath, mGridPaint);
}
gridLinePath.reset();
}
/*for (int i = 0; i < count; i ++) {
int ix = mXAxis.getXLabels().keyAt(i);
position[0] = ix;
mTrans.pointValuesToPixel(position);
c.drawLine(position[0], mViewPortHandler.offsetTop(), position[0],
mViewPortHandler.contentBottom(), mGridPaint);
}*/
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/mychart/MyXAxisRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 894 |
```java
package com.example.yanjiang.stockchart.mychart;
import android.content.Context;
import android.widget.TextView;
import com.example.yanjiang.stockchart.R;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import java.text.DecimalFormat;
/**
* authorajiang
* mail1025065158@qq.com
* blogpath_to_url
*/
public class MyRightMarkerView extends MarkerView {
/**
* Constructor. Sets up the MarkerView with a custom layout resource.
*
* @param context
* @param layoutResource the layout resource to use for the MarkerView
*/
private TextView markerTv;
private float num;
private DecimalFormat mFormat;
public MyRightMarkerView(Context context, int layoutResource) {
super(context, layoutResource);
mFormat = new DecimalFormat("#0.00");
markerTv = (TextView) findViewById(R.id.marker_tv);
markerTv.setTextSize(10);
}
public void setData(float num){
this.num=num;
}
@Override
public void refreshContent(Entry e, Highlight highlight) {
markerTv.setText(mFormat.format(num*100)+"%");
}
@Override
public int getXOffset(float xpos) {
return 0;
}
@Override
public int getYOffset(float ypos) {
return 0;
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/mychart/MyRightMarkerView.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 305 |
```java
package com.example.yanjiang.stockchart.mychart;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import com.example.yanjiang.stockchart.bean.DataParse;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
/**
* ajiang
* 1025065158
* path_to_url
*/
public class MyBarChart extends BarChart {
private MyLeftMarkerView myMarkerViewLeft;
private MyRightMarkerView myMarkerViewRight;
private MyBottomMarkerView mMyBottomMarkerView;
private DataParse minuteHelper;
public MyBarChart(Context context) {
super(context);
}
public MyBarChart(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyBarChart(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void setMarker(MyLeftMarkerView markerLeft, MyRightMarkerView markerRight, MyBottomMarkerView markerBottom, DataParse minuteHelper) {
this.myMarkerViewLeft = markerLeft;
this.myMarkerViewRight = markerRight;
this.mMyBottomMarkerView = markerBottom;
this.minuteHelper = minuteHelper;
}
@Override
protected void init() {
super.init();
/**/
mXAxis = new MyXAxis();
mAxisLeft = new MyYAxis(YAxis.AxisDependency.LEFT);
mAxisRendererLeft = new MyYAxisRenderer(mViewPortHandler, (MyYAxis) mAxisLeft, mLeftAxisTransformer);
mXAxisRenderer = new MyXAxisRenderer(mViewPortHandler, (MyXAxis) mXAxis, mLeftAxisTransformer, this);
mAxisRight = new MyYAxis(YAxis.AxisDependency.RIGHT);
mAxisRendererRight = new MyYAxisRenderer(mViewPortHandler, (MyYAxis) mAxisRight, mRightAxisTransformer);
}
@Override
protected void calcModulus() {
mXAxis.mAxisLabelModulus = 1;
}
/**/
@Override
public MyYAxis getAxisLeft() {
return (MyYAxis) super.getAxisLeft();
}
@Override
public MyXAxis getXAxis() {
return (MyXAxis) super.getXAxis();
}
@Override
public MyYAxis getAxisRight() {
return (MyYAxis) super.getAxisRight();
}
public void setHighlightValue(Highlight h) {
mIndicesToHighlight = new Highlight[]{
h};
}
@Override
protected void drawMarkers(Canvas canvas) {
if (!mDrawMarkerViews || !valuesToHighlight())
return;
for (int i = 0; i < mIndicesToHighlight.length; i++) {
Highlight highlight = mIndicesToHighlight[i];
int xIndex = mIndicesToHighlight[i].getXIndex();
int dataSetIndex = mIndicesToHighlight[i].getDataSetIndex();
float deltaX = mXAxis != null
? mXAxis.mAxisRange
: ((mData == null ? 0.f : mData.getXValCount()) - 1.f);
if (xIndex <= deltaX && xIndex <= deltaX * mAnimator.getPhaseX()) {
Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]);
// make sure entry not null
if (e == null || e.getXIndex() != mIndicesToHighlight[i].getXIndex())
continue;
float[] pos = getMarkerPosition(e, highlight);
// check bounds
if (!mViewPortHandler.isInBounds(pos[0], pos[1]))
continue;
String time = minuteHelper.getDatas().get(mIndicesToHighlight[i].getXIndex()).time;
mMyBottomMarkerView.setData(time);
mMyBottomMarkerView.refreshContent(e, mIndicesToHighlight[i]);
/*bug*/
// invalidate();
/**/
mMyBottomMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
mMyBottomMarkerView.layout(0, 0, mMyBottomMarkerView.getMeasuredWidth(),
mMyBottomMarkerView.getMeasuredHeight());
mMyBottomMarkerView.draw(canvas, pos[0]-mMyBottomMarkerView.getWidth()/2, mViewPortHandler.contentBottom());
}
}
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/mychart/MyBarChart.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 970 |
```java
package com.example.yanjiang.stockchart.mychart;
import android.graphics.Canvas;
import android.text.TextUtils;
import com.github.mikephil.charting.renderer.YAxisRenderer;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* authorajiang
* mail1025065158@qq.com
* blogpath_to_url
*
* ylabels
*/
public class MyYAxisRenderer extends YAxisRenderer {
protected MyYAxis mYAxis;
public MyYAxisRenderer(ViewPortHandler viewPortHandler, MyYAxis yAxis, Transformer trans) {
super(viewPortHandler, yAxis, trans);
mYAxis = yAxis;
}
@Override
protected void computeAxisValues(float min, float max) {
/**/
if (mYAxis.isShowOnlyMinMaxEnabled()) {
mYAxis.mEntryCount = 2;
mYAxis.mEntries = new float[2];
mYAxis.mEntries[0] = min;
mYAxis.mEntries[1] = max;
return;
}
/*basevalue*/
if (Float.isNaN(mYAxis.getBaseValue())) {
super.computeAxisValues(min, max);
return;
}
float base = mYAxis.getBaseValue();
float yMin = min;
int labelCount = mYAxis.getLabelCount();
float interval = (base - yMin) / labelCount;
int n = labelCount * 2 + 1;
mYAxis.mEntryCount = n;
mYAxis.mEntries = new float[n];
int i;
float f;
for (f = min, i = 0; i < n; f += interval, i++) {
mYAxis.mEntries[i] = f;
}
}
@Override
protected void drawYLabels(Canvas c, float fixedPosition, float[] positions, float offset) {
/*text*/
if (!TextUtils.isEmpty(mYAxis.getMinValue()) && mYAxis.isShowOnlyMinMaxEnabled()) {
for (int i = 0; i < mYAxis.mEntryCount; i++) {
/**/
String text = mYAxis.getFormattedLabel(i);
if (i == 0) {
text = mYAxis.getMinValue();
}
if (i == 1) {
c.drawText(text, fixedPosition, mViewPortHandler.offsetTop()+2*offset+5 , mAxisLabelPaint);
} else if (i == 0) {
c.drawText(text, fixedPosition, mViewPortHandler.contentBottom() - 3, mAxisLabelPaint);
}
}
}
else {
for (int i = 0; i < mYAxis.mEntryCount; i++) {
String text = mYAxis.getFormattedLabel(i);
if (!mYAxis.isDrawTopYLabelEntryEnabled() && i >= mYAxis.mEntryCount - 1)
return;
int labelHeight = Utils.calcTextHeight(mAxisLabelPaint, text);
float pos = positions[i * 2 + 1] + offset;
if ((pos - labelHeight) < mViewPortHandler.contentTop()) {
pos = mViewPortHandler.contentTop() + offset * 2.5f + 3;
} else if ((pos + labelHeight / 2) > mViewPortHandler.contentBottom()) {
pos = mViewPortHandler.contentBottom() - 3;
}
c.drawText(text, fixedPosition, pos, mAxisLabelPaint);
}
}
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/mychart/MyYAxisRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 774 |
```java
package com.example.yanjiang.stockchart.mychart;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import com.example.yanjiang.stockchart.bean.DataParse;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
/**
* ajiang
* 1025065158
* path_to_url
*/
public class MyLineChart extends LineChart {
private MyLeftMarkerView myMarkerViewLeft;
private MyRightMarkerView myMarkerViewRight;
private MyBottomMarkerView mMyBottomMarkerView;
private DataParse minuteHelper;
public MyLineChart(Context context) {
super(context);
}
public MyLineChart(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyLineChart(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void init() {
super.init();
/**/
mXAxis = new MyXAxis();
mAxisLeft = new MyYAxis(YAxis.AxisDependency.LEFT);
mXAxisRenderer = new MyXAxisRenderer(mViewPortHandler, (MyXAxis) mXAxis, mLeftAxisTransformer, this);
mAxisRendererLeft = new MyYAxisRenderer(mViewPortHandler, (MyYAxis) mAxisLeft, mLeftAxisTransformer);
mAxisRight = new MyYAxis(YAxis.AxisDependency.RIGHT);
mAxisRendererRight = new MyYAxisRenderer(mViewPortHandler, (MyYAxis) mAxisRight, mRightAxisTransformer);
}
/**/
@Override
public MyYAxis getAxisLeft() {
return (MyYAxis) super.getAxisLeft();
}
@Override
public MyXAxis getXAxis() {
return (MyXAxis) super.getXAxis();
}
@Override
public MyYAxis getAxisRight() {
return (MyYAxis) super.getAxisRight();
}
public void setMarker(MyLeftMarkerView markerLeft, MyRightMarkerView markerRight,MyBottomMarkerView markerBottom, DataParse minuteHelper) {
this.myMarkerViewLeft = markerLeft;
this.myMarkerViewRight = markerRight;
this.mMyBottomMarkerView=markerBottom;
this.minuteHelper = minuteHelper;
}
public void setHighlightValue(Highlight h) {
if (mData == null)
mIndicesToHighlight = null;
else {
mIndicesToHighlight = new Highlight[]{
h};
}
invalidate();
}
@Override
protected void drawMarkers(Canvas canvas) {
if (!mDrawMarkerViews || !valuesToHighlight())
return;
for (int i = 0; i < mIndicesToHighlight.length; i++) {
Highlight highlight = mIndicesToHighlight[i];
int xIndex = mIndicesToHighlight[i].getXIndex();
int dataSetIndex = mIndicesToHighlight[i].getDataSetIndex();
float deltaX = mXAxis != null
? mXAxis.mAxisRange
: ((mData == null ? 0.f : mData.getXValCount()) - 1.f);
if (xIndex <= deltaX && xIndex <= deltaX * mAnimator.getPhaseX()) {
Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]);
// make sure entry not null
if (e == null || e.getXIndex() != mIndicesToHighlight[i].getXIndex())
continue;
float[] pos = getMarkerPosition(e, highlight);
// check bounds
if (!mViewPortHandler.isInBounds(pos[0], pos[1]))
continue;
float yValForXIndex1 = minuteHelper.getDatas().get(mIndicesToHighlight[i].getXIndex()).cjprice;
float yValForXIndex2 = minuteHelper.getDatas().get(mIndicesToHighlight[i].getXIndex()).per;
String time = minuteHelper.getDatas().get(mIndicesToHighlight[i].getXIndex()).time;
myMarkerViewLeft.setData(yValForXIndex1);
myMarkerViewRight.setData(yValForXIndex2);
mMyBottomMarkerView.setData(time);
myMarkerViewLeft.refreshContent(e, mIndicesToHighlight[i]);
myMarkerViewRight.refreshContent(e, mIndicesToHighlight[i]);
mMyBottomMarkerView.refreshContent(e, mIndicesToHighlight[i]);
/*bug*/
// invalidate();
/**/
myMarkerViewLeft.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
myMarkerViewLeft.layout(0, 0, myMarkerViewLeft.getMeasuredWidth(),
myMarkerViewLeft.getMeasuredHeight());
myMarkerViewRight.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
myMarkerViewRight.layout(0, 0, myMarkerViewRight.getMeasuredWidth(),
myMarkerViewRight.getMeasuredHeight());
mMyBottomMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
mMyBottomMarkerView.layout(0, 0, mMyBottomMarkerView.getMeasuredWidth(),
mMyBottomMarkerView.getMeasuredHeight());
mMyBottomMarkerView.draw(canvas, pos[0]-mMyBottomMarkerView.getWidth()/2, mViewPortHandler.contentBottom());
myMarkerViewLeft.draw(canvas, mViewPortHandler.contentLeft() - myMarkerViewLeft.getWidth(), pos[1] - myMarkerViewLeft.getHeight() / 2);
myMarkerViewRight.draw(canvas, mViewPortHandler.contentRight(), pos[1] - myMarkerViewRight.getHeight() / 2);
}
}
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/mychart/MyLineChart.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 1,280 |
```java
package com.example.yanjiang.stockchart.mychart;
import com.github.mikephil.charting.components.YAxis;
/**
* ajiang
* 1025065158
* path_to_url
*/
public class MyYAxis extends YAxis {
private float baseValue=Float.NaN;
private String minValue;
public MyYAxis() {
super();
}
public MyYAxis(AxisDependency axis) {
super(axis);
}
public void setShowMaxAndUnit(String minValue) {
setShowOnlyMinMax(true);
this.minValue = minValue;
}
public float getBaseValue() {
return baseValue;
}
public String getMinValue(){
return minValue;
}
public void setBaseValue(float baseValue) {
this.baseValue = baseValue;
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/mychart/MyYAxis.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 171 |
```java
package com.example.yanjiang.stockchart.mychart;
import android.content.Context;
import android.widget.TextView;
import com.example.yanjiang.stockchart.R;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import java.text.DecimalFormat;
/**
* authorajiang
* mail1025065158@qq.com
* blogpath_to_url
*/
public class MyLeftMarkerView extends MarkerView {
/**
* Constructor. Sets up the MarkerView with a custom layout resource.
*
* @param context
* @param layoutResource the layout resource to use for the MarkerView
*/
private TextView markerTv;
private float num;
private DecimalFormat mFormat;
public MyLeftMarkerView(Context context, int layoutResource) {
super(context, layoutResource);
mFormat=new DecimalFormat("#0.00");
markerTv = (TextView) findViewById(R.id.marker_tv);
markerTv.setTextSize(10);
}
public void setData(float num){
this.num=num;
}
@Override
public void refreshContent(Entry e, Highlight highlight) {
markerTv.setText(mFormat.format(num));
}
@Override
public int getXOffset(float xpos) {
return 0;
}
@Override
public int getYOffset(float ypos) {
return 0;
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/mychart/MyLeftMarkerView.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 302 |
```java
package com.example.yanjiang.stockchart.mychart;
import android.util.SparseArray;
import com.github.mikephil.charting.components.XAxis;
/**
* authorajiang
* mail1025065158@qq.com
* blogpath_to_url
*/
public class MyXAxis extends XAxis {
private SparseArray<String> labels;
public SparseArray<String> getXLabels() {
return labels;
}
public void setXLabels(SparseArray<String> labels) {
this.labels = labels;
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/mychart/MyXAxis.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 110 |
```java
package com.example.yanjiang.stockchart.event;
public class ProgressUpdateEvent {
private long bytesRead,contentLength;
private boolean done;
public ProgressUpdateEvent(long bytesRead, long contentLength, boolean done){
this.bytesRead = bytesRead;
this.contentLength=contentLength;
this.done=done;
}
public long getbytesRead(){
return bytesRead;
}
public long getcontentLength(){
return contentLength;
}
public boolean getdone(){
return done;
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/event/ProgressUpdateEvent.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 107 |
```java
package com.example.yanjiang.stockchart.rxutils;
/**
* authorajiang
* mail1025065158@qq.com
* blogpath_to_url
*/
public class MyUtils {
/**
* Prevent class instantiation.
*/
private MyUtils() {
}
public static String getVolUnit(float num) {
int e = (int) Math.floor(Math.log10(num));
if (e >= 8) {
return "";
} else if (e >= 4) {
return "";
} else {
return "";
}
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/rxutils/MyUtils.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 120 |
```java
package com.example.yanjiang.stockchart.rxutils;
import android.os.Build;
import android.support.annotation.NonNull;
import java.io.File;
import java.io.FileFilter;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
public class ExecutorManager {
public static final int DEVICE_INFO_UNKNOWN = 0;
public static ExecutorService eventExecutor;
//private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
private static final int CPU_COUNT = ExecutorManager.getCountOfCPU();
private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
private static final int KEEP_ALIVE = 1;
private static final BlockingQueue<Runnable> eventPoolWaitQueue = new LinkedBlockingQueue<>(128);
private static final ThreadFactory eventThreadFactory = new ThreadFactory() {
private final AtomicInteger mCount = new AtomicInteger(1);
@Override
public Thread newThread(@NonNull Runnable r) {
return new Thread(r, "eventAsyncAndBackground #" + mCount.getAndIncrement());
}
};
private static final RejectedExecutionHandler eventHandler =
new ThreadPoolExecutor.CallerRunsPolicy();
static {
eventExecutor =
new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE, TimeUnit.SECONDS,
eventPoolWaitQueue, eventThreadFactory, eventHandler);
}
/**
* LinuxCPUCPU
* AndroidCPU /sys/devices/system/cpu/cpu\d+
*
* path_to_url# liangfeizc :)
* path_to_url
*/
public static int getCountOfCPU() {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
return 1;
}
int count;
try {
count = new File("/sys/devices/system/cpu/").listFiles(CPU_FILTER).length;
} catch (SecurityException | NullPointerException e) {
count = DEVICE_INFO_UNKNOWN;
}
return count;
}
private static final FileFilter CPU_FILTER = new FileFilter() {
@Override
public boolean accept(File pathname) {
String path = pathname.getName();
if (path.startsWith("cpu")) {
for (int i = 3; i < path.length(); i++) {
if (path.charAt(i) < '0' || path.charAt(i) > '9') {
return false;
}
}
return true;
}
return false;
}
};
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/rxutils/ExecutorManager.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 579 |
```java
package com.example.yanjiang.stockchart.rxutils;
import android.util.Log;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.formatter.YAxisValueFormatter;
import java.text.DecimalFormat;
public class VolFormatter implements YAxisValueFormatter {
private final int unit;
private DecimalFormat mFormat;
private String u;
public VolFormatter(int unit) {
if (unit == 1) {
mFormat = new DecimalFormat("#0");
} else {
mFormat = new DecimalFormat("#0.00");
}
this.unit = unit;
this.u=MyUtils.getVolUnit(unit);
}
@Override
public String getFormattedValue(float value, YAxis yAxis) {
value = value / unit;
if(value==0){
return u;
}
return mFormat.format(value);
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/rxutils/VolFormatter.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 186 |
```java
package com.example.yanjiang.stockchart.rxutils;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
/**
* :.compose( ) path_to_url
* Created by Joker on 2015/8/10.
*/
public class SchedulersCompat {
private static final Observable.Transformer computationTransformer =
new Observable.Transformer() {
@Override
public Object call(Object observable) {
return ((Observable) observable).subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread());
}
};
private static final Observable.Transformer ioTransformer = new Observable.Transformer() {
@Override
public Object call(Object observable) {
return ((Observable) observable).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
};
private static final Observable.Transformer newTransformer = new Observable.Transformer() {
@Override
public Object call(Object observable) {
return ((Observable) observable).subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
}
};
private static final Observable.Transformer trampolineTransformer = new Observable.Transformer() {
@Override
public Object call(Object observable) {
return ((Observable) observable).subscribeOn(Schedulers.trampoline())
.observeOn(AndroidSchedulers.mainThread());
}
};
private static final Observable.Transformer executorTransformer = new Observable.Transformer() {
@Override
public Object call(Object observable) {
return ((Observable) observable).subscribeOn(Schedulers.from(ExecutorManager.eventExecutor))
.observeOn(AndroidSchedulers.mainThread());
}
};
/**
* Don't break the chain: use RxJava's compose() operator
*/
public static <T> Observable.Transformer<T, T> applyComputationSchedulers() {
return (Observable.Transformer<T, T>) computationTransformer;
}
public static <T> Observable.Transformer<T, T> applyIoSchedulers() {
return (Observable.Transformer<T, T>) ioTransformer;
}
public static <T> Observable.Transformer<T, T> applyNewSchedulers() {
return (Observable.Transformer<T, T>) newTransformer;
}
public static <T> Observable.Transformer<T, T> applyTrampolineSchedulers() {
return (Observable.Transformer<T, T>) trampolineTransformer;
}
public static <T> Observable.Transformer<T, T> applyExecutorSchedulers() {
return (Observable.Transformer<T, T>) executorTransformer;
}
/* *//**
* loading
*//*
@SuppressWarnings("unchecked")
public static <T> Observable.Transformer<T, T> showLoading(final TransActivity activity) {
return new Observable.Transformer<T, T>() {
@Override
public Observable<T> call(Observable<T> observable) {
return observable.doOnSubscribe(new Action0() {
@Override
public void call() {
activity.showLoadingDialog();
}
}).subscribeOn(AndroidSchedulers.mainThread()).doOnTerminate(new Action0() {
@Override
public void call() {
activity.hideLoadingDialog();
}
}).observeOn(AndroidSchedulers.mainThread());
}
};
}*/
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/rxutils/SchedulersCompat.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 664 |
```java
package com.example.yanjiang.stockchart.rxutils;
import android.content.Context;
import android.os.Environment;
import android.util.Log;
import com.example.yanjiang.stockchart.api.Constant;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import okhttp3.ResponseBody;
public class FileUtils {
/**/
public static boolean writeResponseBodyToDisk(ResponseBody body,Context context) {
try {
String patchPath = Constant.EXTERNALPATH + Constant.APATCH_PATH;///storage/emulated/0/out.apatch
// todo change the file location/name according to your needs
File futureStudioIconFile = new File(patchPath);
InputStream inputStream = null;
OutputStream outputStream = null;
try {
byte[] fileReader = new byte[4096];
long fileSize = body.contentLength();
long fileSizeDownloaded = 0;
inputStream = body.byteStream();
outputStream = new FileOutputStream(futureStudioIconFile);
while (true) {
int read = inputStream.read(fileReader);
if (read == -1) {
break;
}
outputStream.write(fileReader, 0, read);
fileSizeDownloaded += read;
Log.e("@@@", "file download: " + fileSizeDownloaded + " of " + fileSize + futureStudioIconFile.getPath());
}
outputStream.flush();
return true;
} catch (IOException e) {
return false;
} finally {
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
}
} catch (IOException e) {
return false;
}
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/rxutils/FileUtils.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 356 |
```java
package com.example.yanjiang.stockchart.rxutils;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Environment;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.Log;
import android.widget.TextView;
import com.example.yanjiang.stockchart.api.Constant;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Enumeration;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by lizhi on 2016/2/23.
*/
public class CommonUtil {
/**
* id
* IMEIIMEImac
* ACCESS_WIFI_STATE() mac
* <p/>
* IMEImac
* IMEI000000000000000
*
* @param context
* @return
*/
public static String getUUID(Context context) {
if (context == null) {
return "";
}
final TelephonyManager tm = (TelephonyManager) context.
getSystemService(Context.TELEPHONY_SERVICE);
String tmDeviceId = "";
String androidId = "";
String mac = "";
String serial = Build.SERIAL; //12
String time = Build.TIME + "";//13
if (tm != null) {
tmDeviceId = "" + tm.getDeviceId();
}
androidId = "" + Settings.Secure.getString(context.getContentResolver(),
Settings.Secure.ANDROID_ID);
// mac = "" + getMacAdress(context);
Log.e("@@@","tmDeviceId=" + tmDeviceId + ",\nandroidId=" + androidId
+ ",\nmac=" + mac);
long uuidParam2;
uuidParam2 = (long) (androidId.hashCode() << 32 | (serial + time).hashCode());
UUID deviceUuid = new UUID(tmDeviceId.hashCode(), uuidParam2);
//32
String uniqueId = deviceUuid.toString();
String encryption = encryption(uniqueId);
Log.e("@@@","encryption====>" + encryption);
return encryption;
}
/**
* mac
*
* @param c
* @return
*/
public static String getMacAdress(Context c) {
ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
if (info == null) {
return "";
} else if (info.getType() == ConnectivityManager.TYPE_WIFI) {
return getWifiAddress(c);
} else {
return getmobileAddress(c);
}
}
public static String getmobileAddress(Context c) {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
return inetAddress.getHostAddress().toString();
}
}
}
} catch (SocketException ex) {
Log.e("@@@","mac");
}
return "";
}
public static String getWifiAddress(Context c) {
WifiManager wifiManager = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null) {
return wifiInfo.getMacAddress();
}
return "";
}
public static String encryption(String plainText) {
String re_md5 = "";
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(plainText.getBytes());
byte b[] = md.digest();
int i = 0;
StringBuilder sb = new StringBuilder("");
for (int offset = 0, len = b.length; offset < len; offset++) {
i = b[offset];
if (i < 0) {
i += 256;
}
if (i < 16) {
sb.append("0");
}
sb.append(Integer.toHexString(i));
}
re_md5 = sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return re_md5;
}
/**
*
*
* @return
*/
public static String getDeviceInfo(Context context) {
StringBuffer sb = new StringBuffer();
String androidId = Settings.Secure.getString(context.getContentResolver(),
Settings.Secure.ANDROID_ID);
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
sb.append("deviceId" + tm.getDeviceId());
sb.append("\nandroidId" + androidId);
sb.append(
" \n" + Build.ID);
sb.append(
"" + Build.SERIAL);
sb.append(
"\n TIME:" + Build.TIME);
return sb.toString();
}
/**
* CPU
*
* @return
*/
public static String getCpuName() {
try {
FileReader fr = new FileReader("/proc/cpuinfo");
BufferedReader br = new BufferedReader(fr);
String text = br.readLine();
String[] array = text.split(":\\s+", 2);
for (int i = 0; i < array.length; i++) {
}
return array[1];
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static boolean isEmpty(String text) {
if (TextUtils.isEmpty(text)) {
return true;
}
return false;
}
public static boolean isNotEmpty(String text) {
if (!TextUtils.isEmpty(text)) {
return true;
}
return false;
}
/**
* :133/153/180/181/189/177 1 3578 01379
* :130/131/132/155/156/185/186/145/176 1 34578 01256
* 134/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/178
* <p/>
* 13 0123456789
* 14 57
* 15 012356789
* 17 678
* 18 0123456789
*
* @param phoneNum
* @return
*/
public static boolean isMobilePhone(String phoneNum) {
if (isNotEmpty(phoneNum)) {
//11
Pattern p = Pattern.compile("^((13[0-9])|(14[5,7])|(15[0,1,2,3,5,6,7,8,9])|(17[6,7,8])|(18[0-9]))\\d{8}$");
boolean m = p.matcher(phoneNum).matches();
Log.e("@@@","===>" + m);
return m;
}
return false;
}
public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
public static int px2dip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}
public static int getScreenWidth(Context context) {
return (int) (context.getResources().getDisplayMetrics().widthPixels + 0.5);
}
public static int getScreenHeight(Context context) {
return (int) (context.getResources().getDisplayMetrics().heightPixels + 0.5);
}
/**
*
*
* @param context
* @return
*/
public static String getAppVersionName(Context context) {
if (context != null) {
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
if (packageInfo != null) {
return packageInfo.versionName;
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
return "";
}
public static boolean isSDCardAvailable() {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
return true;
} else {
return false;
}
}
/**
* ;
*
* @param filePath
* @return
*/
public static boolean deleteSpicificFile(String filePath) {
if (!isEmpty(filePath) && isSDCardAvailable()) {
try {
File file = new File(filePath);
if (file.exists() && file.isFile()) {
return file.delete();
}
} catch (Exception e) {
if (e != null && isNotEmpty(e.getMessage())) {
Log.e("@@@",e.getMessage());
}
}
}
return false;
}
/**
*
*
* @param context
* @return
*/
public static String getDiskCacheDir(Context context) {
String cachePath = null;
if (context != null && CommonUtil.isSDCardAvailable()) {
File cacheDirTemp = context.getExternalCacheDir();
if (cacheDirTemp != null) {
cachePath = cacheDirTemp.getPath();
}
}
return cachePath;
}
/**
*
*
* @param context
* @return
*/
public static String getImageCacheDir(Context context) {
String cachePath = null;
if (context != null && CommonUtil.isSDCardAvailable()) {
File cacheDirTemp = context.getExternalCacheDir();
if (cacheDirTemp != null) {
cachePath = cacheDirTemp.getAbsolutePath() + File.separator + "image_cache";
}
}
return cachePath;
}
/**
*
*
* @param context
* @return
*/
public static String getDiskDownloadDir(Context context) {
String downloadPath = null;
if (context != null && CommonUtil.isSDCardAvailable()) {
File downloadDirTemp = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
if (downloadDirTemp != null) {
downloadPath = downloadDirTemp.getAbsolutePath();
}
}
return downloadPath;
}
/**
*
*
* @param context
* @return
*/
public static String getApatchDownloadPath(Context context) {
String downDir = getDiskDownloadDir(context);
if (isNotEmpty(downDir)) {
//apatchhttpUrlconnection
File patchdir = new File(downDir + File.separator+"apatch");
if(!patchdir.exists()){
patchdir.mkdir();
}
return downDir + File.separator +"apatch" + File.separator + Constant.APATCH_PATH;
}
return "";
}
/**
* apk(apk)
*
* @param context
* @return
*/
public static String getApkDownloadPath(Context context) {
String downDir = getDiskDownloadDir(context);
if (isNotEmpty(downDir)) {
//apkhttpUrlconnection
File apkdir = new File(downDir + File.separator + "apk");
if(!apkdir.exists()){
apkdir.mkdir();
}
return downDir + File.separator + "apk" ;
}
return "";
}
public static int getAppVersionCode(Context context) {
if (context != null) {
PackageManager pm = context.getPackageManager();
try {
PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
if (packageInfo != null) {
return packageInfo.versionCode;
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
return -1;
}
/**
*
*/
public static void dialNumber(Activity context, String phoneNumber) {
if (context == null) {
return;
}
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + phoneNumber));
context.startActivity(intent);
}
public static String getDirSizeWithUnit(File file) {
long dirSize = getDirSize(file);
return getDataWithUnit(dirSize);
}
/**
*
*
* @param size
* @return
*/
public static String getDataWithUnit(long size) {
long kb = 1024;
long mb = kb * 1024;
if (size >= mb) {
float f = (float) size / mb;
return String.format("%.2f MB", f);
} else if (size >= kb) {
float f = (float) size / kb;
return String.format("%.2f KB", f);
}
return "0KB";
}
// 6-9;
public static boolean isValidCharacters(String s) {
Pattern p = Pattern.compile("^[0-9a-zA-Z]{6,9}$");
Matcher m = p.matcher(s);
return m.matches();
}
/**
* 2
* 2
*
* @param s
* @return true:false:
*/
public static boolean verifyMore2NumAfterPoint(CharSequence s) {
if (s != null && !isEmpty(s.toString()) && s.toString().contains(".")) {
Pattern p = Pattern.compile("^[0-9]+.[0-9]{3,}$");
boolean m = p.matcher(s).matches();
Log.e("@@@","===>" + m);
return m;
}
return false;
}
/**
*
*
* @param s
* @return
*/
public static boolean verifyPointAndEn(CharSequence s) {
if (s != null && !isEmpty(s.toString())) {
Pattern p = Pattern.compile("^[a-zA-Z0-9]+$");
boolean m = p.matcher(s).matches();
Log.e("@@@","===>" + m);
return m;
}
return false;
}
/**
*
* <p/>
* 1,
* 22
*
* @param s
* @return
*/
public static boolean verifyDataFormat(CharSequence s) {
if (s != null && !isEmpty(s.toString())) {
Pattern p1 = Pattern.compile("^[0-9]+$");
Pattern p2 = Pattern.compile("^[0-9]+.[0-9]{1,2}$");
boolean m1 = p1.matcher(s).matches();
boolean m2 = p2.matcher(s).matches();
Log.e("@@@","m1--->" + m1 + ",m2--->" + m2);
return m1 || m2;
}
return false;
}
/**
*
*
* @param s
* @param minLen
* @return
*/
public static boolean verifyLen(CharSequence s, int minLen) {
if (s != null && !isEmpty(s.toString()) && s.toString().length() >= minLen) {
return true;
}
return false;
}
/**
* 2
*
* @param s
* @return
*/
public static float formatJeNumber(CharSequence s) {
if (s != null && !TextUtils.isEmpty(s.toString())) {
BigDecimal bigDecimal = new BigDecimal(s.toString());
bigDecimal.setScale(2);
// setScale(2);//2
// setScale(2,BigDecimal.ROUND_DOWN);// 11.116=11.11
// setScale(2,BigDecimal.ROUND_UP);//11.114=11.12
// setScale(2,BigDecimal.ROUND_HALF_UP);// 2.335=2.332.3351=2.34
// setScaler(2,BigDecimal.ROUND_HALF_DOWN);//2.335=2.332.3351=2.3411.11711.12
return bigDecimal.floatValue();
}
return 0.00f;
}
/**
*
*
* @param chars
* @param prepostLen
* @return String
*/
public static String hideYhkCenterPart(String chars, int prepostLen) {
if (isEmpty(chars)) {
return "";
} else if (chars.length() > prepostLen * 2) {
int replaceCharsLen = chars.length() - prepostLen * 2;
String preStr = chars.substring(0, prepostLen);
StringBuilder sb = new StringBuilder(preStr);
for (int i = 0; i < replaceCharsLen; i++) {
sb.append("*");
}
String postStr = chars.substring(prepostLen + replaceCharsLen);
sb.append(postStr);
return sb.toString();
}
return chars;
}
/**
*
*
* @param file
*/
public static long getDirSize(File file) {
long totalSize = 0;
if (file != null && file.exists()) {
if (file.isDirectory()) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
//
if (file.isDirectory()) {
totalSize += getDirSize(files[i]);
} else {
totalSize += file.length();
}
}
} else {
totalSize += file.length();
}
}
return totalSize;
}
/**
*
*
* @param context
* @return
*/
public static boolean isConnected(Context context) {
if (context != null) {
ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (conn != null) {
NetworkInfo info = conn.getActiveNetworkInfo();
return (info != null && info.isConnected());
}
}
return false;
}
/**
*
*
* @param timeIns
* @return "xxxxxxx";
*/
public static int[] timeFormat(int timeIns) {
int dayMs = 24 * 3600;
int hourMs = 3600;
int minuteMs = 60;
int lastDays = 0;
int lastHours = 0;
int lastminutes = 0;
int lastMs = 0;
// StringBuilder sb = new StringBuilder();
//
if (timeIns > dayMs) {
lastDays = timeIns / dayMs;
timeIns = timeIns % dayMs;
}
//
if (timeIns > hourMs) {
lastHours = timeIns / hourMs;
timeIns = timeIns % hourMs;
}
//
if (timeIns > minuteMs) {
lastminutes = timeIns / minuteMs;
timeIns = timeIns % minuteMs;
}
//
lastMs = timeIns;
// sb.append(lastDays + "" + lastHours + "" + lastminutes + "" + lastMs + "");
int[] dhms = new int[4];
dhms[0] = lastDays;
dhms[1] = lastHours;
dhms[2] = lastminutes;
dhms[3] = lastMs;
return dhms;
}
/**
* tv
*
* @param tv
* @param timeIns
*/
public static void updateTimeLabel(TextView tv, int timeIns) {
if (tv == null) {
return;
}
if (timeIns <= 0) {
timeIns = 0;
}
int[] dhms = CommonUtil.timeFormat(timeIns);
Spanned spanned = Html.fromHtml("<font color=\"#c3130f\">" + dhms[0] + "</font>" +
"<font color=\"#c3130f\">" + dhms[1] + "</font>" + "<font color=\"#c3130f\">"
+ dhms[2] + "</font>" + "<font color=\"#c3130f\">" + dhms[3] + "</font>");
tv.setText(spanned);
}
/**
*
*
* @param cacehDir
*/
public static void clearCacheDir(File cacehDir) {
if (cacehDir != null) {
if (cacehDir.isDirectory()) {
File[] files = cacehDir.listFiles();
if (files != null && files.length > 0) {
for (File itemFile : files) {
//
if (itemFile.isFile()) {
itemFile.delete();
} else {
clearCacheDir(itemFile);
}
}
}
} else {
cacehDir.delete();
}
}
}
/**
* 0,0.0,0.00;
*
* @param je
* @return
*/
public static boolean verifyNoZero(String je) {
if (isNotEmpty(je)) {
if ("0".equals(je) || "0.0".equals(je) || "0.00".equals(je)) {
return true;
}
}
return false;
}
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/rxutils/CommonUtil.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 4,704 |
```java
package com.example.yanjiang.stockchart.api;
import okhttp3.ResponseBody;
import retrofit2.http.GET;
import retrofit2.http.Query;
import rx.Observable;
/**
* Created by yanjiang on 2016/3/15.
* 1
*
* @GET("Advertisement") Observable<List<TransMainDao>> getWeatherData(@Query("instID") String id);
* <p/>
* 2
* @GET("FundPaperTrade/AppUserLogin") Observable<TransDao> getTransData(@QueryMap Map<String,String> map);
* <p/>
* 3
* @FormUrlEncoded
* @POST("/newfind/index_ask") Observable<Response> getDaJia(@Field("page") int page,
* @Field("pageSize") int size,
* @Field("tokenMark") long tokenMark,
* @Field("token") String token
* );
* <p/>
* 4
* @FormUrlEncoded
* @POST("FundPaperTrade/AppUserLogin") Observable<Response> getTransData(@FieldMap Map<String,String> map);
*/
public interface ClientApi {
/*url*/
@GET(Constant.DETAILURL)
Observable<ResponseBody> getMinutes(@Query("code") String code);
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/api/ClientApi.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 257 |
```java
package com.example.yanjiang.stockchart.api;
import android.os.Environment;
/**
* Created by Administrator on 2016/6/13.
*/
public class Constant {
public static final String MINUTESURL="path_to_url";
public static final String DETAILURL="test/";
public static final String APATCH_PATH = "/out.apatch";
public static final String EXTERNALPATH = Environment.getExternalStorageDirectory().getAbsolutePath();
public static final String HTTP_BASE = "path_to_url";/*path_to_url";*/
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/api/Constant.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 110 |
```java
package com.example.yanjiang.stockchart.api;
import okhttp3.ResponseBody;
import retrofit2.http.GET;
import retrofit2.http.Streaming;
import rx.Observable;
/**
* Created by yanjiang on 2016/4/20.
*
*/
public interface DownLoadApi {
/*path_to_url
@Streaming
@GET("out.apatch")
Observable<ResponseBody> getDownApk();
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/api/DownLoadApi.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 86 |
```java
package com.example.yanjiang.stockchart;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="path_to_url">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
``` | /content/code_sandbox/app/src/androidTest/java/com/example/yanjiang/stockchart/ApplicationTest.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 62 |
```java
package com.github.mikephil.charting.highlight;
import java.util.ArrayList;
import java.util.List;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider;
import com.github.mikephil.charting.utils.SelectionDetail;
import com.github.mikephil.charting.utils.Utils;
/**
* Created by Philipp Jahoda on 21/07/15.
*/
public class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider> {
/** instance of the data-provider */
protected T mChart;
public ChartHighlighter(T chart) {
this.mChart = chart;
}
/**
* Returns a Highlight object corresponding to the given x- and y- touch positions in pixels.
*
* @param x
* @param y
* @return
*/
public Highlight getHighlight(float x, float y) {
int xIndex = getXIndex(x);
SelectionDetail selectionDetail = getSelectionDetail(xIndex, y, -1);
if (selectionDetail == null)
return null;
return new Highlight(xIndex,
selectionDetail.value,
selectionDetail.dataIndex,
selectionDetail.dataSetIndex);
}
/**
* Returns the corresponding x-index for a given touch-position in pixels.
*
* @param x
* @return
*/
protected int getXIndex(float x) {
// create an array of the touch-point
float[] pts = new float[2];
pts[0] = x;
// take any transformer to determine the x-axis value
mChart.getTransformer(YAxis.AxisDependency.LEFT).pixelsToValue(pts);
return Math.round(pts[0]);
}
/**
* Returns the corresponding SelectionDetail for a given xIndex and y-touch position in pixels.
*
* @param xIndex
* @param y
* @param dataSetIndex
* @return
*/
protected SelectionDetail getSelectionDetail(int xIndex, float y, int dataSetIndex) {
List<SelectionDetail> valsAtIndex = getSelectionDetailsAtIndex(xIndex, dataSetIndex);
float leftdist = Utils.getMinimumDistance(valsAtIndex, y, YAxis.AxisDependency.LEFT);
float rightdist = Utils.getMinimumDistance(valsAtIndex, y, YAxis.AxisDependency.RIGHT);
YAxis.AxisDependency axis = leftdist < rightdist ? YAxis.AxisDependency.LEFT : YAxis.AxisDependency.RIGHT;
return Utils.getClosestSelectionDetailByPixelY(valsAtIndex, y, axis);
}
/**
* Returns a list of SelectionDetail object corresponding to the given xIndex.
*
* @param xIndex
* @param dataSetIndex dataSet index to look at. -1 if unspecified.
* @return
*/
protected List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex, int dataSetIndex) {
List<SelectionDetail> vals = new ArrayList<>();
if (mChart.getData() == null)
return vals;
float[] pts = new float[2];
for (int i = 0, dataSetCount = mChart.getData().getDataSetCount();
i < dataSetCount;
i++) {
if (dataSetIndex > -1 && dataSetIndex != i)
continue;
IDataSet dataSet = mChart.getData().getDataSetByIndex(i);
// dont include datasets that cannot be highlighted
if (!dataSet.isHighlightEnabled())
continue;
// extract all y-values from all DataSets at the given x-index
final float[] yVals = dataSet.getYValsForXIndex(xIndex);
for (float yVal : yVals) {
if (Float.isNaN(yVal))
continue;
pts[1] = yVal;
mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts);
if (!Float.isNaN(pts[1]))
{
vals.add(new SelectionDetail(pts[1], yVal, i, dataSet));
}
}
}
return vals;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/highlight/ChartHighlighter.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 884 |
```java
package com.github.mikephil.charting.highlight;
/**
* Created by Philipp Jahoda on 24/07/15. Class that represents the range of one value in a stacked bar entry. e.g.
* stack values are -10, 5, 20 -> then ranges are (-10 - 0, 0 - 5, 5 - 25).
*/
public final class Range {
public float from;
public float to;
public Range(float from, float to) {
this.from = from;
this.to = to;
}
/**
* Returns true if this range contains (if the value is in between) the given value, false if not.
*
* @param value
* @return
*/
public boolean contains(float value) {
return (value > from && value <= to);
}
public boolean isLarger(float value) {
return value > to;
}
public boolean isSmaller(float value) {
return value < from;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/highlight/Range.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 211 |
```java
package com.github.mikephil.charting.highlight;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
import com.github.mikephil.charting.utils.SelectionDetail;
/**
* Created by Philipp Jahoda on 22/07/15.
*/
public class HorizontalBarHighlighter extends BarHighlighter {
public HorizontalBarHighlighter(BarDataProvider chart) {
super(chart);
}
@Override
public Highlight getHighlight(float x, float y) {
BarData barData = mChart.getBarData();
final int xIndex = getXIndex(x);
final float baseNoSpace = getBase(x);
final int setCount = barData.getDataSetCount();
int dataSetIndex = ((int)baseNoSpace) % setCount;
if (dataSetIndex < 0) {
dataSetIndex = 0;
} else if (dataSetIndex >= setCount) {
dataSetIndex = setCount - 1;
}
SelectionDetail selectionDetail = getSelectionDetail(xIndex, y, dataSetIndex);
if (selectionDetail == null)
return null;
IBarDataSet set = barData.getDataSetByIndex(dataSetIndex);
if (set.isStacked()) {
float[] pts = new float[2];
pts[0] = y;
// take any transformer to determine the x-axis value
mChart.getTransformer(set.getAxisDependency()).pixelsToValue(pts);
return getStackedHighlight(selectionDetail,
set,
xIndex,
pts[0]);
}
return new Highlight(
xIndex,
selectionDetail.value,
selectionDetail.dataIndex,
selectionDetail.dataSetIndex,
-1);
}
@Override
protected int getXIndex(float x) {
if (!mChart.getBarData().isGrouped()) {
// create an array of the touch-point
float[] pts = new float[2];
pts[1] = x;
// take any transformer to determine the x-axis value
mChart.getTransformer(YAxis.AxisDependency.LEFT).pixelsToValue(pts);
return Math.round(pts[1]);
} else {
float baseNoSpace = getBase(x);
int setCount = mChart.getBarData().getDataSetCount();
int xIndex = (int) baseNoSpace / setCount;
int valCount = mChart.getData().getXValCount();
if (xIndex < 0)
xIndex = 0;
else if (xIndex >= valCount)
xIndex = valCount - 1;
return xIndex;
}
}
/**
* Returns the base y-value to the corresponding x-touch value in pixels.
*
* @param y
* @return
*/
@Override
protected float getBase(float y) {
// create an array of the touch-point
float[] pts = new float[2];
pts[1] = y;
// take any transformer to determine the x-axis value
mChart.getTransformer(YAxis.AxisDependency.LEFT).pixelsToValue(pts);
float yVal = pts[1];
int setCount = mChart.getBarData().getDataSetCount();
// calculate how often the group-space appears
int steps = (int) (yVal / ((float) setCount + mChart.getBarData().getGroupSpace()));
float groupSpaceSum = mChart.getBarData().getGroupSpace() * (float) steps;
return yVal - groupSpaceSum;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/highlight/HorizontalBarHighlighter.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 804 |
```java
package com.github.mikephil.charting.highlight;
/**
* Contains information needed to determine the highlighted value.
*
* @author Philipp Jahoda
*/
public class Highlight {
/** the x-index of the highlighted value */
private int mXIndex;
/** the y-value of the highlighted value */
private float mValue = Float.NaN;
/** the index of the data object - in case it refers to more than one */
private int mDataIndex;
/** the index of the dataset the highlighted value is in */
private int mDataSetIndex;
/** index which value of a stacked bar entry is highlighted, default -1 */
private int mStackIndex = -1;
/** the range of the bar that is selected (only for stacked-barchart) */
private Range mRange;
/**
* constructor
*
* @param x the index of the highlighted value on the x-axis
* @param value the y-value of the highlighted value
* @param dataIndex the index of the Data the highlighted value belongs to
* @param dataSetIndex the index of the DataSet the highlighted value belongs to
*/
public Highlight(int x, float value, int dataIndex, int dataSetIndex) {
this.mXIndex = x;
this.mValue = value;
this.mDataIndex = dataIndex;
this.mDataSetIndex = dataSetIndex;
}
/**
* Constructor, only used for stacked-barchart.
*
* @param x the index of the highlighted value on the x-axis
* @param value the y-value of the highlighted value
* @param dataIndex the index of the Data the highlighted value belongs to
* @param dataSetIndex the index of the DataSet the highlighted value belongs to
* @param stackIndex references which value of a stacked-bar entry has been
* selected
*/
public Highlight(int x, float value, int dataIndex, int dataSetIndex, int stackIndex) {
this(x, value, dataIndex, dataSetIndex);
mStackIndex = stackIndex;
}
/**
* Constructor, only used for stacked-barchart.
*
* @param x the index of the highlighted value on the x-axis
* @param value the y-value of the highlighted value
* @param dataIndex the index of the Data the highlighted value belongs to
* @param dataSetIndex the index of the DataSet the highlighted value belongs to
* @param stackIndex references which value of a stacked-bar entry has been
* selected
* @param range the range the selected stack-value is in
*/
public Highlight(int x, float value, int dataIndex, int dataSetIndex, int stackIndex, Range range) {
this(x, value, dataIndex, dataSetIndex, stackIndex);
this.mRange = range;
}
/**
* Constructor, only used for stacked-barchart.
*
* @param x the index of the highlighted value on the x-axis
* @param dataSetIndex the index of the DataSet the highlighted value belongs to
*/
public Highlight(int x, int dataSetIndex) {
this(x, Float.NaN, 0, dataSetIndex, -1);
}
/**
* returns the index of the highlighted value on the x-axis
*
* @return
*/
public int getXIndex() {
return mXIndex;
}
/**
* returns the y-value of the highlighted value
*
* @return
*/
public float getValue() {
return mValue;
}
/**
* the index of the data object - in case it refers to more than one
*
* @return
*/
public int getDataIndex() {
return mDataIndex;
}
/**
* returns the index of the DataSet the highlighted value is in
*
* @return
*/
public int getDataSetIndex() {
return mDataSetIndex;
}
/**
* Only needed if a stacked-barchart entry was highlighted. References the
* selected value within the stacked-entry.
*
* @return
*/
public int getStackIndex() {
return mStackIndex;
}
/**
* Returns the range of values the selected value of a stacked bar is in. (this is only relevant for stacked-barchart)
* @return
*/
public Range getRange() {
return mRange;
}
/**
* returns true if this highlight object is equal to the other (compares
* xIndex and dataSetIndex)
*
* @param h
* @return
*/
public boolean equalTo(Highlight h) {
if (h == null)
return false;
else {
return (this.mDataSetIndex == h.mDataSetIndex && this.mXIndex == h.mXIndex
&& this.mStackIndex == h.mStackIndex);
}
}
@Override
public String toString() {
return "Highlight, xIndex: " + mXIndex + ", dataSetIndex: " + mDataSetIndex
+ ", stackIndex (only stacked barentry): " + mStackIndex;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/highlight/Highlight.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 1,105 |
```java
package com.github.mikephil.charting.highlight;
import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.data.CombinedData;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider;
import com.github.mikephil.charting.utils.SelectionDetail;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Philipp Jahoda on 12/09/15.
*/
public class CombinedHighlighter extends ChartHighlighter<BarLineScatterCandleBubbleDataProvider> {
public CombinedHighlighter(BarLineScatterCandleBubbleDataProvider chart) {
super(chart);
}
/**
* Returns a list of SelectionDetail object corresponding to the given xIndex.
*
* @param xIndex
* @return
*/
@Override
protected List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex, int dataSetIndex) {
List<SelectionDetail> vals = new ArrayList<>();
float[] pts = new float[2];
CombinedData data = (CombinedData) mChart.getData();
// get all chartdata objects
List<ChartData> dataObjects = data.getAllData();
for (int i = 0; i < dataObjects.size(); i++) {
for(int j = 0; j < dataObjects.get(i).getDataSetCount(); j++) {
IDataSet dataSet = dataObjects.get(i).getDataSetByIndex(j);
// dont include datasets that cannot be highlighted
if (!dataSet.isHighlightEnabled())
continue;
// extract all y-values from all DataSets at the given x-index
final float[] yVals = dataSet.getYValsForXIndex(xIndex);
for (float yVal : yVals) {
pts[1] = yVal;
mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts);
if (!Float.isNaN(pts[1])) {
vals.add(new SelectionDetail(pts[1], yVal, i, j, dataSet));
}
}
}
}
return vals;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/highlight/CombinedHighlighter.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 457 |
```java
package com.github.mikephil.charting.highlight;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.utils.SelectionDetail;
/**
* Created by Philipp Jahoda on 22/07/15.
*/
public class BarHighlighter extends ChartHighlighter<BarDataProvider> {
public BarHighlighter(BarDataProvider chart) {
super(chart);
}
@Override
public Highlight getHighlight(float x, float y) {
BarData barData = mChart.getBarData();
final int xIndex = getXIndex(x);
final float baseNoSpace = getBase(x);
final int setCount = barData.getDataSetCount();
int dataSetIndex = ((int)baseNoSpace) % setCount;
if (dataSetIndex < 0) {
dataSetIndex = 0;
} else if (dataSetIndex >= setCount) {
dataSetIndex = setCount - 1;
}
SelectionDetail selectionDetail = getSelectionDetail(xIndex, y, dataSetIndex);
if (selectionDetail == null)
return null;
IBarDataSet set = barData.getDataSetByIndex(dataSetIndex);
if (set.isStacked()) {
float[] pts = new float[2];
pts[1] = y;
// take any transformer to determine the x-axis value
mChart.getTransformer(set.getAxisDependency()).pixelsToValue(pts);
return getStackedHighlight(selectionDetail,
set,
xIndex,
pts[1]);
}
return new Highlight(
xIndex,
selectionDetail.value,
selectionDetail.dataIndex,
selectionDetail.dataSetIndex,
-1);
}
@Override
protected int getXIndex(float x) {
if (!mChart.getBarData().isGrouped()) {
return super.getXIndex(x);
} else {
float baseNoSpace = getBase(x);
int setCount = mChart.getBarData().getDataSetCount();
int xIndex = (int) baseNoSpace / setCount;
int valCount = mChart.getData().getXValCount();
if (xIndex < 0)
xIndex = 0;
else if (xIndex >= valCount)
xIndex = valCount - 1;
return xIndex;
}
}
@Override
protected SelectionDetail getSelectionDetail(int xIndex, float y, int dataSetIndex) {
dataSetIndex = Math.max(dataSetIndex, 0);
BarData barData = mChart.getBarData();
IDataSet dataSet = barData.getDataSetCount() > dataSetIndex
? barData.getDataSetByIndex(dataSetIndex)
: null;
if (dataSet == null)
return null;
final float yValue = dataSet.getYValForXIndex(xIndex);
if (yValue == Double.NaN)
return null;
return new SelectionDetail(
yValue,
dataSetIndex,
dataSet);
}
/**
* This method creates the Highlight object that also indicates which value of a stacked BarEntry has been selected.
*
* @param selectionDetail the selection detail to work with looking for stacked values
* @param set
* @param xIndex
* @param yValue
* @return
*/
protected Highlight getStackedHighlight(
SelectionDetail selectionDetail,
IBarDataSet set,
int xIndex,
double yValue) {
BarEntry entry = set.getEntryForXIndex(xIndex);
if (entry == null)
return null;
if (entry.getVals() == null) {
return new Highlight(xIndex,
entry.getVal(),
selectionDetail.dataIndex,
selectionDetail.dataSetIndex);
}
Range[] ranges = getRanges(entry);
if (ranges.length > 0) {
int stackIndex = getClosestStackIndex(ranges, (float)yValue);
return new Highlight(
xIndex,
entry.getPositiveSum() - entry.getNegativeSum(),
selectionDetail.dataIndex,
selectionDetail.dataSetIndex,
stackIndex,
ranges[stackIndex]
);
}
return null;
}
/**
* Returns the index of the closest value inside the values array / ranges (stacked barchart) to the value given as
* a parameter.
*
* @param ranges
* @param value
* @return
*/
protected int getClosestStackIndex(Range[] ranges, float value) {
if (ranges == null || ranges.length == 0)
return 0;
int stackIndex = 0;
for (Range range : ranges) {
if (range.contains(value))
return stackIndex;
else
stackIndex++;
}
int length = Math.max(ranges.length - 1, 0);
return (value > ranges[length].to) ? length : 0;
//
// float[] vals = e.getVals();
//
// if (vals == null)
// return -1;
//
// int index = 0;
// float remainder = e.getNegativeSum();
//
// while (index < vals.length - 1 && value > vals[index] + remainder) {
// remainder += vals[index];
// index++;
// }
//
// return index;
}
/**
* Returns the base x-value to the corresponding x-touch value in pixels.
*
* @param x
* @return
*/
protected float getBase(float x) {
// create an array of the touch-point
float[] pts = new float[2];
pts[0] = x;
// take any transformer to determine the x-axis value
mChart.getTransformer(YAxis.AxisDependency.LEFT).pixelsToValue(pts);
float xVal = pts[0];
int setCount = mChart.getBarData().getDataSetCount();
// calculate how often the group-space appears
int steps = (int) (xVal / ((float) setCount + mChart.getBarData().getGroupSpace()));
float groupSpaceSum = mChart.getBarData().getGroupSpace() * (float) steps;
return xVal - groupSpaceSum;
}
/**
* Splits up the stack-values of the given bar-entry into Range objects.
*
* @param entry
* @return
*/
protected Range[] getRanges(BarEntry entry) {
float[] values = entry.getVals();
if (values == null || values.length == 0)
return new Range[0];
Range[] ranges = new Range[values.length];
float negRemain = -entry.getNegativeSum();
float posRemain = 0f;
for (int i = 0; i < ranges.length; i++) {
float value = values[i];
if (value < 0) {
ranges[i] = new Range(negRemain, negRemain + Math.abs(value));
negRemain += Math.abs(value);
} else {
ranges[i] = new Range(posRemain, posRemain + value);
posRemain += value;
}
}
return ranges;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/highlight/BarHighlighter.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 1,664 |
```java
package com.github.mikephil.charting.jobs;
import android.view.View;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* Runnable that is used for viewport modifications since they cannot be
* executed at any time. This can be used to delay the execution of viewport
* modifications until the onSizeChanged(...) method of the chart-view is called.
* This is especially important if viewport modifying methods are called on the chart
* directly after initialization.
*
* @author Philipp Jahoda
*/
public abstract class ViewPortJob implements Runnable {
protected float[] pts = new float[2];
protected ViewPortHandler mViewPortHandler;
protected float xValue = 0f;
protected float yValue = 0f;
protected Transformer mTrans;
protected View view;
public ViewPortJob(ViewPortHandler viewPortHandler, float xValue, float yValue,
Transformer trans, View v) {
this.mViewPortHandler = viewPortHandler;
this.xValue = xValue;
this.yValue = yValue;
this.mTrans = trans;
this.view = v;
}
public float getXValue() {
return xValue;
}
public float getYValue() {
return yValue;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/jobs/ViewPortJob.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 278 |
```java
package com.github.mikephil.charting.jobs;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.view.View;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* Created by Philipp Jahoda on 19/02/16.
*/
@SuppressLint("NewApi")
public abstract class AnimatedViewPortJob extends ViewPortJob implements ValueAnimator.AnimatorUpdateListener {
protected ObjectAnimator animator;
protected float phase;
protected float xOrigin;
protected float yOrigin;
public AnimatedViewPortJob(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v, float xOrigin, float yOrigin, long duration) {
super(viewPortHandler, xValue, yValue, trans, v);
this.xOrigin = xOrigin;
this.yOrigin = yOrigin;
animator = ObjectAnimator.ofFloat(this, "phase", 0f, 1f);
animator.setDuration(duration);
animator.addUpdateListener(this);
}
@SuppressLint("NewApi")
@Override
public void run() {
animator.start();
}
public float getPhase() {
return phase;
}
public void setPhase(float phase) {
this.phase = phase;
}
public float getXOrigin() {
return xOrigin;
}
public float getYOrigin() {
return yOrigin;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/jobs/AnimatedViewPortJob.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 310 |
```java
package com.github.mikephil.charting.jobs;
import android.animation.Animator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.graphics.Matrix;
import android.view.View;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* Created by Philipp Jahoda on 19/02/16.
*/
@SuppressLint("NewApi")
public class AnimatedZoomJob extends AnimatedViewPortJob implements Animator.AnimatorListener {
protected float zoomOriginX;
protected float zoomOriginY;
protected float zoomCenterX;
protected float zoomCenterY;
protected YAxis yAxis;
protected float xValCount;
@SuppressLint("NewApi")
public AnimatedZoomJob(ViewPortHandler viewPortHandler, View v, Transformer trans, YAxis axis, float xValCount, float scaleX, float scaleY, float xOrigin, float yOrigin, float zoomCenterX, float zoomCenterY, float zoomOriginX, float zoomOriginY, long duration) {
super(viewPortHandler, scaleX, scaleY, trans, v, xOrigin, yOrigin, duration);
this.zoomCenterX = zoomCenterX;
this.zoomCenterY = zoomCenterY;
this.zoomOriginX = zoomOriginX;
this.zoomOriginY = zoomOriginY;
this.animator.addListener(this);
this.yAxis = axis;
this.xValCount = xValCount;
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float scaleX = xOrigin + (xValue - xOrigin) * phase;
float scaleY = yOrigin + (yValue - yOrigin) * phase;
Matrix save = mViewPortHandler.setZoom(scaleX, scaleY);
mViewPortHandler.refresh(save, view, false);
float valsInView = yAxis.mAxisRange / mViewPortHandler.getScaleY();
float xsInView = xValCount / mViewPortHandler.getScaleX();
pts[0] = zoomOriginX + ((zoomCenterX - xsInView / 2f) - zoomOriginX) * phase;
pts[1] = zoomOriginY + ((zoomCenterY + valsInView / 2f) - zoomOriginY) * phase;
mTrans.pointValuesToPixel(pts);
save = mViewPortHandler.translate(pts);
mViewPortHandler.refresh(save, view, true);
}
@Override
public void onAnimationEnd(Animator animation) {
((BarLineChartBase) view).calculateOffsets();
view.postInvalidate();
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
@Override
public void onAnimationStart(Animator animation) {
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/jobs/AnimatedZoomJob.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 610 |
```java
package com.github.mikephil.charting.jobs;
import android.graphics.Matrix;
import android.view.View;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* Created by Philipp Jahoda on 19/02/16.
*/
public class ZoomJob extends ViewPortJob {
protected float scaleX;
protected float scaleY;
protected YAxis.AxisDependency axisDependency;
public ZoomJob(ViewPortHandler viewPortHandler, float scaleX, float scaleY, float xValue, float yValue, Transformer trans, YAxis.AxisDependency axis, View v) {
super(viewPortHandler, xValue, yValue, trans, v);
this.scaleX = scaleX;
this.scaleY = scaleY;
this.axisDependency = axis;
}
@Override
public void run() {
Matrix save = mViewPortHandler.zoom(scaleX, scaleY);
mViewPortHandler.refresh(save, view, false);
float valsInView = ((BarLineChartBase) view).getDeltaY(axisDependency) / mViewPortHandler.getScaleY();
float xsInView = ((BarLineChartBase) view).getXAxis().getValues().size() / mViewPortHandler.getScaleX();
pts[0] = xValue - xsInView / 2f;
pts[1] = yValue + valsInView / 2f;
mTrans.pointValuesToPixel(pts);
save = mViewPortHandler.translate(pts);
mViewPortHandler.refresh(save, view, false);
((BarLineChartBase) view).calculateOffsets();
view.postInvalidate();
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/jobs/ZoomJob.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 368 |
```java
package com.github.mikephil.charting.jobs;
import android.view.View;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* Created by Philipp Jahoda on 19/02/16.
*/
public class MoveViewJob extends ViewPortJob {
public MoveViewJob(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v) {
super(viewPortHandler, xValue, yValue, trans, v);
}
@Override
public void run() {
pts[0] = xValue;
pts[1] = yValue;
mTrans.pointValuesToPixel(pts);
mViewPortHandler.centerViewPort(pts, view);
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/jobs/MoveViewJob.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 164 |
```java
package com.example.yanjiang.stockchart.api;
/**
* ajiang
* 1025065158@qq.com
* path_to_url
*/
public class ConstantTest {
public static final String MINUTESURL="{\"code\":0,\"msg\":\"\",\"data\":{\"sz002081\":{\"fundQt\":{\"sz002081\":[\"002081\",\"\\u5927\\u6210\\u666f\\u6c9b\\u7075\\u6d3b\\u914d\\u7f6e\\u6df7\\u5408A\",\"20160608\",\"1.0150\",\"1.0150\",\"0.000\",\"0.0000\",\"0\",\"0.0030\",\"2561\",\"\",\"\",\"\",\"\\u5f20\\u6587\\u5e73\",\"0.0040\",\"2411\",\"\\u6682\\u505c\",\"\\u5f00\\u653e\",\"\\u6df7\\u5408\\u578b\",\"\\u80a1\\u503a\\u5e73\\u8861\\u578b\\u57fa\\u91d1\",\"\\u7a33\\u5065\\u6210\\u957f\\u578b\",\"52611.5000\",\"53400.6725\",\"\\u5927\\u6210\\u57fa\\u91d1\\u7ba1\\u7406\\u6709\\u9650\\u516c\\u53f8\",\"\\u4e2d\\u56fd\\u5149\\u5927\\u94f6\\u884c\\u80a1\\u4efd\\u6709\\u9650\\u516c\\u53f8\",\"0.6000\",\"2015-11-24\",\"\",\"\",\"\"]},\"data\":{\"data\":[\"0930 10.04 7917\",\"0931 9.85 9930\",\"0932 9.89 12499\",\"0933 9.90 13067\",\"0934 9.89 15408\",\"0935 9.89 17624\",\"0936 9.98 19084\",\"0937 9.98 20211\",\"0938 9.96 21584\",\"0939 9.98 22349\",\"0940 9.98 23491\",\"0941 9.98 24351\",\"0942 9.97 25142\",\"0943 9.97 26147\",\"0944 9.99 27426\",\"0945 9.99 29993\",\"0946 9.99 31094\",\"0947 9.99 32164\",\"0948 10.00 32974\",\"0949 10.00 33465\",\"0950 10.02 35108\",\"0951 10.04 37338\",\"0952 10.07 38109\",\"0953 10.07 40841\",\"0954 10.07 41753\",\"0955 10.07 43262\",\"0956 10.10 46752\",\"0957 10.10 47782\",\"0958 10.09 49067\",\"0959 10.10 49802\",\"1000 10.11 51435\",\"1001 10.10 52497\",\"1002 10.09 53863\",\"1003 10.09 54607\",\"1004 10.08 55707\",\"1005 10.10 57385\",\"1006 10.10 58524\",\"1007 10.10 59442\",\"1008 10.12 59949\",\"1009 10.13 61275\",\"1010 10.13 61982\",\"1011 10.13 62976\",\"1012 10.12 64241\",\"1013 10.12 64962\",\"1014 10.11 65454\",\"1015 10.11 65788\",\"1016 10.12 66318\",\"1017 10.13 67815\",\"1018 10.15 69167\",\"1019 10.18 71204\",\"1020 10.18 72609\"],\"date\":\"20160613\"},\"qt\":{\"v_s_jj002081\":[\"002081\",\"\\u5927\\u6210\\u666f\\u6c9b\\u7075\\u6d3b\\u914d\\u7f6e\\u6df7\\u5408A\",\"20160608\",\"1.0150\",\"1.0150\",\"0.000\",\"0.0000\",\"0\",\"0.0030\",\"2561\",\"\",\"\",\"\",\"\\u5f20\\u6587\\u5e73\",\"0.0040\",\"2411\",\"\\u6682\\u505c\",\"\\u5f00\\u653e\",\"\\u6df7\\u5408\\u578b\",\"\\u80a1\\u503a\\u5e73\\u8861\\u578b\\u57fa\\u91d1\",\"\\u7a33\\u5065\\u6210\\u957f\\u578b\",\"52611.5000\",\"53400.6725\",\"\\u5927\\u6210\\u57fa\\u91d1\\u7ba1\\u7406\\u6709\\u9650\\u516c\\u53f8\",\"\\u4e2d\\u56fd\\u5149\\u5927\\u94f6\\u884c\\u80a1\\u4efd\\u6709\\u9650\\u516c\\u53f8\",\"0.6000\",\"2015-11-24\",\"\",\"\",\"\"],\"market\":[\"2016-06-13 16:06:01|HK_close_\\u5df2\\u6536\\u76d8|SH_close_\\u5df2\\u6536\\u76d8|SZ_close_\\u5df2\\u6536\\u76d8|US_close_\\u672a\\u5f00\\u76d8|SQ_close_\\u5df2\\u4f11\\u5e02|DS_close_\\u5df2\\u4f11\\u5e02|ZS_close_\\u5df2\\u4f11\\u5e02\"],\"sz002081\":[\"51\",\"\\u91d1 \\u87b3 \\u8782\",\"002081\",\"9.86\",\"10.04\",\"10.04\",\"299741\",\"143765\",\"155976\",\"9.85\",\"1280\",\"9.84\",\"226\",\"9.83\",\"164\",\"9.82\",\"680\",\"9.81\",\"697\",\"9.86\",\"430\",\"9.87\",\"321\",\"9.88\",\"701\",\"9.89\",\"607\",\"9.90\",\"281\",\"15:00:01\\/9.86\\/3535\\/S\\/3485510\\/33300|14:57:01\\/9.86\\/101\\/B\\/99559\\/32990|14:56:58\\/9.86\\/18\\/B\\/17743\\/32981|14:56:52\\/9.86\\/73\\/S\\/72481\\/32970|14:56:49\\/9.86\\/38\\/S\\/36980\\/32964|14:56:46\\/9.87\\/64\\/B\\/63108\\/32959\",\"20160613150137\",\"-0.18\",\"-1.79\",\"10.26\",\"9.80\",\"9.86\\/296206\\/298840720\",\"299741\",\"30233\",\"1.19\",\"15.99\",\"\",\"10.26\",\"9.80\",\"4.58\",\"248.32\",\"260.63\",\"1.91\",\"11.04\",\"9.04\",\"\"],\"zjlx\":[\"sz002081\",\"13808.61\",\"16272.41\",\"-2463.80\",\"-8.15\",\"16424.02\",\"13960.23\",\"2463.79\",\"8.15\",\"30232.63\",\"53095.67\",\"61220.51\",\"\\u91d1 \\u87b3 \\u8782\",\"20160613\",\"20160608^8921.92^12669.59\",\"20160607^7605.27^7386.58\",\"20160606^7653.72^9006.39\",\"20160603^15106.15^15885.54\"]},\"mx_price\":{\"mx\":{\"data\":[50,\"32858\\/14:56:04\\/9.86\\/-0.02\\/210\\/207049\\/S|32866\\/14:56:07\\/9.86\\/0.00\\/28\\/27602\\/B|32874\\/14:56:10\\/9.85\\/-0.01\\/20\\/19700\\/S|32880\\/14:56:13\\/9.86\\/0.01\\/33\\/32538\\/B|32888\\/14:56:16\\/9.86\\/0.00\\/29\\/28594\\/B|32896\\/14:56:19\\/9.85\\/-0.01\\/78\\/76497\\/S|32905\\/14:56:22\\/9.88\\/0.03\\/112\\/110642\\/B|32918\\/14:56:25\\/9.85\\/-0.03\\/277\\/273346\\/S|32921\\/14:56:28\\/9.85\\/0.00\\/107\\/105405\\/S|32929\\/14:56:31\\/9.85\\/0.00\\/28\\/27100\\/S|32935\\/14:56:31\\/9.86\\/0.01\\/41\\/40426\\/B|32946\\/14:56:37\\/9.86\\/0.00\\/44\\/43383\\/B|32948\\/14:56:40\\/9.86\\/0.00\\/4\\/3944\\/B|32955\\/14:56:43\\/9.87\\/0.01\\/21\\/21210\\/B|32962\\/14:56:46\\/9.87\\/0.00\\/64\\/63108\\/B|32967\\/14:56:49\\/9.86\\/-0.01\\/38\\/36980\\/S|32973\\/14:56:52\\/9.86\\/0.00\\/73\\/72481\\/S|32984\\/14:56:58\\/9.86\\/0.00\\/18\\/17743\\/B|32993\\/14:57:01\\/9.86\\/0.00\\/101\\/99559\\/B|33303\\/15:00:01\\/9.86\\/0.00\\/3535\\/3485510\\/S\"],\"timeline\":[20160613,\"14:56:04~15:00:01\"]},\"price\":{\"data\":[20160613,150137,33321,\"10.25~460~4283~1.43^10.24~2132~3812~1.27^10.23~1105~3863~1.29^10.22~3051~7668~2.56^10.21~5581~11037~3.68^10.20~5646~20697~6.90^10.19~9154~15900~5.30^10.18~5746~14858~4.96^10.17~12684~19835~6.62^10.16~6512~9043~3.02^10.15~11042~15534~5.18^10.14~2534~7038~2.35^10.13~2822~5734~1.91^10.12~2156~5601~1.87^10.11~2300~4515~1.51^10.10~4598~10455~3.49^10.09~2067~6172~2.06^10.08~5943~10398~3.47^10.07~2665~4940~1.65^10.06~2774~4990~1.66^10.05~2838~5195~1.73^10.04~12008~15567~5.19^10.03~1644~3970~1.32^10.02~2250~6338~2.11^10.01~3822~7979~2.66^10.00~6255~13495~4.50^9.99~5900~9588~3.20^9.98~758~2669~0.89^9.97~2110~3280~1.09^9.96~1186~2705~0.90^9.95~359~1274~0.43^9.94~635~1959~0.65^9.93~10~379~0.13^9.92~827~2709~0.90^9.91~1642~3453~1.15^9.90~8921~13480~4.50^9.89~2954~4504~1.50^9.88~2245~4212~1.41^9.87~1174~2035~0.68^9.86~4938~5236~1.75^9.85~995~2121~0.71^9.84~152~622~0.21^9.83~598~598~0.20\"]}}}}}";
public static final String KLINEURL="{\"code\":0,\"msg\":\"\",\"data\":{\"sz002081\":{\"day\":[[\"2015-01-08\",\"19.12\",\"19.00\",\"19.25\",\"18.36\",\"185103.00\"],[\"2015-01-09\",\"18.72\",\"18.53\",\"19.30\",\"18.50\",\"148269.00\"],[\"2015-01-12\",\"18.54\",\"18.70\",\"18.99\",\"18.20\",\"121594.00\"],[\"2015-01-13\",\"18.60\",\"20.57\",\"20.57\",\"18.40\",\"356289.00\"],[\"2015-01-14\",\"20.29\",\"20.12\",\"21.20\",\"20.10\",\"224766.00\"],[\"2015-01-15\",\"20.11\",\"20.88\",\"21.18\",\"19.80\",\"169003.00\"],[\"2015-01-16\",\"20.78\",\"22.56\",\"22.97\",\"20.75\",\"358150.00\"],[\"2015-01-19\",\"21.78\",\"23.19\",\"24.30\",\"21.01\",\"372455.00\"],[\"2015-01-20\",\"23.50\",\"23.63\",\"24.42\",\"23.01\",\"329929.00\"],[\"2015-01-21\",\"23.60\",\"23.45\",\"24.20\",\"23.00\",\"230416.00\"],[\"2015-01-22\",\"23.33\",\"23.60\",\"23.95\",\"23.33\",\"140173.00\"],[\"2015-01-23\",\"23.65\",\"23.60\",\"24.30\",\"22.90\",\"150031.00\"],[\"2015-01-26\",\"23.60\",\"25.10\",\"25.50\",\"23.00\",\"213255.00\"],[\"2015-01-27\",\"25.08\",\"24.91\",\"25.19\",\"24.17\",\"130545.00\"],[\"2015-01-28\",\"24.55\",\"24.31\",\"24.98\",\"23.88\",\"112312.00\"],[\"2015-01-29\",\"24.00\",\"24.08\",\"24.50\",\"23.75\",\"100329.00\"],[\"2015-01-30\",\"24.08\",\"22.73\",\"24.29\",\"22.51\",\"200311.00\"],[\"2015-02-02\",\"22.22\",\"22.76\",\"22.89\",\"22.18\",\"136929.00\"],[\"2015-02-03\",\"22.87\",\"24.65\",\"24.95\",\"22.84\",\"202499.00\"],[\"2015-02-04\",\"24.90\",\"24.91\",\"25.37\",\"24.00\",\"171597.00\"],[\"2015-02-05\",\"25.29\",\"24.02\",\"25.36\",\"24.00\",\"162542.00\"],[\"2015-02-06\",\"23.98\",\"23.40\",\"24.50\",\"22.90\",\"95130.00\"],[\"2015-02-09\",\"23.25\",\"24.79\",\"25.11\",\"23.25\",\"193043.00\"],[\"2015-02-10\",\"24.95\",\"25.00\",\"25.08\",\"24.15\",\"100616.00\"],[\"2015-02-11\",\"24.72\",\"25.65\",\"26.77\",\"24.72\",\"250914.00\"],[\"2015-02-12\",\"25.50\",\"25.81\",\"26.35\",\"25.50\",\"126058.00\"],[\"2015-02-13\",\"25.85\",\"25.81\",\"26.30\",\"25.68\",\"91586.00\"],[\"2015-02-16\",\"25.82\",\"26.83\",\"27.19\",\"25.80\",\"230116.00\"],[\"2015-02-17\",\"27.11\",\"28.99\",\"29.51\",\"26.90\",\"145368.00\"],[\"2015-02-25\",\"29.65\",\"28.76\",\"31.00\",\"27.46\",\"238173.00\"],[\"2015-02-26\",\"28.40\",\"29.45\",\"30.50\",\"28.21\",\"169563.00\"],[\"2015-02-27\",\"28.60\",\"28.74\",\"29.20\",\"28.20\",\"176638.00\"],[\"2015-03-02\",\"28.86\",\"28.37\",\"29.04\",\"27.44\",\"206785.00\"],[\"2015-03-03\",\"28.22\",\"27.55\",\"28.41\",\"27.33\",\"184383.00\"],[\"2015-03-04\",\"27.55\",\"26.74\",\"27.55\",\"26.18\",\"304093.00\"],[\"2015-03-05\",\"26.57\",\"26.80\",\"27.16\",\"26.30\",\"176714.00\"],[\"2015-03-06\",\"26.81\",\"26.20\",\"26.95\",\"25.50\",\"175459.00\"],[\"2015-03-09\",\"25.80\",\"26.45\",\"26.48\",\"25.33\",\"159204.00\"],[\"2015-03-10\",\"26.50\",\"27.62\",\"27.74\",\"26.10\",\"221012.00\"],[\"2015-03-11\",\"27.46\",\"26.56\",\"27.66\",\"26.20\",\"173080.00\"],[\"2015-03-12\",\"26.66\",\"26.41\",\"27.09\",\"25.88\",\"117987.00\"],[\"2015-03-13\",\"26.21\",\"26.71\",\"26.82\",\"26.01\",\"120784.00\"],[\"2015-03-16\",\"26.68\",\"29.05\",\"29.06\",\"26.18\",\"332473.00\"],[\"2015-03-17\",\"29.08\",\"28.45\",\"29.15\",\"28.12\",\"193844.00\"],[\"2015-03-18\",\"28.28\",\"28.73\",\"28.79\",\"27.80\",\"218231.00\"],[\"2015-03-19\",\"28.54\",\"28.12\",\"28.54\",\"27.80\",\"202060.00\"],[\"2015-03-20\",\"28.05\",\"27.92\",\"28.06\",\"27.58\",\"195466.00\"],[\"2015-03-23\",\"28.36\",\"28.96\",\"29.30\",\"28.18\",\"280738.00\"],[\"2015-03-24\",\"28.97\",\"29.90\",\"30.29\",\"27.71\",\"377201.00\"],[\"2015-03-25\",\"30.24\",\"32.89\",\"32.89\",\"30.24\",\"492223.00\"],[\"2015-03-26\",\"33.00\",\"32.19\",\"34.20\",\"31.28\",\"515999.00\"],[\"2015-03-27\",\"32.85\",\"35.40\",\"35.41\",\"31.51\",\"359527.37\"],[\"2015-03-30\",\"34.90\",\"35.00\",\"36.68\",\"34.19\",\"241667.00\"],[\"2015-03-31\",\"35.50\",\"35.17\",\"36.89\",\"35.00\",\"222157.00\"],[\"2015-04-01\",\"36.24\",\"35.90\",\"36.31\",\"34.65\",\"208226.00\"],[\"2015-04-02\",\"35.60\",\"34.40\",\"35.80\",\"34.15\",\"357314.00\"],[\"2015-04-03\",\"34.00\",\"33.96\",\"34.37\",\"33.38\",\"235621.00\"],[\"2015-04-07\",\"33.90\",\"34.26\",\"34.50\",\"33.74\",\"216172.00\"],[\"2015-04-08\",\"34.10\",\"32.85\",\"34.28\",\"32.72\",\"267892.00\"],[\"2015-04-09\",\"32.85\",\"33.23\",\"33.50\",\"31.35\",\"279596.00\"],[\"2015-04-10\",\"33.16\",\"34.30\",\"34.39\",\"32.60\",\"247968.00\"],[\"2015-04-13\",\"34.10\",\"33.33\",\"34.65\",\"33.01\",\"302627.00\"],[\"2015-04-14\",\"33.33\",\"32.38\",\"33.33\",\"32.00\",\"237550.00\"],[\"2015-04-15\",\"32.27\",\"32.84\",\"33.50\",\"31.35\",\"237718.00\"],[\"2015-04-16\",\"32.55\",\"32.38\",\"33.58\",\"32.00\",\"204321.00\"],[\"2015-04-17\",\"32.20\",\"32.30\",\"33.15\",\"32.02\",\"191028.00\"],[\"2015-04-20\",\"32.19\",\"31.20\",\"33.00\",\"30.78\",\"222683.00\"],[\"2015-04-21\",\"31.10\",\"31.89\",\"32.50\",\"30.88\",\"221715.00\"],[\"2015-04-22\",\"32.07\",\"33.04\",\"33.30\",\"32.03\",\"217471.00\"],[\"2015-04-23\",\"33.12\",\"33.50\",\"34.48\",\"32.70\",\"293017.00\"],[\"2015-04-24\",\"33.20\",\"32.65\",\"33.98\",\"32.48\",\"169516.00\"],[\"2015-04-27\",\"32.70\",\"32.31\",\"33.59\",\"31.72\",\"209953.00\"],[\"2015-04-28\",\"31.96\",\"30.01\",\"31.98\",\"29.40\",\"372144.00\"],[\"2015-04-29\",\"30.00\",\"30.28\",\"30.51\",\"29.69\",\"193173.00\"],[\"2015-04-30\",\"30.50\",\"30.39\",\"31.13\",\"30.25\",\"200255.00\"],[\"2015-05-04\",\"30.39\",\"30.21\",\"30.81\",\"30.08\",\"128096.00\"],[\"2015-05-05\",\"30.11\",\"30.90\",\"31.26\",\"30.01\",\"221361.00\"],[\"2015-05-06\",\"31.39\",\"30.12\",\"31.49\",\"30.01\",\"196728.00\"],[\"2015-05-07\",\"30.06\",\"28.89\",\"30.50\",\"28.45\",\"176297.00\"],[\"2015-05-08\",\"28.63\",\"30.10\",\"30.36\",\"28.63\",\"201379.00\"],[\"2015-05-11\",\"30.15\",\"32.53\",\"32.85\",\"30.02\",\"300765.00\"],[\"2015-06-17\",\"35.67\",\"35.67\",\"35.67\",\"35.67\",\"31555.00\"],[\"2015-06-18\",\"36.00\",\"35.37\",\"38.98\",\"34.97\",\"704041.00\"],[\"2015-06-19\",\"34.60\",\"35.21\",\"37.50\",\"32.55\",\"390824.00\"],[\"2015-06-23\",\"35.90\",\"37.12\",\"37.34\",\"34.30\",\"506878.00\"],[\"2015-06-24\",\"37.69\",\"35.70\",\"37.90\",\"34.50\",\"484916.00\"],[\"2015-06-25\",\"35.15\",\"32.14\",\"35.17\",\"32.13\",\"448311.00\"],[\"2015-06-26\",\"30.00\",\"28.93\",\"31.12\",\"28.93\",\"285069.00\"],[\"2015-06-29\",\"29.50\",\"26.04\",\"30.19\",\"26.04\",\"512053.00\"],[\"2015-06-30\",\"26.04\",\"28.19\",\"28.64\",\"23.44\",\"598296.00\"],[\"2015-07-01\",\"27.79\",\"25.43\",\"29.50\",\"25.37\",\"532487.00\"],[\"2015-07-02\",\"26.45\",\"25.27\",\"27.25\",\"24.38\",\"589364.00\"],[\"2015-07-03\",\"25.22\",\"25.10\",\"27.49\",\"22.80\",\"464546.00\"],[\"2015-07-06\",\"27.61\",\"25.80\",\"27.61\",\"23.77\",\"604335.00\"],[\"2015-07-07\",\"25.00\",\"23.26\",\"25.58\",\"23.22\",\"500520.00\"],[\"2015-07-10\",\"25.59\",\"25.59\",\"25.59\",\"24.69\",\"294731.00\"],[\"2015-07-13\",\"27.90\",\"28.15\",\"28.15\",\"26.08\",\"490461.00\"],[\"2015-07-14\",\"28.20\",\"29.18\",\"30.50\",\"27.29\",\"508763.00\"],[\"2015-07-15\",\"28.13\",\"26.26\",\"28.60\",\"26.26\",\"309393.00\"],[\"2015-07-16\",\"26.26\",\"26.79\",\"27.50\",\"24.20\",\"259400.00\"],[\"2015-07-17\",\"26.99\",\"28.37\",\"28.88\",\"26.95\",\"236307.00\"],[\"2015-07-20\",\"28.58\",\"27.97\",\"29.18\",\"27.60\",\"256482.00\"],[\"2015-07-21\",\"27.58\",\"27.98\",\"28.53\",\"27.20\",\"194943.00\"],[\"2015-07-22\",\"27.55\",\"26.82\",\"28.00\",\"26.10\",\"368791.00\"],[\"2015-07-23\",\"26.85\",\"27.27\",\"27.52\",\"26.29\",\"328047.00\"],[\"2015-07-24\",\"27.17\",\"26.65\",\"27.23\",\"26.41\",\"285046.00\"],[\"2015-07-27\",\"27.00\",\"23.99\",\"27.10\",\"23.99\",\"305865.00\"],[\"2015-07-28\",\"23.00\",\"22.30\",\"23.85\",\"21.59\",\"565467.00\"],[\"2015-07-29\",\"22.90\",\"23.05\",\"23.80\",\"20.93\",\"366429.00\"],[\"2015-07-30\",\"22.58\",\"21.60\",\"22.99\",\"21.50\",\"265692.00\"],[\"2015-07-31\",\"21.16\",\"22.14\",\"22.19\",\"20.90\",\"302069.00\"],[\"2015-08-03\",\"22.00\",\"21.78\",\"22.00\",\"20.35\",\"295652.00\"],[\"2015-08-04\",\"21.70\",\"22.93\",\"23.10\",\"21.50\",\"218375.00\"],[\"2015-08-05\",\"22.68\",\"22.36\",\"23.50\",\"22.30\",\"176969.00\"],[\"2015-08-06\",\"21.77\",\"21.40\",\"22.35\",\"21.31\",\"182870.00\"],[\"2015-08-07\",\"21.71\",\"21.88\",\"22.09\",\"21.31\",\"203770.00\"],[\"2015-08-10\",\"22.20\",\"23.51\",\"23.74\",\"21.89\",\"423415.00\"],[\"2015-08-11\",\"23.38\",\"22.91\",\"23.69\",\"22.80\",\"390854.00\"],[\"2015-08-12\",\"22.50\",\"21.91\",\"22.80\",\"21.86\",\"351568.00\"],[\"2015-08-13\",\"21.70\",\"22.31\",\"22.32\",\"21.50\",\"250720.00\"],[\"2015-08-14\",\"21.71\",\"22.13\",\"22.56\",\"21.70\",\"380285.00\"],[\"2015-08-17\",\"21.89\",\"21.85\",\"22.13\",\"21.51\",\"382347.00\"],[\"2015-08-18\",\"21.87\",\"19.90\",\"22.28\",\"19.67\",\"418692.00\"],[\"2015-08-19\",\"19.20\",\"19.70\",\"19.88\",\"17.91\",\"867565.00\"],[\"2015-08-20\",\"19.29\",\"18.18\",\"19.38\",\"17.97\",\"713111.00\"],[\"2015-08-21\",\"17.60\",\"16.60\",\"18.00\",\"16.55\",\"654835.00\"],[\"2015-08-24\",\"15.79\",\"14.94\",\"15.79\",\"14.94\",\"570743.00\"],[\"2015-08-25\",\"13.75\",\"13.45\",\"14.80\",\"13.45\",\"676539.00\"],[\"2015-08-26\",\"13.45\",\"13.64\",\"14.68\",\"13.01\",\"684866.00\"],[\"2015-08-27\",\"14.15\",\"14.93\",\"14.96\",\"13.64\",\"589858.00\"],[\"2015-08-28\",\"15.32\",\"15.90\",\"15.99\",\"14.75\",\"694801.00\"],[\"2015-08-31\",\"15.45\",\"15.41\",\"15.65\",\"14.76\",\"461673.00\"],[\"2015-09-01\",\"15.05\",\"14.65\",\"15.11\",\"13.90\",\"479480.00\"],[\"2015-09-02\",\"13.69\",\"14.91\",\"15.10\",\"13.60\",\"498930.00\"],[\"2015-09-07\",\"14.92\",\"14.20\",\"15.60\",\"14.20\",\"402829.00\"],[\"2015-09-08\",\"14.01\",\"14.86\",\"15.00\",\"13.70\",\"268439.00\"],[\"2015-09-09\",\"15.10\",\"15.49\",\"15.65\",\"14.88\",\"478260.00\"],[\"2015-09-10\",\"15.20\",\"15.05\",\"15.43\",\"15.00\",\"280570.00\"],[\"2015-09-11\",\"14.99\",\"14.75\",\"15.22\",\"14.45\",\"246984.00\"],[\"2015-09-14\",\"14.85\",\"13.28\",\"14.86\",\"13.28\",\"394075.00\"],[\"2015-09-15\",\"13.00\",\"12.25\",\"13.19\",\"12.02\",\"302154.00\"],[\"2015-09-16\",\"12.45\",\"13.48\",\"13.48\",\"12.31\",\"281973.00\"],[\"2015-09-17\",\"13.41\",\"13.39\",\"14.10\",\"13.11\",\"374399.00\"],[\"2015-09-18\",\"13.45\",\"13.30\",\"13.57\",\"12.99\",\"266589.00\"],[\"2015-09-21\",\"13.00\",\"13.70\",\"13.80\",\"12.90\",\"258642.00\"],[\"2015-09-22\",\"13.71\",\"13.90\",\"14.23\",\"13.60\",\"317067.00\"],[\"2015-09-23\",\"13.75\",\"13.65\",\"13.84\",\"13.48\",\"251750.00\"],[\"2015-09-24\",\"13.76\",\"13.89\",\"14.14\",\"13.70\",\"213722.00\"],[\"2015-09-25\",\"13.80\",\"13.17\",\"13.86\",\"12.95\",\"209454.00\"],[\"2015-09-28\",\"13.20\",\"13.39\",\"13.47\",\"13.00\",\"131688.00\"],[\"2015-09-29\",\"13.10\",\"12.97\",\"13.17\",\"12.89\",\"147435.00\"],[\"2015-09-30\",\"12.99\",\"13.15\",\"13.24\",\"12.86\",\"148187.00\"],[\"2015-10-08\",\"13.81\",\"13.88\",\"14.05\",\"13.53\",\"380919.00\"],[\"2015-10-09\",\"13.88\",\"14.22\",\"14.43\",\"13.77\",\"324269.00\"],[\"2015-10-12\",\"14.44\",\"15.17\",\"15.35\",\"14.35\",\"483082.00\"],[\"2015-10-13\",\"14.95\",\"15.12\",\"15.19\",\"14.83\",\"303929.00\"],[\"2015-10-14\",\"15.00\",\"14.97\",\"15.29\",\"14.87\",\"284898.00\"],[\"2015-10-15\",\"14.84\",\"15.77\",\"15.85\",\"14.80\",\"389705.00\"],[\"2015-10-16\",\"15.93\",\"15.72\",\"16.18\",\"15.36\",\"370393.00\"],[\"2015-10-19\",\"15.73\",\"15.62\",\"16.10\",\"15.38\",\"379663.00\"],[\"2015-10-20\",\"15.61\",\"15.94\",\"16.03\",\"15.38\",\"433642.00\"],[\"2015-10-21\",\"15.95\",\"14.60\",\"16.05\",\"14.50\",\"486439.00\"],[\"2015-10-22\",\"14.63\",\"15.02\",\"15.17\",\"14.34\",\"373226.00\"],[\"2015-10-23\",\"15.09\",\"15.40\",\"15.60\",\"14.90\",\"412351.00\"],[\"2015-10-26\",\"15.66\",\"15.52\",\"15.83\",\"15.29\",\"437417.00\"],[\"2015-10-27\",\"15.40\",\"15.33\",\"15.45\",\"14.53\",\"339427.00\"],[\"2015-10-28\",\"15.26\",\"15.10\",\"15.80\",\"15.00\",\"348481.00\"],[\"2015-10-29\",\"15.21\",\"15.55\",\"15.66\",\"15.02\",\"283531.00\"],[\"2015-10-30\",\"15.55\",\"15.30\",\"15.56\",\"14.91\",\"356755.00\"],[\"2015-11-02\",\"14.93\",\"14.56\",\"15.23\",\"14.50\",\"329189.00\"],[\"2015-11-03\",\"14.55\",\"14.48\",\"14.76\",\"14.35\",\"207398.00\"],[\"2015-11-04\",\"14.60\",\"15.85\",\"15.90\",\"14.56\",\"492216.00\"],[\"2015-11-05\",\"15.88\",\"16.52\",\"17.04\",\"15.78\",\"868952.00\"],[\"2015-11-06\",\"16.65\",\"17.51\",\"17.77\",\"16.41\",\"650157.00\"],[\"2015-11-09\",\"17.40\",\"17.46\",\"17.80\",\"16.81\",\"545421.00\"],[\"2015-11-10\",\"17.27\",\"17.45\",\"17.79\",\"17.11\",\"407447.00\"],[\"2015-11-11\",\"17.30\",\"17.54\",\"17.64\",\"17.00\",\"427455.00\"],[\"2015-11-12\",\"17.66\",\"17.55\",\"18.20\",\"17.33\",\"490032.00\"],[\"2015-11-13\",\"17.21\",\"16.80\",\"17.33\",\"16.66\",\"400540.00\"],[\"2015-11-16\",\"16.28\",\"17.31\",\"17.38\",\"16.22\",\"284873.00\"],[\"2015-11-17\",\"17.51\",\"16.91\",\"17.90\",\"16.88\",\"408779.00\"],[\"2015-11-18\",\"16.91\",\"16.54\",\"17.08\",\"16.42\",\"304213.00\"],[\"2015-11-19\",\"16.59\",\"16.91\",\"16.94\",\"16.37\",\"279270.00\"],[\"2015-11-20\",\"16.92\",\"16.91\",\"17.08\",\"16.72\",\"270150.00\"],[\"2015-11-23\",\"16.89\",\"17.23\",\"17.70\",\"16.78\",\"416514.00\"],[\"2015-11-24\",\"17.32\",\"17.83\",\"17.85\",\"17.06\",\"350648.00\"],[\"2015-11-25\",\"17.88\",\"18.09\",\"18.10\",\"17.53\",\"391541.00\"],[\"2015-11-26\",\"18.17\",\"17.40\",\"18.35\",\"17.40\",\"436484.00\"],[\"2015-11-27\",\"17.29\",\"15.86\",\"17.36\",\"15.66\",\"418290.00\"],[\"2015-11-30\",\"16.02\",\"16.18\",\"16.25\",\"15.17\",\"353051.00\"],[\"2015-12-01\",\"16.15\",\"16.49\",\"16.78\",\"15.77\",\"355027.00\"],[\"2015-12-02\",\"16.30\",\"16.94\",\"17.06\",\"16.10\",\"422471.00\"],[\"2015-12-03\",\"17.00\",\"17.04\",\"17.45\",\"16.88\",\"397669.00\"],[\"2015-12-04\",\"16.80\",\"16.76\",\"16.98\",\"16.60\",\"254673.00\"],[\"2015-12-07\",\"16.83\",\"16.76\",\"16.92\",\"16.61\",\"192508.00\"],[\"2015-12-08\",\"16.72\",\"15.97\",\"16.72\",\"15.91\",\"281667.00\"],[\"2015-12-09\",\"15.85\",\"16.10\",\"16.15\",\"15.75\",\"162891.00\"],[\"2015-12-10\",\"16.12\",\"16.46\",\"16.88\",\"16.10\",\"319148.00\"],[\"2015-12-11\",\"16.44\",\"16.70\",\"16.84\",\"16.36\",\"217099.00\"],[\"2015-12-14\",\"16.55\",\"18.37\",\"18.37\",\"16.47\",\"488192.00\"],[\"2015-12-15\",\"18.40\",\"19.00\",\"19.68\",\"18.35\",\"782479.00\"],[\"2015-12-16\",\"19.12\",\"18.91\",\"19.48\",\"18.70\",\"411009.00\"],[\"2015-12-17\",\"18.93\",\"19.30\",\"19.48\",\"18.90\",\"434939.00\"],[\"2015-12-18\",\"19.38\",\"19.16\",\"19.69\",\"18.87\",\"411471.00\"],[\"2015-12-21\",\"19.00\",\"19.34\",\"19.87\",\"18.71\",\"411641.00\"],[\"2015-12-22\",\"19.40\",\"19.85\",\"19.89\",\"19.08\",\"343137.00\"],[\"2015-12-23\",\"19.98\",\"19.07\",\"19.99\",\"19.00\",\"315581.00\"],[\"2015-12-24\",\"18.95\",\"19.06\",\"19.35\",\"18.72\",\"237126.00\"],[\"2015-12-25\",\"19.11\",\"19.17\",\"19.38\",\"18.93\",\"163681.00\"],[\"2015-12-28\",\"19.17\",\"18.45\",\"19.35\",\"18.45\",\"229227.00\"],[\"2015-12-29\",\"18.55\",\"19.18\",\"19.35\",\"18.22\",\"212629.00\"],[\"2015-12-30\",\"19.20\",\"19.14\",\"19.35\",\"18.83\",\"207808.00\"],[\"2015-12-31\",\"19.16\",\"18.68\",\"19.20\",\"18.60\",\"162437.00\"],[\"2016-01-04\",\"18.81\",\"17.05\",\"18.81\",\"16.90\",\"180120.00\"],[\"2016-01-05\",\"16.20\",\"16.75\",\"18.03\",\"15.80\",\"272718.00\"],[\"2016-01-06\",\"16.90\",\"16.94\",\"17.08\",\"16.43\",\"198058.00\"],[\"2016-01-07\",\"16.61\",\"15.27\",\"16.74\",\"15.25\",\"63479.00\"],[\"2016-01-08\",\"15.60\",\"15.26\",\"15.94\",\"14.63\",\"289668.00\"],[\"2016-01-11\",\"14.90\",\"13.97\",\"15.30\",\"13.91\",\"208439.00\"],[\"2016-01-12\",\"14.05\",\"14.14\",\"14.28\",\"13.79\",\"198535.00\"],[\"2016-01-13\",\"14.25\",\"13.78\",\"14.65\",\"13.71\",\"183315.00\"],[\"2016-01-14\",\"13.35\",\"14.28\",\"14.35\",\"13.27\",\"194797.00\"],[\"2016-01-15\",\"14.26\",\"13.84\",\"14.54\",\"13.67\",\"211021.00\"],[\"2016-01-18\",\"13.48\",\"13.97\",\"14.28\",\"13.37\",\"129268.00\"],[\"2016-01-19\",\"13.96\",\"14.56\",\"14.66\",\"13.80\",\"223909.00\"],[\"2016-01-20\",\"14.48\",\"14.30\",\"14.60\",\"14.21\",\"142733.00\"],[\"2016-01-21\",\"14.06\",\"13.60\",\"14.40\",\"13.60\",\"129618.00\"],[\"2016-01-22\",\"13.80\",\"13.59\",\"13.89\",\"13.20\",\"189615.00\"],[\"2016-01-25\",\"13.74\",\"13.82\",\"13.95\",\"13.61\",\"125423.00\"],[\"2016-01-26\",\"13.66\",\"12.53\",\"13.77\",\"12.50\",\"168538.00\"],[\"2016-01-27\",\"12.56\",\"12.37\",\"12.70\",\"11.44\",\"347611.00\"],[\"2016-01-28\",\"12.03\",\"11.84\",\"12.47\",\"11.71\",\"173067.00\"],[\"2016-01-29\",\"11.90\",\"12.36\",\"12.46\",\"11.86\",\"160726.00\"],[\"2016-02-01\",\"12.15\",\"12.02\",\"12.36\",\"11.83\",\"122485.00\"],[\"2016-02-02\",\"12.02\",\"12.52\",\"12.56\",\"12.02\",\"139139.00\"],[\"2016-02-03\",\"12.50\",\"12.53\",\"12.62\",\"12.31\",\"116326.00\"],[\"2016-02-04\",\"12.74\",\"12.79\",\"13.00\",\"12.64\",\"169624.00\"],[\"2016-02-05\",\"12.83\",\"12.67\",\"12.90\",\"12.66\",\"93049.00\"],[\"2016-02-15\",\"12.10\",\"12.30\",\"12.47\",\"12.10\",\"107412.00\"],[\"2016-02-16\",\"12.45\",\"12.85\",\"12.87\",\"12.43\",\"181297.00\"],[\"2016-02-17\",\"12.96\",\"13.30\",\"13.38\",\"12.96\",\"206638.00\"],[\"2016-02-18\",\"13.42\",\"13.95\",\"14.22\",\"13.27\",\"350170.00\"],[\"2016-02-19\",\"14.00\",\"13.70\",\"14.00\",\"13.60\",\"261421.00\"],[\"2016-02-22\",\"13.81\",\"14.00\",\"14.33\",\"13.80\",\"298902.00\"],[\"2016-02-23\",\"14.00\",\"13.81\",\"14.01\",\"13.57\",\"141709.00\"],[\"2016-02-24\",\"13.65\",\"13.82\",\"13.95\",\"13.41\",\"138151.00\"],[\"2016-02-25\",\"13.80\",\"12.45\",\"13.80\",\"12.44\",\"220304.00\"],[\"2016-02-26\",\"12.61\",\"12.63\",\"12.85\",\"12.44\",\"157598.00\"],[\"2016-02-29\",\"12.63\",\"12.20\",\"12.63\",\"11.82\",\"167929.00\"],[\"2016-03-01\",\"12.23\",\"12.76\",\"12.90\",\"12.07\",\"246822.00\"],[\"2016-03-02\",\"12.72\",\"14.04\",\"14.04\",\"12.72\",\"287224.00\"],[\"2016-03-03\",\"14.90\",\"14.95\",\"15.44\",\"14.76\",\"870902.00\"],[\"2016-03-04\",\"15.09\",\"14.69\",\"15.58\",\"14.33\",\"699604.00\"],[\"2016-03-07\",\"14.76\",\"14.71\",\"15.50\",\"14.50\",\"512004.00\"],[\"2016-03-08\",\"14.51\",\"14.68\",\"14.84\",\"14.05\",\"331510.00\"],[\"2016-03-09\",\"14.15\",\"14.15\",\"14.45\",\"14.01\",\"231897.00\"],[\"2016-03-10\",\"14.23\",\"13.70\",\"14.33\",\"13.68\",\"193441.00\"],[\"2016-03-11\",\"13.42\",\"13.47\",\"13.70\",\"13.10\",\"174475.00\"],[\"2016-03-14\",\"13.56\",\"14.54\",\"14.82\",\"13.56\",\"399240.00\"],[\"2016-03-15\",\"14.39\",\"14.23\",\"14.74\",\"14.10\",\"305928.00\"],[\"2016-03-16\",\"14.32\",\"14.11\",\"14.40\",\"14.00\",\"143571.00\"],[\"2016-03-17\",\"14.17\",\"14.91\",\"15.00\",\"14.17\",\"269213.00\"],[\"2016-03-18\",\"14.92\",\"15.50\",\"15.62\",\"14.85\",\"375522.00\"],[\"2016-03-21\",\"15.60\",\"15.65\",\"16.21\",\"15.58\",\"317073.00\"],[\"2016-03-22\",\"15.40\",\"15.79\",\"16.40\",\"15.31\",\"287952.00\"],[\"2016-03-23\",\"15.91\",\"15.92\",\"16.03\",\"15.60\",\"164341.00\"],[\"2016-03-24\",\"15.60\",\"15.55\",\"16.08\",\"15.50\",\"202585.00\"],[\"2016-03-25\",\"15.53\",\"15.74\",\"15.88\",\"15.45\",\"111713.00\"],[\"2016-03-28\",\"15.74\",\"15.70\",\"16.25\",\"15.65\",\"194782.00\"],[\"2016-03-29\",\"15.75\",\"16.30\",\"16.38\",\"15.53\",\"301944.00\"],[\"2016-03-30\",\"16.29\",\"17.57\",\"17.93\",\"16.11\",\"433027.00\"],[\"2016-03-31\",\"17.40\",\"17.08\",\"17.55\",\"17.04\",\"246606.00\"],[\"2016-04-01\",\"17.09\",\"17.55\",\"17.60\",\"16.95\",\"216661.00\"],[\"2016-04-05\",\"17.46\",\"17.55\",\"17.96\",\"17.27\",\"218921.00\"],[\"2016-04-06\",\"17.40\",\"17.20\",\"17.57\",\"16.82\",\"217841.00\"],[\"2016-04-07\",\"17.21\",\"16.91\",\"17.38\",\"16.91\",\"149523.00\"],[\"2016-04-08\",\"16.59\",\"16.45\",\"16.80\",\"16.33\",\"137207.00\"],[\"2016-04-11\",\"16.69\",\"17.55\",\"17.97\",\"16.67\",\"217821.00\"],[\"2016-04-12\",\"17.54\",\"17.21\",\"17.96\",\"17.14\",\"155616.00\"],[\"2016-04-13\",\"17.19\",\"17.31\",\"17.91\",\"17.17\",\"196837.00\"],[\"2016-04-14\",\"17.20\",\"17.22\",\"17.50\",\"16.95\",\"121346.00\"],[\"2016-04-15\",\"17.25\",\"17.13\",\"17.31\",\"16.96\",\"80561.00\"],[\"2016-04-18\",\"17.12\",\"16.35\",\"17.12\",\"16.30\",\"157622.00\"],[\"2016-04-19\",\"16.52\",\"16.38\",\"16.70\",\"16.19\",\"86750.00\"],[\"2016-04-20\",\"16.43\",\"15.67\",\"16.55\",\"15.27\",\"182457.00\"],[\"2016-04-21\",\"15.56\",\"15.45\",\"15.86\",\"15.18\",\"67845.00\"],[\"2016-04-22\",\"15.42\",\"15.70\",\"15.78\",\"15.12\",\"159974.00\"],[\"2016-04-25\",\"15.77\",\"15.55\",\"15.98\",\"15.40\",\"150715.00\"],[\"2016-04-26\",\"15.60\",\"15.70\",\"15.74\",\"15.46\",\"89126.00\"],[\"2016-04-27\",\"15.71\",\"15.49\",\"15.83\",\"15.40\",\"108200.00\"],[\"2016-04-28\",\"15.45\",\"15.24\",\"15.56\",\"14.99\",\"144103.00\"],[\"2016-04-29\",\"15.18\",\"15.30\",\"15.43\",\"15.07\",\"76883.00\"],[\"2016-05-03\",\"15.28\",\"15.91\",\"16.06\",\"15.18\",\"124344.00\"],[\"2016-05-04\",\"15.78\",\"15.69\",\"16.00\",\"15.56\",\"150615.00\"],[\"2016-05-05\",\"15.40\",\"15.74\",\"15.79\",\"15.40\",\"95713.00\"],[\"2016-05-06\",\"15.78\",\"15.11\",\"15.87\",\"15.10\",\"139890.00\"],[\"2016-05-09\",\"14.91\",\"14.33\",\"15.00\",\"14.31\",\"161207.00\"],[\"2016-05-10\",\"14.34\",\"14.30\",\"14.52\",\"14.20\",\"72236.00\"],[\"2016-05-11\",\"14.45\",\"14.30\",\"14.47\",\"14.21\",\"82662.00\"],[\"2016-05-12\",\"14.14\",\"14.20\",\"14.35\",\"13.97\",\"94724.00\"],[\"2016-05-13\",\"14.21\",\"14.21\",\"14.48\",\"14.10\",\"73611.00\"],[\"2016-05-16\",\"14.22\",\"14.37\",\"14.37\",\"14.00\",\"82875.00\"],[\"2016-05-17\",\"14.40\",\"14.40\",\"14.62\",\"14.27\",\"88418.00\"],[\"2016-05-18\",\"14.30\",\"14.09\",\"14.30\",\"13.64\",\"134740.00\"],[\"2016-05-19\",\"14.05\",\"13.99\",\"14.22\",\"13.91\",\"68580.00\"],[\"2016-05-20\",\"13.86\",\"14.08\",\"14.10\",\"13.78\",\"66820.00\"],[\"2016-05-23\",\"14.08\",\"14.14\",\"14.25\",\"14.00\",\"79913.00\"],[\"2016-05-24\",\"14.15\",\"14.09\",\"14.25\",\"14.04\",\"92120.00\"],[\"2016-05-25\",\"14.20\",\"14.08\",\"14.29\",\"13.98\",\"74598.00\"],[\"2016-05-26\",\"14.08\",\"14.16\",\"14.18\",\"13.67\",\"79067.00\"],[\"2016-05-27\",\"14.09\",\"14.02\",\"14.19\",\"13.98\",\"61079.00\"],[\"2016-05-30\",\"14.12\",\"14.60\",\"14.70\",\"14.12\",\"177216.00\"],[\"2016-05-31\",\"14.69\",\"15.16\",\"15.26\",\"14.55\",\"261970.00\"],[\"2016-06-01\",\"15.10\",\"15.24\",\"15.57\",\"15.01\",\"229556.00\"],[\"2016-06-02\",\"15.25\",\"15.80\",\"15.97\",\"15.25\",\"286928.00\"],[\"2016-06-03\",\"10.40\",\"10.21\",\"10.63\",\"10.16\",\"330628.00\",{\"nd\":\"2015\",\"fh_sh\":\"2\",\"djr\":\"2016-06-02\",\"cqr\":\"2016-06-03\",\"FHcontent\":\"10\\u6d3e2\\u5143\\u90015\\u80a1\"}],[\"2016-06-06\",\"10.22\",\"10.23\",\"10.58\",\"10.08\",\"210343.00\"],[\"2016-06-07\",\"10.24\",\"10.22\",\"10.32\",\"10.10\",\"163159.00\"],[\"2016-06-08\",\"10.19\",\"10.04\",\"10.21\",\"9.91\",\"254633.00\"],[\"2016-06-13\",\"10.04\",\"9.86\",\"10.26\",\"9.80\",\"299741.00\"]],\"qt\":{\"sz002081\":[\"51\",\"\\u91d1 \\u87b3 \\u8782\",\"002081\",\"9.86\",\"10.04\",\"10.04\",\"299741\",\"143765\",\"155976\",\"9.85\",\"1280\",\"9.84\",\"226\",\"9.83\",\"164\",\"9.82\",\"680\",\"9.81\",\"697\",\"9.86\",\"430\",\"9.87\",\"321\",\"9.88\",\"701\",\"9.89\",\"607\",\"9.90\",\"281\",\"15:00:01\\/9.86\\/3535\\/S\\/3485510\\/33300|14:57:01\\/9.86\\/101\\/B\\/99559\\/32990|14:56:58\\/9.86\\/18\\/B\\/17743\\/32981|14:56:52\\/9.86\\/73\\/S\\/72481\\/32970|14:56:49\\/9.86\\/38\\/S\\/36980\\/32964|14:56:46\\/9.87\\/64\\/B\\/63108\\/32959\",\"20160613150137\",\"-0.18\",\"-1.79\",\"10.26\",\"9.80\",\"9.86\\/296206\\/298840720\",\"299741\",\"30233\",\"1.19\",\"15.99\",\"\",\"10.26\",\"9.80\",\"4.58\",\"248.32\",\"260.63\",\"1.91\",\"11.04\",\"9.04\",\"\"],\"market\":[\"2016-06-13 16:11:01|HK_close_\\u5df2\\u6536\\u76d8|SH_close_\\u5df2\\u6536\\u76d8|SZ_close_\\u5df2\\u6536\\u76d8|US_close_\\u672a\\u5f00\\u76d8|SQ_close_\\u5df2\\u4f11\\u5e02|DS_close_\\u5df2\\u4f11\\u5e02|ZS_close_\\u5df2\\u4f11\\u5e02\"],\"zjlx\":[\"sz002081\",\"13808.61\",\"16272.41\",\"-2463.80\",\"-8.15\",\"16424.02\",\"13960.23\",\"2463.79\",\"8.15\",\"30232.63\",\"53095.67\",\"61220.51\",\"\\u91d1 \\u87b3 \\u8782\",\"20160613\",\"20160608^8921.92^12669.59\",\"20160607^7605.27^7386.58\",\"20160606^7653.72^9006.39\",\"20160603^15106.15^15885.54\"]},\"mx_price\":{\"mx\":[],\"price\":[]},\"prec\":\"19.15\",\"version\":\"4\"}}}";
}
``` | /content/code_sandbox/app/src/main/java/com/example/yanjiang/stockchart/api/ConstantTest.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 13,308 |
```java
package com.github.mikephil.charting.jobs;
import android.animation.ValueAnimator;
import android.view.View;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* Created by Philipp Jahoda on 19/02/16.
*/
public class AnimatedMoveViewJob extends AnimatedViewPortJob {
public AnimatedMoveViewJob(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v, float xOrigin, float yOrigin, long duration) {
super(viewPortHandler, xValue, yValue, trans, v, xOrigin, yOrigin, duration);
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
pts[0] = xOrigin + (xValue - xOrigin) * phase;
pts[1] = yOrigin + (yValue - yOrigin) * phase;
mTrans.pointValuesToPixel(pts);
mViewPortHandler.centerViewPort(pts, view);
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/jobs/AnimatedMoveViewJob.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 215 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* Superclass of all render classes for the different data types (line, bar, ...).
*
* @author Philipp Jahoda
*/
public abstract class DataRenderer extends Renderer {
/**
* the animator object used to perform animations on the chart data
*/
protected ChartAnimator mAnimator;
/**
* main paint object used for rendering
*/
protected Paint mRenderPaint;
/**
* paint used for highlighting values
*/
protected Paint mHighlightPaint;
protected Paint mDrawPaint;
/**
* paint object for drawing values (text representing values of chart
* entries)
*/
protected Paint mValuePaint;
public DataRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
super(viewPortHandler);
this.mAnimator = animator;
mRenderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mRenderPaint.setStyle(Style.FILL);
mDrawPaint = new Paint(Paint.DITHER_FLAG);
mValuePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mValuePaint.setColor(Color.rgb(63, 63, 63));
mValuePaint.setTextAlign(Align.CENTER);
mValuePaint.setTextSize(Utils.convertDpToPixel(9f));
mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mHighlightPaint.setStyle(Style.STROKE);
mHighlightPaint.setStrokeWidth(2f);
mHighlightPaint.setColor(Color.rgb(255, 187, 115));
}
/**
* Returns the Paint object this renderer uses for drawing the values
* (value-text).
*
* @return
*/
public Paint getPaintValues() {
return mValuePaint;
}
/**
* Returns the Paint object this renderer uses for drawing highlight
* indicators.
*
* @return
*/
public Paint getPaintHighlight() {
return mHighlightPaint;
}
/**
* Returns the Paint object used for rendering.
*
* @return
*/
public Paint getPaintRender() {
return mRenderPaint;
}
/**
* Applies the required styling (provided by the DataSet) to the value-paint
* object.
*
* @param set
*/
protected void applyValueTextStyle(IDataSet set) {
mValuePaint.setTypeface(set.getValueTypeface());
mValuePaint.setTextSize(set.getValueTextSize());
}
/**
* Initializes the buffers used for rendering with a new size. Since this
* method performs memory allocations, it should only be called if
* necessary.
*/
public abstract void initBuffers();
/**
* Draws the actual data in form of lines, bars, ... depending on Renderer subclass.
*
* @param c
*/
public abstract void drawData(Canvas c);
/**
* Loops over all Entrys and draws their values.
*
* @param c
*/
public abstract void drawValues(Canvas c);
/**
* Draws the value of the given entry by using the provided ValueFormatter.
*
* @param c canvas
* @param formatter formatter for custom value-formatting
* @param value the value to be drawn
* @param entry the entry the value belongs to
* @param dataSetIndex the index of the DataSet the drawn Entry belongs to
* @param x position
* @param y position
* @param color
*/
public void drawValue(Canvas c, ValueFormatter formatter, float value, Entry entry, int dataSetIndex, float x, float y, int color) {
mValuePaint.setColor(color);
c.drawText(formatter.getFormattedValue(value, entry, dataSetIndex, mViewPortHandler), x, y, mValuePaint);
}
/**
* Draws any kind of additional information (e.g. line-circles).
*
* @param c
*/
public abstract void drawExtras(Canvas c);
/**
* Draws all highlight indicators for the values that are currently highlighted.
*
* @param c
* @param indices the highlighted values
*/
public abstract void drawHighlighted(Canvas c, Highlight[] indices);
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/DataRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 1,010 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.PointF;
import com.github.mikephil.charting.charts.RadarChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
public class XAxisRendererRadarChart extends XAxisRenderer {
private RadarChart mChart;
public XAxisRendererRadarChart(ViewPortHandler viewPortHandler, XAxis xAxis, RadarChart chart) {
super(viewPortHandler, xAxis, null);
mChart = chart;
}
@Override
public void renderAxisLabels(Canvas c) {
if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled())
return;
final float labelRotationAngleDegrees = mXAxis.getLabelRotationAngle();
final PointF drawLabelAnchor = new PointF(0.5f, 0.0f);
mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
mAxisLabelPaint.setColor(mXAxis.getTextColor());
float sliceangle = mChart.getSliceAngle();
// calculate the factor that is needed for transforming the value to
// pixels
float factor = mChart.getFactor();
PointF center = mChart.getCenterOffsets();
int mod = mXAxis.mAxisLabelModulus;
for (int i = 0; i < mXAxis.getValues().size(); i += mod) {
String label = mXAxis.getValues().get(i);
float angle = (sliceangle * i + mChart.getRotationAngle()) % 360f;
PointF p = Utils.getPosition(center, mChart.getYRange() * factor
+ mXAxis.mLabelRotatedWidth / 2f, angle);
drawLabel(c, label, i, p.x, p.y - mXAxis.mLabelRotatedHeight / 2.f,
drawLabelAnchor, labelRotationAngleDegrees);
}
}
/**
* XAxis LimitLines on RadarChart not yet supported.
*
* @param c
*/
@Override
public void renderLimitLines(Canvas c) {
// this space intentionally left blank
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/XAxisRendererRadarChart.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 486 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Path;
import android.graphics.PointF;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.LimitLine;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.XAxis.XAxisPosition;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.utils.FSize;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.List;
public class XAxisRendererHorizontalBarChart extends XAxisRendererBarChart {
public XAxisRendererHorizontalBarChart(ViewPortHandler viewPortHandler, XAxis xAxis,
Transformer trans, BarChart chart) {
super(viewPortHandler, xAxis, trans, chart);
}
@Override
public void computeAxis(float xValAverageLength, List<String> xValues) {
mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
mXAxis.setValues(xValues);
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);
}
@Override
public void renderAxisLabels(Canvas c) {
if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled())
return;
float xoffset = mXAxis.getXOffset();
mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
mAxisLabelPaint.setColor(mXAxis.getTextColor());
if (mXAxis.getPosition() == XAxisPosition.TOP) {
drawLabels(c, mViewPortHandler.contentRight() + xoffset,
new PointF(0.0f, 0.5f));
} else if (mXAxis.getPosition() == XAxisPosition.TOP_INSIDE) {
drawLabels(c, mViewPortHandler.contentRight() - xoffset,
new PointF(1.0f, 0.5f));
} else if (mXAxis.getPosition() == XAxisPosition.BOTTOM) {
drawLabels(c, mViewPortHandler.contentLeft() - xoffset,
new PointF(1.0f, 0.5f));
} else if (mXAxis.getPosition() == XAxisPosition.BOTTOM_INSIDE) {
drawLabels(c, mViewPortHandler.contentLeft() + xoffset,
new PointF(0.0f, 0.5f));
} else { // BOTH SIDED
drawLabels(c, mViewPortHandler.contentRight() + xoffset,
new PointF(0.0f, 0.5f));
drawLabels(c, mViewPortHandler.contentLeft() - xoffset,
new PointF(1.0f, 0.5f));
}
}
/**
* draws the x-labels on the specified y-position
*
* @param pos
*/
@Override
protected void drawLabels(Canvas c, float pos, PointF anchor) {
final float labelRotationAngleDegrees = mXAxis.getLabelRotationAngle();
// pre allocate to save performance (dont allocate in loop)
float[] position = new float[] {
0f, 0f
};
BarData bd = mChart.getData();
int step = bd.getDataSetCount();
for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) {
position[1] = i * step + i * bd.getGroupSpace()
+ bd.getGroupSpace() / 2f;
// consider groups (center label for each group)
if (step > 1) {
position[1] += ((float) step - 1f) / 2f;
}
mTrans.pointValuesToPixel(position);
if (mViewPortHandler.isInBoundsY(position[1])) {
String label = mXAxis.getValues().get(i);
drawLabel(c, label, i, pos, position[1], anchor, labelRotationAngleDegrees);
}
}
}
@Override
public void renderGridLines(Canvas c) {
if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled())
return;
float[] position = new float[] {
0f, 0f
};
mGridPaint.setColor(mXAxis.getGridColor());
mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth());
BarData bd = mChart.getData();
// take into consideration that multiple DataSets increase mDeltaX
int step = bd.getDataSetCount();
for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) {
position[1] = i * step + i * bd.getGroupSpace() - 0.5f;
mTrans.pointValuesToPixel(position);
if (mViewPortHandler.isInBoundsY(position[1])) {
c.drawLine(mViewPortHandler.contentLeft(), position[1],
mViewPortHandler.contentRight(), position[1], mGridPaint);
}
}
}
@Override
public void renderAxisLine(Canvas c) {
if (!mXAxis.isDrawAxisLineEnabled() || !mXAxis.isEnabled())
return;
mAxisLinePaint.setColor(mXAxis.getAxisLineColor());
mAxisLinePaint.setStrokeWidth(mXAxis.getAxisLineWidth());
if (mXAxis.getPosition() == XAxisPosition.TOP
|| mXAxis.getPosition() == XAxisPosition.TOP_INSIDE
|| mXAxis.getPosition() == XAxisPosition.BOTH_SIDED) {
c.drawLine(mViewPortHandler.contentRight(),
mViewPortHandler.contentTop(), mViewPortHandler.contentRight(),
mViewPortHandler.contentBottom(), mAxisLinePaint);
}
if (mXAxis.getPosition() == XAxisPosition.BOTTOM
|| mXAxis.getPosition() == XAxisPosition.BOTTOM_INSIDE
|| mXAxis.getPosition() == XAxisPosition.BOTH_SIDED) {
c.drawLine(mViewPortHandler.contentLeft(),
mViewPortHandler.contentTop(), mViewPortHandler.contentLeft(),
mViewPortHandler.contentBottom(), mAxisLinePaint);
}
}
/**
* 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 = new float[2];
Path limitLinePath = new Path();
for (int i = 0; i < limitLines.size(); i++) {
LimitLine l = limitLines.get(i);
if(!l.isEnabled())
continue;
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 && !"".equals(label)) {
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);
}
}
}
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/XAxisRendererHorizontalBarChart.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 2,194 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.PointF;
import com.github.mikephil.charting.charts.RadarChart;
import com.github.mikephil.charting.components.LimitLine;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.List;
public class YAxisRendererRadarChart extends YAxisRenderer {
private RadarChart mChart;
public YAxisRendererRadarChart(ViewPortHandler viewPortHandler, YAxis yAxis, RadarChart chart) {
super(viewPortHandler, yAxis, null);
this.mChart = chart;
}
@Override
public void computeAxis(float yMin, float yMax) {
computeAxisValues(yMin, yMax);
}
@Override
protected void computeAxisValues(float min, float max) {
float yMin = min;
float yMax = max;
int labelCount = mYAxis.getLabelCount();
double range = Math.abs(yMax - yMin);
if (labelCount == 0 || range <= 0) {
mYAxis.mEntries = new float[]{};
mYAxis.mEntryCount = 0;
return;
}
double rawInterval = range / labelCount;
double interval = Utils.roundToNextSignificant(rawInterval);
double intervalMagnitude = Math.pow(10, (int) Math.log10(interval));
int intervalSigDigit = (int) (interval / intervalMagnitude);
if (intervalSigDigit > 5) {
// Use one order of magnitude higher, to avoid intervals like 0.9 or
// 90
interval = Math.floor(10 * intervalMagnitude);
}
// force label count
if (mYAxis.isForceLabelsEnabled()) {
float step = (float) range / (float) (labelCount - 1);
mYAxis.mEntryCount = labelCount;
if (mYAxis.mEntries.length < labelCount) {
// Ensure stops contains at least numStops elements.
mYAxis.mEntries = new float[labelCount];
}
float v = min;
for (int i = 0; i < labelCount; i++) {
mYAxis.mEntries[i] = v;
v += step;
}
// no forced count
} else {
// if the labels should only show min and max
if (mYAxis.isShowOnlyMinMaxEnabled()) {
mYAxis.mEntryCount = 2;
mYAxis.mEntries = new float[2];
mYAxis.mEntries[0] = yMin;
mYAxis.mEntries[1] = yMax;
} else {
final double rawCount = yMin / interval;
double first = rawCount < 0.0 ? Math.floor(rawCount) * interval : Math.ceil(rawCount) * interval;
if (first == 0.0) // Fix for IEEE negative zero case (Where value == -0.0, and 0.0 == -0.0)
first = 0.0;
double last = Utils.nextUp(Math.floor(yMax / interval) * interval);
double f;
int i;
int n = 0;
for (f = first; f <= last; f += interval) {
++n;
}
if (!mYAxis.isAxisMaxCustom())
n += 1;
mYAxis.mEntryCount = n;
if (mYAxis.mEntries.length < n) {
// Ensure stops contains at least numStops elements.
mYAxis.mEntries = new float[n];
}
for (f = first, i = 0; i < n; f += interval, ++i) {
mYAxis.mEntries[i] = (float) f;
}
}
}
if (interval < 1) {
mYAxis.mDecimals = (int) Math.ceil(-Math.log10(interval));
} else {
mYAxis.mDecimals = 0;
}
if (mYAxis.mEntries[0] < yMin) {
// If startAtZero is disabled, and the first label is lower that the axis minimum,
// Then adjust the axis minimum
mYAxis.mAxisMinimum = mYAxis.mEntries[0];
}
mYAxis.mAxisMaximum = mYAxis.mEntries[mYAxis.mEntryCount - 1];
mYAxis.mAxisRange = Math.abs(mYAxis.mAxisMaximum - mYAxis.mAxisMinimum);
}
@Override
public void renderAxisLabels(Canvas c) {
if (!mYAxis.isEnabled() || !mYAxis.isDrawLabelsEnabled())
return;
mAxisLabelPaint.setTypeface(mYAxis.getTypeface());
mAxisLabelPaint.setTextSize(mYAxis.getTextSize());
mAxisLabelPaint.setColor(mYAxis.getTextColor());
PointF center = mChart.getCenterOffsets();
float factor = mChart.getFactor();
int labelCount = mYAxis.mEntryCount;
for (int j = 0; j < labelCount; j++) {
if (j == labelCount - 1 && mYAxis.isDrawTopYLabelEntryEnabled() == false)
break;
float r = (mYAxis.mEntries[j] - mYAxis.mAxisMinimum) * factor;
PointF p = Utils.getPosition(center, r, mChart.getRotationAngle());
String label = mYAxis.getFormattedLabel(j);
c.drawText(label, p.x + 10, p.y, mAxisLabelPaint);
}
}
@Override
public void renderLimitLines(Canvas c) {
List<LimitLine> limitLines = mYAxis.getLimitLines();
if (limitLines == null)
return;
float sliceangle = mChart.getSliceAngle();
// calculate the factor that is needed for transforming the value to
// pixels
float factor = mChart.getFactor();
PointF center = mChart.getCenterOffsets();
for (int i = 0; i < limitLines.size(); i++) {
LimitLine l = limitLines.get(i);
if (!l.isEnabled())
continue;
mLimitLinePaint.setColor(l.getLineColor());
mLimitLinePaint.setPathEffect(l.getDashPathEffect());
mLimitLinePaint.setStrokeWidth(l.getLineWidth());
float r = (l.getLimit() - mChart.getYChartMin()) * factor;
Path limitPath = new Path();
for (int j = 0; j < mChart.getData().getXValCount(); j++) {
PointF p = Utils.getPosition(center, r, sliceangle * j + mChart.getRotationAngle());
if (j == 0)
limitPath.moveTo(p.x, p.y);
else
limitPath.lineTo(p.x, p.y);
}
limitPath.close();
c.drawPath(limitPath, mLimitLinePaint);
}
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/YAxisRendererRadarChart.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 1,516 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Paint.Style;
import android.graphics.Path;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.buffer.ScatterBuffer;
import com.github.mikephil.charting.charts.ScatterChart.ScatterShape;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.ScatterData;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.ScatterDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.List;
public class ScatterChartRenderer extends LineScatterCandleRadarRenderer {
protected ScatterDataProvider mChart;
protected ScatterBuffer[] mScatterBuffers;
public ScatterChartRenderer(ScatterDataProvider chart, ChartAnimator animator,
ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
mChart = chart;
}
@Override
public void initBuffers() {
ScatterData scatterData = mChart.getScatterData();
mScatterBuffers = new ScatterBuffer[scatterData.getDataSetCount()];
for (int i = 0; i < mScatterBuffers.length; i++) {
IScatterDataSet set = scatterData.getDataSetByIndex(i);
mScatterBuffers[i] = new ScatterBuffer(set.getEntryCount() * 2);
}
}
@Override
public void drawData(Canvas c) {
ScatterData scatterData = mChart.getScatterData();
for (IScatterDataSet set : scatterData.getDataSets()) {
if (set.isVisible())
drawDataSet(c, set);
}
}
protected void drawDataSet(Canvas c, IScatterDataSet dataSet) {
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
float phaseY = mAnimator.getPhaseY();
final float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize());
final float shapeHalf = shapeSize / 2f;
final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
final int shapeHoleColor = dataSet.getScatterShapeHoleColor();
final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;
final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f;
ScatterShape shape = dataSet.getScatterShape();
ScatterBuffer buffer = mScatterBuffers[mChart.getScatterData().getIndexOfDataSet(
dataSet)];
buffer.setPhases(phaseX, phaseY);
buffer.feed(dataSet);
trans.pointValuesToPixel(buffer.buffer);
switch (shape) {
case SQUARE:
for (int i = 0; i < buffer.size(); i += 2) {
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
break;
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
continue;
mRenderPaint.setColor(dataSet.getColor(i / 2));
if (shapeHoleSize > 0.0) {
mRenderPaint.setStyle(Style.STROKE);
mRenderPaint.setStrokeWidth(shapeStrokeSize);
c.drawRect(buffer.buffer[i] - shapeHoleSizeHalf - shapeStrokeSizeHalf,
buffer.buffer[i + 1] - shapeHoleSizeHalf - shapeStrokeSizeHalf,
buffer.buffer[i] + shapeHoleSizeHalf + shapeStrokeSizeHalf,
buffer.buffer[i + 1] + shapeHoleSizeHalf + shapeStrokeSizeHalf,
mRenderPaint);
if (shapeHoleColor != ColorTemplate.COLOR_NONE) {
mRenderPaint.setStyle(Style.FILL);
mRenderPaint.setColor(shapeHoleColor);
c.drawRect(buffer.buffer[i] - shapeHoleSizeHalf,
buffer.buffer[i + 1] - shapeHoleSizeHalf,
buffer.buffer[i] + shapeHoleSizeHalf,
buffer.buffer[i + 1] + shapeHoleSizeHalf,
mRenderPaint);
}
} else {
mRenderPaint.setStyle(Style.FILL);
c.drawRect(buffer.buffer[i] - shapeHalf,
buffer.buffer[i + 1] - shapeHalf,
buffer.buffer[i] + shapeHalf,
buffer.buffer[i + 1] + shapeHalf,
mRenderPaint);
}
}
break;
case CIRCLE:
for (int i = 0; i < buffer.size(); i += 2) {
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
break;
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
continue;
mRenderPaint.setColor(dataSet.getColor(i / 2));
if (shapeHoleSize > 0.0) {
mRenderPaint.setStyle(Style.STROKE);
mRenderPaint.setStrokeWidth(shapeStrokeSize);
c.drawCircle(
buffer.buffer[i],
buffer.buffer[i + 1],
shapeHoleSizeHalf + shapeStrokeSizeHalf,
mRenderPaint);
if (shapeHoleColor != ColorTemplate.COLOR_NONE) {
mRenderPaint.setStyle(Style.FILL);
mRenderPaint.setColor(shapeHoleColor);
c.drawCircle(
buffer.buffer[i],
buffer.buffer[i + 1],
shapeHoleSizeHalf,
mRenderPaint);
}
} else {
mRenderPaint.setStyle(Style.FILL);
c.drawCircle(
buffer.buffer[i],
buffer.buffer[i + 1],
shapeHalf,
mRenderPaint);
}
}
break;
case TRIANGLE:
mRenderPaint.setStyle(Style.FILL);
// create a triangle path
Path tri = new Path();
for (int i = 0; i < buffer.size(); i += 2) {
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
break;
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
continue;
mRenderPaint.setColor(dataSet.getColor(i / 2));
tri.moveTo(buffer.buffer[i], buffer.buffer[i + 1] - shapeHalf);
tri.lineTo(buffer.buffer[i] + shapeHalf, buffer.buffer[i + 1] + shapeHalf);
tri.lineTo(buffer.buffer[i] - shapeHalf, buffer.buffer[i + 1] + shapeHalf);
if (shapeHoleSize > 0.0) {
tri.lineTo(buffer.buffer[i], buffer.buffer[i + 1] - shapeHalf);
tri.moveTo(buffer.buffer[i] - shapeHalf + shapeStrokeSize,
buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
tri.lineTo(buffer.buffer[i] + shapeHalf - shapeStrokeSize,
buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
tri.lineTo(buffer.buffer[i],
buffer.buffer[i + 1] - shapeHalf + shapeStrokeSize);
tri.lineTo(buffer.buffer[i] - shapeHalf + shapeStrokeSize,
buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
}
tri.close();
c.drawPath(tri, mRenderPaint);
tri.reset();
if (shapeHoleSize > 0.0 &&
shapeHoleColor != ColorTemplate.COLOR_NONE) {
mRenderPaint.setColor(shapeHoleColor);
tri.moveTo(buffer.buffer[i],
buffer.buffer[i + 1] - shapeHalf + shapeStrokeSize);
tri.lineTo(buffer.buffer[i] + shapeHalf - shapeStrokeSize,
buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
tri.lineTo(buffer.buffer[i] - shapeHalf + shapeStrokeSize,
buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
tri.close();
c.drawPath(tri, mRenderPaint);
tri.reset();
}
}
break;
case CROSS:
mRenderPaint.setStyle(Style.STROKE);
mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
for (int i = 0; i < buffer.size(); i += 2) {
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
break;
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
continue;
mRenderPaint.setColor(dataSet.getColor(i / 2));
c.drawLine(
buffer.buffer[i] - shapeHalf,
buffer.buffer[i + 1],
buffer.buffer[i] + shapeHalf,
buffer.buffer[i + 1],
mRenderPaint);
c.drawLine(
buffer.buffer[i],
buffer.buffer[i + 1] - shapeHalf,
buffer.buffer[i],
buffer.buffer[i + 1] + shapeHalf,
mRenderPaint);
}
break;
case X:
mRenderPaint.setStyle(Style.STROKE);
mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
for (int i = 0; i < buffer.size(); i += 2) {
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
break;
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
continue;
mRenderPaint.setColor(dataSet.getColor(i / 2));
c.drawLine(
buffer.buffer[i] - shapeHalf,
buffer.buffer[i + 1] - shapeHalf,
buffer.buffer[i] + shapeHalf,
buffer.buffer[i + 1] + shapeHalf,
mRenderPaint);
c.drawLine(
buffer.buffer[i] + shapeHalf,
buffer.buffer[i + 1] - shapeHalf,
buffer.buffer[i] - shapeHalf,
buffer.buffer[i + 1] + shapeHalf,
mRenderPaint);
}
break;
default:
break;
}
// else { // draw the custom-shape
//
// Path customShape = dataSet.getCustomScatterShape();
//
// for (int j = 0; j < entries.size() * mAnimator.getPhaseX(); j += 2) {
//
// Entry e = entries.get(j / 2);
//
// if (!fitsBounds(e.getXIndex(), mMinX, mMaxX))
// continue;
//
// if (customShape == null)
// return;
//
// mRenderPaint.setColor(dataSet.getColor(j));
//
// Path newPath = new Path(customShape);
// newPath.offset(e.getXIndex(), e.getVal());
//
// // transform the provided custom path
// trans.pathValueToPixel(newPath);
// c.drawPath(newPath, mRenderPaint);
// }
// }
}
@Override
public void drawValues(Canvas c) {
// if values are drawn
if (mChart.getScatterData().getYValCount() < mChart.getMaxVisibleCount()
* mViewPortHandler.getScaleX()) {
List<IScatterDataSet> dataSets = mChart.getScatterData().getDataSets();
for (int i = 0; i < mChart.getScatterData().getDataSetCount(); i++) {
IScatterDataSet dataSet = dataSets.get(i);
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
continue;
// apply the text-styling defined by the DataSet
applyValueTextStyle(dataSet);
float[] positions = mChart.getTransformer(dataSet.getAxisDependency())
.generateTransformedValuesScatter(dataSet,
mAnimator.getPhaseY());
float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize());
for (int j = 0; j < positions.length * mAnimator.getPhaseX(); 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);
drawValue(c, dataSet.getValueFormatter(), entry.getVal(), entry, i, positions[j],
positions[j + 1] - shapeSize, dataSet.getValueTextColor(j / 2));
}
}
}
}
@Override
public void drawExtras(Canvas c) {
}
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
ScatterData scatterData = mChart.getScatterData();
for (Highlight high : indices) {
final int minDataSetIndex = high.getDataSetIndex() == -1
? 0
: high.getDataSetIndex();
final int maxDataSetIndex = high.getDataSetIndex() == -1
? scatterData.getDataSetCount()
: (high.getDataSetIndex() + 1);
if (maxDataSetIndex - minDataSetIndex < 1) continue;
for (int dataSetIndex = minDataSetIndex;
dataSetIndex < maxDataSetIndex;
dataSetIndex++) {
IScatterDataSet set = scatterData.getDataSetByIndex(dataSetIndex);
if (set == null || !set.isHighlightEnabled())
continue;
int xIndex = high.getXIndex(); // get the
// x-position
if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX())
continue;
final float yVal = set.getYValForXIndex(xIndex);
if (Float.isNaN(yVal))
continue;
float y = yVal * mAnimator.getPhaseY();
float[] pts = new float[]{
xIndex, y
};
mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts);
// draw the lines
drawHighlightLines(c, pts, set);
}
}
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/ScatterChartRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 3,126 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Paint.Align;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.buffer.BarBuffer;
import com.github.mikephil.charting.buffer.HorizontalBarBuffer;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.List;
/**
* Renderer for the HorizontalBarChart.
*
* @author Philipp Jahoda
*/
public class HorizontalBarChartRenderer extends BarChartRenderer {
public HorizontalBarChartRenderer(BarDataProvider chart, ChartAnimator animator,
ViewPortHandler viewPortHandler) {
super(chart, animator, viewPortHandler);
mValuePaint.setTextAlign(Align.LEFT);
}
@Override
public void initBuffers() {
BarData barData = mChart.getBarData();
mBarBuffers = new HorizontalBarBuffer[barData.getDataSetCount()];
for (int i = 0; i < mBarBuffers.length; i++) {
IBarDataSet set = barData.getDataSetByIndex(i);
mBarBuffers[i] = new HorizontalBarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1),
barData.getGroupSpace(),
barData.getDataSetCount(), set.isStacked());
}
}
@Override
protected void drawDataSet(Canvas c, IBarDataSet dataSet, int index) {
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
mShadowPaint.setColor(dataSet.getBarShadowColor());
mBarBorderPaint.setColor(dataSet.getBarBorderColor());
mBarBorderPaint.setStrokeWidth(Utils.convertDpToPixel(dataSet.getBarBorderWidth()));
final boolean drawBorder = dataSet.getBarBorderWidth() > 0.f;
float phaseX = mAnimator.getPhaseX();
float phaseY = mAnimator.getPhaseY();
// initialize the buffer
BarBuffer buffer = mBarBuffers[index];
buffer.setPhases(phaseX, phaseY);
buffer.setBarSpace(dataSet.getBarSpace());
buffer.setDataSet(index);
buffer.setInverted(mChart.isInverted(dataSet.getAxisDependency()));
buffer.feed(dataSet);
trans.pointValuesToPixel(buffer.buffer);
for (int j = 0; j < buffer.size(); j += 4) {
if (!mViewPortHandler.isInBoundsTop(buffer.buffer[j + 3]))
break;
if (!mViewPortHandler.isInBoundsBottom(buffer.buffer[j + 1]))
continue;
if (mChart.isDrawBarShadowEnabled()) {
c.drawRect(mViewPortHandler.contentLeft(), buffer.buffer[j + 1],
mViewPortHandler.contentRight(),
buffer.buffer[j + 3], mShadowPaint);
}
// Set the color for the currently drawn value. If the index
// is out of bounds, reuse colors.
mRenderPaint.setColor(dataSet.getColor(j / 4));
c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],
buffer.buffer[j + 3], mRenderPaint);
if (drawBorder) {
c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],
buffer.buffer[j + 3], mBarBorderPaint);
}
}
}
@Override
public void drawValues(Canvas c) {
// if values are drawn
if (passesCheck()) {
List<IBarDataSet> dataSets = mChart.getBarData().getDataSets();
final float valueOffsetPlus = Utils.convertDpToPixel(5f);
float posOffset;
float negOffset;
final boolean drawValueAboveBar = mChart.isDrawValueAboveBarEnabled();
for (int i = 0; i < mChart.getBarData().getDataSetCount(); i++) {
IBarDataSet dataSet = dataSets.get(i);
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
continue;
boolean isInverted = mChart.isInverted(dataSet.getAxisDependency());
// apply the text-styling defined by the DataSet
applyValueTextStyle(dataSet);
final float halfTextHeight = Utils.calcTextHeight(mValuePaint, "10") / 2f;
ValueFormatter formatter = dataSet.getValueFormatter();
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
float[] valuePoints = getTransformedValues(trans, dataSet, i);
// if only single values are drawn (sum)
if (!dataSet.isStacked()) {
for (int j = 0; j < valuePoints.length * mAnimator.getPhaseX(); j += 2) {
if (!mViewPortHandler.isInBoundsTop(valuePoints[j + 1]))
break;
if (!mViewPortHandler.isInBoundsX(valuePoints[j]))
continue;
if (!mViewPortHandler.isInBoundsBottom(valuePoints[j + 1]))
continue;
BarEntry e = dataSet.getEntryForIndex(j / 2);
float val = e.getVal();
String formattedValue = formatter.getFormattedValue(val, e, i, mViewPortHandler);
// calculate the correct offset depending on the draw position of the value
float valueTextWidth = Utils.calcTextWidth(mValuePaint, formattedValue);
posOffset = (drawValueAboveBar ? valueOffsetPlus : -(valueTextWidth + valueOffsetPlus));
negOffset = (drawValueAboveBar ? -(valueTextWidth + valueOffsetPlus) : valueOffsetPlus);
if (isInverted) {
posOffset = -posOffset - valueTextWidth;
negOffset = -negOffset - valueTextWidth;
}
drawValue(c, formattedValue, valuePoints[j] + (val >= 0 ? posOffset : negOffset),
valuePoints[j + 1] + halfTextHeight, dataSet.getValueTextColor(j / 2));
}
// if each value of a potential stack should be drawn
} else {
for (int j = 0; j < (valuePoints.length - 1) * mAnimator.getPhaseX(); j += 2) {
BarEntry e = dataSet.getEntryForIndex(j / 2);
float[] vals = e.getVals();
// we still draw stacked bars, but there is one
// non-stacked
// in between
if (vals == null) {
if (!mViewPortHandler.isInBoundsTop(valuePoints[j + 1]))
break;
if (!mViewPortHandler.isInBoundsX(valuePoints[j]))
continue;
if (!mViewPortHandler.isInBoundsBottom(valuePoints[j + 1]))
continue;
float val = e.getVal();
String formattedValue = formatter.getFormattedValue(val, e, i, mViewPortHandler);
// calculate the correct offset depending on the draw position of the value
float valueTextWidth = Utils.calcTextWidth(mValuePaint, formattedValue);
posOffset = (drawValueAboveBar ? valueOffsetPlus : -(valueTextWidth + valueOffsetPlus));
negOffset = (drawValueAboveBar ? -(valueTextWidth + valueOffsetPlus) : valueOffsetPlus);
if (isInverted) {
posOffset = -posOffset - valueTextWidth;
negOffset = -negOffset - valueTextWidth;
}
drawValue(c, formattedValue, valuePoints[j]
+ (e.getVal() >= 0 ? posOffset : negOffset),
valuePoints[j + 1] + halfTextHeight, dataSet.getValueTextColor(j / 2));
} else {
float[] transformed = new float[vals.length * 2];
float posY = 0f;
float negY = -e.getNegativeSum();
for (int k = 0, idx = 0; k < transformed.length; k += 2, idx++) {
float value = vals[idx];
float y;
if (value >= 0f) {
posY += value;
y = posY;
} else {
y = negY;
negY -= value;
}
transformed[k] = y * mAnimator.getPhaseY();
}
trans.pointValuesToPixel(transformed);
for (int k = 0; k < transformed.length; k += 2) {
float val = vals[k / 2];
String formattedValue = formatter.getFormattedValue(val, e, i, mViewPortHandler);
// calculate the correct offset depending on the draw position of the value
float valueTextWidth = Utils.calcTextWidth(mValuePaint, formattedValue);
posOffset = (drawValueAboveBar ? valueOffsetPlus : -(valueTextWidth + valueOffsetPlus));
negOffset = (drawValueAboveBar ? -(valueTextWidth + valueOffsetPlus) : valueOffsetPlus);
if (isInverted) {
posOffset = -posOffset - valueTextWidth;
negOffset = -negOffset - valueTextWidth;
}
float x = transformed[k]
+ (val >= 0 ? posOffset : negOffset);
float y = valuePoints[j + 1];
if (!mViewPortHandler.isInBoundsTop(y))
break;
if (!mViewPortHandler.isInBoundsX(x))
continue;
if (!mViewPortHandler.isInBoundsBottom(y))
continue;
drawValue(c, formattedValue, x, y + halfTextHeight, dataSet.getValueTextColor(j / 2));
}
}
}
}
}
}
}
protected void drawValue(Canvas c, String valueText, float x, float y, int color) {
mValuePaint.setColor(color);
c.drawText(valueText, x, y, mValuePaint);
}
@Override
protected void prepareBarHighlight(float x, float y1, float y2, float barspaceHalf,
Transformer trans) {
float top = x - 0.5f + barspaceHalf;
float bottom = x + 0.5f - barspaceHalf;
float left = y1;
float right = y2;
mBarRect.set(left, top, right, bottom);
trans.rectValueToPixelHorizontal(mBarRect, mAnimator.getPhaseY());
}
@Override
public float[] getTransformedValues(Transformer trans, IBarDataSet data,
int dataSetIndex) {
return trans.generateTransformedValuesHorizontalBarChart(data, dataSetIndex,
mChart.getBarData(), mAnimator.getPhaseY());
}
@Override
protected boolean passesCheck() {
return mChart.getBarData().getYValCount() < mChart.getMaxVisibleCount()
* mViewPortHandler.getScaleY();
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 2,377 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Path;
import android.util.Log;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.interfaces.datasets.ILineScatterCandleRadarDataSet;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* Created by Philipp Jahoda on 11/07/15.
*
*/
public abstract class LineScatterCandleRadarRenderer extends DataRenderer {
/**
* path that is used for drawing highlight-lines (drawLines(...) cannot be used because of dashes)
*/
private Path mHighlightLinePath = new Path();
public LineScatterCandleRadarRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
}
/**
* Draws vertical & horizontal highlight-lines if enabled.
*
* @param c
* @param pts the transformed x- and y-position of the lines
* @param set the currently drawn dataset
*/
protected void drawHighlightLines(Canvas c, float[] pts, ILineScatterCandleRadarDataSet set) {
// set color and stroke-width
mHighlightPaint.setColor(set.getHighLightColor());
mHighlightPaint.setStrokeWidth(set.getHighlightLineWidth());
// draw highlighted lines (if enabled)
mHighlightPaint.setPathEffect(set.getDashPathEffectHighlight());
// draw vertical highlight lines
if (set.isVerticalHighlightIndicatorEnabled()) {
// create vertical path
mHighlightLinePath.reset();
mHighlightLinePath.moveTo(pts[0], mViewPortHandler.contentTop());
mHighlightLinePath.lineTo(pts[0], mViewPortHandler.contentBottom());
c.drawPath(mHighlightLinePath, mHighlightPaint);
}
// draw horizontal highlight lines
if (set.isHorizontalHighlightIndicatorEnabled()) {
// create horizontal path
mHighlightLinePath.reset();
mHighlightLinePath.moveTo(mViewPortHandler.contentLeft(), pts[1]);
mHighlightLinePath.lineTo(mViewPortHandler.contentRight(), pts[1]);
c.drawPath(mHighlightLinePath, mHighlightPaint);
}
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/LineScatterCandleRadarRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 463 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.buffer.BarBuffer;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.List;
public class BarChartRenderer extends DataRenderer {
protected BarDataProvider mChart;
/**
* the rect object that is used for drawing the bars
*/
protected RectF mBarRect = new RectF();
protected BarBuffer[] mBarBuffers;
protected Paint mShadowPaint;
protected Paint mBarBorderPaint;
public BarChartRenderer(BarDataProvider chart, ChartAnimator animator,
ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
this.mChart = chart;
mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mHighlightPaint.setStyle(Paint.Style.FILL);
mHighlightPaint.setColor(Color.rgb(0, 0, 0));
// set alpha after color
mHighlightPaint.setAlpha(120);
mShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mShadowPaint.setStyle(Paint.Style.FILL);
mBarBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mBarBorderPaint.setStyle(Paint.Style.STROKE);
}
@Override
public void initBuffers() {
BarData barData = mChart.getBarData();
mBarBuffers = new BarBuffer[barData.getDataSetCount()];
for (int i = 0; i < mBarBuffers.length; i++) {
IBarDataSet set = barData.getDataSetByIndex(i);
mBarBuffers[i] = new BarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1),
barData.getGroupSpace(),
barData.getDataSetCount(), set.isStacked());
}
}
@Override
public void drawData(Canvas c) {
BarData barData = mChart.getBarData();
for (int i = 0; i < barData.getDataSetCount(); i++) {
IBarDataSet set = barData.getDataSetByIndex(i);
if (set.isVisible() && set.getEntryCount() > 0) {
drawDataSet(c, set, i);
}
}
}
protected void drawDataSet(Canvas c, IBarDataSet dataSet, int index) {
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
mShadowPaint.setColor(dataSet.getBarShadowColor());
mBarBorderPaint.setColor(dataSet.getBarBorderColor());
mBarBorderPaint.setStrokeWidth(Utils.convertDpToPixel(dataSet.getBarBorderWidth()));
final boolean drawBorder = dataSet.getBarBorderWidth() > 0.f;
float phaseX = mAnimator.getPhaseX();
float phaseY = mAnimator.getPhaseY();
// initialize the buffer
BarBuffer buffer = mBarBuffers[index];
buffer.setPhases(phaseX, phaseY);
buffer.setBarSpace(dataSet.getBarSpace());
buffer.setDataSet(index);
buffer.setInverted(mChart.isInverted(dataSet.getAxisDependency()));
buffer.feed(dataSet);
trans.pointValuesToPixel(buffer.buffer);
// draw the bar shadow before the values
if (mChart.isDrawBarShadowEnabled()) {
for (int j = 0; j < buffer.size(); j += 4) {
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[j + 2]))
continue;
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[j]))
break;
c.drawRect(buffer.buffer[j], mViewPortHandler.contentTop(),
buffer.buffer[j + 2],
mViewPortHandler.contentBottom(), mShadowPaint);
}
}
// if multiple colors
if (dataSet.getColors().size() > 1) {
for (int j = 0; j < buffer.size(); j += 4) {
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[j + 2]))
continue;
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[j]))
break;
// Set the color for the currently drawn value. If the index
// is out of bounds, reuse colors.
/**/
int i = j / 4;
if (i > 0) {
if (dataSet.getEntryForIndex(i).getVal() > dataSet.getEntryForIndex(i - 1).getVal()) {
mRenderPaint.setColor(Color.RED);
} else {
mRenderPaint.setColor(Color.GREEN);
}
}
// mRenderPaint.setColor(dataSet.getColor(j / 4));
c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],
buffer.buffer[j + 3], mRenderPaint);
if (drawBorder) {
c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],
buffer.buffer[j + 3], mBarBorderPaint);
}
}
} else {
mRenderPaint.setColor(dataSet.getColor());
for (int j = 0; j < buffer.size(); j += 4) {
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[j + 2]))
continue;
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[j]))
break;
mRenderPaint.setColor(dataSet.getColor(j / 4));
/**/
c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],
buffer.buffer[j + 3], mRenderPaint);
/* c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2] - (buffer.buffer[j + 2] - buffer.buffer[j]) / 3,
buffer.buffer[j + 3], mRenderPaint);*/
if (drawBorder) {
c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],
buffer.buffer[j + 3], mBarBorderPaint);
}
}
}
}
/**
* Prepares a bar for being highlighted.
*
* @param x the x-position
* @param y1 the y1-position
* @param y2 the y2-position
* @param barspaceHalf the space between bars
* @param trans
*/
protected void prepareBarHighlight(float x, float y1, float y2, float barspaceHalf,
Transformer trans) {
float barWidth = 0.5f;
float left = x - barWidth + barspaceHalf;
float right = x + barWidth - barspaceHalf;
float top = y1;
float bottom = y2;
mBarRect.set(left, top, right, bottom);
trans.rectValueToPixel(mBarRect, mAnimator.getPhaseY());
}
@Override
public void drawValues(Canvas c) {
// if values are drawn
if (passesCheck()) {
List<IBarDataSet> dataSets = mChart.getBarData().getDataSets();
final float valueOffsetPlus = Utils.convertDpToPixel(4.5f);
float posOffset;
float negOffset;
boolean drawValueAboveBar = mChart.isDrawValueAboveBarEnabled();
for (int i = 0; i < mChart.getBarData().getDataSetCount(); i++) {
IBarDataSet dataSet = dataSets.get(i);
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
continue;
// apply the text-styling defined by the DataSet
applyValueTextStyle(dataSet);
boolean isInverted = mChart.isInverted(dataSet.getAxisDependency());
// calculate the correct offset depending on the draw position of
// the value
float valueTextHeight = Utils.calcTextHeight(mValuePaint, "8");
posOffset = (drawValueAboveBar ? -valueOffsetPlus : valueTextHeight + valueOffsetPlus);
negOffset = (drawValueAboveBar ? valueTextHeight + valueOffsetPlus : -valueOffsetPlus);
if (isInverted) {
posOffset = -posOffset - valueTextHeight;
negOffset = -negOffset - valueTextHeight;
}
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
float[] valuePoints = getTransformedValues(trans, dataSet, i);
// if only single values are drawn (sum)
if (!dataSet.isStacked()) {
for (int j = 0; j < valuePoints.length * mAnimator.getPhaseX(); j += 2) {
if (!mViewPortHandler.isInBoundsRight(valuePoints[j]))
break;
if (!mViewPortHandler.isInBoundsY(valuePoints[j + 1])
|| !mViewPortHandler.isInBoundsLeft(valuePoints[j]))
continue;
BarEntry entry = dataSet.getEntryForIndex(j / 2);
float val = entry.getVal();
drawValue(c, dataSet.getValueFormatter(), val, entry, i, valuePoints[j],
valuePoints[j + 1] + (val >= 0 ? posOffset : negOffset), dataSet.getValueTextColor(j / 2));
}
// if we have stacks
} else {
for (int j = 0; j < (valuePoints.length - 1) * mAnimator.getPhaseX(); j += 2) {
BarEntry entry = dataSet.getEntryForIndex(j / 2);
float[] vals = entry.getVals();
// we still draw stacked bars, but there is one
// non-stacked
// in between
if (vals == null) {
if (!mViewPortHandler.isInBoundsRight(valuePoints[j]))
break;
if (!mViewPortHandler.isInBoundsY(valuePoints[j + 1])
|| !mViewPortHandler.isInBoundsLeft(valuePoints[j]))
continue;
drawValue(c, dataSet.getValueFormatter(), entry.getVal(), entry, i, valuePoints[j],
valuePoints[j + 1] + (entry.getVal() >= 0 ? posOffset : negOffset), dataSet.getValueTextColor(j / 2));
// draw stack values
} else {
int color = dataSet.getValueTextColor(j / 2);
float[] transformed = new float[vals.length * 2];
float posY = 0f;
float negY = -entry.getNegativeSum();
for (int k = 0, idx = 0; k < transformed.length; k += 2, idx++) {
float value = vals[idx];
float y;
if (value >= 0f) {
posY += value;
y = posY;
} else {
y = negY;
negY -= value;
}
transformed[k + 1] = y * mAnimator.getPhaseY();
}
trans.pointValuesToPixel(transformed);
for (int k = 0; k < transformed.length; k += 2) {
float x = valuePoints[j];
float y = transformed[k + 1]
+ (vals[k / 2] >= 0 ? posOffset : negOffset);
if (!mViewPortHandler.isInBoundsRight(x))
break;
if (!mViewPortHandler.isInBoundsY(y)
|| !mViewPortHandler.isInBoundsLeft(x))
continue;
drawValue(c, dataSet.getValueFormatter(), vals[k / 2], entry, i, x, y, color);
}
}
}
}
}
}
}
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
BarData barData = mChart.getBarData();
int setCount = barData.getDataSetCount();
for (Highlight high : indices) {
final int minDataSetIndex = high.getDataSetIndex() == -1
? 0
: high.getDataSetIndex();
final int maxDataSetIndex = high.getDataSetIndex() == -1
? barData.getDataSetCount()
: (high.getDataSetIndex() + 1);
if (maxDataSetIndex - minDataSetIndex < 1)
continue;
for (int dataSetIndex = minDataSetIndex;
dataSetIndex < maxDataSetIndex;
dataSetIndex++) {
IBarDataSet set = barData.getDataSetByIndex(dataSetIndex);
if (set == null || !set.isHighlightEnabled())
continue;
float barspaceHalf = set.getBarSpace() / 2f;
Transformer trans = mChart.getTransformer(set.getAxisDependency());
mHighlightPaint.setColor(set.getHighLightColor());
mHighlightPaint.setAlpha(set.getHighLightAlpha());
int index = high.getXIndex();
// check outofbounds
if (index >= 0
&& index < (mChart.getXChartMax() * mAnimator.getPhaseX()) / setCount) {
BarEntry e = set.getEntryForXIndex(index);
if (e == null || e.getXIndex() != index)
continue;
float groupspace = barData.getGroupSpace();
boolean isStack = high.getStackIndex() < 0 ? false : true;
// calculate the correct x-position
float x = index * setCount + dataSetIndex + groupspace / 2f
+ groupspace * index;
final float y1;
final float y2;
if (isStack) {
y1 = high.getRange().from;
y2 = high.getRange().to;
} else {
y1 = e.getVal();
y2 = 0.f;
}
prepareBarHighlight(x, y1, y2, barspaceHalf, trans);
/**/
c.drawLine(mBarRect.centerX(), mViewPortHandler.getContentRect().bottom, mBarRect.centerX(), 0, mHighlightPaint);
// c.drawRect(mBarRect, mHighlightPaint);
if (mChart.isDrawHighlightArrowEnabled()) {
mHighlightPaint.setAlpha(255);
// distance between highlight arrow and bar
float offsetY = mAnimator.getPhaseY() * 0.07f;
float[] values = new float[9];
trans.getPixelToValueMatrix().getValues(values);
final float xToYRel = Math.abs(
values[Matrix.MSCALE_Y] / values[Matrix.MSCALE_X]);
final float arrowWidth = set.getBarSpace() / 2.f;
final float arrowHeight = arrowWidth * xToYRel;
final float yArrow = (y1 > -y2 ? y1 : y1) * mAnimator.getPhaseY();
Path arrow = new Path();
arrow.moveTo(x + 0.4f, yArrow + offsetY);
arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY - arrowHeight);
arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY + arrowHeight);
trans.pathValueToPixel(arrow);
c.drawPath(arrow, mHighlightPaint);
}
}
}
}
}
public float[] getTransformedValues(Transformer trans, IBarDataSet data,
int dataSetIndex) {
return trans.generateTransformedValuesBarChart(data, dataSetIndex,
mChart.getBarData(),
mAnimator.getPhaseY());
}
protected boolean passesCheck() {
return mChart.getBarData().getYValCount() < mChart.getMaxVisibleCount()
* mViewPortHandler.getScaleX();
}
@Override
public void drawExtras(Canvas c) {
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/BarChartRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 3,449 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Path;
import com.github.mikephil.charting.components.LimitLine;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.components.YAxis.AxisDependency;
import com.github.mikephil.charting.components.YAxis.YAxisLabelPosition;
import com.github.mikephil.charting.utils.PointD;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.List;
public class YAxisRenderer extends AxisRenderer {
protected YAxis mYAxis;
protected Paint mZeroLinePaint;
public YAxisRenderer(ViewPortHandler viewPortHandler, YAxis yAxis, Transformer trans) {
super(viewPortHandler, trans);
this.mYAxis = yAxis;
mAxisLabelPaint.setColor(Color.BLACK);
mAxisLabelPaint.setTextSize(Utils.convertDpToPixel(10f));
mZeroLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mZeroLinePaint.setColor(Color.GRAY);
mZeroLinePaint.setStrokeWidth(1f);
mZeroLinePaint.setStyle(Paint.Style.STROKE);
}
/**
* Computes the axis values.
*
* @param yMin - the minimum y-value in the data object for this axis
* @param yMax - the maximum y-value in the data object for this axis
*/
public void computeAxis(float yMin, float yMax) {
// calculate the starting and entry point of the y-labels (depending on
// zoom / contentrect bounds)
if (mViewPortHandler.contentWidth() > 10 && !mViewPortHandler.isFullyZoomedOutY()) {
PointD p1 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop());
PointD p2 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom());
if (!mYAxis.isInverted()) {
yMin = (float) p2.y;
yMax = (float) p1.y;
} else {
yMin = (float) p1.y;
yMax = (float) p2.y;
}
}
computeAxisValues(yMin, yMax);
}
/**
* Sets up the y-axis labels. Computes the desired number of labels between the two given extremes. Unlike the
* papareXLabels() method, this method needs to be called upon every refresh of the view.
*
* @return
*/
protected void computeAxisValues(float min, float max) {
float yMin = min;
float yMax = max;
int labelCount = mYAxis.getLabelCount();
double range = Math.abs(yMax - yMin);
if (labelCount == 0 || range <= 0) {
mYAxis.mEntries = new float[]{};
mYAxis.mEntryCount = 0;
return;
}
// Find out how much spacing (in y value space) between axis values
double rawInterval = range / labelCount;
double interval = Utils.roundToNextSignificant(rawInterval);
// If granularity is enabled, then do not allow the interval to go below specified granularity.
// This is used to avoid repeated values when rounding values for display.
if (mYAxis.isGranularityEnabled())
interval = interval < mYAxis.getGranularity() ? mYAxis.getGranularity() : interval;
// Normalize interval
double intervalMagnitude = Utils.roundToNextSignificant(Math.pow(10, (int) Math.log10(interval)));
int intervalSigDigit = (int) (interval / intervalMagnitude);
if (intervalSigDigit > 5) {
// Use one order of magnitude higher, to avoid intervals like 0.9 or
// 90
interval = Math.floor(10 * intervalMagnitude);
}
// force label count
if (mYAxis.isForceLabelsEnabled()) {
float step = (float) range / (float) (labelCount - 1);
mYAxis.mEntryCount = labelCount;
if (mYAxis.mEntries.length < labelCount) {
// Ensure stops contains at least numStops elements.
mYAxis.mEntries = new float[labelCount];
}
float v = min;
for (int i = 0; i < labelCount; i++) {
mYAxis.mEntries[i] = v;
v += step;
}
// no forced count
} else {
// if the labels should only show min and max
if (mYAxis.isShowOnlyMinMaxEnabled()) {
mYAxis.mEntryCount = 2;
mYAxis.mEntries = new float[2];
mYAxis.mEntries[0] = yMin;
mYAxis.mEntries[1] = yMax;
} else {
double first = interval == 0.0 ? 0.0 : Math.ceil(yMin / interval) * interval;
double last = interval == 0.0 ? 0.0 : Utils.nextUp(Math.floor(yMax / interval) * interval);
double f;
int i;
int n = 0;
if (interval != 0.0) {
for (f = first; f <= last; f += interval) {
++n;
}
}
mYAxis.mEntryCount = n;
if (mYAxis.mEntries.length < n) {
// Ensure stops contains at least numStops elements.
mYAxis.mEntries = new float[n];
}
for (f = first, i = 0; i < n; f += interval, ++i) {
if (f == 0.0) // Fix for negative zero case (Where value == -0.0, and 0.0 == -0.0)
f = 0.0;
mYAxis.mEntries[i] = (float) f;
}
}
}
// set decimals
if (interval < 1) {
mYAxis.mDecimals = (int) Math.ceil(-Math.log10(interval));
} else {
mYAxis.mDecimals = 0;
}
}
/**
* 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;
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);
}
@Override
public void renderAxisLine(Canvas c) {
if (!mYAxis.isEnabled() || !mYAxis.isDrawAxisLineEnabled())
return;
mAxisLinePaint.setColor(mYAxis.getAxisLineColor());
mAxisLinePaint.setStrokeWidth(mYAxis.getAxisLineWidth());
if (mYAxis.getAxisDependency() == AxisDependency.LEFT) {
c.drawLine(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), mViewPortHandler.contentLeft(),
mViewPortHandler.contentBottom(), mAxisLinePaint);
} else {
c.drawLine(mViewPortHandler.contentRight(), mViewPortHandler.contentTop(), mViewPortHandler.contentRight(),
mViewPortHandler.contentBottom(), mAxisLinePaint);
}
}
/**
* draws the y-labels on the specified x-position
*
* @param fixedPosition
* @param positions
*/
protected void drawYLabels(Canvas c, float fixedPosition, float[] positions, float offset) {
// draw
for (int i = 0; i < mYAxis.mEntryCount; i++) {
String text = mYAxis.getFormattedLabel(i);
if (!mYAxis.isDrawTopYLabelEntryEnabled() && i >= mYAxis.mEntryCount - 1)
return;
c.drawText(text, fixedPosition, positions[i * 2 + 1] + offset, mAxisLabelPaint);
}
}
@Override
public void renderGridLines(Canvas c) {
if (!mYAxis.isEnabled())
return;
// pre alloc
float[] position = new float[2];
if (mYAxis.isDrawGridLinesEnabled()) {
mGridPaint.setColor(mYAxis.getGridColor());
mGridPaint.setStrokeWidth(mYAxis.getGridLineWidth());
mGridPaint.setPathEffect(mYAxis.getGridDashPathEffect());
Path gridLinePath = new Path();
// draw the horizontal grid
for (int i = 0; i < mYAxis.mEntryCount; i++) {
position[1] = mYAxis.mEntries[i];
mTrans.pointValuesToPixel(position);
gridLinePath.moveTo(mViewPortHandler.offsetLeft(), position[1]);
gridLinePath.lineTo(mViewPortHandler.contentRight(), position[1]);
// draw a path because lines don't support dashing on lower android versions
c.drawPath(gridLinePath, mGridPaint);
gridLinePath.reset();
}
}
if (mYAxis.isDrawZeroLineEnabled()) {
// draw zero line
position[1] = 0f;
mTrans.pointValuesToPixel(position);
drawZeroLine(c, mViewPortHandler.offsetLeft(), mViewPortHandler.contentRight(), position[1] - 1, position[1] - 1);
}
}
/**
* Draws the zero line at the specified position.
*
* @param c
* @param x1
* @param x2
* @param y1
* @param y2
*/
protected void drawZeroLine(Canvas c, float x1, float x2, float y1, float y2) {
mZeroLinePaint.setColor(mYAxis.getZeroLineColor());
mZeroLinePaint.setStrokeWidth(mYAxis.getZeroLineWidth());
Path zeroLinePath = new Path();
zeroLinePath.moveTo(x1, y1);
zeroLinePath.lineTo(x2, y2);
// draw a path because lines don't support dashing on lower android versions
c.drawPath(zeroLinePath, mZeroLinePaint);
}
/**
* Draws the LimitLines associated with this axis to the screen.
*
* @param c
*/
@Override
public void renderLimitLines(Canvas c) {
List<LimitLine> limitLines = mYAxis.getLimitLines();
if (limitLines == null || limitLines.size() <= 0)
return;
float[] pts = new float[2];
Path limitLinePath = new Path();
for (int i = 0; i < limitLines.size(); i++) {
LimitLine l = limitLines.get(i);
if (!l.isEnabled())
continue;
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 && !"".equals(label)) {
mLimitLinePaint.setStyle(l.getTextStyle());
mLimitLinePaint.setPathEffect(null);
mLimitLinePaint.setColor(l.getTextColor());
mLimitLinePaint.setTypeface(l.getTypeface());
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);
}
}
}
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/YAxisRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 3,229 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Typeface;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.FSize;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class LegendRenderer extends Renderer {
/**
* paint for the legend labels
*/
protected Paint mLegendLabelPaint;
/**
* paint used for the legend forms
*/
protected Paint mLegendFormPaint;
/**
* the legend object this renderer renders
*/
protected Legend mLegend;
public LegendRenderer(ViewPortHandler viewPortHandler, Legend legend) {
super(viewPortHandler);
this.mLegend = legend;
mLegendLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mLegendLabelPaint.setTextSize(Utils.convertDpToPixel(9f));
mLegendLabelPaint.setTextAlign(Align.LEFT);
mLegendFormPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mLegendFormPaint.setStyle(Paint.Style.FILL);
mLegendFormPaint.setStrokeWidth(3f);
}
/**
* Returns the Paint object used for drawing the Legend labels.
*
* @return
*/
public Paint getLabelPaint() {
return mLegendLabelPaint;
}
/**
* Returns the Paint object used for drawing the Legend forms.
*
* @return
*/
public Paint getFormPaint() {
return mLegendFormPaint;
}
/**
* Prepares the legend and calculates all needed forms, labels and colors.
*
* @param data
*/
public void computeLegend(ChartData<?> data) {
if (!mLegend.isLegendCustom()) {
List<String> labels = new ArrayList<>();
List<Integer> colors = new ArrayList<>();
// loop for building up the colors and labels used in the legend
for (int i = 0; i < data.getDataSetCount(); i++) {
IDataSet dataSet = data.getDataSetByIndex(i);
List<Integer> clrs = dataSet.getColors();
int entryCount = dataSet.getEntryCount();
// if we have a barchart with stacked bars
if (dataSet instanceof IBarDataSet && ((IBarDataSet) dataSet).isStacked()) {
IBarDataSet bds = (IBarDataSet) dataSet;
String[] sLabels = bds.getStackLabels();
for (int j = 0; j < clrs.size() && j < bds.getStackSize(); j++) {
labels.add(sLabels[j % sLabels.length]);
colors.add(clrs.get(j));
}
if (bds.getLabel() != null) {
// add the legend description label
colors.add(ColorTemplate.COLOR_SKIP);
labels.add(bds.getLabel());
}
} else if (dataSet instanceof IPieDataSet) {
List<String> xVals = data.getXVals();
IPieDataSet pds = (IPieDataSet) dataSet;
for (int j = 0; j < clrs.size() && j < entryCount && j < xVals.size(); j++) {
labels.add(xVals.get(j));
colors.add(clrs.get(j));
}
if (pds.getLabel() != null) {
// add the legend description label
colors.add(ColorTemplate.COLOR_SKIP);
labels.add(pds.getLabel());
}
} else if(dataSet instanceof ICandleDataSet && ((ICandleDataSet) dataSet).getDecreasingColor() != ColorTemplate.COLOR_NONE) {
colors.add(((ICandleDataSet) dataSet).getDecreasingColor());
colors.add(((ICandleDataSet) dataSet).getIncreasingColor());
labels.add(null);
labels.add(dataSet.getLabel());
} else { // all others
for (int j = 0; j < clrs.size() && j < entryCount; j++) {
// if multiple colors are set for a DataSet, group them
if (j < clrs.size() - 1 && j < entryCount - 1) {
labels.add(null);
} else { // add label to the last entry
String label = data.getDataSetByIndex(i).getLabel();
labels.add(label);
}
colors.add(clrs.get(j));
}
}
}
if (mLegend.getExtraColors() != null && mLegend.getExtraLabels() != null) {
for (int color : mLegend.getExtraColors())
colors.add(color);
Collections.addAll(labels, mLegend.getExtraLabels());
}
mLegend.setComputedColors(colors);
mLegend.setComputedLabels(labels);
}
Typeface tf = mLegend.getTypeface();
if (tf != null)
mLegendLabelPaint.setTypeface(tf);
mLegendLabelPaint.setTextSize(mLegend.getTextSize());
mLegendLabelPaint.setColor(mLegend.getTextColor());
// calculate all dimensions of the mLegend
mLegend.calculateDimensions(mLegendLabelPaint, mViewPortHandler);
}
public void renderLegend(Canvas c) {
if (!mLegend.isEnabled())
return;
Typeface tf = mLegend.getTypeface();
if (tf != null)
mLegendLabelPaint.setTypeface(tf);
mLegendLabelPaint.setTextSize(mLegend.getTextSize());
mLegendLabelPaint.setColor(mLegend.getTextColor());
float labelLineHeight = Utils.getLineHeight(mLegendLabelPaint);
float labelLineSpacing = Utils.getLineSpacing(mLegendLabelPaint) + mLegend.getYEntrySpace();
float formYOffset = labelLineHeight - Utils.calcTextHeight(mLegendLabelPaint, "ABC") / 2.f;
String[] labels = mLegend.getLabels();
int[] colors = mLegend.getColors();
float formToTextSpace = mLegend.getFormToTextSpace();
float xEntrySpace = mLegend.getXEntrySpace();
Legend.LegendOrientation orientation = mLegend.getOrientation();
Legend.LegendHorizontalAlignment horizontalAlignment = mLegend.getHorizontalAlignment();
Legend.LegendVerticalAlignment verticalAlignment = mLegend.getVerticalAlignment();
Legend.LegendDirection direction = mLegend.getDirection();
float formSize = mLegend.getFormSize();
// space between the entries
float stackSpace = mLegend.getStackSpace();
float yoffset = mLegend.getYOffset();
float xoffset = mLegend.getXOffset();
float originPosX = 0.f;
switch (horizontalAlignment) {
case LEFT:
if (orientation == Legend.LegendOrientation.VERTICAL)
originPosX = xoffset;
else
originPosX = mViewPortHandler.contentLeft() + xoffset;
if (direction == Legend.LegendDirection.RIGHT_TO_LEFT)
originPosX += mLegend.mNeededWidth;
break;
case RIGHT:
if (orientation == Legend.LegendOrientation.VERTICAL)
originPosX = mViewPortHandler.getChartWidth() - xoffset;
else
originPosX = mViewPortHandler.contentRight() - xoffset;
if (direction == Legend.LegendDirection.LEFT_TO_RIGHT)
originPosX -= mLegend.mNeededWidth;
break;
case CENTER:
if (orientation == Legend.LegendOrientation.VERTICAL)
originPosX = mViewPortHandler.getChartWidth() / 2.f;
else
originPosX = mViewPortHandler.contentLeft()
+ mViewPortHandler.contentWidth() / 2.f;
originPosX += (direction == Legend.LegendDirection.LEFT_TO_RIGHT
? +xoffset
: -xoffset);
// Horizontally layed out legends do the center offset on a line basis,
// So here we offset the vertical ones only.
if (orientation == Legend.LegendOrientation.VERTICAL) {
originPosX += (direction == Legend.LegendDirection.LEFT_TO_RIGHT
? -mLegend.mNeededWidth / 2.0 + xoffset
: mLegend.mNeededWidth / 2.0 - xoffset);
}
break;
}
switch (orientation) {
case HORIZONTAL: {
FSize[] calculatedLineSizes = mLegend.getCalculatedLineSizes();
FSize[] calculatedLabelSizes = mLegend.getCalculatedLabelSizes();
Boolean[] calculatedLabelBreakPoints = mLegend.getCalculatedLabelBreakPoints();
float posX = originPosX;
float posY = 0.f;
switch (verticalAlignment) {
case TOP:
posY = yoffset;
break;
case BOTTOM:
posY = mViewPortHandler.getChartHeight() - yoffset - mLegend.mNeededHeight;
break;
case CENTER:
posY = (mViewPortHandler.getChartHeight() - mLegend.mNeededHeight) / 2.f + yoffset;
break;
}
int lineIndex = 0;
for (int i = 0, count = labels.length; i < count; i++) {
if (i < calculatedLabelBreakPoints.length && calculatedLabelBreakPoints[i]) {
posX = originPosX;
posY += labelLineHeight + labelLineSpacing;
}
if (posX == originPosX &&
horizontalAlignment == Legend.LegendHorizontalAlignment.CENTER &&
lineIndex < calculatedLineSizes.length) {
posX += (direction == Legend.LegendDirection.RIGHT_TO_LEFT
? calculatedLineSizes[lineIndex].width
: -calculatedLineSizes[lineIndex].width) / 2.f;
lineIndex++;
}
boolean drawingForm = colors[i] != ColorTemplate.COLOR_SKIP;
boolean isStacked = labels[i] == null; // grouped forms have null labels
if (drawingForm) {
if (direction == Legend.LegendDirection.RIGHT_TO_LEFT)
posX -= formSize;
drawForm(c, posX, posY + formYOffset, i, mLegend);
if (direction == Legend.LegendDirection.LEFT_TO_RIGHT)
posX += formSize;
}
if (!isStacked) {
if (drawingForm)
posX += direction == Legend.LegendDirection.RIGHT_TO_LEFT ? -formToTextSpace : formToTextSpace;
if (direction == Legend.LegendDirection.RIGHT_TO_LEFT)
posX -= calculatedLabelSizes[i].width;
drawLabel(c, posX, posY + labelLineHeight, labels[i]);
if (direction == Legend.LegendDirection.LEFT_TO_RIGHT)
posX += calculatedLabelSizes[i].width;
posX += direction == Legend.LegendDirection.RIGHT_TO_LEFT ? -xEntrySpace : xEntrySpace;
} else
posX += direction == Legend.LegendDirection.RIGHT_TO_LEFT ? -stackSpace : stackSpace;
}
break;
}
case VERTICAL: {
// contains the stacked legend size in pixels
float stack = 0f;
boolean wasStacked = false;
float posY = 0.f;
switch (verticalAlignment) {
case TOP:
posY = (horizontalAlignment == Legend.LegendHorizontalAlignment.CENTER
? 0.f
: mViewPortHandler.contentTop());
posY += yoffset;
break;
case BOTTOM:
posY = (horizontalAlignment == Legend.LegendHorizontalAlignment.CENTER
? mViewPortHandler.getChartHeight()
: mViewPortHandler.contentBottom());
posY -= mLegend.mNeededHeight + yoffset;
break;
case CENTER:
posY = mViewPortHandler.getChartHeight() / 2.f
- mLegend.mNeededHeight / 2.f
+ mLegend.getYOffset();
break;
}
for (int i = 0; i < labels.length; i++) {
Boolean drawingForm = colors[i] != ColorTemplate.COLOR_SKIP;
float posX = originPosX;
if (drawingForm) {
if (direction == Legend.LegendDirection.LEFT_TO_RIGHT)
posX += stack;
else
posX -= formSize - stack;
drawForm(c, posX, posY + formYOffset, i, mLegend);
if (direction == Legend.LegendDirection.LEFT_TO_RIGHT)
posX += formSize;
}
if (labels[i] != null) {
if (drawingForm && !wasStacked)
posX += direction == Legend.LegendDirection.LEFT_TO_RIGHT ? formToTextSpace
: -formToTextSpace;
else if (wasStacked)
posX = originPosX;
if (direction == Legend.LegendDirection.RIGHT_TO_LEFT)
posX -= Utils.calcTextWidth(mLegendLabelPaint, labels[i]);
if (!wasStacked) {
drawLabel(c, posX, posY + labelLineHeight, labels[i]);
} else {
posY += labelLineHeight + labelLineSpacing;
drawLabel(c, posX, posY + labelLineHeight, labels[i]);
}
// make a step down
posY += labelLineHeight + labelLineSpacing;
stack = 0f;
} else {
stack += formSize + stackSpace;
wasStacked = true;
}
}
break;
}
}
}
/**
* Draws the Legend-form at the given position with the color at the given
* index.
*
* @param c canvas to draw with
* @param x position
* @param y position
* @param index the index of the color to use (in the colors array)
*/
protected void drawForm(Canvas c, float x, float y, int index, Legend legend) {
if (legend.getColors()[index] == ColorTemplate.COLOR_SKIP)
return;
mLegendFormPaint.setColor(legend.getColors()[index]);
float formsize = legend.getFormSize();
float half = formsize / 2f;
switch (legend.getForm()) {
case CIRCLE:
c.drawCircle(x + half, y, half, mLegendFormPaint);
break;
case SQUARE:
c.drawRect(x, y - half, x + formsize, y + half, mLegendFormPaint);
break;
case LINE:
c.drawLine(x, y, x + formsize, y, mLegendFormPaint);
break;
}
}
/**
* Draws the provided label at the given position.
*
* @param c canvas to draw with
* @param x
* @param y
* @param label the label to draw
*/
protected void drawLabel(Canvas c, float x, float y, String label) {
c.drawText(label, x, y, mLegendLabelPaint);
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/LegendRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 3,148 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint.Style;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.data.BubbleData;
import com.github.mikephil.charting.data.BubbleEntry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.BubbleDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.List;
/**
*/
public class BubbleChartRenderer extends DataRenderer {
protected BubbleDataProvider mChart;
public BubbleChartRenderer(BubbleDataProvider chart, ChartAnimator animator,
ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
mChart = chart;
mRenderPaint.setStyle(Style.FILL);
mHighlightPaint.setStyle(Style.STROKE);
mHighlightPaint.setStrokeWidth(Utils.convertDpToPixel(1.5f));
}
@Override
public void initBuffers() {
}
@Override
public void drawData(Canvas c) {
BubbleData bubbleData = mChart.getBubbleData();
for (IBubbleDataSet set : bubbleData.getDataSets()) {
if (set.isVisible() && set.getEntryCount() > 0)
drawDataSet(c, set);
}
}
private float[] sizeBuffer = new float[4];
private float[] pointBuffer = new float[2];
protected float getShapeSize(float entrySize,
float maxSize,
float reference,
boolean normalizeSize) {
final float factor = normalizeSize
? ((maxSize == 0f) ? 1f : (float) Math.sqrt(entrySize / maxSize))
: entrySize;
return reference * factor;
}
protected void drawDataSet(Canvas c, IBubbleDataSet dataSet) {
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
float phaseY = mAnimator.getPhaseY();
BubbleEntry entryFrom = dataSet.getEntryForXIndex(mMinX);
BubbleEntry entryTo = dataSet.getEntryForXIndex(mMaxX);
int minx = Math.max(dataSet.getEntryIndex(entryFrom), 0);
int maxx = Math.min(dataSet.getEntryIndex(entryTo) + 1, dataSet.getEntryCount());
sizeBuffer[0] = 0f;
sizeBuffer[2] = 1f;
trans.pointValuesToPixel(sizeBuffer);
boolean normalizeSize = dataSet.isNormalizeSizeEnabled();
// calcualte the full width of 1 step on the x-axis
final float maxBubbleWidth = Math.abs(sizeBuffer[2] - sizeBuffer[0]);
final float maxBubbleHeight = Math.abs(mViewPortHandler.contentBottom() - mViewPortHandler.contentTop());
final float referenceSize = Math.min(maxBubbleHeight, maxBubbleWidth);
for (int j = minx; j < maxx; j++) {
final BubbleEntry entry = dataSet.getEntryForIndex(j);
pointBuffer[0] = (float) (entry.getXIndex() - minx) * phaseX + (float) minx;
pointBuffer[1] = (float) (entry.getVal()) * phaseY;
trans.pointValuesToPixel(pointBuffer);
float shapeHalf = getShapeSize(entry.getSize(), dataSet.getMaxSize(), referenceSize, normalizeSize) / 2f;
if (!mViewPortHandler.isInBoundsTop(pointBuffer[1] + shapeHalf)
|| !mViewPortHandler.isInBoundsBottom(pointBuffer[1] - shapeHalf))
continue;
if (!mViewPortHandler.isInBoundsLeft(pointBuffer[0] + shapeHalf))
continue;
if (!mViewPortHandler.isInBoundsRight(pointBuffer[0] - shapeHalf))
break;
final int color = dataSet.getColor(entry.getXIndex());
mRenderPaint.setColor(color);
c.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, mRenderPaint);
}
}
@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);
}
}
}
}
@Override
public void drawExtras(Canvas c) {
}
private float[] _hsvBuffer = new float[3];
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
BubbleData bubbleData = mChart.getBubbleData();
float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
float phaseY = mAnimator.getPhaseY();
for (Highlight high : indices) {
final int minDataSetIndex = high.getDataSetIndex() == -1
? 0
: high.getDataSetIndex();
final int maxDataSetIndex = high.getDataSetIndex() == -1
? bubbleData.getDataSetCount()
: (high.getDataSetIndex() + 1);
if (maxDataSetIndex - minDataSetIndex < 1)
continue;
for (int dataSetIndex = minDataSetIndex;
dataSetIndex < maxDataSetIndex;
dataSetIndex++) {
IBubbleDataSet dataSet = bubbleData.getDataSetByIndex(dataSetIndex);
if (dataSet == null || !dataSet.isHighlightEnabled())
continue;
final BubbleEntry entry = (BubbleEntry) bubbleData.getEntryForHighlight(high);
if (entry == null || entry.getXIndex() != high.getXIndex())
continue;
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());
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
sizeBuffer[0] = 0f;
sizeBuffer[2] = 1f;
trans.pointValuesToPixel(sizeBuffer);
boolean normalizeSize = dataSet.isNormalizeSizeEnabled();
// calcualte the full width of 1 step on the x-axis
final float maxBubbleWidth = Math.abs(sizeBuffer[2] - sizeBuffer[0]);
final float maxBubbleHeight = Math.abs(
mViewPortHandler.contentBottom() - mViewPortHandler.contentTop());
final float referenceSize = Math.min(maxBubbleHeight, maxBubbleWidth);
pointBuffer[0] = (float) (entry.getXIndex() - minx) * phaseX + (float) minx;
pointBuffer[1] = (float) (entry.getVal()) * phaseY;
trans.pointValuesToPixel(pointBuffer);
float shapeHalf = getShapeSize(entry.getSize(),
dataSet.getMaxSize(),
referenceSize,
normalizeSize) / 2f;
if (!mViewPortHandler.isInBoundsTop(pointBuffer[1] + shapeHalf)
|| !mViewPortHandler.isInBoundsBottom(pointBuffer[1] - shapeHalf))
continue;
if (!mViewPortHandler.isInBoundsLeft(pointBuffer[0] + shapeHalf))
continue;
if (!mViewPortHandler.isInBoundsRight(pointBuffer[0] - shapeHalf))
break;
if (high.getXIndex() < minx || high.getXIndex() >= maxx)
continue;
final int originalColor = dataSet.getColor(entry.getXIndex());
Color.RGBToHSV(Color.red(originalColor), Color.green(originalColor),
Color.blue(originalColor), _hsvBuffer);
_hsvBuffer[2] *= 0.5f;
final int color = Color.HSVToColor(Color.alpha(originalColor), _hsvBuffer);
mHighlightPaint.setColor(color);
mHighlightPaint.setStrokeWidth(dataSet.getHighlightCircleWidth());
c.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, mHighlightPaint);
}
}
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/BubbleChartRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 2,232 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.charts.CombinedChart;
import com.github.mikephil.charting.charts.CombinedChart.DrawOrder;
import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.data.CombinedData;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
/**
* Renderer class that is responsible for rendering multiple different data-types.
*/
public class CombinedChartRenderer extends DataRenderer {
/**
* all rederers for the different kinds of data this combined-renderer can draw
*/
protected List<DataRenderer> mRenderers;
protected WeakReference<Chart> mChart;
public CombinedChartRenderer(CombinedChart chart, ChartAnimator animator, ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
mChart = new WeakReference<Chart>(chart);
createRenderers(chart, animator, viewPortHandler);
}
/**
* Creates the renderers needed for this combined-renderer in the required order. Also takes the DrawOrder into
* consideration.
*
* @param chart
* @param animator
* @param viewPortHandler
*/
protected void createRenderers(CombinedChart chart, ChartAnimator animator, ViewPortHandler viewPortHandler) {
mRenderers = new ArrayList<>();
DrawOrder[] orders = chart.getDrawOrder();
for (DrawOrder order : orders) {
switch (order) {
case BAR:
if (chart.getBarData() != null)
mRenderers.add(new BarChartRenderer(chart, animator, viewPortHandler));
break;
case BUBBLE:
if (chart.getBubbleData() != null)
mRenderers.add(new BubbleChartRenderer(chart, animator, viewPortHandler));
break;
case LINE:
if (chart.getLineData() != null)
mRenderers.add(new LineChartRenderer(chart, animator, viewPortHandler));
break;
case CANDLE:
if (chart.getCandleData() != null)
mRenderers.add(new CandleStickChartRenderer(chart, animator, viewPortHandler));
break;
case SCATTER:
if (chart.getScatterData() != null)
mRenderers.add(new ScatterChartRenderer(chart, animator, viewPortHandler));
break;
}
}
}
@Override
public void initBuffers() {
for (DataRenderer renderer : mRenderers)
renderer.initBuffers();
}
@Override
public void drawData(Canvas c) {
for (DataRenderer renderer : mRenderers)
renderer.drawData(c);
}
@Override
public void drawValues(Canvas c) {
for (DataRenderer renderer : mRenderers)
renderer.drawValues(c);
}
@Override
public void drawExtras(Canvas c) {
for (DataRenderer renderer : mRenderers)
renderer.drawExtras(c);
}
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
Chart chart = mChart.get();
if (chart == null)
return;
for (DataRenderer renderer : mRenderers) {
ChartData data = null;
if (renderer instanceof BarChartRenderer)
data = ((BarChartRenderer)renderer).mChart.getBarData();
else if (renderer instanceof LineChartRenderer)
data = ((LineChartRenderer)renderer).mChart.getLineData();
else if (renderer instanceof CandleStickChartRenderer)
data = ((CandleStickChartRenderer)renderer).mChart.getCandleData();
else if (renderer instanceof ScatterChartRenderer)
data = ((ScatterChartRenderer)renderer).mChart.getScatterData();
else if (renderer instanceof BubbleChartRenderer)
data = ((BubbleChartRenderer)renderer).mChart.getBubbleData();
int dataIndex = data == null
? -1
: ((CombinedData)chart.getData()).getAllData().indexOf(data);
ArrayList<Highlight> dataIndices = new ArrayList<>();
for (Highlight h : indices) {
if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1)
dataIndices.add(h);
}
renderer.drawHighlighted(c, dataIndices.toArray(new Highlight[dataIndices.size()]));
}
}
@Override
public void calcXBounds(BarLineScatterCandleBubbleDataProvider chart, int xAxisModulus) {
for (DataRenderer renderer : mRenderers)
renderer.calcXBounds(chart, xAxisModulus);
}
/**
* Returns the sub-renderer object at the specified index.
*
* @param index
* @return
*/
public DataRenderer getSubRenderer(int index) {
if (index >= mRenderers.size() || index < 0)
return null;
else
return mRenderers.get(index);
}
/**
* Returns all sub-renderers.
*
* @return
*/
public List<DataRenderer> getSubRenderers() {
return mRenderers;
}
public void setSubRenderers(List<DataRenderer> renderers) {
this.mRenderers = renderers;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/CombinedChartRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 1,181 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* Created by Philipp Jahoda on 25/01/16.
*/
public abstract class LineRadarRenderer extends LineScatterCandleRadarRenderer {
public LineRadarRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
}
/**
* Draws the provided path in filled mode with the provided drawable.
*
* @param c
* @param filledPath
* @param drawable
*/
protected void drawFilledPath(Canvas c, Path filledPath, Drawable drawable) {
if (clipPathSupported()) {
c.save();
c.clipPath(filledPath);
drawable.setBounds((int) mViewPortHandler.contentLeft(),
(int) mViewPortHandler.contentTop(),
(int) mViewPortHandler.contentRight(),
(int) mViewPortHandler.contentBottom());
drawable.draw(c);
c.restore();
} else {
throw new RuntimeException("Fill-drawables not (yet) supported below API level 18, " +
"this code was run on API level " + Utils.getSDKInt() + ".");
}
}
/**
* Draws the provided path in filled mode with the provided color and alpha.
* Special thanks to Angelo Suzuki (path_to_url for this.
*
* @param c
* @param filledPath
* @param fillColor
* @param fillAlpha
*/
protected void drawFilledPath(Canvas c, Path filledPath, int fillColor, int fillAlpha) {
int color = (fillAlpha << 24) | (fillColor & 0xffffff);
if (clipPathSupported()) {
c.save();
c.clipPath(filledPath);
c.drawColor(color);
c.restore();
} else {
// save
Paint.Style previous = mRenderPaint.getStyle();
int previousColor = mRenderPaint.getColor();
// set
mRenderPaint.setStyle(Paint.Style.FILL);
mRenderPaint.setColor(color);
c.drawPath(filledPath, mRenderPaint);
// restore
mRenderPaint.setColor(previousColor);
mRenderPaint.setStyle(previous);
}
}
/**
* Clip path with hardware acceleration only working properly on API level 18 and above.
*
* @return
*/
private boolean clipPathSupported() {
return Utils.getSDKInt() >= 18;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/LineRadarRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 573 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Paint;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.data.CandleData;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.CandleDataProvider;
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.List;
/**/
public class CandleStickChartRenderer extends LineScatterCandleRadarRenderer {
protected CandleDataProvider mChart;
private float[] mShadowBuffers = new float[8];
private float[] mBodyBuffers = new float[4];
private float[] mRangeBuffers = new float[4];
private float[] mOpenBuffers = new float[4];
private float[] mCloseBuffers = new float[4];
public CandleStickChartRenderer(CandleDataProvider chart, ChartAnimator animator,
ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
mChart = chart;
}
@Override
public void initBuffers() {
}
@Override
public void drawData(Canvas c) {
CandleData candleData = mChart.getCandleData();
for (ICandleDataSet set : candleData.getDataSets()) {
if (set.isVisible() && set.getEntryCount() > 0)
drawDataSet(c, set);
}
}
@SuppressWarnings("ResourceAsColor")
protected void drawDataSet(Canvas c, ICandleDataSet dataSet) {
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
float phaseY = mAnimator.getPhaseY();
float barSpace = dataSet.getBarSpace();
boolean showCandleBar = dataSet.getShowCandleBar();
int minx = Math.max(mMinX, 0);
int maxx = Math.min(mMaxX + 1, dataSet.getEntryCount());
mRenderPaint.setStrokeWidth(dataSet.getShadowWidth());
// draw the body
for (int j = minx,
count = (int) Math.ceil((maxx - minx) * phaseX + (float)minx);
j < count;
j++) {
// get the entry
CandleEntry e = dataSet.getEntryForIndex(j);
final int xIndex = e.getXIndex();
if (xIndex < minx || xIndex >= maxx)
continue;
final float open = e.getOpen();
final float close = e.getClose();
final float high = e.getHigh();
final float low = e.getLow();
if (showCandleBar) {
// calculate the shadow
mShadowBuffers[0] = xIndex;
mShadowBuffers[2] = xIndex;
mShadowBuffers[4] = xIndex;
mShadowBuffers[6] = xIndex;
if (open > close) {
mShadowBuffers[1] = high * phaseY;
mShadowBuffers[3] = open * phaseY;
mShadowBuffers[5] = low * phaseY;
mShadowBuffers[7] = close * phaseY;
} else if (open < close) {
mShadowBuffers[1] = high * phaseY;
mShadowBuffers[3] = close * phaseY;
mShadowBuffers[5] = low * phaseY;
mShadowBuffers[7] = open * phaseY;
} else {
mShadowBuffers[1] = high * phaseY;
mShadowBuffers[3] = open * phaseY;
mShadowBuffers[5] = low * phaseY;
mShadowBuffers[7] = mShadowBuffers[3];
}
trans.pointValuesToPixel(mShadowBuffers);
// draw the shadows
if (dataSet.getShadowColorSameAsCandle()) {
if (open > close)
mRenderPaint.setColor(
dataSet.getDecreasingColor() == ColorTemplate.COLOR_NONE ?
dataSet.getColor(j) :
dataSet.getDecreasingColor()
);
else if (open < close)
mRenderPaint.setColor(
dataSet.getIncreasingColor() == ColorTemplate.COLOR_NONE ?
dataSet.getColor(j) :
dataSet.getIncreasingColor()
);
else
mRenderPaint.setColor(
dataSet.getNeutralColor() == ColorTemplate.COLOR_NONE ?
dataSet.getColor(j) :
dataSet.getNeutralColor()
);
} else {
mRenderPaint.setColor(
dataSet.getShadowColor() == ColorTemplate.COLOR_NONE ?
dataSet.getColor(j) :
dataSet.getShadowColor()
);
}
mRenderPaint.setStyle(Paint.Style.STROKE);
c.drawLines(mShadowBuffers, mRenderPaint);
// calculate the body
mBodyBuffers[0] = xIndex - 0.5f + barSpace;
mBodyBuffers[1] = close * phaseY;
mBodyBuffers[2] = (xIndex + 0.5f - barSpace);
mBodyBuffers[3] = open * phaseY;
trans.pointValuesToPixel(mBodyBuffers);
// draw body differently for increasing and decreasing entry
if (open > close) { // decreasing
if (dataSet.getDecreasingColor() == ColorTemplate.COLOR_NONE) {
mRenderPaint.setColor(dataSet.getColor(j));
} else {
mRenderPaint.setColor(dataSet.getDecreasingColor());
}
mRenderPaint.setStyle(dataSet.getDecreasingPaintStyle());
c.drawRect(
mBodyBuffers[0], mBodyBuffers[3],
mBodyBuffers[2], mBodyBuffers[1],
mRenderPaint);
} else if (open < close) {
if (dataSet.getIncreasingColor() == ColorTemplate.COLOR_NONE) {
mRenderPaint.setColor(dataSet.getColor(j));
} else {
mRenderPaint.setColor(dataSet.getIncreasingColor());
}
mRenderPaint.setStyle(dataSet.getIncreasingPaintStyle());
c.drawRect(
mBodyBuffers[0], mBodyBuffers[1],
mBodyBuffers[2], mBodyBuffers[3],
mRenderPaint);
} else { // equal values
if (dataSet.getNeutralColor() == ColorTemplate.COLOR_NONE) {
mRenderPaint.setColor(dataSet.getColor(j));
} else {
mRenderPaint.setColor(dataSet.getNeutralColor());
}
c.drawLine(
mBodyBuffers[0], mBodyBuffers[1],
mBodyBuffers[2], mBodyBuffers[3],
mRenderPaint);
}
} else {
mRangeBuffers[0] = xIndex;
mRangeBuffers[1] = high * phaseY;
mRangeBuffers[2] = xIndex;
mRangeBuffers[3] = low * phaseY;
mOpenBuffers[0] = xIndex - 0.5f + barSpace;
mOpenBuffers[1] = open * phaseY;
mOpenBuffers[2] = xIndex;
mOpenBuffers[3] = open * phaseY;
mCloseBuffers[0] = xIndex + 0.5f - barSpace;
mCloseBuffers[1] = close * phaseY;
mCloseBuffers[2] = xIndex;
mCloseBuffers[3] = close * phaseY;
trans.pointValuesToPixel(mRangeBuffers);
trans.pointValuesToPixel(mOpenBuffers);
trans.pointValuesToPixel(mCloseBuffers);
// draw the ranges
int barColor;
if (open > close)
barColor = dataSet.getDecreasingColor() == ColorTemplate.COLOR_NONE
? dataSet.getColor(j)
: dataSet.getDecreasingColor();
else if (open < close)
barColor = dataSet.getIncreasingColor() == ColorTemplate.COLOR_NONE
? dataSet.getColor(j)
: dataSet.getIncreasingColor();
else
barColor = dataSet.getNeutralColor() == ColorTemplate.COLOR_NONE
? dataSet.getColor(j)
: dataSet.getNeutralColor();
mRenderPaint.setColor(barColor);
c.drawLine(
mRangeBuffers[0], mRangeBuffers[1],
mRangeBuffers[2], mRangeBuffers[3],
mRenderPaint);
c.drawLine(
mOpenBuffers[0], mOpenBuffers[1],
mOpenBuffers[2], mOpenBuffers[3],
mRenderPaint);
c.drawLine(
mCloseBuffers[0], mCloseBuffers[1],
mCloseBuffers[2], mCloseBuffers[3],
mRenderPaint);
}
}
}
@Override
public void drawValues(Canvas c) {
// if values are drawn
if (mChart.getCandleData().getYValCount() < mChart.getMaxVisibleCount()
* mViewPortHandler.getScaleX()) {
List<ICandleDataSet> dataSets = mChart.getCandleData().getDataSets();
for (int i = 0; i < dataSets.size(); i++) {
ICandleDataSet 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());
int minx = Math.max(mMinX, 0);
int maxx = Math.min(mMaxX + 1, dataSet.getEntryCount());
float[] positions = trans.generateTransformedValuesCandle(
dataSet, 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 = dataSet.getEntryForIndex(j / 2 + minx);
drawValue(c, dataSet.getValueFormatter(), entry.getHigh(), entry, i, x, y - yOffset, dataSet.getValueTextColor(j / 2));
}
}
}
}
@Override
public void drawExtras(Canvas c) {
}
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
CandleData candleData = mChart.getCandleData();
for (Highlight high : indices) {
final int minDataSetIndex = high.getDataSetIndex() == -1
? 0
: high.getDataSetIndex();
final int maxDataSetIndex = high.getDataSetIndex() == -1
? candleData.getDataSetCount()
: (high.getDataSetIndex() + 1);
if (maxDataSetIndex - minDataSetIndex < 1)
continue;
for (int dataSetIndex = minDataSetIndex;
dataSetIndex < maxDataSetIndex;
dataSetIndex++) {
int xIndex = high.getXIndex(); // get the
// x-position
ICandleDataSet set = mChart.getCandleData().getDataSetByIndex(dataSetIndex);
if (set == null || !set.isHighlightEnabled())
continue;
CandleEntry e = set.getEntryForXIndex(xIndex);
if (e == null || e.getXIndex() != xIndex)
continue;
float lowValue = e.getLow() * mAnimator.getPhaseY();
float highValue = e.getHigh() * mAnimator.getPhaseY();
float y = (lowValue + highValue) / 2f;
float[] pts = new float[]{
xIndex, y
};
mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts);
// draw the lines
drawHighlightLines(c, pts, set);
}
}
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 2,613 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* Baseclass of all axis renderers.
*
* @author Philipp Jahoda
*/
public abstract class AxisRenderer extends Renderer {
protected Transformer mTrans;
/** paint object for the grid lines */
protected Paint mGridPaint;
/** paint for the x-label values */
protected Paint mAxisLabelPaint;
/** paint for the line surrounding the chart */
protected Paint mAxisLinePaint;
/** paint used for the limit lines */
protected Paint mLimitLinePaint;
public AxisRenderer(ViewPortHandler viewPortHandler, Transformer trans) {
super(viewPortHandler);
this.mTrans = trans;
mAxisLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mGridPaint = new Paint();
mGridPaint.setColor(Color.GRAY);
mGridPaint.setStrokeWidth(1f);
mGridPaint.setStyle(Style.STROKE);
mGridPaint.setAlpha(90);
mAxisLinePaint = new Paint();
mAxisLinePaint.setColor(Color.BLACK);
mAxisLinePaint.setStrokeWidth(1f);
mAxisLinePaint.setStyle(Style.STROKE);
mLimitLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mLimitLinePaint.setStyle(Style.STROKE);
}
/**
* Returns the Paint object used for drawing the axis (labels).
*
* @return
*/
public Paint getPaintAxisLabels() {
return mAxisLabelPaint;
}
/**
* Returns the Paint object that is used for drawing the grid-lines of the
* axis.
*
* @return
*/
public Paint getPaintGrid() {
return mGridPaint;
}
/**
* Returns the Paint object that is used for drawing the axis-line that goes
* alongside the axis.
*
* @return
*/
public Paint getPaintAxisLine() {
return mAxisLinePaint;
}
/**
* Returns the Transformer object used for transforming the axis values.
*
* @return
*/
public Transformer getTransformer() {
return mTrans;
}
/**
* Draws the axis labels to the screen.
*
* @param c
*/
public abstract void renderAxisLabels(Canvas c);
/**
* Draws the grid lines belonging to the axis.
*
* @param c
*/
public abstract void renderGridLines(Canvas c);
/**
* Draws the line that goes alongside the axis.
*
* @param c
*/
public abstract void renderAxisLine(Canvas c);
/**
* Draws the LimitLines associated with this axis to the screen.
*
* @param c
*/
public abstract void renderLimitLines(Canvas c);
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/AxisRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 637 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.charts.RadarChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.RadarData;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
public class RadarChartRenderer extends LineRadarRenderer {
protected RadarChart mChart;
/**
* paint for drawing the web
*/
protected Paint mWebPaint;
protected Paint mHighlightCirclePaint;
public RadarChartRenderer(RadarChart chart, ChartAnimator animator,
ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
mChart = chart;
mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mHighlightPaint.setStyle(Paint.Style.STROKE);
mHighlightPaint.setStrokeWidth(2f);
mHighlightPaint.setColor(Color.rgb(255, 187, 115));
mWebPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mWebPaint.setStyle(Paint.Style.STROKE);
mHighlightCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
}
public Paint getWebPaint() {
return mWebPaint;
}
@Override
public void initBuffers() {
// TODO Auto-generated method stub
}
@Override
public void drawData(Canvas c) {
RadarData radarData = mChart.getData();
int mostEntries = 0;
for (IRadarDataSet set : radarData.getDataSets()) {
if (set.getEntryCount() > mostEntries) {
mostEntries = set.getEntryCount();
}
}
for (IRadarDataSet set : radarData.getDataSets()) {
if (set.isVisible() && set.getEntryCount() > 0) {
drawDataSet(c, set, mostEntries);
}
}
}
/**
* Draws the RadarDataSet
*
* @param c
* @param dataSet
* @param mostEntries the entry count of the dataset with the most entries
*/
protected void drawDataSet(Canvas c, IRadarDataSet dataSet, int mostEntries) {
float phaseX = mAnimator.getPhaseX();
float phaseY = mAnimator.getPhaseY();
float sliceangle = mChart.getSliceAngle();
// calculate the factor that is needed for transforming the value to
// pixels
float factor = mChart.getFactor();
PointF center = mChart.getCenterOffsets();
Path surface = new Path();
boolean hasMovedToPoint = false;
for (int j = 0; j < dataSet.getEntryCount(); j++) {
mRenderPaint.setColor(dataSet.getColor(j));
Entry e = dataSet.getEntryForIndex(j);
PointF p = Utils.getPosition(
center,
(e.getVal() - mChart.getYChartMin()) * factor * phaseY,
sliceangle * j * phaseX + mChart.getRotationAngle());
if (Float.isNaN(p.x))
continue;
if (!hasMovedToPoint) {
surface.moveTo(p.x, p.y);
hasMovedToPoint = true;
} else
surface.lineTo(p.x, p.y);
}
if (dataSet.getEntryCount() > mostEntries) {
// if this is not the largest set, draw a line to the center before closing
surface.lineTo(center.x, center.y);
}
surface.close();
if(dataSet.isDrawFilledEnabled()) {
final Drawable drawable = dataSet.getFillDrawable();
if (drawable != null) {
drawFilledPath(c, surface, drawable);
} else {
drawFilledPath(c, surface, dataSet.getFillColor(), dataSet.getFillAlpha());
}
}
mRenderPaint.setStrokeWidth(dataSet.getLineWidth());
mRenderPaint.setStyle(Paint.Style.STROKE);
// draw the line (only if filled is disabled or alpha is below 255)
if (!dataSet.isDrawFilledEnabled() || dataSet.getFillAlpha() < 255)
c.drawPath(surface, mRenderPaint);
//
// // draw filled
// if (dataSet.isDrawFilledEnabled()) {
// mRenderPaint.setStyle(Paint.Style.FILL);
// mRenderPaint.setAlpha(dataSet.getFillAlpha());
// c.drawPath(surface, mRenderPaint);
// mRenderPaint.setAlpha(255);
// }
}
@Override
public void drawValues(Canvas c) {
float phaseX = mAnimator.getPhaseX();
float phaseY = mAnimator.getPhaseY();
float sliceangle = mChart.getSliceAngle();
// calculate the factor that is needed for transforming the value to
// pixels
float factor = mChart.getFactor();
PointF center = mChart.getCenterOffsets();
float yoffset = Utils.convertDpToPixel(5f);
for (int i = 0; i < mChart.getData().getDataSetCount(); i++) {
IRadarDataSet dataSet = mChart.getData().getDataSetByIndex(i);
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
continue;
// apply the text-styling defined by the DataSet
applyValueTextStyle(dataSet);
for (int j = 0; j < dataSet.getEntryCount(); j++) {
Entry entry = dataSet.getEntryForIndex(j);
PointF p = Utils.getPosition(
center,
(entry.getVal() - mChart.getYChartMin()) * factor * phaseY,
sliceangle * j * phaseX + mChart.getRotationAngle());
drawValue(c, dataSet.getValueFormatter(), entry.getVal(), entry, i, p.x, p.y - yoffset, dataSet.getValueTextColor(j));
}
}
}
@Override
public void drawExtras(Canvas c) {
drawWeb(c);
}
protected void drawWeb(Canvas c) {
float sliceangle = mChart.getSliceAngle();
// calculate the factor that is needed for transforming the value to
// pixels
float factor = mChart.getFactor();
float rotationangle = mChart.getRotationAngle();
PointF center = mChart.getCenterOffsets();
// draw the web lines that come from the center
mWebPaint.setStrokeWidth(mChart.getWebLineWidth());
mWebPaint.setColor(mChart.getWebColor());
mWebPaint.setAlpha(mChart.getWebAlpha());
final int xIncrements = 1 + mChart.getSkipWebLineCount();
for (int i = 0; i < mChart.getData().getXValCount(); i += xIncrements) {
PointF p = Utils.getPosition(
center,
mChart.getYRange() * factor,
sliceangle * i + rotationangle);
c.drawLine(center.x, center.y, p.x, p.y, mWebPaint);
}
// draw the inner-web
mWebPaint.setStrokeWidth(mChart.getWebLineWidthInner());
mWebPaint.setColor(mChart.getWebColorInner());
mWebPaint.setAlpha(mChart.getWebAlpha());
int labelCount = mChart.getYAxis().mEntryCount;
for (int j = 0; j < labelCount; j++) {
for (int i = 0; i < mChart.getData().getXValCount(); i++) {
float r = (mChart.getYAxis().mEntries[j] - mChart.getYChartMin()) * factor;
PointF p1 = Utils.getPosition(center, r, sliceangle * i + rotationangle);
PointF p2 = Utils.getPosition(center, r, sliceangle * (i + 1) + rotationangle);
c.drawLine(p1.x, p1.y, p2.x, p2.y, mWebPaint);
}
}
}
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
float phaseX = mAnimator.getPhaseX();
float phaseY = mAnimator.getPhaseY();
float sliceangle = mChart.getSliceAngle();
float factor = mChart.getFactor();
PointF center = mChart.getCenterOffsets();
for (int i = 0; i < indices.length; i++) {
IRadarDataSet set = mChart.getData()
.getDataSetByIndex(indices[i]
.getDataSetIndex());
if (set == null || !set.isHighlightEnabled())
continue;
// get the index to highlight
int xIndex = indices[i].getXIndex();
Entry e = set.getEntryForXIndex(xIndex);
if (e == null || e.getXIndex() != xIndex)
continue;
int j = set.getEntryIndex(e);
float y = (e.getVal() - mChart.getYChartMin());
if (Float.isNaN(y))
continue;
PointF p = Utils.getPosition(
center,
y * factor * phaseY,
sliceangle * j * phaseX + mChart.getRotationAngle());
float[] pts = new float[]{
p.x, p.y
};
// draw the lines
drawHighlightLines(c, pts, set);
if (set.isDrawHighlightCircleEnabled()) {
if (!Float.isNaN(pts[0]) && !Float.isNaN(pts[1])) {
int strokeColor = set.getHighlightCircleStrokeColor();
if (strokeColor == ColorTemplate.COLOR_NONE) {
strokeColor = set.getColor(0);
}
if (set.getHighlightCircleStrokeAlpha() < 255) {
strokeColor = ColorTemplate.getColorWithAlphaComponent(strokeColor, set.getHighlightCircleStrokeAlpha());
}
drawHighlightCircle(c,
p,
set.getHighlightCircleInnerRadius(),
set.getHighlightCircleOuterRadius(),
set.getHighlightCircleFillColor(),
strokeColor,
set.getHighlightCircleStrokeWidth());
}
}
}
}
public void drawHighlightCircle(Canvas c,
PointF point,
float innerRadius,
float outerRadius,
int fillColor,
int strokeColor,
float strokeWidth) {
c.save();
outerRadius = Utils.convertDpToPixel(outerRadius);
innerRadius = Utils.convertDpToPixel(innerRadius);
if (fillColor != ColorTemplate.COLOR_NONE) {
Path p = new Path();
p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW);
if (innerRadius > 0.f) {
p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW);
}
mHighlightCirclePaint.setColor(fillColor);
mHighlightCirclePaint.setStyle(Paint.Style.FILL);
c.drawPath(p, mHighlightCirclePaint);
}
if (strokeColor != ColorTemplate.COLOR_NONE) {
mHighlightCirclePaint.setColor(strokeColor);
mHighlightCirclePaint.setStyle(Paint.Style.STROKE);
mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth));
c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint);
}
c.restore();
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/RadarChartRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 2,404 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Path;
import com.github.mikephil.charting.components.LimitLine;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.components.YAxis.AxisDependency;
import com.github.mikephil.charting.components.YAxis.YAxisLabelPosition;
import com.github.mikephil.charting.utils.PointD;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.List;
public class YAxisRendererHorizontalBarChart extends YAxisRenderer {
public YAxisRendererHorizontalBarChart(ViewPortHandler viewPortHandler, YAxis yAxis,
Transformer trans) {
super(viewPortHandler, yAxis, trans);
mLimitLinePaint.setTextAlign(Align.LEFT);
}
/**
* Computes the axis values.
*
* @param yMin - the minimum y-value in the data object for this axis
* @param yMax - the maximum y-value in the data object for this axis
*/
public void computeAxis(float yMin, float yMax) {
// calculate the starting and entry point of the y-labels (depending on
// zoom / contentrect bounds)
if (mViewPortHandler.contentHeight() > 10 && !mViewPortHandler.isFullyZoomedOutX()) {
PointD p1 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(),
mViewPortHandler.contentTop());
PointD p2 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentRight(),
mViewPortHandler.contentTop());
if (!mYAxis.isInverted()) {
yMin = (float) p1.x;
yMax = (float) p2.x;
} else {
yMin = (float) p2.x;
yMax = (float) p1.x;
}
}
computeAxisValues(yMin, yMax);
}
/**
* 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;
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());
}
@Override
public void renderAxisLine(Canvas c) {
if (!mYAxis.isEnabled() || !mYAxis.isDrawAxisLineEnabled())
return;
mAxisLinePaint.setColor(mYAxis.getAxisLineColor());
mAxisLinePaint.setStrokeWidth(mYAxis.getAxisLineWidth());
if (mYAxis.getAxisDependency() == AxisDependency.LEFT) {
c.drawLine(mViewPortHandler.contentLeft(),
mViewPortHandler.contentTop(), mViewPortHandler.contentRight(),
mViewPortHandler.contentTop(), mAxisLinePaint);
} else {
c.drawLine(mViewPortHandler.contentLeft(),
mViewPortHandler.contentBottom(), mViewPortHandler.contentRight(),
mViewPortHandler.contentBottom(), mAxisLinePaint);
}
}
/**
* draws the y-labels on the specified x-position
*
* @param fixedPosition
* @param positions
*/
@Override
protected void drawYLabels(Canvas c, float fixedPosition, float[] positions, float offset) {
mAxisLabelPaint.setTypeface(mYAxis.getTypeface());
mAxisLabelPaint.setTextSize(mYAxis.getTextSize());
mAxisLabelPaint.setColor(mYAxis.getTextColor());
for (int i = 0; i < mYAxis.mEntryCount; i++) {
String text = mYAxis.getFormattedLabel(i);
if (!mYAxis.isDrawTopYLabelEntryEnabled() && i >= mYAxis.mEntryCount - 1)
return;
c.drawText(text, positions[i * 2], fixedPosition - offset, mAxisLabelPaint);
}
}
@Override
public void renderGridLines(Canvas c) {
if (!mYAxis.isEnabled())
return;
// pre alloc
float[] position = new float[2];
if (mYAxis.isDrawGridLinesEnabled()) {
mGridPaint.setColor(mYAxis.getGridColor());
mGridPaint.setStrokeWidth(mYAxis.getGridLineWidth());
// draw the horizontal grid
for (int i = 0; i < mYAxis.mEntryCount; i++) {
position[0] = mYAxis.mEntries[i];
mTrans.pointValuesToPixel(position);
c.drawLine(position[0], mViewPortHandler.contentTop(), position[0],
mViewPortHandler.contentBottom(),
mGridPaint);
}
}
if (mYAxis.isDrawZeroLineEnabled()) {
// draw zero line
position[0] = 0f;
mTrans.pointValuesToPixel(position);
drawZeroLine(c, position[0]+1, position[0]+1, mViewPortHandler.contentTop(), mViewPortHandler.contentBottom());
}
}
/**
* Draws the LimitLines associated with this axis to the screen.
* This is the standard XAxis renderer using the YAxis limit lines.
*
* @param c
*/
@Override
public void renderLimitLines(Canvas c) {
List<LimitLine> limitLines = mYAxis.getLimitLines();
if (limitLines == null || limitLines.size() <= 0)
return;
float[] pts = new float[4];
Path limitLinePath = new Path();
for (int i = 0; i < limitLines.size(); i++) {
LimitLine l = limitLines.get(i);
if (!l.isEnabled())
continue;
pts[0] = l.getLimit();
pts[2] = l.getLimit();
mTrans.pointValuesToPixel(pts);
pts[1] = mViewPortHandler.contentTop();
pts[3] = mViewPortHandler.contentBottom();
limitLinePath.moveTo(pts[0], pts[1]);
limitLinePath.lineTo(pts[2], pts[3]);
mLimitLinePaint.setStyle(Paint.Style.STROKE);
mLimitLinePaint.setColor(l.getLineColor());
mLimitLinePaint.setPathEffect(l.getDashPathEffect());
mLimitLinePaint.setStrokeWidth(l.getLineWidth());
c.drawPath(limitLinePath, mLimitLinePaint);
limitLinePath.reset();
String label = l.getLabel();
// if drawing the limit-value label is enabled
if (label != null && !"".equals(label)) {
mLimitLinePaint.setStyle(l.getTextStyle());
mLimitLinePaint.setPathEffect(null);
mLimitLinePaint.setColor(l.getTextColor());
mLimitLinePaint.setTypeface(l.getTypeface());
mLimitLinePaint.setStrokeWidth(0.5f);
mLimitLinePaint.setTextSize(l.getTextSize());
float xOffset = l.getLineWidth() + l.getXOffset();
float yOffset = Utils.convertDpToPixel(2f) + l.getYOffset();
final LimitLine.LimitLabelPosition position = l.getLabelPosition();
if (position == LimitLine.LimitLabelPosition.RIGHT_TOP) {
final float labelLineHeight = Utils.calcTextHeight(mLimitLinePaint, label);
mLimitLinePaint.setTextAlign(Align.LEFT);
c.drawText(label, pts[0] + xOffset, mViewPortHandler.contentTop() + yOffset + labelLineHeight, mLimitLinePaint);
} else if (position == LimitLine.LimitLabelPosition.RIGHT_BOTTOM) {
mLimitLinePaint.setTextAlign(Align.LEFT);
c.drawText(label, pts[0] + xOffset, mViewPortHandler.contentBottom() - yOffset, mLimitLinePaint);
} else if (position == LimitLine.LimitLabelPosition.LEFT_TOP) {
mLimitLinePaint.setTextAlign(Align.RIGHT);
final float labelLineHeight = Utils.calcTextHeight(mLimitLinePaint, label);
c.drawText(label, pts[0] - xOffset, mViewPortHandler.contentTop() + yOffset + labelLineHeight, mLimitLinePaint);
} else {
mLimitLinePaint.setTextAlign(Align.RIGHT);
c.drawText(label, pts[0] - xOffset, mViewPortHandler.contentBottom() - yOffset, mLimitLinePaint);
}
}
}
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/YAxisRendererHorizontalBarChart.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 2,102 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Path;
import android.graphics.PointF;
import com.github.mikephil.charting.components.LimitLine;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.XAxis.XAxisPosition;
import com.github.mikephil.charting.utils.FSize;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.List;
public class XAxisRenderer extends AxisRenderer {
protected XAxis mXAxis;
public XAxisRenderer(ViewPortHandler viewPortHandler, XAxis xAxis, Transformer trans) {
super(viewPortHandler, trans);
this.mXAxis = xAxis;
mAxisLabelPaint.setColor(Color.BLACK);
mAxisLabelPaint.setTextAlign(Align.CENTER);
mAxisLabelPaint.setTextSize(Utils.convertDpToPixel(10f));
}
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);
}
@Override
public void renderAxisLabels(Canvas c) {
if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled())
return;
float yoffset = mXAxis.getYOffset();
mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
mAxisLabelPaint.setColor(mXAxis.getTextColor());
if (mXAxis.getPosition() == XAxisPosition.TOP) {
drawLabels(c, mViewPortHandler.contentTop() - yoffset,
new PointF(0.5f, 1.0f));
} else if (mXAxis.getPosition() == XAxisPosition.TOP_INSIDE) {
drawLabels(c, mViewPortHandler.contentTop() + yoffset + mXAxis.mLabelRotatedHeight,
new PointF(0.5f, 1.0f));
} else if (mXAxis.getPosition() == XAxisPosition.BOTTOM) {
drawLabels(c, mViewPortHandler.contentBottom() + yoffset,
new PointF(0.5f, 0.0f));
} else if (mXAxis.getPosition() == XAxisPosition.BOTTOM_INSIDE) {
drawLabels(c, mViewPortHandler.contentBottom() - yoffset - mXAxis.mLabelRotatedHeight,
new PointF(0.5f, 0.0f));
} else { // BOTH SIDED
drawLabels(c, mViewPortHandler.contentTop() - yoffset,
new PointF(0.5f, 1.0f));
drawLabels(c, mViewPortHandler.contentBottom() + yoffset,
new PointF(0.5f, 0.0f));
}
}
@Override
public void renderAxisLine(Canvas c) {
if (!mXAxis.isDrawAxisLineEnabled() || !mXAxis.isEnabled())
return;
mAxisLinePaint.setColor(mXAxis.getAxisLineColor());
mAxisLinePaint.setStrokeWidth(mXAxis.getAxisLineWidth());
if (mXAxis.getPosition() == XAxisPosition.TOP
|| mXAxis.getPosition() == XAxisPosition.TOP_INSIDE
|| mXAxis.getPosition() == XAxisPosition.BOTH_SIDED) {
c.drawLine(mViewPortHandler.contentLeft(),
mViewPortHandler.contentTop(), mViewPortHandler.contentRight(),
mViewPortHandler.contentTop(), mAxisLinePaint);
}
if (mXAxis.getPosition() == XAxisPosition.BOTTOM
|| mXAxis.getPosition() == XAxisPosition.BOTTOM_INSIDE
|| mXAxis.getPosition() == XAxisPosition.BOTH_SIDED) {
c.drawLine(mViewPortHandler.contentLeft(),
mViewPortHandler.contentBottom(), mViewPortHandler.contentRight(),
mViewPortHandler.contentBottom(), mAxisLinePaint);
}
}
/**
* draws the x-labels on the specified y-position
*
* @param pos
*/
protected void drawLabels(Canvas c, float pos, PointF anchor) {
final float labelRotationAngleDegrees = mXAxis.getLabelRotationAngle();
// pre allocate to save performance (dont allocate in loop)
float[] position = new float[] {
0f, 0f
};
for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) {
position[0] = i;
mTrans.pointValuesToPixel(position);
if (mViewPortHandler.isInBoundsX(position[0])) {
String label = mXAxis.getValues().get(i);
if (mXAxis.isAvoidFirstLastClippingEnabled()) {
// avoid clipping of the last
if (i == mXAxis.getValues().size() - 1 && mXAxis.getValues().size() > 1) {
float width = Utils.calcTextWidth(mAxisLabelPaint, label);
if (width > mViewPortHandler.offsetRight() * 2
&& position[0] + width > mViewPortHandler.getChartWidth())
position[0] -= width / 2;
// avoid clipping of the first
} else if (i == 0) {
float width = Utils.calcTextWidth(mAxisLabelPaint, label);
position[0] += width / 2;
}
}
drawLabel(c, label, i, position[0], pos, anchor, labelRotationAngleDegrees);
}
}
}
protected void drawLabel(Canvas c, String label, int xIndex, float x, float y, PointF anchor, float angleDegrees) {
String formattedLabel = mXAxis.getValueFormatter().getXValue(label, xIndex, mViewPortHandler);
Utils.drawXAxisValue(c, formattedLabel, x, y, mAxisLabelPaint, anchor, angleDegrees);
}
@Override
public void renderGridLines(Canvas c) {
if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled())
return;
// pre alloc
float[] position = new float[] {
0f, 0f
};
mGridPaint.setColor(mXAxis.getGridColor());
mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth());
mGridPaint.setPathEffect(mXAxis.getGridDashPathEffect());
Path gridLinePath = new Path();
for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) {
position[0] = i;
mTrans.pointValuesToPixel(position);
if (position[0] >= mViewPortHandler.offsetLeft()
&& position[0] <= mViewPortHandler.getChartWidth()) {
gridLinePath.moveTo(position[0], mViewPortHandler.contentBottom());
gridLinePath.lineTo(position[0], mViewPortHandler.contentTop());
// draw a path because lines don't support dashing on lower android versions
c.drawPath(gridLinePath, mGridPaint);
}
gridLinePath.reset();
}
}
/**
* Draws the LimitLines associated with this axis to the screen.
*
* @param c
*/
@Override
public void renderLimitLines(Canvas c) {
List<LimitLine> limitLines = mXAxis.getLimitLines();
if (limitLines == null || limitLines.size() <= 0)
return;
float[] position = new float[2];
for (int i = 0; i < limitLines.size(); i++) {
LimitLine l = limitLines.get(i);
if(!l.isEnabled())
continue;
position[0] = l.getLimit();
position[1] = 0.f;
mTrans.pointValuesToPixel(position);
renderLimitLineLine(c, l, position);
renderLimitLineLabel(c, l, position, 2.f + l.getYOffset());
}
}
float[] mLimitLineSegmentsBuffer = new float[4];
private Path mLimitLinePath = new Path();
public void renderLimitLineLine(Canvas c, LimitLine limitLine, float[] position)
{
mLimitLineSegmentsBuffer[0] = position[0];
mLimitLineSegmentsBuffer[1] = mViewPortHandler.contentTop();
mLimitLineSegmentsBuffer[2] = position[0];
mLimitLineSegmentsBuffer[3] = mViewPortHandler.contentBottom();
mLimitLinePath.reset();
mLimitLinePath.moveTo(mLimitLineSegmentsBuffer[0], mLimitLineSegmentsBuffer[1]);
mLimitLinePath.lineTo(mLimitLineSegmentsBuffer[2], mLimitLineSegmentsBuffer[3]);
mLimitLinePaint.setStyle(Paint.Style.STROKE);
mLimitLinePaint.setColor(limitLine.getLineColor());
mLimitLinePaint.setStrokeWidth(limitLine.getLineWidth());
mLimitLinePaint.setPathEffect(limitLine.getDashPathEffect());
c.drawPath(mLimitLinePath, mLimitLinePaint);
}
public void renderLimitLineLabel(Canvas c, LimitLine limitLine, float[] position, float yOffset)
{
String label = limitLine.getLabel();
// if drawing the limit-value label is enabled
if (label != null && !"".equals(label)) {
mLimitLinePaint.setStyle(limitLine.getTextStyle());
mLimitLinePaint.setPathEffect(null);
mLimitLinePaint.setColor(limitLine.getTextColor());
mLimitLinePaint.setStrokeWidth(0.5f);
mLimitLinePaint.setTextSize(limitLine.getTextSize());
float xOffset = limitLine.getLineWidth() + limitLine.getXOffset();
final LimitLine.LimitLabelPosition labelPosition = limitLine.getLabelPosition();
if (labelPosition == LimitLine.LimitLabelPosition.RIGHT_TOP) {
final float labelLineHeight = Utils.calcTextHeight(mLimitLinePaint, label);
mLimitLinePaint.setTextAlign(Align.LEFT);
c.drawText(label, position[0] + xOffset, mViewPortHandler.contentTop() + yOffset + labelLineHeight, mLimitLinePaint);
} else if (labelPosition == LimitLine.LimitLabelPosition.RIGHT_BOTTOM) {
mLimitLinePaint.setTextAlign(Align.LEFT);
c.drawText(label, position[0] + xOffset, mViewPortHandler.contentBottom() - yOffset, mLimitLinePaint);
} else if (labelPosition == LimitLine.LimitLabelPosition.LEFT_TOP) {
mLimitLinePaint.setTextAlign(Align.RIGHT);
final float labelLineHeight = Utils.calcTextHeight(mLimitLinePaint, label);
c.drawText(label, position[0] - xOffset, mViewPortHandler.contentTop() + yOffset + labelLineHeight, mLimitLinePaint);
} else {
mLimitLinePaint.setTextAlign(Align.RIGHT);
c.drawText(label, position[0] - xOffset, mViewPortHandler.contentBottom() - yOffset, mLimitLinePaint);
}
}
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/XAxisRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 2,633 |
```java
package com.github.mikephil.charting.renderer;
import com.github.mikephil.charting.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* Abstract baseclass of all Renderers.
*
* @author Philipp Jahoda
*/
public abstract class Renderer {
/**
* the component that handles the drawing area of the chart and it's offsets
*/
protected ViewPortHandler mViewPortHandler;
/** the minimum value on the x-axis that should be plotted */
protected int mMinX = 0;
/** the maximum value on the x-axis that should be plotted */
protected int mMaxX = 0;
public Renderer(ViewPortHandler viewPortHandler) {
this.mViewPortHandler = viewPortHandler;
}
/**
* Returns true if the specified value fits in between the provided min
* and max bounds, false if not.
*
* @param val
* @param min
* @param max
* @return
*/
protected boolean fitsBounds(float val, float min, float max) {
return !(val < min || val > max);
}
/**
* Calculates the minimum and maximum x-value the chart can currently
* display (with the given zoom level). -> mMinX, mMaxX
*
* @param dataProvider
* @param xAxisModulus
*/
public void calcXBounds(BarLineScatterCandleBubbleDataProvider dataProvider, int xAxisModulus) {
int low = dataProvider.getLowestVisibleXIndex();
int high = dataProvider.getHighestVisibleXIndex();
int subLow = (low % xAxisModulus == 0) ? xAxisModulus : 0;
mMinX = Math.max((low / xAxisModulus) * (xAxisModulus) - subLow, 0);
mMaxX = Math.min((high / xAxisModulus) * (xAxisModulus) + xAxisModulus, (int) dataProvider.getXChartMax());
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/Renderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 452 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.drawable.Drawable;
import android.util.Log;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.lang.ref.WeakReference;
import java.util.List;
public class LineChartRenderer extends LineRadarRenderer {
protected LineDataProvider mChart;
/**
* paint for the inner circle of the value indicators
*/
protected Paint mCirclePaintInner;
/**
* Bitmap object used for drawing the paths (otherwise they are too long if
* rendered directly on the canvas)
*/
protected WeakReference<Bitmap> mDrawBitmap;
/**
* on this canvas, the paths are rendered, it is initialized with the
* pathBitmap
*/
protected Canvas mBitmapCanvas;
/**
* the bitmap configuration to be used
*/
protected Bitmap.Config mBitmapConfig = Bitmap.Config.ARGB_8888;
protected Path cubicPath = new Path();
protected Path cubicFillPath = new Path();
public LineChartRenderer(LineDataProvider chart, ChartAnimator animator,
ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
mChart = chart;
mCirclePaintInner = new Paint(Paint.ANTI_ALIAS_FLAG);
mCirclePaintInner.setStyle(Paint.Style.FILL);
mCirclePaintInner.setColor(Color.WHITE);
}
@Override
public void initBuffers() {
}
@Override
public void drawData(Canvas c) {
int width = (int) mViewPortHandler.getChartWidth();
int height = (int) mViewPortHandler.getChartHeight();
if (mDrawBitmap == null
|| (mDrawBitmap.get().getWidth() != width)
|| (mDrawBitmap.get().getHeight() != height)) {
if (width > 0 && height > 0) {
mDrawBitmap = new WeakReference<>(Bitmap.createBitmap(width, height, mBitmapConfig));
mBitmapCanvas = new Canvas(mDrawBitmap.get());
} else
return;
}
mDrawBitmap.get().eraseColor(Color.TRANSPARENT);
LineData lineData = mChart.getLineData();
for (ILineDataSet set : lineData.getDataSets()) {
if (set.isVisible() && set.getEntryCount() > 0)
drawDataSet(c, set);
}
c.drawBitmap(mDrawBitmap.get(), 0, 0, mRenderPaint);
}
protected void drawDataSet(Canvas c, ILineDataSet dataSet) {
if (dataSet.getEntryCount() < 1)
return;
mRenderPaint.setStrokeWidth(dataSet.getLineWidth());
mRenderPaint.setPathEffect(dataSet.getDashPathEffect());
switch (dataSet.getMode()) {
default:
case LINEAR:
case STEPPED:
drawLinear(c, dataSet);
break;
case CUBIC_BEZIER:
drawCubicBezier(c, dataSet);
break;
case HORIZONTAL_BEZIER:
drawHorizontalBezier(c, dataSet);
break;
}
mRenderPaint.setPathEffect(null);
}
/**
* Draws a cubic line.
*
* @param c
* @param dataSet
*/
protected void drawHorizontalBezier(Canvas c, ILineDataSet dataSet) {
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
int entryCount = dataSet.getEntryCount();
Entry entryFrom = dataSet.getEntryForXIndex((mMinX < 0) ? 0 : mMinX, DataSet.Rounding.DOWN);
Entry entryTo = dataSet.getEntryForXIndex(mMaxX, DataSet.Rounding.UP);
int diff = (entryFrom == entryTo) ? 1 : 0;
int minx = Math.max(dataSet.getEntryIndex(entryFrom) - diff, 0);
int maxx = Math.min(Math.max(minx + 2, dataSet.getEntryIndex(entryTo) + 1), entryCount);
float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
float phaseY = mAnimator.getPhaseY();
cubicPath.reset();
int size = (int) Math.ceil((maxx - minx) * phaseX + minx);
if (size - minx >= 2) {
Entry prev = dataSet.getEntryForIndex(minx);
Entry cur = prev;
// let the spline start
cubicPath.moveTo(cur.getXIndex(), cur.getVal() * phaseY);
for (int j = minx + 1, count = Math.min(size, entryCount); j < count; j++) {
prev = dataSet.getEntryForIndex(j - 1);
cur = dataSet.getEntryForIndex(j);
final float cpx = (float) (prev.getXIndex())
+ (float) (cur.getXIndex() - prev.getXIndex()) / 2.0f;
cubicPath.cubicTo(
cpx, prev.getVal() * phaseY,
cpx, cur.getVal() * phaseY,
cur.getXIndex(), cur.getVal() * phaseY);
}
}
// if filled is enabled, close the path
if (dataSet.isDrawFilledEnabled()) {
cubicFillPath.reset();
cubicFillPath.addPath(cubicPath);
// create a new path, this is bad for performance
drawCubicFill(mBitmapCanvas, dataSet, cubicFillPath, trans,
minx, size);
}
mRenderPaint.setColor(dataSet.getColor());
mRenderPaint.setStyle(Paint.Style.STROKE);
trans.pathValueToPixel(cubicPath);
mBitmapCanvas.drawPath(cubicPath, mRenderPaint);
mRenderPaint.setPathEffect(null);
}
protected void drawCubicBezier(Canvas c, ILineDataSet dataSet) {
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
int entryCount = dataSet.getEntryCount();
Entry entryFrom = dataSet.getEntryForXIndex((mMinX < 0) ? 0 : mMinX, DataSet.Rounding.DOWN);
Entry entryTo = dataSet.getEntryForXIndex(mMaxX, DataSet.Rounding.UP);
int diff = (entryFrom == entryTo) ? 1 : 0;
int minx = Math.max(dataSet.getEntryIndex(entryFrom) - diff - 1, 0);
int maxx = Math.min(Math.max(minx + 2, dataSet.getEntryIndex(entryTo) + 1), entryCount);
float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
float phaseY = mAnimator.getPhaseY();
float intensity = dataSet.getCubicIntensity();
cubicPath.reset();
int size = (int) Math.ceil((maxx - minx) * phaseX + minx);
if (size - minx >= 2) {
float prevDx;
float prevDy;
float curDx;
float curDy;
Entry prevPrev = dataSet.getEntryForIndex(minx);
Entry prev = prevPrev;
Entry cur = prev;
Entry next = dataSet.getEntryForIndex(minx + 1);
// let the spline start
cubicPath.moveTo(cur.getXIndex(), cur.getVal() * phaseY);
for (int j = minx + 1, count = Math.min(size, entryCount); j < count; j++) {
prevPrev = dataSet.getEntryForIndex(j == 1 ? 0 : j - 2);
prev = dataSet.getEntryForIndex(j - 1);
cur = dataSet.getEntryForIndex(j);
next = entryCount > j + 1 ? dataSet.getEntryForIndex(j + 1) : cur;
prevDx = (cur.getXIndex() - prevPrev.getXIndex()) * intensity;
prevDy = (cur.getVal() - prevPrev.getVal()) * intensity;
curDx = (next.getXIndex() - prev.getXIndex()) * intensity;
curDy = (next.getVal() - prev.getVal()) * intensity;
cubicPath.cubicTo(prev.getXIndex() + prevDx, (prev.getVal() + prevDy) * phaseY,
cur.getXIndex() - curDx,
(cur.getVal() - curDy) * phaseY, cur.getXIndex(), cur.getVal() * phaseY);
}
}
// if filled is enabled, close the path
if (dataSet.isDrawFilledEnabled()) {
cubicFillPath.reset();
cubicFillPath.addPath(cubicPath);
// create a new path, this is bad for performance
drawCubicFill(mBitmapCanvas, dataSet, cubicFillPath, trans,
minx, size);
}
mRenderPaint.setColor(dataSet.getColor());
mRenderPaint.setStyle(Paint.Style.STROKE);
trans.pathValueToPixel(cubicPath);
mBitmapCanvas.drawPath(cubicPath, mRenderPaint);
mRenderPaint.setPathEffect(null);
}
protected void drawCubicFill(Canvas c, ILineDataSet dataSet, Path spline, Transformer trans,
int from, int to) {
if (to - from <= 1)
return;
float fillMin = dataSet.getFillFormatter()
.getFillLinePosition(dataSet, mChart);
// Take the from/to xIndex from the entries themselves,
// so missing entries won't screw up the filling.
// What we need to draw is line from points of the xIndexes - not arbitrary entry indexes!
final Entry toEntry = dataSet.getEntryForIndex(to - 1);
final Entry fromEntry = dataSet.getEntryForIndex(from);
final float xTo = toEntry == null ? 0 : toEntry.getXIndex();
final float xFrom = fromEntry == null ? 0 : fromEntry.getXIndex();
spline.lineTo(xTo, fillMin);
spline.lineTo(xFrom, fillMin);
spline.close();
trans.pathValueToPixel(spline);
final Drawable drawable = dataSet.getFillDrawable();
if (drawable != null) {
drawFilledPath(c, spline, drawable);
} else {
drawFilledPath(c, spline, dataSet.getFillColor(), dataSet.getFillAlpha());
}
}
private float[] mLineBuffer = new float[4];
/**
* Draws a normal line.
*
* @param c
* @param dataSet
*/
protected void drawLinear(Canvas c, ILineDataSet dataSet) {
int entryCount = dataSet.getEntryCount();
final boolean isDrawSteppedEnabled = dataSet.isDrawSteppedEnabled();
final int pointsPerEntryPair = isDrawSteppedEnabled ? 4 : 2;
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
float phaseY = mAnimator.getPhaseY();
mRenderPaint.setStyle(Paint.Style.STROKE);
Canvas canvas;
// if the data-set is dashed, draw on bitmap-canvas
if (dataSet.isDashedLineEnabled()) {
canvas = mBitmapCanvas;
} else {
canvas = c;
}
Entry entryFrom = dataSet.getEntryForXIndex((mMinX < 0) ? 0 : mMinX, DataSet.Rounding.DOWN);
Entry entryTo = dataSet.getEntryForXIndex(mMaxX, DataSet.Rounding.UP);
int diff = (entryFrom == entryTo) ? 1 : 0;
int minx = Math.max(dataSet.getEntryIndex(entryFrom) - diff, 0);
int maxx = Math.min(Math.max(minx + 2, dataSet.getEntryIndex(entryTo) + 1), entryCount);
final int count = (int) (Math.ceil((float) (maxx - minx) * phaseX + (float) (minx)));
// more than 1 color
if (dataSet.getColors().size() > 1) {
if (mLineBuffer.length != pointsPerEntryPair * 2)
mLineBuffer = new float[pointsPerEntryPair * 2];
for (int j = minx;
j < count;
j++) {
if (count > 1 && j == count - 1) {
// Last point, we have already drawn a line to this point
break;
}
Entry e = dataSet.getEntryForIndex(j);
if (e == null)
continue;
mLineBuffer[0] = e.getXIndex();
mLineBuffer[1] = e.getVal() * phaseY;
if (j + 1 < count) {
e = dataSet.getEntryForIndex(j + 1);
if (e == null)
break;
if (isDrawSteppedEnabled) {
mLineBuffer[2] = e.getXIndex();
mLineBuffer[3] = mLineBuffer[1];
mLineBuffer[4] = mLineBuffer[2];
mLineBuffer[5] = mLineBuffer[3];
mLineBuffer[6] = e.getXIndex();
mLineBuffer[7] = e.getVal() * phaseY;
} else {
mLineBuffer[2] = e.getXIndex();
mLineBuffer[3] = e.getVal() * phaseY;
}
} else {
mLineBuffer[2] = mLineBuffer[0];
mLineBuffer[3] = mLineBuffer[1];
}
trans.pointValuesToPixel(mLineBuffer);
if (!mViewPortHandler.isInBoundsRight(mLineBuffer[0]))
break;
// make sure the lines don't do shitty things outside
// bounds
if (!mViewPortHandler.isInBoundsLeft(mLineBuffer[2])
|| (!mViewPortHandler.isInBoundsTop(mLineBuffer[1]) && !mViewPortHandler
.isInBoundsBottom(mLineBuffer[3]))
|| (!mViewPortHandler.isInBoundsTop(mLineBuffer[1]) && !mViewPortHandler
.isInBoundsBottom(mLineBuffer[3])))
continue;
// get the color that is set for this line-segment
mRenderPaint.setColor(dataSet.getColor(j));
canvas.drawLines(mLineBuffer, 0, pointsPerEntryPair * 2, mRenderPaint);
}
} else { // only one color per dataset
if (mLineBuffer.length != Math.max((entryCount - 1) * pointsPerEntryPair, pointsPerEntryPair) * 2)
mLineBuffer = new float[Math.max((entryCount - 1) * pointsPerEntryPair, pointsPerEntryPair) * 2];
Entry e1, e2;
e1 = dataSet.getEntryForIndex(minx);
if (e1 != null) {
int j = 0;
for (int x = count > 1 ? minx + 1 : minx; x < count; x++) {
e1 = dataSet.getEntryForIndex(x == 0 ? 0 : (x - 1));
e2 = dataSet.getEntryForIndex(x);
if (e1 == null || e2 == null)
continue;
mLineBuffer[j++] = e1.getXIndex();
mLineBuffer[j++] = e1.getVal() * phaseY;
if (isDrawSteppedEnabled) {
mLineBuffer[j++] = e2.getXIndex();
mLineBuffer[j++] = e1.getVal() * phaseY;
mLineBuffer[j++] = e2.getXIndex();
mLineBuffer[j++] = e1.getVal() * phaseY;
}
mLineBuffer[j++] = e2.getXIndex();
mLineBuffer[j++] = e2.getVal() * phaseY;
}
if (j > 0) {
trans.pointValuesToPixel(mLineBuffer);
final int size =
Math.max((count - minx - 1) * pointsPerEntryPair, pointsPerEntryPair) *
2;
mRenderPaint.setColor(dataSet.getColor());
canvas.drawLines(mLineBuffer, 0, size,
mRenderPaint);
}
}
}
mRenderPaint.setPathEffect(null);
// if drawing filled is enabled
if (dataSet.isDrawFilledEnabled() && entryCount > 0) {
drawLinearFill(c, dataSet, minx, maxx, trans);
}
}
protected void drawLinearFill(Canvas c, ILineDataSet dataSet, int minx,
int maxx,
Transformer trans) {
Path filled = generateFilledPath(
dataSet, minx, maxx);
trans.pathValueToPixel(filled);
final Drawable drawable = dataSet.getFillDrawable();
if (drawable != null) {
drawFilledPath(c, filled, drawable);
} else {
drawFilledPath(c, filled, dataSet.getFillColor(), dataSet.getFillAlpha());
}
}
/**
* Generates the path that is used for filled drawing.
*
* @param dataSet
* @return
*/
private Path generateFilledPath(ILineDataSet dataSet, int from, int to) {
float fillMin = dataSet.getFillFormatter().getFillLinePosition(dataSet, mChart);
float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
float phaseY = mAnimator.getPhaseY();
final boolean isDrawSteppedEnabled = dataSet.isDrawSteppedEnabled();
Path filled = new Path();
Entry entry = dataSet.getEntryForIndex(from);
filled.moveTo(entry.getXIndex(), fillMin);
filled.lineTo(entry.getXIndex(), entry.getVal() * phaseY);
// create a new path
for (int x = from + 1, count = (int) Math.ceil((to - from) * phaseX + from); x < count; x++) {
Entry e = dataSet.getEntryForIndex(x);
if (isDrawSteppedEnabled) {
final Entry ePrev = dataSet.getEntryForIndex(x - 1);
if (ePrev == null)
continue;
filled.lineTo(e.getXIndex(), ePrev.getVal() * phaseY);
}
filled.lineTo(e.getXIndex(), e.getVal() * phaseY);
}
// close up
filled.lineTo(
dataSet.getEntryForIndex(
Math.max(
Math.min((int) Math.ceil((to - from) * phaseX + from) - 1,
dataSet.getEntryCount() - 1), 0)).getXIndex(), fillMin);
filled.close();
return filled;
}
@Override
public void drawValues(Canvas c) {
if (mChart.getLineData().getYValCount() < mChart.getMaxVisibleCount()
* mViewPortHandler.getScaleX()) {
List<ILineDataSet> dataSets = mChart.getLineData().getDataSets();
for (int i = 0; i < dataSets.size(); i++) {
ILineDataSet 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());
// make sure the values do not interfear with the circles
int valOffset = (int) (dataSet.getCircleRadius() * 1.75f);
if (!dataSet.isDrawCirclesEnabled())
valOffset = valOffset / 2;
int entryCount = dataSet.getEntryCount();
Entry entryFrom = dataSet.getEntryForXIndex((mMinX < 0) ? 0 : mMinX,
DataSet.Rounding.DOWN);
Entry entryTo = dataSet.getEntryForXIndex(mMaxX, DataSet.Rounding.UP);
int diff = (entryFrom == entryTo) ? 1 : 0;
if (dataSet.getMode() == LineDataSet.Mode.CUBIC_BEZIER)
diff += 1;
int minx = Math.max(dataSet.getEntryIndex(entryFrom) - diff, 0);
int maxx = Math.min(Math.max(minx + 2, dataSet.getEntryIndex(entryTo) + 1), entryCount);
float[] positions = trans.generateTransformedValuesLine(
dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), 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;
Entry entry = dataSet.getEntryForIndex(j / 2 + minx);
drawValue(c, dataSet.getValueFormatter(), entry.getVal(), entry, i, x,
y - valOffset, dataSet.getValueTextColor(j / 2));
}
}
}
}
@Override
public void drawExtras(Canvas c) {
drawCircles(c);
}
private Path mCirclePathBuffer = new Path();
protected void drawCircles(Canvas c) {
mRenderPaint.setStyle(Paint.Style.FILL);
float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
float phaseY = mAnimator.getPhaseY();
float[] circlesBuffer = new float[2];
List<ILineDataSet> dataSets = mChart.getLineData().getDataSets();
for (int i = 0; i < dataSets.size(); i++) {
ILineDataSet dataSet = dataSets.get(i);
if (!dataSet.isVisible() || !dataSet.isDrawCirclesEnabled() ||
dataSet.getEntryCount() == 0)
continue;
mCirclePaintInner.setColor(dataSet.getCircleHoleColor());
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
int entryCount = dataSet.getEntryCount();
Entry entryFrom = dataSet.getEntryForXIndex((mMinX < 0) ? 0 : mMinX,
DataSet.Rounding.DOWN);
Entry entryTo = dataSet.getEntryForXIndex(mMaxX, DataSet.Rounding.UP);
int diff = (entryFrom == entryTo) ? 1 : 0;
if (dataSet.getMode() == LineDataSet.Mode.CUBIC_BEZIER)
diff += 1;
int minx = Math.max(dataSet.getEntryIndex(entryFrom) - diff, 0);
int maxx = Math.min(Math.max(minx + 2, dataSet.getEntryIndex(entryTo) + 1), entryCount);
float circleRadius = dataSet.getCircleRadius();
float circleHoleRadius = dataSet.getCircleHoleRadius();
boolean drawCircleHole = dataSet.isDrawCircleHoleEnabled() &&
circleHoleRadius < circleRadius &&
circleHoleRadius > 0.f;
boolean drawTransparentCircleHole = drawCircleHole &&
dataSet.getCircleHoleColor() == ColorTemplate.COLOR_NONE;
for (int j = minx,
count = (int) Math.ceil((maxx - minx) * phaseX + minx);
j < count;
j++) {
Entry e = dataSet.getEntryForIndex(j);
if (e == null)
break;
circlesBuffer[0] = e.getXIndex();
circlesBuffer[1] = e.getVal() * phaseY;
trans.pointValuesToPixel(circlesBuffer);
if (!mViewPortHandler.isInBoundsRight(circlesBuffer[0]))
break;
// make sure the circles don't do shitty things outside
// bounds
if (!mViewPortHandler.isInBoundsLeft(circlesBuffer[0]) ||
!mViewPortHandler.isInBoundsY(circlesBuffer[1]))
continue;
mRenderPaint.setColor(dataSet.getCircleColor(j));
if (drawTransparentCircleHole) {
// Begin path for circle with hole
mCirclePathBuffer.reset();
mCirclePathBuffer.addCircle(circlesBuffer[0], circlesBuffer[1],
circleRadius,
Path.Direction.CW);
// Cut hole in path
mCirclePathBuffer.addCircle(circlesBuffer[0], circlesBuffer[1],
circleHoleRadius,
Path.Direction.CCW);
// Fill in-between
c.drawPath(mCirclePathBuffer, mRenderPaint);
} else {
c.drawCircle(circlesBuffer[0], circlesBuffer[1],
circleRadius,
mRenderPaint);
if (drawCircleHole) {
c.drawCircle(circlesBuffer[0], circlesBuffer[1],
circleHoleRadius,
mCirclePaintInner);
}
}
}
}
}
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
LineData lineData = mChart.getLineData();
for (Highlight high : indices) {
final int minDataSetIndex = high.getDataSetIndex() == -1
? 0
: high.getDataSetIndex();
final int maxDataSetIndex = high.getDataSetIndex() == -1
? lineData.getDataSetCount()
: (high.getDataSetIndex() + 1);
if (maxDataSetIndex - minDataSetIndex < 1)
continue;
for (int dataSetIndex = minDataSetIndex;
dataSetIndex < maxDataSetIndex;
dataSetIndex++) {
ILineDataSet set = lineData.getDataSetByIndex(dataSetIndex);
if (set == null || !set.isHighlightEnabled())
continue;
int xIndex = high.getXIndex(); // get the
// x-position
if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX())
continue;
final float yVal = set.getYValForXIndex(xIndex);
/**/
/* if (Float.isNaN(yVal))
continue;*/
float y = yVal * mAnimator.getPhaseY(); // get
// the
// y-position
float[] pts = new float[]{
xIndex, y
};
mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts);
// draw the lines
drawHighlightLines(c, pts, set);
}
}
}
/**
* Sets the Bitmap.Config to be used by this renderer.
* Default: Bitmap.Config.ARGB_8888
* Use Bitmap.Config.ARGB_4444 to consume less memory.
*
* @param config
*/
public void setBitmapConfig(Bitmap.Config config) {
mBitmapConfig = config;
releaseBitmap();
}
/**
* Returns the Bitmap.Config that is used by this renderer.
*
* @return
*/
public Bitmap.Config getBitmapConfig() {
return mBitmapConfig;
}
/**
* Releases the drawing bitmap. This should be called when {@link LineChart#onDetachedFromWindow()}.
*/
public void releaseBitmap() {
if (mBitmapCanvas != null) {
mBitmapCanvas.setBitmap(null);
mBitmapCanvas = null;
}
if (mDrawBitmap != null) {
mDrawBitmap.get().recycle();
mDrawBitmap.clear();
mDrawBitmap = null;
}
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/LineChartRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 6,033 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.PointF;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
public class XAxisRendererBarChart extends XAxisRenderer {
protected BarChart mChart;
public XAxisRendererBarChart(ViewPortHandler viewPortHandler, XAxis xAxis, Transformer trans,
BarChart chart) {
super(viewPortHandler, xAxis, trans);
this.mChart = chart;
}
/**
* draws the x-labels on the specified y-position
*
* @param pos
*/
@Override
protected void drawLabels(Canvas c, float pos, PointF anchor) {
final float labelRotationAngleDegrees = mXAxis.getLabelRotationAngle();
// pre allocate to save performance (dont allocate in loop)
float[] position = new float[] {
0f, 0f
};
BarData bd = mChart.getData();
int step = bd.getDataSetCount();
for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) {
position[0] = i * step + i * bd.getGroupSpace()
+ bd.getGroupSpace() / 2f;
// consider groups (center label for each group)
if (step > 1) {
position[0] += ((float) step - 1f) / 2f;
}
mTrans.pointValuesToPixel(position);
if (mViewPortHandler.isInBoundsX(position[0]) && i >= 0
&& i < mXAxis.getValues().size()) {
String label = mXAxis.getValues().get(i);
if (mXAxis.isAvoidFirstLastClippingEnabled()) {
// avoid clipping of the last
if (i == mXAxis.getValues().size() - 1) {
float width = Utils.calcTextWidth(mAxisLabelPaint, label);
if (position[0] + width / 2.f > mViewPortHandler.contentRight())
position[0] = mViewPortHandler.contentRight() - (width / 2.f);
// avoid clipping of the first
} else if (i == 0) {
float width = Utils.calcTextWidth(mAxisLabelPaint, label);
if (position[0] - width / 2.f < mViewPortHandler.contentLeft())
position[0] = mViewPortHandler.contentLeft() + (width / 2.f);
}
}
drawLabel(c, label, i, position[0], pos, anchor, labelRotationAngleDegrees);
}
}
}
@Override
public void renderGridLines(Canvas c) {
if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled())
return;
float[] position = new float[] {
0f, 0f
};
mGridPaint.setColor(mXAxis.getGridColor());
mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth());
BarData bd = mChart.getData();
int step = bd.getDataSetCount();
for (int i = mMinX; i < mMaxX; i += mXAxis.mAxisLabelModulus) {
position[0] = i * step + i * bd.getGroupSpace() - 0.5f;
mTrans.pointValuesToPixel(position);
if (mViewPortHandler.isInBoundsX(position[0])) {
c.drawLine(position[0], mViewPortHandler.offsetTop(), position[0],
mViewPortHandler.contentBottom(), mGridPaint);
}
}
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/XAxisRendererBarChart.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 839 |
```java
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
import java.util.List;
public class BubbleDataSet extends BarLineScatterCandleBubbleDataSet<BubbleEntry> implements IBubbleDataSet {
// NOTE: Do not initialize these, as the calculate is called by the super,
// and the initializers are called after that and can reset the values
protected float mXMax;
protected float mXMin;
protected float mMaxSize;
protected boolean mNormalizeSize = true;
private float mHighlightCircleWidth = 2.5f;
public BubbleDataSet(List<BubbleEntry> yVals, String label) {
super(yVals, label);
}
@Override
public void setHighlightCircleWidth(float width) {
mHighlightCircleWidth = Utils.convertDpToPixel(width);
}
@Override
public float getHighlightCircleWidth() {
return mHighlightCircleWidth;
}
@Override
public void calcMinMax(int start, int end) {
if (mYVals == null)
return;
if (mYVals.isEmpty())
return;
int endValue;
if (end == 0 || end >= mYVals.size())
endValue = mYVals.size() - 1;
else
endValue = end;
mYMin = yMin(mYVals.get(start));
mYMax = yMax(mYVals.get(start));
// need chart width to guess this properly
for (int i = start; i <= endValue; i++) {
final BubbleEntry entry = mYVals.get(i);
float ymin = yMin(entry);
float ymax = yMax(entry);
if (ymin < mYMin) {
mYMin = ymin;
}
if (ymax > mYMax) {
mYMax = ymax;
}
final float xmin = xMin(entry);
final float xmax = xMax(entry);
if (xmin < mXMin) {
mXMin = xmin;
}
if (xmax > mXMax) {
mXMax = xmax;
}
final float size = largestSize(entry);
if (size > mMaxSize) {
mMaxSize = size;
}
}
}
@Override
public DataSet<BubbleEntry> copy() {
List<BubbleEntry> yVals = new ArrayList<>();
for (int i = 0; i < mYVals.size(); i++) {
yVals.add(mYVals.get(i).copy());
}
BubbleDataSet copied = new BubbleDataSet(yVals, getLabel());
copied.mColors = mColors;
copied.mHighLightColor = mHighLightColor;
return copied;
}
@Override
public float getXMax() {
return mXMax;
}
@Override
public float getXMin() {
return mXMin;
}
@Override
public float getMaxSize() {
return mMaxSize;
}
@Override
public boolean isNormalizeSizeEnabled() {
return mNormalizeSize;
}
public void setNormalizeSizeEnabled(boolean normalizeSize) {
mNormalizeSize = normalizeSize;
}
private float yMin(BubbleEntry entry) {
return entry.getVal();
}
private float yMax(BubbleEntry entry) {
return entry.getVal();
}
private float xMin(BubbleEntry entry) {
return (float) entry.getXIndex();
}
private float xMax(BubbleEntry entry) {
return (float) entry.getXIndex();
}
private float largestSize(BubbleEntry entry) {
return entry.getSize();
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/BubbleDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 813 |
```java
package com.github.mikephil.charting.data;
/**
* Class representing one entry in the chart. Might contain multiple values.
* Might only contain a single value depending on the used constructor.
*
* @author Philipp Jahoda
*/
public class Entry extends ChartData<DataSet<? extends Entry>> {
/** the actual value */
private float mVal = 0f;
/** the index on the x-axis */
private int mXIndex = 0;
/** optional spot for additional data this Entry represents */
private Object mData = null;
/**
* A Entry represents one single entry in the chart.
*
* @param val the y value (the actual value of the entry)
* @param xIndex the corresponding index in the x value array (index on the
* x-axis of the chart, must NOT be higher than the length of the
* x-values String array)
*/
public Entry(float val, int xIndex) {
mVal = val;
mXIndex = xIndex;
}
/**
* A Entry represents one single entry in the chart.
*
* @param val the y value (the actual value of the entry)
* @param xIndex the corresponding index in the x value array (index on the
* x-axis of the chart, must NOT be higher than the length of the
* x-values String array)
* @param data Spot for additional data this Entry represents.
*/
public Entry(float val, int xIndex, Object data) {
this(val, xIndex);
this.mData = data;
}
/**
* returns the x-index the value of this object is mapped to
*
* @return
*/
public int getXIndex() {
return mXIndex;
}
/**
* sets the x-index for the entry
*
* @param x
*/
public void setXIndex(int x) {
this.mXIndex = x;
}
/**
* Returns the total value the entry represents.
*
* @return
*/
public float getVal() {
return mVal;
}
/**
* Sets the value for the entry.
*
* @param val
*/
public void setVal(float val) {
this.mVal = val;
}
/**
* Returns the data, additional information that this Entry represents, or
* null, if no data has been specified.
*
* @return
*/
public Object getData() {
return mData;
}
/**
* Sets additional data this Entry should represent.
*
* @param data
*/
public void setData(Object data) {
this.mData = data;
}
/**
* returns an exact copy of the entry
*
* @return
*/
public Entry copy() {
return new Entry(mVal, mXIndex, mData);
}
/**
* Compares value, xIndex and data of the entries. Returns true if entries
* are equal in those points, false if not. Does not check by hash-code like
* it's done by the "equals" method.
*
* @param e
* @return
*/
public boolean equalTo(Entry e) {
if (e == null)
return false;
if (e.mData != this.mData)
return false;
if (e.mXIndex != this.mXIndex)
return false;
if (Math.abs(e.mVal - this.mVal) > 0.00001f)
return false;
return true;
}
/**
* returns a string representation of the entry containing x-index and value
*/
@Override
public String toString() {
return "Entry, xIndex: " + mXIndex + " val (sum): " + getVal();
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/Entry.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 839 |
```java
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
import java.util.ArrayList;
import java.util.List;
/**
* A PieData object can only represent one DataSet. Unlike all other charts, the
* legend labels of the PieChart are created from the x-values array, and not
* from the DataSet labels. Each PieData object can only represent one
* PieDataSet (multiple PieDataSets inside a single PieChart are not possible).
*
* @author Philipp Jahoda
*/
public class PieData extends ChartData<IPieDataSet> {
public PieData() {
super();
}
public PieData(List<String> xVals) {
super(xVals);
}
public PieData(String[] xVals) {
super(xVals);
}
public PieData(List<String> xVals, IPieDataSet dataSet) {
super(xVals, toList(dataSet));
}
public PieData(String[] xVals, IPieDataSet dataSet) {
super(xVals, toList(dataSet));
}
private static List<IPieDataSet> toList(IPieDataSet dataSet) {
List<IPieDataSet> sets = new ArrayList<>();
sets.add(dataSet);
return sets;
}
/**
* Sets the PieDataSet this data object should represent.
*
* @param dataSet
*/
public void setDataSet(IPieDataSet dataSet) {
mDataSets.clear();
mDataSets.add(dataSet);
init();
}
/**
* Returns the DataSet this PieData object represents. A PieData object can
* only contain one DataSet.
*
* @return
*/
public IPieDataSet getDataSet() {
return mDataSets.get(0);
}
/**
* The PieData object can only have one DataSet. Use getDataSet() method instead.
*
* @param index
* @return
*/
@Override
public IPieDataSet getDataSetByIndex(int index) {
return index == 0 ? getDataSet() : null;
}
@Override
public IPieDataSet getDataSetByLabel(String label, boolean ignorecase) {
return ignorecase ? label.equalsIgnoreCase(mDataSets.get(0).getLabel()) ? mDataSets.get(0)
: null : label.equals(mDataSets.get(0).getLabel()) ? mDataSets.get(0) : null;
}
/**
* Returns the sum of all values in this PieData object.
*
* @return
*/
public float getYValueSum() {
float sum = 0;
for (int i = 0; i < getDataSet().getEntryCount(); i++)
sum += getDataSet().getEntryForIndex(i).getVal();
return sum;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/PieData.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 598 |
```java
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import java.util.ArrayList;
import java.util.List;
/**
* Data object that encapsulates all data associated with a LineChart.
*
* @author Philipp Jahoda
*/
public class LineData extends BarLineScatterCandleBubbleData<ILineDataSet> {
public LineData() {
super();
}
public LineData(List<String> xVals) {
super(xVals);
}
public LineData(String[] xVals) {
super(xVals);
}
public LineData(List<String> xVals, List<ILineDataSet> dataSets) {
super(xVals, dataSets);
}
public LineData(String[] xVals, List<ILineDataSet> dataSets) {
super(xVals, dataSets);
}
public LineData(List<String> xVals, ILineDataSet dataSet) {
super(xVals, toList(dataSet));
}
public LineData(String[] xVals, ILineDataSet dataSet) {
super(xVals, toList(dataSet));
}
private static List<ILineDataSet> toList(ILineDataSet dataSet) {
List<ILineDataSet> sets = new ArrayList<>();
sets.add(dataSet);
return sets;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/LineData.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 283 |
```java
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
import java.util.List;
public class PieDataSet extends DataSet<Entry> implements IPieDataSet {
/** the space in pixels between the chart-slices, default 0f */
private float mSliceSpace = 0f;
/** indicates the selection distance of a pie slice */
private float mShift = 18f;
private ValuePosition mXValuePosition = ValuePosition.INSIDE_SLICE;
private ValuePosition mYValuePosition = ValuePosition.INSIDE_SLICE;
private int mValueLineColor = 0xff000000;
private float mValueLineWidth = 1.0f;
private float mValueLinePart1OffsetPercentage = 75.f;
private float mValueLinePart1Length = 0.3f;
private float mValueLinePart2Length = 0.4f;
private boolean mValueLineVariableLength = true;
public PieDataSet(List<Entry> yVals, String label) {
super(yVals, label);
// mShift = Utils.convertDpToPixel(12f);
}
@Override
public DataSet<Entry> copy() {
List<Entry> yVals = new ArrayList<>();
for (int i = 0; i < mYVals.size(); i++) {
yVals.add(mYVals.get(i).copy());
}
PieDataSet copied = new PieDataSet(yVals, getLabel());
copied.mColors = mColors;
copied.mSliceSpace = mSliceSpace;
copied.mShift = mShift;
return copied;
}
/**
* Sets the space that is left out between the piechart-slices in dp.
* Default: 0 --> no space, maximum 20f
*
* @param spaceDp
*/
public void setSliceSpace(float spaceDp) {
if (spaceDp > 20)
spaceDp = 20f;
if (spaceDp < 0)
spaceDp = 0f;
mSliceSpace = Utils.convertDpToPixel(spaceDp);
}
@Override
public float getSliceSpace() {
return mSliceSpace;
}
/**
* sets the distance the highlighted piechart-slice of this DataSet is
* "shifted" away from the center of the chart, default 12f
*
* @param shift
*/
public void setSelectionShift(float shift) {
mShift = Utils.convertDpToPixel(shift);
}
@Override
public float getSelectionShift() {
return mShift;
}
@Override
public ValuePosition getXValuePosition()
{
return mXValuePosition;
}
public void setXValuePosition(ValuePosition xValuePosition)
{
this.mXValuePosition = xValuePosition;
}
@Override
public ValuePosition getYValuePosition()
{
return mYValuePosition;
}
public void setYValuePosition(ValuePosition yValuePosition)
{
this.mYValuePosition = yValuePosition;
}
/** When valuePosition is OutsideSlice, indicates line color */
@Override
public int getValueLineColor()
{
return mValueLineColor;
}
public void setValueLineColor(int valueLineColor)
{
this.mValueLineColor = valueLineColor;
}
/** When valuePosition is OutsideSlice, indicates line width */
@Override
public float getValueLineWidth()
{
return mValueLineWidth;
}
public void setValueLineWidth(float valueLineWidth)
{
this.mValueLineWidth = valueLineWidth;
}
/** When valuePosition is OutsideSlice, indicates offset as percentage out of the slice size */
@Override
public float getValueLinePart1OffsetPercentage()
{
return mValueLinePart1OffsetPercentage;
}
public void setValueLinePart1OffsetPercentage(float valueLinePart1OffsetPercentage)
{
this.mValueLinePart1OffsetPercentage = valueLinePart1OffsetPercentage;
}
/** When valuePosition is OutsideSlice, indicates length of first half of the line */
@Override
public float getValueLinePart1Length()
{
return mValueLinePart1Length;
}
public void setValueLinePart1Length(float valueLinePart1Length)
{
this.mValueLinePart1Length = valueLinePart1Length;
}
/** When valuePosition is OutsideSlice, indicates length of second half of the line */
@Override
public float getValueLinePart2Length()
{
return mValueLinePart2Length;
}
public void setValueLinePart2Length(float valueLinePart2Length)
{
this.mValueLinePart2Length = valueLinePart2Length;
}
/** When valuePosition is OutsideSlice, this allows variable line length */
@Override
public boolean isValueLineVariableLength()
{
return mValueLineVariableLength;
}
public void setValueLineVariableLength(boolean valueLineVariableLength)
{
this.mValueLineVariableLength = valueLineVariableLength;
}
public enum ValuePosition {
INSIDE_SLICE,
OUTSIDE_SLICE
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/PieDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 1,135 |
```java
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
import java.util.ArrayList;
import java.util.List;
/**
* Data container for the RadarChart.
*
* @author Philipp Jahoda
*/
public class RadarData extends ChartData<IRadarDataSet> {
public RadarData() {
super();
}
public RadarData(List<String> xVals) {
super(xVals);
}
public RadarData(String[] xVals) {
super(xVals);
}
public RadarData(List<String> xVals, List<IRadarDataSet> dataSets) {
super(xVals, dataSets);
}
public RadarData(String[] xVals, List<IRadarDataSet> dataSets) {
super(xVals, dataSets);
}
public RadarData(List<String> xVals, IRadarDataSet dataSet) {
super(xVals, toList(dataSet));
}
public RadarData(String[] xVals, IRadarDataSet dataSet) {
super(xVals, toList(dataSet));
}
private static List<IRadarDataSet> toList(IRadarDataSet dataSet) {
List<IRadarDataSet> sets = new ArrayList<>();
sets.add(dataSet);
return sets;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/RadarData.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 270 |
```java
package com.github.mikephil.charting.renderer;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Build;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.lang.ref.WeakReference;
import java.util.List;
public class PieChartRenderer extends DataRenderer {
protected PieChart mChart;
/**
* paint for the hole in the center of the pie chart and the transparent
* circle
*/
protected Paint mHolePaint;
protected Paint mTransparentCirclePaint;
protected Paint mValueLinePaint;
/**
* paint object for the text that can be displayed in the center of the
* chart
*/
private TextPaint mCenterTextPaint;
private StaticLayout mCenterTextLayout;
private CharSequence mCenterTextLastValue;
private RectF mCenterTextLastBounds = new RectF();
private RectF[] mRectBuffer = {new RectF(), new RectF(), new RectF()};
/**
* Bitmap for drawing the center hole
*/
protected WeakReference<Bitmap> mDrawBitmap;
protected Canvas mBitmapCanvas;
public PieChartRenderer(PieChart chart, ChartAnimator animator,
ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
mChart = chart;
mHolePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mHolePaint.setColor(Color.WHITE);
mHolePaint.setStyle(Style.FILL);
mTransparentCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mTransparentCirclePaint.setColor(Color.WHITE);
mTransparentCirclePaint.setStyle(Style.FILL);
mTransparentCirclePaint.setAlpha(105);
mCenterTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mCenterTextPaint.setColor(Color.BLACK);
mCenterTextPaint.setTextSize(Utils.convertDpToPixel(12f));
mValuePaint.setTextSize(Utils.convertDpToPixel(13f));
mValuePaint.setColor(Color.WHITE);
mValuePaint.setTextAlign(Align.CENTER);
mValueLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mValueLinePaint.setStyle(Style.STROKE);
}
public Paint getPaintHole() {
return mHolePaint;
}
public Paint getPaintTransparentCircle() {
return mTransparentCirclePaint;
}
public TextPaint getPaintCenterText() {
return mCenterTextPaint;
}
@Override
public void initBuffers() {
// TODO Auto-generated method stub
}
@Override
public void drawData(Canvas c) {
int width = (int) mViewPortHandler.getChartWidth();
int height = (int) mViewPortHandler.getChartHeight();
if (mDrawBitmap == null
|| (mDrawBitmap.get().getWidth() != width)
|| (mDrawBitmap.get().getHeight() != height)) {
if (width > 0 && height > 0) {
mDrawBitmap = new WeakReference<>(Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444));
mBitmapCanvas = new Canvas(mDrawBitmap.get());
} else
return;
}
mDrawBitmap.get().eraseColor(Color.TRANSPARENT);
PieData pieData = mChart.getData();
for (IPieDataSet set : pieData.getDataSets()) {
if (set.isVisible() && set.getEntryCount() > 0)
drawDataSet(c, set);
}
}
private Path mPathBuffer = new Path();
private RectF mInnerRectBuffer = new RectF();
protected float calculateMinimumRadiusForSpacedSlice(
PointF center,
float radius,
float angle,
float arcStartPointX,
float arcStartPointY,
float startAngle,
float sweepAngle)
{
final float angleMiddle = startAngle + sweepAngle / 2.f;
// Other point of the arc
float arcEndPointX = center.x + radius * (float) Math.cos((startAngle + sweepAngle) * Utils.FDEG2RAD);
float arcEndPointY = center.y + radius * (float) Math.sin((startAngle + sweepAngle) * Utils.FDEG2RAD);
// Middle point on the arc
float arcMidPointX = center.x + radius * (float) Math.cos(angleMiddle * Utils.FDEG2RAD);
float arcMidPointY = center.y + radius * (float) Math.sin(angleMiddle * Utils.FDEG2RAD);
// This is the base of the contained triangle
double basePointsDistance = Math.sqrt(
Math.pow(arcEndPointX - arcStartPointX, 2) +
Math.pow(arcEndPointY - arcStartPointY, 2));
// After reducing space from both sides of the "slice",
// the angle of the contained triangle should stay the same.
// So let's find out the height of that triangle.
float containedTriangleHeight = (float)(basePointsDistance / 2.0 *
Math.tan((180.0 - angle) / 2.0 * Utils.DEG2RAD));
// Now we subtract that from the radius
float spacedRadius = radius - containedTriangleHeight;
// And now subtract the height of the arc that's between the triangle and the outer circle
spacedRadius -= Math.sqrt(
Math.pow(arcMidPointX - (arcEndPointX + arcStartPointX) / 2.f, 2) +
Math.pow(arcMidPointY - (arcEndPointY + arcStartPointY) / 2.f, 2));
return spacedRadius;
}
protected void drawDataSet(Canvas c, IPieDataSet dataSet) {
float angle = 0;
float rotationAngle = mChart.getRotationAngle();
float phaseX = mAnimator.getPhaseX();
float phaseY = mAnimator.getPhaseY();
final RectF circleBox = mChart.getCircleBox();
final int entryCount = dataSet.getEntryCount();
final float[] drawAngles = mChart.getDrawAngles();
final PointF center = mChart.getCenterCircleBox();
final float radius = mChart.getRadius();
final boolean drawInnerArc = mChart.isDrawHoleEnabled() && !mChart.isDrawSlicesUnderHoleEnabled();
final float userInnerRadius = drawInnerArc
? radius * (mChart.getHoleRadius() / 100.f)
: 0.f;
int visibleAngleCount = 0;
for (int j = 0; j < entryCount; j++) {
// draw only if the value is greater than zero
if (Math.abs(dataSet.getEntryForIndex(j).getVal()) > 0.000001) {
visibleAngleCount++;
}
}
final float sliceSpace = visibleAngleCount <= 1 ? 0.f : dataSet.getSliceSpace();
for (int j = 0; j < entryCount; j++) {
float sliceAngle = drawAngles[j];
float innerRadius = userInnerRadius;
Entry e = dataSet.getEntryForIndex(j);
// draw only if the value is greater than zero
if (Math.abs(e.getVal()) > 0.000001) {
if (!mChart.needsHighlight(e.getXIndex(),
mChart.getData().getIndexOfDataSet(dataSet))) {
final boolean accountForSliceSpacing = sliceSpace > 0.f && sliceAngle <= 180.f;
mRenderPaint.setColor(dataSet.getColor(j));
final float sliceSpaceAngleOuter = visibleAngleCount == 1 ?
0.f :
sliceSpace / (Utils.FDEG2RAD * radius);
final float startAngleOuter = rotationAngle + (angle + sliceSpaceAngleOuter / 2.f) * phaseY;
float sweepAngleOuter = (sliceAngle - sliceSpaceAngleOuter) * phaseY;
if (sweepAngleOuter < 0.f)
{
sweepAngleOuter = 0.f;
}
mPathBuffer.reset();
float arcStartPointX = 0.f, arcStartPointY = 0.f;
if (sweepAngleOuter % 360f == 0.f) {
// Android is doing "mod 360"
mPathBuffer.addCircle(center.x, center.y, radius, Path.Direction.CW);
} else {
arcStartPointX = center.x + radius * (float) Math.cos(startAngleOuter * Utils.FDEG2RAD);
arcStartPointY = center.y + radius * (float) Math.sin(startAngleOuter * Utils.FDEG2RAD);
mPathBuffer.moveTo(arcStartPointX, arcStartPointY);
mPathBuffer.arcTo(
circleBox,
startAngleOuter,
sweepAngleOuter
);
}
// API < 21 does not receive floats in addArc, but a RectF
mInnerRectBuffer.set(
center.x - innerRadius,
center.y - innerRadius,
center.x + innerRadius,
center.y + innerRadius);
if (drawInnerArc &&
(innerRadius > 0.f || accountForSliceSpacing)) {
if (accountForSliceSpacing) {
float minSpacedRadius =
calculateMinimumRadiusForSpacedSlice(
center, radius,
sliceAngle * phaseY,
arcStartPointX, arcStartPointY,
startAngleOuter,
sweepAngleOuter);
if (minSpacedRadius < 0.f)
minSpacedRadius = -minSpacedRadius;
innerRadius = Math.max(innerRadius, minSpacedRadius);
}
final float sliceSpaceAngleInner = visibleAngleCount == 1 || innerRadius == 0.f ?
0.f :
sliceSpace / (Utils.FDEG2RAD * innerRadius);
final float startAngleInner = rotationAngle + (angle + sliceSpaceAngleInner / 2.f) * phaseY;
float sweepAngleInner = (sliceAngle - sliceSpaceAngleInner) * phaseY;
if (sweepAngleInner < 0.f)
{
sweepAngleInner = 0.f;
}
final float endAngleInner = startAngleInner + sweepAngleInner;
if (sweepAngleOuter % 360f == 0.f) {
// Android is doing "mod 360"
mPathBuffer.addCircle(center.x, center.y, innerRadius, Path.Direction.CCW);
} else {
mPathBuffer.lineTo(
center.x + innerRadius * (float) Math.cos(endAngleInner * Utils.FDEG2RAD),
center.y + innerRadius * (float) Math.sin(endAngleInner * Utils.FDEG2RAD));
mPathBuffer.arcTo(
mInnerRectBuffer,
endAngleInner,
-sweepAngleInner
);
}
}
else {
if (sweepAngleOuter % 360f != 0.f) {
if (accountForSliceSpacing) {
float angleMiddle = startAngleOuter + sweepAngleOuter / 2.f;
float sliceSpaceOffset =
calculateMinimumRadiusForSpacedSlice(
center,
radius,
sliceAngle * phaseY,
arcStartPointX,
arcStartPointY,
startAngleOuter,
sweepAngleOuter);
float arcEndPointX = center.x +
sliceSpaceOffset * (float) Math.cos(angleMiddle * Utils.FDEG2RAD);
float arcEndPointY = center.y +
sliceSpaceOffset * (float) Math.sin(angleMiddle * Utils.FDEG2RAD);
mPathBuffer.lineTo(
arcEndPointX,
arcEndPointY);
} else {
mPathBuffer.lineTo(
center.x,
center.y);
}
}
}
mPathBuffer.close();
mBitmapCanvas.drawPath(mPathBuffer, mRenderPaint);
}
}
angle += sliceAngle * phaseX;
}
}
@Override
public void drawValues(Canvas c) {
PointF center = mChart.getCenterCircleBox();
// get whole the radius
float radius = mChart.getRadius();
float rotationAngle = mChart.getRotationAngle();
float[] drawAngles = mChart.getDrawAngles();
float[] absoluteAngles = mChart.getAbsoluteAngles();
float phaseX = mAnimator.getPhaseX();
float phaseY = mAnimator.getPhaseY();
final float holeRadiusPercent = mChart.getHoleRadius() / 100.f;
float labelRadiusOffset = radius / 10f * 3.6f;
if (mChart.isDrawHoleEnabled()) {
labelRadiusOffset = (radius - (radius * holeRadiusPercent)) / 2f;
}
final float labelRadius = radius - labelRadiusOffset;
PieData data = mChart.getData();
List<IPieDataSet> dataSets = data.getDataSets();
float yValueSum = data.getYValueSum();
boolean drawXVals = mChart.isDrawSliceTextEnabled();
float angle;
int xIndex = 0;
c.save();
for (int i = 0; i < dataSets.size(); i++) {
IPieDataSet dataSet = dataSets.get(i);
final boolean drawYVals = dataSet.isDrawValuesEnabled();
if (!drawYVals && !drawXVals)
continue;
final PieDataSet.ValuePosition xValuePosition = dataSet.getXValuePosition();
final PieDataSet.ValuePosition yValuePosition = dataSet.getYValuePosition();
// apply the text-styling defined by the DataSet
applyValueTextStyle(dataSet);
float lineHeight = Utils.calcTextHeight(mValuePaint, "Q")
+ Utils.convertDpToPixel(4f);
ValueFormatter formatter = dataSet.getValueFormatter();
int entryCount = dataSet.getEntryCount();
mValueLinePaint.setColor(dataSet.getValueLineColor());
mValueLinePaint.setStrokeWidth(Utils.convertDpToPixel(dataSet.getValueLineWidth()));
for (int j = 0; j < entryCount; j++) {
Entry entry = dataSet.getEntryForIndex(j);
if (xIndex == 0)
angle = 0.f;
else
angle = absoluteAngles[xIndex - 1] * phaseX;
final float sliceAngle = drawAngles[xIndex];
final float sliceSpace = dataSet.getSliceSpace();
final float sliceSpaceMiddleAngle = sliceSpace / (Utils.FDEG2RAD * labelRadius);
// offset needed to center the drawn text in the slice
final float angleOffset = (sliceAngle - sliceSpaceMiddleAngle / 2.f) / 2.f;
angle = angle + angleOffset;
final float transformedAngle = rotationAngle + angle * phaseY;
float value = mChart.isUsePercentValuesEnabled() ? entry.getVal()
/ yValueSum * 100f : entry.getVal();
final float sliceXBase = (float)Math.cos(transformedAngle * Utils.FDEG2RAD);
final float sliceYBase = (float)Math.sin(transformedAngle * Utils.FDEG2RAD);
final boolean drawXOutside = drawXVals &&
xValuePosition == PieDataSet.ValuePosition.OUTSIDE_SLICE;
final boolean drawYOutside = drawYVals &&
yValuePosition == PieDataSet.ValuePosition.OUTSIDE_SLICE;
final boolean drawXInside = drawXVals &&
xValuePosition == PieDataSet.ValuePosition.INSIDE_SLICE;
final boolean drawYInside = drawYVals &&
yValuePosition == PieDataSet.ValuePosition.INSIDE_SLICE;
if (drawXOutside || drawYOutside) {
final float valueLineLength1 = dataSet.getValueLinePart1Length();
final float valueLineLength2 = dataSet.getValueLinePart2Length();
final float valueLinePart1OffsetPercentage = dataSet.getValueLinePart1OffsetPercentage() / 100.f;
float pt2x, pt2y;
float labelPtx, labelPty;
float line1Radius;
if (mChart.isDrawHoleEnabled())
line1Radius = (radius - (radius * holeRadiusPercent))
* valueLinePart1OffsetPercentage
+ (radius * holeRadiusPercent);
else
line1Radius = radius * valueLinePart1OffsetPercentage;
final float polyline2Width = dataSet.isValueLineVariableLength()
? labelRadius * valueLineLength2 * (float)Math.abs(Math.sin(
transformedAngle * Utils.FDEG2RAD))
: labelRadius * valueLineLength2;
final float pt0x = line1Radius * sliceXBase + center.x;
final float pt0y = line1Radius * sliceYBase + center.y;
final float pt1x = labelRadius * (1 + valueLineLength1) * sliceXBase + center.x;
final float pt1y = labelRadius * (1 + valueLineLength1) * sliceYBase + center.y;
if (transformedAngle % 360.0 >= 90.0 && transformedAngle % 360.0 <= 270.0) {
pt2x = pt1x - polyline2Width;
pt2y = pt1y;
mValuePaint.setTextAlign(Align.RIGHT);
labelPtx = pt2x - Utils.convertDpToPixel(5.f);
labelPty = pt2y;
} else {
pt2x = pt1x + polyline2Width;
pt2y = pt1y;
mValuePaint.setTextAlign(Align.LEFT);
labelPtx = pt2x + Utils.convertDpToPixel(5.f);
labelPty = pt2y;
}
if (dataSet.getValueLineColor() != ColorTemplate.COLOR_NONE) {
c.drawLine(pt0x, pt0y, pt1x, pt1y, mValueLinePaint);
c.drawLine(pt1x, pt1y, pt2x, pt2y, mValueLinePaint);
}
// draw everything, depending on settings
if (drawXOutside && drawYOutside) {
drawValue(c,
formatter,
value,
entry,
0,
labelPtx,
labelPty,
dataSet.getValueTextColor(j));
if (j < data.getXValCount()) {
c.drawText(data.getXVals().get(j), labelPtx, labelPty + lineHeight,
mValuePaint);
}
} else if (drawXOutside) {
if (j < data.getXValCount()) {
mValuePaint.setColor(dataSet.getValueTextColor(j));
c.drawText(data.getXVals().get(j), labelPtx, labelPty + lineHeight / 2.f, mValuePaint);
}
} else if (drawYOutside) {
drawValue(c, formatter, value, entry, 0, labelPtx, labelPty + lineHeight / 2.f, dataSet.getValueTextColor(j));
}
}
if (drawXInside || drawYInside) {
// calculate the text position
float x = labelRadius * sliceXBase + center.x;
float y = labelRadius * sliceYBase + center.y;
mValuePaint.setTextAlign(Align.CENTER);
// draw everything, depending on settings
if (drawXInside && drawYInside) {
drawValue(c, formatter, value, entry, 0, x, y, dataSet.getValueTextColor(j));
if (j < data.getXValCount()) {
c.drawText(data.getXVals().get(j), x, y + lineHeight,
mValuePaint);
}
} else if (drawXInside) {
if (j < data.getXValCount()) {
mValuePaint.setColor(dataSet.getValueTextColor(j));
c.drawText(data.getXVals().get(j), x, y + lineHeight / 2f, mValuePaint);
}
} else if (drawYInside) {
drawValue(c, formatter, value, entry, 0, x, y + lineHeight / 2f, dataSet.getValueTextColor(j));
}
}
xIndex++;
}
}
c.restore();
}
@Override
public void drawExtras(Canvas c) {
// drawCircles(c);
drawHole(c);
c.drawBitmap(mDrawBitmap.get(), 0, 0, null);
drawCenterText(c);
}
private Path mHoleCirclePath = new Path();
/**
* draws the hole in the center of the chart and the transparent circle /
* hole
*/
protected void drawHole(Canvas c) {
if (mChart.isDrawHoleEnabled()) {
float radius = mChart.getRadius();
float holeRadius = radius * (mChart.getHoleRadius() / 100);
PointF center = mChart.getCenterCircleBox();
if (Color.alpha(mHolePaint.getColor()) > 0) {
// draw the hole-circle
mBitmapCanvas.drawCircle(
center.x, center.y,
holeRadius, mHolePaint);
}
// only draw the circle if it can be seen (not covered by the hole)
if (Color.alpha(mTransparentCirclePaint.getColor()) > 0 &&
mChart.getTransparentCircleRadius() > mChart.getHoleRadius()) {
int alpha = mTransparentCirclePaint.getAlpha();
float secondHoleRadius = radius * (mChart.getTransparentCircleRadius() / 100);
mTransparentCirclePaint.setAlpha((int) ((float) alpha * mAnimator.getPhaseX() * mAnimator.getPhaseY()));
// draw the transparent-circle
mHoleCirclePath.reset();
mHoleCirclePath.addCircle(center.x, center.y, secondHoleRadius, Path.Direction.CW);
mHoleCirclePath.addCircle(center.x, center.y, holeRadius, Path.Direction.CCW);
mBitmapCanvas.drawPath(mHoleCirclePath, mTransparentCirclePaint);
// reset alpha
mTransparentCirclePaint.setAlpha(alpha);
}
}
}
/**
* draws the description text in the center of the pie chart makes most
* sense when center-hole is enabled
*/
protected void drawCenterText(Canvas c) {
CharSequence centerText = mChart.getCenterText();
if (mChart.isDrawCenterTextEnabled() && centerText != null) {
PointF center = mChart.getCenterCircleBox();
float innerRadius = mChart.isDrawHoleEnabled() && !mChart.isDrawSlicesUnderHoleEnabled()
? mChart.getRadius() * (mChart.getHoleRadius() / 100f)
: mChart.getRadius();
RectF holeRect = mRectBuffer[0];
holeRect.left = center.x - innerRadius;
holeRect.top = center.y - innerRadius;
holeRect.right = center.x + innerRadius;
holeRect.bottom = center.y + innerRadius;
RectF boundingRect = mRectBuffer[1];
boundingRect.set(holeRect);
float radiusPercent = mChart.getCenterTextRadiusPercent() / 100f;
if (radiusPercent > 0.0) {
boundingRect.inset(
(boundingRect.width() - boundingRect.width() * radiusPercent) / 2.f,
(boundingRect.height() - boundingRect.height() * radiusPercent) / 2.f
);
}
if (!centerText.equals(mCenterTextLastValue) || !boundingRect.equals(mCenterTextLastBounds)) {
// Next time we won't recalculate StaticLayout...
mCenterTextLastBounds.set(boundingRect);
mCenterTextLastValue = centerText;
float width = mCenterTextLastBounds.width();
// If width is 0, it will crash. Always have a minimum of 1
mCenterTextLayout = new StaticLayout(centerText, 0, centerText.length(),
mCenterTextPaint,
(int) Math.max(Math.ceil(width), 1.f),
Layout.Alignment.ALIGN_CENTER, 1.f, 0.f, false);
}
//float layoutWidth = Utils.getStaticLayoutMaxWidth(mCenterTextLayout);
float layoutHeight = mCenterTextLayout.getHeight();
c.save();
if (Build.VERSION.SDK_INT >= 18) {
Path path = new Path();
path.addOval(holeRect, Path.Direction.CW);
c.clipPath(path);
}
c.translate(boundingRect.left, boundingRect.top + (boundingRect.height() - layoutHeight) / 2.f);
mCenterTextLayout.draw(c);
c.restore();
}
}
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
float phaseX = mAnimator.getPhaseX();
float phaseY = mAnimator.getPhaseY();
float angle;
float rotationAngle = mChart.getRotationAngle();
float[] drawAngles = mChart.getDrawAngles();
float[] absoluteAngles = mChart.getAbsoluteAngles();
final PointF center = mChart.getCenterCircleBox();
final float radius = mChart.getRadius();
final boolean drawInnerArc = mChart.isDrawHoleEnabled() && !mChart.isDrawSlicesUnderHoleEnabled();
final float userInnerRadius = drawInnerArc
? radius * (mChart.getHoleRadius() / 100.f)
: 0.f;
final RectF highlightedCircleBox = new RectF();
for (int i = 0; i < indices.length; i++) {
// get the index to highlight
int xIndex = indices[i].getXIndex();
if (xIndex >= drawAngles.length)
continue;
IPieDataSet set = mChart.getData()
.getDataSetByIndex(indices[i]
.getDataSetIndex());
if (set == null || !set.isHighlightEnabled())
continue;
final int entryCount = set.getEntryCount();
int visibleAngleCount = 0;
for (int j = 0; j < entryCount; j++) {
// draw only if the value is greater than zero
if (Math.abs(set.getEntryForIndex(j).getVal()) > 0.000001) {
visibleAngleCount++;
}
}
if (xIndex == 0)
angle = 0.f;
else
angle = absoluteAngles[xIndex - 1] * phaseX;
final float sliceSpace = visibleAngleCount <= 1 ? 0.f : set.getSliceSpace();
float sliceAngle = drawAngles[xIndex];
float innerRadius = userInnerRadius;
float shift = set.getSelectionShift();
final float highlightedRadius = radius + shift;
highlightedCircleBox.set(mChart.getCircleBox());
highlightedCircleBox.inset(-shift, -shift);
final boolean accountForSliceSpacing = sliceSpace > 0.f && sliceAngle <= 180.f;
mRenderPaint.setColor(set.getColor(xIndex));
final float sliceSpaceAngleOuter = visibleAngleCount == 1 ?
0.f :
sliceSpace / (Utils.FDEG2RAD * radius);
final float sliceSpaceAngleShifted = visibleAngleCount == 1 ?
0.f :
sliceSpace / (Utils.FDEG2RAD * highlightedRadius);
final float startAngleOuter = rotationAngle + (angle + sliceSpaceAngleOuter / 2.f) * phaseY;
float sweepAngleOuter = (sliceAngle - sliceSpaceAngleOuter) * phaseY;
if (sweepAngleOuter < 0.f)
{
sweepAngleOuter = 0.f;
}
final float startAngleShifted = rotationAngle + (angle + sliceSpaceAngleShifted / 2.f) * phaseY;
float sweepAngleShifted = (sliceAngle - sliceSpaceAngleShifted) * phaseY;
if (sweepAngleShifted < 0.f)
{
sweepAngleShifted = 0.f;
}
mPathBuffer.reset();
if (sweepAngleOuter % 360f == 0.f) {
// Android is doing "mod 360"
mPathBuffer.addCircle(center.x, center.y, highlightedRadius, Path.Direction.CW);
} else {
mPathBuffer.moveTo(
center.x + highlightedRadius * (float) Math.cos(startAngleShifted * Utils.FDEG2RAD),
center.y + highlightedRadius * (float) Math.sin(startAngleShifted * Utils.FDEG2RAD));
mPathBuffer.arcTo(
highlightedCircleBox,
startAngleShifted,
sweepAngleShifted
);
}
float sliceSpaceRadius = 0.f;
if (accountForSliceSpacing) {
sliceSpaceRadius =
calculateMinimumRadiusForSpacedSlice(
center, radius,
sliceAngle * phaseY,
center.x + radius * (float) Math.cos(startAngleOuter * Utils.FDEG2RAD),
center.y + radius * (float) Math.sin(startAngleOuter * Utils.FDEG2RAD),
startAngleOuter,
sweepAngleOuter);
}
// API < 21 does not receive floats in addArc, but a RectF
mInnerRectBuffer.set(
center.x - innerRadius,
center.y - innerRadius,
center.x + innerRadius,
center.y + innerRadius);
if (drawInnerArc &&
(innerRadius > 0.f || accountForSliceSpacing)) {
if (accountForSliceSpacing) {
float minSpacedRadius = sliceSpaceRadius;
if (minSpacedRadius < 0.f)
minSpacedRadius = -minSpacedRadius;
innerRadius = Math.max(innerRadius, minSpacedRadius);
}
final float sliceSpaceAngleInner = visibleAngleCount == 1 || innerRadius == 0.f ?
0.f :
sliceSpace / (Utils.FDEG2RAD * innerRadius);
final float startAngleInner = rotationAngle + (angle + sliceSpaceAngleInner / 2.f) * phaseY;
float sweepAngleInner = (sliceAngle - sliceSpaceAngleInner) * phaseY;
if (sweepAngleInner < 0.f)
{
sweepAngleInner = 0.f;
}
final float endAngleInner = startAngleInner + sweepAngleInner;
if (sweepAngleOuter % 360f == 0.f) {
// Android is doing "mod 360"
mPathBuffer.addCircle(center.x, center.y, innerRadius, Path.Direction.CCW);
} else {
mPathBuffer.lineTo(
center.x + innerRadius * (float) Math.cos(endAngleInner * Utils.FDEG2RAD),
center.y + innerRadius * (float) Math.sin(endAngleInner * Utils.FDEG2RAD));
mPathBuffer.arcTo(
mInnerRectBuffer,
endAngleInner,
-sweepAngleInner
);
}
}
else {
if (sweepAngleOuter % 360f != 0.f) {
if (accountForSliceSpacing) {
final float angleMiddle = startAngleOuter + sweepAngleOuter / 2.f;
final float arcEndPointX = center.x +
sliceSpaceRadius * (float) Math.cos(angleMiddle * Utils.FDEG2RAD);
final float arcEndPointY = center.y +
sliceSpaceRadius * (float) Math.sin(angleMiddle * Utils.FDEG2RAD);
mPathBuffer.lineTo(
arcEndPointX,
arcEndPointY);
} else {
mPathBuffer.lineTo(
center.x,
center.y);
}
}
}
mPathBuffer.close();
mBitmapCanvas.drawPath(mPathBuffer, mRenderPaint);
}
}
/**
* This gives all pie-slices a rounded edge.
*
* @param c
*/
protected void drawRoundedSlices(Canvas c) {
if (!mChart.isDrawRoundedSlicesEnabled())
return;
IPieDataSet dataSet = mChart.getData().getDataSet();
if (!dataSet.isVisible())
return;
float phaseX = mAnimator.getPhaseX();
float phaseY = mAnimator.getPhaseY();
PointF center = mChart.getCenterCircleBox();
float r = mChart.getRadius();
// calculate the radius of the "slice-circle"
float circleRadius = (r - (r * mChart.getHoleRadius() / 100f)) / 2f;
float[] drawAngles = mChart.getDrawAngles();
float angle = mChart.getRotationAngle();
for (int j = 0; j < dataSet.getEntryCount(); j++) {
float sliceAngle = drawAngles[j];
Entry e = dataSet.getEntryForIndex(j);
// draw only if the value is greater than zero
if (Math.abs(e.getVal()) > 0.000001) {
float x = (float) ((r - circleRadius)
* Math.cos(Math.toRadians((angle + sliceAngle)
* phaseY)) + center.x);
float y = (float) ((r - circleRadius)
* Math.sin(Math.toRadians((angle + sliceAngle)
* phaseY)) + center.y);
mRenderPaint.setColor(dataSet.getColor(j));
mBitmapCanvas.drawCircle(x, y, circleRadius, mRenderPaint);
}
angle += sliceAngle * phaseX;
}
}
/**
* Releases the drawing bitmap. This should be called when {@link LineChart#onDetachedFromWindow()}.
*/
public void releaseBitmap() {
if (mBitmapCanvas != null) {
mBitmapCanvas.setBitmap(null);
mBitmapCanvas = null;
}
if (mDrawBitmap != null) {
mDrawBitmap.get().recycle();
mDrawBitmap.clear();
mDrawBitmap = null;
}
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/renderer/PieChartRenderer.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 7,384 |
```java
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
import java.util.ArrayList;
import java.util.List;
public class ScatterData extends BarLineScatterCandleBubbleData<IScatterDataSet> {
public ScatterData() {
super();
}
public ScatterData(List<String> xVals) {
super(xVals);
}
public ScatterData(String[] xVals) {
super(xVals);
}
public ScatterData(List<String> xVals, List<IScatterDataSet> dataSets) {
super(xVals, dataSets);
}
public ScatterData(String[] xVals, List<IScatterDataSet> dataSets) {
super(xVals, dataSets);
}
public ScatterData(List<String> xVals, IScatterDataSet dataSet) {
super(xVals, toList(dataSet));
}
public ScatterData(String[] xVals, IScatterDataSet dataSet) {
super(xVals, toList(dataSet));
}
private static List<IScatterDataSet> toList(IScatterDataSet dataSet) {
List<IScatterDataSet> sets = new ArrayList<>();
sets.add(dataSet);
return sets;
}
/**
* Returns the maximum shape-size across all DataSets.
*
* @return
*/
public float getGreatestShapeSize() {
float max = 0f;
for (IScatterDataSet set : mDataSets) {
float size = set.getScatterShapeSize();
if (size > max)
max = size;
}
return max;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/ScatterData.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 353 |
```java
package com.github.mikephil.charting.data;
import java.util.ArrayList;
import java.util.List;
/**
* The DataSet class represents one group or type of entries (Entry) in the
* Chart that belong together. It is designed to logically separate different
* groups of values inside the Chart (e.g. the values for a specific line in the
* LineChart, or the values of a specific group of bars in the BarChart).
*
* @author Philipp Jahoda
*/
public abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
/**
* the entries that this dataset represents / holds together
*/
protected List<T> mYVals = null;
/**
* maximum y-value in the y-value array
*/
protected float mYMax = 0.0f;
/**
* the minimum y-value in the y-value array
*/
protected float mYMin = 0.0f;
/**
* Creates a new DataSet object with the given values it represents. Also, a
* label that describes the DataSet can be specified. The label can also be
* used to retrieve the DataSet from a ChartData object.
*
* @param yVals
* @param label
*/
public DataSet(List<T> yVals, String label) {
super(label);
this.mYVals = yVals;
if (mYVals == null)
mYVals = new ArrayList<>();
calcMinMax(0, mYVals.size());
}
@Override
public void calcMinMax(int start, int end) {
if (mYVals == null)
return;
final int yValCount = mYVals.size();
if (yValCount == 0)
return;
int endValue;
if (end == 0 || end >= yValCount)
endValue = yValCount - 1;
else
endValue = end;
mYMin = Float.MAX_VALUE;
mYMax = -Float.MAX_VALUE;
for (int i = start; i <= endValue; i++) {
T e = mYVals.get(i);
if (e != null && !Float.isNaN(e.getVal())) {
if (e.getVal() < mYMin)
mYMin = e.getVal();
if (e.getVal() > mYMax)
mYMax = e.getVal();
}
}
/*if (mYMin == Float.MAX_VALUE) {
mYMin = 0.f;
mYMax = 0.f;
}*/
}
@Override
public int getEntryCount() {
return mYVals.size();
}
/**
* Returns the array of y-values that this DataSet represents.
*
* @return
*/
public List<T> getYVals() {
return mYVals;
}
/**
* Sets the array of y-values that this DataSet represents, and calls notifyDataSetChanged()
*
* @return
*/
public void setYVals(List<T> yVals) {
mYVals = yVals;
notifyDataSetChanged();
}
/**
* Provides an exact copy of the DataSet this method is used on.
*
* @return
*/
public abstract DataSet<T> copy();
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append(toSimpleString());
for (int i = 0; i < mYVals.size(); i++) {
buffer.append(mYVals.get(i).toString() + " ");
}
return buffer.toString();
}
/**
* Returns a simple string representation of the DataSet with the type and
* the number of Entries.
*
* @return
*/
public String toSimpleString() {
StringBuilder buffer = new StringBuilder();
buffer.append("DataSet, label: " + (getLabel() == null ? "" : getLabel()) + ", entries: " + mYVals.size() + "\n");
return buffer.toString();
}
@Override
public float getYMin() {
return mYMin;
}
@Override
public float getYMax() {
return mYMax;
}
@Override
public void addEntryOrdered(T e) {
if (e == null)
return;
float val = e.getVal();
if (mYVals == null) {
mYVals = new ArrayList<>();
}
if (mYVals.isEmpty()) {
mYMax = val;
mYMin = val;
} else {
if (mYMax < val)
mYMax = val;
if (mYMin > val)
mYMin = val;
}
if (!mYVals.isEmpty() && mYVals.get(mYVals.size() - 1).getXIndex() > e.getXIndex()) {
int closestIndex = getEntryIndex(e.getXIndex(), Rounding.UP);
mYVals.add(closestIndex, e);
return;
}
mYVals.add(e);
}
@Override
public void clear() {
mYVals.clear();
notifyDataSetChanged();
}
@Override
public boolean addEntry(T e) {
if (e == null)
return false;
float val = e.getVal();
List<T> yVals = getYVals();
if (yVals == null) {
yVals = new ArrayList<>();
}
if (yVals.isEmpty()) {
mYMax = val;
mYMin = val;
} else {
if (mYMax < val)
mYMax = val;
if (mYMin > val)
mYMin = val;
}
// add the entry
yVals.add(e);
return true;
}
@Override
public boolean removeEntry(T e) {
if (e == null)
return false;
if (mYVals == null)
return false;
// remove the entry
boolean removed = mYVals.remove(e);
if (removed) {
calcMinMax(0, mYVals.size());
}
return removed;
}
@Override
public int getEntryIndex(Entry e) {
return mYVals.indexOf(e);
}
@Override
public T getEntryForXIndex(int xIndex, Rounding rounding) {
int index = getEntryIndex(xIndex, rounding);
if (index > -1)
return mYVals.get(index);
return null;
}
@Override
public T getEntryForXIndex(int xIndex) {
return getEntryForXIndex(xIndex, Rounding.CLOSEST);
}
@Override
public T getEntryForIndex(int index) {
return mYVals.get(index);
}
@Override
public int getEntryIndex(int xIndex, Rounding rounding) {
int low = 0;
int high = mYVals.size() - 1;
int closest = -1;
while (low <= high) {
int m = (high + low) / 2;
if (xIndex == mYVals.get(m).getXIndex()) {
while (m > 0 && mYVals.get(m - 1).getXIndex() == xIndex)
m--;
return m;
}
if (xIndex > mYVals.get(m).getXIndex())
low = m + 1;
else
high = m - 1;
closest = m;
}
if (closest != -1) {
int closestXIndex = mYVals.get(closest).getXIndex();
if (rounding == Rounding.UP) {
if (closestXIndex < xIndex && closest < mYVals.size() - 1) {
++closest;
}
} else if (rounding == Rounding.DOWN) {
if (closestXIndex > xIndex && closest > 0) {
--closest;
}
}
}
return closest;
}
@Override
public float getYValForXIndex(int xIndex) {
Entry e = getEntryForXIndex(xIndex);
if (e != null && e.getXIndex() == xIndex)
return e.getVal();
else
return Float.NaN;
}
@Override
public float[] getYValsForXIndex(int xIndex) {
List<T> entries = getEntriesForXIndex(xIndex);
float[] yVals = new float[entries.size()];
int i = 0;
for (T e : entries)
yVals[i++] = e.getVal();
return yVals;
}
/**
* Returns all Entry objects at the given xIndex. INFORMATION: This method
* does calculations at runtime. Do not over-use in performance critical
* situations.
*
* @param xIndex
* @return
*/
@Override
public List<T> getEntriesForXIndex(int xIndex) {
List<T> entries = new ArrayList<>();
int low = 0;
int high = mYVals.size() - 1;
while (low <= high) {
int m = (high + low) / 2;
T entry = mYVals.get(m);
if (xIndex == entry.getXIndex()) {
while (m > 0 && mYVals.get(m - 1).getXIndex() == xIndex)
m--;
high = mYVals.size();
for (; m < high; m++) {
entry = mYVals.get(m);
if (entry.getXIndex() == xIndex) {
entries.add(entry);
} else {
break;
}
}
break;
} else {
if (xIndex > entry.getXIndex())
low = m + 1;
else
high = m - 1;
}
}
return entries;
}
/**
* Determines how to round DataSet index values for
* {@link DataSet#getEntryIndex(int, Rounding)} DataSet.getEntryIndex()}
* when an exact x-index is not found.
*/
public enum Rounding {
UP,
DOWN,
CLOSEST,
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/DataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 2,201 |
```java
package com.github.mikephil.charting.data;
import android.graphics.Color;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import java.util.ArrayList;
import java.util.List;
public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> implements IBarDataSet {
/**
* space indicator between the bars 0.1f == 10 %
*/
private float mBarSpace = 0.15f;
/**
* the maximum number of bars that are stacked upon each other, this value
* is calculated from the Entries that are added to the DataSet
*/
private int mStackSize = 1;
/**
* the color used for drawing the bar shadows
*/
private int mBarShadowColor = Color.rgb(215, 215, 215);
private float mBarBorderWidth = 0.0f;
private int mBarBorderColor = Color.BLACK;
/**
* the alpha value used to draw the highlight indicator bar
*/
private int mHighLightAlpha = 120;
/**
* the overall entry count, including counting each stack-value individually
*/
private int mEntryCountStacks = 0;
/**
* array of labels used to describe the different values of the stacked bars
*/
private String[] mStackLabels = new String[]{
"Stack"
};
public BarDataSet(List<BarEntry> yVals, String label) {
super(yVals, label);
mHighLightColor = Color.rgb(0, 0, 0);
calcStackSize(yVals);
calcEntryCountIncludingStacks(yVals);
}
@Override
public DataSet<BarEntry> copy() {
List<BarEntry> yVals = new ArrayList<>();
for (int i = 0; i < mYVals.size(); i++) {
yVals.add(((BarEntry) mYVals.get(i)).copy());
}
BarDataSet copied = new BarDataSet(yVals, getLabel());
copied.mColors = mColors;
copied.mStackSize = mStackSize;
copied.mBarSpace = mBarSpace;
copied.mBarShadowColor = mBarShadowColor;
copied.mStackLabels = mStackLabels;
copied.mHighLightColor = mHighLightColor;
copied.mHighLightAlpha = mHighLightAlpha;
return copied;
}
/**
* Calculates the total number of entries this DataSet represents, including
* stacks. All values belonging to a stack are calculated separately.
*/
private void calcEntryCountIncludingStacks(List<BarEntry> yVals) {
mEntryCountStacks = 0;
for (int i = 0; i < yVals.size(); i++) {
float[] vals = yVals.get(i).getVals();
if (vals == null)
mEntryCountStacks++;
else
mEntryCountStacks += vals.length;
}
}
/**
* calculates the maximum stacksize that occurs in the Entries array of this
* DataSet
*/
private void calcStackSize(List<BarEntry> yVals) {
for (int i = 0; i < yVals.size(); i++) {
float[] vals = yVals.get(i).getVals();
if (vals != null && vals.length > mStackSize)
mStackSize = vals.length;
}
}
@Override
public void calcMinMax(int start, int end) {
if (mYVals == null)
return;
final int yValCount = mYVals.size();
if (yValCount == 0)
return;
int endValue;
if (end == 0 || end >= yValCount)
endValue = yValCount - 1;
else
endValue = end;
mYMin = Float.MAX_VALUE;
mYMax = -Float.MAX_VALUE;
for (int i = start; i <= endValue; i++) {
BarEntry e = mYVals.get(i);
if (e != null && !Float.isNaN(e.getVal())) {
if (e.getVals() == null) {
if (e.getVal() < mYMin)
mYMin = e.getVal();
if (e.getVal() > mYMax)
mYMax = e.getVal();
} else {
if (-e.getNegativeSum() < mYMin)
mYMin = -e.getNegativeSum();
if (e.getPositiveSum() > mYMax)
mYMax = e.getPositiveSum();
}
}
}
if (mYMin == Float.MAX_VALUE) {
mYMin = 0.f;
mYMax = 0.f;
}
}
@Override
public int getStackSize() {
return mStackSize;
}
@Override
public boolean isStacked() {
return mStackSize > 1 ? true : false;
}
/**
* returns the overall entry count, including counting each stack-value
* individually
*
* @return
*/
public int getEntryCountStacks() {
return mEntryCountStacks;
}
/**
* returns the space between bars in percent of the whole width of one value
*
* @return
*/
public float getBarSpacePercent() {
return mBarSpace * 100f;
}
@Override
public float getBarSpace() {
return mBarSpace;
}
/**
* sets the space between the bars in percent (0-100) of the total bar width
*
* @param percent
*/
public void setBarSpacePercent(float percent) {
mBarSpace = percent / 100f;
}
/**
* Sets the color used for drawing the bar-shadows. The bar shadows is a
* surface behind the bar that indicates the maximum value. Don't for get to
* use getResources().getColor(...) to set this. Or Color.rgb(...).
*
* @param color
*/
public void setBarShadowColor(int color) {
mBarShadowColor = color;
}
@Override
public int getBarShadowColor() {
return mBarShadowColor;
}
/**
* Sets the width used for drawing borders around the bars.
* If borderWidth == 0, no border will be drawn.
*
* @return
*/
public void setBarBorderWidth(float width) {
mBarBorderWidth = width;
}
/**
* Returns the width used for drawing borders around the bars.
* If borderWidth == 0, no border will be drawn.
*
* @return
*/
@Override
public float getBarBorderWidth() {
return mBarBorderWidth;
}
/**
* Sets the color drawing borders around the bars.
*
* @return
*/
public void setBarBorderColor(int color) {
mBarBorderColor = color;
}
/**
* Returns the color drawing borders around the bars.
*
* @return
*/
@Override
public int getBarBorderColor() {
return mBarBorderColor;
}
/**
* Set the alpha value (transparency) that is used for drawing the highlight
* indicator bar. min = 0 (fully transparent), max = 255 (fully opaque)
*
* @param alpha
*/
public void setHighLightAlpha(int alpha) {
mHighLightAlpha = alpha;
}
@Override
public int getHighLightAlpha() {
return mHighLightAlpha;
}
/**
* Sets labels for different values of bar-stacks, in case there are one.
*
* @param labels
*/
public void setStackLabels(String[] labels) {
mStackLabels = labels;
}
@Override
public String[] getStackLabels() {
return mStackLabels;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/BarDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 1,714 |
```java
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
import java.util.List;
/**
* Baseclass for all Line, Bar, Scatter, Candle and Bubble data.
*
* @author Philipp Jahoda
*/
public abstract class BarLineScatterCandleBubbleData<T extends IBarLineScatterCandleBubbleDataSet<? extends Entry>>
extends ChartData<T> {
public BarLineScatterCandleBubbleData() {
super();
}
public BarLineScatterCandleBubbleData(List<String> xVals) {
super(xVals);
}
public BarLineScatterCandleBubbleData(String[] xVals) {
super(xVals);
}
public BarLineScatterCandleBubbleData(List<String> xVals, List<T> sets) {
super(xVals, sets);
}
public BarLineScatterCandleBubbleData(String[] xVals, List<T> sets) {
super(xVals, sets);
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/BarLineScatterCandleBubbleData.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 226 |
```java
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import java.util.ArrayList;
import java.util.List;
/**
* Data object that represents all data for the BarChart.
*
* @author Philipp Jahoda
*/
public class BarData extends BarLineScatterCandleBubbleData<IBarDataSet> {
/** the space that is left between groups of bars */
private float mGroupSpace = 0.8f;
// /**
// * The maximum space (in pixels on the screen) a single bar can consume.
// */
// private float mMaximumBarWidth = 100f;
public BarData() {
super();
}
public BarData(List<String> xVals) {
super(xVals);
}
public BarData(String[] xVals) {
super(xVals);
}
public BarData(List<String> xVals, List<IBarDataSet> dataSets) {
super(xVals, dataSets);
}
public BarData(String[] xVals, List<IBarDataSet> dataSets) {
super(xVals, dataSets);
}
public BarData(List<String> xVals, IBarDataSet dataSet) {
super(xVals, toList(dataSet));
}
public BarData(String[] xVals, IBarDataSet dataSet) {
super(xVals, toList(dataSet));
}
private static List<IBarDataSet> toList(IBarDataSet dataSet) {
List<IBarDataSet> sets = new ArrayList<>();
sets.add(dataSet);
return sets;
}
/**
* Returns the space that is left out between groups of bars. Always returns
* 0 if the BarData object only contains one DataSet (because for one
* DataSet, there is no group-space needed).
*
* @return
*/
public float getGroupSpace() {
if (mDataSets.size() <= 1)
return 0f;
else
return mGroupSpace;
}
/**
* Sets the space between groups of bars of different datasets in percent of
* the total width of one bar. 100 = space is exactly one bar width,
* default: 80
*
* @param percent
*/
public void setGroupSpace(float percent) {
mGroupSpace = percent / 100f;
}
/**
* Returns true if this BarData object contains grouped DataSets (more than
* 1 DataSet).
*
* @return
*/
public boolean isGrouped() {
return mDataSets.size() > 1 ? true : false;
}
//
// /**
// * Sets the maximum width (in density pixels) a single bar in the barchart
// * should consume.
// *
// * @param max
// */
// public void setBarWidthMaximum(float max) {
// mMaximumBarWidth = Utils.convertDpToPixel(max);
// }
//
// /**
// * Returns the maximum width (in density pixels) a single bar in the
// * barchart should consume.
// *
// * @return
// */
// public float getBarWidthMaximum() {
// return mMaximumBarWidth;
// }
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/BarData.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 716 |
```java
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
import java.util.ArrayList;
import java.util.List;
public class BubbleData extends BarLineScatterCandleBubbleData<IBubbleDataSet> {
public BubbleData() {
super();
}
public BubbleData(List<String> xVals) {
super(xVals);
}
public BubbleData(String[] xVals) {
super(xVals);
}
public BubbleData(List<String> xVals, List<IBubbleDataSet> dataSets) {
super(xVals, dataSets);
}
public BubbleData(String[] xVals, List<IBubbleDataSet> dataSets) {
super(xVals, dataSets);
}
public BubbleData(List<String> xVals, IBubbleDataSet dataSet) {
super(xVals, toList(dataSet));
}
public BubbleData(String[] xVals, IBubbleDataSet dataSet) {
super(xVals, toList(dataSet));
}
private static List<IBubbleDataSet> toList(IBubbleDataSet dataSet) {
List<IBubbleDataSet> sets = new ArrayList<>();
sets.add(dataSet);
return sets;
}
/**
* Sets the width of the circle that surrounds the bubble when highlighted
* for all DataSet objects this data object contains, in dp.
*
* @param width
*/
public void setHighlightCircleWidth(float width) {
for (IBubbleDataSet set : mDataSets) {
set.setHighlightCircleWidth(width);
}
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/BubbleData.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 334 |
```java
package com.github.mikephil.charting.data;
import android.graphics.Paint;
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
import java.util.List;
/**
* DataSet for the CandleStickChart.
*
* @author Philipp Jahoda
*/
public class CandleDataSet extends LineScatterCandleRadarDataSet<CandleEntry> implements ICandleDataSet {
/**
* the width of the shadow of the candle
*/
private float mShadowWidth = 3f;
/**
* should the candle bars show?
* when false, only "ticks" will show
*
* - default: true
*/
private boolean mShowCandleBar = true;
/**
* the space between the candle entries, default 0.1f (10%)
*/
private float mBarSpace = 0.1f;
/**
* use candle color for the shadow
*/
private boolean mShadowColorSameAsCandle = false;
/**
* paint style when open < close
* increasing candlesticks are traditionally hollow
*/
protected Paint.Style mIncreasingPaintStyle = Paint.Style.STROKE;
/**
* paint style when open > close
* descreasing candlesticks are traditionally filled
*/
protected Paint.Style mDecreasingPaintStyle = Paint.Style.FILL;
/**
* color for open == close
*/
protected int mNeutralColor = ColorTemplate.COLOR_NONE;
/**
* color for open < close
*/
protected int mIncreasingColor = ColorTemplate.COLOR_NONE;
/**
* color for open > close
*/
protected int mDecreasingColor = ColorTemplate.COLOR_NONE;
/**
* shadow line color, set -1 for backward compatibility and uses default
* color
*/
protected int mShadowColor = ColorTemplate.COLOR_NONE;
public CandleDataSet(List<CandleEntry> yVals, String label) {
super(yVals, label);
}
@Override
public DataSet<CandleEntry> copy() {
List<CandleEntry> yVals = new ArrayList<>();
for (int i = 0; i < mYVals.size(); i++) {
yVals.add(((CandleEntry) mYVals.get(i)).copy());
}
CandleDataSet copied = new CandleDataSet(yVals, getLabel());
copied.mColors = mColors;
copied.mShadowWidth = mShadowWidth;
copied.mShowCandleBar = mShowCandleBar;
copied.mBarSpace = mBarSpace;
copied.mHighLightColor = mHighLightColor;
copied.mIncreasingPaintStyle = mIncreasingPaintStyle;
copied.mDecreasingPaintStyle = mDecreasingPaintStyle;
copied.mShadowColor = mShadowColor;
return copied;
}
@Override
public void calcMinMax(int start, int end) {
// super.calculate();
if (mYVals == null)
return;
if (mYVals.isEmpty())
return;
int endValue;
if (end == 0 || end >= mYVals.size())
endValue = mYVals.size() - 1;
else
endValue = end;
mYMin = Float.MAX_VALUE;
mYMax = -Float.MAX_VALUE;
for (int i = start; i <= endValue; i++) {
CandleEntry e = mYVals.get(i);
if (e.getLow() < mYMin)
mYMin = e.getLow();
if (e.getHigh() > mYMax)
mYMax = e.getHigh();
}
}
/**
* Sets the space that is left out on the left and right side of each
* candle, default 0.1f (10%), max 0.45f, min 0f
*
* @param space
*/
public void setBarSpace(float space) {
if (space < 0f)
space = 0f;
if (space > 0.45f)
space = 0.45f;
mBarSpace = space;
}
@Override
public float getBarSpace() {
return mBarSpace;
}
/**
* Sets the width of the candle-shadow-line in pixels. Default 3f.
*
* @param width
*/
public void setShadowWidth(float width) {
mShadowWidth = Utils.convertDpToPixel(width);
}
@Override
public float getShadowWidth() {
return mShadowWidth;
}
/**
* Sets whether the candle bars should show?
*
* @param showCandleBar
*/
public void setShowCandleBar(boolean showCandleBar) {
mShowCandleBar = showCandleBar;
}
@Override
public boolean getShowCandleBar() {
return mShowCandleBar;
}
// TODO
/**
* It is necessary to implement ColorsList class that will encapsulate
* colors list functionality, because It's wrong to copy paste setColor,
* addColor, ... resetColors for each time when we want to add a coloring
* options for one of objects
*
* @author Mesrop
*/
/** BELOW THIS COLOR HANDLING */
/**
* Sets the one and ONLY color that should be used for this DataSet when
* open == close.
*
* @param color
*/
public void setNeutralColor(int color) {
mNeutralColor = color;
}
@Override
public int getNeutralColor() {
return mNeutralColor;
}
/**
* Sets the one and ONLY color that should be used for this DataSet when
* open <= close.
*
* @param color
*/
public void setIncreasingColor(int color) {
mIncreasingColor = color;
}
@Override
public int getIncreasingColor() {
return mIncreasingColor;
}
/**
* Sets the one and ONLY color that should be used for this DataSet when
* open > close.
*
* @param color
*/
public void setDecreasingColor(int color) {
mDecreasingColor = color;
}
@Override
public int getDecreasingColor() {
return mDecreasingColor;
}
@Override
public Paint.Style getIncreasingPaintStyle() {
return mIncreasingPaintStyle;
}
/**
* Sets paint style when open < close
*
* @param paintStyle
*/
public void setIncreasingPaintStyle(Paint.Style paintStyle) {
this.mIncreasingPaintStyle = paintStyle;
}
@Override
public Paint.Style getDecreasingPaintStyle() {
return mDecreasingPaintStyle;
}
/**
* Sets paint style when open > close
*
* @param decreasingPaintStyle
*/
public void setDecreasingPaintStyle(Paint.Style decreasingPaintStyle) {
this.mDecreasingPaintStyle = decreasingPaintStyle;
}
@Override
public int getShadowColor() {
return mShadowColor;
}
/**
* Sets shadow color for all entries
*
* @param shadowColor
*/
public void setShadowColor(int shadowColor) {
this.mShadowColor = shadowColor;
}
@Override
public boolean getShadowColorSameAsCandle() {
return mShadowColorSameAsCandle;
}
/**
* Sets shadow color to be the same color as the candle color
*
* @param shadowColorSameAsCandle
*/
public void setShadowColorSameAsCandle(boolean shadowColorSameAsCandle) {
this.mShadowColorSameAsCandle = shadowColorSameAsCandle;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/CandleDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 1,696 |
```java
package com.github.mikephil.charting.data;
import android.graphics.Color;
import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
import java.util.List;
/**
* Baseclass of all DataSets for Bar-, Line-, Scatter- and CandleStickChart.
*
* @author Philipp Jahoda
*/
public abstract class BarLineScatterCandleBubbleDataSet<T extends Entry> extends DataSet<T> implements IBarLineScatterCandleBubbleDataSet<T> {
/** default highlight color */
protected int mHighLightColor = Color.rgb(255, 187, 115);
public BarLineScatterCandleBubbleDataSet(List<T> yVals, String label) {
super(yVals, label);
}
/**
* Sets the color that is used for drawing the highlight indicators. Dont
* forget to resolve the color using getResources().getColor(...) or
* Color.rgb(...).
*
* @param color
*/
public void setHighLightColor(int color) {
mHighLightColor = color;
}
@Override
public int getHighLightColor() {
return mHighLightColor;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 251 |
```java
package com.github.mikephil.charting.data;
import android.content.Context;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.formatter.DefaultFillFormatter;
import com.github.mikephil.charting.formatter.FillFormatter;
import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
import java.util.List;
public class LineDataSet extends LineRadarDataSet<Entry> implements ILineDataSet {
/** Drawing mode for this line dataset **/
private Mode mMode = Mode.LINEAR;
/** List representing all colors that are used for the circles */
private List<Integer> mCircleColors = null;
/** the color of the inner circles */
private int mCircleColorHole = Color.WHITE;
/** the radius of the circle-shaped value indicators */
private float mCircleRadius = 8f;
/** the hole radius of the circle-shaped value indicators */
private float mCircleHoleRadius = 4f;
/** sets the intensity of the cubic lines */
private float mCubicIntensity = 0.2f;
/** the path effect of this DataSet that makes dashed lines possible */
private DashPathEffect mDashPathEffect = null;
/** formatter for customizing the position of the fill-line */
private FillFormatter mFillFormatter = new DefaultFillFormatter();
/** if true, drawing circles is enabled */
private boolean mDrawCircles = true;
private boolean mDrawCircleHole = true;
public LineDataSet(List<Entry> yVals, String label) {
super(yVals, label);
// mCircleRadius = Utils.convertDpToPixel(4f);
// mLineWidth = Utils.convertDpToPixel(1f);
mCircleColors = new ArrayList<>();
// default colors
// mColors.add(Color.rgb(192, 255, 140));
// mColors.add(Color.rgb(255, 247, 140));
mCircleColors.add(Color.rgb(140, 234, 255));
}
@Override
public DataSet<Entry> copy() {
List<Entry> yVals = new ArrayList<>();
for (int i = 0; i < mYVals.size(); i++) {
yVals.add(mYVals.get(i).copy());
}
LineDataSet copied = new LineDataSet(yVals, getLabel());
copied.mMode = mMode;
copied.mColors = mColors;
copied.mCircleRadius = mCircleRadius;
copied.mCircleHoleRadius = mCircleHoleRadius;
copied.mCircleColors = mCircleColors;
copied.mDashPathEffect = mDashPathEffect;
copied.mDrawCircles = mDrawCircles;
copied.mDrawCircleHole = mDrawCircleHole;
copied.mHighLightColor = mHighLightColor;
return copied;
}
/**
* Returns the drawing mode for this line dataset
*
* @return
*/
@Override
public Mode getMode() {
return mMode;
}
/**
* Returns the drawing mode for this line dataset
*
* @return
*/
public void setMode(Mode mode) {
mMode = mode;
}
/**
* Sets the intensity for cubic lines (if enabled). Max = 1f = very cubic,
* Min = 0.05f = low cubic effect, Default: 0.2f
*
* @param intensity
*/
public void setCubicIntensity(float intensity) {
if (intensity > 1f)
intensity = 1f;
if (intensity < 0.05f)
intensity = 0.05f;
mCubicIntensity = intensity;
}
@Override
public float getCubicIntensity() {
return mCubicIntensity;
}
/**
* sets the radius of the drawn circles.
* Default radius = 4f
*
* @param radius
*/
public void setCircleRadius(float radius) {
mCircleRadius = Utils.convertDpToPixel(radius);
}
@Override
public float getCircleRadius() {
return mCircleRadius;
}
/**
* sets the hole radius of the drawn circles.
* Default radius = 2f
*
* @param holeRadius
*/
public void setCircleHoleRadius(float holeRadius) {
mCircleHoleRadius = Utils.convertDpToPixel(holeRadius);
}
@Override
public float getCircleHoleRadius() {
return mCircleHoleRadius;
}
/**
* @deprecated Kept for backward compatibility.
* sets the size (radius) of the circle shpaed value indicators,
* default size = 4f
*
* This method is deprecated because of unclarity. Use setCircleRadius instead.
*
* @param size
*/
@Deprecated
public void setCircleSize(float size) {
setCircleRadius(size);
}
/**
* @deprecated Kept for backward compatibility.
* This function is deprecated because of unclarity. Use getCircleRadius instead.
*
*/
@Deprecated
public float getCircleSize() {
return getCircleRadius();
}
/**
* Enables the line to be drawn in dashed mode, e.g. like this
* "- - - - - -". THIS ONLY WORKS IF HARDWARE-ACCELERATION IS TURNED OFF.
* Keep in mind that hardware acceleration boosts performance.
*
* @param lineLength the length of the line pieces
* @param spaceLength the length of space in between the pieces
* @param phase offset, in degrees (normally, use 0)
*/
public void enableDashedLine(float lineLength, float spaceLength, float phase) {
mDashPathEffect = new DashPathEffect(new float[] {
lineLength, spaceLength
}, phase);
}
/**
* Disables the line to be drawn in dashed mode.
*/
public void disableDashedLine() {
mDashPathEffect = null;
}
@Override
public boolean isDashedLineEnabled() {
return mDashPathEffect == null ? false : true;
}
@Override
public DashPathEffect getDashPathEffect() {
return mDashPathEffect;
}
/**
* set this to true to enable the drawing of circle indicators for this
* DataSet, default true
*
* @param enabled
*/
public void setDrawCircles(boolean enabled) {
this.mDrawCircles = enabled;
}
@Override
public boolean isDrawCirclesEnabled() {
return mDrawCircles;
}
/**
* @deprecated Kept for backward compatibility.
* @param enabled
*/
@Deprecated
public void setDrawCubic(boolean enabled) {
mMode = enabled ? Mode.CUBIC_BEZIER : Mode.LINEAR;
}
/**
* @deprecated Kept for backward compatibility.
* @return
*/
@Deprecated
@Override
public boolean isDrawCubicEnabled() {
return mMode == Mode.CUBIC_BEZIER;
}
/**
* @deprecated Kept for backward compatibility.
* @param enabled
*/
@Deprecated
public void setDrawStepped(boolean enabled) {
mMode = enabled ? Mode.STEPPED : Mode.LINEAR;
}
/**
* @deprecated Kept for backward compatibility.
* @return
*/
@Deprecated
@Override
public boolean isDrawSteppedEnabled() {
return mMode == Mode.STEPPED;
}
/** ALL CODE BELOW RELATED TO CIRCLE-COLORS */
/**
* returns all colors specified for the circles
*
* @return
*/
public List<Integer> getCircleColors() {
return mCircleColors;
}
@Override
public int getCircleColor(int index) {
return mCircleColors.get(index % mCircleColors.size());
}
/**
* Sets the colors that should be used for the circles of this DataSet.
* Colors are reused as soon as the number of Entries the DataSet represents
* is higher than the size of the colors array. Make sure that the colors
* are already prepared (by calling getResources().getColor(...)) before
* adding them to the DataSet.
*
* @param colors
*/
public void setCircleColors(List<Integer> colors) {
mCircleColors = colors;
}
/**
* Sets the colors that should be used for the circles of this DataSet.
* Colors are reused as soon as the number of Entries the DataSet represents
* is higher than the size of the colors array. Make sure that the colors
* are already prepared (by calling getResources().getColor(...)) before
* adding them to the DataSet.
*
* @param colors
*/
public void setCircleColors(int[] colors) {
this.mCircleColors = ColorTemplate.createColors(colors);
}
/**
* ets the colors that should be used for the circles of this DataSet.
* Colors are reused as soon as the number of Entries the DataSet represents
* is higher than the size of the colors array. You can use
* "new String[] { R.color.red, R.color.green, ... }" to provide colors for
* this method. Internally, the colors are resolved using
* getResources().getColor(...)
*
* @param colors
*/
public void setCircleColors(int[] colors, Context c) {
List<Integer> clrs = new ArrayList<>();
for (int color : colors) {
clrs.add(c.getResources().getColor(color));
}
mCircleColors = clrs;
}
/**
* Sets the one and ONLY color that should be used for this DataSet.
* Internally, this recreates the colors array and adds the specified color.
*
* @param color
*/
public void setCircleColor(int color) {
resetCircleColors();
mCircleColors.add(color);
}
/**
* resets the circle-colors array and creates a new one
*/
public void resetCircleColors() {
mCircleColors = new ArrayList<>();
}
/**
* Sets the color of the inner circle of the line-circles.
*
* @param color
*/
public void setCircleColorHole(int color) {
mCircleColorHole = color;
}
@Override
public int getCircleHoleColor() {
return mCircleColorHole;
}
/**
* Set this to true to allow drawing a hole in each data circle.
*
* @param enabled
*/
public void setDrawCircleHole(boolean enabled) {
mDrawCircleHole = enabled;
}
@Override
public boolean isDrawCircleHoleEnabled() {
return mDrawCircleHole;
}
/**
* Sets a custom FillFormatter to the chart that handles the position of the
* filled-line for each DataSet. Set this to null to use the default logic.
*
* @param formatter
*/
public void setFillFormatter(FillFormatter formatter) {
if (formatter == null)
mFillFormatter = new DefaultFillFormatter();
else
mFillFormatter = formatter;
}
@Override
public FillFormatter getFillFormatter() {
return mFillFormatter;
}
public enum Mode {
LINEAR,
STEPPED,
CUBIC_BEZIER,
HORIZONTAL_BEZIER
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/LineDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 2,542 |
```java
package com.github.mikephil.charting.data;
import android.graphics.Color;
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import java.util.ArrayList;
import java.util.List;
public class RadarDataSet extends LineRadarDataSet<Entry> implements IRadarDataSet {
/// flag indicating whether highlight circle should be drawn or not
protected boolean mDrawHighlightCircleEnabled = false;
protected int mHighlightCircleFillColor = Color.WHITE;
/// The stroke color for highlight circle.
/// If Utils.COLOR_NONE, the color of the dataset is taken.
protected int mHighlightCircleStrokeColor = ColorTemplate.COLOR_NONE;
protected int mHighlightCircleStrokeAlpha = (int)(0.3 * 255);
protected float mHighlightCircleInnerRadius = 3.0f;
protected float mHighlightCircleOuterRadius = 4.0f;
protected float mHighlightCircleStrokeWidth = 2.0f;
public RadarDataSet(List<Entry> yVals, String label) {
super(yVals, label);
}
/// Returns true if highlight circle should be drawn, false if not
@Override
public boolean isDrawHighlightCircleEnabled()
{
return mDrawHighlightCircleEnabled;
}
/// Sets whether highlight circle should be drawn or not
@Override
public void setDrawHighlightCircleEnabled(boolean enabled)
{
mDrawHighlightCircleEnabled = enabled;
}
@Override
public int getHighlightCircleFillColor()
{
return mHighlightCircleFillColor;
}
public void setHighlightCircleFillColor(int color)
{
mHighlightCircleFillColor = color;
}
/// Returns the stroke color for highlight circle.
/// If Utils.COLOR_NONE, the color of the dataset is taken.
@Override
public int getHighlightCircleStrokeColor()
{
return mHighlightCircleStrokeColor;
}
/// Sets the stroke color for highlight circle.
/// Set to Utils.COLOR_NONE in order to use the color of the dataset;
public void setHighlightCircleStrokeColor(int color)
{
mHighlightCircleStrokeColor = color;
}
@Override
public int getHighlightCircleStrokeAlpha()
{
return mHighlightCircleStrokeAlpha;
}
public void setHighlightCircleStrokeAlpha(int alpha)
{
mHighlightCircleStrokeAlpha = alpha;
}
@Override
public float getHighlightCircleInnerRadius()
{
return mHighlightCircleInnerRadius;
}
public void setHighlightCircleInnerRadius(float radius)
{
mHighlightCircleInnerRadius = radius;
}
@Override
public float getHighlightCircleOuterRadius()
{
return mHighlightCircleOuterRadius;
}
public void setHighlightCircleOuterRadius(float radius)
{
mHighlightCircleOuterRadius = radius;
}
@Override
public float getHighlightCircleStrokeWidth()
{
return mHighlightCircleStrokeWidth;
}
public void setHighlightCircleStrokeWidth(float strokeWidth)
{
mHighlightCircleStrokeWidth = strokeWidth;
}
@Override
public DataSet<Entry> copy() {
List<Entry> yVals = new ArrayList<>();
for (int i = 0; i < mYVals.size(); i++) {
yVals.add(mYVals.get(i).copy());
}
RadarDataSet copied = new RadarDataSet(yVals, getLabel());
copied.mColors = mColors;
copied.mHighLightColor = mHighLightColor;
return copied;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/RadarDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 748 |
```java
package com.github.mikephil.charting.data;
import android.annotation.TargetApi;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.interfaces.datasets.ILineRadarDataSet;
import com.github.mikephil.charting.utils.Utils;
import java.util.List;
/**
* Base dataset for line and radar DataSets.
*
* @author Philipp Jahoda
*/
public abstract class LineRadarDataSet<T extends Entry> extends LineScatterCandleRadarDataSet<T> implements ILineRadarDataSet<T> {
/**
* the color that is used for filling the line surface
*/
private int mFillColor = Color.rgb(140, 234, 255);
/**
* the drawable to be used for filling the line surface
*/
protected Drawable mFillDrawable;
/**
* transparency used for filling line surface
*/
private int mFillAlpha = 85;
/**
* the width of the drawn data lines
*/
private float mLineWidth = 2.5f;
/**
* if true, the data will also be drawn filled
*/
private boolean mDrawFilled = false;
public LineRadarDataSet(List<T> yVals, String label) {
super(yVals, label);
}
@Override
public int getFillColor() {
return mFillColor;
}
/**
* Sets the color that is used for filling the area below the line.
* Resets an eventually set "fillDrawable".
*
* @param color
*/
public void setFillColor(int color) {
mFillColor = color;
mFillDrawable = null;
}
@Override
public Drawable getFillDrawable() {
return mFillDrawable;
}
/**
* Sets the drawable to be used to fill the area below the line.
*
* @param drawable
*/
@TargetApi(18)
public void setFillDrawable(Drawable drawable) {
this.mFillDrawable = drawable;
}
@Override
public int getFillAlpha() {
return mFillAlpha;
}
/**
* sets the alpha value (transparency) that is used for filling the line
* surface (0-255), default: 85
*
* @param alpha
*/
public void setFillAlpha(int alpha) {
mFillAlpha = alpha;
}
/**
* set the line width of the chart (min = 0.2f, max = 10f); default 1f 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 > 10.0f)
width = 10.0f;
mLineWidth = Utils.convertDpToPixel(width);
}
@Override
public float getLineWidth() {
return mLineWidth;
}
@Override
public void setDrawFilled(boolean filled) {
mDrawFilled = filled;
}
@Override
public boolean isDrawFilledEnabled() {
return mDrawFilled;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/LineRadarDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 692 |
```java
package com.github.mikephil.charting.data;
/**
* Subclass of Entry that holds all values for one entry in a CandleStickChart.
*
* @author Philipp Jahoda
*/
public class CandleEntry extends Entry {
/** shadow-high value */
private float mShadowHigh = 0f;
/** shadow-low value */
private float mShadowLow = 0f;
/** close value */
private float mClose = 0f;
/** open value */
private float mOpen = 0f;
/**
* Constructor.
*
* @param xIndex The index on the x-axis.
* @param shadowH The (shadow) high value.
* @param shadowL The (shadow) low value.
* @param open The open value.
* @param close The close value.
*/
public CandleEntry(int xIndex, float shadowH, float shadowL, float open, float close) {
super((shadowH + shadowL) / 2f, xIndex);
this.mShadowHigh = shadowH;
this.mShadowLow = shadowL;
this.mOpen = open;
this.mClose = close;
}
/**
* Constructor.
*
* @param xIndex The index on the x-axis.
* @param shadowH The (shadow) high value.
* @param shadowL The (shadow) low value.
* @param open
* @param close
* @param data Spot for additional data this Entry represents.
*/
public CandleEntry(int xIndex, float shadowH, float shadowL, float open, float close,
Object data) {
super((shadowH + shadowL) / 2f, xIndex, data);
this.mShadowHigh = shadowH;
this.mShadowLow = shadowL;
this.mOpen = open;
this.mClose = close;
}
/**
* Returns the overall range (difference) between shadow-high and
* shadow-low.
*
* @return
*/
public float getShadowRange() {
return Math.abs(mShadowHigh - mShadowLow);
}
/**
* Returns the body size (difference between open and close).
*
* @return
*/
public float getBodyRange() {
return Math.abs(mOpen - mClose);
}
/**
* Returns the center value of the candle. (Middle value between high and
* low)
*/
@Override
public float getVal() {
return super.getVal();
}
public CandleEntry copy() {
return new CandleEntry(getXIndex(), mShadowHigh, mShadowLow, mOpen,
mClose, getData());
}
/**
* Returns the upper shadows highest value.
*
* @return
*/
public float getHigh() {
return mShadowHigh;
}
public void setHigh(float mShadowHigh) {
this.mShadowHigh = mShadowHigh;
}
/**
* Returns the lower shadows lowest value.
*
* @return
*/
public float getLow() {
return mShadowLow;
}
public void setLow(float mShadowLow) {
this.mShadowLow = mShadowLow;
}
/**
* Returns the bodys close value.
*
* @return
*/
public float getClose() {
return mClose;
}
public void setClose(float mClose) {
this.mClose = mClose;
}
/**
* Returns the bodys open value.
*
* @return
*/
public float getOpen() {
return mOpen;
}
public void setOpen(float mOpen) {
this.mOpen = mOpen;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/CandleEntry.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 814 |
```java
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
import java.util.ArrayList;
import java.util.List;
/**
* Data object that allows the combination of Line-, Bar-, Scatter-, Bubble- and
* CandleData. Used in the CombinedChart class.
*
* @author Philipp Jahoda
*/
public class CombinedData extends BarLineScatterCandleBubbleData<IBarLineScatterCandleBubbleDataSet<?>> {
private LineData mLineData;
private BarData mBarData;
private ScatterData mScatterData;
private CandleData mCandleData;
private BubbleData mBubbleData;
public CombinedData() {
super();
}
public CombinedData(List<String> xVals) {
super(xVals);
}
public CombinedData(String[] xVals) {
super(xVals);
}
public void setData(LineData data) {
mLineData = data;
mDataSets.addAll(data.getDataSets());
init();
}
public void setData(BarData data) {
mBarData = data;
mDataSets.addAll(data.getDataSets());
init();
}
public void setData(ScatterData data) {
mScatterData = data;
mDataSets.addAll(data.getDataSets());
init();
}
public void setData(CandleData data) {
mCandleData = data;
mDataSets.addAll(data.getDataSets());
init();
}
public void setData(BubbleData data) {
mBubbleData = data;
mDataSets.addAll(data.getDataSets());
init();
}
public BubbleData getBubbleData() {
return mBubbleData;
}
public LineData getLineData() {
return mLineData;
}
public BarData getBarData() {
return mBarData;
}
public ScatterData getScatterData() {
return mScatterData;
}
public CandleData getCandleData() {
return mCandleData;
}
/**
* Returns all data objects in row: line-bar-scatter-candle-bubble if not null.
* @return
*/
public List<ChartData> getAllData() {
List<ChartData> data = new ArrayList<>();
if(mLineData != null)
data.add(mLineData);
if(mBarData != null)
data.add(mBarData);
if(mScatterData != null)
data.add(mScatterData);
if(mCandleData != null)
data.add(mCandleData);
if(mBubbleData != null)
data.add(mBubbleData);
return data;
}
@Override
public void notifyDataChanged() {
if (mLineData != null)
mLineData.notifyDataChanged();
if (mBarData != null)
mBarData.notifyDataChanged();
if (mCandleData != null)
mCandleData.notifyDataChanged();
if (mScatterData != null)
mScatterData.notifyDataChanged();
if (mBubbleData != null)
mBubbleData.notifyDataChanged();
init(); // recalculate everything
}
/**
* Get the Entry for a corresponding highlight object
*
* @param highlight
* @return the entry that is highlighted
*/
@Override
public Entry getEntryForHighlight(Highlight highlight) {
List<ChartData> dataObjects = getAllData();
if (highlight.getDataIndex() >= dataObjects.size())
return null;
ChartData data = dataObjects.get(highlight.getDataIndex());
if (highlight.getDataSetIndex() >= data.getDataSetCount())
return null;
else {
// The value of the highlighted entry could be NaN -
// if we are not interested in highlighting a specific value.
List<?> entries = data.getDataSetByIndex(highlight.getDataSetIndex())
.getEntriesForXIndex(highlight.getXIndex());
for (Object entry : entries)
if (((Entry)entry).getVal() == highlight.getValue() ||
Float.isNaN(highlight.getValue()))
return (Entry)entry;
return null;
}
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/CombinedData.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 904 |
```java
package com.github.mikephil.charting.data;
import android.graphics.Typeface;
import android.util.Log;
import com.github.mikephil.charting.components.YAxis.AxisDependency;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Class that holds all relevant data that represents the chart. That involves
* at least one (or more) DataSets, and an array of x-values.
*
* @author Philipp Jahoda
*/
public abstract class ChartData<T extends IDataSet<? extends Entry>> {
/**
* maximum y-value in the y-value array across all axes
*/
protected float mYMax = 0.0f;
/**
* the minimum y-value in the y-value array across all axes
*/
protected float mYMin = 0.0f;
protected float mLeftAxisMax = 0.0f;
protected float mLeftAxisMin = 0.0f;
protected float mRightAxisMax = 0.0f;
protected float mRightAxisMin = 0.0f;
/**
* total number of y-values across all DataSet objects
*/
private int mYValCount = 0;
/**
* contains the maximum length (in characters) an entry in the x-vals array
* has
*/
private float mXValMaximumLength = 0;
/**
* holds all x-values the chart represents
*/
protected List<String> mXVals;
/**
* array that holds all DataSets the ChartData object represents
*/
protected List<T> mDataSets;
public ChartData() {
mXVals = new ArrayList<>();
mDataSets = new ArrayList<>();
}
/**
* Constructor for only x-values. This constructor can be used for setting
* up an empty chart without data.
*
* @param xVals
*/
public ChartData(List<String> xVals) {
this.mXVals = xVals;
this.mDataSets = new ArrayList<>();
init();
}
/**
* Constructor for only x-values. This constructor can be used for setting
* up an empty chart without data.
*
* @param xVals
*/
public ChartData(String[] xVals) {
this.mXVals = arrayToList(xVals);
this.mDataSets = new ArrayList<>();
init();
}
/**
* constructor for chart data
*
* @param xVals The values describing the x-axis. Must be at least as long
* as the highest xIndex in the Entry objects across all
* DataSets.
* @param sets the dataset array
*/
public ChartData(List<String> xVals, List<T> sets) {
this.mXVals = xVals;
this.mDataSets = sets;
init();
}
/**
* constructor that takes string array instead of List string
*
* @param xVals The values describing the x-axis. Must be at least as long
* as the highest xIndex in the Entry objects across all
* DataSets.
* @param sets the dataset array
*/
public ChartData(String[] xVals, List<T> sets) {
this.mXVals = arrayToList(xVals);
this.mDataSets = sets;
init();
}
/**
* Turns an array of strings into an List of strings.
*
* @param array
* @return
*/
private List<String> arrayToList(String[] array) {
return Arrays.asList(array);
}
/**
* performs all kinds of initialization calculations, such as min-max and
* value count and sum
*/
protected void init() {
checkLegal();
calcYValueCount();
calcMinMax(0, mYValCount);
calcXValMaximumLength();
}
/**
* calculates the average length (in characters) across all x-value strings
*
*/
private void calcXValMaximumLength() {
if (mXVals.size() <= 0) {
mXValMaximumLength = 1;
return;
}
int max = 1;
for (int i = 0; i < mXVals.size(); i++) {
if (mXVals.get(i) != null) {
int length = mXVals.get(i).length();
if (length > max)
max = length;
}
}
mXValMaximumLength = max;
}
/**
* Checks if the combination of x-values array and DataSet array is legal or
* not.
*/
private void checkLegal() {
if (mDataSets == null)
return;
if (this instanceof ScatterData || this instanceof CombinedData)
return;
for (int i = 0; i < mDataSets.size(); i++) {
if (mDataSets.get(i).getEntryCount() > mXVals.size()) {
throw new IllegalArgumentException(
"One or more of the DataSet Entry arrays are longer than the x-values array of this ChartData object.");
}
}
}
/**
* Call this method to let the ChartData know that the underlying data has
* changed. Calling this performs all necessary recalculations needed when
* the contained data has changed.
*/
public void notifyDataChanged() {
init();
}
/**
* calc minimum and maximum y value over all datasets
*/
public void calcMinMax(int start, int end) {
if (mDataSets == null || mDataSets.size() < 1) {
mYMax = 0f;
mYMin = 0f;
} else {
mYMin = Float.MAX_VALUE;
mYMax = -Float.MAX_VALUE;
for (int i = 0; i < mDataSets.size(); i++) {
IDataSet set = mDataSets.get(i);
set.calcMinMax(start, end);
if (set.getYMin() < mYMin)
mYMin = set.getYMin();
if (set.getYMax() > mYMax)
mYMax = set.getYMax();
}
if (mYMin == Float.MAX_VALUE) {
mYMin = 0.f;
mYMax = 0.f;
}
// left axis
T firstLeft = getFirstLeft();
if (firstLeft != null) {
mLeftAxisMax = firstLeft.getYMax();
mLeftAxisMin = firstLeft.getYMin();
for (IDataSet dataSet : mDataSets) {
if (dataSet.getAxisDependency() == AxisDependency.LEFT) {
if (dataSet.getYMin() < mLeftAxisMin)
mLeftAxisMin = dataSet.getYMin();
if (dataSet.getYMax() > mLeftAxisMax)
mLeftAxisMax = dataSet.getYMax();
}
}
}
// right axis
T firstRight = getFirstRight();
if (firstRight != null) {
mRightAxisMax = firstRight.getYMax();
mRightAxisMin = firstRight.getYMin();
for (IDataSet dataSet : mDataSets) {
if (dataSet.getAxisDependency() == AxisDependency.RIGHT) {
if (dataSet.getYMin() < mRightAxisMin)
mRightAxisMin = dataSet.getYMin();
if (dataSet.getYMax() > mRightAxisMax)
mRightAxisMax = dataSet.getYMax();
}
}
}
// in case there is only one axis, adjust the second axis
handleEmptyAxis(firstLeft, firstRight);
}
}
/**
* Calculates the total number of y-values across all DataSets the ChartData
* represents.
*
* @return
*/
protected void calcYValueCount() {
mYValCount = 0;
if (mDataSets == null)
return;
int count = 0;
for (int i = 0; i < mDataSets.size(); i++) {
count += mDataSets.get(i).getEntryCount();
}
mYValCount = count;
}
/** ONLY GETTERS AND SETTERS BELOW THIS */
/**
* returns the number of LineDataSets this object contains
*
* @return
*/
public int getDataSetCount() {
if (mDataSets == null)
return 0;
return mDataSets.size();
}
/**
* Returns the smallest y-value the data object contains.
*
* @return
*/
public float getYMin() {
return mYMin;
}
/**
* Returns the minimum y-value for the specified axis.
*
* @param axis
* @return
*/
public float getYMin(AxisDependency axis) {
if (axis == AxisDependency.LEFT)
return mLeftAxisMin;
else
return mRightAxisMin;
}
/**
* Returns the greatest y-value the data object contains.
*
* @return
*/
public float getYMax() {
return mYMax;
}
/**
* Returns the maximum y-value for the specified axis.
*
* @param axis
* @return
*/
public float getYMax(AxisDependency axis) {
if (axis == AxisDependency.LEFT)
return mLeftAxisMax;
else
return mRightAxisMax;
}
/**
* returns the maximum length (in characters) across all values in the
* x-vals array
*
* @return
*/
public float getXValMaximumLength() {
return mXValMaximumLength;
}
/**
* Returns the total number of y-values across all DataSet objects the this
* object represents.
*
* @return
*/
public int getYValCount() {
return mYValCount;
}
/**
* returns the x-values the chart represents
*
* @return
*/
public List<String> getXVals() {
return mXVals;
}
/**
* sets the x-values the chart represents
*
*/
public void setXVals(List<String> xVals) {
mXVals = xVals;
}
/**
* Adds a new x-value to the chart data.
*
* @param xVal
*/
public void addXValue(String xVal) {
if (xVal != null && xVal.length() > mXValMaximumLength)
mXValMaximumLength = xVal.length();
mXVals.add(xVal);
}
/**
* Removes the x-value at the specified index.
*
* @param index
*/
public void removeXValue(int index) {
mXVals.remove(index);
}
public List<T> getDataSets() {
return mDataSets;
}
/**
* Retrieve the index of a DataSet with a specific label from the ChartData.
* Search can be case sensitive or not. IMPORTANT: This method does
* calculations at runtime, do not over-use in performance critical
* situations.
*
* @param dataSets the DataSet array to search
* @param label
* @param ignorecase if true, the search is not case-sensitive
* @return
*/
protected int getDataSetIndexByLabel(List<T> dataSets, String label,
boolean ignorecase) {
if (ignorecase) {
for (int i = 0; i < dataSets.size(); i++)
if (label.equalsIgnoreCase(dataSets.get(i).getLabel()))
return i;
} else {
for (int i = 0; i < dataSets.size(); i++)
if (label.equals(dataSets.get(i).getLabel()))
return i;
}
return -1;
}
/**
* returns the total number of x-values this ChartData object represents
* (the size of the x-values array)
*
* @return
*/
public int getXValCount() {
return mXVals.size();
}
/**
* Returns the labels of all DataSets as a string array.
*
* @return
*/
protected String[] getDataSetLabels() {
String[] types = new String[mDataSets.size()];
for (int i = 0; i < mDataSets.size(); i++) {
types[i] = mDataSets.get(i).getLabel();
}
return types;
}
/**
* Get the Entry for a corresponding highlight object
*
* @param highlight
* @return the entry that is highlighted
*/
public Entry getEntryForHighlight(Highlight highlight) {
if (highlight.getDataSetIndex() >= mDataSets.size())
return null;
else {
// The value of the highlighted entry could be NaN -
// if we are not interested in highlighting a specific value.
List<?> entries = mDataSets.get(highlight.getDataSetIndex())
.getEntriesForXIndex(highlight.getXIndex());
for (Object entry : entries)
if (((Entry)entry).getVal() == highlight.getValue() ||
Float.isNaN(highlight.getValue()))
return (Entry)entry;
return null;
}
}
/**
* Returns the DataSet object with the given label. Search can be case
* sensitive or not. IMPORTANT: This method does calculations at runtime.
* Use with care in performance critical situations.
*
* @param label
* @param ignorecase
* @return
*/
public T getDataSetByLabel(String label, boolean ignorecase) {
int index = getDataSetIndexByLabel(mDataSets, label, ignorecase);
if (index < 0 || index >= mDataSets.size())
return null;
else
return mDataSets.get(index);
}
public T getDataSetByIndex(int index) {
if (mDataSets == null || index < 0 || index >= mDataSets.size())
return null;
return mDataSets.get(index);
}
/**
* Adds a DataSet dynamically.
*
* @param d
*/
public void addDataSet(T d) {
if (d == null)
return;
mYValCount += d.getEntryCount();
if (mDataSets.size() <= 0) {
mYMax = d.getYMax();
mYMin = d.getYMin();
if (d.getAxisDependency() == AxisDependency.LEFT) {
mLeftAxisMax = d.getYMax();
mLeftAxisMin = d.getYMin();
} else {
mRightAxisMax = d.getYMax();
mRightAxisMin = d.getYMin();
}
} else {
if (mYMax < d.getYMax())
mYMax = d.getYMax();
if (mYMin > d.getYMin())
mYMin = d.getYMin();
if (d.getAxisDependency() == AxisDependency.LEFT) {
if (mLeftAxisMax < d.getYMax())
mLeftAxisMax = d.getYMax();
if (mLeftAxisMin > d.getYMin())
mLeftAxisMin = d.getYMin();
} else {
if (mRightAxisMax < d.getYMax())
mRightAxisMax = d.getYMax();
if (mRightAxisMin > d.getYMin())
mRightAxisMin = d.getYMin();
}
}
mDataSets.add(d);
handleEmptyAxis(getFirstLeft(), getFirstRight());
}
/**
* This adjusts the other axis if one axis is empty and the other is not.
*
* @param firstLeft
* @param firstRight
*/
private void handleEmptyAxis(T firstLeft, T firstRight) {
// in case there is only one axis, adjust the second axis
if (firstLeft == null) {
mLeftAxisMax = mRightAxisMax;
mLeftAxisMin = mRightAxisMin;
} else if (firstRight == null) {
mRightAxisMax = mLeftAxisMax;
mRightAxisMin = mLeftAxisMin;
}
}
/**
* Removes the given DataSet from this data object. Also recalculates all
* minimum and maximum values. Returns true if a DataSet was removed, false
* if no DataSet could be removed.
*
* @param d
*/
public boolean removeDataSet(T d) {
if (d == null)
return false;
boolean removed = mDataSets.remove(d);
// if a DataSet was removed
if (removed) {
mYValCount -= d.getEntryCount();
calcMinMax(0, mYValCount);
}
return removed;
}
/**
* Removes the DataSet at the given index in the DataSet array from the data
* object. Also recalculates all minimum and maximum values. Returns true if
* a DataSet was removed, false if no DataSet could be removed.
*
* @param index
*/
public boolean removeDataSet(int index) {
if (index >= mDataSets.size() || index < 0)
return false;
T set = mDataSets.get(index);
return removeDataSet(set);
}
/**
* Adds an Entry to the DataSet at the specified index.
* Entries are added to the end of the list.
*
* @param e
* @param dataSetIndex
*/
public void addEntry(Entry e, int dataSetIndex) {
if (mDataSets.size() > dataSetIndex && dataSetIndex >= 0) {
IDataSet set = mDataSets.get(dataSetIndex);
// add the entry to the dataset
if (!set.addEntry(e))
return;
float val = e.getVal();
if (mYValCount == 0) {
mYMin = val;
mYMax = val;
if (set.getAxisDependency() == AxisDependency.LEFT) {
mLeftAxisMax = e.getVal();
mLeftAxisMin = e.getVal();
} else {
mRightAxisMax = e.getVal();
mRightAxisMin = e.getVal();
}
} else {
if (mYMax < val)
mYMax = val;
if (mYMin > val)
mYMin = val;
if (set.getAxisDependency() == AxisDependency.LEFT) {
if (mLeftAxisMax < e.getVal())
mLeftAxisMax = e.getVal();
if (mLeftAxisMin > e.getVal())
mLeftAxisMin = e.getVal();
} else {
if (mRightAxisMax < e.getVal())
mRightAxisMax = e.getVal();
if (mRightAxisMin > e.getVal())
mRightAxisMin = e.getVal();
}
}
mYValCount += 1;
handleEmptyAxis(getFirstLeft(), getFirstRight());
} else {
Log.e("addEntry", "Cannot add Entry because dataSetIndex too high or too low.");
}
}
/**
* Removes the given Entry object from the DataSet at the specified index.
*
* @param e
* @param dataSetIndex
*/
public boolean removeEntry(Entry e, int dataSetIndex) {
// entry null, outofbounds
if (e == null || dataSetIndex >= mDataSets.size())
return false;
IDataSet set = mDataSets.get(dataSetIndex);
if (set != null) {
// remove the entry from the dataset
boolean removed = set.removeEntry(e);
if (removed) {
mYValCount -= 1;
calcMinMax(0, mYValCount);
}
return removed;
} else
return false;
}
/**
* Removes the Entry object at the given xIndex from the DataSet at the
* specified index. Returns true if an Entry was removed, false if no Entry
* was found that meets the specified requirements.
*
* @param xIndex
* @param dataSetIndex
* @return
*/
public boolean removeEntry(int xIndex, int dataSetIndex) {
if (dataSetIndex >= mDataSets.size())
return false;
IDataSet dataSet = mDataSets.get(dataSetIndex);
Entry e = dataSet.getEntryForXIndex(xIndex);
if (e == null || e.getXIndex() != xIndex)
return false;
return removeEntry(e, dataSetIndex);
}
/**
* Returns the DataSet that contains the provided Entry, or null, if no
* DataSet contains this Entry.
*
* @param e
* @return
*/
public T getDataSetForEntry(Entry e) {
if (e == null)
return null;
for (int i = 0; i < mDataSets.size(); i++) {
T set = mDataSets.get(i);
for (int j = 0; j < set.getEntryCount(); j++) {
if (e.equalTo(set.getEntryForXIndex(e.getXIndex())))
return set;
}
}
return null;
}
/**
* Returns all colors used across all DataSet objects this object
* represents.
*
* @return
*/
public int[] getColors() {
if (mDataSets == null)
return new int[0];
int clrcnt = 0;
for (int i = 0; i < mDataSets.size(); i++) {
clrcnt += mDataSets.get(i).getColors().size();
}
int[] colors = new int[clrcnt];
int cnt = 0;
for (int i = 0; i < mDataSets.size(); i++) {
List<Integer> clrs = mDataSets.get(i).getColors();
for (Integer clr : clrs) {
colors[cnt] = clr;
cnt++;
}
}
return colors;
}
public int getIndexOfDataSet(T dataSet) {
for (int i = 0; i < mDataSets.size(); i++) {
if (mDataSets.get(i) == dataSet)
return i;
}
return -1;
}
/**
* Returns the first DataSet from the datasets-array that has it's dependency on the left axis.
* Returns null if no DataSet with left dependency could be found.
*
* @return
*/
public T getFirstLeft() {
for (T dataSet : mDataSets) {
if (dataSet.getAxisDependency() == AxisDependency.LEFT)
return dataSet;
}
return null;
}
/**
* Returns the first DataSet from the datasets-array that has it's dependency on the right axis.
* Returns null if no DataSet with right dependency could be found.
*
* @return
*/
public T getFirstRight() {
for (T dataSet : mDataSets) {
if (dataSet.getAxisDependency() == AxisDependency.RIGHT)
return dataSet;
}
return null;
}
/**
* Generates an x-values array filled with numbers in range specified by the
* parameters. Can be used for convenience.
*
* @return
*/
public static List<String> generateXVals(int from, int to) {
List<String> xvals = new ArrayList<>();
for (int i = from; i < to; i++) {
xvals.add(Integer.toString(i));
}
return xvals;
}
/**
* Sets a custom ValueFormatter for all DataSets this data object contains.
*
* @param f
*/
public void setValueFormatter(ValueFormatter f) {
if (f == null)
return;
else {
for (IDataSet set : mDataSets) {
set.setValueFormatter(f);
}
}
}
/**
* Sets the color of the value-text (color in which the value-labels are
* drawn) for all DataSets this data object contains.
*
* @param color
*/
public void setValueTextColor(int color) {
for (IDataSet set : mDataSets) {
set.setValueTextColor(color);
}
}
/**
* Sets the same list of value-colors for all DataSets this
* data object contains.
*
* @param colors
*/
public void setValueTextColors(List<Integer> colors) {
for (IDataSet set : mDataSets) {
set.setValueTextColors(colors);
}
}
/**
* Sets the Typeface for all value-labels for all DataSets this data object
* contains.
*
* @param tf
*/
public void setValueTypeface(Typeface tf) {
for (IDataSet set : mDataSets) {
set.setValueTypeface(tf);
}
}
/**
* Sets the size (in dp) of the value-text for all DataSets this data object
* contains.
*
* @param size
*/
public void setValueTextSize(float size) {
for (IDataSet set : mDataSets) {
set.setValueTextSize(size);
}
}
/**
* Enables / disables drawing values (value-text) for all DataSets this data
* object contains.
*
* @param enabled
*/
public void setDrawValues(boolean enabled) {
for (IDataSet set : mDataSets) {
set.setDrawValues(enabled);
}
}
/**
* Enables / disables highlighting values for all DataSets this data object
* contains. If set to true, this means that values can
* be highlighted programmatically or by touch gesture.
*/
public void setHighlightEnabled(boolean enabled) {
for (IDataSet set : mDataSets) {
set.setHighlightEnabled(enabled);
}
}
/**
* Returns true if highlighting of all underlying values is enabled, false
* if not.
*
* @return
*/
public boolean isHighlightEnabled() {
for (IDataSet set : mDataSets) {
if (!set.isHighlightEnabled())
return false;
}
return true;
}
/**
* Clears this data object from all DataSets and removes all Entries. Don't
* forget to invalidate the chart after this.
*/
public void clearValues() {
mDataSets.clear();
notifyDataChanged();
}
// /**
// * Checks if this data object contains the specified Entry. Returns true if
// * so, false if not. NOTE: Performance is pretty bad on this one, do not
// * over-use in performance critical situations.
// *
// * @param e
// * @return
// */
// public boolean contains(Entry e) {
//
// for (T set : mDataSets) {
// if (set.contains(e))
// return true;
// }
//
// return false;
// }
/**
* Checks if this data object contains the specified DataSet. Returns true
* if so, false if not.
*
* @param dataSet
* @return
*/
public boolean contains(T dataSet) {
for (T set : mDataSets) {
if (set.equals(dataSet))
return true;
}
return false;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/ChartData.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 5,912 |
```java
package com.github.mikephil.charting.data;
import android.graphics.DashPathEffect;
import com.github.mikephil.charting.interfaces.datasets.ILineScatterCandleRadarDataSet;
import com.github.mikephil.charting.utils.Utils;
import java.util.List;
/**
* Created by Philipp Jahoda on 11/07/15.
*/
public abstract class LineScatterCandleRadarDataSet<T extends Entry> extends BarLineScatterCandleBubbleDataSet<T> implements ILineScatterCandleRadarDataSet<T> {
protected boolean mDrawVerticalHighlightIndicator = true;
protected boolean mDrawHorizontalHighlightIndicator = true;
/** the width of the highlight indicator lines */
protected float mHighlightLineWidth = 0.5f;
/** the path effect for dashed highlight-lines */
protected DashPathEffect mHighlightDashPathEffect = null;
public LineScatterCandleRadarDataSet(List<T> yVals, String label) {
super(yVals, label);
mHighlightLineWidth = Utils.convertDpToPixel(0.5f);
}
/**
* Enables / disables the horizontal highlight-indicator. If disabled, the indicator is not drawn.
* @param enabled
*/
public void setDrawHorizontalHighlightIndicator(boolean enabled) {
this.mDrawHorizontalHighlightIndicator = enabled;
}
/**
* Enables / disables the vertical highlight-indicator. If disabled, the indicator is not drawn.
* @param enabled
*/
public void setDrawVerticalHighlightIndicator(boolean enabled) {
this.mDrawVerticalHighlightIndicator = enabled;
}
/**
* Enables / disables both vertical and horizontal highlight-indicators.
* @param enabled
*/
public void setDrawHighlightIndicators(boolean enabled) {
setDrawVerticalHighlightIndicator(enabled);
setDrawHorizontalHighlightIndicator(enabled);
}
@Override
public boolean isVerticalHighlightIndicatorEnabled() {
return mDrawVerticalHighlightIndicator;
}
@Override
public boolean isHorizontalHighlightIndicatorEnabled() {
return mDrawHorizontalHighlightIndicator;
}
/**
* Sets the width of the highlight line in dp.
* @param width
*/
public void setHighlightLineWidth(float width) {
mHighlightLineWidth = Utils.convertDpToPixel(width);
}
@Override
public float getHighlightLineWidth() {
return mHighlightLineWidth;
}
/**
* Enables the highlight-line to be drawn in dashed mode, e.g. like this "- - - - - -"
*
* @param lineLength the length of the line pieces
* @param spaceLength the length of space inbetween the line-pieces
* @param phase offset, in degrees (normally, use 0)
*/
public void enableDashedHighlightLine(float lineLength, float spaceLength, float phase) {
mHighlightDashPathEffect = new DashPathEffect(new float[] {
lineLength, spaceLength
}, phase);
}
/**
* Disables the highlight-line to be drawn in dashed mode.
*/
public void disableDashedHighlightLine() {
mHighlightDashPathEffect = null;
}
/**
* Returns true if the dashed-line effect is enabled for highlight lines, false if not.
* Default: disabled
*
* @return
*/
public boolean isDashedHighlightLineEnabled() {
return mHighlightDashPathEffect == null ? false : true;
}
@Override
public DashPathEffect getDashPathEffectHighlight() {
return mHighlightDashPathEffect;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/LineScatterCandleRadarDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 755 |
```java
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.charts.ScatterChart.ScatterShape;
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import java.util.ArrayList;
import java.util.List;
public class ScatterDataSet extends LineScatterCandleRadarDataSet<Entry> implements IScatterDataSet {
/**
* the size the scattershape will have, in density pixels
*/
private float mShapeSize = 15f;
/**
* the type of shape that is set to be drawn where the values are at,
* default ScatterShape.SQUARE
*/
private ScatterShape mScatterShape = ScatterShape.SQUARE;
/**
* The radius of the hole in the shape (applies to Square, Circle and Triangle)
* - default: 0.0
*/
private float mScatterShapeHoleRadius = 0f;
/**
* Color for the hole in the shape.
* Setting to `ColorTemplate.COLOR_NONE` will behave as transparent.
* - default: ColorTemplate.COLOR_NONE
*/
private int mScatterShapeHoleColor = ColorTemplate.COLOR_NONE;
/**
* Custom path object the user can provide that is drawn where the values
* are at. This is used when ScatterShape.CUSTOM is set for a DataSet.
*/
//private Path mCustomScatterPath = null;
public ScatterDataSet(List<Entry> yVals, String label) {
super(yVals, label);
}
@Override
public DataSet<Entry> copy() {
List<Entry> yVals = new ArrayList<>();
for (int i = 0; i < mYVals.size(); i++) {
yVals.add(mYVals.get(i).copy());
}
ScatterDataSet copied = new ScatterDataSet(yVals, getLabel());
copied.mColors = mColors;
copied.mShapeSize = mShapeSize;
copied.mScatterShape = mScatterShape;
copied.mScatterShapeHoleRadius = mScatterShapeHoleRadius;
copied.mScatterShapeHoleColor = mScatterShapeHoleColor;
//copied.mCustomScatterPath = mCustomScatterPath;
copied.mHighLightColor = mHighLightColor;
return copied;
}
/**
* Sets the size in density pixels the drawn scattershape will have. This
* only applies for non custom shapes.
*
* @param size
*/
public void setScatterShapeSize(float size) {
mShapeSize = size;
}
@Override
public float getScatterShapeSize() {
return mShapeSize;
}
/**
* Sets the shape that is drawn on the position where the values are at.
*
* @param shape
*/
public void setScatterShape(ScatterShape shape) {
mScatterShape = shape;
}
@Override
public ScatterShape getScatterShape() {
return mScatterShape;
}
/**
* Sets the radius of the hole in the shape (applies to Square, Circle and Triangle)
* Set this to <= 0 to remove holes.
*
* @param holeRadius
*/
public void setScatterShapeHoleRadius(float holeRadius) {
mScatterShapeHoleRadius = holeRadius;
}
@Override
public float getScatterShapeHoleRadius() {
return mScatterShapeHoleRadius;
}
/**
* Sets the color for the hole in the shape.
*
* @param holeColor
*/
public void setScatterShapeHoleColor(int holeColor) {
mScatterShapeHoleColor = holeColor;
}
@Override
public int getScatterShapeHoleColor() {
return mScatterShapeHoleColor;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/ScatterDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 852 |
```java
package com.github.mikephil.charting.data;
/**
* Entry class for the BarChart. (especially stacked bars)
*
* @author Philipp Jahoda
*/
public class BarEntry extends Entry {
/** the values the stacked barchart holds */
private float[] mVals;
/** the sum of all negative values this entry (if stacked) contains */
private float mNegativeSum;
/** the sum of all positive values this entry (if stacked) contains */
private float mPositiveSum;
/**
* Constructor for stacked bar entries.
*
* @param vals
* - the stack values, use at lest 2
* @param xIndex
*/
public BarEntry(float[] vals, int xIndex) {
super(calcSum(vals), xIndex);
this.mVals = vals;
calcPosNegSum();
}
/**
* Constructor for normal bars (not stacked).
*
* @param val
* @param xIndex
*/
public BarEntry(float val, int xIndex) {
super(val, xIndex);
}
/**
* Constructor for stacked bar entries.
*
* @param vals
* - the stack values, use at least 2
* @param xIndex
* @param label
* Additional description label.
*/
public BarEntry(float[] vals, int xIndex, String label) {
super(calcSum(vals), xIndex, label);
this.mVals = vals;
calcPosNegSum();
}
/**
* Constructor for normal bars (not stacked).
*
* @param val
* @param xIndex
* @param data
* Spot for additional data this Entry represents.
*/
public BarEntry(float val, int xIndex, Object data) {
super(val, xIndex, data);
}
/**
* Returns an exact copy of the BarEntry.
*/
public BarEntry copy() {
BarEntry copied = new BarEntry(getVal(), getXIndex(), getData());
copied.setVals(mVals);
return copied;
}
/**
* Returns the stacked values this BarEntry represents, or null, if only a single value is represented (then, use
* getVal()).
*
* @return
*/
public float[] getVals() {
return mVals;
}
/**
* Set the array of values this BarEntry should represent.
*
* @param vals
*/
public void setVals(float[] vals) {
setVal(calcSum(vals));
mVals = vals;
calcPosNegSum();
}
/**
* Returns the value of this BarEntry. If the entry is stacked, it returns the positive sum of all values.
*
* @return
*/
@Override
public float getVal() {
return super.getVal();
}
/**
* Returns true if this BarEntry is stacked (has a values array), false if not.
*
* @return
*/
public boolean isStacked() {
return mVals != null;
}
public float getBelowSum(int stackIndex) {
if (mVals == null)
return 0;
float remainder = 0f;
int index = mVals.length - 1;
while (index > stackIndex && index >= 0) {
remainder += mVals[index];
index--;
}
return remainder;
}
/**
* Reuturns the sum of all positive values this entry (if stacked) contains.
*
* @return
*/
public float getPositiveSum() {
return mPositiveSum;
}
/**
* Returns the sum of all negative values this entry (if stacked) contains. (this is a positive number)
*
* @return
*/
public float getNegativeSum() {
return mNegativeSum;
}
private void calcPosNegSum() {
if (mVals == null) {
mNegativeSum = 0;
mPositiveSum = 0;
return;
}
float sumNeg = 0f;
float sumPos = 0f;
for (float f : mVals) {
if (f <= 0f)
sumNeg += Math.abs(f);
else
sumPos += f;
}
mNegativeSum = sumNeg;
mPositiveSum = sumPos;
}
/**
* Calculates the sum across all values of the given stack.
*
* @param vals
* @return
*/
private static float calcSum(float[] vals) {
if (vals == null)
return 0f;
float sum = 0f;
for (float f : vals)
sum += f;
return sum;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/BarEntry.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 1,040 |
```java
package com.github.mikephil.charting.data;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.formatter.DefaultValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Philipp Jahoda on 21/10/15.
* This is the base dataset of all DataSets. It's purpose is to implement critical methods
* provided by the IDataSet interface.
*/
public abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
/**
* List representing all colors that are used for this DataSet
*/
protected List<Integer> mColors = null;
/**
* List representing all colors that are used for drawing the actual values for this DataSet
*/
protected List<Integer> mValueColors = null;
/**
* label that describes the DataSet or the data the DataSet represents
*/
private String mLabel = "DataSet";
/**
* this specifies which axis this DataSet should be plotted against
*/
protected YAxis.AxisDependency mAxisDependency = YAxis.AxisDependency.LEFT;
/**
* if true, value highlightning is enabled
*/
protected boolean mHighlightEnabled = true;
/**
* custom formatter that is used instead of the auto-formatter if set
*/
protected transient ValueFormatter mValueFormatter;
/**
* the typeface used for the value text
*/
protected Typeface mValueTypeface;
/**
* if true, y-values are drawn on the chart
*/
protected boolean mDrawValues = true;
/**
* the size of the value-text labels
*/
protected float mValueTextSize = 17f;
/**
* flag that indicates if the DataSet is visible or not
*/
protected boolean mVisible = true;
/**
* Default constructor.
*/
public BaseDataSet() {
mColors = new ArrayList<>();
mValueColors = new ArrayList<>();
// default color
mColors.add(Color.rgb(140, 234, 255));
mValueColors.add(Color.BLACK);
}
/**
* Constructor with label.
*
* @param label
*/
public BaseDataSet(String label) {
this();
this.mLabel = label;
}
/**
* Use this method to tell the data set that the underlying data has changed.
*/
public void notifyDataSetChanged() {
calcMinMax(0, getEntryCount() - 1);
}
/**
* ###### ###### COLOR GETTING RELATED METHODS ##### ######
*/
@Override
public List<Integer> getColors() {
return mColors;
}
public List<Integer> getValueColors() { return mValueColors; }
@Override
public int getColor() {
return mColors.get(0);
}
@Override
public int getColor(int index) {
return mColors.get(index % mColors.size());
}
/**
* ###### ###### COLOR SETTING RELATED METHODS ##### ######
*/
/**
* Sets the colors that should be used fore this DataSet. Colors are reused
* as soon as the number of Entries the DataSet represents is higher than
* the size of the colors array. If you are using colors from the resources,
* make sure that the colors are already prepared (by calling
* getResources().getColor(...)) before adding them to the DataSet.
*
* @param colors
*/
public void setColors(List<Integer> colors) {
this.mColors = colors;
}
/**
* Sets the colors that should be used fore this DataSet. Colors are reused
* as soon as the number of Entries the DataSet represents is higher than
* the size of the colors array. If you are using colors from the resources,
* make sure that the colors are already prepared (by calling
* getResources().getColor(...)) before adding them to the DataSet.
*
* @param colors
*/
public void setColors(int[] colors) {
this.mColors = ColorTemplate.createColors(colors);
}
/**
* Sets the colors that should be used fore this DataSet. Colors are reused
* as soon as the number of Entries the DataSet represents is higher than
* the size of the colors array. You can use
* "new int[] { R.color.red, R.color.green, ... }" to provide colors for
* this method. Internally, the colors are resolved using
* getResources().getColor(...)
*
* @param colors
*/
public void setColors(int[] colors, Context c) {
List<Integer> clrs = new ArrayList<>();
for (int color : colors) {
clrs.add(c.getResources().getColor(color));
}
mColors = clrs;
}
/**
* Adds a new color to the colors array of the DataSet.
*
* @param color
*/
public void addColor(int color) {
if (mColors == null)
mColors = new ArrayList<>();
mColors.add(color);
}
/**
* Sets the one and ONLY color that should be used for this DataSet.
* Internally, this recreates the colors array and adds the specified color.
*
* @param color
*/
public void setColor(int color) {
resetColors();
mColors.add(color);
}
/**
* Sets a color with a specific alpha value.
*
* @param color
* @param alpha from 0-255
*/
public void setColor(int color, int alpha) {
setColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)));
}
/**
* Sets colors with a specific alpha value.
*
* @param colors
* @param alpha
*/
public void setColors(int[] colors, int alpha) {
resetColors();
for (int color : colors) {
addColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)));
}
}
/**
* Resets all colors of this DataSet and recreates the colors array.
*/
public void resetColors() {
mColors = new ArrayList<>();
}
/** ###### ###### OTHER STYLING RELATED METHODS ##### ###### */
@Override
public void setLabel(String label) {
mLabel = label;
}
@Override
public String getLabel() {
return mLabel;
}
@Override
public void setHighlightEnabled(boolean enabled) {
mHighlightEnabled = enabled;
}
@Override
public boolean isHighlightEnabled() {
return mHighlightEnabled;
}
@Override
public void setValueFormatter(ValueFormatter f) {
if (f == null)
return;
else
mValueFormatter = f;
}
@Override
public ValueFormatter getValueFormatter() {
if (mValueFormatter == null)
return new DefaultValueFormatter(1);
return mValueFormatter;
}
@Override
public void setValueTextColor(int color) {
mValueColors.clear();
mValueColors.add(color);
}
@Override
public void setValueTextColors(List<Integer> colors) {
mValueColors = colors;
}
@Override
public void setValueTypeface(Typeface tf) {
mValueTypeface = tf;
}
@Override
public void setValueTextSize(float size) {
mValueTextSize = Utils.convertDpToPixel(size);
}
@Override
public int getValueTextColor() {
return mValueColors.get(0);
}
@Override
public int getValueTextColor(int index) {
return mValueColors.get(index % mValueColors.size());
}
@Override
public Typeface getValueTypeface() {
return mValueTypeface;
}
@Override
public float getValueTextSize() {
return mValueTextSize;
}
@Override
public void setDrawValues(boolean enabled) {
this.mDrawValues = enabled;
}
@Override
public boolean isDrawValuesEnabled() {
return mDrawValues;
}
@Override
public void setVisible(boolean visible) {
mVisible = visible;
}
@Override
public boolean isVisible() {
return mVisible;
}
@Override
public YAxis.AxisDependency getAxisDependency() {
return mAxisDependency;
}
@Override
public void setAxisDependency(YAxis.AxisDependency dependency) {
mAxisDependency = dependency;
}
/** ###### ###### DATA RELATED METHODS ###### ###### */
@Override
public int getIndexInEntries(int xIndex) {
for (int i = 0; i < getEntryCount(); i++) {
if (xIndex == getEntryForIndex(i).getXIndex())
return i;
}
return -1;
}
@Override
public boolean removeFirst() {
T entry = getEntryForIndex(0);
return removeEntry(entry);
}
@Override
public boolean removeLast() {
T entry = getEntryForIndex(getEntryCount() - 1);
return removeEntry(entry);
}
@Override
public boolean removeEntry(int xIndex) {
T e = getEntryForXIndex(xIndex);
return removeEntry(e);
}
@Override
public boolean contains(T e) {
for(int i = 0; i < getEntryCount(); i++) {
if(getEntryForIndex(i).equals(e))
return true;
}
return false;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/BaseDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 2,109 |
```java
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
import java.util.ArrayList;
import java.util.List;
public class CandleData extends BarLineScatterCandleBubbleData<ICandleDataSet> {
public CandleData() {
super();
}
public CandleData(List<String> xVals) {
super(xVals);
}
public CandleData(String[] xVals) {
super(xVals);
}
public CandleData(List<String> xVals, List<ICandleDataSet> dataSets) {
super(xVals, dataSets);
}
public CandleData(String[] xVals, List<ICandleDataSet> dataSets) {
super(xVals, dataSets);
}
public CandleData(List<String> xVals, ICandleDataSet dataSet) {
super(xVals, toList(dataSet));
}
public CandleData(String[] xVals, ICandleDataSet dataSet) {
super(xVals, toList(dataSet));
}
private static List<ICandleDataSet> toList(ICandleDataSet dataSet) {
List<ICandleDataSet> sets = new ArrayList<>();
sets.add(dataSet);
return sets;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/CandleData.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 263 |
```java
package com.github.mikephil.charting.data;
/**
* Subclass of Entry that holds a value for one entry in a BubbleChart. Bubble
*
* @author Philipp Jahoda
*/
public class BubbleEntry extends Entry {
/** size value */
private float mSize = 0f;
/**
* Constructor.
*
* @param xIndex The index on the x-axis.
* @param val The value on the y-axis.
* @param size The size of the bubble.
*/
public BubbleEntry(int xIndex, float val, float size) {
super(val, xIndex);
this.mSize = size;
}
/**
* Constructor.
*
* @param xIndex The index on the x-axis.
* @param val The value on the y-axis.
* @param size The size of the bubble.
* @param data Spot for additional data this Entry represents.
*/
public BubbleEntry(int xIndex, float val, float size, Object data) {
super(val, xIndex, data);
this.mSize = size;
}
public BubbleEntry copy() {
return new BubbleEntry(getXIndex(), getVal(), mSize, getData());
}
/**
* Returns the size of this entry (the size of the bubble).
*
* @return
*/
public float getSize() {
return mSize;
}
public void setSize(float size) {
this.mSize = size;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/BubbleEntry.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 318 |
```java
package com.github.mikephil.charting.data.filter;
import com.github.mikephil.charting.data.Entry;
import java.util.ArrayList;
import java.util.List;
/**
* Implemented according to Wiki-Pseudocode {@link}
* path_to_urlDouglasPeucker_algorithm
*
* @author Philipp Baldauf & Phliipp Jahoda
*/
public class Approximator {
/** the type of filtering algorithm to use */
private ApproximatorType mType = ApproximatorType.DOUGLAS_PEUCKER;
/** the tolerance to be filtered with */
private double mTolerance = 0;
private float mScaleRatio = 1f;
private float mDeltaRatio = 1f;
/**
* array that contains "true" on all indices that will be kept after
* filtering
*/
private boolean[] keep;
/** enums for the different types of filtering algorithms */
public enum ApproximatorType {
NONE, DOUGLAS_PEUCKER
}
/**
* Initializes the approximator with type NONE
*/
public Approximator() {
this.mType = ApproximatorType.NONE;
}
/**
* Initializes the approximator with the given type and tolerance. If
* toleranec <= 0, no filtering will be done.
*
* @param type
*/
public Approximator(ApproximatorType type, double tolerance) {
setup(type, tolerance);
}
/**
* sets type and tolerance, if tolerance <= 0, no filtering will be done
*
* @param type
* @param tolerance
*/
public void setup(ApproximatorType type, double tolerance) {
mType = type;
mTolerance = tolerance;
}
/**
* sets the tolerance for the Approximator. When using the
* Douglas-Peucker-Algorithm, the tolerance is an angle in degrees, that
* will trigger the filtering.
*/
public void setTolerance(double tolerance) {
mTolerance = tolerance;
}
/**
* Sets the filtering algorithm that should be used.
*
* @param type
*/
public void setType(ApproximatorType type) {
this.mType = type;
}
/**
* Sets the ratios for x- and y-axis, as well as the ratio of the scale
* levels
*
* @param deltaRatio
* @param scaleRatio
*/
public void setRatios(float deltaRatio, float scaleRatio) {
mDeltaRatio = deltaRatio;
mScaleRatio = scaleRatio;
}
/**
* Filters according to type. Uses the pre set set tolerance
*
* @param points the points to filter
* @return
*/
public List<Entry> filter(List<Entry> points) {
return filter(points, mTolerance);
}
/**
* Filters according to type.
*
* @param points the points to filter
* @param tolerance the angle in degrees that will trigger the filtering
* @return
*/
public List<Entry> filter(List<Entry> points, double tolerance) {
if (tolerance <= 0)
return points;
keep = new boolean[points.size()];
switch (mType) {
case DOUGLAS_PEUCKER:
return reduceWithDouglasPeuker(points, tolerance);
case NONE:
return points;
default:
return points;
}
}
/**
* uses the douglas peuker algorithm to reduce the given List of
* entries
*
* @param entries
* @param epsilon
* @return
*/
private List<Entry> reduceWithDouglasPeuker(List<Entry> entries, double epsilon) {
// if a shape has 2 or less points it cannot be reduced
if (epsilon <= 0 || entries.size() < 3) {
return entries;
}
// first and last always stay
keep[0] = true;
keep[entries.size() - 1] = true;
// first and last entry are entry point to recursion
algorithmDouglasPeucker(entries, epsilon, 0, entries.size() - 1);
// create a new array with series, only take the kept ones
List<Entry> reducedEntries = new ArrayList<>();
for (int i = 0; i < entries.size(); i++) {
if (keep[i]) {
Entry curEntry = entries.get(i);
reducedEntries.add(new Entry(curEntry.getVal(), curEntry.getXIndex()));
}
}
return reducedEntries;
}
/**
* apply the Douglas-Peucker-Reduction to an List of Entry with a given
* epsilon (tolerance)
*
* @param entries
* @param epsilon as y-value
* @param start
* @param end
*/
private void algorithmDouglasPeucker(List<Entry> entries, double epsilon, int start,
int end) {
if (end <= start + 1) {
// recursion finished
return;
}
// find the greatest distance between start and endpoint
int maxDistIndex = 0;
double distMax = 0;
Entry firstEntry = entries.get(start);
Entry lastEntry = entries.get(end);
for (int i = start + 1; i < end; i++) {
double dist = calcAngleBetweenLines(firstEntry, lastEntry, firstEntry, entries.get(i));
// keep the point with the greatest distance
if (dist > distMax) {
distMax = dist;
maxDistIndex = i;
}
}
// Log.i("maxangle", "" + distMax);
if (distMax > epsilon) {
// keep max dist point
keep[maxDistIndex] = true;
// recursive call
algorithmDouglasPeucker(entries, epsilon, start, maxDistIndex);
algorithmDouglasPeucker(entries, epsilon, maxDistIndex, end);
} // else don't keep the point...
}
/**
* calculate the distance between a line between two entries and an entry
* (point)
*
* @param startEntry line startpoint
* @param endEntry line endpoint
* @param entryPoint the point to which the distance is measured from the
* line
* @return
*/
public double calcPointToLineDistance(Entry startEntry, Entry endEntry, Entry entryPoint) {
float xDiffEndStart = (float) endEntry.getXIndex() - (float) startEntry.getXIndex();
float xDiffEntryStart = (float) entryPoint.getXIndex() - (float) startEntry.getXIndex();
double normalLength = Math.sqrt((xDiffEndStart)
* (xDiffEndStart)
+ (endEntry.getVal() - startEntry.getVal())
* (endEntry.getVal() - startEntry.getVal()));
return Math.abs((xDiffEntryStart)
* (endEntry.getVal() - startEntry.getVal())
- (entryPoint.getVal() - startEntry.getVal())
* (xDiffEndStart))
/ normalLength;
}
/**
* Calculates the angle between two given lines. The provided Entry objects
* mark the starting and end points of the lines.
*
* @param start1
* @param end1
* @param start2
* @param end2
* @return
*/
public double calcAngleBetweenLines(Entry start1, Entry end1, Entry start2, Entry end2) {
double angle1 = calcAngleWithRatios(start1, end1);
double angle2 = calcAngleWithRatios(start2, end2);
return Math.abs(angle1 - angle2);
}
/**
* calculates the angle between two Entries (points) in the chart taking
* ratios into consideration
*
* @param p1
* @param p2
* @return
*/
public double calcAngleWithRatios(Entry p1, Entry p2) {
float dx = p2.getXIndex() * mDeltaRatio - p1.getXIndex() * mDeltaRatio;
float dy = p2.getVal() * mScaleRatio - p1.getVal() * mScaleRatio;
return Math.atan2(dy, dx) * 180.0 / Math.PI;
}
/**
* calculates the angle between two Entries (points) in the chart
*
* @param p1
* @param p2
* @return
*/
public double calcAngle(Entry p1, Entry p2) {
float dx = p2.getXIndex() - p1.getXIndex();
float dy = p2.getVal() - p1.getVal();
return Math.atan2(dy, dx) * 180.0 / Math.PI;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/filter/Approximator.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 1,939 |
```java
package com.github.mikephil.charting.data.realm.implementation;
import android.graphics.Paint;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.realm.base.RealmLineScatterCandleRadarDataSet;
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Utils;
import io.realm.DynamicRealmObject;
import io.realm.RealmObject;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 07/11/15.
*/
public class RealmCandleDataSet<T extends RealmObject> extends RealmLineScatterCandleRadarDataSet<T, CandleEntry> implements ICandleDataSet {
private String mHighField;
private String mLowField;
private String mOpenField;
private String mCloseField;
/**
* the width of the shadow of the candle
*/
private float mShadowWidth = 3f;
/**
* should the candle bars show?
* when false, only "ticks" will show
*
* - default: true
*/
private boolean mShowCandleBar = true;
/**
* the space between the candle entries, default 0.1f (10%)
*/
private float mBarSpace = 0.1f;
/**
* use candle color for the shadow
*/
private boolean mShadowColorSameAsCandle = false;
/**
* paint style when open < close
* increasing candlesticks are traditionally hollow
*/
protected Paint.Style mIncreasingPaintStyle = Paint.Style.STROKE;
/**
* paint style when open > close
* descreasing candlesticks are traditionally filled
*/
protected Paint.Style mDecreasingPaintStyle = Paint.Style.FILL;
/**
* color for open == close
*/
protected int mNeutralColor = ColorTemplate.COLOR_NONE;
/**
* color for open < close
*/
protected int mIncreasingColor = ColorTemplate.COLOR_NONE;
/**
* color for open > close
*/
protected int mDecreasingColor = ColorTemplate.COLOR_NONE;
/**
* shadow line color, set -1 for backward compatibility and uses default
* color
*/
protected int mShadowColor = ColorTemplate.COLOR_NONE;
/**
* Constructor for creating a LineDataSet with realm data.
*
* @param result the queried results from the realm database
* @param highField the name of the field in your data object that represents the "high" value
* @param lowField the name of the field in your data object that represents the "low" value
* @param openField the name of the field in your data object that represents the "open" value
* @param closeField the name of the field in your data object that represents the "close" value
*/
public RealmCandleDataSet(RealmResults<T> result, String highField, String lowField, String openField, String closeField) {
super(result, null);
this.mHighField = highField;
this.mLowField = lowField;
this.mOpenField = openField;
this.mCloseField = closeField;
build(this.results);
calcMinMax(0, this.results.size());
}
/**
* Constructor for creating a LineDataSet with realm data.
*
* @param result the queried results from the realm database
* @param highField the name of the field in your data object that represents the "high" value
* @param lowField the name of the field in your data object that represents the "low" value
* @param openField the name of the field in your data object that represents the "open" value
* @param closeField the name of the field in your data object that represents the "close" value
* @param xIndexField the name of the field in your data object that represents the x-index
*/
public RealmCandleDataSet(RealmResults<T> result, String highField, String lowField, String openField, String closeField, String xIndexField) {
super(result, null, xIndexField);
this.mHighField = highField;
this.mLowField = lowField;
this.mOpenField = openField;
this.mCloseField = closeField;
build(this.results);
calcMinMax(0, this.results.size());
}
public CandleEntry buildEntryFromResultObject(T realmObject, int xIndex) {
DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);
return new CandleEntry(
mIndexField == null ? xIndex : dynamicObject.getInt(mIndexField),
dynamicObject.getFloat(mHighField),
dynamicObject.getFloat(mLowField),
dynamicObject.getFloat(mOpenField),
dynamicObject.getFloat(mCloseField));
}
@Override
public void calcMinMax(int start, int end) {
if (mValues == null)
return;
if (mValues.isEmpty())
return;
int endValue;
if (end == 0 || end >= mValues.size())
endValue = mValues.size() - 1;
else
endValue = end;
mYMin = Float.MAX_VALUE;
mYMax = -Float.MAX_VALUE;
for (int i = start; i <= endValue; i++) {
CandleEntry e = mValues.get(i);
if (e.getLow() < mYMin)
mYMin = e.getLow();
if (e.getHigh() > mYMax)
mYMax = e.getHigh();
}
}
/**
* Sets the space that is left out on the left and right side of each
* candle, default 0.1f (10%), max 0.45f, min 0f
*
* @param space
*/
public void setBarSpace(float space) {
if (space < 0f)
space = 0f;
if (space > 0.45f)
space = 0.45f;
mBarSpace = space;
}
@Override
public float getBarSpace() {
return mBarSpace;
}
/**
* Sets the width of the candle-shadow-line in pixels. Default 3f.
*
* @param width
*/
public void setShadowWidth(float width) {
mShadowWidth = Utils.convertDpToPixel(width);
}
@Override
public float getShadowWidth() {
return mShadowWidth;
}
/**
* Sets whether the candle bars should show?
*
* @param showCandleBar
*/
public void setShowCandleBar(boolean showCandleBar) {
mShowCandleBar = showCandleBar;
}
@Override
public boolean getShowCandleBar() {
return mShowCandleBar;
}
/** BELOW THIS COLOR HANDLING */
/**
* Sets the one and ONLY color that should be used for this DataSet when
* open == close.
*
* @param color
*/
public void setNeutralColor(int color) {
mNeutralColor = color;
}
@Override
public int getNeutralColor() {
return mNeutralColor;
}
/**
* Sets the one and ONLY color that should be used for this DataSet when
* open < close.
*
* @param color
*/
public void setIncreasingColor(int color) {
mIncreasingColor = color;
}
@Override
public int getIncreasingColor() {
return mIncreasingColor;
}
/**
* Sets the one and ONLY color that should be used for this DataSet when
* open > close.
*
* @param color
*/
public void setDecreasingColor(int color) {
mDecreasingColor = color;
}
@Override
public int getDecreasingColor() {
return mDecreasingColor;
}
@Override
public Paint.Style getIncreasingPaintStyle() {
return mIncreasingPaintStyle;
}
/**
* Sets paint style when open < close
*
* @param paintStyle
*/
public void setIncreasingPaintStyle(Paint.Style paintStyle) {
this.mIncreasingPaintStyle = paintStyle;
}
@Override
public Paint.Style getDecreasingPaintStyle() {
return mDecreasingPaintStyle;
}
/**
* Sets paint style when open > close
*
* @param decreasingPaintStyle
*/
public void setDecreasingPaintStyle(Paint.Style decreasingPaintStyle) {
this.mDecreasingPaintStyle = decreasingPaintStyle;
}
@Override
public int getShadowColor() {
return mShadowColor;
}
/**
* Sets shadow color for all entries
*
* @param shadowColor
*/
public void setShadowColor(int shadowColor) {
this.mShadowColor = shadowColor;
}
@Override
public boolean getShadowColorSameAsCandle() {
return mShadowColorSameAsCandle;
}
/**
* Sets shadow color to be the same color as the candle color
*
* @param shadowColorSameAsCandle
*/
public void setShadowColorSameAsCandle(boolean shadowColorSameAsCandle) {
this.mShadowColorSameAsCandle = shadowColorSameAsCandle;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmCandleDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 2,050 |
```java
package com.github.mikephil.charting.data.realm.implementation;
import com.github.mikephil.charting.data.RadarData;
import com.github.mikephil.charting.data.realm.base.RealmUtils;
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
import java.util.List;
import io.realm.RealmObject;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 19/12/15.
*/
public class RealmRadarData extends RadarData{
public RealmRadarData(RealmResults<? extends RealmObject> result, String xValuesField, List<IRadarDataSet> dataSets) {
super(RealmUtils.toXVals(result, xValuesField), dataSets);
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmRadarData.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 153 |
```java
package com.github.mikephil.charting.data.realm.implementation;
import android.graphics.Color;
import com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet;
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import io.realm.RealmObject;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 07/11/15.
*/
public class RealmRadarDataSet<T extends RealmObject> extends RealmLineRadarDataSet<T> implements IRadarDataSet {
/// flag indicating whether highlight circle should be drawn or not
protected boolean mDrawHighlightCircleEnabled = false;
protected int mHighlightCircleFillColor = Color.WHITE;
/// The stroke color for highlight circle.
/// If Utils.COLOR_NONE, the color of the dataset is taken.
protected int mHighlightCircleStrokeColor = ColorTemplate.COLOR_NONE;
protected int mHighlightCircleStrokeAlpha = (int)(0.3 * 255);
protected float mHighlightCircleInnerRadius = 3.0f;
protected float mHighlightCircleOuterRadius = 4.0f;
protected float mHighlightCircleStrokeWidth = 2.0f;
/**
* Constructor for creating a RadarDataSet with realm data.
*
* @param result the queried results from the realm database
* @param yValuesField the name of the field in your data object that represents the y-value
*/
public RealmRadarDataSet(RealmResults<T> result, String yValuesField) {
super(result, yValuesField);
build(this.results);
calcMinMax(0, results.size());
}
/**
* Constructor for creating a RadarDataSet with realm data.
*
* @param result the queried results from the realm database
* @param yValuesField the name of the field in your data object that represents the y-value
* @param xIndexField the name of the field in your data object that represents the x-index
*/
public RealmRadarDataSet(RealmResults<T> result, String yValuesField, String xIndexField) {
super(result, yValuesField, xIndexField);
build(this.results);
calcMinMax(0, results.size());
}
/// Returns true if highlight circle should be drawn, false if not
@Override
public boolean isDrawHighlightCircleEnabled()
{
return mDrawHighlightCircleEnabled;
}
/// Sets whether highlight circle should be drawn or not
@Override
public void setDrawHighlightCircleEnabled(boolean enabled)
{
mDrawHighlightCircleEnabled = enabled;
}
@Override
public int getHighlightCircleFillColor()
{
return mHighlightCircleFillColor;
}
public void setHighlightCircleFillColor(int color)
{
mHighlightCircleFillColor = color;
}
/// Returns the stroke color for highlight circle.
/// If Utils.COLOR_NONE, the color of the dataset is taken.
@Override
public int getHighlightCircleStrokeColor()
{
return mHighlightCircleStrokeColor;
}
/// Sets the stroke color for highlight circle.
/// Set to Utils.COLOR_NONE in order to use the color of the dataset;
public void setHighlightCircleStrokeColor(int color)
{
mHighlightCircleStrokeColor = color;
}
@Override
public int getHighlightCircleStrokeAlpha()
{
return mHighlightCircleStrokeAlpha;
}
public void setHighlightCircleStrokeAlpha(int alpha)
{
mHighlightCircleStrokeAlpha = alpha;
}
@Override
public float getHighlightCircleInnerRadius()
{
return mHighlightCircleInnerRadius;
}
public void setHighlightCircleInnerRadius(float radius)
{
mHighlightCircleInnerRadius = radius;
}
@Override
public float getHighlightCircleOuterRadius()
{
return mHighlightCircleOuterRadius;
}
public void setHighlightCircleOuterRadius(float radius)
{
mHighlightCircleOuterRadius = radius;
}
@Override
public float getHighlightCircleStrokeWidth()
{
return mHighlightCircleStrokeWidth;
}
public void setHighlightCircleStrokeWidth(float strokeWidth)
{
mHighlightCircleStrokeWidth = strokeWidth;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmRadarDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 904 |
```java
package com.github.mikephil.charting.data.realm.implementation;
import android.graphics.Color;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.realm.base.RealmBarLineScatterCandleBubbleDataSet;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import io.realm.DynamicRealmObject;
import io.realm.RealmFieldType;
import io.realm.RealmList;
import io.realm.RealmObject;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 07/11/15.
*/
public class RealmBarDataSet<T extends RealmObject> extends RealmBarLineScatterCandleBubbleDataSet<T, BarEntry> implements IBarDataSet {
private String mStackValueFieldName;
/**
* space indicator between the bars 0.1f == 10 %
*/
private float mBarSpace = 0.15f;
/**
* the maximum number of bars that are stacked upon each other, this value
* is calculated from the Entries that are added to the DataSet
*/
private int mStackSize = 1;
/**
* the color used for drawing the bar shadows
*/
private int mBarShadowColor = Color.rgb(215, 215, 215);
private float mBarBorderWidth = 0.0f;
private int mBarBorderColor = Color.BLACK;
/**
* the alpha value used to draw the highlight indicator bar
*/
private int mHighLightAlpha = 120;
/**
* array of labels used to describe the different values of the stacked bars
*/
private String[] mStackLabels = new String[]{
"Stack"
};
public RealmBarDataSet(RealmResults<T> results, String yValuesField, String xIndexField) {
super(results, yValuesField, xIndexField);
mHighLightColor = Color.rgb(0, 0, 0);
build(this.results);
calcMinMax(0, results.size());
}
/**
* Constructor for supporting stacked values.
*
* @param results
* @param yValuesField
* @param xIndexField
* @param stackValueFieldName
*/
public RealmBarDataSet(RealmResults<T> results, String yValuesField, String xIndexField, String stackValueFieldName) {
super(results, yValuesField, xIndexField);
this.mStackValueFieldName = stackValueFieldName;
mHighLightColor = Color.rgb(0, 0, 0);
build(this.results);
calcMinMax(0, results.size());
}
@Override
public void build(RealmResults<T> results) {
super.build(results);
calcStackSize();
}
@Override
public BarEntry buildEntryFromResultObject(T realmObject, int xIndex) {
DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);
if (dynamicObject.getFieldType(mValuesField) == RealmFieldType.LIST) {
RealmList<DynamicRealmObject> list = dynamicObject.getList(mValuesField);
float[] values = new float[list.size()];
int i = 0;
for (DynamicRealmObject o : list) {
values[i] = o.getFloat(mStackValueFieldName);
i++;
}
return new BarEntry(values,
mIndexField == null ? xIndex : dynamicObject.getInt(mIndexField));
} else {
float value = dynamicObject.getFloat(mValuesField);
return new BarEntry(value,
mIndexField == null ? xIndex : dynamicObject.getInt(mIndexField));
}
}
@Override
public void calcMinMax(int start, int end) {
if (mValues == null)
return;
final int yValCount = mValues.size();
if (yValCount == 0)
return;
int endValue;
if (end == 0 || end >= yValCount)
endValue = yValCount - 1;
else
endValue = end;
mYMin = Float.MAX_VALUE;
mYMax = -Float.MAX_VALUE;
for (int i = start; i <= endValue; i++) {
BarEntry e = mValues.get(i);
if (e != null && !Float.isNaN(e.getVal())) {
if (e.getVals() == null) {
if (e.getVal() < mYMin)
mYMin = e.getVal();
if (e.getVal() > mYMax)
mYMax = e.getVal();
} else {
if (-e.getNegativeSum() < mYMin)
mYMin = -e.getNegativeSum();
if (e.getPositiveSum() > mYMax)
mYMax = e.getPositiveSum();
}
}
}
if (mYMin == Float.MAX_VALUE) {
mYMin = 0.f;
mYMax = 0.f;
}
}
private void calcStackSize() {
for (int i = 0; i < mValues.size(); i++) {
float[] vals = mValues.get(i).getVals();
if (vals != null && vals.length > mStackSize)
mStackSize = vals.length;
}
}
@Override
public int getStackSize() {
return mStackSize;
}
@Override
public boolean isStacked() {
return mStackSize > 1 ? true : false;
}
/**
* returns the space between bars in percent of the whole width of one value
*
* @return
*/
public float getBarSpacePercent() {
return mBarSpace * 100f;
}
@Override
public float getBarSpace() {
return mBarSpace;
}
/**
* sets the space between the bars in percent (0-100) of the total bar width
*
* @param percent
*/
public void setBarSpacePercent(float percent) {
mBarSpace = percent / 100f;
}
/**
* Sets the color used for drawing the bar-shadows. The bar shadows is a
* surface behind the bar that indicates the maximum value. Don't for get to
* use getResources().getColor(...) to set this. Or Color.rgb(...).
*
* @param color
*/
public void setBarShadowColor(int color) {
mBarShadowColor = color;
}
@Override
public int getBarShadowColor() {
return mBarShadowColor;
}
/**
* Sets the width used for drawing borders around the bars.
* If borderWidth == 0, no border will be drawn.
*
* @return
*/
public void setBarBorderWidth(float width) {
mBarBorderWidth = width;
}
/**
* Returns the width used for drawing borders around the bars.
* If borderWidth == 0, no border will be drawn.
*
* @return
*/
@Override
public float getBarBorderWidth() {
return mBarBorderWidth;
}
/**
* Sets the color drawing borders around the bars.
*
* @return
*/
public void setBarBorderColor(int color) {
mBarBorderColor = color;
}
/**
* Returns the color drawing borders around the bars.
*
* @return
*/
@Override
public int getBarBorderColor() {
return mBarBorderColor;
}
/**
* Set the alpha value (transparency) that is used for drawing the highlight
* indicator bar. min = 0 (fully transparent), max = 255 (fully opaque)
*
* @param alpha
*/
public void setHighLightAlpha(int alpha) {
mHighLightAlpha = alpha;
}
@Override
public int getHighLightAlpha() {
return mHighLightAlpha;
}
/**
* Sets labels for different values of bar-stacks, in case there are one.
*
* @param labels
*/
public void setStackLabels(String[] labels) {
mStackLabels = labels;
}
@Override
public String[] getStackLabels() {
return mStackLabels;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmBarDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 1,767 |
```java
package com.github.mikephil.charting.data.realm.implementation;
import android.content.Context;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet;
import com.github.mikephil.charting.formatter.DefaultFillFormatter;
import com.github.mikephil.charting.formatter.FillFormatter;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
import java.util.List;
import io.realm.RealmObject;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 21/10/15.
*/
public class RealmLineDataSet<T extends RealmObject> extends RealmLineRadarDataSet<T> implements ILineDataSet {
/** Drawing mode for this line dataset **/
private LineDataSet.Mode mMode = LineDataSet.Mode.LINEAR;
/**
* List representing all colors that are used for the circles
*/
private List<Integer> mCircleColors = null;
/**
* the color of the inner circles
*/
private int mCircleColorHole = Color.WHITE;
/**
* the radius of the circle-shaped value indicators
*/
private float mCircleRadius = 8f;
/** the hole radius of the circle-shaped value indicators */
private float mCircleHoleRadius = 4f;
/**
* sets the intensity of the cubic lines
*/
private float mCubicIntensity = 0.2f;
/**
* the path effect of this DataSet that makes dashed lines possible
*/
private DashPathEffect mDashPathEffect = null;
/**
* formatter for customizing the position of the fill-line
*/
private FillFormatter mFillFormatter = new DefaultFillFormatter();
/**
* if true, drawing circles is enabled
*/
private boolean mDrawCircles = true;
private boolean mDrawCircleHole = true;
/**
* Constructor for creating a LineDataSet with realm data.
*
* @param result the queried results from the realm database
* @param yValuesField the name of the field in your data object that represents the y-value
*/
public RealmLineDataSet(RealmResults<T> result, String yValuesField) {
super(result, yValuesField);
mCircleColors = new ArrayList<>();
// default color
mCircleColors.add(Color.rgb(140, 234, 255));
build(this.results);
calcMinMax(0, results.size());
}
/**
* Constructor for creating a LineDataSet with realm data.
*
* @param result the queried results from the realm database
* @param yValuesField the name of the field in your data object that represents the y-value
* @param xIndexField the name of the field in your data object that represents the x-index
*/
public RealmLineDataSet(RealmResults<T> result, String yValuesField, String xIndexField) {
super(result, yValuesField, xIndexField);
mCircleColors = new ArrayList<>();
// default color
mCircleColors.add(Color.rgb(140, 234, 255));
build(this.results);
calcMinMax(0, results.size());
}
/**
* Returns the drawing mode for this line dataset
*
* @return
*/
@Override
public LineDataSet.Mode getMode() {
return mMode;
}
/**
* Returns the drawing mode for this line dataset
*
* @return
*/
public void setMode(LineDataSet.Mode mode) {
mMode = mode;
}
/**
* Sets the intensity for cubic lines (if enabled). Max = 1f = very cubic,
* Min = 0.05f = low cubic effect, Default: 0.2f
*
* @param intensity
*/
public void setCubicIntensity(float intensity) {
if (intensity > 1f)
intensity = 1f;
if (intensity < 0.05f)
intensity = 0.05f;
mCubicIntensity = intensity;
}
@Override
public float getCubicIntensity() {
return mCubicIntensity;
}
/**
* sets the size (radius) of the circle shpaed value indicators, default
* size = 4f
*
* @param size
*/
public void setCircleSize(float size) {
mCircleRadius = Utils.convertDpToPixel(size);
}
@Override
public float getCircleRadius() {
return mCircleRadius;
}
/**
* sets the hole radius of the drawn circles.
* Default radius = 2f
*
* @param holeRadius
*/
public void setCircleHoleRadius(float holeRadius) {
mCircleHoleRadius = Utils.convertDpToPixel(holeRadius);
}
@Override
public float getCircleHoleRadius() {
return mCircleHoleRadius;
}
/**
* Enables the line to be drawn in dashed mode, e.g. like this
* "- - - - - -". THIS ONLY WORKS IF HARDWARE-ACCELERATION IS TURNED OFF.
* Keep in mind that hardware acceleration boosts performance.
*
* @param lineLength the length of the line pieces
* @param spaceLength the length of space in between the pieces
* @param phase offset, in degrees (normally, use 0)
*/
public void enableDashedLine(float lineLength, float spaceLength, float phase) {
mDashPathEffect = new DashPathEffect(new float[]{
lineLength, spaceLength
}, phase);
}
/**
* Disables the line to be drawn in dashed mode.
*/
public void disableDashedLine() {
mDashPathEffect = null;
}
@Override
public boolean isDashedLineEnabled() {
return mDashPathEffect == null ? false : true;
}
@Override
public DashPathEffect getDashPathEffect() {
return mDashPathEffect;
}
/**
* set this to true to enable the drawing of circle indicators for this
* DataSet, default true
*
* @param enabled
*/
public void setDrawCircles(boolean enabled) {
this.mDrawCircles = enabled;
}
@Override
public boolean isDrawCirclesEnabled() {
return mDrawCircles;
}
/**
* @deprecated Kept for backward compatibility.
* @param enabled
*/
@Deprecated
public void setDrawCubic(boolean enabled) {
mMode = enabled ? LineDataSet.Mode.CUBIC_BEZIER : LineDataSet.Mode.LINEAR;
}
/**
* @deprecated Kept for backward compatibility.
* @return
*/
@Deprecated
@Override
public boolean isDrawCubicEnabled() {
return mMode == LineDataSet.Mode.CUBIC_BEZIER;
}
/**
* @deprecated Kept for backward compatibility.
* @param enabled
*/
@Deprecated
public void setDrawStepped(boolean enabled) {
mMode = enabled ? LineDataSet.Mode.STEPPED : LineDataSet.Mode.LINEAR;
}
/**
* @deprecated Kept for backward compatibility.
* @return
*/
@Deprecated
@Override
public boolean isDrawSteppedEnabled() {
return mMode == LineDataSet.Mode.STEPPED;
}
/** ALL CODE BELOW RELATED TO CIRCLE-COLORS */
/**
* returns all colors specified for the circles
*
* @return
*/
public List<Integer> getCircleColors() {
return mCircleColors;
}
@Override
public int getCircleColor(int index) {
return mCircleColors.get(index % mCircleColors.size());
}
/**
* Sets the colors that should be used for the circles of this DataSet.
* Colors are reused as soon as the number of Entries the DataSet represents
* is higher than the size of the colors array. Make sure that the colors
* are already prepared (by calling getResources().getColor(...)) before
* adding them to the DataSet.
*
* @param colors
*/
public void setCircleColors(List<Integer> colors) {
mCircleColors = colors;
}
/**
* Sets the colors that should be used for the circles of this DataSet.
* Colors are reused as soon as the number of Entries the DataSet represents
* is higher than the size of the colors array. Make sure that the colors
* are already prepared (by calling getResources().getColor(...)) before
* adding them to the DataSet.
*
* @param colors
*/
public void setCircleColors(int[] colors) {
this.mCircleColors = ColorTemplate.createColors(colors);
}
/**
* ets the colors that should be used for the circles of this DataSet.
* Colors are reused as soon as the number of Entries the DataSet represents
* is higher than the size of the colors array. You can use
* "new String[] { R.color.red, R.color.green, ... }" to provide colors for
* this method. Internally, the colors are resolved using
* getResources().getColor(...)
*
* @param colors
*/
public void setCircleColors(int[] colors, Context c) {
List<Integer> clrs = new ArrayList<>();
for (int color : colors) {
clrs.add(c.getResources().getColor(color));
}
mCircleColors = clrs;
}
/**
* Sets the one and ONLY color that should be used for this DataSet.
* Internally, this recreates the colors array and adds the specified color.
*
* @param color
*/
public void setCircleColor(int color) {
resetCircleColors();
mCircleColors.add(color);
}
/**
* resets the circle-colors array and creates a new one
*/
public void resetCircleColors() {
mCircleColors = new ArrayList<>();
}
/**
* Sets the color of the inner circle of the line-circles.
*
* @param color
*/
public void setCircleColorHole(int color) {
mCircleColorHole = color;
}
@Override
public int getCircleHoleColor() {
return mCircleColorHole;
}
/**
* Set this to true to allow drawing a hole in each data circle.
*
* @param enabled
*/
public void setDrawCircleHole(boolean enabled) {
mDrawCircleHole = enabled;
}
@Override
public boolean isDrawCircleHoleEnabled() {
return mDrawCircleHole;
}
/**
* Sets a custom FillFormatter to the chart that handles the position of the
* filled-line for each DataSet. Set this to null to use the default logic.
*
* @param formatter
*/
public void setFillFormatter(FillFormatter formatter) {
if (formatter == null)
mFillFormatter = new DefaultFillFormatter();
else
mFillFormatter = formatter;
}
@Override
public FillFormatter getFillFormatter() {
return mFillFormatter;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmLineDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 2,475 |
```java
package com.github.mikephil.charting.data.realm.implementation;
import com.github.mikephil.charting.data.CandleData;
import com.github.mikephil.charting.data.realm.base.RealmUtils;
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
import java.util.List;
import io.realm.RealmObject;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 19/12/15.
*/
public class RealmCandleData extends CandleData {
public RealmCandleData(RealmResults<? extends RealmObject> result, String xValuesField, List<ICandleDataSet> dataSets) {
super(RealmUtils.toXVals(result, xValuesField), dataSets);
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmCandleData.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 152 |
```java
package com.github.mikephil.charting.data.realm.implementation;
import com.github.mikephil.charting.data.BubbleEntry;
import com.github.mikephil.charting.data.realm.base.RealmBarLineScatterCandleBubbleDataSet;
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
import com.github.mikephil.charting.utils.Utils;
import io.realm.DynamicRealmObject;
import io.realm.RealmObject;
import io.realm.RealmResults;
/**
* Created by Philipp Jahoda on 07/11/15.
*/
public class RealmBubbleDataSet<T extends RealmObject> extends RealmBarLineScatterCandleBubbleDataSet<T, BubbleEntry> implements IBubbleDataSet {
private String mSizeField;
protected float mXMax;
protected float mXMin;
protected float mMaxSize;
protected boolean mNormalizeSize = true;
private float mHighlightCircleWidth = 2.5f;
/**
* Constructor for creating a CandleDataSet with realm data.
*
* @param result the queried results from the realm database
* @param yValuesField the name of the field in your data object that represents the y-value
* @param sizeField the name of the field in your data object that represents the bubble size
*/
public RealmBubbleDataSet(RealmResults<T> result, String yValuesField, String sizeField) {
super(result, yValuesField);
this.mSizeField = sizeField;
build(this.results);
calcMinMax(0, results.size());
}
/**
* Constructor for creating a CandleDataSet with realm data.
*
* @param result the queried results from the realm database
* @param yValuesField the name of the field in your data object that represents the y-value
* @param xIndexField the name of the field in your data object that represents the x-index
* @param sizeField the name of the field in your data object that represents the bubble size
*/
public RealmBubbleDataSet(RealmResults<T> result, String yValuesField, String xIndexField, String sizeField) {
super(result, yValuesField, xIndexField);
this.mSizeField = sizeField;
build(this.results);
calcMinMax(0, results.size());
}
@Override
public BubbleEntry buildEntryFromResultObject(T realmObject, int xIndex) {
DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);
return new BubbleEntry(
mIndexField == null ? xIndex : dynamicObject.getInt(mIndexField),
dynamicObject.getFloat(mValuesField),
dynamicObject.getFloat(mSizeField));
}
@Override
public void calcMinMax(int start, int end) {
if (mValues == null)
return;
if (mValues.isEmpty())
return;
int endValue;
if (end == 0 || end >= mValues.size())
endValue = mValues.size() - 1;
else
endValue = end;
mYMin = yMin(mValues.get(start));
mYMax = yMax(mValues.get(start));
// need chart width to guess this properly
for (int i = start; i < endValue; i++) {
final BubbleEntry entry = mValues.get(i);
final float ymin = yMin(entry);
final float ymax = yMax(entry);
if (ymin < mYMin) {
mYMin = ymin;
}
if (ymax > mYMax) {
mYMax = ymax;
}
final float xmin = xMin(entry);
final float xmax = xMax(entry);
if (xmin < mXMin) {
mXMin = xmin;
}
if (xmax > mXMax) {
mXMax = xmax;
}
final float size = largestSize(entry);
if (size > mMaxSize) {
mMaxSize = size;
}
}
}
@Override
public float getXMax() {
return mXMax;
}
@Override
public float getXMin() {
return mXMin;
}
@Override
public float getMaxSize() {
return mMaxSize;
}
@Override
public boolean isNormalizeSizeEnabled() {
return mNormalizeSize;
}
public void setNormalizeSizeEnabled(boolean normalizeSize) {
mNormalizeSize = normalizeSize;
}
private float yMin(BubbleEntry entry) {
return entry.getVal();
}
private float yMax(BubbleEntry entry) {
return entry.getVal();
}
private float xMin(BubbleEntry entry) {
return (float) entry.getXIndex();
}
private float xMax(BubbleEntry entry) {
return (float) entry.getXIndex();
}
private float largestSize(BubbleEntry entry) {
return entry.getSize();
}
@Override
public void setHighlightCircleWidth(float width) {
mHighlightCircleWidth = Utils.convertDpToPixel(width);
}
@Override
public float getHighlightCircleWidth() {
return mHighlightCircleWidth;
}
/**
* Sets the database fieldname for the bubble size.
*
* @param sizeField
*/
public void setSizeField(String sizeField) {
this.mSizeField = sizeField;
}
/**
* Returns the database fieldname that stores bubble size.
*
* @return
*/
public String getSizeField() {
return mSizeField;
}
}
``` | /content/code_sandbox/MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmBubbleDataSet.java | java | 2016-05-18T03:51:41 | 2024-08-09T09:00:29 | StockChart | AndroidJiang/StockChart | 1,086 | 1,185 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.