forked from benfred/venn.js
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.d.ts
319 lines (277 loc) · 9.3 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import { Selection } from 'd3-selection';
export interface ISetOverlap {
sets: readonly string[];
size: number;
weight?: number;
}
export interface IPoint {
x: number;
y: number;
}
export interface IHierarchyPoint extends IPoint {
parentIndex: [number, number];
}
export interface ICircle {
x: number;
y: number;
radius: number;
setid: string;
}
export interface ISolution {
[set: string]: ICircle;
}
/**
* 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
*/
export function venn(areas: readonly ISetOverlap[], parameters?: any): ISolution;
/**
* Returns the distance necessary for two circles of radius r1 + r2 to
* have the overlap area 'overlap'
*/
export function distanceFromIntersectArea(r1: number, r2: number, overlap: number): number;
/**
* takes the best working variant of either constrained MDS or greedy
*/
export function bestInitialLayout(areas: readonly ISetOverlap[], params?: any): ISolution;
/**
* 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
*/
export function greedyLayout(areas: readonly ISetOverlap[], params?: any): ISolution;
/**
* 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
*/
export function lossFunction(circles: ISolution, areas: readonly ISetOverlap[]): number;
export function logRatioLossFunction(circles: ISolution, areas: readonly ISetOverlap[]): number;
export function disjointCluster(circles: ICircle[]): ICircle[][];
export function normalizeSolution(
solution: ISolution,
orientation?: number,
orientationOrder?: (a: ICircle, b: ICircle) => number
): ISolution;
/**
* 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.
* If the scale parameter is not null, this automatic scaling is ignored in favor of this custom one
*/
export function scaleSolution(
solution: ISolution,
width: number,
height: number,
padding: number,
scaleToFit?: boolean
): ISolution;
/**
* Returns the intersection area of a bunch of circles (where each circle
* is an object having an x,y and radius property)
*/
export function intersectionArea(
circles: readonly ICircle[],
stats?: {
area?: number;
areaArea?: number;
polygonArea?: number;
arcs?: readonly { circle: ICircle; width: number; p1: IPoint; p2: IPoint }[];
innerPoints?: readonly IHierarchyPoint[];
intersectionPoints?: readonly IHierarchyPoint[];
}
): number;
/**
* Circular segment area calculation. See http://mathworld.wolfram.com/CircularSegment.html
*/
export function circleArea(r: number, width: number): number;
/**
* euclidean distance between two points
*/
export function distance(p1: IPoint, p2: IPoint): 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
*/
export 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
*/
export function circleCircleIntersection(p1: ICircle, p2: ICircle): readonly IPoint[];
// sometimes text doesn't fit inside the circle, if thats the case lets wrap
// the text here such that it fits
// todo: looks like this might be merged into d3 (
// https://github.com/mbostock/d3/issues/1642),
// also worth checking out is
// http://engineering.findthebest.com/wrapping-axis-labels-in-d3-js/
// this seems to be one of those things that should be easy but isn't
export function wrapText(circles: ISolution, labeller: (d: any) => string): (this: SVGTextElement) => void;
/**
* compute the center of some circles by maximizing the margin of
* the center point relative to the circles (interior) after subtracting
* nearby circles (exterior)
* @param {readonly {x: number, y: number, radius: number}[]} interior
* @param {readonly {x: number, y: number, radius: number}[]} exterior
* @param {boolean} symmetricalTextCentre
* @returns {{x:number, y: number}}
*/
export function computeTextCentre(
interior: readonly ICircle[],
exterior: readonly ICircle[],
symmetricalTextCentre?: boolean
): IPoint;
export function computeTextCentres(
circles: ISolution,
areas: readonly ISetOverlap[],
symmetricalTextCentre?: boolean
): { [set: string]: IPoint };
// sorts all areas in the venn diagram, so that
// a particular area is on top (relativeTo) - and
// all other areas are so that the smallest areas are on top
export function sortAreas(div: Selection<any, any, any, unknown>, relativeTo: { sets: readonly string[] }): void;
export function circlePath(x: number, y: number, r: number): string;
/**
* inverse of the circlePath function, returns a circle object from an svg path
*/
export function circleFromPath(path: string): ICircle;
/**
* returns a svg path of the intersection area of a bunch of circles
*/
export function intersectionAreaPath(circles: readonly ICircle[]): string;
export interface IVennDiagramOptions {
colourScheme?: readonly string[];
colorScheme?: readonly string[];
symmetricalTextCentre?: boolean;
textFill?: string;
}
export interface IStyledSetOverlap extends ISetOverlap {
color?: string;
colour?: string;
}
export interface IVennDiagram {
(selection: Selection<HTMLElement, readonly IStyledSetOverlap[], any, unknown>): {
circles: ISolution;
textCentres: { [set: string]: IPoint };
nodes: Selection<SVGGElement, IStyledSetOverlap, any, unknown>;
enter: Selection<SVGGElement, IStyledSetOverlap, any, unknown>;
update: Selection<SVGGElement, IStyledSetOverlap, any, unknown>;
exit: Selection<SVGGElement, IStyledSetOverlap, any, unknown>;
};
/**
* wrap the labels
* @default true
*/
wrap(): boolean;
wrap(v: boolean): this;
/**
* use a view box instead of specifying with and height
* @default false
*/
useViewBox(): this;
width(): number;
width(v: number): this;
height(): number;
height(v: number): this;
padding(): number;
padding(v: number): this;
colours(): (key: string) => string;
colours(v: (key: string) => string): this;
colors(): (key: string) => string;
colors(v: (key: string) => string): this;
fontSize(): string | null;
fontSize(v: string | null): this;
duration(): number;
duration(v: number): this;
/**
* normalize the solution
* @default true
*/
normalize(): boolean;
normalize(v: boolean): this;
layoutFunction(): typeof venn;
layoutFunction(v: typeof venn): this;
scaleToFit(): boolean;
scaleToFit(v: boolean): this;
styled(): boolean;
styled(v: boolean): this;
/**
* round generate path to the given number of digits or null to disable
* @default null
*/
round(): number | null;
round(v: number | null): this;
/**
* interpret the data as distinct sets, so set A is actually set A \ B u C
* thus A is (A \ (B u C)) u (A ^ B \ C) u (A ^ C \ B) u (A ^ B ^ C)
* @default false
*/
distinct(): boolean;
distinct(v: boolean): this;
orientation(): number;
orientation(v: number): this;
orientationOrder(): null | ((a: ICircle, b: ICircle) => number);
orientationOrder(v: null | ((a: ICircle, b: ICircle) => number)): this;
lossFunction(): typeof lossFunction;
lossFunction(v: 'logRatio'): this;
lossFunction(v: 'default'): this;
lossFunction(v: typeof lossFunction): this;
}
/**
* VennDiagram includes an optional `options` parameter containing the following option(s):
*
* `colourScheme: Array<String>`
* A list of color values to be applied when coloring diagram circles.
*
* `symmetricalTextCentre: Boolean`
* Whether to symmetrically center each circle's text horizontally and vertically.
* Defaults to `false`.
*
* `textFill: String`
* The color to be applied to the text within each circle.
*/
export function VennDiagram(options?: IVennDiagramOptions): IVennDiagram;
export interface IComputeVennLayoutOptions {
width?: number;
height?: number;
padding?: number;
/**
* @default true
*/
normalize?: boolean;
layoutFunction?: typeof venn;
lossFunction?: typeof lossFunction | 'logRatio';
scaleToFit?: boolean;
orientation?: number;
distinct?: boolean;
/**
* @default 2
*/
round?: number;
orientationOrder?: (a: ICircle, b: ICircle) => number;
}
export interface IVennLayout<T> {
data: T;
/**
* text location
*/
text: IPoint;
circles: readonly (ICircle & { set: string })[];
arcs: readonly { circle: ICircle; width: number; p1: IPoint; p2: IPoint; large: boolean; sweep: boolean }[];
/**
* SVG path
*/
path: string;
/**
* distinct SVG path, render with `fill-rule: evenodd`;
*/
distinctPath: string;
}
export function layout<T extends ISetOverlap>(
data: readonly T[],
options?: IComputeVennLayoutOptions
): IVennLayout<T>[];