-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/move-to-ssr
- Loading branch information
Showing
5 changed files
with
230 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
@use "../../styles/variables.scss"; | ||
|
||
.poll { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
gap: 8rem; | ||
padding: 2rem; | ||
|
||
&-chart { | ||
width: 50%; | ||
|
||
rect { | ||
stroke: variables.$black; | ||
stroke-width: 0.01rem; | ||
} | ||
} | ||
|
||
&-legend { | ||
span { | ||
display: block; | ||
} | ||
span::before { | ||
content: ""; | ||
display: inline-block; | ||
width: 2rem; | ||
height: 2rem; | ||
margin-right: 0.5rem; | ||
background-color: var(--marker-color); | ||
border: 0.2rem variables.$black solid; | ||
vertical-align: middle; | ||
} | ||
} | ||
} | ||
@media (max-width: variables.$screen-md-min) { | ||
.poll { | ||
flex-direction: column; | ||
gap: 2rem; | ||
|
||
&-chart { | ||
width: 80%; | ||
} | ||
|
||
&-legend { | ||
span::before { | ||
width: 1rem; | ||
height: 1rem; | ||
} | ||
} | ||
} | ||
} |
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,60 @@ | ||
import type { TelegramMessagePoll } from "~/service/Parser"; | ||
import "./MediaPoll.scss"; | ||
|
||
// colorblind-friendly colors | ||
// and Telegram has maximum of 10 options | ||
const colors = [ | ||
"#1F77B4", // Strong Blue | ||
"#FF7F0E", // Strong Orange | ||
"#2CA02C", // Strong Green | ||
"#D62728", // Strong Red | ||
"#9467BD", // Strong Purple | ||
"#8C564B", // Strong Brown | ||
"#E377C2", // Strong Pink | ||
"#7F7F7F", // Medium Gray | ||
"#BCBD22", // Strong Yellow | ||
"#17BECF", // Strong Cyan | ||
]; | ||
|
||
export function MediaPoll(props: TelegramMessagePoll) { | ||
const chartSize = 20; | ||
const barWidth = 20 / props.pollResult.length; | ||
|
||
const maxVotes = Math.max(...props.pollResult.map((opt) => opt.votes)); | ||
const normalizeVotes = (vote: number) => (vote / maxVotes) * chartSize * /* provide some top padding */ 0.8; | ||
|
||
return ( | ||
<div class="poll"> | ||
<svg class="poll-chart" xmlns="http://www.w3.org/2000/svg" viewBox={`0 0 ${chartSize} ${chartSize}`}> | ||
<title innerHTML={props.text} /> | ||
|
||
<g class="poll-bars"> | ||
{props.pollResult.map((option, i) => ( | ||
<> | ||
<rect | ||
x={i * barWidth} | ||
y={chartSize - normalizeVotes(option.votes)} | ||
height={normalizeVotes(option.votes)} | ||
width={barWidth} | ||
fill={colors[i] ?? "#7f7f7f"} | ||
/> | ||
<text | ||
x={i * barWidth + barWidth / 2} | ||
y={chartSize - normalizeVotes(option.votes) - 2} | ||
font-size="0.14rem" | ||
text-anchor="middle" | ||
> | ||
{option.votes} | ||
</text> | ||
</> | ||
))} | ||
</g> | ||
</svg> | ||
<div class="poll-legend"> | ||
{props.pollResult.map((option, i) => ( | ||
<span style={{ "--marker-color": colors[i] }}>{option.text}</span> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} |
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