Explorar el Código

Merge pull request #388 from frappe/custom_number_shortner

feat: custom number formatter function
v2-beta
Ankush Menat hace 2 años
committed by GitHub
padre
commit
2b455e95a6
No se encontró ninguna clave conocida en la base de datos para esta firma ID de clave GPG: 4AEE18F83AFDEB23
Se han modificado 4 ficheros con 33 adiciones y 5 borrados
  1. +14
    -0
      .editorconfig
  2. +4
    -2
      src/js/charts/AxisChart.js
  3. +6
    -1
      src/js/objects/ChartComponents.js
  4. +9
    -2
      src/js/utils/draw.js

+ 14
- 0
.editorconfig Ver fichero

@@ -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

+ 4
- 2
src/js/charts/AxisChart.js Ver fichero

@@ -40,6 +40,8 @@ export default class AxisChart extends BaseChart {
this.config.yAxisMode = options.axisOptions.yAxisMode || 'span';
this.config.xIsSeries = options.axisOptions.xIsSeries || 0;
this.config.shortenYAxisNumbers = options.axisOptions.shortenYAxisNumbers || 0;
this.config.numberFormatter = options.axisOptions.numberFormatter;

this.config.yAxisRange = options.axisOptions.yAxisRange || {},

this.config.formatTooltipX = options.tooltipOptions.formatTooltipX;
@@ -196,8 +198,8 @@ export default class AxisChart extends BaseChart {
{
mode: this.config.yAxisMode,
width: this.width,
shortenNumbers: this.config.shortenYAxisNumbers
// pos: 'right'
shortenNumbers: this.config.shortenYAxisNumbers,
numberFormatter: this.config.numberFormatter,
},
function () {
return this.state.yAxis;


+ 6
- 1
src/js/objects/ChartComponents.js Ver fichero

@@ -125,7 +125,12 @@ let componentConfigs = {
makeElements(data) {
return data.positions.map((position, i) =>
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
})
);
},



+ 9
- 2
src/js/utils/draw.js Ver fichero

@@ -324,7 +324,13 @@ function makeVertLine(x, label, y1, y2, options = {}) {

function makeHoriLine(y, label, x1, x2, options = {}) {
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 +
(options.lineType === "dashed" ? "dashed" : "");
@@ -391,7 +397,8 @@ export function yLine(y, label, width, options = {}) {
return makeHoriLine(y, label, x1, x2, {
className: options.className,
lineType: options.lineType,
shortenNumbers: options.shortenNumbers
shortenNumbers: options.shortenNumbers,
numberFormatter: options.numberFormatter,
});
}



Cargando…
Cancelar
Guardar