FlattenJS provides a lot of useful methods and algorithms like finding intersections, checking inclusion, calculating distance, apply transformations and more. Polygon model is rather comprehensive and supports multi polygons with many islands and holes. Edges of polygon may be circular arcs or segments. Some algorithms like Boolean Operations and Offset, implemented in separate packages.
TypeScript users may take advantage of static type checking with typescript definition file index.d.ts included into the package.
FlattenJS does not concern too much about visualization. Anyway, all objects have svg() methods, that returns a string which may be inserted into SVG container. This works pretty well together with d3js library. But it is definitely possible to create bridges to other graphic libraries.
Full documentation may be found here
Follow me on Twitter @alex_bol_
npm install --save flatten-js
Package may be required in different ways:
Require as es6 module:
Require as CommonJS package (nodejs)
const Flatten = ;
Require minified package precompiled into UMD format.
Observable notebooks requires this format.
const Flatten = ;
Require precompiled to es5 package in Commonjs2 format.
This package is not minified.
"" Some third-party packages don't compile their code to ES5 before publishing to npm. This often causes problems in the ecosystem because neither browsers (except for most modern versions) nor some tools currently support all ES6 features. We recommend to publish code on npm as ES5 at least for a few more years. ""
You can see example of FlattenJS + React usage in flatten-react-demo project. It is live here. Just clone it from the GitHub, install dependencies and start working using npm start or compile it to production using npm run build.
After module required, you can create some construction:
// extract object creatorslet point circle segment = Flatten;// make some constructionlet s1 = ;let s2 = ;let c = ;let ip = s1;
You may test the code above also in NPM RunKit