org.pepstock.charba.client.options.Point Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of charba Show documentation
Show all versions of charba Show documentation
Charba, GWT Chart library based on CHART.JS
/**
Copyright 2017 Andrea "Stock" Stocchero
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.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.pepstock.charba.client.options;
import org.pepstock.charba.client.commons.Checker;
import org.pepstock.charba.client.commons.Key;
import org.pepstock.charba.client.commons.NativeObject;
import org.pepstock.charba.client.defaults.IsDefaultPoint;
/**
* Point elements are used to represent the points in a line chart or a bubble chart.
*
* @author Andrea "Stock" Stocchero
*/
public final class Point extends AbstractElement implements IsDefaultPoint, HasPointStyle {
/**
* Name of properties of native object.
*/
private enum Property implements Key
{
RADIUS("radius"),
HIT_RADIUS("hitRadius"),
HOVER_RADIUS("hoverRadius"),
ROTATION("rotation");
// name value of property
private final String value;
/**
* Creates with the property value to use in the native object.
*
* @param value value of property name
*/
private Property(String value) {
this.value = value;
}
/*
* (non-Javadoc)
*
* @see org.pepstock.charba.client.commons.Key#value()
*/
@Override
public String value() {
return value;
}
}
// instance of style of points manager
private final PointStyleHandler pointStyleHandler;
/**
* Creates the object with the parent, the key of this element, default values and native object to map java script properties.
*
* @param elements parent node to use to add this element where changed
* @param childKey the property name of this element to use to add it to the parent.
* @param defaultValues default provider
* @param nativeObject native object to map java script properties
*/
Point(Elements elements, Key childKey, IsDefaultPoint defaultValues, NativeObject nativeObject) {
super(elements, childKey, defaultValues, nativeObject);
// creates point style handler
this.pointStyleHandler = new PointStyleHandler(this, getDefaultValues(), getNativeObject());
}
/*
* (non-Javadoc)
*
* @see org.pepstock.charba.client.options.HasPointStyle#getPointStyleHandler()
*/
@Override
public PointStyleHandler getPointStyleHandler() {
return pointStyleHandler;
}
/**
* Sets the radius of the point shape.
* If set to 0, the point is not rendered.
*
* @param radius array of the radius of the point shape.
*/
public void setRadius(double radius) {
setValueAndAddToParent(Property.RADIUS, Checker.positiveOrZero(radius));
}
/**
* Returns the radius of the point.
*
* @return the radius of the point.
*/
@Override
public double getRadius() {
return getValue(Property.RADIUS, getDefaultValues().getRadius());
}
/**
* Sets the pixel size of the non-displayed point that reacts to mouse events.
*
* @param hitRadius the pixel size of the non-displayed point.
*/
public void setHitRadius(double hitRadius) {
setValueAndAddToParent(Property.HIT_RADIUS, Checker.positiveOrZero(hitRadius));
}
/**
* Returns the pixel size of the non-displayed point that reacts to mouse events.
*
* @return the pixel size of the non-displayed point.
*/
@Override
public double getHitRadius() {
return getValue(Property.HIT_RADIUS, getDefaultValues().getHitRadius());
}
/**
* Sets the radius of the point when hovered.
*
* @param hoverRadius the radius of the point when hovered.
*/
public void setHoverRadius(double hoverRadius) {
setValueAndAddToParent(Property.HOVER_RADIUS, Checker.positiveOrZero(hoverRadius));
}
/**
* Returns the radius of the point when hovered.
*
* @return the radius of the point when hovered.
*/
@Override
public double getHoverRadius() {
return getValue(Property.HOVER_RADIUS, getDefaultValues().getHoverRadius());
}
/**
* Sets the point rotation (in degrees).
*
* @param rotation the point rotation (in degrees).
*/
public void setRotation(double rotation) {
setValueAndAddToParent(Property.ROTATION, rotation);
}
/**
* Returns the point rotation (in degrees).
*
* @return the point rotation (in degrees).
*/
@Override
public double getRotation() {
return getValue(Property.ROTATION, getDefaultValues().getRotation());
}
}