Code:
Ext.define('mypatch', {
override: 'Ext.chart.series.Column',
onPlaceLabel: function(label, storeItem, item, i, display, animate, j, index) {
// Determine the label's final position. Starts with the configured preferred value but
// may get flipped from inside to outside or vice-versa depending on space.
var me = this,
opt = me.bounds,
groupBarWidth = opt.groupBarWidth,
column = me.column,
chart = me.chart,
chartBBox = chart.chartBBox,
resizing = chart.resizing,
xValue = item.value[0],
yValue = item.value[1],
attr = item.attr,
config = me.label,
rotate = config.orientation == 'vertical',
field = [].concat(config.field),
renderer = [].concat(config.renderer),
format = config.renderer[index],
text = format(storeItem.get(field[index])),
size = me.getLabelSize(text),
width = size.width,
height = size.height,
zero = opt.zero,
outside = 'outside',
insideStart = 'insideStart',
insideEnd = 'insideEnd',
offsetX = 10,
offsetY = 6,
signed = opt.signed,
x, y, finalAttr;
label.setAttributes({
text: text
});
label.isOutside = false;
if (column) {
if (display == outside) {
if (height + offsetY + attr.height > (yValue >= 0 ? zero - chartBBox.y : chartBBox.y + chartBBox.height - zero)) {
display = insideEnd;
}
} else {
if (height + offsetY > attr.height) {
display = outside;
label.isOutside = true;
}
}
x = attr.x + groupBarWidth / 2;
y = display == insideStart ?
(zero + ((height / 2 + 3) * (yValue >= 0 ? -1 : 1))) :
(yValue >= 0 ? (attr.y + ((height / 2 + 3) * (display == outside ? -1 : 1))) :
(attr.y + attr.height + ((height / 2 + 3) * (display === outside ? 1 : -1))));
}
else {
if (display == outside) {
if (width + offsetX + attr.width > (yValue >= 0 ? chartBBox.x + chartBBox.width - zero : zero - chartBBox.x)) {
display = insideEnd;
}
}
else {
if (width + offsetX > attr.width) {
display = outside;
label.isOutside = true;
}
}
x = display == insideStart ?
(zero + ((width / 2 + 5) * (yValue >= 0 ? 1 : -1))) :
(yValue >= 0 ? (attr.x + attr.width + ((width / 2 + 5) * (display === outside ? 1 : -1))) :
(attr.x + ((width / 2 + 5) * (display === outside ? -1 : 1))));
y = attr.y + groupBarWidth / 2;
}
//set position
finalAttr = {
x: x,
y: y
};
//rotate
if (rotate) {
finalAttr.rotate = {
x: x,
y: y,
degrees: 270
};
}
//check for resizing
if (animate && resizing) {
if (column) {
x = attr.x + attr.width / 2;
y = zero;
} else {
x = zero;
y = attr.y + attr.height / 2;
}
label.setAttributes({
x: x,
y: y
}, true);
if (rotate) {
label.setAttributes({
rotate: {
x: x,
y: y,
degrees: 270
}
}, true);
}
}
//handle animation
if (animate) {
me.onAnimate(label, { to: finalAttr });
}
else {
label.setAttributes(Ext.apply(finalAttr, {
hidden: false
}), true);
}
}
})