Skip to content

Commit

Permalink
treemap label size tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
epicallan committed Jan 19, 2018
1 parent 313911e commit 4cd85f0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/factories/autofit/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ export const autoFitMetrics = (width, height, text) => {
const availableArea = width * height;
const words = text.split(/\s+/);
const longestWordLength = Math.max.apply(null, words.map((l) => { return l.length; }));
const estimatedArea = longestWordLength * (baseFont * 0.6) * words.length * baseFont;
const estimatedArea = longestWordLength * (baseFont * 0.8) * words.length * baseFont;

const areaRatio = Math.floor(availableArea / estimatedArea);
const widthRatio = width / (longestWordLength * (baseFont * 0.6));
const widthRatio = width / (longestWordLength * (baseFont * 0.8));

if (areaRatio < 2) return {fontSize: 0, showLabels: false};

if (areaRatio < 4) {
if (areaRatio < 3) {
return {fontSize: baseFont * 1.2, showLabels: widthRatio > 1};
}

if (areaRatio < 4) {
return {fontSize: baseFont * 1.3, showLabels: widthRatio > 1};
}

if (areaRatio < 6) {
return {fontSize: baseFont * 1.5, showLabels: widthRatio > 1};
return {fontSize: baseFont * 1.4, showLabels: widthRatio > 1};
}

return {fontSize: baseFont * 1.8, showLabels: widthRatio > 1};
Expand Down

0 comments on commit 4cd85f0

Please sign in to comment.