Skip to content

Commit

Permalink
fix(tooltip): Correct condition of making tooltip text
Browse files Browse the repository at this point in the history
Update condition of making the beginning of tooltip text to avoid it
being left undefined

Fix #940
Close #941
  • Loading branch information
soyme authored and netil committed Jun 20, 2019
1 parent cdd8277 commit c0df6c5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
32 changes: 29 additions & 3 deletions spec/internals/tooltip-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,32 @@ describe("TOOLTIP", function() {
});
});

describe("tooltip for null data", () => {
before(() => {
args = {
data: {
columns: [
["data1", 10, null],
["data2", null, 20]
]
}
};
});

it("check when first data is null", () => {
chart.tooltip.show({x:1});

expect(chart.$.tooltip.html()).to.be.equal(
`<table class="bb-tooltip"><tbody><tr><th colspan="2">1</th></tr>
<tr class="bb-tooltip-name-data2">
<td class="name"><span style="background-color:#fa7171"></span>data2</td>
<td class="value">20</td>
</tr>
</tbody></table>`.replace(/[\r\n\t]/g, "")
);
});
});

describe("tooltip for dynamic loaded data", () => {
before(() => {
args = {
Expand Down Expand Up @@ -773,17 +799,17 @@ describe("TOOLTIP", function() {
.attr("patternUnits", "userSpaceOnUse")
.attr("width", "6")
.attr("height", "6");

var g = pattern
.append("g")
.attr("fill-rule", "evenodd")
.attr("stroke-width", 1)
.append("g")
.attr("fill", "rgb(255, 127, 14)");

g.append("polygon").attr("points", "5 0 6 0 0 6 0 5");
g.append("polygon").attr("points", "6 5 6 6 5 6");

// Should return an array of SVGPatternElement
return [
pattern.node()
Expand Down
4 changes: 2 additions & 2 deletions src/internals/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "d3-selection";
import ChartInternal from "./ChartInternal";
import CLASS from "../config/classes";
import {extend, isFunction, isObject, isString, isValue, callFn, sanitise, tplProcess} from "./util";
import {extend, isFunction, isObject, isString, isValue, callFn, sanitise, tplProcess, isUndefined} from "./util";

extend(ChartInternal.prototype, {
/**
Expand Down Expand Up @@ -142,7 +142,7 @@ extend(ChartInternal.prototype, {
continue;
}

if (i === 0) {
if (isUndefined(text)) {
const title = sanitise(titleFormat ? titleFormat(row.x) : row.x);

text = tplProcess(tpl[0], {
Expand Down

0 comments on commit c0df6c5

Please sign in to comment.