-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathuniform_text.js
78 lines (67 loc) · 2.02 KB
/
uniform_text.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict';
var d3 = require('@plotly/d3');
var Lib = require('../../lib');
function resizeText(gd, gTrace, traceType) {
var fullLayout = gd._fullLayout;
var minSize = fullLayout['_' + traceType + 'Text_minsize'];
if(minSize) {
var shouldHide = fullLayout.uniformtext.mode === 'hide';
var selector;
switch(traceType) {
case 'funnelarea' :
case 'pie' :
case 'sunburst' :
selector = 'g.slice';
break;
case 'treemap' :
case 'voronoi' :
case 'icicle' :
selector = 'g.slice, g.pathbar';
break;
default :
selector = 'g.points > g.point';
}
gTrace.selectAll(selector).each(function(d) {
var transform = d.transform;
if(transform) {
transform.scale = (shouldHide && transform.hide) ? 0 : minSize / transform.fontSize;
var el = d3.select(this).select('text');
Lib.setTransormAndDisplay(el, transform);
}
});
}
}
function recordMinTextSize(
traceType, // in
transform, // inout
fullLayout // inout
) {
if(fullLayout.uniformtext.mode) {
var minKey = getMinKey(traceType);
var minSize = fullLayout.uniformtext.minsize;
var size = transform.scale * transform.fontSize;
transform.hide = size < minSize;
fullLayout[minKey] = fullLayout[minKey] || Infinity;
if(!transform.hide) {
fullLayout[minKey] = Math.min(
fullLayout[minKey],
Math.max(size, minSize)
);
}
}
}
function clearMinTextSize(
traceType, // in
fullLayout // inout
) {
var minKey = getMinKey(traceType);
fullLayout[minKey] = undefined;
}
function getMinKey(traceType) {
return '_' + traceType + 'Text_minsize';
}
module.exports = {
recordMinTextSize: recordMinTextSize,
clearMinTextSize: clearMinTextSize,
resizeText: resizeText
};