Skip to content

Commit

Permalink
Fix legend display issue
Browse files Browse the repository at this point in the history
  • Loading branch information
timqian committed Dec 2, 2023
1 parent 1e0013b commit c6b3aaa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chart.xkcd",
"version": "1.1.14",
"version": "1.1.15",
"description": "xkcd style chart lib",
"jsdelivr": "dist/chart.xkcd.min.js",
"unpkg": "dist/chart.xkcd.min.js",
Expand Down
11 changes: 7 additions & 4 deletions src/utils/addLegend.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config from '../config';

export default function addLegend(parent, {
export default async function addLegend(parent, {
items, position, unxkcdify, parentWidth, parentHeight, strokeColor, backgroundColor,
}) {
const filter = !unxkcdify ? 'url(#xkcdify)' : null;
Expand Down Expand Up @@ -28,6 +28,9 @@ export default function addLegend(parent, {
.text(item.text);
});

// wait for textLayer to render, a bit wired
await new Promise(resolve => setTimeout(resolve, 10))

const bbox = textLayer.node().getBBox();
const backgroundWidth = bbox.width + 15;
const backgroundHeight = bbox.height + 10;
Expand All @@ -50,14 +53,14 @@ export default function addLegend(parent, {
// add background
backgroundLayer.append('rect')
.style('fill', backgroundColor)
.attr('filter', filter)
.attr('fill-opacity', 0.85)
.attr('stroke', strokeColor)
.attr('stroke-width', 2)
.attr('rx', 5)
.attr('ry', 5)
.attr('filter', filter)
.attr('width', backgroundWidth)
.attr('height', backgroundHeight)
.attr('rx', 5)
.attr('ry', 5)
.attr('x', 8)
.attr('y', 5);

Expand Down

0 comments on commit c6b3aaa

Please sign in to comment.