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

Function parseTimeAxisLabelFormatterDictionary

src/util/time.ts:166–236  ·  view source on GitHub ↗

* The final generated dictionary is like: * generated_dict = { * year: { * year: ['{yyyy}', ... ] * }, * month: { * year: ['{yyyy} {MMM}', ... ], * month: ['{MMM}', ... ] * }, *

(
    dictOption: TimeAxisLabelFormatterDictionaryOption | NullUndefined
)

Source from the content-addressed store, hash-verified

164 * but we need it to be "minute", following `Feb 6th 18:30`.
165 */
166function parseTimeAxisLabelFormatterDictionary(
167 dictOption: TimeAxisLabelFormatterDictionaryOption | NullUndefined
168): TimeAxisLabelFormatterDictionary {
169 dictOption = dictOption || {};
170 const dict = {} as TimeAxisLabelFormatterDictionary;
171
172 // Currently if any template is specified by user, it may contain rich text tag,
173 // such as `'{my_bold|{YYYY}}'`, thus we do add highlight style to it.
174 // (Note that nested tag (`'{some|{some2|xxx}}'`) in rich text is not supported yet.)
175 let canAddHighlight = true;
176 zrUtil.each(primaryTimeUnits, lowestUnit => {
177 canAddHighlight &&= dictOption[lowestUnit] == null;
178 });
179
180 zrUtil.each(primaryTimeUnits, (lowestUnit, lowestUnitIdx) => {
181 const upperDictOption = dictOption[lowestUnit];
182 dict[lowestUnit] = {} as TimeAxisLabelFormatterUpperDictionary;
183
184 let lowerTpl: string | null = null;
185 for (let upperUnitIdx = lowestUnitIdx; upperUnitIdx >= 0; upperUnitIdx--) {
186 const upperUnit = primaryTimeUnits[upperUnitIdx];
187 const upperDictItemOption: TimeAxisLabelLeveledFormatterOption =
188 (zrUtil.isObject(upperDictOption) && !zrUtil.isArray(upperDictOption))
189 ? upperDictOption[upperUnit]
190 : upperDictOption;
191
192 let tplArr: string[];
193 if (zrUtil.isArray(upperDictItemOption)) {
194 tplArr = upperDictItemOption.slice();
195 lowerTpl = tplArr[0] || '';
196 }
197 else if (zrUtil.isString(upperDictItemOption)) {
198 lowerTpl = upperDictItemOption;
199 tplArr = [lowerTpl];
200 }
201 else {
202 if (lowerTpl == null) {
203 lowerTpl = defaultFormatterSeed[lowestUnit];
204 }
205 // Generate the dict by the rule as follows:
206 // If the user specify (or by default):
207 // {formatter: {
208 // year: '{yyyy}',
209 // month: '{MMM}',
210 // day: '{d}',
211 // ...
212 // }}
213 // Concat them to make the final dictionary:
214 // {formatter: {
215 // year: {year: ['{yyyy}']},
216 // month: {year: ['{yyyy} {MMM}'], month: ['{MMM}']},
217 // day: {year: ['{yyyy} {MMM} {d}'], month: ['{MMM} {d}'], day: ['{d}']}
218 // ...
219 // }}
220 // And then add `{primary|...}` to each array if from default template.
221 // This strategy is convinient for user configurating and works for most cases.
222 // If bad cases encountered, users can specify the entire dictionary themselves
223 // instead of going through this logic.

Callers 1

Calls 1

eachMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…