Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions web_timeline/static/src/views/timeline/timeline_canvas.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@ export class TimelineCanvas {
constructor(canvas_ref) {
this.canvas_ref = canvas_ref;
}

/**
* Clears all drawings (svg elements) from the canvas.
*/
clear() {
if (this.canvas_ref) {
const tempElement = document.createElement("div");
tempElement.innerHTML = this.canvas_ref;
Array.from(tempElement.children).forEach((child) => {
if (child.tagName.toLowerCase() !== "defs") {
child.remove();
}
});
this.canvas_ref = tempElement.innerHTML;
}
Array.from(this.canvas_ref.children)
.filter((el) => el.tagName.toLowerCase() !== "defs")
.forEach((el) => el.remove());
}

/**
Expand Down Expand Up @@ -158,9 +152,7 @@ export class TimelineCanvas {
if (markerStart) {
line.setAttribute("marker-start", `url(${markerStart})`);
}
if (this.canvas_ref instanceof HTMLElement) {
this.canvas_ref.appendChild(line);
}
this.canvas_ref.appendChild(line);
return line;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export class TimelineRenderer extends Component {
this.fields = this.params.fields;
this.timeline = false;
this.initial_data_loaded = false;
this.canvas_ref = renderToString("TimelineView.Canvas", {});
const canvas_str = renderToString("TimelineView.Canvas", {});
const parser = new DOMParser();
const svgDoc = parser.parseFromString(canvas_str, "image/svg+xml");
this.canvas_ref = svgDoc.documentElement;
onWillUpdateProps(async (props) => {
this.on_data_loaded(props.model.data);
});
Expand Down Expand Up @@ -220,8 +223,8 @@ export class TimelineRenderer extends Component {
}
this.$centerContainer = this.timeline.dom.centerContainer;
this.canvas = new TimelineCanvas(this.canvas_ref);
if (this.$centerContainer.el) {
this.$centerContainer.el.appendChild(this.canvas_ref);
if (this.$centerContainer) {
this.$centerContainer.appendChild(this.canvas_ref);
}
this.timeline.on("changed", () => {
this.draw_canvas();
Expand Down