Skip to content

Commit 77e26af

Browse files
committedDec 10, 2019
fix(core): fix to allow chart to toggle on and off using attribute/css properties
1 parent d7860af commit 77e26af

File tree

1 file changed

+16
-8
lines changed
  • packages/core/src/components/essentials

1 file changed

+16
-8
lines changed
 

‎packages/core/src/components/essentials/title.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ export class Title extends Component {
1010
* Truncates title creating ellipses and attaching tooltip for exposing full title.
1111
*/
1212
truncateTitle() {
13-
const containerWidth = DOMUtils.getSVGElementSize(this.parent).width;
14-
const title = DOMUtils.appendOrSelect(this.parent, "text.title");
13+
// get a reference to the title elements to calculate the size the title can be
14+
const containerBounds = DOMUtils.getSVGElementSize(this.parent, { useAttr: true });
15+
// need to check if the width is 0, and try to use the parent attribute (getSVGElement wont validate if height: 0)
16+
const containerWidth = containerBounds.width ? containerBounds.width : this.parent.node().getAttribute("width");
17+
const title = DOMUtils.appendOrSelect(this.parent, "text.title");
18+
19+
// sanity check to prevent stack overflow on binary search
20+
if (containerWidth <= 0) {
21+
return;
22+
}
1523

1624
// check if the title is too big for the containing svg
1725
if (title.node().getComputedTextLength() > containerWidth) {
@@ -35,17 +43,17 @@ export class Title extends Component {
3543

3644
// add events for displaying the tooltip with the title
3745
const self = this;
38-
title.on("mouseenter", function() {
46+
title.on("mouseenter", function () {
3947
self.services.events.dispatchEvent("show-tooltip", {
4048
hoveredElement: title,
4149
type: TooltipTypes.TITLE
4250
});
4351
})
44-
.on("mouseout", function() {
45-
self.services.events.dispatchEvent("hide-tooltip", {
46-
hoveredElement: title,
52+
.on("mouseout", function () {
53+
self.services.events.dispatchEvent("hide-tooltip", {
54+
hoveredElement: title,
55+
});
4756
});
48-
});
4957
}
5058
}
5159

@@ -77,7 +85,7 @@ export class Title extends Component {
7785
* @param width the width of the svg container that holds the title
7886
*/
7987
protected getSubstringIndex(title, start, end, width) {
80-
const mid = Math.floor((end + start) / 2);
88+
const mid = Math.floor((end + start) / 2);
8189
if (title.getSubStringLength(0, mid) > width) {
8290
return this.getSubstringIndex(title, start, mid, width);
8391
} else if (title.getSubStringLength(0, mid) < width) {

0 commit comments

Comments
 (0)
Please sign in to comment.