Package org.zkoss.chart
Class ClusterLayoutAlgorithm
- java.lang.Object
-
- org.zkoss.chart.Optionable
-
- org.zkoss.chart.ClusterLayoutAlgorithm
-
- All Implemented Interfaces:
Serializable
,OptionDataListener
,org.zkoss.json.JSONAware
public class ClusterLayoutAlgorithm extends Optionable
Options for layout algorithm. Inside there are options to change the type of the algorithm, gridSize, distance or iterations.All the options in this class support
DynamicalAttribute
.- Since:
- 10.2.1.0
- Author:
- jumperchen
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.zkoss.chart.Optionable
NOT_NULL_VALUE, options
-
-
Constructor Summary
Constructors Constructor Description ClusterLayoutAlgorithm()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
getDistance()
Whentype
is set tokmeans
,distance
is a maximum distance between point and cluster center so that this point will be inside the cluster.Object
getGridSize()
Whentype
is set to thegrid
,gridSize
is a size of a grid square element either as a number defining pixels, or a percentage defining a percentage of the plot area width.Number
getIterations()
Whentype
is set tokmeans
,iterations
are the number of iterations that this algorithm will be repeated to find clusters positions.Number
getKmeansThreshold()
Whentype
is set tonull
and there are more visible points than thekmeansThreshold
thegrid
algorithm is used to find clusters, otherwisekmeans
.Object
getType()
Returns the type of the algorithm used to combine points into a cluster.void
setDistance(Number distance)
Whentype
is set tokmeans
,distance
is a maximum distance between point and cluster center so that this point will be inside the cluster.void
setDistance(String distance)
Whentype
is set tokmeans
,distance
is a maximum distance between point and cluster center so that this point will be inside the cluster.void
setGridSize(Number gridSize)
Whentype
is set to thegrid
,gridSize
is a size of a grid square element either as a number defining pixels, or a percentage defining a percentage of the plot area width.void
setGridSize(String gridSize)
Whentype
is set to thegrid
,gridSize
is a size of a grid square element either as a number defining pixels, or a percentage defining a percentage of the plot area width.void
setIterations(Number iterations)
Whentype
is set tokmeans
,iterations
are the number of iterations that this algorithm will be repeated to find clusters positions.void
setKmeansThreshold(Number kmeansThreshold)
Whentype
is set tonull
and there are more visible points than thekmeansThreshold
thegrid
algorithm is used to find clusters, otherwisekmeans
.void
setType(String type)
Sets the type of the algorithm used to combine points into a cluster.void
setType(org.zkoss.json.JavaScriptValue type)
Sets the custom clustering algorithm can be added by assigning a callback function as the type property.-
Methods inherited from class org.zkoss.chart.Optionable
addExtraAttr, addOptionDataListener, clearOptonDataListener, clone, containsKey, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, getAttr, getAttr, getClientState, getExtraAttr, merge, onChange, removeExtraAttr, removeKey, removeOptionDataListener, setAttr, setAttr, setAttr, setAttr, toJSONString, toString
-
-
-
-
Method Detail
-
getDistance
public Object getDistance()
Whentype
is set tokmeans
,distance
is a maximum distance between point and cluster center so that this point will be inside the cluster. The distance is either a number defining pixels or a percentage defining a percentage of the plot area width.Default:
40
-
setDistance
public void setDistance(String distance)
Whentype
is set tokmeans
,distance
is a maximum distance between point and cluster center so that this point will be inside the cluster. The distance is either a number defining pixels or a percentage defining a percentage of the plot area width.Default:
40
- See Also:
setDistance(Number)
-
setDistance
public void setDistance(Number distance)
Whentype
is set tokmeans
,distance
is a maximum distance between point and cluster center so that this point will be inside the cluster. The distance is either a number defining pixels or a percentage defining a percentage of the plot area width.Default:
40
- See Also:
setDistance(String)
-
getGridSize
public Object getGridSize()
Whentype
is set to thegrid
,gridSize
is a size of a grid square element either as a number defining pixels, or a percentage defining a percentage of the plot area width.Default:
50
-
setGridSize
public void setGridSize(String gridSize)
Whentype
is set to thegrid
,gridSize
is a size of a grid square element either as a number defining pixels, or a percentage defining a percentage of the plot area width.Default:
50
- See Also:
setGridSize(Number)
-
setGridSize
public void setGridSize(Number gridSize)
Whentype
is set to thegrid
,gridSize
is a size of a grid square element either as a number defining pixels, or a percentage defining a percentage of the plot area width.Default:
50
- See Also:
setGridSize(String)
-
getIterations
public Number getIterations()
Whentype
is set tokmeans
,iterations
are the number of iterations that this algorithm will be repeated to find clusters positions.Default: null
-
setIterations
public void setIterations(Number iterations)
Whentype
is set tokmeans
,iterations
are the number of iterations that this algorithm will be repeated to find clusters positions.Default: null
-
getKmeansThreshold
public Number getKmeansThreshold()
Whentype
is set tonull
and there are more visible points than thekmeansThreshold
thegrid
algorithm is used to find clusters, otherwisekmeans
. It ensures good performance on large datasets and better clusters arrangement after the zoom.Default: 100
-
setKmeansThreshold
public void setKmeansThreshold(Number kmeansThreshold)
Whentype
is set tonull
and there are more visible points than thekmeansThreshold
thegrid
algorithm is used to find clusters, otherwisekmeans
. It ensures good performance on large datasets and better clusters arrangement after the zoom.Default: 100
-
getType
public Object getType()
Returns the type of the algorithm used to combine points into a cluster.Default: null.
-
setType
public void setType(String type)
Sets the type of the algorithm used to combine points into a cluster.There are three available algorithms:
-
grid
- grid-based clustering technique. Points are assigned to squares of set size depending on their position on the plot area. Points inside the grid square are combined into a cluster. The grid size can be controlled by gridSize property (grid size changes at certain zoom levels). -
kmeans
- based on K-Means clustering technique. In the first step, points are divided using the grid method (distance property is a grid size) to find the initial amount of clusters. Next, each point is classified by computing the distance between each cluster center and that point. When the closest cluster distance is lower than distance property set by a user the point is added to this cluster otherwise is classified as noise. The algorithm is repeated until each cluster center not change its previous position more than one pixel. This technique is more accurate but also more time consuming than the grid algorithm, especially for big datasets. -
optimizedKmeans
- based on K-Means clustering technique. This algorithm uses k-means algorithm only on the chart initialization or when chart extremes have greater range than on initialization. When a chart is redrawn the algorithm checks only clustered points distance from the cluster center and rebuild it when the point is spaced enough to be outside the cluster. It provides performance improvement and more stable clusters position yet can be used rather on small and sparse datasets.
By default, the algorithm depends on visible quantity of points and kmeansThreshold. When there are more visible points than the kmeansThreshold the grid algorithm is used, otherwise kmeans.
- Parameters:
type
- eithergrid
,kmeans
, andoptimizedKmeans
-
-
setType
public void setType(org.zkoss.json.JavaScriptValue type)
Sets the custom clustering algorithm can be added by assigning a callback function as the type property. This function takes an array ofprocessedXData
,processedYData
,processedXData
indexes andlayoutAlgorithm
options as arguments and should return an object with grouped data.The algorithm should return an object like that:
{ clusterId1: [{ x: 573, y: 285, index: 1 // point index in the data array }, { x: 521, y: 197, index: 2 }], clusterId2: [{ ... }] ... } }
clusterId
(example above - unique id of a cluster or noise) is an array of points belonging to a cluster. If the array has only one point or fewer points than set in cluster.minimumClusterSize it won't be combined into a cluster.- See Also:
setType(String)
-
-