Skip to content

Commit 61165ea

Browse files
authoredOct 11, 2021
Fixdisplay second less one minute (#34)
* chore: update changeLog and version * fix: display-second-less-one-minute * 1.0.39-beta-2 * fix: can not brush when there is only one bar * 1.0.39-beta-3 * fix: keep default color and set throttle time to brush * 1.0.39-beta-4 * chore: update package.json ane changeLog
1 parent 53668d8 commit 61165ea

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed
 

‎CHANGELOG.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11

22
# github
3-
4-
## [1.0.39](https://github.com/Erda-FE/dashboard-configuration/pull/31)(2021-10-11)
5-
3+
## [1.0.40](https://github.com/Erda-FE/dashboard-configuration/pull/31)(2021-10-11)
4+
beta version
65
### Feature
76

87
* support brush bar chart to get time range([aeb2bfa](https://github.com/Erda-FE/dashboard-configuration/commit/aeb2bfa91ac255c0c8d7a7a2928bc804a4821960))
98

9+
10+
## [1.0.39](https://github.com/Erda-FE/dashboard-configuration/pull/31)(2021-9-30)
11+
beta version
12+
1013
## [1.0.38](https://github.com/Erda-FE/dashboard-configuration/pull/30)(2021-09-29)
1114

1215
### Feature

‎package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@erda-ui/dashboard-configurator",
3-
"version": "1.0.39",
3+
"version": "1.0.40",
44
"description": "Erda dashboard configurator powered by Echart",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

‎src/components/DcCharts/chart-line/option.ts

+23-8
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export function getOption(data: DC.StaticData, config: DC.ChartConfig = {}) {
5050
defaultMoreThanOneDay = time[time.length - 1] - time[0] > 24 * 3600 * 1000;
5151
}
5252
const moreThanOneDay = isMoreThanOneDay || defaultMoreThanOneDay;
53+
const isLessOneMinute = time?.length === 1 || (time?.[time?.length - 1] - time?.[0]) / (time?.length - 1) < 60 * 1000;
54+
5355
const convertInvalidValueToZero = (dataList: any[]) => {
5456
return invalidToZero
5557
? map(dataList, (item) => (typeof item === 'number' && item > 0 ? item : 0))
@@ -155,8 +157,19 @@ export function getOption(data: DC.StaticData, config: DC.ChartConfig = {}) {
155157

156158
const brushFormatter = (param: DC.BrushTooltip[]) => {
157159
const { value = '', seriesName: _seriesName = '', axisValue = '' } = param?.[0];
160+
const isOneBar = time?.length === 1;
158161
const timeGap = time?.[1] - time?.[0];
159-
return `${textMap['start time']}: ${moment(Number(axisValue)).format('YYYY-MM-DD HH:mm:ss')}<br />${textMap['end time']}: ${moment(Number(axisValue) + Number(timeGap)).format('YYYY-MM-DD HH:mm:ss')}<br />${_seriesName}: ${value} `;
162+
return `${textMap['start time']}: ${moment(Number(axisValue)).format('YYYY-MM-DD HH:mm:ss')}<br />${textMap['end time']}: ${moment(Number(axisValue) + Number(isOneBar ? 0 : timeGap)).format('YYYY-MM-DD HH:mm:ss')}<br />${_seriesName}: ${value} `;
163+
};
164+
165+
const axisLabelFormatter = () => {
166+
if (moreThanOneDay) {
167+
if (moreThanOneDayFormat) {
168+
return moreThanOneDayFormat;
169+
}
170+
return isLessOneMinute ? 'M/D HH:mm:ss' : 'M/D HH:mm';
171+
}
172+
return isLessOneMinute ? 'HH:mm:ss' : 'HH:mm';
160173
};
161174

162175
const computedOption = {
@@ -173,7 +186,7 @@ export function getOption(data: DC.StaticData, config: DC.ChartConfig = {}) {
173186
axisLabel: {
174187
formatter: xData
175188
? (value: string) => value
176-
: (value: string) => moment(Number(value)).format(moreThanOneDay ? moreThanOneDayFormat || 'M/D HH:mm' : 'HH:mm'),
189+
: (value: string) => moment(Number(value)).format(axisLabelFormatter()),
177190
},
178191
},
179192
],
@@ -194,13 +207,15 @@ export function getOption(data: DC.StaticData, config: DC.ChartConfig = {}) {
194207
};
195208

196209
if (useBrush) {
197-
return merge(getDefaultOption(), computedOption, getCustomOption(data, config), option,
210+
const canBrushOption = time?.length > 1 ? { brush: {
211+
toolbox: [''],
212+
throttleType: 'debounce',
213+
throttleDelay: 300,
214+
xAxisIndex: 0,
215+
} } : {};
216+
217+
return merge(getDefaultOption(), computedOption, getCustomOption(data, config), option, canBrushOption,
198218
{
199-
brush: {
200-
toolbox: [''],
201-
throttleType: 'debounce',
202-
xAxisIndex: 0,
203-
},
204219
series: [{
205220
itemStyle: {
206221
color: '#6CB38B',

0 commit comments

Comments
 (0)
Please sign in to comment.