use of org.achartengine.chart.RoundChart in project Anki-Android by Ramblurr.
the class FitZoom method apply.
/**
* Apply the tool.
*/
public void apply() {
if (mChart instanceof XYChart) {
if (((XYChart) mChart).getDataset() == null) {
return;
}
int scales = mRenderer.getScalesCount();
if (mRenderer.isInitialRangeSet()) {
for (int i = 0; i < scales; i++) {
if (mRenderer.isInitialRangeSet(i)) {
mRenderer.setRange(mRenderer.getInitialRange(i), i);
}
}
} else {
XYSeries[] series = ((XYChart) mChart).getDataset().getSeries();
double[] range = null;
int length = series.length;
if (length > 0) {
for (int i = 0; i < scales; i++) {
range = new double[] { MathHelper.NULL_VALUE, -MathHelper.NULL_VALUE, MathHelper.NULL_VALUE, -MathHelper.NULL_VALUE };
for (int j = 0; j < length; j++) {
if (i == series[j].getScaleNumber()) {
range[0] = Math.min(range[0], series[j].getMinX());
range[1] = Math.max(range[1], series[j].getMaxX());
range[2] = Math.min(range[2], series[j].getMinY());
range[3] = Math.max(range[3], series[j].getMaxY());
}
}
double marginX = Math.abs(range[1] - range[0]) / 40;
double marginY = Math.abs(range[3] - range[2]) / 40;
mRenderer.setRange(new double[] { range[0] - marginX, range[1] + marginX, range[2] - marginY, range[3] + marginY }, i);
}
}
}
} else {
DefaultRenderer renderer = ((RoundChart) mChart).getRenderer();
renderer.setScale(renderer.getOriginalScale());
}
}
use of org.achartengine.chart.RoundChart in project Anki-Android by Ramblurr.
the class Pan method apply.
/**
* Apply the tool.
*
* @param oldX the previous location on X axis
* @param oldY the previous location on Y axis
* @param newX the current location on X axis
* @param newY the current location on the Y axis
*/
public void apply(float oldX, float oldY, float newX, float newY) {
boolean notLimitedUp = true;
boolean notLimitedBottom = true;
boolean notLimitedLeft = true;
boolean notLimitedRight = true;
if (mChart instanceof XYChart) {
int scales = mRenderer.getScalesCount();
double[] limits = mRenderer.getPanLimits();
boolean limited = limits != null && limits.length == 4;
XYChart chart = (XYChart) mChart;
for (int i = 0; i < scales; i++) {
double[] range = getRange(i);
double[] calcRange = chart.getCalcRange(i);
if (limitsReachedX && limitsReachedY && (range[0] == range[1] && calcRange[0] == calcRange[1] || range[2] == range[3] && calcRange[2] == calcRange[3])) {
return;
}
checkRange(range, i);
double[] realPoint = chart.toRealPoint(oldX, oldY, i);
double[] realPoint2 = chart.toRealPoint(newX, newY, i);
double deltaX = realPoint[0] - realPoint2[0];
double deltaY = realPoint[1] - realPoint2[1];
double ratio = getAxisRatio(range);
if (chart.isVertical(mRenderer)) {
double newDeltaX = -deltaY * ratio;
double newDeltaY = deltaX / ratio;
deltaX = newDeltaX;
deltaY = newDeltaY;
}
if (mRenderer.isPanXEnabled()) {
if (limits != null) {
if (notLimitedLeft) {
notLimitedLeft = limits[0] <= range[0] + deltaX;
}
if (notLimitedRight) {
notLimitedRight = limits[1] >= range[1] + deltaX;
}
}
if (!limited || (notLimitedLeft && notLimitedRight)) {
setXRange(range[0] + deltaX, range[1] + deltaX, i);
limitsReachedX = false;
} else {
limitsReachedX = true;
}
}
if (mRenderer.isPanYEnabled()) {
if (notLimitedBottom && limits != null) {
notLimitedBottom = limits[2] <= range[2] - deltaY;
}
if (notLimitedUp && limits != null) {
notLimitedUp = limits[3] >= range[3] - deltaY;
}
if (limited && (!notLimitedBottom && !notLimitedUp)) {
limitsReachedY = true;
} else {
if (!notLimitedUp && deltaY < 0) {
setYRange(range[2] + deltaY, range[3] + deltaY, i);
notLimitedUp = true;
} else if (!notLimitedBottom && deltaY > 0) {
setYRange(range[2] + deltaY, range[3] + deltaY, i);
notLimitedBottom = true;
} else if (notLimitedBottom && notLimitedUp) {
setYRange(range[2] + deltaY, range[3] + deltaY, i);
}
limitsReachedY = false;
}
}
}
} else {
RoundChart chart = (RoundChart) mChart;
chart.setCenterX(chart.getCenterX() + (int) (newX - oldX));
chart.setCenterY(chart.getCenterY() + (int) (newY - oldY));
}
notifyPanListeners();
}
use of org.achartengine.chart.RoundChart in project sensorreadout by onyxbits.
the class FitZoom method apply.
/**
* Apply the tool.
*/
public void apply() {
if (mChart instanceof XYChart) {
if (((XYChart) mChart).getDataset() == null) {
return;
}
int scales = mRenderer.getScalesCount();
if (mRenderer.isInitialRangeSet()) {
for (int i = 0; i < scales; i++) {
if (mRenderer.isInitialRangeSet(i)) {
mRenderer.setRange(mRenderer.getInitialRange(i), i);
}
}
} else {
XYSeries[] series = ((XYChart) mChart).getDataset().getSeries();
double[] range = null;
int length = series.length;
if (length > 0) {
for (int i = 0; i < scales; i++) {
range = new double[] { MathHelper.NULL_VALUE, -MathHelper.NULL_VALUE, MathHelper.NULL_VALUE, -MathHelper.NULL_VALUE };
for (int j = 0; j < length; j++) {
if (i == series[j].getScaleNumber()) {
range[0] = Math.min(range[0], series[j].getMinX());
range[1] = Math.max(range[1], series[j].getMaxX());
range[2] = Math.min(range[2], series[j].getMinY());
range[3] = Math.max(range[3], series[j].getMaxY());
}
}
double marginX = Math.abs(range[1] - range[0]) / 40;
double marginY = Math.abs(range[3] - range[2]) / 40;
mRenderer.setRange(new double[] { range[0] - marginX, range[1] + marginX, range[2] - marginY, range[3] + marginY }, i);
}
}
}
} else {
DefaultRenderer renderer = ((RoundChart) mChart).getRenderer();
renderer.setScale(renderer.getOriginalScale());
}
}
use of org.achartengine.chart.RoundChart in project sensorreadout by onyxbits.
the class Pan method apply.
/**
* Apply the tool.
*
* @param oldX the previous location on X axis
* @param oldY the previous location on Y axis
* @param newX the current location on X axis
* @param newY the current location on the Y axis
*/
public void apply(float oldX, float oldY, float newX, float newY) {
boolean notLimitedUp = true;
boolean notLimitedBottom = true;
boolean notLimitedLeft = true;
boolean notLimitedRight = true;
if (mChart instanceof XYChart) {
int scales = mRenderer.getScalesCount();
double[] limits = mRenderer.getPanLimits();
boolean limited = limits != null && limits.length == 4;
XYChart chart = (XYChart) mChart;
for (int i = 0; i < scales; i++) {
double[] range = getRange(i);
double[] calcRange = chart.getCalcRange(i);
if (limitsReachedX && limitsReachedY && (range[0] == range[1] && calcRange[0] == calcRange[1] || range[2] == range[3] && calcRange[2] == calcRange[3])) {
return;
}
checkRange(range, i);
double[] realPoint = chart.toRealPoint(oldX, oldY, i);
double[] realPoint2 = chart.toRealPoint(newX, newY, i);
double deltaX = realPoint[0] - realPoint2[0];
double deltaY = realPoint[1] - realPoint2[1];
double ratio = getAxisRatio(range);
if (chart.isVertical(mRenderer)) {
double newDeltaX = -deltaY * ratio;
double newDeltaY = deltaX / ratio;
deltaX = newDeltaX;
deltaY = newDeltaY;
}
if (mRenderer.isPanXEnabled()) {
if (limits != null) {
if (notLimitedLeft) {
notLimitedLeft = limits[0] <= range[0] + deltaX;
}
if (notLimitedRight) {
notLimitedRight = limits[1] >= range[1] + deltaX;
}
}
if (!limited || (notLimitedLeft && notLimitedRight)) {
setXRange(range[0] + deltaX, range[1] + deltaX, i);
limitsReachedX = false;
} else {
limitsReachedX = true;
}
}
if (mRenderer.isPanYEnabled()) {
if (limits != null) {
if (notLimitedBottom) {
notLimitedBottom = limits[2] <= range[2] + deltaY;
}
if (notLimitedUp) {
notLimitedUp = limits[3] >= range[3] + deltaY;
}
}
if (!limited || (notLimitedBottom && notLimitedUp)) {
setYRange(range[2] + deltaY, range[3] + deltaY, i);
limitsReachedY = false;
} else {
limitsReachedY = true;
}
}
}
} else {
RoundChart chart = (RoundChart) mChart;
chart.setCenterX(chart.getCenterX() + (int) (newX - oldX));
chart.setCenterY(chart.getCenterY() + (int) (newY - oldY));
}
notifyPanListeners();
}
use of org.achartengine.chart.RoundChart in project sensorreadout by onyxbits.
the class Zoom method apply.
/**
* Apply the zoom.
*/
public void apply(int zoom_axis) {
if (mChart instanceof XYChart) {
int scales = mRenderer.getScalesCount();
for (int i = 0; i < scales; i++) {
double[] range = getRange(i);
checkRange(range, i);
double[] limits = mRenderer.getZoomLimits();
double centerX = (range[0] + range[1]) / 2;
double centerY = (range[2] + range[3]) / 2;
double newWidth = range[1] - range[0];
double newHeight = range[3] - range[2];
double newXMin = centerX - newWidth / 2;
double newXMax = centerX + newWidth / 2;
double newYMin = centerY - newHeight / 2;
double newYMax = centerY + newHeight / 2;
// if already reached last zoom, then it will always set to reached
if (i == 0) {
limitsReachedX = limits != null && (newXMin <= limits[0] || newXMax >= limits[1]);
limitsReachedY = limits != null && (newYMin <= limits[2] || newYMax >= limits[3]);
}
if (mZoomIn) {
if (mRenderer.isZoomXEnabled() && (zoom_axis == ZOOM_AXIS_X || zoom_axis == ZOOM_AXIS_XY)) {
if (limitsReachedX && mZoomRate < 1) {
// ignore pinch zoom out once reached X limit
} else {
newWidth /= mZoomRate;
}
}
if (mRenderer.isZoomYEnabled() && (zoom_axis == ZOOM_AXIS_Y || zoom_axis == ZOOM_AXIS_XY)) {
if (limitsReachedY && mZoomRate < 1) {
} else {
newHeight /= mZoomRate;
}
}
} else {
if (mRenderer.isZoomXEnabled() && !limitsReachedX && (zoom_axis == ZOOM_AXIS_X || zoom_axis == ZOOM_AXIS_XY)) {
newWidth *= mZoomRate;
}
if (mRenderer.isZoomYEnabled() && !limitsReachedY && (zoom_axis == ZOOM_AXIS_Y || zoom_axis == ZOOM_AXIS_XY)) {
newHeight *= mZoomRate;
}
}
double minX, minY;
if (limits != null) {
minX = Math.min(mRenderer.getZoomInLimitX(), limits[1] - limits[0]);
minY = Math.min(mRenderer.getZoomInLimitY(), limits[3] - limits[2]);
} else {
minX = mRenderer.getZoomInLimitX();
minY = mRenderer.getZoomInLimitY();
}
newWidth = Math.max(newWidth, minX);
newHeight = Math.max(newHeight, minY);
if (mRenderer.isZoomXEnabled() && (zoom_axis == ZOOM_AXIS_X || zoom_axis == ZOOM_AXIS_XY)) {
newXMin = centerX - newWidth / 2;
newXMax = centerX + newWidth / 2;
setXRange(newXMin, newXMax, i);
}
if (mRenderer.isZoomYEnabled() && (zoom_axis == ZOOM_AXIS_Y || zoom_axis == ZOOM_AXIS_XY)) {
newYMin = centerY - newHeight / 2;
newYMax = centerY + newHeight / 2;
setYRange(newYMin, newYMax, i);
}
}
} else {
DefaultRenderer renderer = ((RoundChart) mChart).getRenderer();
if (mZoomIn) {
renderer.setScale(renderer.getScale() * mZoomRate);
} else {
renderer.setScale(renderer.getScale() / mZoomRate);
}
}
notifyZoomListeners(new ZoomEvent(mZoomIn, mZoomRate));
}
Aggregations