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

[Fix] 기본 배율 지정, 과도한 확대/축소 제한 #412

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions app/src/@shared/components/Chart/hooks/useDefaultOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ const defaultOptions: ApexCharts.ApexOptions = {
tools: {
download: false,
selection: false,
zoom: true,
zoomin: true,
zoomout: true,
pan: false,
zoom: true,
pan: true,
reset: true,
},
autoSelected: 'zoom',
},
fontFamily:
"'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', sans-serif",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useQuery } from '@apollo/client';
import { subMonths } from 'date-fns';

import { gql } from '@shared/__generated__';
import { LineChart } from '@shared/components/Chart';
Expand All @@ -8,7 +9,10 @@ import {
DashboardContentLoading,
DashboardContentNotFound,
} from '@shared/components/DashboardContentView/Error';
import { CALENDAR_MONTHS_FROM_FT_BEGIN_AT } from '@shared/constants/date';
import {
CALENDAR_MONTHS_FROM_FT_BEGIN_AT,
MILLISECONDS,
} from '@shared/constants/date';
import { kiloFormatter } from '@shared/utils/formatters/kiloFormatter';
import { numberWithUnitFormatter } from '@shared/utils/formatters/numberWithUnitFormatter';
import { injectEmptyMonth } from '@shared/utils/injectEmptyMonth';
Expand Down Expand Up @@ -94,18 +98,47 @@ const ScoreRecordsPerCoalitionChart = ({
const options: ApexCharts.ApexOptions = {
chart: {
width: '100%',
events: {
beforeZoom: (ctx, { xaxis }) => {
if (xaxis.max - xaxis.min < MILLISECONDS.MONTH * 2) {
return {
xaxis: {
min: ctx.minX,
max: ctx.maxX,
},
};
}

const newMinX = Math.max(xaxis.min, ctx.w.globals.initialMinX);
const newMaxX = Math.min(xaxis.max, ctx.w.globals.initialMaxX);

return {
xaxis: {
min: newMinX,
max: newMaxX,
},
};
},
beforeResetZoom: (ctx) => {
return {
xaxis: {
min: subMonths(new Date(), 8).getTime(),
max: ctx.maxX,
},
};
},
},
},
xaxis: {
type: 'datetime',
labels: {
datetimeUTC: false,
format: "'yy MMM",
},
min: subMonths(new Date(), 8).getTime(),
},
colors: colors,
yaxis: {
min: Math.floor(min / 10000) * 10000,
max: Math.ceil(max / 10000) * 10000,
labels: {
formatter: (value) => kiloFormatter(value, 0),
},
Expand Down
37 changes: 36 additions & 1 deletion app/src/Home/dashboard-contents/Eval/EvalCountRecords.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useQuery } from '@apollo/client';
import { subDays } from 'date-fns';

import { gql } from '@shared/__generated__';
import { AreaChart } from '@shared/components/Chart';
Expand All @@ -8,6 +9,7 @@ import {
DashboardContentLoading,
DashboardContentNotFound,
} from '@shared/components/DashboardContentView/Error';
import { MILLISECONDS } from '@shared/constants/date';
import { numberWithUnitFormatter } from '@shared/utils/formatters/numberWithUnitFormatter';
import { injectEmptyDay } from '@shared/utils/injectEmptyDay';

Expand All @@ -24,7 +26,7 @@ const GET_EVAL_COUNT_RECORDS = gql(/* GraphQL */ `

export const EvalCountRecords = () => {
const title = '일간 평가 횟수 추이';
const last = 180;
const last = 365;

const { loading, error, data } = useQuery(GET_EVAL_COUNT_RECORDS, {
variables: {
Expand Down Expand Up @@ -69,12 +71,45 @@ type EvalCountRecordsChartProps = {

const EvalCountRecordsChart = ({ series }: EvalCountRecordsChartProps) => {
const options: ApexCharts.ApexOptions = {
chart: {
events: {
beforeZoom: (ctx, { xaxis }) => {
if (xaxis.max - xaxis.min < MILLISECONDS.DAY * 2) {
return {
xaxis: {
min: ctx.minX,
max: ctx.maxX,
},
};
}

const newMinX = Math.max(xaxis.min, ctx.w.globals.initialMinX);
const newMaxX = Math.min(xaxis.max, ctx.w.globals.initialMaxX);

return {
xaxis: {
min: newMinX,
max: newMaxX,
},
};
},
beforeResetZoom: (ctx) => {
return {
xaxis: {
min: subDays(new Date(), 18).getTime(),
max: ctx.maxX,
},
};
},
},
},
xaxis: {
type: 'datetime',
labels: {
format: 'MMM d',
datetimeUTC: false,
},
min: subDays(new Date(), 18).getTime(),
},
tooltip: {
x: {
Expand Down
37 changes: 36 additions & 1 deletion app/src/Home/dashboard-contents/Team/TeamCloseRecords.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useQuery } from '@apollo/client';
import { subDays } from 'date-fns';

import { gql } from '@shared/__generated__';
import { AreaChart } from '@shared/components/Chart';
Expand All @@ -8,6 +9,7 @@ import {
DashboardContentLoading,
DashboardContentNotFound,
} from '@shared/components/DashboardContentView/Error';
import { MILLISECONDS } from '@shared/constants/date';
import { numberWithUnitFormatter } from '@shared/utils/formatters/numberWithUnitFormatter';
import { injectEmptyDay } from '@shared/utils/injectEmptyDay';

Expand All @@ -24,7 +26,7 @@ const GET_TEAM_CLOSE_RECORDS = gql(/* GraphQL */ `

export const TeamCloseRecords = () => {
const title = '일간 팀 제출 횟수 추이';
const last = 180;
const last = 365;

const { loading, error, data } = useQuery(GET_TEAM_CLOSE_RECORDS, {
variables: {
Expand Down Expand Up @@ -69,12 +71,45 @@ type EvalCountRecordsChartProps = {

const EvalCountRecordsChart = ({ series }: EvalCountRecordsChartProps) => {
const options: ApexCharts.ApexOptions = {
chart: {
events: {
beforeZoom: (ctx, { xaxis }) => {
if (xaxis.max - xaxis.min < MILLISECONDS.DAY * 2) {
return {
xaxis: {
min: ctx.minX,
max: ctx.maxX,
},
};
}

const newMinX = Math.max(xaxis.min, ctx.w.globals.initialMinX);
const newMaxX = Math.min(xaxis.max, ctx.w.globals.initialMaxX);

return {
xaxis: {
min: newMinX,
max: newMaxX,
},
};
},
beforeResetZoom: (ctx) => {
return {
xaxis: {
min: subDays(new Date(), 18).getTime(),
max: ctx.maxX,
},
};
},
},
},
xaxis: {
type: 'datetime',
labels: {
format: 'MMM d',
datetimeUTC: false,
},
min: subDays(new Date(), 18).getTime(),
},
tooltip: {
x: {
Expand Down
35 changes: 35 additions & 0 deletions app/src/Home/dashboard-contents/User/AliveUserCountRecords.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useQuery } from '@apollo/client';
import { subDays } from 'date-fns';

import { gql } from '@shared/__generated__';
import { AreaChart } from '@shared/components/Chart';
Expand All @@ -9,6 +10,7 @@ import {
DashboardContentNotFound,
} from '@shared/components/DashboardContentView/Error';
import { InfoTooltip } from '@shared/components/InfoTooltip';
import { MILLISECONDS } from '@shared/constants/date';
import { numberWithUnitFormatter } from '@shared/utils/formatters/numberWithUnitFormatter';

const GET_DAILY_ALIVE_USER_COUNT_RECORDS = gql(/* GraphQL */ `
Expand Down Expand Up @@ -78,12 +80,45 @@ const ActiveUserCountRecordsChart = ({
series,
}: ActiveUserCountRecordsChartProps) => {
const options: ApexCharts.ApexOptions = {
chart: {
events: {
beforeZoom: (ctx, { xaxis }) => {
if (xaxis.max - xaxis.min < MILLISECONDS.DAY * 2) {
return {
xaxis: {
min: ctx.minX,
max: ctx.maxX,
},
};
}

const newMinX = Math.max(xaxis.min, ctx.w.globals.initialMinX);
const newMaxX = Math.min(xaxis.max, ctx.w.globals.initialMaxX);

return {
xaxis: {
min: newMinX,
max: newMaxX,
},
};
},
beforeResetZoom: (ctx) => {
return {
xaxis: {
min: subDays(new Date(), 18).getTime(),
max: ctx.maxX,
},
};
},
},
},
xaxis: {
type: 'datetime',
labels: {
format: "'yy MMM",
datetimeUTC: false,
},
min: subDays(new Date(), 18).getTime(),
},
yaxis: {
labels: {
Expand Down
40 changes: 38 additions & 2 deletions app/src/Home/dashboard-contents/User/BlackholedCountRecords.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useQuery } from '@apollo/client';
import { subMonths } from 'date-fns';

import { gql } from '@shared/__generated__';
import { AreaChart } from '@shared/components/Chart';
Expand All @@ -8,7 +9,10 @@ import {
DashboardContentLoading,
DashboardContentNotFound,
} from '@shared/components/DashboardContentView/Error';
import { CALENDAR_MONTHS_FROM_FT_BEGIN_AT } from '@shared/constants/date';
import {
CALENDAR_MONTHS_FROM_FT_BEGIN_AT,
MILLISECONDS,
} from '@shared/constants/date';
import { numberWithUnitFormatter } from '@shared/utils/formatters/numberWithUnitFormatter';
import { injectEmptyMonth } from '@shared/utils/injectEmptyMonth';

Expand Down Expand Up @@ -74,13 +78,45 @@ const BlackholedCountRecordsChart = ({
series,
}: BlackholedCountRecordsChartProps) => {
const options: ApexCharts.ApexOptions = {
chart: {
events: {
beforeZoom: (ctx, { xaxis }) => {
if (xaxis.max - xaxis.min < MILLISECONDS.MONTH * 2) {
return {
xaxis: {
min: ctx.minX,
max: ctx.maxX,
},
};
}

const newMinX = Math.max(xaxis.min, ctx.w.globals.initialMinX);
const newMaxX = Math.min(xaxis.max, ctx.w.globals.initialMaxX);

return {
xaxis: {
min: newMinX,
max: newMaxX,
},
};
},
beforeResetZoom: (ctx) => {
return {
xaxis: {
min: subMonths(new Date(), 12).getTime(),
max: ctx.maxX,
},
};
},
},
},
xaxis: {
type: 'datetime',

labels: {
datetimeUTC: false,
format: "'yy MMM",
},
min: subMonths(new Date(), 12).getTime(),
},
tooltip: {
x: {
Expand Down
Loading