use of lecho.lib.hellocharts.model.BubbleValue in project hellocharts-android by lecho.
the class BubbleChartRenderer method calculateMaxViewport.
private void calculateMaxViewport() {
float maxZ = Float.MIN_VALUE;
tempMaximumViewport.set(Float.MAX_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MAX_VALUE);
BubbleChartData data = dataProvider.getBubbleChartData();
// TODO: Optimize.
for (BubbleValue bubbleValue : data.getValues()) {
if (Math.abs(bubbleValue.getZ()) > maxZ) {
maxZ = Math.abs(bubbleValue.getZ());
}
if (bubbleValue.getX() < tempMaximumViewport.left) {
tempMaximumViewport.left = bubbleValue.getX();
}
if (bubbleValue.getX() > tempMaximumViewport.right) {
tempMaximumViewport.right = bubbleValue.getX();
}
if (bubbleValue.getY() < tempMaximumViewport.bottom) {
tempMaximumViewport.bottom = bubbleValue.getY();
}
if (bubbleValue.getY() > tempMaximumViewport.top) {
tempMaximumViewport.top = bubbleValue.getY();
}
}
maxRadius = (float) Math.sqrt(maxZ / Math.PI);
// Number 4 is determined by trials and errors method, no magic behind it:).
bubbleScaleX = tempMaximumViewport.width() / (maxRadius * 4);
if (bubbleScaleX == 0) {
// case for 0 viewport width.
bubbleScaleX = 1;
}
bubbleScaleY = tempMaximumViewport.height() / (maxRadius * 4);
if (bubbleScaleY == 0) {
// case for 0 viewport height.
bubbleScaleY = 1;
}
// For cases when user sets different than 1 bubble scale in BubbleChartData.
bubbleScaleX *= data.getBubbleScale();
bubbleScaleY *= data.getBubbleScale();
// Prevent cutting of bubbles on the edges of chart area.
tempMaximumViewport.inset(-maxRadius * bubbleScaleX, -maxRadius * bubbleScaleY);
minRawRadius = ChartUtils.dp2px(density, dataProvider.getBubbleChartData().getMinBubbleRadius());
}
use of lecho.lib.hellocharts.model.BubbleValue in project hellocharts-android by lecho.
the class BubbleChartView method callTouchListener.
@Override
public void callTouchListener() {
SelectedValue selectedValue = chartRenderer.getSelectedValue();
if (selectedValue.isSet()) {
BubbleValue value = data.getValues().get(selectedValue.getFirstIndex());
onValueTouchListener.onValueSelected(selectedValue.getFirstIndex(), value);
} else {
onValueTouchListener.onValueDeselected();
}
}
use of lecho.lib.hellocharts.model.BubbleValue in project hellocharts-android by lecho.
the class BubbleChartRenderer method highlightBubbles.
private void highlightBubbles(Canvas canvas) {
final BubbleChartData data = dataProvider.getBubbleChartData();
BubbleValue bubbleValue = data.getValues().get(selectedValue.getFirstIndex());
highlightBubble(canvas, bubbleValue);
}
use of lecho.lib.hellocharts.model.BubbleValue in project hellocharts-android by lecho.
the class BubbleChartRenderer method checkTouch.
@Override
public boolean checkTouch(float touchX, float touchY) {
selectedValue.clear();
final BubbleChartData data = dataProvider.getBubbleChartData();
int valueIndex = 0;
for (BubbleValue bubbleValue : data.getValues()) {
float rawRadius = processBubble(bubbleValue, bubbleCenter);
if (ValueShape.SQUARE.equals(bubbleValue.getShape())) {
if (bubbleRect.contains(touchX, touchY)) {
selectedValue.set(valueIndex, valueIndex, SelectedValueType.NONE);
}
} else if (ValueShape.CIRCLE.equals(bubbleValue.getShape())) {
final float diffX = touchX - bubbleCenter.x;
final float diffY = touchY - bubbleCenter.y;
final float touchDistance = (float) Math.sqrt((diffX * diffX) + (diffY * diffY));
if (touchDistance <= rawRadius) {
selectedValue.set(valueIndex, valueIndex, SelectedValueType.NONE);
}
} else {
throw new IllegalArgumentException("Invalid bubble shape: " + bubbleValue.getShape());
}
++valueIndex;
}
return isTouched();
}
Aggregations