Skip to content

Commit f5c6f47

Browse files
authored
Merge pull request #6038 from plotly/histogram-text
New attributes to display text on the `histogram` trace
2 parents de1664b + c8f9f73 commit f5c6f47

21 files changed

+225
-3
lines changed

draftlogs/6038_add.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Add `texttemplate`, `textposition`, `textfont`, `textangle`,
2+
`outsidetextfont`, `insidetextfont`, `insidetextanchor`,
3+
`constraintext` and `cliponaxis` to `histogram` trace [[#6038](https://github.com/plotly/plotly.js/pull/6038)]

src/traces/bar/plot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, opts, makeOnCom
428428
}
429429

430430
transform.fontSize = font.size;
431-
recordMinTextSize(trace.type, transform, fullLayout);
431+
recordMinTextSize(trace.type === 'histogram' ? 'bar' : trace.type, transform, fullLayout);
432432
calcBar.transform = transform;
433433

434434
transition(textSelection, fullLayout, opts, makeOnCompleteCallback)

src/traces/histogram/attributes.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
var barAttrs = require('../bar/attributes');
44
var axisHoverFormat = require('../../plots/cartesian/axis_format_attributes').axisHoverFormat;
55
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
6+
var texttemplateAttrs = require('../../plots/template_attributes').texttemplateAttrs;
7+
var fontAttrs = require('../../plots/font_attributes');
68
var makeBinAttrs = require('./bin_attributes');
79
var constants = require('./constants');
810
var extendFlat = require('../../lib/extend').extendFlat;
@@ -198,6 +200,44 @@ module.exports = {
198200
keys: constants.eventDataKeys
199201
}),
200202

203+
texttemplate: texttemplateAttrs({
204+
arrayOk: false,
205+
editType: 'plot'
206+
}, {
207+
keys: ['label', 'value']
208+
}),
209+
210+
textposition: extendFlat({}, barAttrs.textposition, {
211+
arrayOk: false
212+
}),
213+
214+
textfont: fontAttrs({
215+
arrayOk: false,
216+
editType: 'plot',
217+
colorEditType: 'style',
218+
description: 'Sets the text font.'
219+
}),
220+
221+
outsidetextfont: fontAttrs({
222+
arrayOk: false,
223+
editType: 'plot',
224+
colorEditType: 'style',
225+
description: 'Sets the font used for `text` lying outside the bar.'
226+
}),
227+
228+
insidetextfont: fontAttrs({
229+
arrayOk: false,
230+
editType: 'plot',
231+
colorEditType: 'style',
232+
description: 'Sets the font used for `text` lying inside the bar.'
233+
}),
234+
235+
insidetextanchor: barAttrs.insidetextanchor,
236+
237+
textangle: barAttrs.textangle,
238+
cliponaxis: barAttrs.cliponaxis,
239+
constraintext: barAttrs.constraintext,
240+
201241
marker: barAttrs.marker,
202242

203243
offsetgroup: barAttrs.offsetgroup,

src/traces/histogram/defaults.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var Registry = require('../../registry');
44
var Lib = require('../../lib');
55
var Color = require('../../components/color');
66

7+
var handleText = require('../bar/defaults').handleText;
78
var handleStyleDefaults = require('../bar/style_defaults');
89
var attributes = require('./attributes');
910

@@ -22,6 +23,16 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2223
}
2324

2425
coerce('text');
26+
var textposition = coerce('textposition');
27+
handleText(traceIn, traceOut, layout, coerce, textposition, {
28+
moduleHasSelected: true,
29+
moduleHasUnselected: true,
30+
moduleHasConstrain: true,
31+
moduleHasCliponaxis: true,
32+
moduleHasTextangle: true,
33+
moduleHasInsideanchor: true
34+
});
35+
2536
coerce('hovertext');
2637
coerce('hovertemplate');
2738
coerce('xhoverformat');
3.47 KB
Loading
2.41 KB
Loading
2.73 KB
Loading

test/image/baselines/hist_stacked.png

4.32 KB
Loading

test/image/baselines/hist_summed.png

3.46 KB
Loading
-16.6 KB
Loading

0 commit comments

Comments
 (0)