diff --git a/build.gradle b/build.gradle index ef3f57778829a3a3db8f688a13cdf9f686af29cb..cba5c04c866009e88143fdaaa300b151dacf5d28 100644 --- a/build.gradle +++ b/build.gradle @@ -19,8 +19,8 @@ buildscript { jcenter() } dependencies { - classpath 'com.huawei.ohos:hap:2.4.2.5' - classpath 'com.huawei.ohos:decctest:1.0.0.6' + classpath 'com.huawei.ohos:hap:2.4.5.5' + classpath 'com.huawei.ohos:decctest:1.2.5.1' } } 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 230f61a300ab8ea750f2bffba67c07a27b24450d..31437ca9514c6cf307bcfa1b200a3e679dfd0717 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 @@ -4,12 +4,18 @@ import com.jjoe64.graphveiw.GraphView; import com.jjoe64.graphveiw.helper.GraphViewXML; import com.jjoe64.graphveiw.series.BarGraphSeries; import com.jjoe64.graphveiw.series.DataPoint; +import com.jjoe64.graphveiw.series.DataPointInterface; import com.jjoe64.graphveiw.series.LineGraphSeries; +import com.jjoe64.graphveiw.series.OnDataPointTapListener; +import com.jjoe64.graphveiw.series.PointsGraphSeries; +import com.jjoe64.graphveiw.series.Series; +import com.jjoe64.graphveiw.utils.LogUtil; import com.jjoe64.graphview_os.ResourceTable; import com.jjoe64.graphview_os.base.BaseAbilitySlice; import ohos.agp.components.Button; import ohos.agp.components.Component; import ohos.agp.utils.Color; +import ohos.agp.window.dialog.ToastDialog; public class MainAbilitySlice extends BaseAbilitySlice { @@ -35,50 +41,50 @@ public class MainAbilitySlice extends BaseAbilitySlice { componentById.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { - switch (mIndex) { - case 1: - LineGraphSeries series = new LineGraphSeries(new DataPoint[]{ - new DataPoint(0, 1), - new DataPoint(1, 5), - new DataPoint(2, 3), - new DataPoint(3, 2), - new DataPoint(4, 6), - new DataPoint(5, 4) - - }); - series.setTitle("测试2"); - series.setColor(Color.getIntColor("#DC143C")); - - graphViewXml.setCursorMode(true); - graphViewXml.addSeries(series); - break; - case 2: - BarGraphSeries mSeries = new BarGraphSeries(new DataPoint[]{ - new DataPoint(0, 1), - new DataPoint(1, 5), - new DataPoint(2, 3), - new DataPoint(3, 2) - }); - mSeries.setTitle("测试3"); - mSeries.setColor(Color.getIntColor("#00CED1")); - graphViewXml.addSeries(mSeries); - break; - case 3: - BarGraphSeries mSeriesFo = new BarGraphSeries(new DataPoint[]{ - new DataPoint(0, 1), - new DataPoint(1, 5), - new DataPoint(2, 3), - new DataPoint(3, 2) - }); - mSeriesFo.setTitle("测试3"); - mSeriesFo.setColor(Color.getIntColor("#00CED1")); - graphView.getLegendRenderer().setVisible(true); - graphView.setTitle("疫情统计"); - graphView.addSeries(mSeriesFo); - } - - mIndex += 1; - +// switch (mIndex) { +// case 1: +// LineGraphSeries series = new LineGraphSeries(new DataPoint[]{ +// new DataPoint(0, 1), +// new DataPoint(1, 5), +// new DataPoint(2, 3), +// new DataPoint(3, 2), +// new DataPoint(4, 6), +// new DataPoint(5, 4) +// +// }); +// series.setTitle("测试2"); +// series.setColor(Color.getIntColor("#DC143C")); +// +// graphViewXml.setCursorMode(true); +// graphViewXml.addSeries(series); +// break; +// case 2: +// BarGraphSeries mSeries = new BarGraphSeries(new DataPoint[]{ +// new DataPoint(0, 1), +// new DataPoint(1, 5), +// new DataPoint(2, 3), +// new DataPoint(3, 2) +// }); +// mSeries.setTitle("测试3"); +// mSeries.setColor(Color.getIntColor("#00CED1")); +// graphViewXml.addSeries(mSeries); +// break; +// case 3: +// BarGraphSeries mSeriesFo = new BarGraphSeries(new DataPoint[]{ +// new DataPoint(0, 1), +// new DataPoint(1, 5), +// new DataPoint(2, 3), +// new DataPoint(3, 2) +// }); +// mSeriesFo.setTitle("测试3"); +// mSeriesFo.setColor(Color.getIntColor("#00CED1")); +// graphView.getLegendRenderer().setVisible(true); +// graphView.setTitle("疫情统计"); +// graphView.addSeries(mSeriesFo); +// } +// +// mIndex += 1; + test7(); } }); @@ -88,4 +94,113 @@ public class MainAbilitySlice extends BaseAbilitySlice { protected void initData() { } + + private void test1(){ + BarGraphSeries series = new BarGraphSeries<>(new DataPoint[]{ + new DataPoint(0, 520.5), + new DataPoint(492.9, 525), + new DataPoint(521, 523), + new DataPoint(673.8, 672), + new DataPoint(784, 896) + }); + graphView.addSeries(series); + } + + private void test2() { + BarGraphSeries barGraphSeries = 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(barGraphSeries); + graphView.getViewport().setBackgroundColor(Color.RED.getValue()); + } + + private void test3() { + BarGraphSeries barGraphSeries = 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(barGraphSeries); + graphView.getViewport().setDrawBorder(true); + graphView.getViewport().setBorderColor(Color.RED.getValue()); + } + + private void test4() { + LineGraphSeries series2 = new LineGraphSeries<>(new DataPoint[]{ + new DataPoint(0, -1), + new DataPoint(1, 1), + new DataPoint(2, 2), + new DataPoint(3, 1), + new DataPoint(4, 4) + }); + graphView.setTitle("哈哈"); + graphView.setTitleTextSize(100); + graphView.addSeries(series2); + series2.setOnDataPointTapListener(new OnDataPointTapListener() { + @Override + public void onTap(Series series, DataPointInterface dataPoint) { + ToastDialog td = new ToastDialog(graphView.getContext()); + td.setText("Series1: On Data Point clicked: +dataPoint"); + td.show(); + + LogUtil.error("字体大小--->", graphView.getTitleTextSize() + ""); + } + }); + + } + + private void test5() { + 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().setLabelsSpace(104); + } + + private void test6() { + BarGraphSeries series = new BarGraphSeries<>(new DataPoint[]{ + new DataPoint(0, 520.5), + new DataPoint(492.9, 525), + new DataPoint(521, 523), + new DataPoint(673.8, 672), + new DataPoint(784, 896) + }); + graphView.addSeries(series); + series.setDrawValuesOnTop(true); + series.setValuesOnTopColor(Color.RED.getValue()); + graphView.setTitle("Sai Graph"); + graphView.setTitleTextSize(-1); + + } + + private void test7(){ + LineGraphSeries seriesNew2 = new LineGraphSeries<>(new DataPoint[]{ + new DataPoint(3, 20), + new DataPoint(4, 50) + }); + PointsGraphSeries seriesNew = new PointsGraphSeries<>(new DataPoint[]{ + new DataPoint(0, 90), + new DataPoint(1, 30), + new DataPoint(2, 60), + new DataPoint(3, 40), + new DataPoint(4, 80) + }); + graphView.getSecondScale().setMinY(20); + graphView.getSecondScale().setMaxY(100); + graphView.getSecondScale().addSeries(seriesNew); + graphView.getSecondScale().addSeries(seriesNew2); + graphView.getSecondScale().setVerticalAxisTitleColor(Color.BLACK.getValue()); + graphView.getSecondScale().setVerticalAxisTitle("Sai SecondScale"); + graphView.getSecondScale().setVerticalAxisTitleTextSize(-1); + } } diff --git a/entry/src/main/resources/base/layout/ability_main.xml b/entry/src/main/resources/base/layout/ability_main.xml index 31fa733549a0d94916ef0e5423b16602b2875814..7de48d46e88cee7f68381412d99ea3468ba775d5 100644 --- a/entry/src/main/resources/base/layout/ability_main.xml +++ b/entry/src/main/resources/base/layout/ability_main.xml @@ -26,5 +26,6 @@ ohos:seriesType="points" ohos:seriesTitle="测试1" ohos:seriesColor="#1E90FF" + ohos:title ="666" /> \ No newline at end of file diff --git a/graphveiw/src/main/java/com/jjoe64/graphveiw/GraphView.java b/graphveiw/src/main/java/com/jjoe64/graphveiw/GraphView.java index 8a47c4e60ed7710e71c7471fe1b7370433a3dac3..f7d498fd3b4caa1ae2c39717d7cff00ceca03994 100644 --- a/graphveiw/src/main/java/com/jjoe64/graphveiw/GraphView.java +++ b/graphveiw/src/main/java/com/jjoe64/graphveiw/GraphView.java @@ -37,7 +37,8 @@ import java.util.List; */ public class GraphView extends Component implements Component.DrawTask, Component.TouchEventListener { - public static String TAG="GraphView : "; + public static String TAG = "GraphView : "; + @Override public void onDraw(Component component, Canvas canvas) { @@ -118,18 +119,18 @@ public class GraphView extends Component implements Component.DrawTask, Componen if (event.getAction() == TouchEvent.PRIMARY_POINT_DOWN) { lastDown = System.currentTimeMillis(); lastPoint = new PointF(event.getPointerPosition(0).getX(), event.getPointerPosition(0).getY()); - LogUtil.info(TAG,event.getPointerPosition(0).getX()+"/PRIMARY_POINT_DOWN/"+event.getPointerPosition(0).getY()); + LogUtil.info(TAG, event.getPointerPosition(0).getX() + "/PRIMARY_POINT_DOWN/" + event.getPointerPosition(0).getY()); } else if (lastDown > 0 && event.getAction() == TouchEvent.POINT_MOVE) { if (Math.abs(event.getPointerPosition(0).getX() - lastPoint.x) > 60 || Math.abs(event.getPointerPosition(0).getY() - lastPoint.y) > 60) { lastDown = 0; } - LogUtil.info(TAG,event.getPointerPosition(0).getX()+"/POINT_MOVE/"+event.getPointerPosition(0).getY()); + LogUtil.info(TAG, event.getPointerPosition(0).getX() + "/POINT_MOVE/" + event.getPointerPosition(0).getY()); } else if (event.getAction() == TouchEvent.PRIMARY_POINT_UP) { if (System.currentTimeMillis() - lastDown < 400) { return true; } - LogUtil.info(TAG,event.getPointerPosition(0).getX()+"/PRIMARY_POINT_UP/"+event.getPointerPosition(0).getY()); + LogUtil.info(TAG, event.getPointerPosition(0).getX() + "/PRIMARY_POINT_UP/" + event.getPointerPosition(0).getY()); } return false; } @@ -356,7 +357,7 @@ public class GraphView extends Component implements Component.DrawTask, Componen protected void drawTitle(Canvas canvas) { if (mTitle != null && mTitle.length() > 0) { mPaintTitle.setColor(new Color(mStyles.titleColor)); - mPaintTitle.setTextSize((int) mStyles.titleTextSize); + mPaintTitle.setTextSize((int) (mStyles.titleTextSize >= 0 ? mStyles.titleTextSize : 20)); mPaintTitle.setTextAlign(1); float x = getWidth() / 2; float y = mPaintTitle.getTextSize(); @@ -404,7 +405,7 @@ public class GraphView extends Component implements Component.DrawTask, Componen */ public int getGraphContentLeft() { int border = getGridLabelRenderer().getStyles().padding; - return border + getGridLabelRenderer().getLabelVerticalWidth() + getGridLabelRenderer().getVerticalAxisTitleWidth()+20; + return border + getGridLabelRenderer().getLabelVerticalWidth() + getGridLabelRenderer().getVerticalAxisTitleWidth() + 20; } /** @@ -443,7 +444,7 @@ public class GraphView extends Component implements Component.DrawTask, Componen graphwidth -= getGridLabelRenderer().getLabelVerticalSecondScaleWidth(); graphwidth -= mSecondScale.getVerticalAxisTitleTextSize(); } - return graphwidth-40; + return graphwidth - 40; } /** diff --git a/graphveiw/src/main/java/com/jjoe64/graphveiw/GridLabelRenderer.java b/graphveiw/src/main/java/com/jjoe64/graphveiw/GridLabelRenderer.java index 0cb49ed79d455d52bb4006b5a97ee533d1211e6c..9b0731e796d603730270dd82ecc5da8606351970 100644 --- a/graphveiw/src/main/java/com/jjoe64/graphveiw/GridLabelRenderer.java +++ b/graphveiw/src/main/java/com/jjoe64/graphveiw/GridLabelRenderer.java @@ -415,8 +415,7 @@ public class GridLabelRenderer { mPaintLine.setStrokeWidth(0); mPaintLabel = new Paint(); -// mPaintLabel.setTextSize((int) getTextSize()); - mPaintLabel.setTextSize(20); + mPaintLabel.setTextSize((int) getTextSize()); mPaintLabel.setAntiAlias(true); mPaintAxisTitle = new Paint(); diff --git a/graphveiw/src/main/java/com/jjoe64/graphveiw/SecondScale.java b/graphveiw/src/main/java/com/jjoe64/graphveiw/SecondScale.java index 1189ac682397c4a52a6570c8e2e6e432a93a6a9a..f7254f0fbef639c69f7e46440e6973f84c8dd15d 100644 --- a/graphveiw/src/main/java/com/jjoe64/graphveiw/SecondScale.java +++ b/graphveiw/src/main/java/com/jjoe64/graphveiw/SecondScale.java @@ -220,7 +220,7 @@ public class SecondScale { * caches the complete range (minX, maxX, minY, maxY) * by iterating all series and all datapoints and * stores it into #mCompleteRange - * + *

* for the x-range it will respect the series on the * second scale - not for y-values */ @@ -305,7 +305,12 @@ public class SecondScale { * @param verticalAxisTitleTextSize font size of the vertical axis title */ public void setVerticalAxisTitleTextSize(float verticalAxisTitleTextSize) { - mVerticalAxisTitleTextSize = verticalAxisTitleTextSize; + if (verticalAxisTitleTextSize >= 0) { + mVerticalAxisTitleTextSize = verticalAxisTitleTextSize; + } else { + mVerticalAxisTitleTextSize = 20; + } + } /** @@ -332,7 +337,7 @@ public class SecondScale { * * @param canvas canvas * @param height str - * @param width str + * @param width str */ protected void drawVerticalAxisTitle(Canvas canvas, int width, int height) { if (mVerticalAxisTitle != null && mVerticalAxisTitle.length() > 0) { diff --git a/graphveiw/src/main/java/com/jjoe64/graphveiw/Viewport.java b/graphveiw/src/main/java/com/jjoe64/graphveiw/Viewport.java index 4a039e87cc22e99c65c29ff7f275dc00a3a39987..e1f1fda52d3b99f71c8581ad242f0a10c6b43d04 100644 --- a/graphveiw/src/main/java/com/jjoe64/graphveiw/Viewport.java +++ b/graphveiw/src/main/java/com/jjoe64/graphveiw/Viewport.java @@ -100,8 +100,8 @@ public class Viewport { * Called after scaling or scrolling with * the new bounds * - * @param minX min x value - * @param maxX max x value + * @param minX min x value + * @param maxX max x value * @param reason str */ void onXAxisBoundsChanged(double minX, double maxX, Reason reason); @@ -319,7 +319,7 @@ public class Viewport { * @return true if it was consumed */ public boolean onTouchEvent(TouchEvent event) { - boolean b =false; + boolean b = false; // b |= mGestureDetector.onTouchEvent(event); if (mGraphView.isCursorMode()) { if (event.getAction() == TouchEvent.PRIMARY_POINT_DOWN) { @@ -724,9 +724,9 @@ public class Viewport { if (mBackgroundColor != Color.TRANSPARENT.getValue()) { mPaint.setColor(new Color(mBackgroundColor)); - + //TODO c.drawRect( - new RectFloat(mGraphView.getGraphContentLeft(), + new RectFloat(mGraphView.getGraphContentLeft() + 8, mGraphView.getGraphContentTop(), mGraphView.getGraphContentLeft() + mGraphView.getGraphContentWidth(), mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight()), @@ -739,15 +739,16 @@ public class Viewport { p = mBorderPaint; } else { p = mPaint; + p.setStrokeWidth(0); p.setColor(new Color(getBorderColor())); } - c.drawLine( - new Point(mGraphView.getGraphContentLeft(), - mGraphView.getGraphContentTop()), - new Point(mGraphView.getGraphContentLeft(), - mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight()), - p - ); +// c.drawLine( +// new Point(mGraphView.getGraphContentLeft(), +// mGraphView.getGraphContentTop()), +// new Point(mGraphView.getGraphContentLeft(), +// mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight()), +// p +// ); c.drawLine( new Point(mGraphView.getGraphContentLeft(), mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight()), diff --git a/graphveiw/src/main/java/com/jjoe64/graphveiw/helper/GraphViewXML.java b/graphveiw/src/main/java/com/jjoe64/graphveiw/helper/GraphViewXML.java index 451facdb7c0c48313fa091d2eb634dcc8ed7647d..08d0a646598830f005b5b5f3809b1a0c9155a7d4 100644 --- a/graphveiw/src/main/java/com/jjoe64/graphveiw/helper/GraphViewXML.java +++ b/graphveiw/src/main/java/com/jjoe64/graphveiw/helper/GraphViewXML.java @@ -72,6 +72,7 @@ public class GraphViewXML extends GraphView { + dataStr = attrs.getAttr(GRAPH_VIEW_SERIES_DATA).isPresent() ? attrs.getAttr(GRAPH_VIEW_SERIES_DATA).get().getStringValue() : dataStr; type = attrs.getAttr(GRAPH_VIEW_SERIES_TYPE).isPresent() ? attrs.getAttr(GRAPH_VIEW_SERIES_TYPE).get().getStringValue() : type; color = attrs.getAttr(GRAPH_VIEW_SERIES_COLOR).isPresent() ? attrs.getAttr(GRAPH_VIEW_SERIES_COLOR).get().getColorValue() : color; seriesTitle = attrs.getAttr(GRAPH_VIEW_SERIES_TITLE).isPresent() ? attrs.getAttr(GRAPH_VIEW_SERIES_TITLE).get().getStringValue() : seriesTitle; diff --git a/graphveiw/src/main/java/com/jjoe64/graphveiw/series/BarGraphSeries.java b/graphveiw/src/main/java/com/jjoe64/graphveiw/series/BarGraphSeries.java index 529b8d7dabcf139a4332cd4b0265c3d77a2c92b8..63be30ed1b2fea738df3c992bb27b514566a2a66 100644 --- a/graphveiw/src/main/java/com/jjoe64/graphveiw/series/BarGraphSeries.java +++ b/graphveiw/src/main/java/com/jjoe64/graphveiw/series/BarGraphSeries.java @@ -1,13 +1,13 @@ /** * GraphView * Copyright 2016 Jonas Gehring - * + *

* 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. @@ -133,8 +133,8 @@ public class BarGraphSeries extends BaseSeries /** * creates bar series with data * - * @param data data points - * important: array has to be sorted from lowest x-value to the highest + * @param data data points + * important: array has to be sorted from lowest x-value to the highest */ public BarGraphSeries(E[] data) { super(data); @@ -147,8 +147,8 @@ public class BarGraphSeries extends BaseSeries /** * draws the bars on the canvas * - * @param graphView corresponding graphview - * @param canvas canvas + * @param graphView corresponding graphview + * @param canvas canvas * @param isSecondScale whether we are plotting the second scale or not */ @Override @@ -157,10 +157,10 @@ public class BarGraphSeries extends BaseSeries if (mValuesOnTopSize == 0) { mValuesOnTopSize = graphView.getGridLabelRenderer().getTextSize(); } - mPaint.setTextSize((int) mValuesOnTopSize); + mPaint.setTextSize((int) (mValuesOnTopSize >= 0 ? mValuesOnTopSize : 0)); resetDataPoints(); - + // get data double maxX = graphView.getViewport().getMaxX(false); double minX = graphView.getViewport().getMinX(false); @@ -183,10 +183,10 @@ public class BarGraphSeries extends BaseSeries int numValues = 0; boolean isCurrentSeries; SortedSet xVals = new TreeSet(); - for(Series inspectedSeries: graphView.getSeries()) { - if(inspectedSeries instanceof BarGraphSeries) { + for (Series inspectedSeries : graphView.getSeries()) { + if (inspectedSeries instanceof BarGraphSeries) { isCurrentSeries = (inspectedSeries == this); - if(isCurrentSeries) { + if (isCurrentSeries) { currentSeriesOrder = numBarSeries; } numBarSeries++; @@ -199,10 +199,14 @@ public class BarGraphSeries extends BaseSeries Iterator curValues = inspectedSeries.getValues(minX, maxX); if (curValues.hasNext()) { xVals.add(curValues.next().getX()); - if(isCurrentSeries) { numValues++; } + if (isCurrentSeries) { + numValues++; + } while (curValues.hasNext()) { xVals.add(curValues.next().getX()); - if(isCurrentSeries) { numValues++; } + if (isCurrentSeries) { + numValues++; + } } } } @@ -213,13 +217,13 @@ public class BarGraphSeries extends BaseSeries double minGap = 0; - if(mDataWidth > 0.0) { + if (mDataWidth > 0.0) { minGap = mDataWidth; } else { Double lastVal = null; - for(Double curVal: xVals) { - if(lastVal != null) { + for (Double curVal : xVals) { + if (lastVal != null) { double curGap = Math.abs(curVal - lastVal); if (minGap == 0 || (curGap > 0 && curGap < minGap)) { minGap = curGap; @@ -229,22 +233,22 @@ public class BarGraphSeries extends BaseSeries } } - int numBarSlots = (minGap == 0) ? 1 : (int)Math.round((maxX - minX)/minGap) + 1; + int numBarSlots = (minGap == 0) ? 1 : (int) Math.round((maxX - minX) / minGap) + 1; Iterator values = getValues(minX, maxX); // Calculate the overall bar slot width - this includes all bars across // all series, and any spacing between sets of bars int barSlotWidth = numBarSlots == 1 - ? graphView.getGraphContentWidth() - : graphView.getGraphContentWidth() / (numBarSlots-1); + ? graphView.getGraphContentWidth() + : graphView.getGraphContentWidth() / (numBarSlots - 1); // Total spacing (both sides) between sets of bars - double spacing = Math.min(barSlotWidth*mSpacing/100, barSlotWidth*0.98f); + double spacing = Math.min(barSlotWidth * (mSpacing >= 0 ? mSpacing : 0) / 100, barSlotWidth * 0.98f); // Width of an individual bar double barWidth = (barSlotWidth - spacing) / numBarSeries; // Offset from the center of a given bar to start drawing - double offset = barSlotWidth/2; + double offset = barSlotWidth / 2; double diffY = maxY - minY; double diffX = maxX - minX; @@ -254,7 +258,7 @@ public class BarGraphSeries extends BaseSeries double contentTop = graphView.getGraphContentTop(); // draw data - int i=0; + int i = 0; while (values.hasNext()) { E value = values.next(); @@ -278,13 +282,13 @@ public class BarGraphSeries extends BaseSeries mPaint.setColor(new Color(getColor())); } - double left = x + contentLeft - offset + spacing/2 + currentSeriesOrder*barWidth; + double left = x + contentLeft - offset + spacing / 2 + currentSeriesOrder * barWidth; double right = left + barWidth; if (left > contentLeft + contentWidth || right < contentLeft) { continue; } double top = (contentTop - y) + contentHeight; - double bottom = (contentTop - y0) + contentHeight - (graphView.getGridLabelRenderer().isHighlightZeroLines()?4:1); + double bottom = (contentTop - y0) + contentHeight - (graphView.getGridLabelRenderer().isHighlightZeroLines() ? 4 : 1); boolean reverse = top > bottom; @@ -303,16 +307,16 @@ public class BarGraphSeries extends BaseSeries mAnimationStartFrameNo++; } } - float timeFactor = (float) (currentTime-mAnimationStart) / ANIMATION_DURATION; + float timeFactor = (float) (currentTime - mAnimationStart) / ANIMATION_DURATION; - //TODO API 缺失 + //TODO API 缺失 // float factor = mAnimationInterpolator.getInterpolation(timeFactor); if (timeFactor <= 1.0) { double barHeight = bottom - top; //TODO API 缺失 // barHeight = barHeight * factor; - top = bottom-barHeight; + top = bottom - barHeight; // ViewCompat.postInvalidateOnAnimation(graphView); graphView.invalidate(); @@ -325,14 +329,14 @@ public class BarGraphSeries extends BaseSeries if (reverse) { double tmp = top; - top = bottom + (graphView.getGridLabelRenderer().isHighlightZeroLines()?4:1); + top = bottom + (graphView.getGridLabelRenderer().isHighlightZeroLines() ? 4 : 1); bottom = tmp; } // overdraw left = Math.max(left, contentLeft); - right = Math.min(right, contentLeft+contentWidth); - bottom = Math.min(bottom, contentTop+contentHeight); + right = Math.min(right, contentLeft + contentWidth); + bottom = Math.min(bottom, contentTop + contentHeight); top = Math.max(top, contentTop); mDataPoints.put(new RectD(left, top, right, bottom), value); @@ -345,21 +349,21 @@ public class BarGraphSeries extends BaseSeries } - canvas.drawRect( new RectFloat((float)left,(float)top,(float)right,(float)bottom), p); + canvas.drawRect(new RectFloat((float) left, (float) top, (float) right, (float) bottom), p); // set values on top of graph if (mDrawValuesOnTop) { if (reverse) { - top = bottom + mValuesOnTopSize + 4; - if (top > contentTop+contentHeight) top = contentTop + contentHeight; + top = bottom + (mValuesOnTopSize >= 0 ? mValuesOnTopSize : 0) + 4; + if (top > contentTop + contentHeight) top = contentTop + contentHeight; } else { top -= 4; - if (top<=contentTop) top+=contentTop+4; + if (top <= contentTop) top += contentTop + 4; } mPaint.setColor(new Color(mValuesOnTopColor)); - canvas.drawText(mPaint,graphView.getGridLabelRenderer().getLabelFormatter().formatLabel(value.getY(), false),(float) (left+right)/2, (float) top); + canvas.drawText(mPaint, graphView.getGridLabelRenderer().getLabelFormatter().formatLabel(value.getY(), false), (float) (left + right) / 2, (float) top); } i++; @@ -379,8 +383,8 @@ public class BarGraphSeries extends BaseSeries * set a hook to make the color of the bars depending * on the actually value/data. * - * @param mValueDependentColor hook - * null to disable + * @param mValueDependentColor hook + * null to disable */ public void setValueDependentColor(ValueDependentColor mValueDependentColor) { this.mValueDependentColor = mValueDependentColor; @@ -398,9 +402,9 @@ public class BarGraphSeries extends BaseSeries /** * ss * - * @param mSpacing spacing between the bars in percentage. - * 0 => no spacing - * 100 => the space between the bars is as big as the bars itself + * @param mSpacing spacing between the bars in percentage. + * 0 => no spacing + * 100 => the space between the bars is as big as the bars itself */ public void setSpacing(int mSpacing) { this.mSpacing = mSpacing; @@ -418,9 +422,9 @@ public class BarGraphSeries extends BaseSeries /** * ss * - * @param mDataWidth width of a data point (sampling period) - * 0 => no prior knowledge of sampling period, interval between bars will be calculated automatically - * >0 => value is the total distance from one bar to another + * @param mDataWidth width of a data point (sampling period) + * 0 => no prior knowledge of sampling period, interval between bars will be calculated automatically + * >0 => value is the total distance from one bar to another */ public void setDataWidth(double mDataWidth) { this.mDataWidth = mDataWidth; @@ -438,8 +442,8 @@ public class BarGraphSeries extends BaseSeries /** * ss * - * @param mDrawValuesOnTop flag whether the values should drawn - * above the bars as text + * @param mDrawValuesOnTop flag whether the values should drawn + * above the bars as text */ public void setDrawValuesOnTop(boolean mDrawValuesOnTop) { this.mDrawValuesOnTop = mDrawValuesOnTop; @@ -505,7 +509,7 @@ public class BarGraphSeries extends BaseSeries protected E findDataPoint(float x, float y) { for (Map.Entry entry : mDataPoints.entrySet()) { if (x >= entry.getKey().left && x <= entry.getKey().right - && y >= entry.getKey().top && y <= entry.getKey().bottom) { + && y >= entry.getKey().top && y <= entry.getKey().bottom) { return entry.getValue(); } } diff --git a/graphveiw/src/main/java/com/jjoe64/graphveiw/utils/AttrSetString.java b/graphveiw/src/main/java/com/jjoe64/graphveiw/utils/AttrSetString.java index d8a318c11425363cefb7f5e140b78fe67ea97493..914fb1618e8501ee5ff3af4cdc685321efcafd2a 100644 --- a/graphveiw/src/main/java/com/jjoe64/graphveiw/utils/AttrSetString.java +++ b/graphveiw/src/main/java/com/jjoe64/graphveiw/utils/AttrSetString.java @@ -37,5 +37,5 @@ public class AttrSetString { public static String GRAPH_VIEW_SERIES_TYPE="seriesType"; public static String GRAPH_VIEW_SERIES_COLOR="seriesColor"; public static String GRAPH_VIEW_SERIES_TITLE="seriesTitle"; - public static String GRAPH_VIEW_TITLE="mTitle"; + public static String GRAPH_VIEW_TITLE="title"; }