-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from oceanbase/dengfuping-charts
fix(charts): height should be self-adaption for Line, Area and DualAxes
- Loading branch information
Showing
13 changed files
with
5,106 additions
and
13,541 deletions.
There are no files selected for viewing
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
26 changes: 26 additions & 0 deletions
26
packages/charts/src/Area/__tests__/__snapshots__/ref.test.tsx.snap
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Area ref ref 1`] = ` | ||
<div | ||
data-chart-source-type="G2Plot" | ||
size-sensor-id="1" | ||
style="height: inherit;" | ||
> | ||
<div | ||
style="position:relative;" | ||
> | ||
<canvas | ||
height="400" | ||
style="width: 400px; height: 400px; display: inline-block; vertical-align: middle;" | ||
width="400" | ||
/> | ||
</div> | ||
<object | ||
class="size-sensor-object" | ||
data="about:blank" | ||
style="display: block; position: absolute; top: 0px; left: 0px; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1; opacity: 0;" | ||
tabindex="-1" | ||
type="text/html" | ||
/> | ||
</div> | ||
`; |
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,23 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { Area } from '@oceanbase/charts'; | ||
|
||
describe('Area ref', () => { | ||
it('ref', () => { | ||
const DemoArea = () => { | ||
const ref = useRef(null); | ||
useEffect(() => { | ||
expect(ref.current).not.toBeNull(); | ||
expect(typeof ref.current?.getChart).toBe('function'); | ||
}, []); | ||
const config = { | ||
data: [], | ||
xField: 'x', | ||
yField: 'y', | ||
}; | ||
return <Area {...config} ref={ref} />; | ||
}; | ||
const { asFragment } = render(<DemoArea />); | ||
expect(asFragment().firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
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
26 changes: 26 additions & 0 deletions
26
packages/charts/src/DualAxes/__tests__/__snapshots__/ref.test.tsx.snap
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`DualAxes ref ref 1`] = ` | ||
<div | ||
data-chart-source-type="G2Plot" | ||
size-sensor-id="1" | ||
style="height: inherit;" | ||
> | ||
<div | ||
style="position:relative;" | ||
> | ||
<canvas | ||
height="400" | ||
style="width: 400px; height: 400px; display: inline-block; vertical-align: middle;" | ||
width="400" | ||
/> | ||
</div> | ||
<object | ||
class="size-sensor-object" | ||
data="about:blank" | ||
style="display: block; position: absolute; top: 0px; left: 0px; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1; opacity: 0;" | ||
tabindex="-1" | ||
type="text/html" | ||
/> | ||
</div> | ||
`; |
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,23 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { DualAxes } from '@oceanbase/charts'; | ||
|
||
describe('DualAxes ref', () => { | ||
it('ref', () => { | ||
const DemoDualAxes = () => { | ||
const ref = useRef(null); | ||
useEffect(() => { | ||
expect(ref.current).not.toBeNull(); | ||
expect(typeof ref.current?.getChart).toBe('function'); | ||
}, []); | ||
const config = { | ||
data: [[], []], | ||
xField: 'x', | ||
yField: ['y1', 'y2'], | ||
}; | ||
return <DualAxes {...config} ref={ref} />; | ||
}; | ||
const { asFragment } = render(<DemoDualAxes />); | ||
expect(asFragment().firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
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
26 changes: 26 additions & 0 deletions
26
packages/charts/src/Line/__tests__/__snapshots__/ref.test.tsx.snap
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Line ref ref 1`] = ` | ||
<div | ||
data-chart-source-type="G2Plot" | ||
size-sensor-id="1" | ||
style="height: inherit;" | ||
> | ||
<div | ||
style="position:relative;" | ||
> | ||
<canvas | ||
height="400" | ||
style="width: 400px; height: 400px; display: inline-block; vertical-align: middle;" | ||
width="400" | ||
/> | ||
</div> | ||
<object | ||
class="size-sensor-object" | ||
data="about:blank" | ||
style="display: block; position: absolute; top: 0px; left: 0px; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1; opacity: 0;" | ||
tabindex="-1" | ||
type="text/html" | ||
/> | ||
</div> | ||
`; |
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,23 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { Line } from '@oceanbase/charts'; | ||
|
||
describe('Line ref', () => { | ||
it('ref', () => { | ||
const DemoLine = () => { | ||
const ref = useRef(null); | ||
useEffect(() => { | ||
expect(ref.current).not.toBeNull(); | ||
expect(typeof ref.current?.getChart).toBe('function'); | ||
}, []); | ||
const config = { | ||
data: [], | ||
xField: 'x', | ||
yField: 'y', | ||
}; | ||
return <Line {...config} ref={ref} />; | ||
}; | ||
const { asFragment } = render(<DemoLine />); | ||
expect(asFragment().firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
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,36 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { Line } from '@oceanbase/charts'; | ||
|
||
export default () => { | ||
const [data, setData] = useState([]); | ||
const asyncFetch = () => { | ||
fetch('https://gw.alipayobjects.com/os/bmw-prod/55424a73-7cb8-4f79-b60d-3ab627ac5698.json') | ||
.then(response => response.json()) | ||
.then(json => setData(json)) | ||
.catch(error => { | ||
console.log('fetch data failed', error); | ||
}); | ||
}; | ||
useEffect(() => { | ||
asyncFetch(); | ||
}, []); | ||
const config = { | ||
data, | ||
xField: 'year', | ||
yField: 'value', | ||
seriesField: 'category', | ||
xAxis: { | ||
type: 'time', | ||
}, | ||
yAxis: { | ||
label: { | ||
// 数值格式化为千分位 | ||
formatter: v => `${v}`.replace(/\d{1,3}(?=(\d{3})+$)/g, s => `${s},`), | ||
}, | ||
}, | ||
style: { | ||
height: '50vh', | ||
}, | ||
}; | ||
return <Line {...config} />; | ||
}; |
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
Oops, something went wrong.