Code Monkey home page Code Monkey logo

parliament-svg's Introduction

parliament-svg

Generate parliament charts as hast virtual DOM SVG*. Design inspired by the Wikipedia parliament charts. Play around with the live demo! For westminster-style parliament charts, see westminster-svg. If you are using D3, you might prefer working with the d3-parliament module.

*Also compatible with other virtual DOM implementations, see the docs below.

npm version License Contact me

Installation

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm install --save parliament-svg

Usage

import parliamentSVG from 'parliament-svg'

const virtualSvg = parliamentSVG(parties, [opt])
  • opt can contain the following options:
    • seatCount is a boolean, if true the total seat count will be displayed in the chart. Defaults to false.
    • hFunction is a function that will be used to generate the element tree. Defaults to hastscript's s() function, custom values need to match that function's signature. You could use virtual-hyperscript-svg's h() function here if you prefer working with virtual-dom, for example.
  • parties is an object containing seat count and colour for each party, e.g.:
{
	"linke": {
		"seats": 64,
		"colour": "#a08"
	},
	"spd": {
		"seats": 193,
		"colour": "#e02"
	},
	"gruene": {
		"seats": 63,
		"colour": "#0b2"
	},
	"union": {
		"seats": 311,
		"colour": "#333"
	}
}

Each seat contains the party name in its class attribute.

For the given parties object and seatCount enabled, the rendered result should look as follows:

Example: German Bundestag with seat count enabled

