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

Function leveledFormat

src/util/time.ts:331–368  ·  view source on GitHub ↗
(
    tick: ScaleTick,
    idx: number,
    formatter: TimeAxisLabelFormatterParsed,
    lang: string | Model<LocaleOption>,
    isUTC: boolean
)

Source from the content-addressed store, hash-verified

329}
330
331export function leveledFormat(
332 tick: ScaleTick,
333 idx: number,
334 formatter: TimeAxisLabelFormatterParsed,
335 lang: string | Model<LocaleOption>,
336 isUTC: boolean
337) {
338 let template = null;
339 if (zrUtil.isString(formatter)) {
340 // Single formatter for all units at all levels
341 template = formatter;
342 }
343 else if (zrUtil.isFunction(formatter)) {
344 const extra: TimeAxisLabelFormatterExtraParams = {
345 time: tick.time,
346 level: tick.time ? tick.time.level : 0,
347 };
348 const scaleBreakHelper = getScaleBreakHelper();
349 if (scaleBreakHelper) {
350 scaleBreakHelper.makeAxisLabelFormatterParamBreak(extra, tick.break);
351 }
352 template = formatter(tick.value, idx, extra);
353 }
354 else {
355 const tickTime = tick.time;
356 if (tickTime) {
357 const leveledTplArr = formatter[tickTime.lowerTimeUnit][tickTime.upperTimeUnit];
358 template = leveledTplArr[Math.min(tickTime.level, leveledTplArr.length - 1)] || '';
359 }
360 else {
361 // tick may be from customTicks or timeline therefore no tick.time.
362 const unit = getUnitFromValue(tick.value, isUTC);
363 template = formatter[unit][unit][0];
364 }
365 }
366
367 return format(new Date(tick.value), template, isUTC, lang);
368}
369
370export function getUnitFromValue(
371 value: number | string | Date,

Callers 1

getFormattedLabelMethod · 0.90

Calls 3

getScaleBreakHelperFunction · 0.90
getUnitFromValueFunction · 0.85
formatFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…