Skip to content
Open
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
44 changes: 26 additions & 18 deletions src/timelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export default Kapsule({
yAxis: null,
grpAxis: null,

dateMarkerLine: null,
dateMarkerLine: [],

svg: null,
graph: null,
Expand Down Expand Up @@ -389,8 +389,6 @@ export default Kapsule({
);

state.graph = state.svg.append('g');

state.dateMarkerLine = state.svg.append('line').attr('class', 'x-axis-date-marker');

if (state.enableOverview) {
addOverviewArea();
Expand Down Expand Up @@ -845,21 +843,31 @@ export default Kapsule({
.transition().duration(state.transDuration)
.call(state.xGrid);

if (
state.dateMarker &&
state.dateMarker >= state.xScale.domain()[0] &&
state.dateMarker <= state.xScale.domain()[1]
) {
state.dateMarkerLine
.style('display', 'block')
.transition().duration(state.transDuration)
.attr('x1', state.xScale(state.dateMarker) + state.leftMargin)
.attr('x2', state.xScale(state.dateMarker) + state.leftMargin)
.attr('y1', state.topMargin + 1)
.attr('y2', state.graphH + state.topMargin)
} else {
state.dateMarkerLine.style('display', 'none');
}
if (typeof state.dateMarker != "undefined" &&
state.dateMarker != null &&
state.dateMarker.length != null &&
state.dateMarker.length > 0
) {
for (var i = 0; i < state.dateMarker.length; i++) {

state.dateMarkerLine.push(state.svg.append('line').attr('class', 'x-axis-date-marker'));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this won't be able to react to changes in props. Every time the graph is re-rendered a new line will be added to the DOM. Similarly they will not be removed if the prop changes value. The maintenance of these objects should be done with an enter/update/exit d3 pattern.


if (
state.dateMarker[i] >= state.xScale.domain()[0] &&
state.dateMarker[i] <= state.xScale.domain()[1]
) {
state.dateMarkerLine[i]
.style('display', 'block')
.transition().duration(state.transDuration)
.attr('x1', state.xScale(state.dateMarker[i]) + state.leftMargin)
.attr('x2', state.xScale(state.dateMarker[i]) + state.leftMargin)
.attr('y1', state.topMargin + 1)
.attr('y2', state.graphH + state.topMargin)
} else {
state.dateMarkerLine[i].style('display', 'none');
}
}
}

// Y
const fontVerticalMargin = 0.6;
Expand Down