Skip to content

Commit

Permalink
Merge pull request #288 from frappe/refactor-truncate-legends
Browse files Browse the repository at this point in the history
  • Loading branch information
scmmishra committed Jun 3, 2020
2 parents 59416ec + ee38b15 commit a35c765
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 16 deletions.
9 changes: 5 additions & 4 deletions dist/frappe-charts.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@ class BaseChart {
showLegend: 1, // calculate
isNavigable: options.isNavigable || 0,
animate: (typeof options.animate !== 'undefined') ? options.animate : 1,
truncateLegends: options.truncateLegends || 0
truncateLegends: options.truncateLegends || 1
};

this.measures = JSON.parse(JSON.stringify(BASE_MEASURES));
Expand Down Expand Up @@ -1830,7 +1830,7 @@ class AggregationChart extends BaseChart {
let count = 0;
let y = 0;
this.legendTotals.map((d, i) => {
let barWidth = 110;
let barWidth = 150;
let divisor = Math.floor(
(this.width - getExtraWidth(this.measures))/barWidth
);
Expand All @@ -1842,13 +1842,14 @@ class AggregationChart extends BaseChart {
y += 20;
}
let x = barWidth * count + 5;
let label = this.config.truncateLegends ? truncateString(s.labels[i], barWidth/10) : s.labels[i];
let dot = legendDot(
x,
y,
5,
this.colors[i],
`${s.labels[i]}: ${d}`,
this.config.truncateLegends
`${label}: ${d}`,
false
);
this.legendArea.appendChild(dot);
count++;
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.

8 changes: 5 additions & 3 deletions src/js/charts/AggregationChart.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import BaseChart from './BaseChart';
import { truncateString } from '../utils/draw-utils';
import { legendDot } from '../utils/draw';
import { getExtraWidth } from '../utils/constants';

Expand Down Expand Up @@ -63,7 +64,7 @@ export default class AggregationChart extends BaseChart {
let count = 0;
let y = 0;
this.legendTotals.map((d, i) => {
let barWidth = 110;
let barWidth = 150;
let divisor = Math.floor(
(this.width - getExtraWidth(this.measures))/barWidth
);
Expand All @@ -75,13 +76,14 @@ export default class AggregationChart extends BaseChart {
y += 20;
}
let x = barWidth * count + 5;
let label = this.config.truncateLegends ? truncateString(s.labels[i], barWidth/10) : s.labels[i];
let dot = legendDot(
x,
y,
5,
this.colors[i],
`${s.labels[i]}: ${d}`,
this.config.truncateLegends
`${label}: ${d}`,
false
);
this.legendArea.appendChild(dot);
count++;
Expand Down
2 changes: 1 addition & 1 deletion src/js/charts/BaseChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class BaseChart {
showLegend: 1, // calculate
isNavigable: options.isNavigable || 0,
animate: (typeof options.animate !== 'undefined') ? options.animate : 1,
truncateLegends: options.truncateLegends || 0
truncateLegends: options.truncateLegends || 1
};

this.measures = JSON.parse(JSON.stringify(BASE_MEASURES));
Expand Down

0 comments on commit a35c765

Please sign in to comment.