forked from antvis/GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(icon): add icon class for test g ui * feat(marker): add marker ui * feat(icon): use marker for icon * chore: update test case * chore: use father-build (antvis#20) * test: add tc * feat(icon): add background rect Co-authored-by: zhanba <[email protected]>
- Loading branch information
Showing
30 changed files
with
608 additions
and
58 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,9 @@ | ||
export default { | ||
esm: 'rollup', | ||
cjs: 'rollup', | ||
umd: { | ||
minFile: true, | ||
file: 'gui', | ||
name: 'GUI', | ||
}, | ||
}; |
File renamed without changes.
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,39 @@ | ||
import 'babel-polyfill'; | ||
import { Canvas } from '@antv/g'; | ||
import { Renderer as CanvasRenderer } from '@antv/g-canvas'; | ||
import { Icon } from '../../../../src'; | ||
import { createDiv } from '../../../utils'; | ||
|
||
const renderer = new CanvasRenderer({ | ||
enableDirtyRectangleRenderingDebug: false, | ||
enableAutoRendering: true, | ||
enableDirtyRectangleRendering: true, | ||
}); | ||
|
||
describe('icon', () => { | ||
test('basic', async () => { | ||
const div = createDiv(); | ||
|
||
// @ts-ignore | ||
const canvas = new Canvas({ | ||
container: div, | ||
width: 300, | ||
height: 300, | ||
renderer, | ||
}); | ||
|
||
const icon = new Icon({ | ||
attrs: { | ||
symbol: 'triangle-down', | ||
x: 50, | ||
y: 50, | ||
size: 10, | ||
spacing: 4, | ||
fill: 'green', | ||
text: '10.24%', | ||
}, | ||
}); | ||
|
||
canvas.appendChild(icon); | ||
}); | ||
}); |
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,71 @@ | ||
import 'babel-polyfill'; | ||
import { Canvas } from '@antv/g'; | ||
import { Renderer as CanvasRenderer } from '@antv/g-canvas'; | ||
import { Marker, svg2marker } from '../../../../src'; | ||
import { createDiv } from '../../../utils'; | ||
|
||
const renderer = new CanvasRenderer({ | ||
enableDirtyRectangleRenderingDebug: false, | ||
enableAutoRendering: true, | ||
enableDirtyRectangleRendering: true, | ||
}); | ||
|
||
describe('marker', () => { | ||
test('basic', async () => { | ||
const div = createDiv(); | ||
|
||
// @ts-ignore | ||
const canvas = new Canvas({ | ||
container: div, | ||
width: 300, | ||
height: 300, | ||
renderer, | ||
}); | ||
|
||
const marker = new Marker({ | ||
attrs: { | ||
symbol: 'triangle-down', | ||
x: 50, | ||
y: 50, | ||
r: 16, | ||
fill: 'green', | ||
}, | ||
}); | ||
|
||
canvas.appendChild(marker); | ||
|
||
expect(marker.getPathShape().getBounds().center[0]).toBe(100); | ||
expect(marker.getPathShape().getBounds().center[1]).toBe(100); | ||
}); | ||
|
||
test('customize marker', async () => { | ||
Marker.registerSymbol( | ||
'star', | ||
svg2marker( | ||
`<svg height="512" width="512" viewport="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="M480 207H308.6L256 47.9 203.4 207H32l140.2 97.9L117.6 464 256 365.4 394.4 464l-54.7-159.1L480 207zM362.6 421.2l-106.6-76-106.6 76L192 298.7 84 224h131l41-123.3L297 224h131l-108 74.6 42.6 122.6z"/></svg>` | ||
) | ||
); | ||
|
||
const div = createDiv(); | ||
|
||
// @ts-ignore | ||
const canvas = new Canvas({ | ||
container: div, | ||
width: 300, | ||
height: 300, | ||
renderer, | ||
}); | ||
|
||
const marker = new Marker({ | ||
attrs: { | ||
symbol: 'star', | ||
x: 50, | ||
y: 50, | ||
r: 16, | ||
stroke: 'red', | ||
}, | ||
}); | ||
|
||
canvas.appendChild(marker); | ||
}); | ||
}); |
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,12 @@ | ||
/** | ||
* 延迟函数 | ||
* @param ms | ||
* @returns | ||
*/ | ||
export async function delay(ms: number = 1000) { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve(true); | ||
}, ms); | ||
}); | ||
} |
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 @@ | ||
/** | ||
* 创建一个 div 节点,并放到 container,默认放到 body 上 | ||
* @param container | ||
*/ | ||
export function createDiv(container: HTMLElement = document.body): HTMLElement { | ||
const div = document.createElement('div'); | ||
|
||
container.appendChild(div); | ||
|
||
return div; | ||
} | ||
|
||
/** | ||
* 移除一个 DOM | ||
* @param dom | ||
*/ | ||
export function removeDom(dom: HTMLElement) { | ||
const parent = dom.parentNode; | ||
|
||
if (parent) { | ||
parent.removeChild(dom); | ||
} | ||
} |
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,2 @@ | ||
export { createDiv, removeDom } from './dom'; | ||
export { delay } from './delay'; |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
export * from './ui'; | ||
// ui | ||
export * from './ui'; | ||
|
||
// 方法 | ||
export { svg2marker } from './util'; |
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 @@ | ||
export { ShapeAttrs, ShapeCfg, CustomElement, DisplayObject } from '@antv/g'; |
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,4 +1,4 @@ | ||
import { ArrowOptions } from './types'; | ||
import { ArrowOptions } from './types'; | ||
|
||
export { ArrowOptions }; | ||
|
||
|
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,4 +1,4 @@ | ||
import { AxisOptions } from './types'; | ||
import { AxisOptions } from './types'; | ||
|
||
export { AxisOptions }; | ||
|
||
|
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,4 +1,4 @@ | ||
import { ButtonOptions } from './types'; | ||
import { ButtonOptions } from './types'; | ||
|
||
export { ButtonOptions }; | ||
|
||
|
Oops, something went wrong.