-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
156 additions
and
99 deletions.
There are no files selected for viewing
82 changes: 0 additions & 82 deletions
82
x-pack/legacy/plugins/graph/public/angular/angular_venn_simple.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
@import './venn_diagram/index'; | ||
@import './settings/index'; |
1 change: 1 addition & 0 deletions
1
x-pack/legacy/plugins/graph/public/components/venn_diagram/_index.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import './venn_diagram'; |
9 changes: 9 additions & 0 deletions
9
x-pack/legacy/plugins/graph/public/components/venn_diagram/_venn_diagram.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.gphVennDiagram__left { | ||
fill: $euiColorDanger; | ||
fill-opacity: 0.5; | ||
} | ||
|
||
.gphVennDiagram__right { | ||
fill: $euiColorPrimary; | ||
fill-opacity: 0.5; | ||
} |
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/plugins/graph/public/components/venn_diagram/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export * from './venn_diagram'; |
70 changes: 70 additions & 0 deletions
70
x-pack/legacy/plugins/graph/public/components/venn_diagram/venn_diagram.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import { VennDiagram } from './venn_diagram'; | ||
|
||
describe('venn_diagram', () => { | ||
it('should render svg with correct coordinates', () => { | ||
const instance = shallow(<VennDiagram leftValue={30} rightValue={60} overlap={6} />); | ||
expect(instance).toMatchInlineSnapshot(` | ||
<div> | ||
<svg | ||
height={60} | ||
viewBox="0 0 17.480774889473267 8.740387444736633" | ||
width={100} | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<g> | ||
<circle | ||
className="gphVennDiagram__left" | ||
cx={5.284377114585398} | ||
cy={4.370193722368317} | ||
r={3.0901936161855166} | ||
/> | ||
<circle | ||
className="gphVennDiagram__right" | ||
cx={10.91639766870507} | ||
cy={4.370193722368317} | ||
r={4.370193722368317} | ||
/> | ||
</g> | ||
</svg> | ||
</div> | ||
`); | ||
}); | ||
|
||
it('should also work for very big numbers', () => { | ||
const instance = shallow(<VennDiagram leftValue={30000} rightValue={60000} overlap={6000} />); | ||
expect(instance).toMatchInlineSnapshot(` | ||
<div> | ||
<svg | ||
height={60} | ||
viewBox="0 0 552.7906391541368 276.3953195770684" | ||
width={100} | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<g> | ||
<circle | ||
className="gphVennDiagram__left" | ||
cx={167.10667697398674} | ||
cy={138.1976597885342} | ||
r={97.720502380584} | ||
/> | ||
<circle | ||
className="gphVennDiagram__right" | ||
cx={345.20680477219986} | ||
cy={138.1976597885342} | ||
r={138.1976597885342} | ||
/> | ||
</g> | ||
</svg> | ||
</div> | ||
`); | ||
}); | ||
}); |
59 changes: 59 additions & 0 deletions
59
x-pack/legacy/plugins/graph/public/components/venn_diagram/venn_diagram.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
// @ts-ignore | ||
import { distanceFromIntersectArea } from 'venn.js'; | ||
import React from 'react'; | ||
|
||
export interface VennDiagramProps { | ||
leftValue: number; | ||
rightValue: number; | ||
overlap: number; | ||
} | ||
|
||
function getRadius(area: number) { | ||
return Math.sqrt(area / Math.PI); | ||
} | ||
|
||
export function VennDiagram({ leftValue, rightValue, overlap }: VennDiagramProps) { | ||
const leftRadius = getRadius(leftValue); | ||
const rightRadius = getRadius(rightValue); | ||
|
||
const maxRadius = Math.max(leftRadius, rightRadius); | ||
|
||
const imageHeight = maxRadius * 2; | ||
const imageWidth = maxRadius * 4; | ||
|
||
const leftCenter = leftRadius; | ||
const rightCenter = leftCenter + distanceFromIntersectArea(leftRadius, rightRadius, overlap); | ||
|
||
// blank width is what's left after the right venn circle - it is used as padding | ||
const blankWidth = imageWidth - (rightCenter + rightRadius); | ||
const padding = blankWidth / 2; | ||
|
||
const viewBoxDims = `0 0 ${imageWidth} ${imageHeight}`; | ||
|
||
return ( | ||
<div> | ||
<svg xmlns="http://www.w3.org/2000/svg" width={100} height={60} viewBox={viewBoxDims}> | ||
<g> | ||
<circle | ||
cx={leftCenter + padding} | ||
cy={maxRadius} | ||
r={leftRadius} | ||
className="gphVennDiagram__left" | ||
/> | ||
<circle | ||
cx={rightCenter + padding} | ||
cy={maxRadius} | ||
r={rightRadius} | ||
className="gphVennDiagram__right" | ||
/> | ||
</g> | ||
</svg> | ||
</div> | ||
); | ||
} |