Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit55cb0eb

Browse files
committed
add extra axis padding when bars have outside text labels
1 parent5cb0bcd commit55cb0eb

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

‎src/traces/bar/cross_trace_calc.js‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ var Axes = require('../../plots/cartesian/axes');
99
vargetAxisGroup=require('../../plots/cartesian/constraints').getAxisGroup;
1010
varSieve=require('./sieve.js');
1111

12+
varTEXTPAD=require('./constants').TEXTPAD;
13+
1214
/*
1315
* Bar chart stacking/grouping positioning and autoscaling calculations
1416
* for each direction separately calculate the ranges and positions
@@ -565,13 +567,32 @@ function setBaseAndTop(sa, sieve) {
565567
}
566568
}
567569

570+
consttextPadding=estimateExtraPaddingForText(fullTrace);
568571
fullTrace._extremes[sa._id]=Axes.findExtremes(sa,pts,{
569572
tozero:tozero,
570-
padded:true
573+
padded:true,
574+
ppad:textPadding
571575
});
572576
}
573577
}
574578

579+
// Very lightweight estimate of extra padding needed
580+
// to accommodate outside text labels on bars
581+
// Only considers vertical bars with 'outside' textposition for now
582+
// This solves the most common scenario of a simple vertical bar chart
583+
// with textposition set to 'outside'
584+
// More complex scenarios (horizontal bars, multi-line text labels)
585+
// are not (yet) handled here
586+
functionestimateExtraPaddingForText(trace){
587+
if(trace.orientation==='v'&&(trace.text||trace.texttemplate)&&trace.textposition=='outside'){
588+
// could count <br> elements here
589+
// but before that, need to make sure we are only
590+
// adding padding on the side(s) where it is needed
591+
returntrace.outsidetextfont.size+TEXTPAD;
592+
}
593+
return0;
594+
}
595+
575596
functionstackBars(sa,sieve,opts){
576597
varsLetter=getAxisLetter(sa);
577598
varcalcTraces=sieve.traces;
@@ -637,13 +658,16 @@ function stackBars(sa, sieve, opts) {
637658
}
638659
}
639660

661+
consttextPadding=estimateExtraPaddingForText(fullTrace);
662+
640663
// if barnorm is set, let normalizeBars update the axis range
641664
if(!opts.norm){
642665
fullTrace._extremes[sa._id]=Axes.findExtremes(sa,pts,{
643666
// N.B. we don't stack base with 'base',
644667
// so set tozero:true always!
645668
tozero:true,
646-
padded:true
669+
padded:true,
670+
ppad:textPadding
647671
});
648672
}
649673
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp