use of org.eazegraph.lib.models.ValueLinePoint in project EazeGraph by blackfizz.
the class ValueLineChart method calculateLegendBounds.
private boolean calculateLegendBounds() {
int index = 0;
int size = mSeries.get(0).getSeries().size();
// Only calculate if more than one point is available
if (size > 1) {
for (ValueLinePoint valueLinePoint : mSeries.get(0).getSeries()) {
if (!(index == 0 || index == size - 1)) {
valueLinePoint.setLegendBounds(new RectF(valueLinePoint.getCoordinates().getX() - mSeries.get(0).getWidthOffset() / 2, 0, valueLinePoint.getCoordinates().getX() + mSeries.get(0).getWidthOffset() / 2, mLegendHeight));
} else {
valueLinePoint.setIgnore(true);
}
index++;
}
return true;
} else {
return false;
}
}
use of org.eazegraph.lib.models.ValueLinePoint in project EazeGraph by blackfizz.
the class ValueLineChart method recalculateXCoordinates.
private void recalculateXCoordinates(float _GraphWidth) {
int seriesPointCount = mSeries.get(0).getSeries().size();
float widthOffset = _GraphWidth / (float) seriesPointCount;
widthOffset += widthOffset / seriesPointCount;
float currentOffset = 0;
for (ValueLinePoint point : mSeries.get(0).getSeries()) {
point.getCoordinates().setX(currentOffset);
currentOffset += widthOffset;
}
}
use of org.eazegraph.lib.models.ValueLinePoint in project EazeGraph by blackfizz.
the class ValueLineChart method onDataChanged.
/**
* Should be called after new data is inserted. Will be automatically called, when the view dimensions
* changed.
*
* Calculates various offsets and positions for different overlay features based on the graph settings.
* After the calculation the Path is generated as a normal path or cubic path (Based on 'egUseCubic' attribute).
*/
@Override
protected void onDataChanged() {
if (!mSeries.isEmpty()) {
int seriesCount = mSeries.size();
float maxValue = 0.f;
float minValue = Float.MAX_VALUE;
mNegativeValue = 0.f;
mNegativeOffset = 0.f;
mHasNegativeValues = false;
// calculate the maximum and minimum value present in data
for (ValueLineSeries series : mSeries) {
for (ValueLinePoint point : series.getSeries()) {
if (point.getValue() > maxValue)
maxValue = point.getValue();
if (point.getValue() < mNegativeValue)
mNegativeValue = point.getValue();
if (point.getValue() < minValue)
minValue = point.getValue();
}
}
// check if the standardvalue is greater than all other values
if (mShowStandardValues) {
for (StandardValue value : mStandardValues) {
if (value.getValue() > maxValue)
maxValue = value.getValue();
if (value.getValue() < mNegativeValue)
mNegativeValue = value.getValue();
if (value.getValue() < minValue)
minValue = value.getValue();
}
}
if (!mUseDynamicScaling) {
minValue = 0;
} else {
minValue *= mScalingFactor;
}
// check if values below zero were found
if (mNegativeValue < 0) {
mHasNegativeValues = true;
maxValue += (mNegativeValue * -1);
minValue = 0;
}
float heightMultiplier = mUsableGraphHeight / (maxValue - minValue);
// calculate the offset
if (mHasNegativeValues) {
mNegativeOffset = (mNegativeValue * -1) * heightMultiplier;
}
// calculate the y position for standardValue
if (mShowStandardValues) {
for (StandardValue value : mStandardValues) {
value.setY((int) (mGraphHeight - mNegativeOffset - ((value.getValue() - minValue) * heightMultiplier)));
}
}
for (ValueLineSeries series : mSeries) {
int seriesPointCount = series.getSeries().size();
// check if more than one point is available
if (seriesPointCount <= 1) {
Log.w(LOG_TAG, "More than one point should be available!");
} else {
float widthOffset = (float) mGraphWidth / (float) seriesPointCount;
widthOffset += widthOffset / seriesPointCount;
float currentOffset = 0;
series.setWidthOffset(widthOffset);
// used to store first point and set it later as ending point, if a graph fill is selected
float firstX = currentOffset;
float firstY = mGraphHeight - ((series.getSeries().get(0).getValue() - minValue) * heightMultiplier);
Path path = new Path();
path.moveTo(firstX, firstY);
series.getSeries().get(0).setCoordinates(new Point2D(firstX, firstY));
// If not then just draw basic lines
if (mUseCubic) {
Point2D P1 = new Point2D();
Point2D P2 = new Point2D();
Point2D P3 = new Point2D();
for (int i = 0; i < seriesPointCount - 1; i++) {
int i3 = (seriesPointCount - i) < 3 ? i + 1 : i + 2;
float offset2 = (seriesPointCount - i) < 3 ? mGraphWidth : currentOffset + widthOffset;
float offset3 = (seriesPointCount - i) < 3 ? mGraphWidth : currentOffset + (2 * widthOffset);
P1.setX(currentOffset);
P1.setY(mGraphHeight - ((series.getSeries().get(i).getValue() - minValue) * heightMultiplier));
P2.setX(offset2);
P2.setY(mGraphHeight - ((series.getSeries().get(i + 1).getValue() - minValue) * heightMultiplier));
Utils.calculatePointDiff(P1, P2, P1, mSecondMultiplier);
P3.setX(offset3);
P3.setY(mGraphHeight - ((series.getSeries().get(i3).getValue() - minValue) * heightMultiplier));
Utils.calculatePointDiff(P2, P3, P3, mFirstMultiplier);
currentOffset += widthOffset;
series.getSeries().get(i + 1).setCoordinates(new Point2D(P2.getX(), P2.getY()));
path.cubicTo(P1.getX(), P1.getY(), P2.getX(), P2.getY(), P3.getX(), P3.getY());
}
} else {
boolean first = true;
int count = 1;
for (ValueLinePoint point : series.getSeries()) {
if (first) {
first = false;
continue;
}
currentOffset += widthOffset;
if (count == seriesPointCount - 1) {
// to prevent a graph drop
if (currentOffset < mGraphWidth) {
currentOffset = mGraphWidth;
}
}
point.setCoordinates(new Point2D(currentOffset, mGraphHeight - ((point.getValue() - minValue) * heightMultiplier)));
path.lineTo(point.getCoordinates().getX(), point.getCoordinates().getY());
count++;
}
}
if (mUseOverlapFill) {
path.lineTo(mGraphWidth, mGraphHeight);
path.lineTo(0, mGraphHeight);
path.lineTo(firstX, firstY);
}
series.setPath(path);
}
}
if (calculateLegendBounds())
Utils.calculateLegendInformation(mSeries.get(0).getSeries(), 0, mGraphWidth, mLegendPaint);
// set the first point for the indicator
if (mShowIndicator && mSeries.size() == 1) {
int size = mSeries.get(0).getSeries().size();
int index;
// Only calculate if more than one point is available
if (size > 1) {
// position the indicator in the middle at the nearest value
if (size == 3) {
index = size / 2;
} else {
index = (size / 2) - 1;
}
mFocusedPoint = mSeries.get(0).getSeries().get(index);
mTouchedArea = mFocusedPoint.getCoordinates();
calculateValueTextHeight();
}
}
resetZoom(false);
}
super.onDataChanged();
}
use of org.eazegraph.lib.models.ValueLinePoint in project EazeGraph by blackfizz.
the class ValueLineChart method initializeGraph.
/**
* This is the main entry point after the graph has been inflated. Used to initialize the graph
* and its corresponding members.
*/
@Override
protected void initializeGraph() {
super.initializeGraph();
mDrawMatrix.setValues(mDrawMatrixValues);
mGraphOverlay.decelerate();
mSeries = new ArrayList<ValueLineSeries>();
mLegendList = new ArrayList<LegendModel>();
mLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mLinePaint.setStrokeWidth(mLineStroke);
mLegendPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mLegendPaint.setColor(mLegendColor);
mLegendPaint.setTextSize(mLegendTextSize);
mLegendPaint.setStrokeWidth(2);
mLegendPaint.setStyle(Paint.Style.FILL);
mMaxFontHeight = Utils.calculateMaxTextHeight(mLegendPaint, null);
mIndicatorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mIndicatorPaint.setColor(mIndicatorLineColor);
mIndicatorPaint.setTextSize(mIndicatorTextSize);
mIndicatorPaint.setStrokeWidth(mIndicatorWidth);
mIndicatorPaint.setStyle(Paint.Style.FILL);
mScaleGestureDetector = new ScaleGestureDetector(getContext(), mScaleGestureListener);
mGestureDetector = new GestureDetector(getContext(), mGestureListener);
mScroller = new Scroller(getContext());
mRevealAnimator = ValueAnimator.ofFloat(0, 1);
mRevealAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mRevealValue = animation.getAnimatedFraction();
mDrawMatrix.reset();
mDrawMatrix.setScale(1, 1.f * mRevealValue, 0, mGraphHeight - mNegativeOffset);
mGraph.invalidate();
}
});
mRevealAnimator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
mStartedAnimation = false;
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
// The scroller doesn't have any built-in animation functions--it just supplies
// values when we ask it to. So we have to have a way to call it every frame
// until the fling ends. This code (ab)uses a ValueAnimator object to generate
// a callback on every animation frame. We don't use the animated value at all.
mScrollAnimator = ValueAnimator.ofFloat(0, 1);
mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator valueAnimator) {
tickScrollAnimation();
invalidateGlobal();
}
});
if (this.isInEditMode()) {
ValueLineSeries series1 = new ValueLineSeries();
series1.setColor(0xFF63CBB0);
series1.addPoint(new ValueLinePoint(1.4f));
series1.addPoint(new ValueLinePoint(4.4f));
series1.addPoint(new ValueLinePoint(2.4f));
series1.addPoint(new ValueLinePoint(3.2f));
series1.addPoint(new ValueLinePoint(2.6f));
series1.addPoint(new ValueLinePoint(5.0f));
series1.addPoint(new ValueLinePoint(3.5f));
series1.addPoint(new ValueLinePoint(2.4f));
series1.addPoint(new ValueLinePoint(0.4f));
series1.addPoint(new ValueLinePoint(3.4f));
series1.addPoint(new ValueLinePoint(2.5f));
series1.addPoint(new ValueLinePoint(1.0f));
series1.addPoint(new ValueLinePoint(4.2f));
series1.addPoint(new ValueLinePoint(2.4f));
series1.addPoint(new ValueLinePoint(3.6f));
series1.addPoint(new ValueLinePoint(1.0f));
series1.addPoint(new ValueLinePoint(2.5f));
series1.addPoint(new ValueLinePoint(1.4f));
addSeries(series1);
}
}
use of org.eazegraph.lib.models.ValueLinePoint in project EazeGraph by blackfizz.
the class CubicValueLineChartFragment method loadData.
private void loadData() {
ValueLineSeries series = new ValueLineSeries();
series.setColor(0xFF56B7F1);
series.addPoint(new ValueLinePoint("Jan", 2.4f));
series.addPoint(new ValueLinePoint("Feb", 3.4f));
series.addPoint(new ValueLinePoint("Mar", .4f));
series.addPoint(new ValueLinePoint("Apr", 1.2f));
series.addPoint(new ValueLinePoint("Mai", 2.6f));
series.addPoint(new ValueLinePoint("Jun", -1.0f));
series.addPoint(new ValueLinePoint("Jul", 3.5f));
series.addPoint(new ValueLinePoint("Aug", 2.4f));
series.addPoint(new ValueLinePoint("Sep", 2.4f));
series.addPoint(new ValueLinePoint("Oct", 3.4f));
series.addPoint(new ValueLinePoint("Nov", -.4f));
series.addPoint(new ValueLinePoint("Dec", -1.0f));
series.addPoint(new ValueLinePoint("Jan", 1.2f));
series.addPoint(new ValueLinePoint("Feb", 3.4f));
series.addPoint(new ValueLinePoint("Mar", -2.0f));
series.addPoint(new ValueLinePoint("Apr", -1.0f));
series.addPoint(new ValueLinePoint("Mai", 3.5f));
series.addPoint(new ValueLinePoint("Jun", 2.4f));
series.addPoint(new ValueLinePoint("Jan", 2.4f));
series.addPoint(new ValueLinePoint("Feb", 3.4f));
ValueLineSeries series1 = new ValueLineSeries();
series1.setColor(0xFFB3F7B1);
series1.addPoint(new ValueLinePoint("Jan", 1.4f));
series1.addPoint(new ValueLinePoint("Feb", 4.4f));
series1.addPoint(new ValueLinePoint("Mar", 2.4f));
series1.addPoint(new ValueLinePoint("Apr", 5.2f));
series1.addPoint(new ValueLinePoint("Mai", 2.6f));
series1.addPoint(new ValueLinePoint("Jun", 5.0f));
series1.addPoint(new ValueLinePoint("Jul", 7.5f));
series1.addPoint(new ValueLinePoint("Aug", 1.4f));
series1.addPoint(new ValueLinePoint("Sep", 5.4f));
series1.addPoint(new ValueLinePoint("Oct", 2.4f));
series1.addPoint(new ValueLinePoint("Nov", 7.4f));
series1.addPoint(new ValueLinePoint("Dec", 5.0f));
series1.addPoint(new ValueLinePoint("Jan", 2.2f));
series1.addPoint(new ValueLinePoint("Feb", 6.4f));
series1.addPoint(new ValueLinePoint("Mar", 3.6f));
series1.addPoint(new ValueLinePoint("Apr", 6.0f));
series1.addPoint(new ValueLinePoint("Mai", 1.5f));
series1.addPoint(new ValueLinePoint("Jun", 7.4f));
// mCubicValueLineChart.addSeries(series1);
mCubicValueLineChart.addSeries(series);
mCubicValueLineChart.addStandardValue(2.3f);
mCubicValueLineChart.addStandardValue(-1.3f);
mCubicValueLineChart.addStandardValue(4.3f);
mCubicValueLineChart.setOnPointFocusedListener(new IOnPointFocusedListener() {
@Override
public void onPointFocused(int _PointPos) {
Log.d("Test", "Pos: " + _PointPos);
}
});
}
Aggregations