{
const data = adae.filter(d => d.USUBJID === patient)
.filter(d => typeof d.AESTDY !== 'undefined' & typeof d.AEENDY !== 'undefined')
.map((d) => {
if (d.AESTDY === d.AEENDY) {
return {
...d,
AEENDY: nudge(d.AEENDY)
}
}
return d
})
const startDayAccessor = d => d.AESTDY
const endDayAccessor = d => d.AEENDY
const yAccessor = d => d.AESEQ
const colorAccessor = d => d.AESEV
const svg = d3.create("svg")
.attr("width", dimensions.width)
.attr("height", dimensions.height)
const bounds = svg.append("g")
.style("transform", `translate(${
dimensions.margin.left
}px, ${
dimensions.margin.top
}px)`
)
// scales
// const sortedAECodes = data.sort((a, b) => d3.ascending(a.AESEQ, b.AESEQ)).map(d => d.AEDECOD)
// const uniqueAECodes = unique(sortedAECodes)
// const yScale = d3.scaleBand()
// .domain(uniqueAECodes)
// .range([dimensions.boundedHeight, 0])
const yScale = d3.scaleLinear()
// .domain(d3.extent(data, yAccessor))
.domain([0, d3.max(data, yAccessor)])
.range([dimensions.boundedHeight, 0])
const colorScale = d3.scaleOrdinal()
.domain(["MILD", "MODERATE", "SEVERE"])
.range(['#fdd26e', '#ff8041', '#cc66ff'])
// marks
const lines = bounds.selectAll("line")
.data(data)
.join("line")
.attr("x1", d => xScale(startDayAccessor(d)))
.attr("x2", d => xScale(endDayAccessor(d)))
.attr("y1", d => yScale(yAccessor(d)))
.attr("y2", d => yScale(yAccessor(d)))
.attr("stroke", "#004f5b")
.attr("stroke-width", "1px")
const startDots = bounds.selectAll("startCircle")
.data(data)
.join("circle")
.attr("cx", d => xScale(startDayAccessor(d)))
.attr("cy", d => yScale(yAccessor(d)))
.attr("r", 4)
.attr('fill', d => colorScale(colorAccessor(d)))
const endDots = bounds.selectAll("endCircle")
.data(data)
.join("circle")
.attr("cx", d => xScale(endDayAccessor(d)))
.attr("cy", d => yScale(yAccessor(d)))
.attr("r", 4)
.attr("fill", d => colorScale(colorAccessor(d)))
// extras
const xAxisGenerator = d3.axisBottom()
.scale(xScale)
const xAxis = bounds.append("g")
.call(xAxisGenerator)
.style("transform", `translateY(${dimensions.boundedHeight}px)`)
.style("stroke", "#004f5b")
// .selectAll("path, line").remove()
const xAxisLabel = xAxis.append("text")
.attr("class", "ae-x-axis-label")
.attr("x", dimensions.boundedWidth / 2)
.attr("y", dimensions.margin.bottom - 5)
.html("Study Day")
const yAxisGenerator = d3.axisLeft()
.scale(yScale)
// .tickFormat(d => d.AEDECOD)
const yAxis = bounds.append("g")
.call(yAxisGenerator)
return svg.node()
}