Skip to content
Snippets Groups Projects
Commit c43bc417 authored by Julia Friesel's avatar Julia Friesel
Browse files

Draws lines!

parent 3d12e5e4
No related branches found
No related tags found
No related merge requests found
...@@ -116,16 +116,20 @@ export default class DayColumn extends Component { ...@@ -116,16 +116,20 @@ export default class DayColumn extends Component {
let lineToRight let lineToRight
let lineToLeft let lineToLeft
function makeLine(leftY, rightY, leftX, excludeLine) { function makeLine(leftY, rightY, direction, excludeLine) {
const heightDiff = leftY - rightY const colWidth = config.columnWidth
const angle = Math.atan2(config.columnWidth, heightDiff) const heightDiff = -leftY - -rightY
const angle = Math.atan2(heightDiff, colWidth / 2)
const lineStyle = excludeLine ? styles.curveExcluded : styles.curve const lineStyle = excludeLine ? styles.curveExcluded : styles.curve
// hypotenuse // hypotenuse
const h = (config.columnWidth / 2) / Math.cos(angle) const h = (colWidth / 2) / Math.cos(angle)
const neededDiff = Math.sin(Math.PI - (angle + Math.PI / 2)) * (h / 2) // the rotation by default rotates from the middle of the line,
const projectedX = leftX - ((h / 2) - neededDiff) // but we want the transform origin to be at its beginning
console.log(leftX) // react native doesn't have transformOrigin, so we do this manually
console.log(projectedX) // if it's the right line, we put the pivot at 3/4 of the column
// if it's to the left, at 1/4
const pivot = direction === 'right' ? colWidth / 4 : -(colWidth / 4)
const projectedX = -(h - colWidth) / 2 + pivot
return (<View return (<View
width={h} width={h}
...@@ -133,9 +137,6 @@ export default class DayColumn extends Component { ...@@ -133,9 +137,6 @@ export default class DayColumn extends Component {
top={(leftY + rightY) / 2} top={(leftY + rightY) / 2}
left={projectedX} left={projectedX}
style={{ style={{
// the rotation by default rotates from the middle of the line,
// but we want the transform origin to be at its beginning
// react native doesn't have transformOrigin, so we do this manually
transform: [ transform: [
{rotateZ: `${angle}rad`} {rotateZ: `${angle}rad`}
], ],
...@@ -147,12 +148,12 @@ export default class DayColumn extends Component { ...@@ -147,12 +148,12 @@ export default class DayColumn extends Component {
if (this.props.leftY) { if (this.props.leftY) {
const middleY = ((this.props.leftY - currY) / 2) + currY const middleY = ((this.props.leftY - currY) / 2) + currY
const excludedLine = this.props.leftTemperatureExclude || exclude const excludedLine = this.props.leftTemperatureExclude || exclude
lineToLeft = makeLine(middleY, currY, 0, excludedLine) lineToLeft = makeLine(middleY, currY, 'left', excludedLine)
} }
if (this.props.rightY) { if (this.props.rightY) {
const middleY = ((currY - this.props.rightY) / 2) + this.props.rightY const middleY = ((currY - this.props.rightY) / 2) + this.props.rightY
const excludedLine = this.props.rightTemperatureExclude || exclude const excludedLine = this.props.rightTemperatureExclude || exclude
lineToRight = makeLine(currY, middleY, config.columnMiddle, excludedLine) lineToRight = makeLine(currY, middleY, 'right', excludedLine)
} }
const dotStyle = exclude ? styles.curveDotsExcluded : styles.curveDots const dotStyle = exclude ? styles.curveDotsExcluded : styles.curveDots
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment