Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fancy wifi Table and Camera Load widget (Challenge) #11

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f376756
Added sort by key feature in WiFi tab and Improved UI in WiFi tab
hanupratap Mar 17, 2021
d1ee1ca
Highlighted row and added active dot for connected network. Removed u…
hanupratap Mar 18, 2021
433147f
Added Chips for WPA, Updated dependecies, cleaned code
hanupratap Mar 19, 2021
4b06a8e
Added camer load graph
hanupratap Mar 21, 2021
e128d87
Minor UI Changes and code improvement
hanupratap Mar 21, 2021
2bd325f
Minor function name changes
hanupratap Mar 22, 2021
d17e912
Changed graph library to ApexCharts
hanupratap Mar 23, 2021
59d1f6e
graph update
hanupratap Mar 23, 2021
9ad8da4
Added bars icon
hanupratap Mar 23, 2021
8a7d92b
formatted code
hanupratap Mar 23, 2021
317f1e6
Refactored command and graph widget
hanupratap Mar 25, 2021
5b94db9
Fixed graph reset on re-render
hanupratap Mar 25, 2021
f8fe2be
Formatted Code
hanupratap Mar 25, 2021
463328d
Removed ticks and added loading text for no data
hanupratap Mar 26, 2021
7512d10
Changed case for setstate
hanupratap Mar 26, 2021
9afde1a
added showGraph in rebuild list
hanupratap Mar 26, 2021
e359728
Added CanvasJs Charts
hanupratap Mar 27, 2021
eb839ff
Changed lib to chartjs, removed unnecessary libs and files, formatted…
hanupratap Mar 29, 2021
7124ed4
minor improvements
hanupratap Mar 29, 2021
9c4fe9f
minor performance improvement
hanupratap Mar 29, 2021
2ff76b7
Fixed color in tooltip
hanupratap Mar 29, 2021
dd257e0
chartjs replaced with Dygraph charts
hanupratap Mar 30, 2021
04b462d
Graph autoscale x-direction
hanupratap Mar 31, 2021
a0b7b3e
Added open source animation
hanupratap Mar 31, 2021
13308ee
code format
hanupratap Mar 31, 2021
c435618
Added apertus animation
hanupratap Mar 31, 2021
3777914
changed tooltip position, removed hardcoded theme
hanupratap Apr 4, 2021
dfa8512
format code
hanupratap Apr 4, 2021
ddbf771
added accordion on sys-info, improved performanec
hanupratap Apr 4, 2021
8c9ecc8
format code
hanupratap Apr 4, 2021
0685002
small change in accordion
hanupratap Apr 4, 2021
8cc9a8c
added dark mode
hanupratap Apr 7, 2021
efb28fb
color highlight fix
hanupratap Apr 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions frontend/components/CommandWidgets.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,54 @@ export function Command(props) {
);
}

