-
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: group gridY with tickY as axisY layer
Signed-off-by: Florian Amsallem <[email protected]>
- Loading branch information
1 parent
a639dcc
commit cc77094
Showing
8 changed files
with
99 additions
and
195 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
90 changes: 90 additions & 0 deletions
90
ui-speedspacechart/src/components/helpers/drawElements/axisY.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,90 @@ | ||
import type { DrawFunctionParams } from '../../../types/chartTypes'; | ||
import { MARGINS, TICK_TITLE_MARGINS } from '../../const'; | ||
import { clearCanvas, speedRangeValues } from '../../utils'; | ||
|
||
const { MARGIN_LEFT, MARGIN_TOP, MARGIN_BOTTOM, CURVE_MARGIN_TOP, MARGIN_RIGHT } = MARGINS; | ||
const { Y_LEFT_VERTICAL, Y_LEFT_HORIZONTAL } = TICK_TITLE_MARGINS; | ||
const TICK_WIDTH = 6; | ||
const TEXT_POSITION_X = 36; | ||
|
||
export const drawAxisY = ({ ctx, width, height, store }: DrawFunctionParams) => { | ||
const { maxSpeed } = speedRangeValues(store); | ||
|
||
clearCanvas(ctx, width, height); | ||
|
||
ctx.strokeStyle = 'rgb(121, 118, 113)'; | ||
ctx.lineWidth = 0.5; | ||
ctx.font = 'normal 12px IBM Plex Sans'; | ||
ctx.fillStyle = 'rgb(182, 178, 175)'; | ||
|
||
// Define the tick scale depending on the max speed | ||
let tickScale = 5; | ||
if (maxSpeed > 250) { | ||
tickScale = 30; | ||
} else if (maxSpeed > 130) { | ||
tickScale = 20; | ||
} else if (maxSpeed > 60) { | ||
tickScale = 10; | ||
} | ||
|
||
const nbTicks = Math.ceil(maxSpeed / tickScale); | ||
const maxTickSpeed = nbTicks * tickScale; | ||
const ratioRoundPositions = maxTickSpeed / maxSpeed; | ||
const ticksOffset = | ||
((height - MARGIN_BOTTOM - MARGIN_TOP - CURVE_MARGIN_TOP) * ratioRoundPositions) / nbTicks; | ||
|
||
// Draw ticks with text | ||
ctx.beginPath(); | ||
for (let i = 0; i <= nbTicks; i++) { | ||
const positionY = height - MARGIN_BOTTOM - ticksOffset * i; | ||
ctx.moveTo(MARGIN_LEFT - TICK_WIDTH, positionY); | ||
ctx.lineTo(MARGIN_LEFT, positionY); | ||
ctx.textAlign = 'right'; | ||
const text = (i * tickScale).toString(); | ||
const textPositionY = positionY + 4; | ||
|
||
ctx.fillStyle = `rgb(182, 178, 175 )`; | ||
ctx.fillText(text, TEXT_POSITION_X, textPositionY); | ||
} | ||
ctx.stroke(); | ||
|
||
// Draw major lines | ||
ctx.strokeStyle = 'rgba(33, 112, 185, 0.6)'; | ||
ctx.beginPath(); | ||
ctx.lineWidth = 0.5; | ||
for (let i = 3; i <= nbTicks; i += 3) { | ||
const positionY = height - MARGIN_BOTTOM - ticksOffset * i; | ||
ctx.moveTo(MARGIN_LEFT, positionY); | ||
ctx.lineTo(width - MARGIN_RIGHT, positionY); | ||
} | ||
ctx.stroke(); | ||
|
||
// Draw minor lines | ||
ctx.strokeStyle = 'rgba(33, 112, 185, 0.25)'; | ||
ctx.beginPath(); | ||
for (let i = 1; i <= nbTicks; i++) { | ||
if (i % 3 === 0) { | ||
continue; | ||
} | ||
const positionY = height - MARGIN_BOTTOM - ticksOffset * i; | ||
ctx.moveTo(MARGIN_LEFT, positionY); | ||
ctx.lineTo(width - MARGIN_RIGHT, positionY); | ||
} | ||
ctx.stroke(); | ||
|
||
// Prevent overlapping with margin top | ||
ctx.clearRect(0, 0, width, MARGIN_TOP); | ||
ctx.clearRect(MARGIN_LEFT - 6, height - MARGIN_BOTTOM, width, MARGIN_BOTTOM); | ||
ctx.clearRect(0, height - MARGIN_BOTTOM + 6, MARGIN_LEFT, MARGIN_BOTTOM); | ||
|
||
ctx.fillStyle = 'rgb(182, 179, 175)'; | ||
ctx.textAlign = 'center'; | ||
ctx.shadowOffsetY = 0; | ||
ctx.shadowBlur = 0; | ||
|
||
// Draw km/h axis title | ||
ctx.beginPath(); | ||
ctx.fillText('km/h', Y_LEFT_VERTICAL, Y_LEFT_HORIZONTAL); | ||
ctx.closePath(); | ||
ctx.stroke(); | ||
}; |
75 changes: 0 additions & 75 deletions
75
ui-speedspacechart/src/components/helpers/drawElements/gridY.ts
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
ui-speedspacechart/src/components/helpers/drawElements/tickY.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
export { default as AxisLayerX } from './AxisLayerX'; | ||
export { default as AxisLayerY } from './AxisLayerY'; | ||
export { default as CurveLayer } from './CurveLayer'; | ||
export { default as DeclivityLayer } from './DeclivityLayer'; | ||
export { default as ElectricalProfileLayer } from './ElectricalProfileLayer'; | ||
export { default as FrontInteractivityLayer } from './FrontInteractivityLayer'; | ||
export { default as MajorGridY } from './MajorGridY'; | ||
export { default as PowerRestrictionsLayer } from './PowerRestrictionsLayer'; | ||
export { default as ReticleLayer } from './ReticleLayer'; | ||
export { default as SpeedLimitTagsLayer } from './SpeedLimitTagsLayer'; | ||
export { default as StepLayer } from './StepLayer'; | ||
export { default as TickLayerX } from './TickLayerX'; | ||
export { default as TickLayerY } from './TickLayerY'; | ||
export { default as AxisLayerY } from './TickLayerY'; | ||
export { default as TickLayerYRight } from './TickLayerYRight'; |