-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-components): add data quality to xy-plot
- Loading branch information
Showing
33 changed files
with
1,072 additions
and
66 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
import '@testing-library/jest-dom'; | ||
import 'jest-canvas-mock'; | ||
|
||
import { TextDecoder, TextEncoder } from 'util'; | ||
global.TextEncoder = TextEncoder; | ||
global.TextDecoder = TextDecoder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
packages/react-components/src/components/chart/chartOptions/convertTooltip.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...es/react-components/src/components/chart/chartOptions/seriesAndYAxis/convertColor.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { | ||
BAD_DATA_ICON_COLOR, | ||
UNCERTAIN_DATA_ICON_COLOR, | ||
} from '../../eChartsConstants'; | ||
import { convertColor, ConvertColorOptions } from './convertColor'; | ||
|
||
const DEFAULT_ECHARTS_PARAMS = { | ||
componentType: '', | ||
componentSubType: '', | ||
componentIndex: 0, | ||
name: '', | ||
dataIndex: 0, | ||
data: '', | ||
value: '', | ||
$vars: [], | ||
}; | ||
|
||
const GOOD_POINT = { | ||
...DEFAULT_ECHARTS_PARAMS, | ||
data: { | ||
x: 1, | ||
y: 1, | ||
quality: 'GOOD', | ||
}, | ||
}; | ||
|
||
const BAD_POINT = { | ||
...DEFAULT_ECHARTS_PARAMS, | ||
data: { | ||
x: 1, | ||
y: 1, | ||
quality: 'BAD', | ||
}, | ||
}; | ||
|
||
const UNCERTAIN_POINT = { | ||
...DEFAULT_ECHARTS_PARAMS, | ||
data: { | ||
x: 1, | ||
y: 1, | ||
quality: 'UNCERTAIN', | ||
}, | ||
}; | ||
|
||
const setup = (props?: Partial<ConvertColorOptions>) => { | ||
const mergedProps = { | ||
color: 'pink', | ||
showBadDataIcons: true, | ||
showUncertainDataIcons: true, | ||
...props, | ||
}; | ||
const callback = convertColor(mergedProps)?.color; | ||
if (callback === undefined || typeof callback !== 'function') { | ||
throw new Error('echarts callback function type unexpected'); | ||
} | ||
return callback; | ||
}; | ||
|
||
describe('convertColor', () => { | ||
it('returns the symbol color by default', () => { | ||
const convertColor = setup({ color: 'blue' }); | ||
expect(convertColor(GOOD_POINT)).toEqual('blue'); | ||
}); | ||
|
||
it('returns the bad data symbol color if the point is bad data', () => { | ||
const convertColor = setup(); | ||
expect(convertColor(BAD_POINT)).toEqual(BAD_DATA_ICON_COLOR); | ||
}); | ||
|
||
it('returns the uncertain data symbol color if the point is bad data', () => { | ||
const convertColor = setup(); | ||
expect(convertColor(UNCERTAIN_POINT)).toEqual(UNCERTAIN_DATA_ICON_COLOR); | ||
}); | ||
|
||
it('returns the symbol color if the point is bad data but show bad data is false', () => { | ||
const convertColor = setup({ showBadDataIcons: false, color: 'blue' }); | ||
expect(convertColor(BAD_POINT)).toEqual('blue'); | ||
}); | ||
|
||
it('returns the symbol color if the point is uncertain data but show uncertain data is false', () => { | ||
const convertColor = setup({ | ||
showUncertainDataIcons: false, | ||
color: 'blue', | ||
}); | ||
expect(convertColor(UNCERTAIN_POINT)).toEqual('blue'); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/react-components/src/components/chart/chartOptions/seriesAndYAxis/convertColor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { LineSeriesOption } from 'echarts'; | ||
import { | ||
BAD_DATA_ICON_COLOR, | ||
UNCERTAIN_DATA_ICON_COLOR, | ||
} from '../../eChartsConstants'; | ||
import { DataPoint } from '@iot-app-kit/core'; | ||
import { ChartDataQuality } from '../../types'; | ||
|
||
export type ConvertColorOptions = { color?: string } & ChartDataQuality; | ||
export const convertColor = ({ | ||
color = '', | ||
showBadDataIcons, | ||
showUncertainDataIcons, | ||
}: ConvertColorOptions): LineSeriesOption['itemStyle'] => ({ | ||
color: (params) => { | ||
const quality = (params.data as DataPoint | undefined)?.quality; | ||
|
||
if (showUncertainDataIcons && quality === 'UNCERTAIN') { | ||
return UNCERTAIN_DATA_ICON_COLOR; | ||
} else if (showBadDataIcons && quality === 'BAD') { | ||
return BAD_DATA_ICON_COLOR; | ||
} | ||
|
||
return color; | ||
}, | ||
}); |
Oops, something went wrong.