|
1 | 1 | import React, { Component, useEffect, useState, Fragment } from 'react';
|
2 |
| -import { Chart } from 'react-google-charts' |
| 2 | +import { Chart } from 'react-google-charts'; |
3 | 3 |
|
4 | 4 | function AtomsRelationship(props) {
|
5 |
| - const {atomsRel} = props |
| 5 | + const { atomsRel } = props; |
6 | 6 |
|
7 |
| - const atomsAndComp = atomsRel.filter(e => e[2] !== 'atoms and selectors').map(e => { |
8 |
| - let copy = [...e]; |
9 |
| - copy[2] = 1; |
10 |
| - return [...copy] |
11 |
| - }); |
| 7 | + const atomsAndComp = atomsRel |
| 8 | + .filter((e) => e[2] !== 'atoms and selectors') |
| 9 | + .map((e) => { |
| 10 | + let copy = [...e]; |
| 11 | + copy[2] = 1; |
| 12 | + return [...copy]; |
| 13 | + }); |
12 | 14 |
|
13 |
| - const atomsAndSelectors = atomsRel.filter(e => e[2] === 'atoms and selectors').map(e => { |
| 15 | + const atomsAndSelectors = atomsRel |
| 16 | + .filter((e) => e[2] === 'atoms and selectors') |
| 17 | + .map((e) => { |
| 18 | + let copy = [...e]; |
| 19 | + copy[2] = 1; |
| 20 | + return [...copy]; |
| 21 | + }); |
| 22 | + |
| 23 | + const copyatomsRel = atomsRel.map((e) => { |
14 | 24 | let copy = [...e];
|
15 | 25 | copy[2] = 1;
|
16 |
| - return [...copy] |
| 26 | + return copy; |
17 | 27 | });
|
18 |
| - |
19 |
| - const copyatomsRel = atomsRel.map(e => { let copy = [...e]; copy[2] = 1; return copy; }); |
20 | 28 | const [atoms, setAtoms] = useState([...copyatomsRel]);
|
21 | 29 | const [atomAndSelectorCheck, setAtomAndSelectorCheck] = useState(false);
|
22 | 30 | const [atomAndCompCheck, setAtomAndCompCheck] = useState(false);
|
23 | 31 |
|
24 |
| - useEffect( () => { |
25 |
| - if ((!atomAndSelectorCheck && !atomAndCompCheck) || (atomAndSelectorCheck && atomAndCompCheck)) { |
| 32 | + useEffect(() => { |
| 33 | + if ( |
| 34 | + (!atomAndSelectorCheck && !atomAndCompCheck) || |
| 35 | + (atomAndSelectorCheck && atomAndCompCheck) |
| 36 | + ) { |
26 | 37 | setAtoms(copyatomsRel);
|
27 | 38 | } else if (atomAndSelectorCheck) {
|
28 | 39 | setAtoms(atomsAndSelectors);
|
29 | 40 | } else {
|
30 | 41 | setAtoms(atomsAndComp);
|
31 | 42 | }
|
32 |
| - }, [atomAndSelectorCheck, atomAndCompCheck, props]) |
| 43 | + }, [atomAndSelectorCheck, atomAndCompCheck, props]); |
33 | 44 |
|
34 | 45 | return (
|
35 | 46 | <div className="history-d3-container">
|
36 | 47 | {atoms && (
|
37 |
| - <Fragment> |
38 |
| - <Chart |
39 |
| - width={'100%'} |
40 |
| - height={'100%'} |
41 |
| - chartType="Sankey" |
42 |
| - options={{ |
43 |
| - sankey: { |
44 |
| - link: { color: { fill: '#gray', fillOpacity: 0.1 } }, |
45 |
| - node: { |
46 |
| - colors: [ |
47 |
| - '#4a91c7', |
48 |
| - '#5b9bce', |
49 |
| - '#6ba6d5', |
50 |
| - '#7bb0dc', |
51 |
| - '#8abbe3', |
52 |
| - '#99c6ea', |
53 |
| - '#a8d0f1', |
54 |
| - '#b7dbf8', |
55 |
| - '#c6e6ff', |
56 |
| - '#46edf2', |
57 |
| - '#76f5f3', |
58 |
| - '#95B6B7', |
59 |
| - '#76dcde', |
60 |
| - '#5fdaed', |
61 |
| - ], |
| 48 | + <Fragment> |
| 49 | + <Chart |
| 50 | + width={'100%'} |
| 51 | + height={'98%'} |
| 52 | + chartType="Sankey" |
| 53 | + options={{ |
| 54 | + sankey: { |
| 55 | + link: { color: { fill: '#gray', fillOpacity: 0.1 } }, |
| 56 | + node: { |
| 57 | + colors: [ |
| 58 | + '#4a91c7', |
| 59 | + '#5b9bce', |
| 60 | + '#6ba6d5', |
| 61 | + '#7bb0dc', |
| 62 | + '#8abbe3', |
| 63 | + '#99c6ea', |
| 64 | + '#a8d0f1', |
| 65 | + '#b7dbf8', |
| 66 | + '#c6e6ff', |
| 67 | + '#46edf2', |
| 68 | + '#76f5f3', |
| 69 | + '#95B6B7', |
| 70 | + '#76dcde', |
| 71 | + '#5fdaed', |
| 72 | + ], |
62 | 73 |
|
63 |
| - label: { color: '#fff', fontSize: '13', fontName: 'Monaco', }, |
64 |
| - nodePadding: 50, |
65 |
| - width: 15, |
66 |
| - }, |
67 |
| - }, |
68 |
| - tooltip: { textStyle: { color: 'white', fontSize: 0.1, }}, |
69 |
| - }} |
70 |
| - loader={<div>Loading Chart</div>} |
| 74 | + label: { color: '#fff', fontSize: '13', fontName: 'Monaco' }, |
| 75 | + nodePadding: 50, |
| 76 | + width: 15, |
| 77 | + }, |
| 78 | + }, |
| 79 | + tooltip: { textStyle: { color: 'white', fontSize: 0.1 } }, |
| 80 | + }} |
| 81 | + loader={<div>Loading Chart</div>} |
71 | 82 | data={[['Atom', 'Selector', ''], ...atoms]}
|
72 |
| - rootProps={{ 'data-testid': '1' }} |
73 |
| - /> |
74 |
| - <div> |
75 |
| - <input type="checkbox" id='atomscomps' onClick={e => setAtomAndCompCheck(atomAndCompCheck ? false: true)}/> |
76 |
| - <label htmlFor="atomscomps"> Only Show Atoms (or Selectors) and Components </label> |
77 |
| - <input type="checkbox" id='atomsselectors' onClick={e => setAtomAndSelectorCheck(atomAndSelectorCheck ? false : true)} /> |
78 |
| - <label htmlFor="atomsselectors"> Only Show Atoms and Selectors </label> |
79 |
| - </div> |
| 83 | + rootProps={{ 'data-testid': '1' }} |
| 84 | + /> |
| 85 | + <div> |
| 86 | + <input |
| 87 | + type="checkbox" |
| 88 | + id="atomscomps" |
| 89 | + onClick={(e) => |
| 90 | + setAtomAndCompCheck(atomAndCompCheck ? false : true) |
| 91 | + } |
| 92 | + /> |
| 93 | + <label htmlFor="atomscomps"> |
| 94 | + {' '} |
| 95 | + Only Show Atoms (or Selectors) and Components{' '} |
| 96 | + </label> |
| 97 | + <input |
| 98 | + type="checkbox" |
| 99 | + id="atomsselectors" |
| 100 | + onClick={(e) => |
| 101 | + setAtomAndSelectorCheck(atomAndSelectorCheck ? false : true) |
| 102 | + } |
| 103 | + /> |
| 104 | + <label htmlFor="atomsselectors"> |
| 105 | + {' '} |
| 106 | + Only Show Atoms and Selectors{' '} |
| 107 | + </label> |
| 108 | + </div> |
80 | 109 | </Fragment>
|
81 |
| - ) |
82 |
| - |
83 |
| - } |
| 110 | + )} |
84 | 111 | </div>
|
85 | 112 | );
|
86 | 113 | }
|
|
0 commit comments