Merge pull request #388 from frappe/custom_number_shortner
feat: custom number formatter function
This commit is contained in:
commit
2b455e95a6
14
.editorconfig
Normal file
14
.editorconfig
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Root editor config file
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# Common settings
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
charset = utf-8
|
||||||
|
|
||||||
|
# indentation settings
|
||||||
|
[{*.js,*.css,*.html}]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 4
|
||||||
@ -40,6 +40,8 @@ export default class AxisChart extends BaseChart {
|
|||||||
this.config.yAxisMode = options.axisOptions.yAxisMode || 'span';
|
this.config.yAxisMode = options.axisOptions.yAxisMode || 'span';
|
||||||
this.config.xIsSeries = options.axisOptions.xIsSeries || 0;
|
this.config.xIsSeries = options.axisOptions.xIsSeries || 0;
|
||||||
this.config.shortenYAxisNumbers = options.axisOptions.shortenYAxisNumbers || 0;
|
this.config.shortenYAxisNumbers = options.axisOptions.shortenYAxisNumbers || 0;
|
||||||
|
this.config.numberFormatter = options.axisOptions.numberFormatter;
|
||||||
|
|
||||||
this.config.yAxisRange = options.axisOptions.yAxisRange || {},
|
this.config.yAxisRange = options.axisOptions.yAxisRange || {},
|
||||||
|
|
||||||
this.config.formatTooltipX = options.tooltipOptions.formatTooltipX;
|
this.config.formatTooltipX = options.tooltipOptions.formatTooltipX;
|
||||||
@ -196,8 +198,8 @@ export default class AxisChart extends BaseChart {
|
|||||||
{
|
{
|
||||||
mode: this.config.yAxisMode,
|
mode: this.config.yAxisMode,
|
||||||
width: this.width,
|
width: this.width,
|
||||||
shortenNumbers: this.config.shortenYAxisNumbers
|
shortenNumbers: this.config.shortenYAxisNumbers,
|
||||||
// pos: 'right'
|
numberFormatter: this.config.numberFormatter,
|
||||||
},
|
},
|
||||||
function () {
|
function () {
|
||||||
return this.state.yAxis;
|
return this.state.yAxis;
|
||||||
|
|||||||
@ -125,7 +125,12 @@ let componentConfigs = {
|
|||||||
makeElements(data) {
|
makeElements(data) {
|
||||||
return data.positions.map((position, i) =>
|
return data.positions.map((position, i) =>
|
||||||
yLine(position, data.labels[i], this.constants.width,
|
yLine(position, data.labels[i], this.constants.width,
|
||||||
{ mode: this.constants.mode, pos: this.constants.pos, shortenNumbers: this.constants.shortenNumbers })
|
{
|
||||||
|
mode: this.constants.mode,
|
||||||
|
pos: this.constants.pos,
|
||||||
|
shortenNumbers: this.constants.shortenNumbers,
|
||||||
|
numberFormatter: this.constants.numberFormatter
|
||||||
|
})
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -324,7 +324,13 @@ function makeVertLine(x, label, y1, y2, options = {}) {
|
|||||||
|
|
||||||
function makeHoriLine(y, label, x1, x2, options = {}) {
|
function makeHoriLine(y, label, x1, x2, options = {}) {
|
||||||
if (!options.lineType) options.lineType = '';
|
if (!options.lineType) options.lineType = '';
|
||||||
if (options.shortenNumbers) label = shortenLargeNumber(label);
|
if (options.shortenNumbers) {
|
||||||
|
if (options.numberFormatter) {
|
||||||
|
label = options.numberFormatter(label);
|
||||||
|
} else {
|
||||||
|
label = shortenLargeNumber(label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let className = 'line-horizontal ' + options.className +
|
let className = 'line-horizontal ' + options.className +
|
||||||
(options.lineType === "dashed" ? "dashed" : "");
|
(options.lineType === "dashed" ? "dashed" : "");
|
||||||
@ -391,7 +397,8 @@ export function yLine(y, label, width, options = {}) {
|
|||||||
return makeHoriLine(y, label, x1, x2, {
|
return makeHoriLine(y, label, x1, x2, {
|
||||||
className: options.className,
|
className: options.className,
|
||||||
lineType: options.lineType,
|
lineType: options.lineType,
|
||||||
shortenNumbers: options.shortenNumbers
|
shortenNumbers: options.shortenNumbers,
|
||||||
|
numberFormatter: options.numberFormatter,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user