UNPKG

venn-helper

Version:

Area Proportional Venn and Euler Diagrams

334 lines (330 loc) 11.3 kB
type Area = { sets: (string | number)[]; size: number; weight?: number; label?: string; }; type CircleRecord = Record<string | number, Circle>; type Circle = { x: number; y: number; rowid?: number; size?: number; radius: number; parent?: Circle; setid: string; }; type Params = { /** layout algorithm used during computations of the venn diagram */ layout?: "greedy" | "MDS" | "best"; /** max of number iterations when performing a MSDConstrainedLayout */ restarts?: number; maxIterations?: number; /** number from 0-1 that to seed the random positions when using the MSDConstrainedLayout */ seed?: number; history?: { x: number[]; }[]; }; /** given a list of set objects, and their corresponding overlaps. updates the (x, y, radius) attribute on each set such that their positions roughly correspond to the desired overlaps */ declare function venn(areas: Area[], parameters?: Params): CircleRecord; /** Returns the distance necessary for two circles of radius r1 + r2 to have the overlap area 'overlap' */ declare function distanceFromIntersectArea(r1: number, r2: number, overlap: number): number; declare function getDistanceMatrices(areas: Area[], sets: Area[], setids: Record<string, number>): { distances: number[][]; constraints: number[][]; }; declare function bestInitialLayout(areas: Area[], params: Params): CircleRecord; declare function constrainedMDSLayout(areas: Area[], params: Params): CircleRecord; /** Lays out a Venn diagram greedily, going from most overlapped sets to least overlapped, attempting to position each new set such that the overlapping areas to already positioned sets are basically right */ declare function greedyLayout(areas: Area[], _params?: Params): CircleRecord; /** Given a bunch of sets, and the desired overlaps between these sets - computes the distance from the actual overlaps to the desired overlaps. Note that this method ignores overlaps of more than 2 circles */ declare function lossFunction(sets: CircleRecord, overlaps: Area[]): number; declare function disjointCluster(circles: Circle[]): Circle[][]; declare function normalizeSolution(solution: Record<string | number, Circle>, orientation?: number, orientationOrder?: (a: Circle, b: Circle) => number): CircleRecord; /** Scales a solution from venn.venn or venn.greedyLayout such that it fits in a rectangle of width/height - with padding around the borders. also centers the diagram in the available space at the same time */ declare function scaleSolution(solution: CircleRecord, width: number, height: number, padding: number): CircleRecord; type Point = { x: number; y: number; angle?: number; }; type IntersectionPoint = Point & { parentIndex: [number, number]; }; type CircleCoordinates = { radius: number; x: number; y: number; }; type Arc = { width: number; p1: IntersectionPoint | Point; p2: IntersectionPoint | Point; circle: CircleCoordinates; }; /** Returns the intersection area of a bunch of circles (where each circle is an object having an x,y and radius property) */ declare function intersectionArea(circles: CircleCoordinates[]): { overlap: number; stats: { area: number; arcArea: number; polygonArea: number; arcs: Arc[]; innerPoints: IntersectionPoint[]; intersectionPoints: IntersectionPoint[]; }; }; /** returns whether a point is contained by all of a list of circles */ declare function containedInCircles(point: Point, circles: CircleCoordinates[]): boolean; /** Circular segment area calculation. See http://mathworld.wolfram.com/CircularSegment.html */ declare function circleArea(r: number, width: number): number; /** euclidean distance between two points */ declare function distance(p1: Point, p2: Point): number; /** Returns the overlap area of two circles of radius r1 and r2 - that have their centers separated by distance d. Simpler faster circle intersection for only two circles */ declare function circleOverlap(r1: number, r2: number, d: number): number; /** Given two circles (containing a x/y/radius attributes), returns the intersecting points if possible. note: doesn't handle cases where there are infinitely many intersection points (circles are equivalent):, or only one intersection point*/ declare function circleCircleIntersection(p1: CircleCoordinates, p2: CircleCoordinates): { x: number; y: number; }[]; /** Returns the center of a bunch of points */ declare function getCenter(points: Point[]): Point; type GetVennSolutionOptions = { /** orientation of the venn in radians */ orientation: number; /** width of the venn */ width: number; /** height of the venn */ height: number; /** padding of the venn */ padding: number; /** each set has an set_id property joined by a delimiter, set the delimiter here */ set_id_delimiter: string; /** function to determine the order of the orientation */ orientationOrder?: (a: Circle, b: Circle) => number; /** layout algorithm used during computations of the venn diagram */ layout?: "greedy" | "MDS" | "best"; /** number from 0-1 that to seed the random positions when using the MSDConstrainedLayout */ seed?: number; }; declare function chartVega(data: Area[], options: GetVennSolutionOptions): { $schema: string; width: number; height: number; padding: number; data: ({ name: string; values: { set_id: string; x: number; y: number; size: number; textX: number; textY: number; }[]; } | { name: string; values: { set_id: string; sets: (string | number)[]; path: string; textX: number | undefined; textY: number | undefined; size: number; }[]; })[]; scales: { name: string; type: string; domain: { data: string; field: string; }; range: string; }[]; marks: ({ type: string; from: { data: string; }; encode: { enter: { x: { field: string; }; y: { field: string; }; size: { field: string; }; shape: { value: string; }; fillOpacity: { value: number; }; fill: { scale: string; field: string; value?: undefined; }; tooltip: { field: string; type: string; }[]; path?: undefined; text?: undefined; fontSize?: undefined; fontWeight?: undefined; }; hover: { fillOpacity: { value: number; }; stroke?: undefined; strokeWidth?: undefined; fill?: undefined; }; update: { fillOpacity: { value: number; }; strokeWidth?: undefined; }; }; } | { type: string; from: { data: string; }; encode: { enter: { path: { field: string; }; fill: { value: string; scale?: undefined; field?: undefined; }; fillOpacity: { value: number; }; tooltip: { field: string; type: string; }[]; x?: undefined; y?: undefined; size?: undefined; shape?: undefined; text?: undefined; fontSize?: undefined; fontWeight?: undefined; }; hover: { stroke: { value: string; }; strokeWidth: { value: number; }; fill: { value: string; }; fillOpacity?: undefined; }; update: { strokeWidth: { value: number; }; fillOpacity?: undefined; }; }; } | { type: string; from: { data: string; }; encode: { enter: { x: { field: string; }; y: { field: string; }; text: { field: string; }; fontSize: { value: number; }; fill: { scale: string; field: string; value?: undefined; }; fontWeight: { value: string; }; size?: undefined; shape?: undefined; fillOpacity?: undefined; tooltip?: undefined; path?: undefined; }; hover?: undefined; update?: undefined; }; })[]; }; declare function vennSolution(data: Area[], { layout, height, width, padding, seed, orientation, set_id_delimiter, orientationOrder, }: GetVennSolutionOptions): { circles: { set_id: string; x: number; y: number; size: number; textX: number; textY: number; }[]; intersections: { set_id: string; sets: (string | number)[]; path: string; textX: number | undefined; textY: number | undefined; size: number; }[]; }; declare function intersectionAreaPath(circles: Circle[]): string; declare function circlePath(x: number, y: number, r: number): string; type TextCenterRecord = ReturnType<typeof computeTextCentres>; declare function computeTextCentres(circles: CircleRecord, areas: Area[], delimiter?: string): Record<string | number, { x: number; y: number; disjoint?: boolean; }>; declare function computeTextCentre(interior: Circle[], exterior: Circle[]): { x: number; y: number; disjoint?: boolean; }; export { type Area, type Circle, type CircleRecord, type Params, type TextCenterRecord, bestInitialLayout, chartVega, circleArea, circleCircleIntersection, circleOverlap, circlePath, computeTextCentre, computeTextCentres, constrainedMDSLayout, containedInCircles, disjointCluster, distance, distanceFromIntersectArea, getCenter, getDistanceMatrices, greedyLayout, intersectionArea, intersectionAreaPath, lossFunction, normalizeSolution, scaleSolution, venn, vennSolution };