-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
speedspacechart: setup speed limit layer
Signed-off-by: Florian Amsallem <florian.amsallem@gmail.com>
- Loading branch information
1 parent
e8013af
commit c792bf3
Showing
14 changed files
with
178 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
ui-speedspacechart/src/components/helpers/drawElements/speedLimits.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { DrawFunctionParams } from '../../../types/chartTypes'; | ||
import { ERROR_60, MARGINS } from '../../const'; | ||
import { clearCanvas, positionToPosX, maxPositionValue, maxSpeedValue } from '../../utils'; | ||
|
||
const { CURVE_MARGIN_TOP } = MARGINS; | ||
|
||
export const drawSpeedLimits = ({ ctx, width, height, store }: DrawFunctionParams) => { | ||
const { mrsp, trainLength, ratioX, leftOffset } = store; | ||
const maxSpeed = maxSpeedValue(store); | ||
|
||
clearCanvas(ctx, width, height); | ||
|
||
ctx.save(); | ||
ctx.translate(leftOffset, 0); | ||
|
||
const maxPosition = maxPositionValue(store); | ||
|
||
// TODO: draw speed limits | ||
ctx.beginPath(); | ||
ctx.lineWidth = 1; | ||
ctx.lineCap = 'round'; | ||
ctx.strokeStyle = ERROR_60.hex(); | ||
|
||
const adjustedHeight = height - CURVE_MARGIN_TOP; | ||
const y = height - (200 / maxSpeed) * adjustedHeight; | ||
const xStart = positionToPosX(0, maxPosition, width, ratioX); | ||
ctx.lineTo(xStart, y); | ||
const xEnd = positionToPosX(maxPosition, maxPosition, width, ratioX); | ||
ctx.lineTo(xEnd, y); | ||
ctx.stroke(); | ||
|
||
ctx.restore(); | ||
}; |
27 changes: 27 additions & 0 deletions
27
ui-speedspacechart/src/components/layers/SpeedLimitsLayer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
|
||
import type { Store } from '../../types/chartTypes'; | ||
import { drawSpeedLimits } from '../helpers/drawElements/speedLimits'; | ||
import { useCanvas } from '../hooks'; | ||
|
||
type SpeedLimitsLayerProps = { | ||
width: number; | ||
height: number; | ||
store: Store; | ||
}; | ||
|
||
const SpeedLimitsLayer = ({ width, height, store }: SpeedLimitsLayerProps) => { | ||
const canvas = useCanvas(drawSpeedLimits, { width, height, store }); | ||
|
||
return ( | ||
<canvas | ||
id="speed-limits-layer" | ||
className="absolute rounded-t-xl" | ||
ref={canvas} | ||
width={width} | ||
height={height} | ||
/> | ||
); | ||
}; | ||
|
||
export default SpeedLimitsLayer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.