|
1 |
| -import React, { Component, useEffect, useState } from 'react'; |
| 1 | +import React, { Component, useEffect, useState, Fragment } from 'react'; |
2 | 2 | // import * as d3 from 'd3';
|
3 | 3 | // import {sankey} from 'sankey';
|
4 | 4 | import { Chart } from 'react-google-charts';
|
| 5 | +// import { Fragment } from '../../backend/types/backendTypes'; |
5 | 6 |
|
6 | 7 | /**
|
7 | 8 | * @method maked3Tree :Creates a new D3 Tree
|
8 | 9 | */
|
9 | 10 |
|
10 | 11 | function AtomsRelationship(props) {
|
11 |
| - console.log('Props', props.atomsRel); |
12 | 12 |
|
13 | 13 | const {atomsRel} = props
|
14 | 14 |
|
15 | 15 |
|
| 16 | + const atomsAndComp = atomsRel.filter(e => e[2] !== 'atoms and selectors').map(e => { |
| 17 | + let copy = [...e]; |
| 18 | + copy[2] = 1; |
| 19 | + return [...copy] |
| 20 | + }) |
| 21 | + const atomsAndSelectors = atomsRel.filter(e => e[2] === 'atoms and selectors').map(e => { |
| 22 | + let copy = [...e]; |
| 23 | + copy[2] = 1; |
| 24 | + return [...copy] |
| 25 | + }) |
| 26 | + const copyatomsRel = atomsRel.map(e => { let copy = [...e]; copy[2] = 1; return copy; }); |
| 27 | + |
| 28 | + // console.log('atoms and selectors', atomsAndSelectors); |
| 29 | + // console.log('copy Atom rel', copyatomsRel); |
| 30 | + // console.log('initial atom rel', atomsRel); |
| 31 | + const [atoms, setAtoms] = useState([...copyatomsRel]); |
| 32 | + const [atomAndSelectorCheck, setAtomAndSelectorCheck] = useState(false); |
| 33 | + const [atomAndCompCheck, setAtomAndCompCheck] = useState(false); |
| 34 | + |
| 35 | + useEffect( () => { |
| 36 | + if ((!atomAndSelectorCheck && !atomAndCompCheck) || (atomAndSelectorCheck && atomAndCompCheck)) { |
| 37 | + setAtoms(copyatomsRel); |
| 38 | + } else if (atomAndSelectorCheck) { |
| 39 | + setAtoms(atomsAndSelectors); |
| 40 | + } else { |
| 41 | + setAtoms(atomsAndComp); |
| 42 | + } |
| 43 | + }, [atomAndSelectorCheck, atomAndCompCheck]) |
| 44 | + |
16 | 45 | return (
|
17 | 46 | <div className="history-d3-container">
|
18 |
| - {atomsRel && ( |
| 47 | + {atoms && ( |
| 48 | + // <div> |
| 49 | + <Fragment> |
19 | 50 | <Chart
|
20 | 51 | width={'100%'}
|
21 | 52 | height={'100%'}
|
@@ -49,9 +80,19 @@ function AtomsRelationship(props) {
|
49 | 80 | tooltip: { textStyle: { color: 'gray', fontSize: 12 }},
|
50 | 81 | }}
|
51 | 82 | loader={<div>Loading Chart</div>}
|
52 |
| - data={[['Atom', 'Selector', ''], ...atomsRel]} |
| 83 | + data={[['Atom', 'Selector', ''], ...atoms]} |
53 | 84 | rootProps={{ 'data-testid': '1' }}
|
54 |
| - />)} |
| 85 | + /> |
| 86 | + <div> |
| 87 | + <input type="checkbox" id='atomscomps' onClick={e => setAtomAndCompCheck(atomAndCompCheck ? false: true)}/> |
| 88 | + <label htmlFor="atomscomps"> Only Show Atoms (or Selectors) and Components </label> |
| 89 | + <input type="checkbox" id='atomsselectors' onClick={e => setAtomAndSelectorCheck(atomAndSelectorCheck ? false : true)} /> |
| 90 | + <label htmlFor="atomsselectors"> Only Show Atoms and Selectors </label> |
| 91 | + </div> |
| 92 | + </Fragment> |
| 93 | + ) |
| 94 | + |
| 95 | + } |
55 | 96 | </div>
|
56 | 97 | );
|
57 | 98 | }
|
|
0 commit comments