From 22d5cd46e540e0502996748730314186f34dfdfe Mon Sep 17 00:00:00 2001 From: Michael Oberwasserlechner Date: Wed, 30 May 2018 21:33:03 +0200 Subject: [PATCH] feat(option): #61: new option 'axis' on Tooltip and Hover --- .../com/byteowls/vaadin/chartjs/options/Hover.java | 12 ++++++++++++ .../vaadin/chartjs/options/InteractionAxis.java | 9 +++++++++ .../byteowls/vaadin/chartjs/options/Tooltips.java | 12 ++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/main/java/com/byteowls/vaadin/chartjs/options/InteractionAxis.java diff --git a/src/main/java/com/byteowls/vaadin/chartjs/options/Hover.java b/src/main/java/com/byteowls/vaadin/chartjs/options/Hover.java index 1f32499..cfd3a35 100644 --- a/src/main/java/com/byteowls/vaadin/chartjs/options/Hover.java +++ b/src/main/java/com/byteowls/vaadin/chartjs/options/Hover.java @@ -13,6 +13,7 @@ public class Hover extends And 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) @@ -29,6 +30,14 @@ public Hover 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 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. */ @@ -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; diff --git a/src/main/java/com/byteowls/vaadin/chartjs/options/InteractionAxis.java b/src/main/java/com/byteowls/vaadin/chartjs/options/InteractionAxis.java new file mode 100644 index 0000000..590a832 --- /dev/null +++ b/src/main/java/com/byteowls/vaadin/chartjs/options/InteractionAxis.java @@ -0,0 +1,9 @@ +package com.byteowls.vaadin.chartjs.options; + +public enum InteractionAxis { + + X, + Y, + XY + +} diff --git a/src/main/java/com/byteowls/vaadin/chartjs/options/Tooltips.java b/src/main/java/com/byteowls/vaadin/chartjs/options/Tooltips.java index 416a508..8566ccb 100644 --- a/src/main/java/com/byteowls/vaadin/chartjs/options/Tooltips.java +++ b/src/main/java/com/byteowls/vaadin/chartjs/options/Tooltips.java @@ -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; @@ -77,6 +78,14 @@ public Tooltips 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 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. @@ -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());