Skip to content

Commit

Permalink
Merge pull request #36 from puripant/master
Browse files Browse the repository at this point in the history
Create a basic waffle chart
  • Loading branch information
rapee authored Oct 28, 2019
2 parents 322b4d7 + 48a36b9 commit 085d493
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 112 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

- [Development](#development)
- [Getting Started for Contributers](#getting-started-for-contributers)
- [Design & Architecture](#design--architecture)
- [Reference](#reference)
- [Design & Architecture](#design--architecture)
- [Data Dictionary](#data-dictionary)
- [Glossary](#glossary)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
Expand Down
210 changes: 120 additions & 90 deletions src/components/voteLogCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,98 +3,128 @@ import moment from "moment"

import "../styles/global.css"


const VoteLogCard = ({ legal_title, legal_title_en, passed, approve, disprove, abstained, absent, total_voter, vote_date }) => {
const resultColor = passed ? "green" : "red"
const approveBar = approve * 100 / total_voter + "%"
const disproveBar = disprove * 100 / total_voter + "%"
const abstainedBar = abstained * 100 / total_voter + "%"
return (

const VoteLogCard = ({
legal_title,
legal_title_en,
passed,
approve,
disprove,
abstained,
absent,
total_voter,
vote_date,
}) => {
const resultColor = passed ? "green" : "red"
const approveBar = (approve * 100) / total_voter + "%"
const disproveBar = (disprove * 100) / total_voter + "%"
const abstainedBar = (abstained * 100) / total_voter + "%"
return (
<div
style={{
marginBottom: "1.08rem",
display: "flex",
flexDirection: "column",
width: "33%",
minWidth: "400px",
minHeight: "350px",
padding: "2rem",
borderRadius: "10px",
backgroundColor: "var(--cl-white)",
color: "var(--cl-black)",
}}
>
<div
style={{
width: "100%",
height: "1.5rem",
}}
>
<div
style={{
width: approveBar,
height: "100%",
backgroundColor: "green",
display: "inline-block",
border: "1px solid var(--cl-black)",
}}
/>
<div
style={{
width: disproveBar,
height: "100%",
backgroundColor: "#404040",
display: "inline-block",
border: "1px solid var(--cl-black)",
}}
/>
<div
style={{
width: abstainedBar,
height: "100%",
backgroundColor: "lightgray",
display: "inline-block",
border: "1px solid var(--cl-black)",
}}
/>
</div>
<h2
style={{
color: "var(--cl-black)",
textAlign: "left",
marginTop: "2rem",
}}
>
{parseInt((approve / total_voter) * 100)}% เห็นด้วย
</h2>
<h3
style={{
fontSize: "2.5rem",
paddingTop: "1rem",
lineHeight: "3rem",
}}
>
{legal_title}
</h3>
<p
style={{
paddingTop: "1rem",
}}
>
{legal_title_en}
</p>
<div style={{ display: "inline" }}>
<div
style={{
borderRadius: "50%",
backgroundColor: resultColor,
width: "15px",
height: "15px",
display: "inline-block",
}}
/>{" "}
<div
style={{
marginBottom: "1.08rem",
display: "flex",
flexDirection: "column",
width: "33%",
minWidth: "400px",
minHeight: "350px",
padding: "2rem",
borderRadius: "10px",
backgroundColor: "var(--cl-white)",
color: "var(--cl-black)",
}}
style={{
fontFamily: "var(--ff-text)",
fontSize: "3rem",
fontWeight: "bold",
color: resultColor,
display: "inline-block",
}}
>
<div style={{
width: "100%",
height: "1.5rem",
}}>
<div style={{
width: approveBar,
height: "100%",
backgroundColor: "green",
display: "inline-block",
border: "1px solid var(--cl-black)",
}} />
<div style={{
width: disproveBar,
height: "100%",
backgroundColor: "#404040",
display: "inline-block",
border: "1px solid var(--cl-black)",
}} />
<div style={{
width: abstainedBar,
height: "100%",
backgroundColor: "lightgray",
display: "inline-block",
border: "1px solid var(--cl-black)",
}} />
</div>
<h2
style={{
color: "var(--cl-black)",
textAlign: "left",
marginTop: "2rem"
}}>{parseInt(approve / total_voter * 100)}% เห็นด้วย</h2>
<h3
style={{
fontSize: "2.5rem",
paddingTop: "1rem",
lineHeight: "3rem"
}}>{legal_title}</h3>
<p
style={{
paddingTop: "1rem"
}}>
{legal_title_en}
</p>
<div style={{display: "inline"}}>
<div style={{
borderRadius: "50%",
backgroundColor: resultColor,
width: "15px",
height: "15px",
display: "inline-block"
}} /> {" "}
<div
style={{
fontFamily: "var(--ff-text)",
fontSize: "3rem",
fontWeight: "bold",
color: resultColor,
display: "inline-block"
}}>
{passed ? "ผ่าน" : "ไม่ผ่าน"}
</div>
</div>
<p style={{
paddingTop: "1rem"
}}>
เห็นด้วย {approve} ไม่เห็นด้วย {disprove} งดออกเสียง {abstained}
</p>
<h3 style={{ fontSize: "2rem"}}>{moment(vote_date).format("D.M.YYYY")}</h3>
{passed ? "ผ่าน" : "ไม่ผ่าน"}
</div>
)
</div>
<p
style={{
paddingTop: "1rem",
}}
>
เห็นด้วย {approve} ไม่เห็นด้วย {disprove} งดออกเสียง {abstained}
</p>
<h3 style={{ fontSize: "2rem" }}>
{moment(vote_date).format("D.M.YYYY")}
</h3>
</div>
)
}
export default VoteLogCard
16 changes: 13 additions & 3 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Layout from "../components/layout"
import SEO from "../components/seo"
import Button from "../components/button"
import Hero from "../components/hero"
import VoteLogCard from "../components/voteLogCard";
import VoteLogCard from "../components/voteLogCard"

export const query = graphql`
query {
Expand Down Expand Up @@ -134,8 +134,18 @@ const IndexPage = ({ data }) => (
>
<div className="container">
<h2 css={{ ...cssH1 }}>สรุปผลการลงมติล่าสุด</h2>
<div style={{marginTop: "6rem"}}>
<VoteLogCard legal_title="ร่างข้อบังคับการประชุมสภาผู้แทนราษฎพ.ศ. ซึ่งคณะกกรมาธิการวิสามัญพิจารณาเสร็จแล้ว" legal_title_en="The Democrat Party is a Thail political party. The oldest party in Thailand, it was founded as a conservative and royalist party, and now upholds a conservative-" passed={false} approve={101} disprove={365} abstained={13}absent={0} total_voter={479} vote_date="2019-08-22" />
<div style={{ marginTop: "6rem" }}>
<VoteLogCard
legal_title="ร่างข้อบังคับการประชุมสภาผู้แทนราษฎพ.ศ. ซึ่งคณะกกรมาธิการวิสามัญพิจารณาเสร็จแล้ว"
legal_title_en="The Democrat Party is a Thail political party. The oldest party in Thailand, it was founded as a conservative and royalist party, and now upholds a conservative-"
passed={false}
approve={101}
disprove={365}
abstained={13}
absent={0}
total_voter={479}
vote_date="2019-08-22"
/>
</div>
</div>
</section>
Expand Down
99 changes: 81 additions & 18 deletions src/pages/representatives.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,88 @@
import React from "react"
import { graphql, Link } from "gatsby"

import Layout from "../components/layout"
import SEO from "../components/seo"
import "./waffle.css"

const RepresentativesPage = () => (
<Layout
pageStyles={{
background: "#ccccff",
}}
>
<SEO title="สมาชิกสภาผู้แทนราษฎรไทย" />
<h1
css={{
marginTop: 0,
paddingTop: "6rem",
}}
>
สมาชิกสภาผู้แทนราษฎรไทย
</h1>
<h2>House of Representatives</h2>
</Layout>
)
export const query = graphql`
query {
allPeopleYaml {
totalCount
edges {
node {
id
fields {
slug
}
title
name
lastname
cabinet_position
prev_polit_pos
is_cabinet
is_senator
is_mp
}
}
}
}
`

const full_name = node => `${node.title}${node.name} ${node.lastname}`

const split_array = (array, size, callback) =>
Array(Math.ceil(array.length / size))
.fill()
.map((_, index) => index * size)
.map(start => array.slice(start, start + size))
.map(callback)

const waffle = (data, cls) =>
split_array(data, 100, hundred => (
<div class="hundred">
{split_array(hundred, 25, quarter => (
<div class="quarter">
{quarter.map(({ node }) => (
<div title={full_name(node)} class={cls}>
{/* <Link to={node.fields.slug}>{full_name(node)}</Link> */}
</div>
))}
</div>
))}
</div>
))

const RepresentativesPage = ({ data }) => {
let prop_of_interest = {
prop: `is_cabinet`,
name: "รัฐมนตรี",
}
let data_of_interest = data.allPeopleYaml.edges.filter(
({ node }) => node[prop_of_interest.prop]
)
let data_the_rest = data.allPeopleYaml.edges.filter(
({ node }) => !node[prop_of_interest.prop]
)

return (
<Layout>
<SEO title="สมาชิกสภาผู้แทนราษฎรไทย" />
<h1>สัดส่วนผู้แทนของเรา พวกเขาเป็นใครบ้าง</h1>
<h2>
{(
(100 * data_of_interest.length) /
data.allPeopleYaml.edges.length
).toFixed(2)}
% ของผู้แทนในสภาทั้งหมดเป็น{prop_of_interest.name}
</h2>
<div class="waffle">
{waffle(data_of_interest, "person of-interest")}
<div class="line"></div>
{waffle(data_the_rest, "person other")}
</div>
</Layout>
)
}

export default RepresentativesPage
Loading

0 comments on commit 085d493

Please sign in to comment.