Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilJay committed Jun 1, 2015
1 parent b765b90 commit f32cfd0
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ protected void onCreate(Bundle savedInstanceState) {
l.setTextSize(11f);
l.setTextColor(Color.WHITE);
l.setPosition(LegendPosition.BELOW_CHART_LEFT);
// l.setYOffset(11f);

XAxis xAxis = mChart.getXAxis();
xAxis.setTypeface(tf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ protected void onCreate(Bundle savedInstanceState) {
Legend l = mChart.getLegend();
l.setPosition(LegendPosition.RIGHT_OF_CHART);
l.setXEntrySpace(7f);
l.setYEntrySpace(5f);
l.setYEntrySpace(0f);
l.setYOffset(0f);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

mChart.setHighlightIndicatorEnabled(false);
mChart.setDrawGridBackground(false);
mChart.setData(generateScatterData(2, 10000, 400));
mChart.setData(generateScatterData(6, 10000, 200));

XAxis xAxis = mChart.getXAxis();
xAxis.setEnabled(true);
Expand All @@ -54,8 +54,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
Legend l = mChart.getLegend();
l.setWordWrapEnabled(true);
l.setTypeface(tf);
// l.setFormSize(18f);
// l.setTextSize(9f);
l.setFormSize(14f);
l.setTextSize(9f);

// increase the space between legend & bottom and legend & content
l.setYOffset(13f);
mChart.setExtraBottomOffset(16f);

return v;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ protected ScatterData generateScatterData(int dataSets, float range, int count)

ScatterShape[] shapes = ScatterChart.getAllPossibleShapes();

for(int i = 0; i < dataSets*4; i++) {
for(int i = 0; i < dataSets; i++) {

ArrayList<Entry> entries = new ArrayList<Entry>();

for(int j = 0; j < count; j++) {
entries.add(new Entry((float) (Math.random() * range) + range / 4, j));
}

ScatterDataSet ds = new ScatterDataSet(entries, "Company A");
ScatterDataSet ds = new ScatterDataSet(entries, getLabel(i));
ds.setScatterShapeSize(12f);
ds.setScatterShape(shapes[i % shapes.length]);
ds.setColors(ColorTemplate.COLORFUL_COLORS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public View getView(int position, View convertView, Context c) {

Legend l = holder.chart.getLegend();
l.setPosition(LegendPosition.RIGHT_OF_CHART);
l.setYEntrySpace(0f);
l.setYOffset(0f);

// do not forget to refresh the chart
// holder.chart.invalidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ protected void calculateOffsets() {
|| mLegend.getPosition() == LegendPosition.BELOW_CHART_RIGHT
|| mLegend.getPosition() == LegendPosition.BELOW_CHART_CENTER) {

float yOffset = mLegend.mTextHeightMax * 2.f; // It's
float yOffset = mLegend.mTextHeightMax; // It's
// possible
// that we do
// not need
Expand Down
16 changes: 8 additions & 8 deletions MPChartLib/src/com/github/mikephil/charting/charts/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -1037,17 +1037,17 @@ public void setDescriptionColor(int color) {
* @param bottom
*/
public void setExtraOffsets(float left, float top, float right, float bottom) {
mExtraLeftOffset = left;
mExtraTopOffset = top;
mExtraRightOffset = right;
mExtraBottomOffset = bottom;
setExtraLeftOffset(left);
setExtraTopOffset(top);
setExtraRightOffset(right);
setExtraBottomOffset(bottom);
}

/**
* Set an extra offset to be appended to the viewport's top
*/
public void setExtraTopOffset(float offset) {
mExtraTopOffset = offset;
mExtraTopOffset = Utils.convertDpToPixel(offset);
}

/**
Expand All @@ -1061,7 +1061,7 @@ public float getExtraTopOffset() {
* Set an extra offset to be appended to the viewport's right
*/
public void setExtraRightOffset(float offset) {
mExtraRightOffset = offset;
mExtraRightOffset = Utils.convertDpToPixel(offset);
}

/**
Expand All @@ -1075,7 +1075,7 @@ public float getExtraRightOffset() {
* Set an extra offset to be appended to the viewport's bottom
*/
public void setExtraBottomOffset(float offset) {
mExtraBottomOffset = offset;
mExtraBottomOffset = Utils.convertDpToPixel(offset);
}

/**
Expand All @@ -1089,7 +1089,7 @@ public float getExtraBottomOffset() {
* Set an extra offset to be appended to the viewport's left
*/
public void setExtraLeftOffset(float offset) {
mExtraLeftOffset = offset;
mExtraLeftOffset = Utils.convertDpToPixel(offset);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public float getYOffset() {
}

/**
* Sets the used x-axis offset for the labels on this axis.
* Sets the used y-axis offset for the labels on this axis. For the legend,
* higher offset means the legend as a whole will be placed further away
* from the top.
*
* @param xOffset
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Legend() {
mTextSize = Utils.convertDpToPixel(10f);
mStackSpace = Utils.convertDpToPixel(3f);
this.mXOffset = Utils.convertDpToPixel(5f);
this.mYOffset = Utils.convertDpToPixel(6f);
this.mYOffset = Utils.convertDpToPixel(7f);
}

/**
Expand Down Expand Up @@ -477,30 +477,6 @@ public void setFormToTextSpace(float space) {
this.mFormToTextSpace = Utils.convertDpToPixel(space);
}

// /**
// * applies the state from the legend in the parameter to this legend
// (except
// * colors, labels and offsets)
// *
// * @param l
// */
// public void apply(Legend l) {
//
// mPosition = l.mPosition;
// mShape = l.mShape;
// mTypeface = l.mTypeface;
// mFormSize = l.mFormSize;
// mXEntrySpace = l.mXEntrySpace;
// mYEntrySpace = l.mYEntrySpace;
// mFormToTextSpace = l.mFormToTextSpace;
// mTextSize = l.mTextSize;
// mStackSpace = l.mStackSpace;
// mTextColor = l.mTextColor;
// mEnabled = l.mEnabled;
// mXOffset = l.mXOffset;
// mYOffset = l.mYOffset;
// }

/**
* returns the space that is left out between stacked forms (with no label)
*
Expand Down

0 comments on commit f32cfd0

Please sign in to comment.