WIP: lots of messy code for better timelines

This commit is contained in:
Lachlan Kermode
2020-04-03 18:14:15 +02:00
parent 421af5e60c
commit eac3eeaf93
9 changed files with 47 additions and 24 deletions

View File

@@ -81,14 +81,18 @@ class Timeline extends React.Component {
makeScaleY (categories, trackHeight, marginTop) {
const tickHeight = sizes.eventDotR * 2
const catHeight = trackHeight / (categories.length)
const shiftUp = trackHeight / (categories.length + 1) / 2
const catHeight = trackHeight / (categories.length)
const shiftUp = trackHeight / (categories.length) / 2
const marginShift = marginTop === 0 ? 0 : marginTop
const manualAdjustment = trackHeight <= 60 ? (trackHeight <= 30 ? -8 : -5) : 0
const catsYpos = categories.map((g, i) => ((i + 1) * catHeight) - shiftUp + marginShift + manualAdjustment)
return d3.scaleOrdinal()
.domain(categories)
.range(catsYpos)
const catsYpos = categories.map((g, i) => {
return ((i+1) * catHeight) - shiftUp + marginShift + manualAdjustment
})
const catMap = categories.map(c => c.category)
return (cat) => {
const idx = catMap.indexOf(cat)
return catsYpos[idx]
}
}
componentDidUpdate (prevProps, prevState) {