Refactoring
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
f50abec60f
commit
17e604a03f
|
|
@ -50,12 +50,14 @@ void dow_get_text_item_rect(GxEPD2_BW<GxEPD2_583_GDEQ0583T31, GxEPD2_583_GDEQ058
|
|||
{
|
||||
case ITEM_ALIGN_CENTER:
|
||||
{
|
||||
y += tby;
|
||||
y += round((double)h / 2);
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_ALIGN_START:
|
||||
{
|
||||
y += tby;
|
||||
y += h;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,22 +3,10 @@ import { route } from '../route'
|
|||
import { router } from '../router'
|
||||
import { calendarService } from '../services/calendar'
|
||||
import { weatherService } from '../services/weather'
|
||||
// import { getSunrise, getSunset } from 'sunrise-sunset-js'
|
||||
|
||||
const TYPES = {
|
||||
TEXT: 0,
|
||||
LINE: 1,
|
||||
CIRCLE: 2,
|
||||
CIRCLE_FILL: 3,
|
||||
RECT: 4,
|
||||
RECT_FILL: 5,
|
||||
}
|
||||
|
||||
const ALIGN = {
|
||||
START: 0,
|
||||
CENTER: 1,
|
||||
END: 2,
|
||||
}
|
||||
import { TYPES } from '../../lib/dow/constants'
|
||||
import { ALIGN } from '../../lib/dow/constants'
|
||||
import { DowWidget } from '../../lib/dow/constants'
|
||||
import { rectangleWithTitle } from '../../lib/dow/widgets/rectangleWithTitle'
|
||||
|
||||
const weekdaysInCs = [
|
||||
'Pondeli',
|
||||
|
|
@ -37,18 +25,6 @@ const CALENDARS = [
|
|||
'primary',
|
||||
]
|
||||
|
||||
type Widget = {
|
||||
x: number
|
||||
y: number
|
||||
x2?: number
|
||||
y2?: number
|
||||
c?: string
|
||||
t: number
|
||||
va?: number
|
||||
ha?: number
|
||||
f?: number
|
||||
}
|
||||
|
||||
export const dowRoutes = router((router, ctx) => {
|
||||
router.get(
|
||||
'/',
|
||||
|
|
@ -91,7 +67,7 @@ export const dowRoutes = router((router, ctx) => {
|
|||
summary = summary.replace(/_day|_night/, '')
|
||||
}
|
||||
|
||||
const widgets: Widget[] = [
|
||||
const widgets: DowWidget[] = [
|
||||
{
|
||||
x: WIDTH / 2,
|
||||
y: 30,
|
||||
|
|
@ -220,31 +196,17 @@ export const dowRoutes = router((router, ctx) => {
|
|||
const tempGraphP = 10
|
||||
const tempGraphW = tempW - tempGraphP * 2
|
||||
|
||||
widgets.push({
|
||||
widgets.push(
|
||||
...rectangleWithTitle({
|
||||
x: tempX,
|
||||
y: tempY - 40,
|
||||
x2: tempW,
|
||||
y2: tempH,
|
||||
t: TYPES.RECT,
|
||||
})
|
||||
|
||||
widgets.push({
|
||||
x: tempX,
|
||||
y: tempY - 20,
|
||||
x2: tempX + tempW,
|
||||
y2: tempY - 20,
|
||||
t: TYPES.LINE,
|
||||
})
|
||||
|
||||
widgets.push({
|
||||
x: Math.floor(tempX + tempW / 2),
|
||||
y: tempY - 30,
|
||||
t: TYPES.TEXT,
|
||||
ha: ALIGN.CENTER,
|
||||
va: ALIGN.CENTER,
|
||||
c: 'Teplota',
|
||||
f: 3,
|
||||
})
|
||||
width: tempW,
|
||||
height: tempH,
|
||||
title: 'Teplota',
|
||||
titleHeight: 20,
|
||||
titleFont: 3,
|
||||
}),
|
||||
)
|
||||
|
||||
for (const [offset, hour] of next12Hours) {
|
||||
const offsetInt = +offset
|
||||
|
|
@ -312,31 +274,17 @@ export const dowRoutes = router((router, ctx) => {
|
|||
const preGraphP = 10
|
||||
const preGraphW = preW - preGraphP * 2
|
||||
|
||||
widgets.push({
|
||||
widgets.push(
|
||||
...rectangleWithTitle({
|
||||
x: preX,
|
||||
y: preY - 40,
|
||||
x2: preW,
|
||||
y2: preH,
|
||||
t: TYPES.RECT,
|
||||
})
|
||||
|
||||
widgets.push({
|
||||
x: preX,
|
||||
y: preY - 20,
|
||||
x2: preX + preW,
|
||||
y2: preY - 20,
|
||||
t: TYPES.LINE,
|
||||
})
|
||||
|
||||
widgets.push({
|
||||
x: Math.floor(preX + preW / 2),
|
||||
y: preY - 30,
|
||||
t: TYPES.TEXT,
|
||||
ha: ALIGN.CENTER,
|
||||
va: ALIGN.CENTER,
|
||||
c: 'Dest',
|
||||
f: 3,
|
||||
})
|
||||
width: preW,
|
||||
height: preH,
|
||||
title: 'Srazky',
|
||||
titleHeight: 20,
|
||||
titleFont: 3,
|
||||
}),
|
||||
)
|
||||
|
||||
for (const [offset, hour] of next12Hours) {
|
||||
const offsetInt = +offset
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
export type DowWidget = {
|
||||
x: number
|
||||
y: number
|
||||
x2?: number
|
||||
y2?: number
|
||||
c?: string
|
||||
t: DowWidgetType
|
||||
va?: DowWidgetAlign
|
||||
ha?: DowWidgetAlign
|
||||
f?: number
|
||||
co?: DowWidgetColor
|
||||
}
|
||||
|
||||
export type DowWidgetType = (typeof TYPES)[keyof typeof TYPES]
|
||||
|
||||
export const TYPES = {
|
||||
TEXT: 0,
|
||||
LINE: 1,
|
||||
CIRCLE: 2,
|
||||
CIRCLE_FILL: 3,
|
||||
RECT: 4,
|
||||
RECT_FILL: 5,
|
||||
} as const
|
||||
|
||||
export type DowWidgetAlign = (typeof ALIGN)[keyof typeof ALIGN]
|
||||
|
||||
export const ALIGN = {
|
||||
START: 0,
|
||||
CENTER: 1,
|
||||
END: 2,
|
||||
} as const
|
||||
|
||||
export type DowWidgetColor = (typeof COLORS)[keyof typeof COLORS]
|
||||
|
||||
export const COLORS = {
|
||||
BLACK: 0,
|
||||
WHITE: 1,
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import { DowWidget } from './constants'
|
||||
|
||||
export const defineWidget = <TOptions, TResult extends DowWidget | DowWidget[]>(
|
||||
factory: (options: TOptions) => TResult,
|
||||
) => {
|
||||
return factory
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import { DowWidgetColor, TYPES } from '../constants'
|
||||
import { defineWidget } from '../defineWidget'
|
||||
|
||||
type Options = {
|
||||
x: number
|
||||
y: number
|
||||
x2: number
|
||||
y2: number
|
||||
color?: DowWidgetColor
|
||||
}
|
||||
|
||||
export const line = defineWidget(({ x, y, x2, y2, color }: Options) => ({
|
||||
x,
|
||||
y,
|
||||
x2,
|
||||
y2,
|
||||
t: TYPES.LINE,
|
||||
co: color,
|
||||
}))
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import { DowWidgetColor, TYPES } from '../constants'
|
||||
import { defineWidget } from '../defineWidget'
|
||||
|
||||
type Options = {
|
||||
x: number
|
||||
y: number
|
||||
width: number
|
||||
height: number
|
||||
filled?: boolean
|
||||
color?: DowWidgetColor
|
||||
}
|
||||
|
||||
export const rectangle = defineWidget(
|
||||
({ x, y, width, height, filled, color }: Options) => ({
|
||||
x,
|
||||
y,
|
||||
x2: width,
|
||||
y2: height,
|
||||
t: filled ? TYPES.RECT_FILL : TYPES.RECT,
|
||||
co: color,
|
||||
}),
|
||||
)
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
import { DowWidgetAlign, DowWidgetColor, TYPES } from '../constants'
|
||||
import { defineWidget } from '../defineWidget'
|
||||
|
||||
type Options = {
|
||||
x: number
|
||||
y: number
|
||||
text: string
|
||||
font: number
|
||||
verticalAlign?: DowWidgetAlign
|
||||
horizontalAlign?: DowWidgetAlign
|
||||
color?: DowWidgetColor
|
||||
}
|
||||
|
||||
export const text = defineWidget(
|
||||
({ x, y, text, font, verticalAlign, horizontalAlign, color }: Options) => ({
|
||||
x,
|
||||
y,
|
||||
t: TYPES.TEXT,
|
||||
c: text,
|
||||
va: verticalAlign,
|
||||
ha: horizontalAlign,
|
||||
f: font,
|
||||
co: color,
|
||||
}),
|
||||
)
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import { ALIGN, DowWidget } from '../constants'
|
||||
import { defineWidget } from '../defineWidget'
|
||||
import { line } from '../primitives/line'
|
||||
import { rectangle } from '../primitives/rectangle'
|
||||
import { text } from '../primitives/text'
|
||||
|
||||
type Options = {
|
||||
x: number
|
||||
y: number
|
||||
width: number
|
||||
height: number
|
||||
title: string
|
||||
titleHeight: number
|
||||
titleFont: number
|
||||
}
|
||||
|
||||
export const rectangleWithTitle = defineWidget(
|
||||
({ x, y, width, height, title, titleFont, titleHeight }: Options) => {
|
||||
const result = [] as DowWidget[]
|
||||
|
||||
result.push(rectangle({ x, y, width, height }))
|
||||
|
||||
result.push(
|
||||
line({ x, y: y + titleHeight, x2: x + width, y2: y + titleHeight }),
|
||||
)
|
||||
|
||||
result.push(
|
||||
text({
|
||||
x: Math.floor(x + width / 2),
|
||||
y: y + titleHeight / 2,
|
||||
horizontalAlign: ALIGN.CENTER,
|
||||
verticalAlign: ALIGN.CENTER,
|
||||
text: title,
|
||||
font: titleFont,
|
||||
}),
|
||||
)
|
||||
|
||||
return result
|
||||
},
|
||||
)
|
||||
Loading…
Reference in New Issue