-
-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathsolarToHome.ts
More file actions
54 lines (52 loc) · 2.51 KB
/
solarToHome.ts
File metadata and controls
54 lines (52 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { classMap } from "lit/directives/class-map.js";
import { PowerFlowCardPlusConfig } from "@/power-flow-card-plus-config";
import { showLine } from "@/utils/showLine";
import { html, svg } from "lit";
import { styleLine } from "@/utils/styleLine";
import { type Flows } from "./index";
import { checkHasBottomIndividual, checkHasRightIndividual } from "@/utils/computeIndividualPosition";
import { checkShouldShowDots } from "@/utils/checkShouldShowDots";
import { checkFlowDotsCount } from "@/utils/checkFlowDotsCount";
export const flowSolarToHome = (config: PowerFlowCardPlusConfig, { battery, grid, individual, solar, newDur }: Flows) => {
return solar.has && showLine(config, solar.state.toHome || 0) && !config.entities.home?.hide
? html`<div
class="lines ${classMap({
high: battery.has || checkHasBottomIndividual(individual),
"individual1-individual2": !battery.has && individual.every((i) => i?.has),
"multi-individual": checkHasRightIndividual(individual),
})}"
>
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" id="solar-home-flow">
<path
id="solar"
class="solar ${styleLine(solar.state.toHome || 0, config)}"
d="M${battery.has ? 55 : 53},0 v${grid.has ? 15 : 17} c0,${battery.has ? "30 10,30 30,30" : "35 10,35 30,35"} h25"
vector-effect="non-scaling-stroke"
></path>
${checkShouldShowDots(config) && solar.state.toHome
? svg`${Array.from({ length: checkFlowDotsCount(config) ?? 1 }).map((_, i) => {
const n = checkFlowDotsCount(config) ?? 1;
const start = i / n;
const end = (i + 1) / n;
return svg`
<circle
r="1"
class="solar"
vector-effect="non-scaling-stroke"
>
<animateMotion
dur="${newDur.solarToHome / n}s"
keyTimes="0;1;1"
keyPoints="${(i) / n} ; ${(i+1) / n}; ${(i) / n}"
repeatCount="indefinite"
calcMode="linear"
>
<mpath xlink:href="#solar" />
</animateMotion>
</circle>`
})}`
: ""}
</svg>
</div>`
: "";
};