Skip to content

Commit ff028ca

Browse files
authored
Merge pull request #43 from gregzanch/dev-jb-2
rt chart legend
2 parents 46dbef3 + 562b509 commit ff028ca

File tree

1 file changed

+81
-4
lines changed

1 file changed

+81
-4
lines changed

src/components/results/RT60Chart.tsx

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { Grid, GridRows } from '@visx/grid';
88
import { Result, ResultKind, useResult } from '../../store/result-store';
99
import { pickProps } from '../../common/helpers';
1010
import { on } from '../../messenger';
11+
import styled from 'styled-components';
12+
import { LegendItem, LegendOrdinal } from '@visx/legend';
13+
import PropertyRowLabel from '../parameter-config/property-row/PropertyRowLabel';
1114

1215
export type BarGroupProps = {
1316
uuid: string;
@@ -64,9 +67,11 @@ const testrtdata: RTData[] = [
6467

6568
//type CityName = 'New York' | 'San Francisco' | 'Austin';
6669

70+
const blue = '#48beff';
71+
const green = '#43c593';
72+
const darkgreen = '#14453d';
6773
const black = '#000000';
68-
const red = '#ff0000';
69-
const green = '#00ff00';
74+
7075
export const background = '#612efb';
7176

7277
type RtType = 'Sabine' | 'Eyring' | 'AP';
@@ -83,12 +88,48 @@ const getFreqAsString = (d: RTData) => (d.frequency).toString()
8388
const getSabine = (d: RTData) => d.sabine;
8489
const getEyring = (d: RTData) => d.eyring;
8590

91+
const VerticalContainer = styled.div`
92+
display: flex;
93+
flex-direction: column;
94+
`;
95+
96+
const Title = styled.div`
97+
display: flex;
98+
justify-content: center;
99+
`;
100+
101+
const HorizontalContainer = styled.div`
102+
display: flex;
103+
flex-direction: row;
104+
flex: 1;
105+
`;
106+
107+
const LegendContainer = styled.div`
108+
display: flex;
109+
flex-direction: column;
110+
align-items: center;
111+
padding: 0px 16px;
112+
`;
113+
114+
const FrequencyContainer = styled.div`
115+
display: flex;
116+
flex-direction: column;
117+
align-items: center;
118+
padding: 16px 16px;
119+
`;
120+
121+
const GraphContainer = styled.div`
122+
display: flex;
123+
flex: 8;
124+
width: 80%;
125+
`;
126+
86127
const useUpdate = () => {
87128
const [updateCount, setUpdateCount] = useState<number>(0);
88129
return [updateCount, () => setUpdateCount(updateCount + 1)] as [number, () => void];
89130
}
90131

91-
export const RT60Chart = ({
132+
export const Chart = ({
92133
uuid,
93134
width = 500,
94135
height = 300,
@@ -117,7 +158,7 @@ export const RT60Chart = ({
117158

118159
const colorScale = scaleOrdinal<string, string>({
119160
domain: keys,
120-
range: [black, red, green],
161+
range: [blue, green, darkgreen],
121162
});
122163

123164
useEffect(() => on("UPDATE_RESULT", (e) => {
@@ -210,4 +251,40 @@ export const RT60Chart = ({
210251
);
211252
}
212253

254+
export const RT60Chart = ({
255+
uuid,
256+
width = 500,
257+
height = 300,
258+
events = false,
259+
}: BarGroupProps) => {
260+
const {info, data, from} = useResult(state=>pickProps(["info", "data", "from"], state.results[uuid] as Result<ResultKind.StatisticalRT60>))
261+
const keys = Object.keys(data[0]).filter(d => d !== 'frequency') as RtType[];
262+
263+
return width < 10 ? null : (
264+
<VerticalContainer>
265+
<Title>{'Statistical RT60 Results'}</Title>
266+
<HorizontalContainer>
267+
<GraphContainer>
268+
<Chart {...{ width, height, uuid, events }}></Chart>
269+
</GraphContainer>
270+
<VerticalContainer>
271+
<LegendContainer>
272+
{keys.map((k)=>{
273+
<LegendItem
274+
key={`rt-type-${k}`}
275+
margin="0 5px"
276+
onClick={() => {
277+
}}>
278+
<PropertyRowLabel
279+
label={k.toString()}
280+
/>
281+
</LegendItem>
282+
})}
283+
</LegendContainer>
284+
</VerticalContainer>
285+
</HorizontalContainer>
286+
</VerticalContainer>
287+
);
288+
};
289+
213290
export default RT60Chart

0 commit comments

Comments
 (0)