{"id":13827847,"url":"https://github.com/juliuste/parliament-svg","last_synced_at":"2025-04-06T06:07:54.507Z","repository":{"id":46572713,"uuid":"74207222","full_name":"juliuste/parliament-svg","owner":"juliuste","description":"Generate parliament charts as virtual-dom SVG","archived":false,"fork":false,"pushed_at":"2021-10-05T09:29:34.000Z","size":233,"stargazers_count":185,"open_issues_count":1,"forks_count":16,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-05-02T06:16:27.628Z","etag":null,"topics":["election","hacktoberfest","library"],"latest_commit_sha":null,"homepage":"https://juliuste.github.io/parliament-svg/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juliuste.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-19T12:29:06.000Z","updated_at":"2024-02-03T19:17:39.000Z","dependencies_parsed_at":"2022-08-26T01:10:14.038Z","dependency_job_id":null,"html_url":"https://github.com/juliuste/parliament-svg","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fparliament-svg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fparliament-svg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fparliament-svg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fparliament-svg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juliuste","download_url":"https://codeload.github.com/juliuste/parliament-svg/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247441049,"owners_count":20939239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["election","hacktoberfest","library"],"created_at":"2024-08-04T09:02:15.318Z","updated_at":"2025-04-06T06:07:54.482Z","avatar_url":"https://github.com/juliuste.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# parliament-svg\n\nGenerate parliament charts as **[_hast_](https://github.com/syntax-tree/hast) virtual DOM SVG\\***. Design inspired by the [Wikipedia parliament charts](https://github.com/slashme/parliamentdiagram). *Play around with the [__live demo__](https://juliuste.github.io/parliament-svg/)!* For westminster-style parliament charts, see [westminster-svg](https://github.com/juliuste/westminster-svg). If you are using [D3](https://github.com/d3/d3/), you might prefer working with the [d3-parliament](https://github.com/geoffreybr/d3-parliament) module.\n\n\\*Also compatible with other virtual DOM implementations, see the [docs below](#Usage).\n\n[![npm version](https://img.shields.io/npm/v/parliament-svg.svg)](https://www.npmjs.com/package/parliament-svg)\n[![License](https://img.shields.io/github/license/juliuste/parliament-svg.svg?style=flat)](license)\n[![Contact me](https://img.shields.io/badge/contact-email-turquoise)](mailto:mail@juliustens.eu)\n\n## Installation\n\n**This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): Node 12+ is needed to use it and it must be `import`ed instead of `require`d.**\n\n```shell\nnpm install --save parliament-svg\n```\n\n## Usage\n\n```js\nimport parliamentSVG from 'parliament-svg'\n\nconst virtualSvg = parliamentSVG(parties, [opt])\n```\n\n- **`opt`** can contain the following options:\n  - **`seatCount`** is a boolean, if `true` the total seat count will be displayed in the chart. Defaults to `false`.\n  - **`hFunction`** is a function that will be used to generate the element tree. Defaults to [`hastscript`](https://github.com/syntax-tree/hastscript/)'s `s()` function, custom values need to match that function's signature. You could use [`virtual-hyperscript-svg`](https://github.com/substack/virtual-hyperscript-svg)'s `h()` function here if you prefer working with [`virtual-dom`](https://github.com/Matt-Esch/virtual-dom), for example.\n- **`parties`** is an object containing seat count and colour for each party, e.g.:\n\n```json\n{\n\t\"linke\": {\n\t\t\"seats\": 64,\n\t\t\"colour\": \"#a08\"\n\t},\n\t\"spd\": {\n\t\t\"seats\": 193,\n\t\t\"colour\": \"#e02\"\n\t},\n\t\"gruene\": {\n\t\t\"seats\": 63,\n\t\t\"colour\": \"#0b2\"\n\t},\n\t\"union\": {\n\t\t\"seats\": 311,\n\t\t\"colour\": \"#333\"\n\t}\n}\n```\nEach seat contains the party name in its `class` attribute.\n\nFor the given `parties` object and `seatCount` enabled, the rendered result should look as follows:\n\n![Example: German Bundestag with seat count enabled](https://rawgit.com/juliuste/parliament-svg/main/example/seatCount.svg)\n\nIf you want to convert the [_hast_](https://github.com/syntax-tree/hast) tree to an SVG string, use `hast-util-to-html` (don't get confused by the name, the library can also stringify SVG):\n\n```js\nimport parliamentSVG from 'parliament-svg'\nimport { toHtml as toSvg } from 'hast-util-to-html'\n\nconst virtualSvg = parliamentSVG(parties, seatCount)\nconst svg = toSvg(virtualSvg)\n```\n\nCheck the [`code example`](example/example.js) as well.\n\n### What if I prefer virtual-dom (or anything else)?\n\nIf you prefer [`virtual-dom`](https://github.com/Matt-Esch/virtual-dom) over `hast`, e.g. for diffing or patching, you can either:\n- use [`hast-to-hyperscript`](https://github.com/syntax-tree/hast-to-hyperscript) to transform the tree after it was generated _or_\n- use the [`hFunction`](#Usage) parameter documented above with a virtual-dom `h()` function of your choice\n\n## See also\n\n- [westminster-svg](https://github.com/juliuste/westminster-svg) - \"westminster-style parliament charts\"\n- [d3-parliament](https://github.com/geoffreybr/d3-parliament) - \"parliament charts for [D3](https://github.com/d3/d3/)\"\n- [wikidata-parliament-svg](https://github.com/k-nut/wikidata-parliament-svg) - \"draws parliament graphs based on data from wikidata\"\n\n## Contributing\n\nIf you found a bug or want to propose a feature, feel free to visit [the issues page](https://github.com/juliuste/parliament-svg/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliuste%2Fparliament-svg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliuste%2Fparliament-svg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliuste%2Fparliament-svg/lists"}