Skip to content

Commit c9686e4

Browse files
paodbjavier-godoy
authored andcommitted
fix: move chart initialization to onAttach method
Close #37
1 parent 9e26a42 commit c9686e4

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.fasterxml.jackson.core.JsonProcessingException;
2424
import com.fasterxml.jackson.databind.ObjectMapper;
2525
import com.flowingcode.vaadin.addons.orgchart.client.OrgChartState;
26+
import com.vaadin.flow.component.AttachEvent;
2627
import com.vaadin.flow.component.ClientCallable;
2728
import com.vaadin.flow.component.ComponentEvent;
2829
import com.vaadin.flow.component.ComponentEventListener;
@@ -66,13 +67,24 @@ public OrgChart(OrgChartItem orgChartItem) {
6667
this.setId(identifier);
6768
}
6869

69-
public void initializeChart() {
70-
String identifier = "orgchart" + this.hashCode();
70+
@Override
71+
protected void onAttach(AttachEvent attachEvent) {
72+
super.onAttach(attachEvent);
7173
this.getElement()
7274
.executeJs(
73-
"this.initializeOrgChart($0,$1,$2)", convertToJsonObj(state), state.value, identifier);
75+
"this.initializeOrgChart($0,$1,$2)",
76+
convertToJsonObj(state),
77+
state.value,
78+
this.getId().get());
7479
}
7580

81+
/**
82+
* @deprecated This method is no longer needed. Initialization is done in {@link
83+
* #onAttach(AttachEvent)}.
84+
*/
85+
@Deprecated
86+
public void initializeChart() {}
87+
7688
public void setValue(OrgChartItem orgChartItem) {
7789
String value = convertToJsonObj(orgChartItem);
7890
getState().value = value;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public BottomTopDemo() {
3232
component2.setChartTitle("My Organization Chart Demo - Example 2 - BOTTOM TO TOP DIRECTION");
3333
component2.setChartNodeContent("title");
3434
component2.setChartDirection(ChartDirectionEnum.BOTTOM_TO_TOP.getAbreviation());
35-
component2.initializeChart();
3635

3736
setSizeFull();
3837
add(component2);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
*/
2020
package com.flowingcode.vaadin.addons.orgchart;
2121

22+
import java.util.Arrays;
23+
2224
import com.flowingcode.vaadin.addons.orgchart.extra.TemplateLiteralRewriter;
2325
import com.vaadin.flow.component.notification.Notification;
2426
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
25-
import java.util.Arrays;
2627

2728
@SuppressWarnings("serial")
2829
public class DragAndDropExportDemo extends VerticalLayout {
@@ -42,7 +43,6 @@ public DragAndDropExportDemo() {
4243
component1.setChartExportButton(true);
4344
component1.setChartExpandCollapse(true);
4445
component1.setChartDraggable(true);
45-
component1.initializeChart();
4646
component1.addDragAndDropListener(
4747
e ->
4848
System.out.println(

0 commit comments

Comments
 (0)