If you want to convert the hast tree to an SVG string, use hast-util-to-html (don't get confused by the name, the library can also stringify SVG):

import parliamentSVG from 'parliament-svg'
import { toHtml as toSvg } from 'hast-util-to-html'

const virtualSvg = parliamentSVG(parties, seatCount)
const svg = toSvg(virtualSvg)

Check the code example as well.

What if I prefer virtual-dom (or anything else)?

If you prefer virtual-dom over hast, e.g. for diffing or patching, you can either:

  • use hast-to-hyperscript to transform the tree after it was generated or
  • use the hFunction parameter documented above with a virtual-dom h() function of your choice

See also

Contributing

If you found a bug or want to propose a feature, feel free to visit the issues page.

parliament-svg's People

Contributors

derhuerst avatar dgisser avatar greenkeeper[bot] avatar josephkmh avatar juliuste avatar k-nut avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

parliament-svg's Issues

An in-range update of eslint is breaking the build ๐Ÿšจ

The devDependency eslint was updated from 6.7.2 to 6.8.0.

๐Ÿšจ View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • โŒ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v6.8.0
  • c5c7086 Fix: ignore aligning single line in key-spacing (fixes #11414) (#12652) (YeonJuan)
  • 9986d9e Chore: add object option test cases in yield-star-spacing (#12679) (YeonJuan)
  • 1713d07 New: Add no-error-on-unmatched-pattern flag (fixes #10587) (#12377) (ncraley)
  • 5c25a26 Update: autofix bug in lines-between-class-members (fixes #12391) (#12632) (YeonJuan)
  • 4b3cc5c Chore: enable prefer-regex-literals in eslint codebase (#12268) (่–›ๅฎš่ฐ”็š„็Œซ)
  • 05faebb Update: improve suggestion testing experience (#12602) (Brad Zacher)
  • 05f7dd5 Update: Add suggestions for no-unsafe-negation (fixes #12591) (#12609) (Milos Djermanovic)
  • d3e43f1 Docs: Update no-multi-assign explanation (#12615) (Yuping Zuo)
  • 272e4db Fix: no-multiple-empty-lines: Adjust reported loc (#12594) (Tobias Bieniek)
  • a258039 Fix: no-restricted-imports schema allows multiple paths/patterns objects (#12639) (Milos Djermanovic)
  • 51f9620 Fix: improve report location for array-bracket-spacing (#12653) (Milos Djermanovic)
  • 45364af Fix: prefer-numeric-literals doesn't check types of literal arguments (#12655) (Milos Djermanovic)
  • e3c570e Docs: Add example for expression option (#12694) (Arnaud Barrรฉ)
  • 6b774ef Docs: Add spacing in comments for no-console rule (#12696) (Nikki Nikkhoui)
  • 7171fca Chore: refactor regex in config comment parser (#12662) (Milos Djermanovic)
  • 1600648 Update: Allow $schema in config (#12612) (Yordis Prieto)
  • acc0e47 Update: support .eslintrc.cjs (refs eslint/rfcs#43) (#12321) (Evan Plaice)
  • 49c1658 Chore: remove bundling of ESLint during release (#12676) (Kai Cataldo)
  • 257f3d6 Chore: complete to move to GitHub Actions (#12625) (Toru Nagashima)
  • ab912f0 Docs: 1tbs with allowSingleLine edge cases (refs #12284) (#12314) (Ari Kardasis)
  • dd1c30e Sponsors: Sync README with website (ESLint Jenkins)
  • a230f84 Update: include node version in cache (#12582) (Eric Wang)
  • 8b65f17 Chore: remove references to parser demo (#12644) (Kai Cataldo)
  • e9cef99 Docs: wrap {{}} in raw liquid tags to prevent interpolation (#12643) (Kai Cataldo)
  • e707453 Docs: Fix configuration example in no-restricted-imports (fixes #11717) (#12638) (Milos Djermanovic)
  • 19194ce Chore: Add tests to cover default object options in comma-dangle (#12627) (YeonJuan)
  • 6e36d12 Update: do not recommend require-atomic-updates (refs #11899) (#12599) (Kai Cataldo)
Commits

The new version differs by 29 commits.

  • 9738f8c 6.8.0
  • ba59cbf Build: changelog update for 6.8.0
  • c5c7086 Fix: ignore aligning single line in key-spacing (fixes #11414) (#12652)
  • 9986d9e Chore: add object option test cases in yield-star-spacing (#12679)
  • 1713d07 New: Add no-error-on-unmatched-pattern flag (fixes #10587) (#12377)
  • 5c25a26 Update: autofix bug in lines-between-class-members (fixes #12391) (#12632)
  • 4b3cc5c Chore: enable prefer-regex-literals in eslint codebase (#12268)
  • 05faebb Update: improve suggestion testing experience (#12602)
  • 05f7dd5 Update: Add suggestions for no-unsafe-negation (fixes #12591) (#12609)
  • d3e43f1 Docs: Update no-multi-assign explanation (#12615)
  • 272e4db Fix: no-multiple-empty-lines: Adjust reported loc (#12594)
  • a258039 Fix: no-restricted-imports schema allows multiple paths/patterns objects (#12639)
  • 51f9620 Fix: improve report location for array-bracket-spacing (#12653)
  • 45364af Fix: prefer-numeric-literals doesn't check types of literal arguments (#12655)
  • e3c570e Docs: Add example for expression option (#12694)

There are 29 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those donโ€™t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot ๐ŸŒด

missing: tests

It would be nice to have some really basic tests (preferably using tape).

An in-range update of uglify-js is breaking the build ๐Ÿšจ

The devDependency uglify-js was updated from 3.7.1 to 3.7.2.

๐Ÿšจ View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

uglify-js is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • โŒ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v3.7.2

ย 

Commits

The new version differs by 10 commits.

  • fe19ab7 v3.7.2
  • 9074f05 fix corner case in collapse_vars (#3629)
  • 04fbb1f avoid collision with HTML comments (#3625)
  • bf7e4ca fix corner case in collapse_vars (#3627)
  • d68ddc3 fix corner case in reduce_vars (#3623)
  • 500e31e enhance collapse_vars (#3621)
  • bef856a fix corner case in keep_fargs (#3620)
  • 9a6faf3 fix corner cases in keep_fargs & unused (#3618)
  • e915832 enhance unused (#3617)
  • 0593892 enhance collapse_vars (#3616)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those donโ€™t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot ๐ŸŒด

An in-range update of sainte-lague is breaking the build ๐Ÿšจ

The dependency sainte-lague was updated from 2.0.1 to 2.1.0.

๐Ÿšจ View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

sainte-lague is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • โŒ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 14 commits.

  • e0efb7b 2.1.0
  • a4163a7 add documentation for opt.draw
  • f2cd00e add documentation for opt.draw
  • 8beb5ad add test cases, use tape
  • c971069 iterative procedure -> highest average method
  • 53483eb refactor code
  • 89565fc update dev dependencies
  • c6a2d9e test for node 12, update dev dependencies
  • e33af00 add eslintrc ๐Ÿ™ˆ
  • 289e461 LICENSE -> license
  • d6bb82e soothe the linter
  • 31551f3 node >=8, add linter/depcheck setup
  • e3cf6ae update license year
  • b803817 use absolute paths in gitignore, shrinkwrap -> pnpm-lock

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those donโ€™t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot ๐ŸŒด

Include xmlns attribute to make the svg includabel

I tried to reference the created svg source (pulled out into a file) recently in an img element but it would not render correctly. This is because the created svg does not contain the xmlns="http://www.w3.org/2000/svg" tag in the root element which is required for anything other than inline svgs (see this stackoverflow answer).

As the attribute is ignored in inlined svgs I think that it would be safe to include this. If you agree I'll happily provide a PR for this.

An in-range update of tape is breaking the build ๐Ÿšจ

The devDependency tape was updated from 4.11.0 to 4.12.0.

๐Ÿšจ View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

tape is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • โŒ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 9 commits.

  • 42c84d6 v4.12.0
  • 3e0a341 [Deps] update is-regex, string.prototype.trim
  • ba7e2b2 [Dev Deps] update eslint
  • f3a5925 [Tests] use shared travis-ci configs
  • 6e94800 [Deps] update deep-equal, glob, object-inspect, resolve, string.prototype.trim
  • 8150c3b [Refactor] use is-regex instead of instanceof RegExp
  • 24487cb add tap-nyc to pretty-reporters
  • c283615 [New] when the error type is wrong, show the message and stack
  • 44cbbf5 [Tests] add a test for the wrong kind of error

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those donโ€™t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot ๐ŸŒด

An in-range update of depcheck is breaking the build ๐Ÿšจ

The devDependency depcheck was updated from 0.9.0 to 0.9.1.

๐Ÿšจ View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

depcheck is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • โŒ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for The one with a bunch of features

Features

  • better support for workspaces #473
  • support for prettier shared configuration #474
  • support for typescript webpack configuration #459
  • added support for ttypescript #469
  • typescript types! #458
  • added support for lint-staged #456
  • added support for husky #453
  • added support for babel.config.js

Bugfixes

  • consitent exit code #465
  • fixed false positive when using plugin:prettier/recommended #464
  • fixed false positive when using tslint-plugin-prettier #457

Big thanks to @VincentLanglet and @sveyret

I almost made this 1.0.0 but it will be for the next.

Commits

The new version differs by 41 commits.

  • 5e2ae0d Merge pull request #473 from sveyret/noderesolve
  • 6d1d3b8 Use node resolution for dependencies
  • 55622db Merge pull request #474 from sveyret/prettier
  • 671b053 Support prettier shared configuration
  • dcb186f Merge pull request #470 from sveyret/AutoTS
  • 004397b Automate building of TypeScript definitions
  • 64ebbfc Merge pull request #459 from sveyret/loadTS
  • c824eb8 Load typescript transpiler if available
  • d2057a0 Merge pull request #469 from sveyret/TTypeScript
  • 77b4b12 Add TTypeScript transformer special parser
  • 103adab Merge pull request #467 from depcheck/chore-node-10
  • aabf02f chore: update node requirement in package.json and readme
  • 279fb1b Merge pull request #466 from depcheck/chore-more-stale
  • b8f2122 Merge branch 'master' into chore-more-stale
  • dff7ebb Merge pull request #465 from depcheck/feat-consistent-exit-code

There are 41 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those donโ€™t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot ๐ŸŒด

An in-range update of eslint-plugin-import is breaking the build ๐Ÿšจ

The devDependency eslint-plugin-import was updated from 2.18.2 to 2.19.0.

๐Ÿšจ View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-import is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • โŒ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 46 commits.

  • 9b76635 Bump to v2.19.0
  • 47a232e [resolvers/webpack] v0.12.0
  • 26ad476 [resolvers/webpack] [deps] update debug, enhanced-resolve, has, interpret, lodash, resolve, semver
  • 3f0e8f3 [resolvers/node] [Deps] update resolve
  • 7190c3e bump utils to v2.5.0
  • a60e5c6 [New] no-commonjs: add allowConditionalRequire option
  • 414c923 [New] enable passing cwd as an option to eslint-import-resolver-webpack
  • 8224e51 [New] order/no-extraneous-dependencies: Alphabetize imports within groups
  • f12ae59 [New] no-duplicates: add a considerQueryString option to handle false positives when using some webpack loaders.
  • 2d3d045 [fix] importType: Accept '@example' as internal
  • 0426f16 [New] order: add pathGroups option to add support to order by paths
  • 99b3fbf [Fix] no-extraneous-dependencies: Add support for export from
  • 21bf8c6 [Fix] no-cycle: should not warn for Flow imports
  • 0cd5e43 [Fix] no-unused-modules: fix crash due to export *
  • 05085bb [flow] no-unused-modules: add flow type support

There are 46 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those donโ€™t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot ๐ŸŒด

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.