MCPcopy Index your code
hub / github.com/apache/echarts / labelLayout

Function labelLayout

src/chart/funnel/funnelLayout.ts:55–248  ·  view source on GitHub ↗
(data: SeriesData)

Source from the content-addressed store, hash-verified

53}
54
55function labelLayout(data: SeriesData) {
56 const seriesModel = data.hostModel as FunnelSeriesModel;
57 const isHorizontal = isOrientHorizontal(seriesModel);
58 data.each(function (idx) {
59 const itemModel = data.getItemModel<FunnelDataItemOption>(idx);
60 const labelModel = itemModel.getModel('label');
61 let labelPosition = labelModel.get('position');
62
63 const labelLineModel = itemModel.getModel('labelLine');
64
65 const layout = data.getItemLayout(idx);
66 const points = layout.points;
67
68 const isLabelInside = labelPosition === 'inner'
69 || labelPosition === 'inside' || labelPosition === 'center'
70 || labelPosition === 'insideLeft' || labelPosition === 'insideRight';
71
72 let textAlign;
73 let textX;
74 let textY;
75 let linePoints;
76
77 if (isLabelInside) {
78 if (labelPosition === 'insideLeft') {
79 textX = (points[0][0] + points[3][0]) / 2 + 5;
80 textY = (points[0][1] + points[3][1]) / 2;
81 textAlign = 'left';
82 }
83 else if (labelPosition === 'insideRight') {
84 textX = (points[1][0] + points[2][0]) / 2 - 5;
85 textY = (points[1][1] + points[2][1]) / 2;
86 textAlign = 'right';
87 }
88 else {
89 textX = (points[0][0] + points[1][0] + points[2][0] + points[3][0]) / 4;
90 textY = (points[0][1] + points[1][1] + points[2][1] + points[3][1]) / 4;
91 textAlign = 'center';
92 }
93 linePoints = [
94 [textX, textY], [textX, textY]
95 ];
96 }
97 else {
98 let x1;
99 let y1;
100 let x2;
101 let y2;
102 const labelLineLen = labelLineModel.get('length');
103 if (isString(labelPosition)) {
104 if (!isHorizontal && indexOf(['top', 'bottom'], labelPosition) > -1) {
105 labelPosition = 'left';
106 if (__DEV__) {
107 console.warn(
108 'Position error: Funnel chart on vertical orient dose not support top and bottom.'
109 );
110 }
111 }
112 if (isHorizontal && indexOf(['left', 'right'], labelPosition as string) > -1) {

Callers 2

funnelLayoutFunction · 0.85
renderMethod · 0.85

Calls 6

isOrientHorizontalFunction · 0.85
getItemModelMethod · 0.80
getItemLayoutMethod · 0.80
eachMethod · 0.45
getModelMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…