deno.land / x / billboardjs@3.6.0 / ChartInternal / internals / format.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/** * Copyright (c) 2017 ~ present NAVER Corp. * billboard.js project is licensed under the MIT license */import {isValue, isFunction, isObjectType} from "../../module/util";import type {AxisType} from "../../../types/types";
/** * Get formatted * @param {object} $$ Context * @param {string} typeValue Axis type * @param {number} v Value to be formatted * @returns {number | string} * @private */function getFormat($$, typeValue: AxisType, v: number): number | string { const {config} = $$; const type = `axis_${typeValue}_tick_format`; const format = config[type] ? config[type] : $$.defaultValueFormat;
return format(v);}
export default { yFormat(v: number): number | string { return getFormat(this, "y", v); },
y2Format(v: number): number | string { return getFormat(this, "y2", v); },
/** * Get default value format function * @returns {Function} formatter function * @private */ getDefaultValueFormat(): Function { const $$ = this; const {defaultArcValueFormat, yFormat, y2Format} = $$; const hasArc = $$.hasArcType(null, ["gauge", "polar", "radar"]);
return function(v, ratio, id) { const format = hasArc ? defaultArcValueFormat : ( $$.axis && $$.axis.getId(id) === "y2" ? y2Format : yFormat );
return format.call($$, v, ratio); }; },
defaultValueFormat(v): number|string { return isValue(v) ? +v : ""; },
defaultArcValueFormat(v, ratio): string { return `${(ratio * 100).toFixed(1)}%`; },
defaultPolarValueFormat(v): string { return `${v}`; },
dataLabelFormat(targetId: string): Function { const $$ = this; const dataLabels = $$.config.data_labels; const defaultFormat = v => (isValue(v) ? +v : ""); let format = defaultFormat;
// find format according to axis id if (isFunction(dataLabels.format)) { format = dataLabels.format; } else if (isObjectType(dataLabels.format)) { if (dataLabels.format[targetId]) { format = dataLabels.format[targetId] === true ? defaultFormat : dataLabels.format[targetId]; } else { format = () => ""; } }
return format.bind($$.api); }};
billboardjs

Version Info

Tagged at
a year ago