-
Notifications
You must be signed in to change notification settings - Fork 23
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 #674 from VisActor/feat/enhance_dataLabel
Feat/enhance data label
- Loading branch information
Showing
8 changed files
with
243 additions
and
90 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
common/changes/@visactor/vrender-components/feat-enhance_dataLabel_2023-11-14-05-34.json
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,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@visactor/vrender-components", | ||
"comment": "feat(label): support line/area label", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@visactor/vrender-components" | ||
} |
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,47 @@ | ||
import type { IBoundsLike } from '@visactor/vutils'; | ||
import { merge } from '@visactor/vutils'; | ||
import type { IArea } from '@visactor/vrender-core'; | ||
import type { PointLocationCfg } from '../core/type'; | ||
import type { AreaLabelAttrs } from './type'; | ||
import { LabelBase } from './base'; | ||
import { labelingLineOrArea } from './util'; | ||
|
||
export class AreaLabel extends LabelBase<AreaLabelAttrs> { | ||
name = 'line-label'; | ||
|
||
static defaultAttributes: Partial<AreaLabelAttrs> = { | ||
textStyle: { | ||
fontSize: 12, | ||
fill: '#000', | ||
textAlign: 'center', | ||
textBaseline: 'middle', | ||
boundsPadding: [-1, 0, -1, 0] // to ignore the textBound buf | ||
}, | ||
position: 'end', | ||
offset: 6, | ||
pickable: false | ||
}; | ||
|
||
constructor(attributes: AreaLabelAttrs) { | ||
super(merge({}, AreaLabel.defaultAttributes, attributes)); | ||
} | ||
|
||
protected getGraphicBounds(graphic: IArea, point: Partial<PointLocationCfg> = {}) { | ||
if (graphic.type !== 'area') { | ||
return super.getGraphicBounds(graphic, point); | ||
} | ||
const { position = 'end' } = this.attribute; | ||
const points = graphic?.attribute?.points || [point]; | ||
const index = position === 'start' ? 0 : points.length - 1; | ||
return { | ||
x1: points[index].x as number, | ||
x2: points[index].x as number, | ||
y1: points[index].y as number, | ||
y2: points[index].y as number | ||
}; | ||
} | ||
|
||
protected labeling(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position: string = 'end', offset = 0) { | ||
return labelingLineOrArea(textBounds, graphicBounds, position, offset); | ||
} | ||
} |
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.