svelte-hemicycle
v2.1.0
Published
[![NPM](https://img.shields.io/npm/v/svelte-hemicycle.svg)](https://www.npmjs.com/package/svelte-hemicycle)
Downloads
10
Maintainers
Readme
Svelte Hemicycle
A data visualisation for the South African elections as a Svelte component. It accepts data as a JSON property from the IEC's NPE Seat Calculation Results API and renders a hemicycle chart.
Demo
See the hemicycle with South African national elections data here
Installation
npm install svelte-hemicycle
Usage
<script>
import Hemicycle from 'svelte-hemicycle';
const data = [
{
"id": 1,
"text": "UDFMP",
"count": 160,
"color": "#FF0000"
},
{
"id": 2,
"text": "PDMF",
"count": 150,
"color": "#00FF00"
},
{
"id": 3,
"text": "DA",
"count": 40,
"color": "#0000FF"
},
{
"id": 4,
"text": "PDP",
"count": 30,
"color": "#FFFF00"
},
{
"id": 5,
"text": "APC",
"count": 20,
"color": "#00FFFF"
}
]
const total_seats = 400;
const rows= 12;
</script>
<Hemicycle {data} {total_seats} {rows} />
API
data
The data to display on the hemicycle. This is an array of objects, each representing a party or group of seats.
Required.
data = [{
"id": 1, // Unique identifier
"text": "UDFMP (60 seats)", // Text to display on the hemicycle
"count": 60, // Number of seats
"color": "#FF0000" // Colour of the hemicycle segment
}]
total_seats
The total number of seats in the legislature. This can be greater than the total number of seats in the data.
Required.
total_seats = 400;
r
The radius of the hemicycle.
Default: 300
r = 300;
rows
The number of rows of seats to display.
Default: 12
rows = 12;
dotsize
The size of the dots representing seats.
Default: 5
arc
The angle of the hemicycle, in degrees.
Default: 180 Minimum: 10 Maximum: 360
padding
The padding between the hemicycle and the edge of the SVG.
padding = 30;
padding = [30, 30]; // top, bottom
padding = [30, 30, 30, 30]; // top, right, bottom, left
color
The colour of the text and optional markings.
Default: "white"
font_size
The font size of the text.
Default: 12
text_position
The position of the text.
Defaults to center.
text_position = {
x: 0,
y: 0
}
display
An array of strings representing what to display on the hemicycle.
Defaults to ["points", "text"]
"points" - Display the dots of seats "text" - Display the text on mouseover and click "arc" - Display the arcs of the hemicycle "numbers" - Display the seats in order "voronoi" - Display the voronoi diagram "referencePoints" - Display some reference points
display = ["points", "text"]; // Default
display = ["points", "text", "arc", "numbers", "voronoi", "referencePoints"]; // All
shape
Choose between circle and hexagon.
Default: "circle"
shape = "circle";
shape = "hexagon";
stroke
The colour of the stroke around the shapes (Currently hexagon only).
default: "#444444"
stroke = "white";
display_width and display_height
The width and height of the SVG.
Default: 600w x 300h
Tip: For 180 degree arcs, you might want to set the height as half the width. For acute or obtuse angles, you might want to tend towards square.
display_width = 600;
display_height = 300;
License
MIT
Copyright 2024 Jason Norwood-Young
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.