Skip to content

Commit

Permalink
Merge pull request #45 from SoopSASM/feature/add-components
Browse files Browse the repository at this point in the history
Modify all components code based on socket data format
  • Loading branch information
hrookim authored Oct 2, 2022
2 parents 82e9c64 + 55efbb6 commit bcb11a6
Show file tree
Hide file tree
Showing 18 changed files with 342 additions and 313 deletions.
40 changes: 19 additions & 21 deletions dashboard/src/components/SoopChart/SoopBarChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ const SoopBarChart = () => {
"rgba(255, 135, 66, 1)",
];
const exampleData = {
node: {
title: "bar timeseries chart",
chartType: "bar",
legend: true,
blankLabel: "no data",
xAxisFormat: "HH:mm:ss",
yMin: 0,
yMax: 5,
isTimeSeriesData: true,
},
title: "bar timeseries chart",
chartType: "bar",
legend: true,
blankLabel: "no data",
xAxisFormat: "HH:mm:ss",
yMin: 0,
yMax: 5,
isTimeSeries: true,
id: "노드의 id",
states: {
// TODO: nontime 버전
Expand Down Expand Up @@ -91,11 +89,11 @@ const SoopBarChart = () => {
const [chartOptions, setChartOptions] = useState({});

// const timeSeries = Date.now();
// const timeseriesToDateMoment = moment(timeSeries).format(exampleData.node.xAxisFormat);
// const timeseriesToDateMoment = moment(timeSeries).format( exampleData.xAxisFormat);
// console.log("moment 변환", timeseriesToDateMoment);

useEffect(() => {
if (!exampleData.node.isTimeSeriesData) {
if (!exampleData.isTimeSeries) {
const currentChartData = {
labels: Object.keys(exampleData.states),
datasets: [
Expand Down Expand Up @@ -129,7 +127,7 @@ const SoopBarChart = () => {
// 제목 변경
title: {
display: true,
text: exampleData.node.title,
text: exampleData.title,
color: fontColor.light,
font: {
family: "Pretendard-Bold",
Expand All @@ -138,7 +136,7 @@ const SoopBarChart = () => {
},
// 범례 변경
legend: {
display: exampleData.node.legend,
display: exampleData.legend,
labels: {
font: {
family: "Pretendard-Regular",
Expand All @@ -151,8 +149,8 @@ const SoopBarChart = () => {
// 축 변경
scales: {
y: {
min: exampleData.node.yMin,
max: exampleData.node.yMax,
min: exampleData.yMin,
max: exampleData.yMax,
ticks: {
font: {
family: "Pretendard-Light",
Expand All @@ -177,7 +175,7 @@ const SoopBarChart = () => {
} else {
const currentDatasetsLabel = Object.keys(exampleData.states);
const currentLabels = exampleData.states[currentDatasetsLabel[0]].map(data =>
moment(data.time).format(exampleData.node.xAxisFormat),
moment(data.time).format(exampleData.xAxisFormat),
);
const currentDatasets = Object.keys(exampleData.states).map((key, idx) => {
return {
Expand All @@ -199,7 +197,7 @@ const SoopBarChart = () => {
// 제목 변경
title: {
display: true,
text: exampleData.node.title,
text: exampleData.title,
color: fontColor.light,
font: {
family: "Pretendard-Bold",
Expand All @@ -208,7 +206,7 @@ const SoopBarChart = () => {
},
// 범례 변경
legend: {
display: exampleData.node.legend,
display: exampleData.legend,
labels: {
font: {
family: "Pretendard-Regular",
Expand All @@ -221,8 +219,8 @@ const SoopBarChart = () => {
// 축 변경
scales: {
y: {
min: exampleData.node.yMin,
max: exampleData.node.yMax,
min: exampleData.yMin,
max: exampleData.yMax,
ticks: {
font: {
family: "Pretendard-Light",
Expand Down
30 changes: 14 additions & 16 deletions dashboard/src/components/SoopChart/SoopLineChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@ const SoopLineChart = () => {
"rgba(255, 135, 66, 0.8)",
];
const exampleData = {
node: {
title: "bar timeseries chart",
chartType: "bar",
legend: true,
blankLabel: "no data",
xAxisFormat: "HH:mm:ss",
yMin: 0,
yMax: 10,
isTimeSeriesData: true,
},
title: "bar timeseries chart",
chartType: "bar",
legend: true,
blankLabel: "no data",
xAxisFormat: "HH:mm:ss",
yMin: 0,
yMax: 10,
isTimeSeriesData: true,
id: "노드의 id",
states: {
냉장고: [
{ value: 1, time: 1664544739836 },
{ value: 9, time: 1664544739836 },
{ value: 2, time: 1664545142444 },
{ value: 3, time: 1664545186484 },
{ value: 6, time: 1664545206079 },
Expand Down Expand Up @@ -88,7 +86,7 @@ const SoopLineChart = () => {
useEffect(() => {
const currentDatasetsLabel = Object.keys(exampleData.states);
const currentLabels = exampleData.states[currentDatasetsLabel[0]].map(data =>
moment(data.time).format(exampleData.node.xAxisFormat),
moment(data.time).format(exampleData.xAxisFormat),
);
const currentDatasets = Object.keys(exampleData.states).map((key, idx) => {
return {
Expand All @@ -111,7 +109,7 @@ const SoopLineChart = () => {
// 제목 변경
title: {
display: true,
text: exampleData.node.title,
text: exampleData.title,
color: fontColor.light,
font: {
family: "Pretendard-Bold",
Expand All @@ -120,7 +118,7 @@ const SoopLineChart = () => {
},
// 범례 변경
legend: {
display: exampleData.node.legend,
display: exampleData.legend,
labels: {
font: {
family: "Pretendard-Regular",
Expand All @@ -133,8 +131,8 @@ const SoopLineChart = () => {
// 축 변경
scales: {
y: {
min: exampleData.node.yMin,
max: exampleData.node.yMax,
min: exampleData.yMin,
max: exampleData.yMax,
ticks: {
font: {
family: "Pretendard-Light",
Expand Down
18 changes: 8 additions & 10 deletions dashboard/src/components/SoopChart/SoopPieChart.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import React, { useState, useEffect } from "react";
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from "chart.js";
import { Pie } from "react-chartjs-2";
import styled from "styled-components";
import { fontSize, fontColor } from "../../assets/DesignOption";

ChartJS.register(ArcElement, Tooltip, Legend);
// FIXME: width, height 둘 중 작은 것을 기준으로 제작이 되게!!
// FIXME: width, height 둘 중 작은 것을 기준으로 제작이 되게!!

// FIXME: props로 넘어오게 될 것.
// FIXME: 나중에 받을 때 {node, states}로 구조분해할당받기
const SoopPieChart = () => {
const exampleData = {
node: {
title: "pie chart",
chartType: "pie",
cutout: 0,
legend: true,
blankLabel: "no data",
},
title: "pie chart",
chartType: "pie",
cutout: 0,
legend: true,
blankLabel: "no data",
id: "노드의 id",
states: {
냉장고: [{ value: 1 }],
Expand Down Expand Up @@ -67,7 +65,7 @@ const SoopPieChart = () => {
// 제목 변경
title: {
display: true,
text: exampleData.node.title,
text: exampleData.title,
color: fontColor.light,
font: {
family: "Pretendard-Bold",
Expand All @@ -76,7 +74,7 @@ const SoopPieChart = () => {
},
//범례 변경
legend: {
display: exampleData.node.legend,
display: exampleData.legend,
// position: "top",
labels: {
font: {
Expand Down
23 changes: 11 additions & 12 deletions dashboard/src/components/SoopDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ const DropdownContainer = styled.div`
box-sizing: border-box;
`;

const SoopDropdown = ({ node, states }) => {
const SoopDropdown = node => {
const [selectedOption, setSelectedOption] = useState("");
const [currentOptions, setCurrentOptions] = useState([]);
const [currentLabel, setCurrentLabel] = useState("");
console.log(node);
const exampleData = {
node: {
label: "dropdown라벨",
tooltip: "dropdown node",
placeholder: "Select option",
option: { option1: "value1", option2: "value2" },
},
states: {},
label: "dropdown라벨",
tooltip: "툴팁",
options: [
{ label: "val1", value: "0", type: "str" },
{ label: "val2", value: "1", type: "str" },
{ label: "val3", value: "2", type: "str" },
],
states: [{}],
};

const onChange = e => {
Expand All @@ -43,12 +43,11 @@ const SoopDropdown = ({ node, states }) => {
};

useEffect(() => {
console.log("리액트 드롭다운 컴포넌트 결과: ", node, states);
const optionsArray = node.options.map(opt => {
return opt.label;
});
if (Array.isArray(states) && states[0]) {
setSelectedOption(states[0].key);
if (Array.isArray(node.states) && states[0]) {
setSelectedOption(node.states[0].key);
}
setCurrentOptions(optionsArray);
setCurrentLabel(node.label);
Expand Down
20 changes: 16 additions & 4 deletions dashboard/src/components/SoopGauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,37 @@ const GaugeContainer = styled.div`

const SoopGauge = () => {
// FIXME: 넘겨받은 데이터에 따라서 return되는 component가 다르다
const type = "liquid";
const type = "gauge";

switch (type) {
case "gauge":
return (
<GaugeContainer>
<SoopNormalGauge />
(
<GaugeContainer>
<SoopNormalGauge />
</GaugeContainer>
)
</GaugeContainer>
);
case "donut":
return (
<GaugeContainer>
<SoopDonutGauge />
(
<GaugeContainer>
<SoopDonutGauge />
</GaugeContainer>
)
</GaugeContainer>
);
case "liquid":
return (
<GaugeContainer>
<SoopLiquidGauge />
(
<GaugeContainer>
<SoopLiquidGauge />
</GaugeContainer>
)
</GaugeContainer>
);
}
Expand Down
Loading

0 comments on commit bcb11a6

Please sign in to comment.