Skip to content

Commit

Permalink
Graph components bracnh (#69)
Browse files Browse the repository at this point in the history
* feat : ์ฃผ์ฐจ๋ฅผ ๊ตฌํ•˜๋Š” util ์ƒ์„ฑ

* feat : title ์ƒ์„ฑ

* chore : title ์ˆ˜์ •

* feat : api ํ˜ธ์ถœ param ์ถ”๊ฐ€

* env : rechart ์„ค์น˜

* fix : ์ ˆ๋Œ€๊ฒฝ๋กœ๋ฅผ ์Šคํ† ๋ถ์ด ์ธ์ง€ ๋ชปํ•˜๋Š” ์˜ค๋ฅ˜ ์ˆ˜์ •

* env : storybook ์—๋Ÿฌ ์ˆ˜์ •

* feat : chart ์ปดํฌ๋„ŒํŠธ

* refactor : ์žฌ์‚ฌ์šฉ์„ฑ์„ ์œ„ํ•ด INFO ์ปดํฌ๋„ŒํŠธ๋กœ ๋ถ„๋ฆฌ

* feat : ์‚ฌ์šฉ์ž์˜ ํ˜„์žฌ ์ฃผ์ฐจ๋ฅผ ๊ตฌํ•˜๋Š” ์œ ํ‹ธ

* chore : ๊ฒฝ๋กœ ๋ณ€๊ฒฝ ๋ฐ ์ฝ”๋“œ ์œ„์น˜ ๋ณ€๊ฒฝ

* feat : ํ‰๊ท  ๊ฐ์ •์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” hook  ์ƒ์„ฑ

* feat : api๋ฅผ ๋ถˆ๋Ÿฌ์™€ ์—ฐ๊ฒฐ

* env : date-fns ์˜์กด์„ฑ ์ถ”๊ฐ€

* feat : char ํ•„ํ„ฐ๋ง ๊ตฌํ˜„

* chore : ์Šคํ† ๋ฆฌ๋ถ ๊ฒฝ๋กœ ์ˆ˜์ •

* env : ์˜์กด์„ฑ ์—๋Ÿฌ ์ œ๊ฑฐ

* chore : ์ฐจํŠธ ์Šคํƒ€์ผ๋ง ์ˆ˜์ •
  • Loading branch information
HelloWook authored Oct 30, 2024
1 parent 87cba15 commit 194585d
Show file tree
Hide file tree
Showing 41 changed files with 994 additions and 37 deletions.
16 changes: 15 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { StorybookConfig } from '@storybook/react-webpack5';
import path from 'path';
import React from 'react';

const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
Expand All @@ -14,6 +16,18 @@ const config: StorybookConfig = {
name: '@storybook/react-webpack5',
options: {}
},
staticDirs: ['../public']
staticDirs: ['../public'], // ์ •์  ํŒŒ์ผ ๋””๋ ‰ํ† ๋ฆฌ
webpackFinal: async (config) => {
// Webpack alias ์„ค์ • ์ถ”๊ฐ€
config.resolve = config.resolve || {};
config.resolve.alias = {
...config.resolve.alias,
'@': path.resolve(__dirname, '../src'), // '@'๋ฅผ src ํด๋”๋กœ ๋งคํ•‘
'@/components': path.resolve(__dirname, '../src/components') // '@/components'๋ฅผ src/components๋กœ ๋งคํ•‘
};

return config;
}
};

export default config;
14 changes: 0 additions & 14 deletions .storybook/preview.ts

This file was deleted.

25 changes: 25 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Preview } from '@storybook/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import React from 'react';

const queryClient = new QueryClient();

const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i
}
}
},
decorators: [
(Story) => (
<QueryClientProvider client={queryClient}>
<Story />
</QueryClientProvider>
)
]
};

