Skip to content

Commit

Permalink
fix(mis): 平台数据统计可视化图表y轴优化 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
cuvalign authored Sep 13, 2024
1 parent f7ad353 commit de3e5f1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-apricots-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/mis-web": patch
---

平台数据统计可视化图表 y 轴刻度优化
5 changes: 3 additions & 2 deletions apps/mis-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@
"@scow/lib-auth": "workspace:*",
"@scow/lib-config": "workspace:*",
"@scow/lib-decimal": "workspace:*",
"@scow/lib-notification": "workspace:*",
"@scow/lib-operation-log": "workspace:*",
"@scow/lib-web": "workspace:*",
"@scow/notification-protos": "workspace:*",
"@scow/protos": "workspace:*",
"@scow/rich-error-model": "workspace:*",
"@scow/utils": "workspace:*",
"@scow/lib-notification": "workspace:*",
"@scow/notification-protos": "workspace:*",
"@sinclair/typebox": "0.32.34",
"antd": "5.18.3",
"csv-stringify": "6.5.0",
"d3-scale": "4.0.2",
"dayjs": "1.11.11",
"google-protobuf": "3.21.2",
"http-proxy": "1.18.1",
Expand Down
10 changes: 9 additions & 1 deletion apps/mis-web/src/pageComponents/admin/DataBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import { Empty, Spin } from "antd";
import { scaleLinear } from "d3-scale";
import React from "react";
import { Bar, BarChart,
ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
Expand Down Expand Up @@ -63,6 +64,13 @@ export const DataBarChart: React.FC<Props> = ({
return roundedValue.toString();
};

const min = Math.min(...data.map((d) => +d.y));
const max = Math.max(...data.map((d) => +d.y));
const [niceMin,niceMax] = scaleLinear()
.domain([min, max])
.nice().domain();


return (
<StatisticContainer>
{isLoading ? <Spin /> : (
Expand All @@ -83,7 +91,7 @@ export const DataBarChart: React.FC<Props> = ({
height={ 80 }
tick={<CustomizedAxisTick /> }
/>
<YAxis padding={{ top: 20 }} tickFormatter={tickFormatter} />
<YAxis padding={{ top: 20 }} tickFormatter={tickFormatter} domain={[niceMin,niceMax]} />
<Tooltip
formatter={toolTipFormatter}
/>
Expand Down
10 changes: 9 additions & 1 deletion apps/mis-web/src/pageComponents/admin/DataLineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import { Spin } from "antd";
import { scaleLinear } from "d3-scale";
import { Line, LineChart,
ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
import { Formatter } from "recharts/types/component/DefaultTooltipContent";
Expand Down Expand Up @@ -45,6 +46,13 @@ export const DataLineChart: React.FC<Props> = ({
lineType = "linear",
toolTipFormatter = (value) => value,
}) => {

const min = Math.min(...data.map((d) => +d.y));
const max = Math.max(...data.map((d) => +d.y));
const [niceMin,niceMax] = scaleLinear()
.domain([min, max])
.nice().domain();

return (
<StatisticContainer>
{isLoading ? <Spin /> : (
Expand All @@ -56,7 +64,7 @@ export const DataLineChart: React.FC<Props> = ({
>
<XAxis dataKey="x" padding={{ left: 20, right: 20 }} type="category" />
<YAxis
domain={["dataMin", "dataMax"]}
domain={[niceMin,niceMax]}
interval={"preserveStartEnd"}
/>
<Tooltip
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit de3e5f1

Please sign in to comment.