Skip to content

Commit 12f9497

Browse files
paodbjavier-godoy
authored andcommitted
feat: add support to mark items as hybrid
Close #85
1 parent 945b6cc commit 12f9497

File tree

5 files changed

+116
-2
lines changed

5 files changed

+116
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.flowingcode.vaadin.addons</groupId>
44
<artifactId>orgchart-addon</artifactId>
5-
<version>5.1.1-SNAPSHOT</version>
5+
<version>5.2.0-SNAPSHOT</version>
66
<name>OrgChart Add-on</name>
77

88
<properties>

src/main/java/com/flowingcode/vaadin/addons/orgchart/OrgChartItem.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.Map;
2929
import java.util.Optional;
3030

31+
import com.fasterxml.jackson.annotation.JsonProperty;
32+
3133
/** @author pbartolo */
3234
@SuppressWarnings("serial")
3335
public class OrgChartItem implements Serializable {
@@ -44,6 +46,8 @@ public class OrgChartItem implements Serializable {
4446

4547
private Map<String, String> data;
4648

49+
private boolean hybrid;
50+
4751
public OrgChartItem(Integer id, String name, String title) {
4852
super();
4953
this.id = id;
@@ -129,6 +133,30 @@ public void addChildren(OrgChartItem item) {
129133
this.children.add(item);
130134
}
131135

136+
/**
137+
* Indicates whether this item is a hybrid node.
138+
* A hybrid node arranges its descendant children vertically instead of
139+
* horizontally.
140+
*
141+
* @return {@code true} if this item is hybrid; {@code false} otherwise
142+
*/
143+
public boolean isHybrid() {
144+
return this.hybrid;
145+
}
146+
147+
/**
148+
* Sets whether this item is a hybrid node.
149+
* When {@code true}, the item's descendant children will be arranged
150+
* vertically.
151+
*
152+
* @param hybrid {@code true} to mark this node as hybrid; {@code false}
153+
* otherwise
154+
*/
155+
@JsonProperty("isHybrid")
156+
public void setHybrid(boolean hybrid) {
157+
this.hybrid = hybrid;
158+
}
159+
132160
@Override
133161
public int hashCode() {
134162
final int prime = 31;
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*-
2+
* #%L
3+
* OrgChart Add-on
4+
* %%
5+
* Copyright (C) 2017 - 2025 Flowing Code S.A.
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.orgchart;
21+
22+
import java.util.Arrays;
23+
24+
import com.flowingcode.vaadin.addons.demo.DemoSource;
25+
import com.flowingcode.vaadin.addons.orgchart.extra.TemplateLiteralRewriter;
26+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
27+
import com.vaadin.flow.router.PageTitle;
28+
import com.vaadin.flow.router.Route;
29+
30+
@SuppressWarnings("serial")
31+
@PageTitle("Hybrid Data Property")
32+
@DemoSource
33+
@Route(value = "orgchart/hybrid-data-property", layout = OrgchartDemoView.class)
34+
public class HybridDataPropertyDemo extends VerticalLayout {
35+
36+
public HybridDataPropertyDemo() {
37+
OrgChart component = getExample();
38+
String nodeTemplate =
39+
"<div class='title'>${item.title}</div>"
40+
+ "<div class='middle content'>${item.name}</div>"
41+
+ "${item.data.mail?`<div class='custom content'>${item.data.mail}</div>`:''}";
42+
component.setNodeTemplate("item", TemplateLiteralRewriter.rewriteFunction(nodeTemplate));
43+
component.addClassName("chart-container");
44+
component.setChartTitle(
45+
"My Organization Chart Demo - Example 5 - HYBRID DATA PROPERTY WITH CUSTOM TEMPLATE");
46+
component.setChartNodeContent("title");
47+
setSizeFull();
48+
add(component);
49+
}
50+
51+
private OrgChart getExample() {
52+
OrgChartItem item1 = new OrgChartItem(1, "John Williams", "Director");
53+
item1.setData("mail", "jwilliams@example.com");
54+
item1.setClassName("blue-node");
55+
OrgChartItem item2 = new OrgChartItem(2, "Anna Thompson", "Administration");
56+
item2.setData("mail", "athomp@example.com");
57+
item2.setClassName("blue-node");
58+
59+
// set item 2 as hybrid
60+
item2.setHybrid(true);
61+
62+
OrgChartItem item3 =
63+
new OrgChartItem(
64+
3, "Timothy Albert Henry Jones ", "Sub-Director of Administration Department");
65+
item3.setData("mail", "timothy.albert.jones@example.com");
66+
item1.setChildren(Arrays.asList(item2, item3));
67+
OrgChartItem item4 = new OrgChartItem(4, "Louise Night", "Department 1");
68+
item4.setData("mail", "lnight@example.com");
69+
OrgChartItem item5 = new OrgChartItem(5, "John Porter", "Department 2");
70+
item5.setData("mail", "jporter@example.com");
71+
OrgChartItem item6 = new OrgChartItem(6, "Charles Thomas", "Department 3");
72+
item6.setData("mail", "ctomas@example.com");
73+
74+
// set item 6 as hybrid
75+
item6.setHybrid(true);
76+
77+
item2.setChildren(Arrays.asList(item4, item5, item6));
78+
OrgChartItem item7 = new OrgChartItem(7, "Michael Wood", "Section 3.1");
79+
OrgChartItem item8 = new OrgChartItem(8, "Martha Brown", "Section 3.2");
80+
OrgChartItem item9 = new OrgChartItem(9, "Mary Parker", "Section 3.3");
81+
OrgChartItem item10 = new OrgChartItem(10, "Mary Williamson", "Section 3.4");
82+
item6.setChildren(Arrays.asList(item7, item8, item9, item10));
83+
return new OrgChart(item1);
84+
}
85+
}

src/test/java/com/flowingcode/vaadin/addons/orgchart/HybridEnhancedChartDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public HybridEnhancedChartDemo() {
6464
iconsAnchor.setTitle("people icons");
6565
iconsDiv.add(iconsAnchor);
6666

67-
orgchart.setChartTitle("My Organization Chart Demo - Example 4 - HYBRID CHART WITH CUSTOM TEMPLATE" + iconsDiv.getElement());
67+
orgchart.setChartTitle("My Organization Chart Demo - Example 4 - HYBRID CHART USING VERTICALLEVEL PROPERTY WITH CUSTOM TEMPLATE" + iconsDiv.getElement());
6868

6969
setSizeFull();
7070
add(orgchart);

src/test/java/com/flowingcode/vaadin/addons/orgchart/OrgchartDemoView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ public OrgchartDemoView() {
4040
addDemo(BottomTopDemo.class);
4141
addDemo(ImageInTitleDemo.class);
4242
addDemo(HybridEnhancedChartDemo.class);
43+
addDemo(HybridDataPropertyDemo.class);
4344
}
4445
}

0 commit comments

Comments
 (0)