MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / makeLabelFormatter

Function makeLabelFormatter

libs/echarts/echarts.simple.js:37851–37886  ·  view source on GitHub ↗

* @param {module:echarts/coord/Axis} axis * @return {Function} Label formatter function. * param: {number} tickValue, * param: {number} idx, the index in all ticks. * If category axis, this param is not requied. * return: {string} label string.

(axis)

Source from the content-addressed store, hash-verified

37849 * return: {string} label string.
37850 */
37851function makeLabelFormatter(axis) {
37852 var labelFormatter = axis.getLabelModel().get('formatter');
37853 var categoryTickStart = axis.type === 'category' ? axis.scale.getExtent()[0] : null;
37854
37855 if (typeof labelFormatter === 'string') {
37856 labelFormatter = (function (tpl) {
37857 return function (val) {
37858 // For category axis, get raw value; for numeric axis,
37859 // get foramtted label like '1,333,444'.
37860 val = axis.scale.getLabel(val);
37861 return tpl.replace('{value}', val != null ? val : '');
37862 };
37863 })(labelFormatter);
37864 // Consider empty array
37865 return labelFormatter;
37866 }
37867 else if (typeof labelFormatter === 'function') {
37868 return function (tickValue, idx) {
37869 // The original intention of `idx` is "the index of the tick in all ticks".
37870 // But the previous implementation of category axis do not consider the
37871 // `axisLabel.interval`, which cause that, for example, the `interval` is
37872 // `1`, then the ticks "name5", "name7", "name9" are displayed, where the
37873 // corresponding `idx` are `0`, `2`, `4`, but not `0`, `1`, `2`. So we keep
37874 // the definition here for back compatibility.
37875 if (categoryTickStart != null) {
37876 idx = tickValue - categoryTickStart;
37877 }
37878 return labelFormatter(getAxisRawValue(axis, tickValue), idx);
37879 };
37880 }
37881 else {
37882 return function (tick) {
37883 return axis.scale.getLabel(tick);
37884 };
37885 }
37886}
37887
37888function getAxisRawValue(axis, value) {
37889 // In category axis with data zoom, tick is not the original

Calls 3

getAxisRawValueFunction · 0.70
getMethod · 0.45
getExtentMethod · 0.45

Tested by

no test coverage detected