UNPKG

venn-helper

Version:

Area Proportional Venn and Euler Diagrams

316 lines (312 loc) 10.8 kB
type Area = { sets: (string | number)[]; size: number; weight?: number; label?: string; }; type CircleRecord = Record<string | number, Circle$1>; type Circle$1 = { x: number; y: number; rowid?: number; size?: number; radius: number; parent?: Circle$1; setid?: string; }; type Params = { lossFunction?: (sets: CircleRecord, overlaps: Area[]) => number; initialLayout?: (areas: Area[], params: Params) => CircleRecord; restarts?: number; maxIterations?: 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?: any): 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$1[]): Circle$1[][]; declare function normalizeSolution(solution: Record<string | number, Circle$1>, orientation?: number, orientationOrder?: (a: Circle$1, b: Circle$1) => 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 Circle = { radius: number; x: number; y: number; }; type Arc = { width: number; p1: IntersectionPoint | Point; p2: IntersectionPoint | Point; circle: Circle; }; /** 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: Circle[]): { 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: Circle[]): 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: Circle, p2: Circle): { x: number; y: number; }[]; /** Returns the center of a bunch of points */ declare function getCenter(points: Point[]): Point; type Options = { orientation: number; width: number; height: number; padding: number; normalize: boolean; }; declare function chartVega(data: Area[], options: Options): { circles: { set: string; x: number; y: number; size: number; text: string; textX: number; textY: number; }[]; intersections: ({ sets: Area; path: string; text: string; } | null)[]; schema: { $schema: string; width: number; height: number; padding: number; data: ({ name: string; values: { set: string; x: number; y: number; size: number; text: string; textX: number; textY: number; }[]; } | { name: string; values: ({ sets: Area; path: string; text: string; } | null)[]; })[]; 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 intersectionAreaPath(circles: Circle$1[]): string; declare function circlePath(x: number, y: number, r: number): string; type TextCenterRecord = ReturnType<typeof computeTextCentres>; declare function computeTextCentres(circles: CircleRecord, areas: Area[]): Record<string | number, { x: number; y: number; disjoint?: boolean; }>; declare function computeTextCentre(interior: Circle$1[], exterior: Circle$1[]): { x: number; y: number; disjoint?: boolean; }; export { type Area, type Circle$1 as Circle, type CircleRecord, type TextCenterRecord, bestInitialLayout, chartVega, circleArea, circleCircleIntersection, circleOverlap, circlePath, computeTextCentre, computeTextCentres, constrainedMDSLayout, containedInCircles, disjointCluster, distance, distanceFromIntersectArea, getCenter, getDistanceMatrices, greedyLayout, intersectionArea, intersectionAreaPath, lossFunction, normalizeSolution, scaleSolution, venn };