Skip to content

Commit

Permalink
Hotfix for label autospace endless loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandro Burato committed Jun 20, 2017
1 parent 3a62190 commit cf55b04
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ https://github.com/plotly/plotly.js/compare/vX.Y.Z...master

where X.Y.Z is the semver of most recent plotly.js release.

## [1.25.0-d38] -- 2017-06-20

### Fix
- Hotfix for label auto space endless loop


## [1.25.0-d37] -- 2017-04-13

Expand Down
31 changes: 17 additions & 14 deletions dist/plotly-ion.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* plotly.js (ion) v1.25.0-d37
* plotly.js (ion) v1.25.0-d38
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
* Licensed under the MIT license
Expand Down Expand Up @@ -27154,7 +27154,7 @@ exports.svgAttrs = {
var Plotly = require('./plotly');

// package version injected by `npm run preprocess`
exports.version = '1.25.0-d37';
exports.version = '1.25.0-d38';

// inject promise polyfill
require('es6-promise').polyfill();
Expand Down Expand Up @@ -39055,21 +39055,22 @@ axes.doTicks = function(gd, axid, skipTitle) {
right: x + bb.width / 2 + 2,
width: bb.width + 2
});
ax._lastLabelWidth = bb.width;
});
for(i = 0; i < lbbArray.length - 1; i++) {
if(Lib.bBoxIntersect(lbbArray[i], lbbArray[i + 1])) {
// any overlap at all - set 30 degrees
autoangle = 30;
autoangle = 90;
break;
}
}
if(autoangle) {
var tickspacing = Math.abs(
(vals[vals.length - 1].x - vals[0].x) * ax._m
) / (vals.length - 1);
if(tickspacing < maxFontSize * 2.5) {
autoangle = 90;
}
// var tickspacing = Math.abs(
// (vals[vals.length - 1].x - vals[0].x) * ax._m
// ) / (vals.length - 1);
// if(tickspacing < maxFontSize * 2.5) {
// autoangle = 90;
// }
positionLabels(tickLabels, autoangle);
}
ax._lastangle = autoangle;
Expand All @@ -39089,8 +39090,8 @@ axes.doTicks = function(gd, axid, skipTitle) {
}

function performLabelEllipsis() {
var maxLengthtPct = 0.25; // the max percent of the total chart w/h after which labels get the ellipsis.
var maxLengthCap = 200; // we still won't give labels more than this amount of space.
var maxLengthtPct = 0.3; // the max percent of the total chart w/h after which labels get the ellipsis.
var maxLengthCap = 220; // we still won't give labels more than this amount of space.
var maxLength = (axletter === "x" ? gd._fullLayout["height"] : gd._fullLayout["width"]) * maxLengthtPct;
maxLength = Math.min(maxLength, maxLengthCap);

Expand All @@ -39108,7 +39109,7 @@ axes.doTicks = function(gd, axid, skipTitle) {
var labelLength = (axletter === "x" ? bb["height"] : bb["width"]);

// aburato: if the label is too long perform a middle ellipsis
if (labelLength > maxLength) {
if (labelLength > maxLength + 1) {
var drawnText = d.text;
var maxCharLength = Math.round(maxLength / (labelLength / drawnText.length));
var firstLen = Math.floor(maxCharLength / 2);
Expand Down Expand Up @@ -39177,10 +39178,12 @@ axes.doTicks = function(gd, axid, skipTitle) {
shiftMargins[marginDimension] = shiftAmount;

if (perpMarginDimension === "r") {
perpShiftAmount = axBB.width - ax._length;
if (ax._lastangle === 0) {
perpShiftAmount = ax._lastLabelWidth / 2;
}
if (perpShiftAmount > 0) {
var perpShiftMargins = {
x: 1.1,
x: 1.01,
y: 0,
l: 0,
r: perpShiftAmount,
Expand Down
8 changes: 4 additions & 4 deletions dist/plotly-ion.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plotly.js",
"version": "1.25.0-d37",
"version": "1.25.0-d38",
"description": "The open source javascript graphing library that powers plotly",
"license": "MIT",
"main": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/geo_assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ var saneTopojson = require('sane-topojson');


// package version injected by `npm run preprocess`
exports.version = '1.25.0-d37';
exports.version = '1.25.0-d38';

exports.topojson = saneTopojson;
2 changes: 1 addition & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
var Plotly = require('./plotly');

// package version injected by `npm run preprocess`
exports.version = '1.25.0-d37';
exports.version = '1.25.0-d38';

// inject promise polyfill
require('es6-promise').polyfill();
Expand Down
4 changes: 2 additions & 2 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,7 @@ axes.doTicks = function(gd, axid, skipTitle) {
function performLabelEllipsis() {
var maxLengthtPct = 0.3; // the max percent of the total chart w/h after which labels get the ellipsis.
var maxLengthCap = 220; // we still won't give labels more than this amount of space.
var maxLength = (axLetter === "x" ? gd._fullLayout["height"] : gd._fullLayout["width"]) * maxLengthtPct;
var maxLength = (axletter === "x" ? gd._fullLayout["height"] : gd._fullLayout["width"]) * maxLengthtPct;
maxLength = Math.min(maxLength, maxLengthCap);

// cache?
Expand All @@ -1919,7 +1919,7 @@ axes.doTicks = function(gd, axid, skipTitle) {
bb = Drawing.bBox(thisG.node());
ax.ellipsisCache[d.text] = bb;
}
var labelLength = (axLetter === "x" ? bb["height"] : bb["width"]);
var labelLength = (axletter === "x" ? bb["height"] : bb["width"]);

// aburato: if the label is too long perform a middle ellipsis
if (labelLength > maxLength + 1) {
Expand Down

0 comments on commit cf55b04

Please sign in to comment.