Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduced xAxisLabelFormatter #302

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# What's in this fork?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this portion of README from the PR?


Frappe Charts doesn't give you a way to format x-axis labels. This is necessary especially when you have a lot of data points in a series and the Frappe Charts ends up truncating x-axis labels (by default). You end-up with a mess in the x-axis consisting of tons of ellipsis - essentially making the x-axes useless. This fork introduces the following config parameter:

```javascript
{
xAxisLabelFormatter: function(xAxisWidth, xAxisOriginaLabels, xIsSeries) {
// create a COPY of xAxisOriginalLabels, transform individual labels, and return a new array of labels
}
}
```

<div align="center">
<img src="https://github.com/frappe/design/blob/master/logos/logo-2019/frappe-charts-logo.png" height="128">
<a href="https://frappe.github.io/charts">
Expand Down
10 changes: 2 additions & 8 deletions dist/frappe-charts.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,6 @@ class SvgTip {
}
}

/**
* Returns the value of a number upto 2 decimal places.
* @param {Number} d Any number
*/
function floatTwo(d) {
return parseFloat(d.toFixed(2));
}
Expand Down Expand Up @@ -3317,6 +3313,7 @@ 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.xAxisLabelFormatter = options.xAxisLabelFormatter || getShortenedLabels;

this.config.formatTooltipX = options.tooltipOptions.formatTooltipX;
this.config.formatTooltipY = options.tooltipOptions.formatTooltipY;
Expand Down Expand Up @@ -3488,9 +3485,7 @@ class AxisChart extends BaseChart {
},
function() {
let s = this.state;
s.xAxis.calcLabels = getShortenedLabels(this.width,
s.xAxis.labels, this.config.xIsSeries);

s.xAxis.calcLabels = this.config.xAxisLabelFormatter(this.width, s.xAxis.labels, this.config.xIsSeries);
return s.xAxis;
}.bind(this)
],
Expand Down Expand Up @@ -4020,7 +4015,6 @@ class DonutChart extends AggregationChart {
}
}

// import MultiAxisChart from './charts/MultiAxisChart';
const chartTypes = {
bar: AxisChart,
line: AxisChart,
Expand Down
2 changes: 1 addition & 1 deletion dist/frappe-charts.min.cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/frappe-charts.min.cjs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/frappe-charts.min.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/frappe-charts.min.esm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/frappe-charts.min.iife.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/frappe-charts.min.iife.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/js/frappe-charts.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/js/frappe-charts.min.js.map

Large diffs are not rendered by default.

21 changes: 15 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/js/charts/AxisChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ 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.xAxisLabelFormatter = options.xAxisLabelFormatter || getShortenedLabels;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this is axisOptions instead of the top level option?


this.config.formatTooltipX = options.tooltipOptions.formatTooltipX;
this.config.formatTooltipY = options.tooltipOptions.formatTooltipY;
Expand Down Expand Up @@ -210,9 +211,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.calcLabels = this.config.xAxisLabelFormatter(this.width, s.xAxis.labels, this.config.xIsSeries);
return s.xAxis;
}.bind(this)
],
Expand Down
Loading