Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(view): 修复 view 更新时, tooltip 依赖 coordinate 更新位置导致 crosshairs 位置错位 (#…
…4001) * fix(view): 修复 view 更新时, tooltip 依赖 coordinate 更新位置导致 crosshairs 位置错位 - 增加 demo * fix: 修复单测,避免 tooltip 为空
- Loading branch information
Showing
7 changed files
with
179 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Site deploy | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest # change to macOS-latest if need to run ci/test | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: yarn install | ||
- run: npm run lint | ||
|
||
publish-site: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: yarn install | ||
- run: npm run site:build | ||
- run: | | ||
cd public | ||
git init | ||
git config --local user.name antv | ||
git config --local user.email antv@antfin.com | ||
git add . | ||
git commit -m "update by release action" | ||
- uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{secrets.PERSONAL_ACCESS_TOKEN}} | ||
directory: public | ||
branch: gh-pages | ||
force: true |
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,115 @@ | ||
import { Chart, registerInteraction, registerAction, Action } from '@antv/g2'; | ||
|
||
class DragPoint extends Action { | ||
// Action 开始,不等同于 拖拽开始,需要判定移动的范围 | ||
protected starting = false; | ||
// 拖拽开始 | ||
protected dragStart = false; | ||
// 开始的节点 | ||
protected startPoint: any; | ||
protected target: any = null; | ||
|
||
start() { | ||
this.starting = true; | ||
this.startPoint = this.context.getCurrentPoint(); | ||
const { target } = this.context.event; | ||
// 只对 point 起拖拽作用 | ||
if (String(target.get('name')) === 'element,point') { | ||
this.target = target; | ||
} | ||
} | ||
|
||
drag() { | ||
if (!this.startPoint || !this.target) return; | ||
const current = this.context.getCurrentPoint(); | ||
const { view } = this.context; | ||
const event = this.context.event; | ||
if (!this.dragStart) { | ||
// 只能上下移动 | ||
if (Math.abs(current.y - this.startPoint.y) > 4) { | ||
view.emit('dragstart', { | ||
target: event.target, | ||
x: event.x, | ||
y: event.y, | ||
}); | ||
this.dragStart = true; | ||
} | ||
} else { | ||
view.emit('drag', { | ||
target: event.target, | ||
x: event.x, | ||
y: event.y, | ||
}); | ||
} | ||
const { shape } = this.target.get('element'); | ||
shape.attr('y', current.y); | ||
} | ||
|
||
end() { | ||
if (this.dragStart) { | ||
const view = this.context.view; | ||
const event = this.context.event; | ||
|
||
const { shape } = this.target.get('element'); | ||
const scale = view.getScalesByDim('y')['nlp']; | ||
const coordinate = view.getCoordinate(); | ||
const changedValue = scale.invert(coordinate.invertPoint({ x: 0, y: shape.attr('y') }).y); | ||
const origin = this.target.get('origin'); | ||
|
||
view.emit('dragend', { | ||
target: event.target, | ||
x: event.x, | ||
y: event.y, | ||
changedDatum: { ...origin.data, nlp: changedValue }, | ||
}); | ||
} | ||
this.target = null; | ||
this.starting = false; | ||
this.dragStart = false; | ||
} | ||
} | ||
|
||
registerAction('drag-point', DragPoint); | ||
registerInteraction('custom-interaction', { | ||
start: [{ trigger: 'element:mousedown', action: 'drag-point:start' }], | ||
processing: [{ trigger: 'plot:mousemove', action: 'drag-point:drag' }], | ||
end: [{ trigger: 'plot:mouseup', action: 'drag-point:end' }], | ||
}); | ||
|
||
fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/blockchain.json') | ||
.then((data) => data.json()) | ||
.then((data) => { | ||
const chart = new Chart({ | ||
container: 'container', | ||
autoFit: true, | ||
height: 500, | ||
}); | ||
chart.data(data); | ||
|
||
chart.line().position('date*blockchain').color('#1890ff'); | ||
chart.line().position('date*nlp').color('#2fc25b'); | ||
chart.point().position('date*nlp').color('#2fc25b').size(3).style({ zIndex: 2 }); | ||
|
||
chart.scale('blockchain', { sync: true }); | ||
chart.scale('nlp', { sync: 'blockchain' }); | ||
chart.axis('nlp', false); | ||
|
||
chart.option('slider', { start: 0.2, end: 0.4 }); | ||
|
||
chart.interaction('custom-interaction'); | ||
|
||
chart.render(); | ||
|
||
chart.tooltip({ showCrosshairs: true, showMarkers: false }); | ||
|
||
chart.on('dragend', ({ changedDatum }) => { | ||
const newData = data.map((d) => { | ||
if (d.date === changedDatum.date) { | ||
return changedDatum; | ||
} | ||
return d; | ||
}); | ||
chart.data(newData); | ||
chart.render(true); | ||
}); | ||
}); |
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,17 @@ | ||
{ | ||
"title": { | ||
"zh": "中文分类", | ||
"en": "Category" | ||
}, | ||
"demos": [ | ||
{ | ||
"filename": "drag-point.ts", | ||
"title": { | ||
"zh": "拖拽点交互", | ||
"en": "Drag point" | ||
}, | ||
"new": true, | ||
"screenshot": "" | ||
} | ||
] | ||
} |
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 @@ | ||
--- | ||
title: Custom interactions | ||
order: 8 | ||
--- |
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 @@ | ||
--- | ||
title: 自定义交互 | ||
order: 8 | ||
--- |
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