Skip to content

Commit

Permalink
fix(tooltip): Fix handling on color tile (#875)
Browse files Browse the repository at this point in the history
Fix issue caused by #816.

Ref #816
  • Loading branch information
netil committed May 9, 2019
1 parent 316e2f7 commit 56c2f99
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions spec/internals/tooltip-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,5 +762,45 @@ describe("TOOLTIP", function() {

expect(d3.select("#tooltip").html()).to.be.equal(html);
});

it("set options color.tiles", () => {
delete args.data.colors;
delete args.tooltip.contents;

args.color = {
tiles: function() {
var pattern = d3.select(document.createElementNS(d3.namespaces.svg, "pattern"))
.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()
];
}
}
});

it("check for color tiled tooltip", () => {
const id = chart.data().map(v => v.id);

// when
chart.tooltip.show({x:0});

chart.$.tooltip.selectAll(".name").each(function(d, i) {
expect(/^<svg>(.*)<\/svg>$/.test(this.innerHTML.replace(id[i], ""))).to.be.true;
});
});
});
});
2 changes: 1 addition & 1 deletion src/internals/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ extend(ChartInternal.prototype, {
return (tplStr || `<table class="{=CLASS_TOOLTIP}"><tbody>
{=TITLE}
{{<tr class="{=CLASS_TOOLTIP_NAME}">
<td class="name"><span style="background-color:{=COLOR}"></span>{=NAME}</td>
<td class="name">${this.patterns ? `{=COLOR}` : `<span style="background-color:{=COLOR}"></span>`}{=NAME}</td>
<td class="value">{=VALUE}</td>
</tr>}}
</tbody></table>`)
Expand Down

0 comments on commit 56c2f99

Please sign in to comment.