-
Notifications
You must be signed in to change notification settings - Fork 652
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 增加Pictorial组件 * fix: 修改api --------- Co-authored-by: xuying.xu <xuying.xu@alibaba-inc.com>
- Loading branch information
1 parent
d715549
commit 24f5944
Showing
6 changed files
with
164 additions
and
0 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
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,4 @@ | ||
import Pictorial, { PictorialProps } from './pictorial'; | ||
|
||
export { PictorialProps, Pictorial }; | ||
export default Pictorial; |
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,35 @@ | ||
import { jsx } from '@antv/f-engine'; | ||
import { GeometryProps } from '../geometry'; | ||
import { withInterval } from '../interval'; | ||
import { DataRecord } from '../../chart/Data'; | ||
export interface PictorialProps<TRecord extends DataRecord = DataRecord> | ||
extends GeometryProps<TRecord> { | ||
symbol?: any; | ||
} | ||
|
||
export default class Pictorial extends withInterval({}) { | ||
props: PictorialProps; | ||
|
||
render() { | ||
const { props, context } = this; | ||
const { px2hd } = context; | ||
const { symbol: Symbol } = px2hd(props); | ||
const records = this.mapping(); | ||
|
||
return ( | ||
<group> | ||
{records.map((record) => { | ||
const { key, children } = record; | ||
return ( | ||
<group key={key}> | ||
{children.map((item) => { | ||
const { xMax, xMin, yMax, yMin } = item; | ||
return <Symbol {...item} width={xMax - xMin} height={yMax - yMin} px2hd={px2hd} />; | ||
})} | ||
</group> | ||
); | ||
})} | ||
</group> | ||
); | ||
} | ||
} |
Binary file added
BIN
+10.7 KB
...ictorial/__image_snapshots__/basic-test-tsx-pictorial-ellipse-symbol-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.1 KB
.../pictorial/__image_snapshots__/basic-test-tsx-pictorial-image-symbol-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,124 @@ | ||
import { jsx } from '../../../src'; | ||
import { Canvas, Chart, Pictorial, Axis, Tooltip } from '../../../src'; | ||
import { createContext, delay, gestureSimulator } from '../../util'; | ||
const context = createContext(); | ||
|
||
const data = [ | ||
{ | ||
x: '产品1', | ||
value: 4927, | ||
}, | ||
{ | ||
x: '产品2', | ||
value: 11607, | ||
}, | ||
]; | ||
|
||
describe('pictorial', () => { | ||
it('image symbol', async () => { | ||
const { props } = ( | ||
<Canvas context={context} pixelRatio={1}> | ||
<Chart data={data}> | ||
<Axis field="value" min={0}></Axis> | ||
|
||
<Pictorial | ||
x="x" | ||
y="value" | ||
symbol={({ xMin, xMax, yMin, yMax, px2hd }) => ( | ||
<group> | ||
<image | ||
style={{ | ||
x: xMin, | ||
y: yMax - px2hd('20px') / 2, | ||
width: xMax - xMin, | ||
height: '20px', | ||
src: | ||
'https://gw.alipayobjects.com/zos/finxbff/compress-tinypng/76LdyFixxEmUqrGG6rmCG/tuoyuanxingbeifen_32.png', | ||
}} | ||
/> | ||
<image | ||
style={{ | ||
x: xMin, | ||
y: yMin, | ||
width: xMax - xMin, | ||
height: yMax - yMin, | ||
src: | ||
'https://gw.alipayobjects.com/zos/finxbff/compress-tinypng/mNyB6MXFwnxLMwzfEWHYt/juxingbeifen_6.png', | ||
}} | ||
/> | ||
<image | ||
style={{ | ||
x: xMin, | ||
y: yMin - px2hd('20px') / 2, | ||
width: xMax - xMin, | ||
height: '20px', | ||
src: | ||
'https://gw.alipayobjects.com/zos/finxbff/compress-tinypng/VV9WVNGexcXLVYpQxjBFH/tuoyuanxingbeifen_13.png', | ||
}} | ||
/> | ||
</group> | ||
)} | ||
/> | ||
</Chart> | ||
</Canvas> | ||
); | ||
|
||
const canvas = new Canvas(props); | ||
await canvas.render(); | ||
|
||
await delay(1000); | ||
expect(context).toMatchImageSnapshot(); | ||
}); | ||
|
||
it('ellipse symbol', async () => { | ||
const { props } = ( | ||
<Canvas context={context} pixelRatio={1}> | ||
<Chart data={data}> | ||
<Axis field="value" min={0}></Axis> | ||
<Pictorial | ||
x="x" | ||
y="value" | ||
symbol={({ xMin, xMax, yMin, yMax, width, height, origin }) => ( | ||
<group> | ||
<ellipse | ||
style={{ | ||
cx: xMin + width / 2, | ||
cy: yMax, | ||
rx: width / 2, | ||
ry: '20px', | ||
fill: 'l(90) 0:#1f7eff 1:#64adff', | ||
}} | ||
/> | ||
<rect | ||
style={{ | ||
x: xMin, | ||
y: yMin, | ||
width, | ||
height, | ||
fill: 'l(90) 0:#9cc1ff 1:#ecf5ff', | ||
fillOpacity: 0.9, | ||
}} | ||
/> | ||
<ellipse | ||
style={{ | ||
cx: xMin + width / 2, | ||
cy: yMin, | ||
rx: width / 2, | ||
ry: '20px', | ||
fill: 'l(90) 0:#1f7eff 1:#64adff', | ||
}} | ||
/> | ||
</group> | ||
)} | ||
/> | ||
</Chart> | ||
</Canvas> | ||
); | ||
|
||
const canvas = new Canvas(props); | ||
await canvas.render(); | ||
|
||
await delay(1000); | ||
expect(context).toMatchImageSnapshot(); | ||
}); | ||
}); |