Skip to content

Commit d0af409

Browse files
visikylxfu1
andauthored
fix: 修复 view 上没有正确的 scale 时,绘制 annotation 出错 (#3450)
* fix: 修复 view 上没有正确的 scale 时,绘制 annotation 出错 * fix: surge version Co-authored-by: Joel Alan <31396322+lxfu1@users.noreply.github.com>
1 parent 76e08d0 commit d0af409

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

.github/workflows/auto-inspection.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- uses: actions/checkout@v2
1313
- name: Get branch name (pull request)
1414
run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_ENV
15-
- uses: lxfu1/surge-preview@v2
15+
- uses: lxfu1/surge-preview@v2.0.1
1616
id: preview_step
1717
with:
1818
project_name: 'G2'

src/util/annotation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { Scale } from '../dependents';
77
* @param scale
88
*/
99
export function getNormalizedValue(val: number | string, scale: Scale) {
10+
if (!scale) {
11+
return null;
12+
}
1013
let scaled: number;
1114

1215
switch (val) {

tests/bugs/annotation-spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Chart } from '../../src';
2+
import { createDiv } from '../util/dom';
3+
4+
const data = [
5+
{
6+
click_count: 423,
7+
hour: '00',
8+
},
9+
{
10+
click_count: 570,
11+
hour: '01',
12+
},
13+
{
14+
click_count: 634,
15+
hour: '02',
16+
},
17+
];
18+
19+
describe('text annotation', () => {
20+
it('parse positon error', () => {
21+
const chart = new Chart({
22+
container: createDiv(),
23+
width: 400,
24+
height: 400,
25+
});
26+
27+
const view = chart.createView();
28+
view.data(data);
29+
view.line().position('hour*click_count');
30+
31+
chart.render();
32+
33+
const drawAnnotation = () => {
34+
chart.annotation().text({ position: ['min', 'median'], content: 'xx' });
35+
chart.render();
36+
};
37+
38+
expect(drawAnnotation).not.toThrowError();
39+
});
40+
});

0 commit comments

Comments
 (0)