Skip to content

Commit d781df3

Browse files
paodbjavier-godoy
authored andcommitted
feat(demo): add new hybrid chart demo example
Close #69
1 parent 3ef22de commit d781df3

File tree

13 files changed

+194
-0
lines changed

13 files changed

+194
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*-
2+
* #%L
3+
* OrgChart Add-on
4+
* %%
5+
* Copyright (C) 2017 - 2023 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+
import com.flowingcode.vaadin.addons.demo.DemoSource;
24+
import com.flowingcode.vaadin.addons.orgchart.extra.TemplateLiteralRewriter;
25+
import com.vaadin.flow.component.dependency.CssImport;
26+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
27+
import com.vaadin.flow.router.PageTitle;
28+
import com.vaadin.flow.router.Route;
29+
30+
/**
31+
* Chart demo showing how to display a hybrid demo (horizontal + vertical) and how to customize the
32+
* nodes to show information as cards.
33+
*
34+
*/
35+
@SuppressWarnings("serial")
36+
@PageTitle("Hybrid")
37+
@DemoSource
38+
@Route(value = "orgchart/hybrid", layout = OrgchartDemoView.class)
39+
@CssImport("./styles/orgchart/hybrid-demo-styles.css")
40+
public class HybridEnhancedChartDemo extends VerticalLayout {
41+
42+
public HybridEnhancedChartDemo() {
43+
OrgChart orgchart = getExample1();
44+
String nodeTemplate = "<div class='title'>"
45+
+ "${item.data.imageUrl?`<img class='avatar'src=${item.data.imageUrl}></img>`:''}"
46+
+ "<div class='item-name'>${item.name}</div>"
47+
+ "<div class='item-title'>${item.title}</div>"
48+
+ "${item.data.phone?`<div class='item-phone'><i class='fa fa-phone'></i>${item.data.phone}</div>`:''}"
49+
+ "${item.data.mail?`<div class='item-email'><i class='fa fa-envelope-o'></i>${item.data.mail}</div>`:''}"
50+
+ "</div>";
51+
orgchart.setNodeTemplate("item", TemplateLiteralRewriter.rewriteFunction(nodeTemplate));
52+
orgchart.addClassNames("chart-container", "hybrid-chart");
53+
orgchart.setChartNodeContent("title");
54+
55+
// make the chart to show children as vertical starting in level 3
56+
orgchart.setChartVerticalDepth(3);
57+
58+
orgchart.setChartTitle("My Organization Chart Demo - Example 4 - HYBRID CHART WITH CUSTOM TEMPLATE");
59+
60+
setSizeFull();
61+
add(orgchart);
62+
}
63+
64+
private OrgChart getExample1() {
65+
OrgChartItem item1 = new OrgChartItem(1, "John Williams", "Director");
66+
item1.setData("mail", "[email protected]");
67+
item1.setData("imageUrl", "images/1.png");
68+
item1.setData("phone", "(333) 445-5898");
69+
OrgChartItem item2 = new OrgChartItem(2, "Anna Thompson", "Administration");
70+
item2.setData("mail", "[email protected]");
71+
item2.setData("imageUrl", "images/2.png");
72+
item2.setData("phone", "(333) 407-5559");
73+
OrgChartItem item3 = new OrgChartItem(3, "Timothy Henry Jones", "Administration");
74+
item3.setData("mail", "[email protected]");
75+
item3.setData("imageUrl", "images/3.png");
76+
item3.setData("phone", "(344) 508-7894");
77+
OrgChartItem item4 = new OrgChartItem(4, "Louise Night", "Administration");
78+
item4.setData("mail", "[email protected]");
79+
item4.setData("imageUrl", "images/4.png");
80+
81+
OrgChartItem item5 = new OrgChartItem(5, "John Porter", "Head of Department");
82+
item5.setData("mail", "[email protected]");
83+
item5.setData("imageUrl", "images/5.png");
84+
OrgChartItem item6 = new OrgChartItem(6, "Charles Thomas", "Head of Department");
85+
item6.setData("mail", "[email protected]");
86+
item6.setData("imageUrl", "images/6.png");
87+
OrgChartItem item7 = new OrgChartItem(7, "Angela Wood", "Section 1");
88+
item7.setData("mail", "[email protected]");
89+
item7.setData("imageUrl", "images/7.png");
90+
OrgChartItem item8 = new OrgChartItem(8, "Martha Brown", "Section 1");
91+
item8.setData("imageUrl", "images/8.png");
92+
OrgChartItem item9 = new OrgChartItem(9, "Mary Parker", "Section 1.1");
93+
item9.setData("imageUrl", "images/9.png");
94+
OrgChartItem item10 = new OrgChartItem(10, "Mary Williamson", "Section 2");
95+
item10.setData("imageUrl", "images/10.png");
96+
item10.setData("phone", "(234) 567-9323");
97+
98+
item1.setChildren(Arrays.asList(item2, item3, item4));
99+
item4.addChildren(item5);
100+
item2.setChildren(Arrays.asList(item6));
101+
item6.setChildren(Arrays.asList(item7, item8));
102+
item8.setChildren(Arrays.asList(item9));
103+
item5.setChildren(Arrays.asList(item10));
104+
return new OrgChart(item1);
105+
}
106+
107+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ public OrgchartDemoView() {
3838
addDemo(DragAndDropExportDemo.class);
3939
addDemo(BottomTopDemo.class);
4040
addDemo(ImageInTitleDemo.class);
41+
addDemo(HybridEnhancedChartDemo.class);
4142
}
4243
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*-
2+
* #%L
3+
* OrgChart Add-on
4+
* %%
5+
* Copyright (C) 2017 - 2023 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+
.hybrid-chart .orgchart .node {
21+
width: 220px;
22+
}
23+
24+
.hybrid-chart .orgchart .node .title {
25+
height: 80px !important;
26+
text-align: left;
27+
line-height: 18px;
28+
font-size: 11px;
29+
border-radius: 0;
30+
background-color: rgb(255, 255, 255);
31+
border: 1px solid var(--lumo-body-text-color);
32+
color: var(--lumo-body-text-color);
33+
padding: 10px 4px 4px 0;
34+
}
35+
36+
.hybrid-chart .orgchart .node .avatar {
37+
width: 60px;
38+
height: 60px;
39+
float: left;
40+
margin-top: 8px;
41+
margin-left: 3px;
42+
margin-right: 3px;
43+
}
44+
45+
.hybrid-chart .orgchart .node .item-name {
46+
font-weight: 800;
47+
}
48+
49+
.hybrid-chart .orgchart .node .item-name, .item-title, .item-email,
50+
.item-phone {
51+
overflow: hidden;
52+
text-overflow: ellipsis;
53+
white-space: nowrap;
54+
}
55+
56+
.hybrid-chart .orgchart .node .item-email i, .item-phone i {
57+
margin-right: 4px;
58+
}
59+
60+
.hybrid-chart .orgchart .title .symbol {
61+
display: none
62+
}
63+
64+
.hybrid-chart .orgchart .lines .rightLine {
65+
border-right-color: var(--lumo-body-text-color);
66+
}
67+
68+
.hybrid-chart .orgchart .lines .leftLine {
69+
border-left-color: var(--lumo-body-text-color);
70+
}
71+
72+
.hybrid-chart .orgchart .lines .topLine {
73+
border-top-color: var(--lumo-body-text-color);
74+
}
75+
76+
.hybrid-chart .orgchart .verticalNodes>td::before {
77+
border-color: var(--lumo-body-text-color);
78+
}
79+
80+
.hybrid-chart .orgchart .lines .downLine {
81+
background-color: var(--lumo-body-text-color);
82+
}
83+
84+
.hybrid-chart .orgchart .verticalNodes ul>li::after, .hybrid-chart .orgchart .verticalNodes ul>li::before {
85+
border-color: var(--lumo-body-text-color);
86+
}
32.3 KB
Loading
23.8 KB
Loading
26 KB
Loading
24.5 KB
Loading
31.1 KB
Loading
23.9 KB
Loading
24.7 KB
Loading

0 commit comments

Comments
 (0)