Compare commits
6 Commits
sem2-lab8-
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c82bceccf | ||
|
|
68da0a5e7c | ||
|
|
95f1fce0e2 | ||
|
|
e52bf11cc4 | ||
|
|
eda72b4c70 | ||
| c0894969dd |
@@ -2,7 +2,7 @@ import NavBar from './components/Navbar'
|
|||||||
import Gallery from "./components/Gallery";
|
import Gallery from "./components/Gallery";
|
||||||
import Content from "./components/Content";
|
import Content from "./components/Content";
|
||||||
import CustomFooter from "./components/CustomFooter";
|
import CustomFooter from "./components/CustomFooter";
|
||||||
|
import Task from "./Task"
|
||||||
|
|
||||||
import './styles/App.css'
|
import './styles/App.css'
|
||||||
|
|
||||||
@@ -13,6 +13,7 @@ function App() {
|
|||||||
<Gallery/>
|
<Gallery/>
|
||||||
<Content/>
|
<Content/>
|
||||||
<CustomFooter/>
|
<CustomFooter/>
|
||||||
|
<Task/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
38
labs/lab6/src/Task.tsx
Normal file
38
labs/lab6/src/Task.tsx
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { useState,useEffect } from "react"
|
||||||
|
import type {ReactElement} from "react"
|
||||||
|
const lines = [
|
||||||
|
"Ночь, улица, фонарь, аптека,",
|
||||||
|
"Бессмыссленный и тусклый свет.",
|
||||||
|
"Живи ещё хоть четверть века - ",
|
||||||
|
"Всё будет так. Исхода нет.",
|
||||||
|
"Умрёшь - начнёшь опять сначала",
|
||||||
|
"И повториться всё как встарь:",
|
||||||
|
"Ночь, ледяная рябь канала",
|
||||||
|
"Аптека, Улица, фонарь."
|
||||||
|
];
|
||||||
|
|
||||||
|
interface ComponentProps {
|
||||||
|
Inputinterval: number
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const Task = ({Inputinterval}:ComponentProps): ReactElement =>{
|
||||||
|
const [interval, updateInterval] = useState<number>(Inputinterval);
|
||||||
|
const [lineIdx, updateLineIdx] = useState<number>(0);
|
||||||
|
const updateLine = ():void =>{
|
||||||
|
updateLineIdx((lineIdx+1)%lines.length);
|
||||||
|
}
|
||||||
|
useEffect(()=>{
|
||||||
|
const intervalId = setInterval(updateLine,Number(interval));
|
||||||
|
return ()=>{ clearInterval(intervalId)}
|
||||||
|
})
|
||||||
|
return(
|
||||||
|
<>
|
||||||
|
<input type="number" value={interval} onChange={(event)=>{updateInterval(Number(event.target.value))}}></input>
|
||||||
|
<div className="blackDiv">
|
||||||
|
<h2 className="bigWhite">{lines[lineIdx]}</h2>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
export default Task;
|
||||||
@@ -24,8 +24,10 @@ interface ComponentProps {
|
|||||||
|
|
||||||
|
|
||||||
function BuildCard({ building,cardNum} : ComponentProps) {
|
function BuildCard({ building,cardNum} : ComponentProps) {
|
||||||
|
const reverseModifier = cardNum % 2 == 0 ? "-reverse" : "";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card style={cardNum%2==0?{'flexDirection':'row-reverse'}:{}}sx={{ display: 'flex' }} >
|
<Card sx={{ display: 'flex', flexDirection:{xs:"column", sm:"row"+reverseModifier} }} >
|
||||||
<CardMedia
|
<CardMedia
|
||||||
component="img"
|
component="img"
|
||||||
alt={ building.title }
|
alt={ building.title }
|
||||||
|
|||||||
@@ -10,21 +10,43 @@ type GroupProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function GroupChart({ data }: GroupProps) {
|
function GroupChart({ data }: GroupProps) {
|
||||||
const [isBar, setIsBar] = useState(true);
|
const [isBar, setIsBar] = useState(true);
|
||||||
|
const [doStack, setDoStack] = useState(false);
|
||||||
const [series, setSeries] = useState({
|
const [series, setSeries] = useState({
|
||||||
'max': true,
|
|
||||||
'mean': false,
|
|
||||||
'min': false,
|
'min': false,
|
||||||
|
'mean': false,
|
||||||
|
'max': true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const deltas = data.map((val) => {
|
||||||
|
const out = { ...val };
|
||||||
|
const deltaMinMean = (val["mean"] - (Number(series["min"])?val["min"]:0));
|
||||||
|
const deltaMeanMax = (val["max"] - (Number(series["mean"])?val["mean"]:(series["min"]?val["min"]:0)));
|
||||||
|
out["mean"] = deltaMinMean;
|
||||||
|
out["max"] = deltaMeanMax;
|
||||||
|
return out;
|
||||||
|
})
|
||||||
|
const formatLabel = (key:string)=>(value:number,didx:{dataIndex:number}):number => {
|
||||||
|
const idx= didx["dataIndex"]
|
||||||
|
return String(data[idx][key]);
|
||||||
|
}
|
||||||
|
|
||||||
const selectedSeries = Object.entries(series).filter(item => item[1] === true);
|
const selectedSeries = Object.entries(series).filter(item => item[1] === true);
|
||||||
|
|
||||||
let seriesY = selectedSeries.map(item => {
|
let seriesY = selectedSeries.map(item => {
|
||||||
return {
|
return {
|
||||||
dataKey: item[0],
|
dataKey: item[0],
|
||||||
label: item[0],
|
label: item[0],
|
||||||
barLabel: selectedSeries.length === 1 ? ('value' as const) : undefined,
|
barLabel: (selectedSeries.length === 1) && (data.length < 20) ? ('value' as const) : undefined,
|
||||||
|
stack: doStack && isBar ? 'prices' : undefined,
|
||||||
|
valueFormatter: (doStack && isBar)? formatLabel(item[0]):(v:number)=>String(v)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
console.log(seriesY)
|
||||||
|
console.log(doStack)
|
||||||
const chartSetting = {
|
const chartSetting = {
|
||||||
yAxis: [{ label: 'Price ($)' }],
|
yAxis: [{ label: 'Price ($)' }],
|
||||||
height: 400,
|
height: 400,
|
||||||
@@ -33,7 +55,7 @@ function GroupChart({ data }: GroupProps) {
|
|||||||
return (
|
return (
|
||||||
<Container maxWidth="lg">
|
<Container maxWidth="lg">
|
||||||
{isBar && <BarChart
|
{isBar && <BarChart
|
||||||
dataset={data}
|
dataset={doStack ? deltas : data}
|
||||||
xAxis={[{ scaleType: 'band', dataKey: 'group' }]}
|
xAxis={[{ scaleType: 'band', dataKey: 'group' }]}
|
||||||
series={seriesY}
|
series={seriesY}
|
||||||
slotProps={{
|
slotProps={{
|
||||||
@@ -43,7 +65,7 @@ function GroupChart({ data }: GroupProps) {
|
|||||||
}}
|
}}
|
||||||
{...chartSetting}
|
{...chartSetting}
|
||||||
/>}
|
/>}
|
||||||
{!isBar &&<LineChart
|
{!isBar && <LineChart
|
||||||
dataset={data}
|
dataset={data}
|
||||||
xAxis={[{ scaleType: 'band', dataKey: 'group' }]}
|
xAxis={[{ scaleType: 'band', dataKey: 'group' }]}
|
||||||
series={seriesY}
|
series={seriesY}
|
||||||
@@ -54,7 +76,7 @@ function GroupChart({ data }: GroupProps) {
|
|||||||
}}
|
}}
|
||||||
{...chartSetting}
|
{...chartSetting}
|
||||||
/>}
|
/>}
|
||||||
<SettingChart series={series} setSeries={setSeries} isBar={isBar} setIsBar={setIsBar} />
|
<SettingChart series={series} setSeries={setSeries} isBar={isBar} setIsBar={setIsBar} doStack={doStack} setDoStack={setDoStack} />
|
||||||
</Container>
|
</Container>
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import Stack from '@mui/material/Stack';
|
|||||||
import Divider from '@mui/material/Divider';
|
import Divider from '@mui/material/Divider';
|
||||||
import RadioGroup from '@mui/material/RadioGroup';
|
import RadioGroup from '@mui/material/RadioGroup';
|
||||||
import Radio from '@mui/material/Radio';
|
import Radio from '@mui/material/Radio';
|
||||||
|
import Switch from '@mui/material/Switch';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type tSeries = {
|
type tSeries = {
|
||||||
@@ -19,9 +21,12 @@ type CheckboxProps = {
|
|||||||
setSeries: React.Dispatch<React.SetStateAction<tSeries>>;
|
setSeries: React.Dispatch<React.SetStateAction<tSeries>>;
|
||||||
isBar: boolean;
|
isBar: boolean;
|
||||||
setIsBar: React.Dispatch<React.SetStateAction<boolean>>
|
setIsBar: React.Dispatch<React.SetStateAction<boolean>>
|
||||||
|
doStack: boolean;
|
||||||
|
setDoStack: React.Dispatch<React.SetStateAction<boolean>>
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function SettingChart({ series, setSeries, isBar, setIsBar }: CheckboxProps) {
|
function SettingChart({ series, setSeries, isBar, setIsBar, doStack, setDoStack }: CheckboxProps) {
|
||||||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setSeries({
|
setSeries({
|
||||||
...series,
|
...series,
|
||||||
@@ -29,6 +34,10 @@ function SettingChart({ series, setSeries, isBar, setIsBar }: CheckboxProps) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const changeDoStack =(event:React.ChangeEvent<HTMLInputElement>)=>{
|
||||||
|
setDoStack(event.target.checked)
|
||||||
|
}
|
||||||
|
|
||||||
const handleRadioButtonChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleRadioButtonChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setIsBar(event.target.value === "bar");
|
setIsBar(event.target.value === "bar");
|
||||||
};
|
};
|
||||||
@@ -89,6 +98,17 @@ function SettingChart({ series, setSeries, isBar, setIsBar }: CheckboxProps) {
|
|||||||
}
|
}
|
||||||
label="Min price"
|
label="Min price"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<FormControlLabel
|
||||||
|
control={
|
||||||
|
<Switch
|
||||||
|
checked={doStack}
|
||||||
|
onChange={changeDoStack}
|
||||||
|
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
label="Do Stack"
|
||||||
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</Stack>
|
</Stack>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -173,8 +173,8 @@ type GroupedRamPrice =Array<{
|
|||||||
id: number;
|
id: number;
|
||||||
group: string | number;
|
group: string | number;
|
||||||
min:number;
|
min:number;
|
||||||
max:number;
|
|
||||||
mean:number;
|
mean:number;
|
||||||
|
max:number;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
const gropuedPrices = groupBycolumns.map((col) => {
|
const gropuedPrices = groupBycolumns.map((col) => {
|
||||||
@@ -184,9 +184,10 @@ const gropuedPrices = groupBycolumns.map((col) => {
|
|||||||
out.push({
|
out.push({
|
||||||
id: out.length + 1,
|
id: out.length + 1,
|
||||||
group: key,
|
group: key,
|
||||||
min: d3.min(prices) ?? 0,
|
|
||||||
max: d3.max(prices) ?? 0,
|
|
||||||
mean: Math.round((d3.mean(prices) ?? 0)*1000)/1000,
|
mean: Math.round((d3.mean(prices) ?? 0)*1000)/1000,
|
||||||
|
max: d3.max(prices) ?? 0,
|
||||||
|
min: d3.min(prices) ?? 0,
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ function Gallery() {
|
|||||||
sx={{
|
sx={{
|
||||||
columnCount: {
|
columnCount: {
|
||||||
xs: '1 !important',
|
xs: '1 !important',
|
||||||
sm: '3 !important',
|
sm: '1 !important',
|
||||||
md: '3 !important',
|
md: '3 !important',
|
||||||
lg: '3 !important',
|
lg: '3 !important',
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user