fix: make series label space ratio configurable (#424)

This commit is contained in:
Soham Kulkarni 2025-03-25 19:55:03 +05:30 committed by GitHub
parent f5fc2c1bf7
commit dc6ef83a7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
"name": "frappe-charts",
"version": "2.0.0-rc23",
"version": "2.0.0-rc24",
"main": "dist/frappe-charts.esm.js",
"module": "dist/frappe-charts.esm.js",
"browser": "dist/frappe-charts.umd.js",

View File

@ -41,6 +41,7 @@ export default class AxisChart extends BaseChart {
this.config.xIsSeries = options.axisOptions.xIsSeries || 0;
this.config.shortenYAxisNumbers = options.axisOptions.shortenYAxisNumbers || 0;
this.config.numberFormatter = options.axisOptions.numberFormatter;
this.config.seriesLabelSpaceRatio = options.axisOptions.seriesLabelSpaceRatio
this.config.yAxisRange = options.axisOptions.yAxisRange || {},
@ -216,7 +217,7 @@ export default class AxisChart extends BaseChart {
function () {
let s = this.state;
s.xAxis.calcLabels = getShortenedLabels(this.width,
s.xAxis.labels, this.config.xIsSeries);
s.xAxis.labels, this.config.xIsSeries,this.config.seriesLabelSpaceRatio);
return s.xAxis;
}.bind(this)

View File

@ -97,8 +97,8 @@ export function zeroDataPrep(realData) {
return zeroData;
}
export function getShortenedLabels(chartWidth, labels = [], isSeries = true) {
let allowedSpace = (chartWidth / labels.length) * SERIES_LABEL_SPACE_RATIO;
export function getShortenedLabels(chartWidth, labels = [], isSeries = true, seriesLabelSpaceRatio) {
let allowedSpace = (chartWidth / labels.length) * (seriesLabelSpaceRatio || SERIES_LABEL_SPACE_RATIO);
if (allowedSpace <= 0) allowedSpace = 1;
let allowedLetters = allowedSpace / DEFAULT_CHAR_WIDTH;