{"id":14036378,"url":"https://github.com/juliuste/westminster-svg","last_synced_at":"2025-04-08T03:34:58.160Z","repository":{"id":22937315,"uuid":"97727085","full_name":"juliuste/westminster-svg","owner":"juliuste","description":"Generate westminster parliament charts as virtual-dom SVG.","archived":false,"fork":false,"pushed_at":"2021-10-05T10:50:59.000Z","size":190,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-02T06:16:29.038Z","etag":null,"topics":["election","library"],"latest_commit_sha":null,"homepage":"https://juliuste.github.io/westminster-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":"2017-07-19T14:38:04.000Z","updated_at":"2024-03-04T18:27:34.000Z","dependencies_parsed_at":"2022-07-27T03:47:08.660Z","dependency_job_id":null,"html_url":"https://github.com/juliuste/westminster-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%2Fwestminster-svg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fwestminster-svg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fwestminster-svg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fwestminster-svg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juliuste","download_url":"https://codeload.github.com/juliuste/westminster-svg/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223300903,"owners_count":17122712,"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","library"],"created_at":"2024-08-12T03:01:56.722Z","updated_at":"2024-11-06T07:33:09.157Z","avatar_url":"https://github.com/juliuste.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# westminster-svg\n\nGenerate westminster 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/westminster-svg/)!* For \"normal\" parliament charts, see **[parliament-svg](https://github.com/juliuste/parliament-svg)**.\n\n\\*Also compatible with other virtual DOM implementations, see the [docs below](#Usage).\n\n[![npm version](https://img.shields.io/npm/v/westminster-svg.svg)](https://www.npmjs.com/package/westminster-svg)\n[![License](https://img.shields.io/github/license/juliuste/westminster-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 westminster-svg\n```\n\n## Usage\n\n```js\nimport westminsterSVG from 'westminster-svg'\n\nconst virtualSvg = westminsterSVG(parliament, [opt])\n```\n\n- **`opt`** can contain the following options:\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- **`parliament`** is an object containing party information for all four 'sides' of the parliament: `headBench`, `left`, `crossBench` and `right`. After the [2017 UK general election](https://en.wikipedia.org/wiki/United_Kingdom_general_election,_2017) it should look as follows:\n\n```js\n{\n\theadBench: {\n\t\tspeaker: {\n\t\t\tseats: 1,\n\t\t\tcolour: '#000'\n\t\t}\n\t},\n\tleft: {\n\t\tlabour: {\n\t\t\tseats: 262,\n\t\t\tcolour: '#dc241f',\n\t\t},\n\t\tsnp: {\n\t\t\tseats: 35,\n\t\t\tcolour: '#ff0',\n\t\t},\n\t\tlibdems: {\n\t\t\tseats: 12,\n\t\t\tcolour: '#faa61a',\n\t\t},\n\t\tsinnfein: {\n\t\t\tseats: 7,\n\t\t\tcolour: '#080',\n\t\t},\n\t\tplaidcymru: {\n\t\t\tseats: 4,\n\t\t\tcolour: '#008142',\n\t\t},\n\t\tgreen: {\n\t\t\tseats: 1,\n\t\t\tcolour: '#6ab023',\n\t\t},\n\t\tindependent: {\n\t\t\tseats: 1,\n\t\t\tcolour: '#aadfff',\n\t\t}\n\t},\n\tcrossBench: {\n\t\tdup: {\n\t\t\tseats: 10,\n\t\t\tcolour: '#d46a4c',\n\t\t}\n\t},\n\tright: {\n\t\tconservative: {\n\t\t\tseats: 317,\n\t\t\tcolour: '#0087dc',\n\t\t}\n\t}\n}\n```\n\nPlease note that the parties will be displayed in the order of their `object` keys from left to right (based on the speaker's viewpoint). Further, each seat SVG element contains the party name in its `class` attribute.\n\nFor the given `parliament` object, the rendered result should look as follows:\n\n![Example: House of Commons after GE 2017](https://rawgit.com/juliuste/westminster-svg/main/example/westminster.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 westminsterSVG from 'westminster-svg'\nimport { toHtml as toSvg } from 'hast-util-to-html'\n\nconst virtualSvg = westminsterSVG(parliament)\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## Contributing\n\nIf you found a bug or want to propose a feature, feel free to visit [the issues page](https://github.com/juliuste/westminster-svg/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliuste%2Fwestminster-svg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliuste%2Fwestminster-svg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliuste%2Fwestminster-svg/lists"}