Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wisdom-components
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
wisdom-components
Commits
6c970f76
Commit
6c970f76
authored
Dec 12, 2022
by
崔佳豪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: 优化基础图表标题内容及y轴样式
parent
c7432710
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
79 additions
and
170 deletions
+79
-170
BasicChart.md
packages/base-components/BasicChart/src/BasicChart.md
+4
-4
LineChart.js
packages/base-components/BasicChart/src/LineChart.js
+5
-4
AreaLine.tsx
packages/base-components/BasicChart/src/demos/AreaLine.tsx
+1
-2
BaseBar.tsx
packages/base-components/BasicChart/src/demos/BaseBar.tsx
+1
-2
BaseLine.tsx
packages/base-components/BasicChart/src/demos/BaseLine.tsx
+1
-2
BasePieChartDemo.tsx
...base-components/BasicChart/src/demos/BasePieChartDemo.tsx
+2
-2
Basic.tsx
packages/base-components/BasicChart/src/demos/Basic.tsx
+7
-3
StackBar.tsx
packages/base-components/BasicChart/src/demos/StackBar.tsx
+1
-2
TimeTypeBar.tsx
...ages/base-components/BasicChart/src/demos/TimeTypeBar.tsx
+1
-2
TimeTypeLine.tsx
...ges/base-components/BasicChart/src/demos/TimeTypeLine.tsx
+1
-2
index copy.js
packages/base-components/BasicChart/src/index copy.js
+0
-138
index.js
packages/base-components/BasicChart/src/index.js
+5
-5
default.js
packages/base-components/BasicChart/src/utils/default.js
+50
-2
No files found.
packages/base-components/BasicChart/src/BasicChart.md
View file @
6c970f76
...
...
@@ -41,7 +41,7 @@ axisPointer 规范
### 基本柱状图
`Ba
sicChart.Ba
rChart`
拥有默认配置的柱状图,适用于仅包含柱状图的使用场景。
`BarChart`
拥有默认配置的柱状图,适用于仅包含柱状图的使用场景。
#### 类目类型柱状图
...
...
@@ -57,7 +57,7 @@ axisPointer 规范
### 基本折线图
`
BasicChart.
LineChart`
拥有默认配置的折线图,适用于仅包含折线图的使用场景。
`LineChart`
拥有默认配置的折线图,适用于仅包含折线图的使用场景。
#### 类目类型折线图
...
...
@@ -90,7 +90,7 @@ axisPointer 规范
`option`
参考 echarts 库 https://echarts.apache.org/zh/index.html
#### Ba
sicChart.Ba
rChart(基本柱状图)
#### BarChart(基本柱状图)
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
| --- | --- | --- | --- | --- | --- |
...
...
@@ -100,7 +100,7 @@ axisPointer 规范
dataSource | 参数 | 说明 | 类型 | 默认值 | 可选值 | | --- | --- | --- | --- | --- | | name | 数据系列名称,有 name 时才会显示图例 | string | - | - | | unit | 数据单位,显示在
`tooltip`
和
`yAxis`
上 | string | - | - | | data | 图表数据,
`category`
类型和
`time`
类型有所区别,
<font
color=
"#008dff"
>
详见案例
</font>
| Array
[
] | - | - |
####
BasicChart.
LineChart(基本折线图)
#### LineChart(基本折线图)
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
| --- | --- | --- | --- | --- | --- |
...
...
packages/base-components/BasicChart/src/LineChart.js
View file @
6c970f76
...
...
@@ -3,11 +3,11 @@ import ECharts from './ECharts';
import
propTypes
from
'prop-types'
;
import
_
from
'lodash'
;
// 基础柱状图
const
isCategory
=
(
category
)
=>
category
!==
undefined
;
const
isArea
=
(
lineType
)
=>
lineType
===
'area'
;
const
LineChart
=
forwardRef
(({
category
,
lineType
,
smooth
,
dataSource
},
ref
)
=>
{
const
LineChart
=
forwardRef
(({
category
,
lineType
,
smooth
,
dataSource
,
title
},
ref
)
=>
{
const
option
=
useMemo
(()
=>
{
const
titleCfg
=
typeof
title
===
'string'
?
{
show
:
true
,
text
}
:
{
show
:
false
};
const
xAxis
=
isCategory
(
category
)
?
{
type
:
'category'
,
...
...
@@ -32,8 +32,8 @@ const LineChart = forwardRef(({ category, lineType, smooth, dataSource }, ref) =
...
config
,
};
});
return
{
xAxis
,
yAxis
,
series
};
},
[
category
,
smooth
,
lineType
,
dataSource
]);
return
{
xAxis
,
yAxis
,
series
,
title
:
titleCfg
};
},
[
category
,
smooth
,
lineType
,
dataSource
,
title
]);
return
<
ECharts
ref
=
{
ref
}
option
=
{
option
}
/>
;
});
...
...
@@ -47,6 +47,7 @@ LineChart.PropTypes = {
data
:
propTypes
.
array
,
unit
:
propTypes
.
unit
,
}),
title
:
propTypes
.
string
||
propTypes
.
object
,
};
LineChart
.
defaultProps
=
{
smooth
:
true
,
...
...
packages/base-components/BasicChart/src/demos/AreaLine.tsx
View file @
6c970f76
import
React
from
'react'
;
import
{
BasicChart
}
from
'../index'
;
const
{
LineChart
}
=
BasicChart
;
import
{
LineChart
}
from
'../index'
;
export
default
()
=>
{
const
category
=
[
'11-01'
,
'11-02'
,
'11-03'
,
'11-04'
,
'11-05'
,
'11-06'
,
'11-07'
];
...
...
packages/base-components/BasicChart/src/demos/BaseBar.tsx
View file @
6c970f76
import
React
from
'react'
;
import
{
BasicChart
}
from
'../index'
;
const
{
BarChart
}
=
BasicChart
;
import
{
BarChart
}
from
'../index'
;
export
default
()
=>
{
const
category
=
[
'周一'
,
'周二'
,
'周三'
,
'周四'
,
'周五'
,
'周六'
,
'周日'
];
...
...
packages/base-components/BasicChart/src/demos/BaseLine.tsx
View file @
6c970f76
import
React
from
'react'
;
import
{
BasicChart
}
from
'../index'
;
const
{
LineChart
}
=
BasicChart
;
import
{
LineChart
}
from
'../index'
;
export
default
()
=>
{
const
category
=
[
'11-01'
,
'11-02'
,
'11-03'
,
'11-04'
,
'11-05'
,
'11-06'
,
'11-07'
];
...
...
packages/base-components/BasicChart/src/demos/BasePieChartDemo.tsx
View file @
6c970f76
import
React
from
'react'
;
import
ECharts
from
'../ECharts
'
;
import
{
BasicChart
}
from
'../index
'
;
const
Demo
=
()
=>
{
const
option
=
{
...
...
@@ -40,7 +40,7 @@ const Demo = () => {
},
],
};
return
<
ECharts
option=
{
option
}
/>;
return
<
BasicChart
option=
{
option
}
/>;
};
export
default
Demo
;
packages/base-components/BasicChart/src/demos/Basic.tsx
View file @
6c970f76
...
...
@@ -5,6 +5,10 @@ const Demo = () => {
const
colors
=
[
'#5470C6'
,
'#91CC75'
,
'#EE6666'
];
const
option
=
{
color
:
colors
,
title
:
{
show
:
true
,
text
:
'{prefix|}{t|今日供水量}{suffix|(单位:m)}'
,
},
tooltip
:
{
trigger
:
'axis'
,
axisPointer
:
{
...
...
@@ -37,7 +41,7 @@ const Demo = () => {
yAxis
:
[
{
type
:
'value'
,
name
:
'Evaporation'
,
//
name: 'Evaporation',
position
:
'right'
,
alignTicks
:
true
,
axisLine
:
{
...
...
@@ -52,7 +56,7 @@ const Demo = () => {
},
{
type
:
'value'
,
name
:
'Precipitation'
,
//
name: 'Precipitation',
position
:
'right'
,
alignTicks
:
true
,
offset
:
80
,
...
...
@@ -68,7 +72,7 @@ const Demo = () => {
},
{
type
:
'value'
,
name
:
'温度'
,
//
name: '温度',
position
:
'left'
,
alignTicks
:
true
,
axisLine
:
{
...
...
packages/base-components/BasicChart/src/demos/StackBar.tsx
View file @
6c970f76
import
React
from
'react'
;
import
{
BasicChart
}
from
'../index'
;
const
{
BarChart
}
=
BasicChart
;
import
{
BarChart
}
from
'../index'
;
export
default
()
=>
{
const
category
=
[
'周一'
,
'周二'
,
'周三'
,
'周四'
,
'周五'
,
'周六'
,
'周日'
];
...
...
packages/base-components/BasicChart/src/demos/TimeTypeBar.tsx
View file @
6c970f76
import
React
from
'react'
;
import
{
BasicChart
}
from
'../index'
;
const
{
BarChart
}
=
BasicChart
;
import
{
BarChart
}
from
'../index'
;
// 数据格式: [[时间戳, value]]
const
getData
=
()
=>
{
...
...
packages/base-components/BasicChart/src/demos/TimeTypeLine.tsx
View file @
6c970f76
import
React
from
'react'
;
import
{
BasicChart
}
from
'../index'
;
const
{
LineChart
}
=
BasicChart
;
import
{
LineChart
}
from
'../index'
;
// 数据格式: [[时间戳, value]]
const
getData
=
()
=>
{
...
...
packages/base-components/BasicChart/src/index copy.js
deleted
100644 → 0
View file @
c7432710
import
React
,
{
useContext
,
useEffect
,
useRef
,
useState
}
from
'react'
;
import
classNames
from
'classnames'
;
import
PropTypes
from
'prop-types'
;
import
Highcharts
from
'highcharts/highstock'
;
import
HighchartsReact
from
'highcharts-react-official'
;
import
{
ConfigProvider
}
from
'antd'
;
import
'./index.less'
;
let
chartWidth
=
0
;
// chart width
let
chartHeight
=
0
;
// chart height
const
BasicChart
=
(
props
)
=>
{
const
{
getPrefixCls
}
=
useContext
(
ConfigProvider
.
ConfigContext
);
const
prefixCls
=
getPrefixCls
(
'basic-chart'
);
const
{
chartOptions
,
constructorType
}
=
props
;
const
[
options
,
setOptions
]
=
useState
(
defaultOptions
);
const
container
=
useRef
(
null
);
// 处理图表options
const
handleChartOptions
=
()
=>
{
const
options
=
{
...
defaultOptions
,
...
chartOptions
,
};
if
(
container
.
current
)
{
if
(
container
.
current
.
offsetWidth
!==
0
)
{
chartWidth
=
container
.
current
.
offsetWidth
;
chartHeight
=
container
.
current
.
offsetHeight
;
}
Highcharts
.
setOptions
({
// 处理 chart 高度坍塌
chart
:
{
width
:
container
.
current
.
offsetWidth
===
0
?
chartWidth
:
container
.
current
.
offsetWidth
,
height
:
container
.
current
.
offsetHeight
===
0
?
chartHeight
:
container
.
current
.
offsetHeight
,
},
});
}
Highcharts
.
setOptions
({
global
:
{
timezoneOffset
:
-
8
*
60
},
});
return
options
;
};
useEffect
(()
=>
{
setOptions
({
...
handleChartOptions
()
});
},
[
chartOptions
]);
return
(
<
div
className
=
{
classNames
(
prefixCls
)}
ref
=
{
container
}
>
<
HighchartsReact
immutable
=
{
true
}
highcharts
=
{
Highcharts
}
constructorType
=
{
constructorType
}
options
=
{
options
}
{...
props
}
/
>
<
/div
>
);
};
BasicChart
.
defaultProps
=
{
constructorType
:
'chart'
,
chartOptions
:
{},
};
BasicChart
.
propTypes
=
{
columns
:
PropTypes
.
string
,
chartOptions
:
PropTypes
.
object
,
};
export
default
BasicChart
;
const
defaultOptions
=
{
chart
:
{
zoomType
:
'x'
,
backgroundColor
:
'rgba(255, 255, 255, 0.5)'
,
},
title
:
null
,
credits
:
false
,
rangeSelector
:
{
enabled
:
false
,
},
xAxis
:
[
{
lineWidth
:
0
,
crosshair
:
true
,
type
:
'datetime'
,
dateTimeLabelFormats
:
{
second
:
'%H:%M:%S'
,
minute
:
'%H:%M'
,
hour
:
'%H:%M'
,
day
:
'%d'
,
week
:
'%d'
,
month
:
'%d'
,
year
:
'%Y'
,
},
},
],
yAxis
:
[
{
title
:
null
,
opposite
:
false
,
// 即坐标轴会显示在对立面
lineWidth
:
1
,
},
],
tooltip
:
{
shared
:
true
,
split
:
false
,
valueDecimals
:
3
,
dateTimeLabelFormats
:
{
second
:
'%H:%M:%S'
,
minute
:
'%H:%M'
,
hour
:
'%H:%M'
,
day
:
'%d'
,
week
:
'%d'
,
month
:
'%d'
,
year
:
'%Y'
,
},
},
plotOptions
:
{
series
:
{
showInNavigator
:
true
,
connectNulls
:
false
,
zoneAxis
:
'x'
,
},
},
legend
:
{
verticalAlign
:
'top'
,
},
series
:
[],
};
packages/base-components/BasicChart/src/index.js
View file @
6c970f76
import
*
as
echarts
from
'echarts/core'
;
import
Echarts
from
'./ECharts'
;
import
{
default
as
BasicChart
}
from
'./ECharts'
;
import
BarChart
from
'./BarChart'
;
import
LineChart
from
'./LineChart'
;
const
BasicChart
=
Echarts
;
//
const BasicChart = Echarts;
BasicChart
.
BarChart
=
BarChart
;
BasicChart
.
LineChart
=
LineChart
;
//
BasicChart.BarChart = BarChart;
//
BasicChart.LineChart = LineChart;
export
{
BasicChart
,
echarts
};
export
{
BasicChart
,
BarChart
,
LineChart
,
echarts
};
packages/base-components/BasicChart/src/utils/default.js
View file @
6c970f76
...
...
@@ -6,11 +6,56 @@ import { buildDefaultTooltip } from './tooltip';
// 默认标题配置
export
const
deafultTitle
=
{
show
:
false
};
// const titleFormater = text => `{prefix|}{t|${title}}{suffix|内容}`;
export
const
buildDefaultTitle
=
(
option
)
=>
{
const
{
title
}
=
option
;
const
{
show
,
text
}
=
title
??
{};
if
(
show
&&
text
)
{
return
{
textStyle
:
{
rich
:
{
prefix
:
{
width
:
5
,
height
:
16
,
backgroundColor
:
'#1685FF'
,
},
t
:
{
fontSize
:
15
,
fontFamily
:
'Microsoft YaHei'
,
fontWeight
:
'bold'
,
color
:
'#333333'
,
lineHeight
:
28
,
padding
:
[
0
,
0
,
0
,
10
],
},
suffix
:
{
fontSize
:
12
,
color
:
'#999999'
,
padding
:
[
0
,
0
,
0
,
5
],
},
},
},
};
}
else
{
return
{
show
:
false
};
}
};
export
const
defaultGrid
=
{
right
:
40
,
left
:
60
,
};
export
const
buildDefaultGrid
=
(
option
)
=>
{
const
{
title
,
yAxis
,
series
}
=
option
;
const
axisArr
=
Array
.
isArray
(
yAxis
)
?
yAxis
:
_
.
isObject
(
yAxis
)
?
[
yAxis
]
:
[];
const
seriesArr
=
Array
.
isArray
(
series
)
?
series
:
_
.
isObject
(
series
)
?
[
series
]
:
[];
const
hasName
=
axisArr
.
some
((
d
)
=>
!!
d
.
name
)
||
seriesArr
.
some
((
d
)
=>
!!
d
.
unit
);
const
hasTitle
=
!!
title
&&
title
.
show
;
const
top
=
hasTitle
&&
hasName
?
70
:
50
;
return
{
right
:
40
,
left
:
60
,
top
};
};
export
const
defaultLegend
=
{
show
:
true
,
right
:
40
,
...
...
@@ -73,6 +118,7 @@ export const buildDefaultXAxis = (axis) => {
}
return
cfg
;
};
export
const
defaultXAxis
=
{
show
:
true
,
axisLine
:
{
...
...
@@ -186,7 +232,7 @@ export const buildDefaultSeries = (option) => {
export
const
buildDefaultOption
=
(
option
)
=>
{
const
exports
=
{};
exports
.
color
=
DEF_COLORS
;
exports
.
title
=
deafultTitle
;
exports
.
title
=
buildDefaultTitle
(
option
)
;
(
option
.
dataZoom
==
undefined
||
option
.
dataZoom
===
null
)
&&
(
exports
.
dataZoom
=
defaultDataZoom
);
exports
.
tooltip
=
buildDefaultTooltip
(
option
);
...
...
@@ -204,7 +250,9 @@ export const buildSpecificOption = (option) => {
?
xAxis
.
map
((
item
)
=>
({
...
buildDefaultXAxis
(
item
)
}))
:
buildDefaultXAxis
(
xAxis
),
yAxis
:
Array
.
isArray
(
yAxis
)
?
yAxis
.
map
(()
=>
({
...
defaultYAxis
}))
:
defaultYAxis
,
grid
:
Array
.
isArray
(
grid
)
?
grid
.
map
(()
=>
({
...
defaultGrid
}))
:
defaultGrid
,
grid
:
Array
.
isArray
(
grid
)
?
grid
.
map
(()
=>
({
...
buildDefaultGrid
(
option
)
}))
:
buildDefaultGrid
(
option
),
legend
:
Array
.
isArray
(
legend
)
?
legend
.
map
(()
=>
({
...
defaultLegend
}))
:
defaultLegend
,
series
:
buildDefaultSeries
(
option
),
tooltip
:
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment