Skip to content

Commit 86d2f64

Browse files
committed
Styling Feature
Co-authored-by: jwagner988 jwagner988@gmail.com Co-authored by: vincent114 Vincent.trang1@gmail.com Co-authored by: mimiwrp mimiwirapa@gmail.com Co-authored by: ericJH92 eric.j.h92@gmail.com
1 parent 7bbc607 commit 86d2f64

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

frontend/components/views/CompareView/CompareChart.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,19 @@ const getChartData = (
3535
const comparedQueries = Object.values(queries);
3636

3737
// unique query labels
38-
const groupLabels = [...new Set(comparedQueries.map((query) => `label:${query.label} db:${query.db} group:${query.group}`))];
38+
const uniqueLabels = [...new Set(comparedQueries.map((query) => `label:${query.label} db:${query.db} group:${query.group}`))];
3939
const labels = [...new Set(comparedQueries.map((query) => query.group))];
4040

4141
// unique dbs in comparison
4242
const comparedDbs = [...new Set(comparedQueries.map((query) => query.db))];
4343

44+
//Algorithm for grouping speeds by group
4445
const groups:object = {};
45-
for (let i = 0; i < groupLabels.length; i++) {
46-
if (groups[queries[groupLabels[i]].db]) {
47-
groups[queries[groupLabels[i]].db].push(getTotalTime(queries[groupLabels[i]]));
46+
for (let i = 0; i < uniqueLabels.length; i++) {
47+
if (groups[queries[uniqueLabels[i]].db]) {
48+
groups[queries[uniqueLabels[i]].db].push(getTotalTime(queries[uniqueLabels[i]]));
4849
} else {
49-
groups[queries[groupLabels[i]].db] = [getTotalTime(queries[groupLabels[i]])];
50+
groups[queries[uniqueLabels[i]].db] = [getTotalTime(queries[uniqueLabels[i]])];
5051
};
5152
};
5253

@@ -58,12 +59,11 @@ const getChartData = (
5859
backgroundColor: color,
5960
borderColor: color,
6061
borderWidth: 1,
61-
// array with values for each label. If db doesn't have a query with a
62+
// array with values for each group. If group doesn't have a query with a
6263
// given label being compared, set it's value to
6364
data: groups[db],
6465
};
6566
});
66-
console.log(labels, datasets)
6767

6868
return { labels, datasets };
6969
};
@@ -77,6 +77,7 @@ const CompareChart = ({ queries }: CompareChartProps) => (
7777
<Bar
7878
data={getChartData(queries)}
7979
options={{
80+
8081
title: {
8182
display: true,
8283
text: 'QUERY GROUP VS RUNTIME (ms)',
@@ -94,6 +95,13 @@ const CompareChart = ({ queries }: CompareChartProps) => (
9495
}],
9596
},
9697
maintainAspectRatio: false,
98+
// tooltips: {
99+
// callbacks: {
100+
// label: function(data) {
101+
// return `${Object.keys(data)} THIS IS THE OTHER THING: ${data.index}`
102+
// }
103+
// }
104+
// },
97105
}}
98106
/>
99107
</ChartContainer>

frontend/components/views/CompareView/CompareTable.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const StyledCell = styled(TableCell)<{
3131
`;
3232

3333
const FastestMarker = () => (
34-
<Tooltip title="Fastest Query in label group">
34+
<Tooltip title="Fastest Query in group">
3535
<SpeedIcon style={{ margin: 0 }} />
3636
</Tooltip>
3737
);
@@ -50,6 +50,7 @@ type InfoColumn = [
5050

5151
// Array of columns names and transformers that receive query and return printable value
5252
const tableInfo: InfoColumn[] = [
53+
['Group', 'left', (q: QueryData) => q.group],
5354
['Label', 'left', (q: QueryData) => q.label],
5455
['Database', 'left', (q: QueryData) => q.db],
5556
['Timing', 'right', getPrettyTime],
@@ -67,7 +68,7 @@ const getFastestPerGroup = (queries: QueryData[]) =>
6768
queries.reduce<Record<string, number>>(
6869
(acc, q) => ({
6970
...acc,
70-
[q.label]: Math.min(acc[q.label] ?? Infinity, getTotalTime(q)),
71+
[q.group]: Math.min(acc[q.group] ?? Infinity, getTotalTime(q)),
7172
}),
7273
{}
7374
);
@@ -77,8 +78,8 @@ const analyze = (queries: QueryData[]): AnalysedQuery[] => {
7778
const fastest = getFastestPerGroup(queries);
7879
return queries.map((q) => ({
7980
...q,
80-
relativeSpeed: getTotalTime(q) / fastest[q.label],
81-
isFastest: fastest[q.label] === getTotalTime(q),
81+
relativeSpeed: getTotalTime(q) / fastest[q.group],
82+
isFastest: fastest[q.group] === getTotalTime(q),
8283
}));
8384
};
8485

@@ -110,11 +111,11 @@ const CompareTable = ({ queries }: CompareTableProps) => {
110111
</TableHead>
111112
<TableBody>
112113
{comparedQueries.map((query: AnalysedQuery) => (
113-
<TableRow key={query.label + query.db}>
114+
<TableRow key={query.label + query.db + query.group}>
114115
{tableInfo.map(([columnLabel, alignment, transformer]) => (
115116
<StyledCell
116117
align={alignment}
117-
key={`${query.label}_${query.db}_${columnLabel}`}
118+
key={`${query.label}_${query.db}_${query.group}_${columnLabel}`}
118119
$isFastest={query.isFastest}
119120
$isMarker={!columnLabel}
120121
>

0 commit comments

Comments
 (0)