-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: replace htmllabels and htmllabelitem with annotation based labe…
…ls (#4481) * feat: remove unsupported htmllabels and implement annotation support * refactor: add convenience methods and remove unused fields and classes * docs: add javadocs for the new api * refactor: remove unnecessary styling * test: add serialization test * test: add annotation based label display test * docs: remove param annotations from javadocs * refactor: remove clearLabels method * docs: add missing javadoc params and rename point options --------- Co-authored-by: Diego Cardoso <[email protected]>
- Loading branch information
1 parent
8b6c3f1
commit 31d0441
Showing
10 changed files
with
299 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...adin-charts-flow/src/main/java/com/vaadin/flow/component/charts/model/AnnotationItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Copyright 2000-2022 Vaadin Ltd. | ||
* | ||
* This program is available under Vaadin Commercial License and Service Terms. | ||
* | ||
* See <https://vaadin.com/commercial-license-and-service-terms> for the full | ||
* license. | ||
*/ | ||
package com.vaadin.flow.component.charts.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Container for labels on the chart | ||
*/ | ||
public class AnnotationItem extends AbstractConfigurationObject { | ||
|
||
private List<AnnotationItemLabel> labels; | ||
|
||
/** | ||
* @see #setLabels(AnnotationItemLabel...) | ||
* @return Labels | ||
*/ | ||
public List<AnnotationItemLabel> getLabels() { | ||
if (labels == null) { | ||
labels = new ArrayList<>(); | ||
} | ||
return labels; | ||
} | ||
|
||
/** | ||
* Sets labels that can be positioned anywhere in the chart area. | ||
* | ||
* @param labels | ||
*/ | ||
public void setLabels(AnnotationItemLabel... labels) { | ||
clearLabels(); | ||
addLabels(labels); | ||
} | ||
|
||
/** | ||
* Adds multiple labels | ||
* | ||
* @see #setLabels(AnnotationItemLabel...) | ||
* @param labels | ||
*/ | ||
public void addLabels(AnnotationItemLabel... labels) { | ||
for (AnnotationItemLabel label : labels) { | ||
addLabel(label); | ||
} | ||
} | ||
|
||
/** | ||
* Adds a single label | ||
* | ||
* @see #setLabels(AnnotationItemLabel...) | ||
* @param label | ||
*/ | ||
public void addLabel(AnnotationItemLabel label) { | ||
getLabels().add(label); | ||
} | ||
|
||
/** | ||
* Clears all labels | ||
* | ||
* @see #setLabels(AnnotationItemLabel...) | ||
*/ | ||
public void clearLabels() { | ||
getLabels().clear(); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
...charts-flow/src/main/java/com/vaadin/flow/component/charts/model/AnnotationItemLabel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.vaadin.flow.component.charts.model; | ||
|
||
import com.vaadin.flow.component.charts.model.style.Style; | ||
|
||
/** | ||
* Label that can be positioned anywhere in the chart area | ||
*/ | ||
public class AnnotationItemLabel extends AbstractConfigurationObject { | ||
|
||
private AnnotationItemLabelPoint point; | ||
private Style style; | ||
private String text; | ||
private Boolean useHTML; | ||
|
||
/** | ||
* Constructs an AnnotationItemLabel with the given text | ||
* | ||
* @param text | ||
* Text to be displayed | ||
*/ | ||
public AnnotationItemLabel(String text) { | ||
this.text = text; | ||
} | ||
|
||
/** | ||
* @see #setPoint(AnnotationItemLabelPoint) | ||
*/ | ||
public AnnotationItemLabelPoint getPoint() { | ||
return point; | ||
} | ||
|
||
/** | ||
* Sets the {@link AnnotationItemLabelPoint} that contains the coordinate | ||
* data for the label | ||
* | ||
* @param point | ||
* Label point options | ||
*/ | ||
public void setPoint(AnnotationItemLabelPoint point) { | ||
this.point = point; | ||
} | ||
|
||
/** | ||
* @see #setStyle(Style) | ||
*/ | ||
public Style getStyle() { | ||
return style; | ||
} | ||
|
||
/** | ||
* Sets the label style options | ||
* | ||
* @param style | ||
* Label style options | ||
*/ | ||
public void setStyle(Style style) { | ||
this.style = style; | ||
} | ||
|
||
/** | ||
* @see #setText(String) | ||
*/ | ||
public String getText() { | ||
return text; | ||
} | ||
|
||
/** | ||
* Sets the text to be displayed | ||
* | ||
* @param text | ||
* Text to be displayed | ||
*/ | ||
public void setText(String text) { | ||
this.text = text; | ||
} | ||
|
||
/** | ||
* @see #setUseHTML(Boolean) | ||
*/ | ||
public Boolean getUseHTML() { | ||
return useHTML; | ||
} | ||
|
||
/** | ||
* Whether to enable HTML parsing for the label contents | ||
* | ||
* @param useHTML | ||
* Whether to enable HTML | ||
*/ | ||
public void setUseHTML(Boolean useHTML) { | ||
this.useHTML = useHTML; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...s-flow/src/main/java/com/vaadin/flow/component/charts/model/AnnotationItemLabelPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.vaadin.flow.component.charts.model; | ||
|
||
/** | ||
* Contains coordinates for {@link AnnotationItemLabel} | ||
*/ | ||
public class AnnotationItemLabelPoint extends AbstractConfigurationObject { | ||
|
||
private Number x; | ||
private Number y; | ||
|
||
/** | ||
* Constructs an AnnotationItemLabelPoint with the given coordinates | ||
* | ||
* @param x | ||
* Horizontal offset | ||
* @param y | ||
* Vertical offset | ||
*/ | ||
public AnnotationItemLabelPoint(Number x, Number y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
/** | ||
* @see #setX(Number) | ||
*/ | ||
public Number getX() { | ||
return x; | ||
} | ||
|
||
/** | ||
* Sets the horizontal offset of the label within chart | ||
* | ||
* @param x | ||
* Horizontal offset | ||
*/ | ||
public void setX(Number x) { | ||
this.x = x; | ||
} | ||
|
||
/** | ||
* @see #setY(Number) | ||
*/ | ||
public Number getY() { | ||
return y; | ||
} | ||
|
||
/** | ||
* Sets the vertical offset of the label within chart | ||
* | ||
* @param y | ||
* Vertical offset | ||
*/ | ||
public void setY(Number y) { | ||
this.y = y; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.