提交 a245ad82 编写于 作者: P pissang

refact: put label as textContent in pie and funnel. fix inside text color issue.

上级 fc26a5f3
...@@ -46,7 +46,7 @@ class FunnelPiece extends graphic.Group { ...@@ -46,7 +46,7 @@ class FunnelPiece extends graphic.Group {
let text = new graphic.Text(); let text = new graphic.Text();
this.add(polygon); this.add(polygon);
this.add(labelLine); this.add(labelLine);
this.add(text); polygon.setTextContent(text);
this.updateData(data, idx, true); this.updateData(data, idx, true);
} }
...@@ -123,9 +123,9 @@ class FunnelPiece extends graphic.Group { ...@@ -123,9 +123,9 @@ class FunnelPiece extends graphic.Group {
} }
_updateLabel(data: List, idx: number) { _updateLabel(data: List, idx: number) {
let polygon = this.childAt(0);
let labelLine = this.childAt(1) as graphic.Polyline; let labelLine = this.childAt(1) as graphic.Polyline;
let labelText = this.childAt(2) as graphic.Text; let labelText = polygon.getTextContent();
let seriesModel = data.hostModel; let seriesModel = data.hostModel;
let itemModel = data.getItemModel<FunnelDataItemOption>(idx); let itemModel = data.getItemModel<FunnelDataItemOption>(idx);
...@@ -144,9 +144,7 @@ class FunnelPiece extends graphic.Group { ...@@ -144,9 +144,7 @@ class FunnelPiece extends graphic.Group {
{ {
labelFetcher: data.hostModel as FunnelSeriesModel, labelFetcher: data.hostModel as FunnelSeriesModel,
labelDataIndex: idx, labelDataIndex: idx,
defaultText: data.getName(idx), defaultText: data.getName(idx)
autoColor: visualColor,
useInsideStyle: !!labelLayout.inside
}, },
{ {
align: labelLayout.textAlign, align: labelLayout.textAlign,
...@@ -154,6 +152,14 @@ class FunnelPiece extends graphic.Group { ...@@ -154,6 +152,14 @@ class FunnelPiece extends graphic.Group {
} }
); );
polygon.setTextConfig({
local: true,
inside: !!labelLayout.inside,
insideStroke: visualColor,
insideFill: 'auto',
outsideFill: visualColor
});
graphic.updateProps(labelLine, { graphic.updateProps(labelLine, {
shape: { shape: {
points: labelLayout.linePoints || labelLayout.linePoints points: labelLayout.linePoints || labelLayout.linePoints
...@@ -168,6 +174,7 @@ class FunnelPiece extends graphic.Group { ...@@ -168,6 +174,7 @@ class FunnelPiece extends graphic.Group {
y: labelLayout.y y: labelLayout.y
} }
}, seriesModel, idx); }, seriesModel, idx);
labelText.attr({ labelText.attr({
rotation: labelLayout.rotation, rotation: labelLayout.rotation,
origin: [labelLayout.x, labelLayout.y], origin: [labelLayout.x, labelLayout.y],
......
...@@ -29,7 +29,6 @@ import List from '../../data/List'; ...@@ -29,7 +29,6 @@ import List from '../../data/List';
import PieSeriesModel, {PieDataItemOption} from './PieSeries'; import PieSeriesModel, {PieDataItemOption} from './PieSeries';
import { Dictionary } from 'zrender/src/core/types'; import { Dictionary } from 'zrender/src/core/types';
import Element from 'zrender/src/Element'; import Element from 'zrender/src/Element';
import Displayable from 'zrender/src/graphic/Displayable';
function updateDataSelected( function updateDataSelected(
this: PiePiece, this: PiePiece,
...@@ -86,11 +85,6 @@ function toggleItemSelected( ...@@ -86,11 +85,6 @@ function toggleItemSelected(
: el.attr('position', position); : el.attr('position', position);
} }
interface PieceElementExtension extends Displayable {
hoverIgnore?: boolean
normalIgnore?: boolean
};
/** /**
* Piece of pie including Sector, Label, LabelLine * Piece of pie including Sector, Label, LabelLine
*/ */
...@@ -107,15 +101,14 @@ class PiePiece extends graphic.Group { ...@@ -107,15 +101,14 @@ class PiePiece extends graphic.Group {
let text = new graphic.Text(); let text = new graphic.Text();
this.add(sector); this.add(sector);
this.add(polyline); this.add(polyline);
this.add(text);
sector.setTextContent(text);
this.updateData(data, idx, true); this.updateData(data, idx, true);
} }
updateData(data: List, idx: number, firstCreate?: boolean): void { updateData(data: List, idx: number, firstCreate?: boolean): void {
let sector = this.childAt(0) as graphic.Sector; let sector = this.childAt(0) as graphic.Sector;
let labelLine = this.childAt(1) as PieceElementExtension;
let labelText = this.childAt(2) as PieceElementExtension;
let seriesModel = data.hostModel as PieSeriesModel; let seriesModel = data.hostModel as PieSeriesModel;
let itemModel = data.getItemModel<PieDataItemOption>(idx); let itemModel = data.getItemModel<PieDataItemOption>(idx);
...@@ -197,8 +190,6 @@ class PiePiece extends graphic.Group { ...@@ -197,8 +190,6 @@ class PiePiece extends graphic.Group {
(this as ECElement).highDownOnUpdate = (itemModel.get('hoverAnimation') && seriesModel.isAnimationEnabled()) (this as ECElement).highDownOnUpdate = (itemModel.get('hoverAnimation') && seriesModel.isAnimationEnabled())
? function (fromState: DisplayState, toState: DisplayState): void { ? function (fromState: DisplayState, toState: DisplayState): void {
if (toState === 'emphasis') { if (toState === 'emphasis') {
labelLine.ignore = labelLine.hoverIgnore;
labelText.ignore = labelText.hoverIgnore;
// Sector may has animation of updating data. Force to move to the last frame // Sector may has animation of updating data. Force to move to the last frame
// Or it may stopped on the wrong shape // Or it may stopped on the wrong shape
...@@ -210,9 +201,6 @@ class PiePiece extends graphic.Group { ...@@ -210,9 +201,6 @@ class PiePiece extends graphic.Group {
}, { duration: 300, easing: 'elasticOut' }); }, { duration: 300, easing: 'elasticOut' });
} }
else { else {
labelLine.ignore = labelLine.normalIgnore;
labelText.ignore = labelText.normalIgnore;
sector.stopAnimation(true); sector.stopAnimation(true);
sector.animateTo({ sector.animateTo({
shape: { shape: {
...@@ -227,19 +215,22 @@ class PiePiece extends graphic.Group { ...@@ -227,19 +215,22 @@ class PiePiece extends graphic.Group {
} }
private _updateLabel(data: List, idx: number, withAnimation: boolean): void { private _updateLabel(data: List, idx: number, withAnimation: boolean): void {
const sector = this.childAt(0);
let labelLine = this.childAt(1) as (PieceElementExtension & graphic.Polyline); const labelLine = this.childAt(1) as graphic.Polyline;
let labelText = this.childAt(2) as (PieceElementExtension & graphic.Text); const labelText = sector.getTextContent() as graphic.Text;
let seriesModel = data.hostModel; const seriesModel = data.hostModel;
let itemModel = data.getItemModel<PieDataItemOption>(idx); const itemModel = data.getItemModel<PieDataItemOption>(idx);
let layout = data.getItemLayout(idx); const layout = data.getItemLayout(idx);
let labelLayout = layout.label; const labelLayout = layout.label;
// let visualColor = data.getItemVisual(idx, 'color'); // let visualColor = data.getItemVisual(idx, 'color');
const labelTextEmphasisState = labelText.ensureState('emphasis');
const labelLineEmphasisState = labelLine.ensureState('emphasis');
if (!labelLayout || isNaN(labelLayout.x) || isNaN(labelLayout.y)) { if (!labelLayout || isNaN(labelLayout.x) || isNaN(labelLayout.y)) {
labelText.ignore = labelText.normalIgnore = labelText.hoverIgnore = labelText.ignore = labelTextEmphasisState.ignore = true;
labelLine.ignore = labelLine.normalIgnore = labelLine.hoverIgnore = true; labelLine.ignore = labelLineEmphasisState.ignore = true;
return; return;
} }
...@@ -263,9 +254,7 @@ class PiePiece extends graphic.Group { ...@@ -263,9 +254,7 @@ class PiePiece extends graphic.Group {
{ {
labelFetcher: data.hostModel as PieSeriesModel, labelFetcher: data.hostModel as PieSeriesModel,
labelDataIndex: idx, labelDataIndex: idx,
defaultText: labelLayout.text, defaultText: labelLayout.text
autoColor: visualColor,
useInsideStyle: !!labelLayout.inside
}, },
{ {
align: labelLayout.textAlign, align: labelLayout.textAlign,
...@@ -274,6 +263,15 @@ class PiePiece extends graphic.Group { ...@@ -274,6 +263,15 @@ class PiePiece extends graphic.Group {
} }
); );
// Set textConfig on sector.
sector.setTextConfig({
local: true,
inside: !!labelLayout.inside,
insideStroke: visualColor,
insideFill: 'auto',
outsideFill: visualColor
});
let targetTextStyle = { let targetTextStyle = {
x: labelLayout.x, x: labelLayout.x,
y: labelLayout.y y: labelLayout.y
...@@ -304,11 +302,11 @@ class PiePiece extends graphic.Group { ...@@ -304,11 +302,11 @@ class PiePiece extends graphic.Group {
z2: 10 z2: 10
}); });
labelText.ignore = labelText.normalIgnore = !labelModel.get('show'); labelText.ignore = !labelModel.get('show');
labelText.hoverIgnore = !labelHoverModel.get('show'); labelTextEmphasisState.ignore = !labelHoverModel.get('show');
labelLine.ignore = labelLine.normalIgnore = !labelLineModel.get('show'); labelLine.ignore = !labelLineModel.get('show');
labelLine.hoverIgnore = !labelLineHoverModel.get('show'); labelLineEmphasisState.ignore = !labelLineHoverModel.get('show');
// Default use item visual color // Default use item visual color
labelLine.setStyle({ labelLine.setStyle({
......
...@@ -52,16 +52,19 @@ class SunburstPiece extends graphic.Group { ...@@ -52,16 +52,19 @@ class SunburstPiece extends graphic.Group {
super(); super();
let sector = new graphic.Sector({ let sector = new graphic.Sector({
z2: DEFAULT_SECTOR_Z z2: DEFAULT_SECTOR_Z,
textConfig: {
inside: true
}
}); });
this.add(sector);
graphic.getECData(sector).seriesIndex = seriesModel.seriesIndex; graphic.getECData(sector).seriesIndex = seriesModel.seriesIndex;
let text = new graphic.Text({ let text = new graphic.Text({
z2: DEFAULT_TEXT_Z, z2: DEFAULT_TEXT_Z,
silent: node.getModel<SunburstSeriesNodeOption>().get(['label', 'silent']) silent: node.getModel<SunburstSeriesNodeOption>().get(['label', 'silent'])
}); });
this.add(sector); sector.setTextContent(text);
this.add(text);
this.updateData(true, node, 'normal', seriesModel, ecModel); this.updateData(true, node, 'normal', seriesModel, ecModel);
...@@ -238,16 +241,22 @@ class SunburstPiece extends graphic.Group { ...@@ -238,16 +241,22 @@ class SunburstPiece extends graphic.Group {
text = ''; text = '';
} }
let label = this.childAt(1) as graphic.Text; let sector = this.childAt(0);
let label = sector.getTextContent();
graphic.setLabelStyle( graphic.setLabelStyle(
label, normalModel, labelHoverModel, label, normalModel, labelHoverModel,
{ {
defaultText: labelModel.getShallow('show') ? text : null, defaultText: labelModel.getShallow('show') ? text : null,
autoColor: visualColor, autoColor: visualColor
useInsideStyle: true
} }
); );
sector.setTextConfig({
inside: true,
insideStroke: visualColor,
insideFill: 'auto',
outsideFill: visualColor
});
let midAngle = (layout.startAngle + layout.endAngle) / 2; let midAngle = (layout.startAngle + layout.endAngle) / 2;
let dx = Math.cos(midAngle); let dx = Math.cos(midAngle);
......
...@@ -274,8 +274,7 @@ class MapDraw { ...@@ -274,8 +274,7 @@ class MapDraw {
{ {
labelFetcher: labelFetcher, labelFetcher: labelFetcher,
labelDataIndex: query, labelDataIndex: query,
defaultText: region.name, defaultText: region.name
useInsideStyle: false
}, },
{ {
align: 'center', align: 'center',
......
...@@ -114,14 +114,6 @@ type TextCommonParams = { ...@@ -114,14 +114,6 @@ type TextCommonParams = {
* for textFill, textStroke, textBackgroundColor, and textBorderColor. If autoColor specified, it is used as default textFill. * for textFill, textStroke, textBackgroundColor, and textBorderColor. If autoColor specified, it is used as default textFill.
*/ */
autoColor?: ColorString autoColor?: ColorString
/**
* `true`: Use inside style (textFill, textStroke, textStrokeWidth)
* if `textFill` is not specified.
* `false`: Do not use inside style.
* `null/undefined`: use inside style if `isRectText` is true and
* `textFill` is not specified and textPosition contains `'inside'`.
*/
useInsideStyle?: boolean
forceRich?: boolean forceRich?: boolean
...@@ -592,7 +584,7 @@ interface SetLabelStyleOpt<LDI> extends TextCommonParams { ...@@ -592,7 +584,7 @@ interface SetLabelStyleOpt<LDI> extends TextCommonParams {
* If target is other Element. It will create or reuse RichText which is attached on the target. * If target is other Element. It will create or reuse RichText which is attached on the target.
* And create a new style object. * And create a new style object.
* *
* NOTICE: Because the style on RichText will be replaced with new. * NOTICE: Because the style on RichText will be replaced with new(only x, y are keeped).
* So please use the style on RichText after use this method. * So please use the style on RichText after use this method.
*/ */
export function setLabelStyle<LDI>( export function setLabelStyle<LDI>(
...@@ -692,6 +684,14 @@ export function setLabelStyle<LDI>( ...@@ -692,6 +684,14 @@ export function setLabelStyle<LDI>(
normalStyle.text = normalStyleText; normalStyle.text = normalStyleText;
emphasisState.style.text = emphasisStyleText; emphasisState.style.text = emphasisStyleText;
// Keep x and y
if (richText.style.x != null) {
normalStyle.x = richText.style.x;
}
if (richText.style.y != null) {
normalStyle.y = richText.style.y;
}
// Always create new style. // Always create new style.
richText.useStyle(normalStyle); richText.useStyle(normalStyle);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册