fix: make series label space ratio configurable (#424)
This commit is contained in:
parent
f5fc2c1bf7
commit
dc6ef83a7b
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "frappe-charts",
|
"name": "frappe-charts",
|
||||||
"version": "2.0.0-rc23",
|
"version": "2.0.0-rc24",
|
||||||
"main": "dist/frappe-charts.esm.js",
|
"main": "dist/frappe-charts.esm.js",
|
||||||
"module": "dist/frappe-charts.esm.js",
|
"module": "dist/frappe-charts.esm.js",
|
||||||
"browser": "dist/frappe-charts.umd.js",
|
"browser": "dist/frappe-charts.umd.js",
|
||||||
|
|||||||
@ -41,6 +41,7 @@ export default class AxisChart extends BaseChart {
|
|||||||
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.numberFormatter = options.axisOptions.numberFormatter;
|
||||||
|
this.config.seriesLabelSpaceRatio = options.axisOptions.seriesLabelSpaceRatio
|
||||||
|
|
||||||
this.config.yAxisRange = options.axisOptions.yAxisRange || {},
|
this.config.yAxisRange = options.axisOptions.yAxisRange || {},
|
||||||
|
|
||||||
@ -216,7 +217,7 @@ export default class AxisChart extends BaseChart {
|
|||||||
function () {
|
function () {
|
||||||
let s = this.state;
|
let s = this.state;
|
||||||
s.xAxis.calcLabels = getShortenedLabels(this.width,
|
s.xAxis.calcLabels = getShortenedLabels(this.width,
|
||||||
s.xAxis.labels, this.config.xIsSeries);
|
s.xAxis.labels, this.config.xIsSeries,this.config.seriesLabelSpaceRatio);
|
||||||
|
|
||||||
return s.xAxis;
|
return s.xAxis;
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
|
|||||||
@ -97,8 +97,8 @@ export function zeroDataPrep(realData) {
|
|||||||
return zeroData;
|
return zeroData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getShortenedLabels(chartWidth, labels = [], isSeries = true) {
|
export function getShortenedLabels(chartWidth, labels = [], isSeries = true, seriesLabelSpaceRatio) {
|
||||||
let allowedSpace = (chartWidth / labels.length) * SERIES_LABEL_SPACE_RATIO;
|
let allowedSpace = (chartWidth / labels.length) * (seriesLabelSpaceRatio || SERIES_LABEL_SPACE_RATIO);
|
||||||
if (allowedSpace <= 0) allowedSpace = 1;
|
if (allowedSpace <= 0) allowedSpace = 1;
|
||||||
let allowedLetters = allowedSpace / DEFAULT_CHAR_WIDTH;
|
let allowedLetters = allowedSpace / DEFAULT_CHAR_WIDTH;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user