{"id":23508986,"url":"https://github.com/two-n/cirque","last_synced_at":"2025-04-16T19:21:15.327Z","repository":{"id":57198991,"uuid":"86888097","full_name":"two-n/cirque","owner":"two-n","description":"Utilities for negotiating between circles and polygons in SVG","archived":false,"fork":false,"pushed_at":"2017-04-22T01:15:44.000Z","size":249,"stargazers_count":13,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T07:42:02.094Z","etag":null,"topics":["animation","circle","geometry","transitions"],"latest_commit_sha":null,"homepage":"http://projects.two-n.com/cirque/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/two-n.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-04-01T06:00:45.000Z","updated_at":"2024-06-01T07:49:31.000Z","dependencies_parsed_at":"2022-09-16T14:51:11.593Z","dependency_job_id":null,"html_url":"https://github.com/two-n/cirque","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/two-n%2Fcirque","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/two-n%2Fcirque/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/two-n%2Fcirque/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/two-n%2Fcirque/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/two-n","download_url":"https://codeload.github.com/two-n/cirque/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249268445,"owners_count":21240927,"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":["animation","circle","geometry","transitions"],"created_at":"2024-12-25T11:36:17.698Z","updated_at":"2025-04-16T19:21:15.295Z","avatar_url":"https://github.com/two-n.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cirque\n\nUtilities for negotiating between circles and paths in SVG. See [demo](http://projects.two-n.com/cirque/).\n\n![Cirque](loop.gif)\n\n`npm install --save cirque` (or `yarn add cirque`)\n\n\n## Functions\n\n\u003ca href=\"#interpolatePath\" name=\"interpolatePath\"\u003e#\u003c/a\u003e __interpolatePath__(_a_, _b_)\n\nInterpolates between two SVG path description strings.\n\nExpects a _circle path_ (which gets sampled) and a polygonal _chain path_ (which gets oversampled when necessary), although two circles work just by ordinary interpolation, and two chains should work in many cases as well.\n\n\u003ca href=\"#interpolatePaths\" name=\"interpolatePaths\"\u003e#\u003c/a\u003e __interpolatePaths__(_a_, _b_)\n\nIndividually interpolates (using [interpolatePath](#interpolatePath)) between corresponding items in two parallel arrays of SVG path strings.\n\n\u003ca href=\"#circlePath\" name=\"circlePath\"\u003e#\u003c/a\u003e __circlePath__(_circle_)\n\nConverts the passed _circle object_ to an SVG path string (i.e. a _circle path_ consisting of two arc commands).\n\n\u003ca href=\"#geoToCircle\" name=\"geoToCircle\"\u003e#\u003c/a\u003e __geoToCircle__(_geometry_, [_path_], [_radius_], [_object_])\n\nConverts the geometry object to a _circle object_ sharing its centroid.\n\n_Circle objects_ take the form: `{ x, y, r }`\n\n- _geometry_: any GeoJSON geometry or feature (required)\n- _path_: [geographic path generator](https://github.com/d3/d3-geo#geoPath). Defaults to bare `d3.geoPath()`, which assumes pre-projected geometry\n- _radius_: circle radius. Defaults to deriving radius from projected area\n- _object_: mutates passed existing object rather than creating a new one\n\n\u003ca href=\"#polygonToCircle\" name=\"polygonToCircle\"\u003e#\u003c/a\u003e __polygonToCircle__(_polygon_)\n\nConverts a polygon to a _circle object_ sharing its centroid.\n\n- _polygon_: an array of polygon vertices (as two-element arrays) (required)\n- _radius_: circle radius. Defaults to computing radius from polygon area\n- _object_: mutates passed existing object rather than creating a new one\n\n\u003ca href=\"#avoidOverlap\" name=\"avoidOverlap\"\u003e#\u003c/a\u003e __avoidOverlap__(_objects_, [_margin_])\n\nPass an array of _circle objects_ to separate colliding circles so that no overlaps remain. Mutates objects in place. Margin (minimum gap, or maximum overlap if negative) defaults to 0. (Uses `d3.forceCollide`.)\n\n\u003ca href=\"#radiusScale\" name=\"radiusScale\"\u003e#\u003c/a\u003e __radiusScale__(_area_, _value_)\n\nReceives total area and total value as arguments, and returns a D3 scale in which the area of a circle with the given radius corresponds to a linearly-scaled value.\n\n\n## Examples\n```js\nlet render  // Given a function that renders SVG paths\nlet path    // Given a geo path generator\n```\n\n### Example: geometry\n```js\nimport { geoToCircle, circlePath, interpolatePath } from 'cirque'\n\nlet geometry  // Given a GeoJSON Polygon or MultiPolygon geometry\n\nconst interpolator = interpolatePath(\n  path(geometry),\n  circlePath( geoToCircle(geometry, path) )\n)\n\nd3.transition().tween('shape', () =\u003e t =\u003e { render( interpolator(t) ) })\n```\n\n### Example: features\n\n```js\nimport * as cirque from 'cirque'\n\nlet features  // Given an array of GeoJSON Polygon or MultiPolygon features\n\nconst scale = cirque.radiusScale( path.area(mergedFeatures), 7.5e9 )\nconst circles = features.map(feature =\u003e\n  circle.geoToCircle(feature, path, scale(feature.properties['population']))\n)\n\nconst separatedCircles = cirque.avoidOverlap(circles)\nconst circlePaths = separatedCircles.map(cirque.circlePath)\nconst interpolator = cirque.interpolatePaths(features.map(path), circlePaths)\n\nd3.transition().tween('shapes', () =\u003e t =\u003e { render( interpolator(t) ) })\n```\n\n\n## Approach\n\n- Aligns circle and path by tracing a circle using the path's commands\n- Splits path commands when necessary to maintain a balance between a) mapping path commands uniformly, and b) aligning per distance unit\n- Avoids [more sophisticated](http://spencermortensen.com/articles/bezier-circle/) circle approximation methods in favor of high-rate sampling\n\n\n## Limitations\n\nThe _chain path_ is a SVG path description of a polygonal chain (i.e. polyline, composite Bézier, etc.) containing any SVG path commands except arcs, support for which is planned.\n\nThe _circle path_ is a SVG path description containing an M command followed by at least one A command (but typically two). `circlePath` is a utility for generating simple, compatible _circle paths_. Some more flexiblility in the format may come in the future, including (optionally) adhering to winding order.\n\n\n## Rationale\n\nJust as a lack of color is physically considered _black_ (though artistically often considered _white_), a lack of shape can in a certain sense be called a _circle_ (or a n-sphere generally): no discrete segmentation, and no starting point any better than another.\n\nThis shapelessness is desirable for comparing values in a controlled way (say, in a bubble map) to minimize distortion and distraction.\n\nThe tools in this package amount to a method for going between precise forms such as geographic areas, and corresponding value-sized bubbles, while maintaining constancy.\n\n\n## Shape morphing alternatives\n\n- [SVG.js path morphing plugin](https://github.com/svgdotjs/svg.pathmorphing.js): simple and well done. Has some of the same approach and associated limitations\n- [SVG Morpheus](http://alexk111.github.io/SVG-Morpheus/): works well and supports arbitrary SVG 👍\n- [MorphSVG](https://greensock.com/morphSVG): proprietary but seems quite customizable and the demos are awesome\n\n\n## Discussion and contribution\n\nOpen an [issue](https://github.com/two-n/cirque/issues/new) or [pull request](https://github.com/two-n/cirque/compare) with either high-level use cases or practical support tickets, or contact us on [twitter](https://twitter.com/2nfo). We intend to keep this package focused on its stated mission, but advice, critique, and experiences are very welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwo-n%2Fcirque","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwo-n%2Fcirque","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwo-n%2Fcirque/lists"}