MCPcopy
hub / github.com/apache/echarts / getValueLabel

Function getValueLabel

src/component/axisPointer/viewHelper.ts:147–192  ·  view source on GitHub ↗
(
    value: ScaleDataValue,
    axis: Axis,
    ecModel: GlobalModel,
    seriesDataIndices: CommonAxisPointerOption['seriesDataIndices'],
    opt?: {
        precision?: number | 'auto'
        formatter?: CommonAxisPointerOption['label']['formatter']
    }
)

Source from the content-addressed store, hash-verified

145}
146
147export function getValueLabel(
148 value: ScaleDataValue,
149 axis: Axis,
150 ecModel: GlobalModel,
151 seriesDataIndices: CommonAxisPointerOption['seriesDataIndices'],
152 opt?: {
153 precision?: number | 'auto'
154 formatter?: CommonAxisPointerOption['label']['formatter']
155 }
156): string {
157 value = axis.scale.parse(value);
158 let text = (axis.scale as IntervalScale).getLabel(
159 {
160 value
161 }, {
162 // If `precision` is set, width can be fixed (like '12.00500'), which
163 // helps to debounce when when moving label.
164 precision: opt.precision
165 }
166 );
167 const formatter = opt.formatter;
168
169 if (formatter) {
170 const params = {
171 value: axisHelper.getAxisRawValue(axis, {value}),
172 axisDimension: axis.dim,
173 axisIndex: (axis as Axis2D).index, // Only Carteian Axis has index
174 seriesData: [] as CallbackDataParams[]
175 };
176 zrUtil.each(seriesDataIndices, function (idxItem) {
177 const series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
178 const dataIndex = idxItem.dataIndexInside;
179 const dataParams = series && series.getDataParams(dataIndex);
180 dataParams && params.seriesData.push(dataParams);
181 });
182
183 if (zrUtil.isString(formatter)) {
184 text = formatter.replace('{value}', text);
185 }
186 else if (zrUtil.isFunction(formatter)) {
187 text = formatter(params);
188 }
189 }
190
191 return text;
192}
193
194export function getTransformedPosition(
195 axis: Axis,

Callers 1

buildLabelElOptionFunction · 0.85

Calls 5

getSeriesByIndexMethod · 0.80
getDataParamsMethod · 0.65
parseMethod · 0.45
getLabelMethod · 0.45
eachMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…