Skip to content
This repository has been archived by the owner on Jul 10, 2020. It is now read-only.

Commit

Permalink
feat(option): #61: new option 'axis' on Tooltip and Hover
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Oberwasserlechner committed May 30, 2018
1 parent dcc6f58 commit 22d5cd4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/byteowls/vaadin/chartjs/options/Hover.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class Hover<T> extends And<T> implements JsonBuilder, Serializable {
private static final long serialVersionUID = 1317225903701999027L;

private InteractionMode mode;
private InteractionAxis axis;
private Boolean intersect;
private Integer animationDuration;
// TODO Callback onhover Called when any of the events fire. Called in the context of the chart and passed an array of active elements (bars, points, etc)
Expand All @@ -29,6 +30,14 @@ public Hover<T> mode(InteractionMode mode) {
return this;
}

/**
* Defines which directions are used in calculating distances. Defaults to {@link Axis#X} for index mode and {@link Axis#XY} in dataset and nearest modes.
*/
public Hover<T> axis(InteractionAxis axis) {
this.axis = axis;
return this;
}

/**
* If true, the hover mode only applies when the mouse position intersects an item on the chart. Defaults to true.
*/
Expand All @@ -51,6 +60,9 @@ public JsonObject buildJson() {
if (mode != null) {
JUtils.putNotNull(map, "mode", mode.name().toLowerCase());
}
if (axis != null) {
JUtils.putNotNull(map, "axis", axis.name().toLowerCase());
}
JUtils.putNotNull(map, "intersect", intersect);
JUtils.putNotNull(map, "animationDuration", animationDuration);
return map;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.byteowls.vaadin.chartjs.options;

public enum InteractionAxis {

X,
Y,
XY

}
12 changes: 12 additions & 0 deletions src/main/java/com/byteowls/vaadin/chartjs/options/Tooltips.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum PositionMode {
private Boolean enabled;
// TODO custom call
private InteractionMode mode;
private InteractionAxis axis;
private Boolean intersect;
private PositionMode position;
private String backgroundColor;
Expand Down Expand Up @@ -77,6 +78,14 @@ public Tooltips<T> mode(InteractionMode mode) {
return this;
}

/**
* Defines which directions are used in calculating distances. Defaults to {@link Axis#X} for index mode and {@link Axis#XY} in dataset and nearest modes.
*/
public Tooltips<T> axis(InteractionAxis axis) {
this.axis = axis;
return this;
}

/**
* If true, the tooltip mode applies only when the mouse position intersects with an element else
* the mode will be applied at all times. Defaults to true.
Expand Down Expand Up @@ -317,6 +326,9 @@ public JsonObject buildJson() {
if (mode != null) {
JUtils.putNotNull(map, "mode", mode.name().toLowerCase());
}
if (axis != null) {
JUtils.putNotNull(map, "axis", axis.name().toLowerCase());
}
JUtils.putNotNull(map, "intersect", intersect);
if (position != null) {
JUtils.putNotNull(map, "position", position.name().toLowerCase());
Expand Down

0 comments on commit 22d5cd4

Please sign in to comment.