export function PlainCommand({ command, interval, children }) {
function extractLoadFromString(str = '') {
let list = str.split(',').map(ele => {
return ele.trim();
});
let one_min = list[2].split(':')[1];
let five_min = list[3];
let fifteen_min = list[4];

return [
{
label: 'One Minute Load',
data: [
{
primary: new Date(),
rroohhh marked this conversation as resolved.
Show resolved Hide resolved
secondary: parseFloat(one_min),
},
],
},
{
label: 'Five Minute Load',
data: [
{
primary: new Date(),
secondary: parseFloat(five_min),
},
],
},
{
label: 'Fifteen Minute Load',
data: [
{
primary: new Date(),
secondary: parseFloat(fifteen_min),
},
],
},
];
}

export function PlainCommand({ command, interval, children, updateData }) {
const [output, setOutput] = useState('');
useEffect(() => {
const callback = () =>
exec(command)
.then(result => setOutput(result[0]))
.then(result => {
setOutput(result[0]);
if (updateData !== undefined) updateData(extractLoadFromString(result[0]));
rroohhh marked this conversation as resolved.
Show resolved Hide resolved
})
.catch(err => setOutput(err[1]));
const interval_handle = setInterval(callback, interval);
callback();
Expand Down
43 changes: 43 additions & 0 deletions frontend/components/GraphUtils/ResizableBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import { ResizableBox as ReactResizableBox } from 'react-resizable';

import 'react-resizable/css/styles.css';

export default function ResizableBox({
children,
width = 500,
height = 300,
resizable = true,
style = {},
className,
}) {
return (
<div>
{resizable ? (
<ReactResizableBox width={width} height={height}>
<div
style={{
...style,
width: '100%',
height: '100%',
}}
className={className}
>
{children}
</div>
</ReactResizableBox>
) : (
<div
style={{
width: `${width}px`,
height: `${height}px`,
...style,
}}
className={className}
>
{children}
</div>
)}
</div>
);
}
155 changes: 155 additions & 0 deletions frontend/components/GraphUtils/useDevConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import React, { useEffect, useState } from 'react';
rroohhh marked this conversation as resolved.
Show resolved Hide resolved

const options = {
elementType: ['line', 'area', 'bar', 'bubble'],
primaryAxisType: ['linear', 'time', 'log', 'ordinal'],
secondaryAxisType: ['linear', 'time', 'log', 'ordinal'],
primaryAxisPosition: ['top', 'left', 'right', 'bottom'],
secondaryAxisPosition: ['top', 'left', 'right', 'bottom'],
secondaryAxisStack: [true, false],
primaryAxisShow: [true, false],
secondaryAxisShow: [true, false],
grouping: ['single', 'series', 'primary', 'secondary'],
tooltipAnchor: [
'closest',
'top',
'bottom',
'left',
'right',
'center',
'gridTop',
'gridBottom',
'gridLeft',
'gridRight',
'gridCenter',
'pointer',
],
tooltipAlign: [
'auto',
'top',
'bottom',
'left',
'right',
'topLeft',
'topRight',
'bottomLeft',
'bottomRight',
'center',
],
snapCursor: [true, false],
};

const optionKeys = Object.keys(options);

export default function useChartConfig({
series,
useR,
show = [],
count = 1,
resizable = true,
canRandomize = false,
dataType = 'time',
elementType = 'line',
primaryAxisType = 'time',
secondaryAxisType = 'linear',
primaryAxisPosition = 'bottom',
secondaryAxisPosition = 'left',
primaryAxisStack = false,
secondaryAxisStack = true,
primaryAxisShow = true,
secondaryAxisShow = true,
tooltipAnchor = 'closest',
tooltipAlign = 'auto',
grouping = 'primary',
snapCursor = true,
datums = 10,
}) {
const [state, setState] = useState({
count,
resizable,
canRandomize,
dataType,
elementType,
primaryAxisType,
secondaryAxisType,
primaryAxisPosition,
secondaryAxisPosition,
primaryAxisStack,
secondaryAxisStack,
primaryAxisShow,
secondaryAxisShow,
tooltipAnchor,
tooltipAlign,
grouping,
snapCursor,
datums,
data: [
{
label: 'One Minute Load',
data: [],
},
{
label: 'Five Minute Load',
data: [],
},
{
label: 'Fifteen Minute Load',
data: [],
},
],
});

useEffect(() => {
setState(old => ({
...old,
data: state.data,
}));
}, [count, dataType, datums, series, useR]);

const updateData = new_data => {
if (new_data === undefined) return null;

const temp_data = state;
rroohhh marked this conversation as resolved.
Show resolved Hide resolved
temp_data.data = temp_data.data.map((ele, i) => {
return {
label: new_data[i].label,
rroohhh marked this conversation as resolved.
Show resolved Hide resolved
data: ele.data.concat(new_data[i].data),
};
});

setState(old => ({
...old,
data: temp_data.data,
}));
};

const Options = optionKeys
rroohhh marked this conversation as resolved.
Show resolved Hide resolved
.filter(option => show.indexOf(option) > -1)
.map(option => (
<div key={option}>
{option}: &nbsp;
<select
value={state[option]}
onChange={({ target: { value } }) =>
setState(old => ({
...old,
[option]: typeof options[option][0] === 'boolean' ? value === 'true' : value,
}))
}
>
{options[option].map(d => (
<option value={d} key={d.toString()}>
{d.toString()}
</option>
))}
</select>
<br />
</div>
));

return {
...state,
updateData,
Options,
};
}
64 changes: 64 additions & 0 deletions frontend/components/LoadGraph.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import { Chart } from 'react-charts';

import useDemoConfig from './GraphUtils/useDevConfig';
rroohhh marked this conversation as resolved.
Show resolved Hide resolved
import ResizableBox from './GraphUtils/ResizableBox';
import { Command } from './CommandWidgets';
import { Box, Typography } from '@material-ui/core';

export default function LoadGraph() {
const datasets = {
rroohhh marked this conversation as resolved.
Show resolved Hide resolved
labels: [],
data: [{}],
};

const { data, updateData } = useDemoConfig({
series: 3,
});

const series = React.useMemo(
() => ({
showPoints: true,
}),
[]
);

const axes = React.useMemo(
() => [
{
primary: true,
type: 'time',
position: 'bottom',
},
{ type: 'linear', position: 'left' },
],
[]
);

return (
<>
<Box
style={{
padding: '0.5rem',
}}
>
<br />
<Typography variant="overline" display="block" gutterBottom>
Camera Load averages
</Typography>
<br />

<ResizableBox
style={{
background: 'rgba(0, 27, 45, 0.9)',
borderRadius: '5px',
padding: '0.1rem',
}}
>
<Chart data={data} series={series} axes={axes} tooltip dark />
</ResizableBox>
</Box>
<Command command="uptime" interval={2000} updateData={updateData} />
</>
);
}
2 changes: 1 addition & 1 deletion frontend/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const theme = createMuiTheme({
palette: {
primary: {
main: '#FA8756',
contrastText: 'white',
contrastText: '#ffffff',
},
secondary: green,
},
Expand Down
3 changes: 2 additions & 1 deletion frontend/routes/SystemInformation.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { Command } from '../components/CommandWidgets';
import LoadGraph from '../components/LoadGraph';

export const title = 'System Information';
export const route = '/system_information';
Expand All @@ -9,8 +10,8 @@ export const explanation = `Get an overview of whats going on in the linux side
export function Component(props) {
return (
<div>
<LoadGraph />
<Command command="date" interval={1000} />
<Command command="uptime" interval={1000} />
<Command command="free -h" interval={1000} />
<Command command="ip a" interval={1000} />
<Command command="uname -a" interval={10000} />
Expand Down
Loading