diff --git a/changelog.md b/changelog.md index af3e76368293407548d59888a4929f3fd39414a0..b5e77be1660012392431016b65e71e824061179d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,2 +1,27 @@ # GraphView -v3.1.0支持原有组件的所有效果 \ No newline at end of file +v1.1.0 + + +不支持功能 +1.滑动功能 ,缩放功能 + + +不支持功能具体API如下 + +1. BaseSeries --> public void appendData(E dataPoint,boolean scrollToEnd,int maxDataPoints,boolean silent); +2. BaseSeries --> public void appendData(E dataPoint,boolean scrollToEnd,int maxDataPoints); +3. LineGraphSeries --> public void appendData(E dataPoint,boolean scrollToEnd,int maxDataPoints,boolean silent); +4. Viewport --> public boolean isScrollable(); +5. Viewport --> public boolean setScrollable(boolean mIsScrollable); +6. Viewport --> public boolean isScalable(); +7. Viewport --> public boolean setScalable(boolean mIsScalable); +8. Viewport --> public boolean scalableTOEnd(); +9. Viewport --> public OnXAxisBoundsChangedListener getOnXAxisBoundsChangedListener (); +10. Viewport --> public void setOnXAxisBoundListener(OnXAxisBoundsChangedListener l); +11. Viewport --> public void setScrollableY(boolean scrollableY); +12. Viewport --> public void setScalableY(boolean scalableY); +13. Viewport --> public double getMaxXAxisSize(); +14. Viewport --> public double getMaxYAxisSize(); +15. Viewport --> public double setMaxXAxisSize(double mMaxXAxisViewportSize); +16. Viewport --> public double setMaxYAxisSize(double mMaxYAxisViewportSize); +16. Viewport --> public double setMinimalViewport(double minX,double maxX,double minY,double maxY); \ No newline at end of file diff --git a/entry/src/main/java/com/jjoe64/graphview_os/slice/MainAbilitySlice.java b/entry/src/main/java/com/jjoe64/graphview_os/slice/MainAbilitySlice.java index bdf9999e38cd0cb5ed63e0cfa85871ccb9ca414a..f34d72ab7a38106a01dc3aa50efb6f6a668c9e71 100644 --- a/entry/src/main/java/com/jjoe64/graphview_os/slice/MainAbilitySlice.java +++ b/entry/src/main/java/com/jjoe64/graphview_os/slice/MainAbilitySlice.java @@ -1,7 +1,9 @@ package com.jjoe64.graphview_os.slice; import com.jjoe64.graphview.GraphView; +import com.jjoe64.graphview.UniqueLegendRenderer; import com.jjoe64.graphview.helper.GraphViewXML; +import com.jjoe64.graphview.helper.StaticLabelsFormatter; import com.jjoe64.graphview.series.BarGraphSeries; import com.jjoe64.graphview.series.DataPoint; import com.jjoe64.graphview.series.DataPointInterface; @@ -32,7 +34,7 @@ public class MainAbilitySlice extends BaseAbilitySlice { @Override protected void initView() { graphView = (GraphView) findComponentById(ResourceTable.Id_graphView); - graphViewXml = (GraphViewXML) findComponentById(ResourceTable.Id_graphViewXml); +// graphViewXml = (GraphViewXML) findComponentById(ResourceTable.Id_graphViewXml); componentById = (Button) findComponentById(ResourceTable.Id_tvButton); @@ -84,7 +86,7 @@ public class MainAbilitySlice extends BaseAbilitySlice { // } // // mIndex += 1; - test9(); + test15(); } }); @@ -95,7 +97,7 @@ public class MainAbilitySlice extends BaseAbilitySlice { } - private void test1(){ + private void test1() { BarGraphSeries series = new BarGraphSeries<>(new DataPoint[]{ new DataPoint(0, 520.5), new DataPoint(492.9, 525), @@ -183,7 +185,7 @@ public class MainAbilitySlice extends BaseAbilitySlice { } - private void test7(){ + private void test7() { LineGraphSeries seriesNew2 = new LineGraphSeries<>(new DataPoint[]{ new DataPoint(3, 20), new DataPoint(4, 50) @@ -204,7 +206,7 @@ public class MainAbilitySlice extends BaseAbilitySlice { graphView.getSecondScale().setVerticalAxisTitleTextSize(-1); } - private void test8(){ + private void test8() { PointsGraphSeries seriesNew = new PointsGraphSeries<>(new DataPoint[]{ new DataPoint(0, 1), new DataPoint(1, 5), @@ -218,7 +220,7 @@ public class MainAbilitySlice extends BaseAbilitySlice { graphView.getGridLabelRenderer().setTextSize(35.5f); } - private void test9(){ + private void test9() { BarGraphSeries series = new BarGraphSeries<>(new DataPoint[]{ new DataPoint(0, 1), new DataPoint(1, 5), @@ -229,7 +231,169 @@ public class MainAbilitySlice extends BaseAbilitySlice { graphView.addSeries(series); series.setTitle("Bar"); graphView.getLegendRenderer().setVisible(true); - graphView.getLegendRenderer().setFixedPosition(583,90); + graphView.getLegendRenderer().setFixedPosition(583, 90); graphView.getLegendRenderer().setMargin(30); } + + private void test10() { + LineGraphSeries lineGraph = new LineGraphSeries<>(new DataPoint[]{ + new DataPoint(0, 1), + new DataPoint(1, 5), + new DataPoint(2, 3), + new DataPoint(3, 2), + new DataPoint(4, 6) + }); + lineGraph.setDrawAsPath(true); + PointsGraphSeries pointsGraph = new PointsGraphSeries<>(new DataPoint[]{ + new DataPoint(0, 2), + new DataPoint(2, 5), + new DataPoint(4, 1), + new DataPoint(6, 4), + new DataPoint(8, 6) + }); + graphView.addSeries(lineGraph); + graphView.addSeries(pointsGraph); + StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graphView, new String[]{"old", "new"}, new String[]{"high", "low"}); + graphView.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter); + } + + private void test11() { + PointsGraphSeries pointsGraphSeries = new PointsGraphSeries<>(new DataPoint[]{ + new DataPoint(0, 1), + new DataPoint(1, 5), + new DataPoint(2, 3), + new DataPoint(3, 2), + new DataPoint(4, 6) + }); + graphView.addSeries(pointsGraphSeries); + graphView.getGridLabelRenderer().setPadding(4); + } + + private void test12() { + PointsGraphSeries pointsGraphSeries = new PointsGraphSeries<>(new DataPoint[]{ + new DataPoint(0, 2), + new DataPoint(2, 5), + new DataPoint(4, 1), + new DataPoint(6, 4), + new DataPoint(8, 6) + }); + graphView.addSeries(pointsGraphSeries); + graphView.getGridLabelRenderer().setLabelsSpace(104); + } + + private void test13() { + BarGraphSeries series = new BarGraphSeries<>(new DataPoint[]{ + new DataPoint(0, 1), + new DataPoint(1, 5), + new DataPoint(2, 3), + new DataPoint(3, 2), + new DataPoint(4, 6) + }); + graphView.addSeries(series); + } + + private void test14() { + LineGraphSeries lineGraph = new LineGraphSeries<>(new DataPoint[]{ + new DataPoint(0.0, 1.0), + new DataPoint(2.0, -51.0), + new DataPoint(2.0, -51.0), + }); + lineGraph.setTitle("Air"); + lineGraph.setColor(Color.rgb(115,211,230)); + graphView.addSeries(lineGraph); + + LineGraphSeries lineGraph2 = new LineGraphSeries<>(new DataPoint[]{ + new DataPoint(2.0, -51.0), + new DataPoint(5.0, -110.0), + new DataPoint(15.0, -110.0), + new DataPoint(21.0, -51.0), + new DataPoint(21.0, -51.0) + }); + lineGraph2.setTitle("TMX12/50"); + lineGraph2.setColor(Color.getIntColor("#000000")); + graphView.addSeries(lineGraph2); + + LineGraphSeries lineGraph4 = new LineGraphSeries<>(new DataPoint[]{ + new DataPoint(34.3, -21.0), + new DataPoint(37.0, -21.0), + new DataPoint(37.3, -18.0), + new DataPoint(41.0, -18.0), + new DataPoint(41.3, -15.0), + new DataPoint(46.0, -15.0), + new DataPoint(46.3, -12.0), + new DataPoint(54.0, -12.0), + new DataPoint(54.3, -9.0), + new DataPoint(65.0, -9.0), + new DataPoint(65.3, -6.0), + new DataPoint(84.0, -6.0), + new DataPoint(84.3, -3.0), + new DataPoint(124.0, -3.0), + new DataPoint(124.3, 0.0) + }); + lineGraph4.setTitle("NTX50"); + lineGraph4.setColor(Color.rgb(115,230,115)); + graphView.addSeries(lineGraph4); + + LineGraphSeries lineGraph3 = new LineGraphSeries<>(new DataPoint[]{ + new DataPoint(21.0, -51.0), + new DataPoint(22.0, -51.0), + new DataPoint(22.3, -48.0), + new DataPoint(23.0, -48.0), + new DataPoint(23.3, -45.0), + new DataPoint(24.0, -45.0), + new DataPoint(24.3, -45.0), + new DataPoint(25.0, -42.0), + new DataPoint(25.3, -39.0), + new DataPoint(26.3, -36.0), + new DataPoint(27.0, -36.0), + new DataPoint(27.3, -33.0), + new DataPoint(28.0, -33.0), + new DataPoint(28.3, -30.0), + new DataPoint(29.0, -30.0), + new DataPoint(29.3, -27.0), + new DataPoint(31.0, -27.0), + new DataPoint(31.3, -24.0), + new DataPoint(34.0, -24.0), + new DataPoint(34.3, -21.0) + }); + lineGraph3.setTitle("Air"); + lineGraph3.setColor(Color.rgb(115,211,230)); + graphView.addSeries(lineGraph3); + + graphView.getViewport().setMinX(0); + graphView.getViewport().setMaxX(130); + graphView.getViewport().setXAxisBoundsManual(true); + graphView.getViewport().setMinY(-115); + graphView.getViewport().setMaxY(0); + graphView.getViewport().setXAxisBoundsManual(true); + graphView.getGridLabelRenderer().setHighlightZeroLines(false); + + graphView.setLegendRenderer(new UniqueLegendRenderer(graphView)); + graphView.getLegendRenderer().setVisible(true); + + } + + private void test15(){ + LineGraphSeries lineGraph = new LineGraphSeries<>(new DataPoint[]{ + new DataPoint(0, 1), + new DataPoint(1, 5), + new DataPoint(2, 3), + new DataPoint(3, 2), + new DataPoint(4, 6) + }); + graphView.addSeries(lineGraph); + + PointsGraphSeries pointsGraphSeries = new PointsGraphSeries<>(new DataPoint[]{ + new DataPoint(0, 120), + new DataPoint(1, -30), + new DataPoint(2, 60), + new DataPoint(3, 20), + new DataPoint(4, 50) + }); + graphView.getSecondScale().setMinY(20.6f); + graphView.getSecondScale().setMaxY(100.8f); + graphView.getSecondScale().addSeries(pointsGraphSeries); + graphView.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(Color.RED.getValue()); + + } } diff --git a/graphveiw/src/main/java/com/jjoe64/graphview/GridLabelRenderer.java b/graphveiw/src/main/java/com/jjoe64/graphview/GridLabelRenderer.java index de79c6b575c3c776541d9f786374ee87832ed9b3..da460dc9660cdce49c013fbcf27aafa92aa3daa5 100644 --- a/graphveiw/src/main/java/com/jjoe64/graphview/GridLabelRenderer.java +++ b/graphveiw/src/main/java/com/jjoe64/graphview/GridLabelRenderer.java @@ -374,1556 +374,1570 @@ public class GridLabelRenderer { int size; int size2; - color1 = Color.BLACK.getValue(); - color2 = Color.GRAY.getValue(); - size = 20; - size2 = 20; - - mStyles.verticalLabelsColor = color1; - mStyles.verticalLabelsSecondScaleColor = color1; - mStyles.horizontalLabelsColor = color1; - mStyles.gridColor = color2; - mStyles.textSize = size; - mStyles.padding = size2; - mStyles.labelsSpace = (int) mStyles.textSize / 5; - - mStyles.verticalLabelsAlign = 2; - mStyles.verticalLabelsSecondScaleAlign = 0; - mStyles.highlightZeroLines = true; - - mStyles.verticalAxisTitleColor = mStyles.verticalLabelsColor; - mStyles.horizontalAxisTitleColor = mStyles.horizontalLabelsColor; - mStyles.verticalAxisTitleTextSize = mStyles.textSize; - mStyles.horizontalAxisTitleTextSize = mStyles.textSize; - - mStyles.horizontalLabelsVisible = true; - mStyles.verticalLabelsVisible = true; - - mStyles.horizontalLabelsAngle = 0f; - - mStyles.gridStyle = GridStyle.BOTH; - reloadStyles(); - } + color1 = Color.BLACK.getValue(); + color2 = Color.GRAY.getValue(); + size = 25; + size2 = 25; + + mStyles.verticalLabelsColor = color1; + mStyles.verticalLabelsSecondScaleColor = color1; + mStyles.horizontalLabelsColor = color1; + mStyles.gridColor = color2; + mStyles.textSize = size; + mStyles.padding = size2; + mStyles.labelsSpace = (int) mStyles.textSize / 5; + + mStyles.verticalLabelsAlign = 2; + mStyles.verticalLabelsSecondScaleAlign = 0; + mStyles.highlightZeroLines = true; + + mStyles.verticalAxisTitleColor = mStyles.verticalLabelsColor; + mStyles.horizontalAxisTitleColor = mStyles.horizontalLabelsColor; + mStyles.verticalAxisTitleTextSize = mStyles.textSize; + mStyles.horizontalAxisTitleTextSize = mStyles.textSize; + + mStyles.horizontalLabelsVisible = true; + mStyles.verticalLabelsVisible = true; + + mStyles.horizontalLabelsAngle = 0f; + + mStyles.gridStyle = GridStyle.BOTH; + reloadStyles(); + } - /** - * will load the styles to the internal - * paint objects (color, text size, text align) - */ - public void reloadStyles () { - mPaintLine = new Paint(); - mPaintLine.setColor(new Color(mStyles.gridColor)); - mPaintLine.setStrokeWidth(0); - - mPaintLabel = new Paint(); - mPaintLabel.setTextSize((int) getTextSize()); - mPaintLabel.setAntiAlias(true); - - mPaintAxisTitle = new Paint(); - mPaintAxisTitle.setTextSize((int) getTextSize()); - mPaintAxisTitle.setTextAlign(1); - } + /** + * will load the styles to the internal + * paint objects (color, text size, text align) + */ + public void reloadStyles() { + mPaintLine = new Paint(); + mPaintLine.setColor(new Color(mStyles.gridColor)); + mPaintLine.setStrokeWidth(0); + + mPaintLabel = new Paint(); + mPaintLabel.setTextSize((int) getTextSize()); + mPaintLabel.setAntiAlias(true); + + mPaintAxisTitle = new Paint(); + mPaintAxisTitle.setTextSize((int) getTextSize()); + mPaintAxisTitle.setTextAlign(1); + } - /** - * GraphView tries to fit the labels - * to display numbers that can be divided by 1, 2, or 5. - *
- * By default this is enabled. It makes sense to deactivate it - * when using Dates on the x axis. - * - * @return if human rounding is enabled - */ - public boolean isHumanRoundingX () { - return mHumanRoundingX; - } + /** + * GraphView tries to fit the labels + * to display numbers that can be divided by 1, 2, or 5. + *
+ * By default this is enabled. It makes sense to deactivate it + * when using Dates on the x axis. + * + * @return if human rounding is enabled + */ + public boolean isHumanRoundingX() { + return mHumanRoundingX; + } - /** - * GraphView tries to fit the labels - * to display numbers that can be divided by 1, 2, or 5. - * - * @return if human rounding is enabled - */ - public boolean isHumanRoundingY () { - return mHumanRoundingY; - } + /** + * GraphView tries to fit the labels + * to display numbers that can be divided by 1, 2, or 5. + * + * @return if human rounding is enabled + */ + public boolean isHumanRoundingY() { + return mHumanRoundingY; + } - /** - * activate or deactivate human rounding of the - * horizontal axis. GraphView tries to fit the labels - * to display numbers that can be divided by 1, 2, or 5. - *
- * By default this is enabled. It makes sense to deactivate it - * when using Dates on the x axis. - * - * @param humanRoundingX false to deactivate - * @param humanRoundingY false to deactivate - */ - public void setHumanRounding ( boolean humanRoundingX, boolean humanRoundingY){ - this.mHumanRoundingX = humanRoundingX; - this.mHumanRoundingY = humanRoundingY; - } + /** + * activate or deactivate human rounding of the + * horizontal axis. GraphView tries to fit the labels + * to display numbers that can be divided by 1, 2, or 5. + *
+ * By default this is enabled. It makes sense to deactivate it + * when using Dates on the x axis. + * + * @param humanRoundingX false to deactivate + * @param humanRoundingY false to deactivate + */ + public void setHumanRounding(boolean humanRoundingX, boolean humanRoundingY) { + this.mHumanRoundingX = humanRoundingX; + this.mHumanRoundingY = humanRoundingY; + } - /** - * activate or deactivate human rounding of the - * horizontal axis. GraphView tries to fit the labels - * to display numbers that can be divided by 1, 2, or 5. - *
- * By default this is enabled. - * - * @param humanRoundingBoth false to deactivate on both axises - */ - public void setHumanRounding ( boolean humanRoundingBoth){ - this.mHumanRoundingX = humanRoundingBoth; - this.mHumanRoundingY = humanRoundingBoth; - } + /** + * activate or deactivate human rounding of the + * horizontal axis. GraphView tries to fit the labels + * to display numbers that can be divided by 1, 2, or 5. + *
+ * By default this is enabled.
+ *
+ * @param humanRoundingBoth false to deactivate on both axises
+ */
+ public void setHumanRounding(boolean humanRoundingBoth) {
+ this.mHumanRoundingX = humanRoundingBoth;
+ this.mHumanRoundingY = humanRoundingBoth;
+ }
- /**
- * ss
- *
- * @return the general text size for the axis titles
- */
- public float getTextSize () {
- return mStyles.textSize;
- }
+ /**
+ * ss
+ *
+ * @return the general text size for the axis titles
+ */
+ public float getTextSize() {
+ return mStyles.textSize;
+ }
- /**
- * ss
- *
- * @return the font color of the vertical labels
- */
- public int getVerticalLabelsColor () {
- return mStyles.verticalLabelsColor;
- }
+ /**
+ * ss
+ *
+ * @return the font color of the vertical labels
+ */
+ public int getVerticalLabelsColor() {
+ return mStyles.verticalLabelsColor;
+ }
- /**
- * ss
- *
- * @return the alignment of the text of the
- * vertical labels
- */
- public int getVerticalLabelsAlign () {
- return mStyles.verticalLabelsAlign;
- }
+ /**
+ * ss
+ *
+ * @return the alignment of the text of the
+ * vertical labels
+ */
+ public int getVerticalLabelsAlign() {
+ return mStyles.verticalLabelsAlign;
+ }
- /**
- * ss
- *
- * @return the font color of the horizontal labels
- */
- public int getHorizontalLabelsColor () {
- return mStyles.horizontalLabelsColor;
- }
+ /**
+ * ss
+ *
+ * @return the font color of the horizontal labels
+ */
+ public int getHorizontalLabelsColor() {
+ return mStyles.horizontalLabelsColor;
+ }
- /**
- * ss
- *
- * @return the angle of the horizontal labels
- */
- public float getHorizontalLabelsAngle () {
- return mStyles.horizontalLabelsAngle;
- }
+ /**
+ * ss
+ *
+ * @return the angle of the horizontal labels
+ */
+ public float getHorizontalLabelsAngle() {
+ return mStyles.horizontalLabelsAngle;
+ }
- /**
- * clears the internal cache and forces
- * to redraw the grid and labels.
- * Normally you should always call {@link GraphView#onDataChanged(boolean, boolean)}
- * which will call this method.
- *
- * @param keepLabelsSize true if you don't want
- * to recalculate the size of
- * the labels. It is recommended
- * to use "true" because this will
- * improve performance and prevent
- * a flickering.
- * @param keepViewport true if you don't want that
- * the viewport will be recalculated.
- * It is recommended to use "true" for
- * performance.
- */
- public void invalidate ( boolean keepLabelsSize, boolean keepViewport){
- if (!keepViewport) {
- mIsAdjusted = false;
- }
- if (!keepLabelsSize) {
- if (!mLabelVerticalWidthFixed) {
- mLabelVerticalWidth = null;
- }
- mLabelVerticalHeight = null;
- mLabelVerticalSecondScaleWidth = null;
- mLabelVerticalSecondScaleHeight = null;
+ /**
+ * clears the internal cache and forces
+ * to redraw the grid and labels.
+ * Normally you should always call {@link GraphView#onDataChanged(boolean, boolean)}
+ * which will call this method.
+ *
+ * @param keepLabelsSize true if you don't want
+ * to recalculate the size of
+ * the labels. It is recommended
+ * to use "true" because this will
+ * improve performance and prevent
+ * a flickering.
+ * @param keepViewport true if you don't want that
+ * the viewport will be recalculated.
+ * It is recommended to use "true" for
+ * performance.
+ */
+ public void invalidate(boolean keepLabelsSize, boolean keepViewport) {
+ if (!keepViewport) {
+ mIsAdjusted = false;
+ }
+ if (!keepLabelsSize) {
+ if (!mLabelVerticalWidthFixed) {
+ mLabelVerticalWidth = null;
}
- //reloadStyles();
+ mLabelVerticalHeight = null;
+ mLabelVerticalSecondScaleWidth = null;
+ mLabelVerticalSecondScaleHeight = null;
}
+ //reloadStyles();
+ }
- /**
- * calculates the vertical steps of
- * the second scale.
- * This will not do any automatically update
- * of the bounds.
- * Use always manual bounds for the second scale.
- *
- * @return true if it is ready
- */
- protected boolean adjustVerticalSecondScale () {
- if (mLabelHorizontalHeight == null) {
- return false;
- }
- if (mGraphView.mSecondScale == null) {
- return true;
- }
+ /**
+ * calculates the vertical steps of
+ * the second scale.
+ * This will not do any automatically update
+ * of the bounds.
+ * Use always manual bounds for the second scale.
+ *
+ * @return true if it is ready
+ */
+ protected boolean adjustVerticalSecondScale() {
+ if (mLabelHorizontalHeight == null) {
+ return false;
+ }
+ if (mGraphView.mSecondScale == null) {
+ return true;
+ }
- double minY = mGraphView.mSecondScale.getMinY(false);
- double maxY = mGraphView.mSecondScale.getMaxY(false);
+ double minY = mGraphView.mSecondScale.getMinY(false);
+ double maxY = mGraphView.mSecondScale.getMaxY(false);
- // TODO find the number of labels
- int numVerticalLabels = mNumVerticalLabels;
+ // TODO find the number of labels
+ int numVerticalLabels = mNumVerticalLabels;
- double newMinY;
- double exactSteps;
+ double newMinY;
+ double exactSteps;
- if (mGraphView.mSecondScale.isYAxisBoundsManual()) {
- // split range into equal steps
- exactSteps = (maxY - minY) / (numVerticalLabels - 1);
+ if (mGraphView.mSecondScale.isYAxisBoundsManual()) {
+ // split range into equal steps
+ exactSteps = (maxY - minY) / (numVerticalLabels - 1);
- // round because of floating error
- exactSteps = Math.round(exactSteps * 1000000d) / 1000000d;
- } else {
- // TODO auto adjusting
- throw new IllegalStateException("Not yet implemented");
- }
+ // round because of floating error
+ exactSteps = Math.round(exactSteps * 1000000d) / 1000000d;
+ } else {
+ // TODO auto adjusting
+ throw new IllegalStateException("Not yet implemented");
+ }
- if (mStepsVerticalSecondScale != null && mStepsVerticalSecondScale.size() > 1) {
- // else choose other nice steps that previous
- // steps are included (divide to have more, or multiplicate to have less)
+ if (mStepsVerticalSecondScale != null && mStepsVerticalSecondScale.size() > 1) {
+ // else choose other nice steps that previous
+ // steps are included (divide to have more, or multiplicate to have less)
- double d1 = 0, d2 = 0;
- int i = 0;
- for (Double v : mStepsVerticalSecondScale.values()) {
- if (i == 0) {
- d1 = v;
- } else {
- d2 = v;
- break;
- }
- i++;
+ double d1 = 0, d2 = 0;
+ int i = 0;
+ for (Double v : mStepsVerticalSecondScale.values()) {
+ if (i == 0) {
+ d1 = v;
+ } else {
+ d2 = v;
+ break;
+ }
+ i++;
+ }
+ double oldSteps = d2 - d1;
+ if (oldSteps > 0) {
+ double newSteps = Double.NaN;
+
+ if (oldSteps > exactSteps) {
+ newSteps = oldSteps / 2;
+ } else if (oldSteps < exactSteps) {
+ newSteps = oldSteps * 2;
}
- double oldSteps = d2 - d1;
- if (oldSteps > 0) {
- double newSteps = Double.NaN;
-
- if (oldSteps > exactSteps) {
- newSteps = oldSteps / 2;
- } else if (oldSteps < exactSteps) {
- newSteps = oldSteps * 2;
- }
- // only if there wont be more than numLabels
- // and newSteps will be better than oldSteps
- int numStepsOld = (int) ((maxY - minY) / oldSteps);
- int numStepsNew = (int) ((maxY - minY) / newSteps);
+ // only if there wont be more than numLabels
+ // and newSteps will be better than oldSteps
+ int numStepsOld = (int) ((maxY - minY) / oldSteps);
+ int numStepsNew = (int) ((maxY - minY) / newSteps);
- boolean shouldChange;
+ boolean shouldChange;
- // avoid switching between 2 steps
- if (numStepsOld <= numVerticalLabels && numStepsNew <= numVerticalLabels) {
- // both are possible
- // only the new if it hows more labels
- shouldChange = numStepsNew > numStepsOld;
- } else {
- shouldChange = true;
- }
+ // avoid switching between 2 steps
+ if (numStepsOld <= numVerticalLabels && numStepsNew <= numVerticalLabels) {
+ // both are possible
+ // only the new if it hows more labels
+ shouldChange = numStepsNew > numStepsOld;
+ } else {
+ shouldChange = true;
+ }
- if (newSteps != Double.NaN && shouldChange && numStepsNew <= numVerticalLabels) {
- exactSteps = newSteps;
- } else {
- // try to stay to the old steps
- exactSteps = oldSteps;
- }
+ if (newSteps != Double.NaN && shouldChange && numStepsNew <= numVerticalLabels) {
+ exactSteps = newSteps;
+ } else {
+ // try to stay to the old steps
+ exactSteps = oldSteps;
}
- } else {
- // first time
- LogUtil.debug("find","find");
}
+ } else {
+ // first time
+ LogUtil.debug("find", "find");
+ }
- // find the first data point that is relevant to display
- // starting from 1st datapoint so that the steps have nice numbers
- // goal is to start with the minY or 1 step before
- newMinY = mGraphView.getSecondScale().mReferenceY;
- // must be down-rounded
- double count = Math.floor((minY - newMinY) / exactSteps);
- newMinY = count * exactSteps + newMinY;
+ // find the first data point that is relevant to display
+ // starting from 1st datapoint so that the steps have nice numbers
+ // goal is to start with the minY or 1 step before
+ newMinY = mGraphView.getSecondScale().mReferenceY;
+ // must be down-rounded
+ double count = Math.floor((minY - newMinY) / exactSteps);
+ newMinY = count * exactSteps + newMinY;
- // it can happen that we need to add some more labels to fill the complete screen
- numVerticalLabels = (int) ((mGraphView.getSecondScale().mCurrentViewport.height() * -1 / exactSteps)) + 2;
+ // it can happen that we need to add some more labels to fill the complete screen
+ numVerticalLabels = (int) ((mGraphView.getSecondScale().mCurrentViewport.height() * -1 / exactSteps)) + 2;
- // ensure that the value is valid (minimum 2)
- numVerticalLabels = Math.max(numVerticalLabels, 2);
+ // ensure that the value is valid (minimum 2)
+ numVerticalLabels = Math.max(numVerticalLabels, 2);
- if (mStepsVerticalSecondScale != null) {
- mStepsVerticalSecondScale.clear();
- } else {
- mStepsVerticalSecondScale = new LinkedHashMap<>(numVerticalLabels);
- }
+ if (mStepsVerticalSecondScale != null) {
+ mStepsVerticalSecondScale.clear();
+ } else {
+ mStepsVerticalSecondScale = new LinkedHashMap<>(numVerticalLabels);
+ }
- int height = mGraphView.getGraphContentHeight();
- // convert data-y to pixel-y in current viewport
- double pixelPerData = height / mGraphView.getSecondScale().mCurrentViewport.height() * -1;
+ int height = mGraphView.getGraphContentHeight();
+ // convert data-y to pixel-y in current viewport
+ double pixelPerData = height / mGraphView.getSecondScale().mCurrentViewport.height() * -1;
- for (int i = 0; i < numVerticalLabels; i++) {
- // dont draw if it is top of visible screen
- if (newMinY + (i * exactSteps) > mGraphView.getSecondScale().mCurrentViewport.top) {
- continue;
- }
- // dont draw if it is below of visible screen
- if (newMinY + (i * exactSteps) < mGraphView.getSecondScale().mCurrentViewport.bottom) {
- continue;
- }
+ for (int i = 0; i < numVerticalLabels; i++) {
+ // dont draw if it is top of visible screen
+ if (newMinY + (i * exactSteps) > mGraphView.getSecondScale().mCurrentViewport.top) {
+ continue;
+ }
+ // dont draw if it is below of visible screen
+ if (newMinY + (i * exactSteps) < mGraphView.getSecondScale().mCurrentViewport.bottom) {
+ continue;
+ }
- // where is the data point on the current screen
- double dataPointPos = newMinY + (i * exactSteps);
- double relativeToCurrentViewport = dataPointPos - mGraphView.getSecondScale().mCurrentViewport.bottom;
+ // where is the data point on the current screen
+ double dataPointPos = newMinY + (i * exactSteps);
+ double relativeToCurrentViewport = dataPointPos - mGraphView.getSecondScale().mCurrentViewport.bottom;
- double pixelPos = relativeToCurrentViewport * pixelPerData;
- mStepsVerticalSecondScale.put((int) pixelPos, dataPointPos);
- }
+ double pixelPos = relativeToCurrentViewport * pixelPerData;
+ mStepsVerticalSecondScale.put((int) pixelPos, dataPointPos);
+ }
- return true;
+ return true;
+ }
+
+ /**
+ * calculates the vertical steps. This will
+ * automatically change the bounds to nice
+ * human-readable min/max.
+ *
+ * @param changeBounds str
+ * @return true if it is ready
+ */
+ protected boolean adjustVertical(boolean changeBounds) {
+ if (mLabelHorizontalHeight == null) {
+ return false;
}
- /**
- * calculates the vertical steps. This will
- * automatically change the bounds to nice
- * human-readable min/max.
- *
- * @param changeBounds str
- * @return true if it is ready
- */
- protected boolean adjustVertical ( boolean changeBounds){
- if (mLabelHorizontalHeight == null) {
- return false;
- }
+ double minY = mGraphView.getViewport().getMinY(false);
+ double maxY = mGraphView.getViewport().getMaxY(false);
- double minY = mGraphView.getViewport().getMinY(false);
- double maxY = mGraphView.getViewport().getMaxY(false);
+ if (minY == maxY) {
+ return false;
+ }
- if (minY == maxY) {
- return false;
- }
+ // TODO find the number of labels
+ int numVerticalLabels = mNumVerticalLabels;
- // TODO find the number of labels
- int numVerticalLabels = mNumVerticalLabels;
+ double newMinY;
+ double exactSteps;
- double newMinY;
- double exactSteps;
+ // split range into equal steps
+ exactSteps = (maxY - minY) / (numVerticalLabels - 1);
- // split range into equal steps
- exactSteps = (maxY - minY) / (numVerticalLabels - 1);
+ // round because of floating error
+ exactSteps = Math.round(exactSteps * 1000000d) / 1000000d;
- // round because of floating error
- exactSteps = Math.round(exactSteps * 1000000d) / 1000000d;
+ // smallest viewport
+ if (exactSteps == 0d) {
+ exactSteps = 0.0000001d;
+ maxY = minY + exactSteps * (numVerticalLabels - 1);
+ }
- // smallest viewport
- if (exactSteps == 0d) {
- exactSteps = 0.0000001d;
- maxY = minY + exactSteps * (numVerticalLabels - 1);
- }
+ // human rounding to have nice numbers (1, 2, 5, ...)
+ if (isHumanRoundingY()) {
+ exactSteps = humanRound(exactSteps, changeBounds);
+ } else if (mStepsVertical != null && mStepsVertical.size() > 1) {
+ // else choose other nice steps that previous
+ // steps are included (divide to have more, or multiplicate to have less)
- // human rounding to have nice numbers (1, 2, 5, ...)
- if (isHumanRoundingY()) {
- exactSteps = humanRound(exactSteps, changeBounds);
- } else if (mStepsVertical != null && mStepsVertical.size() > 1) {
- // else choose other nice steps that previous
- // steps are included (divide to have more, or multiplicate to have less)
-
- double d1 = 0, d2 = 0;
- int i = 0;
- for (Double v : mStepsVertical.values()) {
- if (i == 0) {
- d1 = v;
- } else {
- d2 = v;
- break;
- }
- i++;
+ double d1 = 0, d2 = 0;
+ int i = 0;
+ for (Double v : mStepsVertical.values()) {
+ if (i == 0) {
+ d1 = v;
+ } else {
+ d2 = v;
+ break;
+ }
+ i++;
+ }
+ double oldSteps = d2 - d1;
+ if (oldSteps > 0) {
+ double newSteps = Double.NaN;
+
+ if (oldSteps > exactSteps) {
+ newSteps = oldSteps / 2;
+ } else if (oldSteps < exactSteps) {
+ newSteps = oldSteps * 2;
}
- double oldSteps = d2 - d1;
- if (oldSteps > 0) {
- double newSteps = Double.NaN;
-
- if (oldSteps > exactSteps) {
- newSteps = oldSteps / 2;
- } else if (oldSteps < exactSteps) {
- newSteps = oldSteps * 2;
- }
- // only if there wont be more than numLabels
- // and newSteps will be better than oldSteps
- int numStepsOld = (int) ((maxY - minY) / oldSteps);
- int numStepsNew = (int) ((maxY - minY) / newSteps);
+ // only if there wont be more than numLabels
+ // and newSteps will be better than oldSteps
+ int numStepsOld = (int) ((maxY - minY) / oldSteps);
+ int numStepsNew = (int) ((maxY - minY) / newSteps);
- boolean shouldChange;
+ boolean shouldChange;
- // avoid switching between 2 steps
- if (numStepsOld <= numVerticalLabels && numStepsNew <= numVerticalLabels) {
- // both are possible
- // only the new if it hows more labels
- shouldChange = numStepsNew > numStepsOld;
- } else {
- shouldChange = true;
- }
+ // avoid switching between 2 steps
+ if (numStepsOld <= numVerticalLabels && numStepsNew <= numVerticalLabels) {
+ // both are possible
+ // only the new if it hows more labels
+ shouldChange = numStepsNew > numStepsOld;
+ } else {
+ shouldChange = true;
+ }
- if (newSteps != Double.NaN && shouldChange && numStepsNew <= numVerticalLabels) {
- exactSteps = newSteps;
- } else {
- // try to stay to the old steps
- exactSteps = oldSteps;
- }
+ if (newSteps != Double.NaN && shouldChange && numStepsNew <= numVerticalLabels) {
+ exactSteps = newSteps;
+ } else {
+ // try to stay to the old steps
+ exactSteps = oldSteps;
}
- } else {
- // first time
- LogUtil.debug("find","find");
}
+ } else {
+ // first time
+ LogUtil.debug("find", "find");
+ }
- // find the first data point that is relevant to display
- // starting from 1st datapoint so that the steps have nice numbers
- // goal is to start with the minX or 1 step before
- newMinY = mGraphView.getViewport().getReferenceY();
- // must be down-rounded
- double count = Math.floor((minY - newMinY) / exactSteps);
- newMinY = count * exactSteps + newMinY;
-
- // now we have our labels bounds
- if (changeBounds) {
- mGraphView.getViewport().setMinY(newMinY);
- mGraphView.getViewport().setMaxY(Math.max(maxY, newMinY + (numVerticalLabels - 1) * exactSteps));
- mGraphView.getViewport().mYAxisBoundsStatus = Viewport.AxisBoundsStatus.AUTO_ADJUSTED;
- }
+ // find the first data point that is relevant to display
+ // starting from 1st datapoint so that the steps have nice numbers
+ // goal is to start with the minX or 1 step before
+ newMinY = mGraphView.getViewport().getReferenceY();
+ // must be down-rounded
+ double count = Math.floor((minY - newMinY) / exactSteps);
+ newMinY = count * exactSteps + newMinY;
- // it can happen that we need to add some more labels to fill the complete screen
- numVerticalLabels = (int) ((mGraphView.getViewport().mCurrentViewport.height() * -1 / exactSteps)) + 2;
+ // now we have our labels bounds
+ if (changeBounds) {
+ mGraphView.getViewport().setMinY(newMinY);
+ mGraphView.getViewport().setMaxY(Math.max(maxY, newMinY + (numVerticalLabels - 1) * exactSteps));
+ mGraphView.getViewport().mYAxisBoundsStatus = Viewport.AxisBoundsStatus.AUTO_ADJUSTED;
+ }
- if (mStepsVertical != null) {
- mStepsVertical.clear();
- } else {
- mStepsVertical = new LinkedHashMap<>((int) numVerticalLabels);
- }
+ // it can happen that we need to add some more labels to fill the complete screen
+ numVerticalLabels = (int) ((mGraphView.getViewport().mCurrentViewport.height() * -1 / exactSteps)) + 2;
- int height = mGraphView.getGraphContentHeight();
- // convert data-y to pixel-y in current viewport
- double pixelPerData = height / mGraphView.getViewport().mCurrentViewport.height() * -1;
+ if (mStepsVertical != null) {
+ mStepsVertical.clear();
+ } else {
+ mStepsVertical = new LinkedHashMap<>((int) numVerticalLabels);
+ }
- for (int i = 0; i < numVerticalLabels; i++) {
- // dont draw if it is top of visible screen
- if (newMinY + (i * exactSteps) > mGraphView.getViewport().mCurrentViewport.top) {
- continue;
- }
- // dont draw if it is below of visible screen
- if (newMinY + (i * exactSteps) < mGraphView.getViewport().mCurrentViewport.bottom) {
- continue;
- }
+ int height = mGraphView.getGraphContentHeight();
+ // convert data-y to pixel-y in current viewport
+ double pixelPerData = height / mGraphView.getViewport().mCurrentViewport.height() * -1;
+ for (int i = 0; i < numVerticalLabels; i++) {
+ // dont draw if it is top of visible screen
+ if (newMinY + (i * exactSteps) > mGraphView.getViewport().mCurrentViewport.top) {
+ continue;
+ }
+ // dont draw if it is below of visible screen
+ if (newMinY + (i * exactSteps) < mGraphView.getViewport().mCurrentViewport.bottom) {
+ continue;
+ }
- // where is the data point on the current screen
- double dataPointPos = newMinY + (i * exactSteps);
- double relativeToCurrentViewport = dataPointPos - mGraphView.getViewport().mCurrentViewport.bottom;
- double pixelPos = relativeToCurrentViewport * pixelPerData;
- mStepsVertical.put((int) pixelPos, dataPointPos);
- }
+ // where is the data point on the current screen
+ double dataPointPos = newMinY + (i * exactSteps);
+ double relativeToCurrentViewport = dataPointPos - mGraphView.getViewport().mCurrentViewport.bottom;
- return true;
+ double pixelPos = relativeToCurrentViewport * pixelPerData;
+ mStepsVertical.put((int) pixelPos, dataPointPos);
}
- /**
- * calculates the horizontal steps.
- *
- * @param changeBounds This will automatically change the
- * bounds to nice human-readable min/max.
- * @return true if it is ready
- */
- protected boolean adjustHorizontal ( boolean changeBounds){
- if (mLabelVerticalWidth == null) {
- return false;
- }
+ return true;
+ }
- double minX = mGraphView.getViewport().getMinX(false);
- double maxX = mGraphView.getViewport().getMaxX(false);
- if (minX == maxX) return false;
+ /**
+ * calculates the horizontal steps.
+ *
+ * @param changeBounds This will automatically change the
+ * bounds to nice human-readable min/max.
+ * @return true if it is ready
+ */
+ protected boolean adjustHorizontal(boolean changeBounds) {
+ if (mLabelVerticalWidth == null) {
+ return false;
+ }
- // TODO find the number of labels
- int numHorizontalLabels = mNumHorizontalLabels;
+ double minX = mGraphView.getViewport().getMinX(false);
+ double maxX = mGraphView.getViewport().getMaxX(false);
+ if (minX == maxX) return false;
- double newMinX;
- double exactSteps;
+ // TODO find the number of labels
+ int numHorizontalLabels = mNumHorizontalLabels;
- // split range into equal steps
- exactSteps = (maxX - minX) / (numHorizontalLabels - 1);
+ double newMinX;
+ double exactSteps;
- // round because of floating error
- exactSteps = Math.round(exactSteps * 1000000d) / 1000000d;
+ // split range into equal steps
+ exactSteps = (maxX - minX) / (numHorizontalLabels - 1);
- // smallest viewport
- if (exactSteps == 0d) {
- exactSteps = 0.0000001d;
- maxX = minX + exactSteps * (numHorizontalLabels - 1);
- }
+ // round because of floating error
+ exactSteps = Math.round(exactSteps * 1000000d) / 1000000d;
- // human rounding to have nice numbers (1, 2, 5, ...)
- if (isHumanRoundingX()) {
- exactSteps = humanRound(exactSteps, false);
- } else if (mStepsHorizontal != null && mStepsHorizontal.size() > 1) {
- // else choose other nice steps that previous
- // steps are included (divide to have more, or multiplicate to have less)
-
- double d1 = 0, d2 = 0;
- int i = 0;
- for (Double v : mStepsHorizontal.values()) {
- if (i == 0) {
- d1 = v;
- } else {
- d2 = v;
- break;
- }
- i++;
+ // smallest viewport
+ if (exactSteps == 0d) {
+ exactSteps = 0.0000001d;
+ maxX = minX + exactSteps * (numHorizontalLabels - 1);
+ }
+
+ // human rounding to have nice numbers (1, 2, 5, ...)
+ if (isHumanRoundingX()) {
+ exactSteps = humanRound(exactSteps, false);
+ } else if (mStepsHorizontal != null && mStepsHorizontal.size() > 1) {
+ // else choose other nice steps that previous
+ // steps are included (divide to have more, or multiplicate to have less)
+
+ double d1 = 0, d2 = 0;
+ int i = 0;
+ for (Double v : mStepsHorizontal.values()) {
+ if (i == 0) {
+ d1 = v;
+ } else {
+ d2 = v;
+ break;
+ }
+ i++;
+ }
+ double oldSteps = d2 - d1;
+ if (oldSteps > 0) {
+ double newSteps = Double.NaN;
+
+ if (oldSteps > exactSteps) {
+ newSteps = oldSteps / 2;
+ } else if (oldSteps < exactSteps) {
+ newSteps = oldSteps * 2;
}
- double oldSteps = d2 - d1;
- if (oldSteps > 0) {
- double newSteps = Double.NaN;
-
- if (oldSteps > exactSteps) {
- newSteps = oldSteps / 2;
- } else if (oldSteps < exactSteps) {
- newSteps = oldSteps * 2;
- }
- // only if there wont be more than numLabels
- // and newSteps will be better than oldSteps
- int numStepsOld = (int) ((maxX - minX) / oldSteps);
- int numStepsNew = (int) ((maxX - minX) / newSteps);
+ // only if there wont be more than numLabels
+ // and newSteps will be better than oldSteps
+ int numStepsOld = (int) ((maxX - minX) / oldSteps);
+ int numStepsNew = (int) ((maxX - minX) / newSteps);
- boolean shouldChange;
+ boolean shouldChange;
- // avoid switching between 2 steps
- if (numStepsOld <= numHorizontalLabels && numStepsNew <= numHorizontalLabels) {
- // both are possible
- // only the new if it hows more labels
- shouldChange = numStepsNew > numStepsOld;
- } else {
- shouldChange = true;
- }
+ // avoid switching between 2 steps
+ if (numStepsOld <= numHorizontalLabels && numStepsNew <= numHorizontalLabels) {
+ // both are possible
+ // only the new if it hows more labels
+ shouldChange = numStepsNew > numStepsOld;
+ } else {
+ shouldChange = true;
+ }
- if (newSteps != Double.NaN && shouldChange && numStepsNew <= numHorizontalLabels) {
- exactSteps = newSteps;
- } else {
- // try to stay to the old steps
- exactSteps = oldSteps;
- }
+ if (newSteps != Double.NaN && shouldChange && numStepsNew <= numHorizontalLabels) {
+ exactSteps = newSteps;
+ } else {
+ // try to stay to the old steps
+ exactSteps = oldSteps;
}
- } else {
- // first time
- LogUtil.debug("find","find");
}
+ } else {
+ // first time
+ LogUtil.debug("find", "find");
+ }
- // starting from 1st datapoint
- // goal is to start with the minX or 1 step before
- newMinX = mGraphView.getViewport().getReferenceX();
- // must be down-rounded
- double count = Math.floor((minX - newMinX) / exactSteps);
- newMinX = count * exactSteps + newMinX;
+ // starting from 1st datapoint
+ // goal is to start with the minX or 1 step before
+ newMinX = mGraphView.getViewport().getReferenceX();
+ // must be down-rounded
+ double count = Math.floor((minX - newMinX) / exactSteps);
+ newMinX = count * exactSteps + newMinX;
- // now we have our labels bounds
- if (changeBounds) {
- mGraphView.getViewport().setMinX(newMinX);
- mGraphView.getViewport().setMaxX(newMinX + (numHorizontalLabels - 1) * exactSteps);
- mGraphView.getViewport().mXAxisBoundsStatus = Viewport.AxisBoundsStatus.AUTO_ADJUSTED;
- }
+ // now we have our labels bounds
+ if (changeBounds) {
+ mGraphView.getViewport().setMinX(newMinX);
+ mGraphView.getViewport().setMaxX(newMinX + (numHorizontalLabels - 1) * exactSteps);
+ mGraphView.getViewport().mXAxisBoundsStatus = Viewport.AxisBoundsStatus.AUTO_ADJUSTED;
+ }
+
+ // it can happen that we need to add some more labels to fill the complete screen
+ numHorizontalLabels = (int) ((mGraphView.getViewport().mCurrentViewport.width() / exactSteps)) + 1;
+
+ if (mStepsHorizontal != null) {
+ mStepsHorizontal.clear();
+ } else {
+ mStepsHorizontal = new LinkedHashMap<>((int) numHorizontalLabels);
+ }
- // it can happen that we need to add some more labels to fill the complete screen
- numHorizontalLabels = (int) ((mGraphView.getViewport().mCurrentViewport.width() / exactSteps)) + 1;
+ int width = mGraphView.getGraphContentWidth();
+ // convert data-x to pixel-x in current viewport
+ double pixelPerData = width / mGraphView.getViewport().mCurrentViewport.width();
- if (mStepsHorizontal != null) {
- mStepsHorizontal.clear();
- } else {
- mStepsHorizontal = new LinkedHashMap<>((int) numHorizontalLabels);
+ for (int i = 0; i < numHorizontalLabels; i++) {
+ // dont draw if it is left of visible screen
+ if (newMinX + (i * exactSteps) < mGraphView.getViewport().mCurrentViewport.left) {
+ continue;
}
- int width = mGraphView.getGraphContentWidth();
- // convert data-x to pixel-x in current viewport
- double pixelPerData = width / mGraphView.getViewport().mCurrentViewport.width();
+ // where is the data point on the current screen
+ double dataPointPos = newMinX + (i * exactSteps);
+ double relativeToCurrentViewport = dataPointPos - mGraphView.getViewport().mCurrentViewport.left;
- for (int i = 0; i < numHorizontalLabels; i++) {
- // dont draw if it is left of visible screen
- if (newMinX + (i * exactSteps) < mGraphView.getViewport().mCurrentViewport.left) {
- continue;
- }
+ double pixelPos = relativeToCurrentViewport * pixelPerData;
+ mStepsHorizontal.put((int) pixelPos, dataPointPos);
+ }
- // where is the data point on the current screen
- double dataPointPos = newMinX + (i * exactSteps);
- double relativeToCurrentViewport = dataPointPos - mGraphView.getViewport().mCurrentViewport.left;
+ return true;
+ }
- double pixelPos = relativeToCurrentViewport * pixelPerData;
- mStepsHorizontal.put((int) pixelPos, dataPointPos);
- }
+ /**
+ * adjusts the grid and labels to match to the data
+ * this will automatically change the bounds to
+ * nice human-readable values, except the bounds
+ * are manual.
+ */
+ protected void adjustSteps() {
+ mIsAdjusted = adjustVertical(!Viewport.AxisBoundsStatus.FIX.equals(mGraphView.getViewport().mYAxisBoundsStatus));
+ mIsAdjusted &= adjustVerticalSecondScale();
+ mIsAdjusted &= adjustHorizontal(!Viewport.AxisBoundsStatus.FIX.equals(mGraphView.getViewport().mXAxisBoundsStatus));
+ }
- return true;
- }
+ /**
+ * calculates the vertical label size
+ *
+ * @param canvas canvas
+ */
+ protected void calcLabelVerticalSize(Canvas canvas) {
+ // test label with first and last label
+ String testLabel = mLabelFormatter.formatLabel(mGraphView.getViewport().getMaxY(false), false);
+ if (testLabel == null) testLabel = "";
+ LogUtil.error("calcLabelVerticalSize--1->", testLabel);
+ Rect textBounds = new Rect();
+ mPaintLabel.getTextBounds(testLabel);
+ mLabelVerticalWidth = textBounds.getWidth();
+ mLabelVerticalHeight = textBounds.getHeight();
+
+ testLabel = mLabelFormatter.formatLabel(mGraphView.getViewport().getMinY(false), false);
+ if (testLabel == null) testLabel = "";
+ LogUtil.error("calcLabelVerticalSize--2->", testLabel);
+ mPaintLabel.getTextBounds(testLabel);
+ mLabelVerticalWidth = Math.max(mLabelVerticalWidth, textBounds.getWidth());
+
+ // add some pixel to get a margin
+ mLabelVerticalWidth += 6;
+
+ // space between text and graph content
+ mLabelVerticalWidth += mStyles.labelsSpace;
+
+ // multiline
+ int lines = 1;
+ for (byte c : testLabel.getBytes()) {
+ if (c == '\n') lines++;
+ }
+ mLabelVerticalHeight *= lines;
+ }
- /**
- * adjusts the grid and labels to match to the data
- * this will automatically change the bounds to
- * nice human-readable values, except the bounds
- * are manual.
- */
- protected void adjustSteps () {
- mIsAdjusted = adjustVertical(!Viewport.AxisBoundsStatus.FIX.equals(mGraphView.getViewport().mYAxisBoundsStatus));
- mIsAdjusted &= adjustVerticalSecondScale();
- mIsAdjusted &= adjustHorizontal(!Viewport.AxisBoundsStatus.FIX.equals(mGraphView.getViewport().mXAxisBoundsStatus));
+ /**
+ * calculates the vertical second scale
+ * label size
+ *
+ * @param canvas canvas
+ */
+ protected void calcLabelVerticalSecondScaleSize(Canvas canvas) {
+ if (mGraphView.mSecondScale == null) {
+ mLabelVerticalSecondScaleWidth = 0;
+ mLabelVerticalSecondScaleHeight = 0;
+ return;
+ }
+
+ // test label
+ double testY = ((mGraphView.mSecondScale.getMaxY(false) - mGraphView.mSecondScale.getMinY(false)) * 0.783) + mGraphView.mSecondScale.getMinY(false);
+ String testLabel = mGraphView.mSecondScale.getLabelFormatter().formatLabel(testY, false);
+ Rect textBounds = new Rect();
+ mPaintLabel.getTextBounds(testLabel);
+ mLabelVerticalSecondScaleWidth = textBounds.getWidth();
+ mLabelVerticalSecondScaleHeight = textBounds.getHeight();
+
+ // multiline
+ int lines = 1;
+ for (byte c : testLabel.getBytes()) {
+ if (c == '\n') lines++;
+ }
+ mLabelVerticalSecondScaleHeight *= lines;
+ }
+
+ /**
+ * calculates the horizontal label size
+ *
+ * @param canvas canvas
+ */
+ protected void calcLabelHorizontalSize(Canvas canvas) {
+ // test label
+ double testX = ((mGraphView.getViewport().getMaxX(false) - mGraphView.getViewport().getMinX(false)) * 0.783) + mGraphView.getViewport().getMinX(false);
+ String testLabel = mLabelFormatter.formatLabel(testX, true);
+ if (testLabel == null) {
+ testLabel = "";
}
+ Rect textBounds = new Rect();
+ mPaintLabel.getTextBounds(testLabel);
+ mLabelHorizontalWidth = textBounds.getWidth();
- /**
- * calculates the vertical label size
- *
- * @param canvas canvas
- */
- protected void calcLabelVerticalSize (Canvas canvas){
- // test label with first and last label
- String testLabel = mLabelFormatter.formatLabel(mGraphView.getViewport().getMaxY(false), false);
- if (testLabel == null) testLabel = "";
- LogUtil.error("calcLabelVerticalSize--1->",testLabel);
- Rect textBounds = new Rect();
- mPaintLabel.getTextBounds(testLabel);
- mLabelVerticalWidth = textBounds.getWidth();
- mLabelVerticalHeight = textBounds.getHeight();
-
- testLabel = mLabelFormatter.formatLabel(mGraphView.getViewport().getMinY(false), false);
- if (testLabel == null) testLabel = "";
- LogUtil.error("calcLabelVerticalSize--2->",testLabel);
- mPaintLabel.getTextBounds(testLabel);
- mLabelVerticalWidth = Math.max(mLabelVerticalWidth, textBounds.getWidth());
-
- // add some pixel to get a margin
- mLabelVerticalWidth += 6;
-
- // space between text and graph content
- mLabelVerticalWidth += mStyles.labelsSpace;
+ if (!mLabelHorizontalHeightFixed) {
+ mLabelHorizontalHeight = textBounds.getHeight();
// multiline
int lines = 1;
for (byte c : testLabel.getBytes()) {
if (c == '\n') lines++;
}
- mLabelVerticalHeight *= lines;
- }
+ mLabelHorizontalHeight *= lines;
- /**
- * calculates the vertical second scale
- * label size
- *
- * @param canvas canvas
- */
- protected void calcLabelVerticalSecondScaleSize (Canvas canvas){
- if (mGraphView.mSecondScale == null) {
- mLabelVerticalSecondScaleWidth = 0;
- mLabelVerticalSecondScaleHeight = 0;
- return;
- }
+ mLabelHorizontalHeight = (int) Math.max(mLabelHorizontalHeight, mStyles.textSize);
+ }
- // test label
- double testY = ((mGraphView.mSecondScale.getMaxY(false) - mGraphView.mSecondScale.getMinY(false)) * 0.783) + mGraphView.mSecondScale.getMinY(false);
- String testLabel = mGraphView.mSecondScale.getLabelFormatter().formatLabel(testY, false);
- Rect textBounds = new Rect();
- mPaintLabel.getTextBounds(testLabel);
- mLabelVerticalSecondScaleWidth = textBounds.getWidth();
- mLabelVerticalSecondScaleHeight = textBounds.getHeight();
+ if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) {
+ int adjHorizontalHeightH = (int) Math.round(Math.abs(mLabelHorizontalHeight * Math.cos(Math.toRadians(mStyles.horizontalLabelsAngle))));
+ int adjHorizontalHeightW = (int) Math.round(Math.abs(mLabelHorizontalWidth * Math.sin(Math.toRadians(mStyles.horizontalLabelsAngle))));
+ int adjHorizontalWidthH = (int) Math.round(Math.abs(mLabelHorizontalHeight * Math.sin(Math.toRadians(mStyles.horizontalLabelsAngle))));
+ int adjHorizontalWidthW = (int) Math.round(Math.abs(mLabelHorizontalWidth * Math.cos(Math.toRadians(mStyles.horizontalLabelsAngle))));
- // multiline
- int lines = 1;
- for (byte c : testLabel.getBytes()) {
- if (c == '\n') lines++;
- }
- mLabelVerticalSecondScaleHeight *= lines;
+ mLabelHorizontalHeight = adjHorizontalHeightH + adjHorizontalHeightW;
+ mLabelHorizontalWidth = adjHorizontalWidthH + adjHorizontalWidthW;
}
- /**
- * calculates the horizontal label size
- *
- * @param canvas canvas
- */
- protected void calcLabelHorizontalSize (Canvas canvas){
- // test label
- double testX = ((mGraphView.getViewport().getMaxX(false) - mGraphView.getViewport().getMinX(false)) * 0.783) + mGraphView.getViewport().getMinX(false);
- String testLabel = mLabelFormatter.formatLabel(testX, true);
- if (testLabel == null) {
- testLabel = "";
- }
- Rect textBounds = new Rect();
- mPaintLabel.getTextBounds(testLabel);
- mLabelHorizontalWidth = textBounds.getWidth();
+ // space between text and graph content
+ mLabelHorizontalHeight += mStyles.labelsSpace;
+ }
- if (!mLabelHorizontalHeightFixed) {
- mLabelHorizontalHeight = textBounds.getHeight();
+ /**
+ * do the drawing of the grid
+ * and labels
+ *
+ * @param width str
+ * @param height str
+ * @param canvas canvas
+ */
+ public void draw(Canvas canvas, int width, int height) {
- // multiline
- int lines = 1;
- for (byte c : testLabel.getBytes()) {
- if (c == '\n') lines++;
- }
- mLabelHorizontalHeight *= lines;
+ boolean labelSizeChanged = false;
+ if (mLabelHorizontalWidth == null) {
+ calcLabelHorizontalSize(canvas);
+ labelSizeChanged = true;
+ }
+ if (mLabelVerticalWidth == null) {
+ calcLabelVerticalSize(canvas);
+ labelSizeChanged = true;
+ }
+ if (mLabelVerticalSecondScaleWidth == null) {
+ calcLabelVerticalSecondScaleSize(canvas);
+ labelSizeChanged = true;
+ }
+ if (labelSizeChanged) {
+ // redraw directly
+ mGraphView.drawGraphElements(canvas);
+ return;
+ }
- mLabelHorizontalHeight = (int) Math.max(mLabelHorizontalHeight, mStyles.textSize);
- }
-
- if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) {
- int adjHorizontalHeightH = (int) Math.round(Math.abs(mLabelHorizontalHeight * Math.cos(Math.toRadians(mStyles.horizontalLabelsAngle))));
- int adjHorizontalHeightW = (int) Math.round(Math.abs(mLabelHorizontalWidth * Math.sin(Math.toRadians(mStyles.horizontalLabelsAngle))));
- int adjHorizontalWidthH = (int) Math.round(Math.abs(mLabelHorizontalHeight * Math.sin(Math.toRadians(mStyles.horizontalLabelsAngle))));
- int adjHorizontalWidthW = (int) Math.round(Math.abs(mLabelHorizontalWidth * Math.cos(Math.toRadians(mStyles.horizontalLabelsAngle))));
-
- mLabelHorizontalHeight = adjHorizontalHeightH + adjHorizontalHeightW;
- mLabelHorizontalWidth = adjHorizontalWidthH + adjHorizontalWidthW;
- }
-
- // space between text and graph content
- mLabelHorizontalHeight += mStyles.labelsSpace;
+ if (!mIsAdjusted) {
+ adjustSteps();
}
- /**
- * do the drawing of the grid
- * and labels
- *
- * @param width str
- * @param height str
- * @param canvas canvas
- */
- public void draw (Canvas canvas,int width,int height){
-
- boolean labelSizeChanged = false;
- if (mLabelHorizontalWidth == null) {
- calcLabelHorizontalSize(canvas);
- labelSizeChanged = true;
- }
- if (mLabelVerticalWidth == null) {
- calcLabelVerticalSize(canvas);
- labelSizeChanged = true;
- }
- if (mLabelVerticalSecondScaleWidth == null) {
- calcLabelVerticalSecondScaleSize(canvas);
- labelSizeChanged = true;
- }
- if (labelSizeChanged) {
- // redraw directly
- mGraphView.drawGraphElements(canvas);
- return;
- }
-
- if (!mIsAdjusted) {
- adjustSteps();
- }
-
- if (mIsAdjusted) {
- //Y轴数据
- drawVerticalSteps(canvas);
- drawVerticalStepsSecondScale(canvas);
- //X轴数据
- drawHorizontalSteps(canvas,width,height);
- } else {
- // we can not draw anything
- return;
- }
+ if (mIsAdjusted) {
+ //Y轴数据
+ drawVerticalSteps(canvas);
+ drawVerticalStepsSecondScale(canvas);
+ //X轴数据
+ drawHorizontalSteps(canvas, width, height);
+ } else {
+ // we can not draw anything
+ return;
+ }
- drawHorizontalAxisTitle(canvas,width,height);
- drawVerticalAxisTitle(canvas,width,height);
+ drawHorizontalAxisTitle(canvas, width, height);
+ drawVerticalAxisTitle(canvas, width, height);
- // draw second scale axis title if it exists
- if (mGraphView.mSecondScale != null) {
- mGraphView.mSecondScale.drawVerticalAxisTitle(canvas,width,height);
- }
+ // draw second scale axis title if it exists
+ if (mGraphView.mSecondScale != null) {
+ mGraphView.mSecondScale.drawVerticalAxisTitle(canvas, width, height);
}
+ }
- /**
- * draws the horizontal axis title if
- * it is set
- *
- * @param canvas canvas
- * @param width str
- * @param height str
- */
- protected void drawHorizontalAxisTitle (Canvas canvas,int width,int height){
- if (mHorizontalAxisTitle != null && mHorizontalAxisTitle.length() > 0) {
- mPaintAxisTitle.setColor(new Color(getHorizontalAxisTitleColor()));
- mPaintAxisTitle.setTextSize((int) getHorizontalAxisTitleTextSize());
- float x = width / 2;
- float y = height - mStyles.padding;
- canvas.drawText(mPaintAxisTitle, mHorizontalAxisTitle, x, y);
- }
+ /**
+ * draws the horizontal axis title if
+ * it is set
+ *
+ * @param canvas canvas
+ * @param width str
+ * @param height str
+ */
+ protected void drawHorizontalAxisTitle(Canvas canvas, int width, int height) {
+ if (mHorizontalAxisTitle != null && mHorizontalAxisTitle.length() > 0) {
+ mPaintAxisTitle.setColor(new Color(getHorizontalAxisTitleColor()));
+ mPaintAxisTitle.setTextSize((int) getHorizontalAxisTitleTextSize());
+ float x = width / 2;
+ float y = height - mStyles.padding;
+ canvas.drawText(mPaintAxisTitle, mHorizontalAxisTitle, x, y);
}
+ }
- /**
- * draws the vertical axis title if
- * it is set
- *
- * @param canvas canvas
- * @param width str
- * @param height str
- */
- protected void drawVerticalAxisTitle (Canvas canvas,int width,int height){
- if (mVerticalAxisTitle != null && mVerticalAxisTitle.length() > 0) {
- mPaintAxisTitle.setColor(new Color(getVerticalAxisTitleColor()));
- mPaintAxisTitle.setTextSize((int) getVerticalAxisTitleTextSize());
- float x = getVerticalAxisTitleWidth();
- float y = height / 2;
- canvas.save();
- canvas.rotate(-90, x, y);
- canvas.drawText(mPaintAxisTitle, mVerticalAxisTitle, x, y);
- canvas.restore();
- }
+ /**
+ * draws the vertical axis title if
+ * it is set
+ *
+ * @param canvas canvas
+ * @param width str
+ * @param height str
+ */
+ protected void drawVerticalAxisTitle(Canvas canvas, int width, int height) {
+ if (mVerticalAxisTitle != null && mVerticalAxisTitle.length() > 0) {
+ mPaintAxisTitle.setColor(new Color(getVerticalAxisTitleColor()));
+ mPaintAxisTitle.setTextSize((int) getVerticalAxisTitleTextSize());
+ float x = getVerticalAxisTitleWidth();
+ float y = height / 2;
+ canvas.save();
+ canvas.rotate(-90, x, y);
+ canvas.drawText(mPaintAxisTitle, mVerticalAxisTitle, x, y);
+ canvas.restore();
}
+ }
- /**
- * ss
- *
- * @return the horizontal axis title height
- * or 0 if there is no title
- */
- public int getHorizontalAxisTitleHeight () {
- if (mHorizontalAxisTitle != null && mHorizontalAxisTitle.length() > 0) {
- return (int) getHorizontalAxisTitleTextSize();
- } else {
- return 0;
- }
+ /**
+ * ss
+ *
+ * @return the horizontal axis title height
+ * or 0 if there is no title
+ */
+ public int getHorizontalAxisTitleHeight() {
+ if (mHorizontalAxisTitle != null && mHorizontalAxisTitle.length() > 0) {
+ return (int) getHorizontalAxisTitleTextSize();
+ } else {
+ return 0;
}
+ }
- /**
- * ss
- *
- * @return the vertical axis title width
- * or 0 if there is no title
- */
- public int getVerticalAxisTitleWidth () {
- if (mVerticalAxisTitle != null && mVerticalAxisTitle.length() > 0) {
- return (int) getVerticalAxisTitleTextSize();
- } else {
- return 0;
- }
+ /**
+ * ss
+ *
+ * @return the vertical axis title width
+ * or 0 if there is no title
+ */
+ public int getVerticalAxisTitleWidth() {
+ if (mVerticalAxisTitle != null && mVerticalAxisTitle.length() > 0) {
+ return (int) getVerticalAxisTitleTextSize();
+ } else {
+ return 0;
}
+ }
- /**
- * draws the horizontal steps
- * vertical lines and horizontal labels
- * TODO 画X轴数据
- *
- * @param canvas canvas
- * @param height str
- * @param width str
- */
- protected void drawHorizontalSteps (Canvas canvas,int width,int height){
- // draw horizontal steps (vertical lines and horizontal labels)
- mPaintLabel.setColor(new Color(getHorizontalLabelsColor()));
- int i = 0;
- for (Map.Entry
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,6 +21,7 @@ import com.jjoe64.graphview.utils.Point;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
+import ohos.agp.utils.Rect;
import ohos.agp.utils.RectFloat;
@@ -153,7 +154,7 @@ public class LegendRenderer {
mPaint.setTextSize((int) mStyles.textSize);
- int shapeSize = (int) (mStyles.textSize*0.8d);
+ int shapeSize = (int) (mStyles.textSize * 0.8d);
List