export default preview;
14 changes: 4 additions & 10 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default [
'**/*stories*',
'**/webpack*.js',
'**/webpack/**/*.js',
'src/stories/**'
'src/stories/**',
'.storybook'
]
},
...compat.config({
Expand Down Expand Up @@ -45,15 +46,8 @@ export default [
1,
{ extensions: ['.jsx', '.tsx'] }
],
'import/extensions': [
'error',
'ignorePackages',
{ js: 'never', jsx: 'never', ts: 'never', tsx: 'never' }
],
'import/no-extraneous-dependencies': [
'error',
{ devDependencies: true }
],
'import/extensions': 'off',
'import/no-extraneous-dependencies': 'off',
'react/function-component-definition': [
'error',
{
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
"@tanstack/react-query-devtools": "^5.59.0",
"axios": "^1.7.7",
"axios-mock-adapter": "^2.1.0",
"date-fns": "^4.1.0",
"husky": "^9.1.6",
"init": "^0.1.2",
"jest": "^29.7.0",
"moment": "^2.30.1",
"react": "^18.3.1",
"react-calendar": "^5.1.0",
"react-dom": "^18.3.1",
"recharts": "^2.13.0",
"storybook": "^8.3.0",
"styled-components": "^6.1.13",
"webpack-merge": "^6.0.1",
Expand Down
7 changes: 7 additions & 0 deletions src/entities/chart/lib/calculateWeek.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// ์ฃผ์ฐจ๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ์œ ํ‹ธ ํ•จ์ˆ˜
export const calculateWeekOfYear = (date: Date): number => {
const startOfYear = new Date(date.getFullYear(), 0, 1);
const pastDaysOfYear =
(date.getTime() - startOfYear.getTime()) / (24 * 60 * 60 * 1000);
return Math.ceil((pastDaysOfYear + startOfYear.getDay() + 1) / 7);
};
12 changes: 12 additions & 0 deletions src/entities/chart/lib/isDailyEmotion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {
DailyEmotionType,
WeeklyEmotionSummaryType
} from '@/shared/model/moodTypes';

const isDailyEmotion = (
data: DailyEmotionType[] | WeeklyEmotionSummaryType[]
): data is DailyEmotionType[] => {
return (data as DailyEmotionType[])[0]?.day !== undefined;
};

export default isDailyEmotion;
29 changes: 29 additions & 0 deletions src/entities/chart/ui/Chart.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Meta, StoryObj } from '@storybook/react';
import Chart from './Chart';

const meta: Meta<typeof Chart> = {
component: Chart,
title: 'entities/UI/CHART',
tags: ['autodocs'],
argTypes: {},
};
export default meta;

type Story = StoryObj<typeof Chart>;

const dailyEmotionData = [
{ day: 'Mon' as const, mood: null },
{ day: 'Tue' as const, mood: '๋‚˜์จ' },
{ day: 'Wed' as const, mood: '๋‚˜์จ' },
{ day: 'Thu' as const, mood: null },
{ day: 'Fri' as const, mood: null },
{ day: 'Sat' as const, mood: null },
{ day: 'Sun' as const, mood: null },
];


export const Default: Story = {
args: {
data: dailyEmotionData,
},
};
97 changes: 97 additions & 0 deletions src/entities/chart/ui/Chart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React from 'react';
import {
DailyEmotionType,
WeeklyEmotionSummaryType
} from '@/shared/model/moodTypes';

import {
LineChart,
Line,
XAxis,
YAxis,
CartesianGrid,
Tooltip,
ResponsiveContainer
} from 'recharts';
import isDailyEmotion from '../lib/isDailyEmotion';

const emotions = ['๋งค์šฐ ๋‚˜์จ', '๋‚˜์จ', '๋ณดํ†ต', '์ข‹์Œ', '๋งค์šฐ ์ข‹์Œ'];

interface ChartProps {
data: DailyEmotionType[] | WeeklyEmotionSummaryType[];
}

const Chart = ({ data }: ChartProps) => {
return (
<ResponsiveContainer width="100%" height={400}>
<LineChart
data={data}
margin={{ top: 20, right: 10, left: 10, bottom: 20 }}
>
<CartesianGrid vertical={false} />
{isDailyEmotion(data) ? (
<>
<XAxis
dataKey="day"
angle={0}
dy={10}
height={50}
axisLine={false}
/>
<YAxis
type="category"
dataKey="mood"
tickLine={false}
axisLine={false}
domain={emotions}
ticks={emotions}
allowDuplicatedCategory={false}
/>
<Line
type="monotone"
dataKey="mood"
stroke="#FF480E"
activeDot={{ r: 8 }}
connectNulls
/>
</>
) : (
<>
<XAxis
dataKey="week"
angle={0}
dy={10}
height={50}
axisLine={false}
/>
<YAxis
type="category"
dataKey="mostFrequentEmotion"
tickLine={false}
axisLine={false}
domain={emotions}
ticks={emotions}
allowDuplicatedCategory={false}
/>
<Line
type="monotone"
dataKey="mostFrequentEmotion"
stroke="#FF480E"
activeDot={{ r: 8 }}
connectNulls
/>
</>
)}
<Tooltip
formatter={(value) =>
value === '์ •๋ณด ์—†์Œ' || value === null
? '์ •๋ณด ์—†์Œ'
: value
}
/>
</LineChart>
</ResponsiveContainer>
);
};

export default Chart;
27 changes: 27 additions & 0 deletions src/entities/dataSldier/DateSlider.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Storybook configuration for DateSlider
import type { Meta, StoryObj } from '@storybook/react';
import DateSlider from "./DateSlider"
const meta: Meta<typeof DateSlider> = {
component: DateSlider,
title: 'entities/ui/DateSlider',
tags: ['autodocs'],
argTypes: {
year: { control: 'number', defaultValue: 2023 },
month: { control: 'number', defaultValue: 10 },
week: { control: 'number', defaultValue: 1 },
viewMode: { control: 'radio', options: ['week', 'month'], defaultValue: 'week' },
onDateChange: { action: 'dateChanged' },
},
};
export default meta;

type Story = StoryObj<typeof DateSlider>;

export const Default: Story = {
args: {
year: 2023,
month: 10,
week: 1,
viewMode: 'week',
},
};
28 changes: 28 additions & 0 deletions src/entities/dataSldier/DateSlider.styled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import styled from 'styled-components';

export const MonthWeekSelectorWrapper = styled.div`
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
`;

export const ArrowButton = styled.button`
background: none;
border: none;
font-size: 24px;
cursor: pointer;
&:focus {
outline: none;
}
`;

export const Display = styled.span`
margin: 0 140px;
font-size: 20px;
`;

export const SliderInfoContainer = styled.div`
margin-bottom: 100px;
`;
Loading

0 comments on commit 194585d

Please sign in to comment.