Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions src/legends/swatches.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {path} from "d3";
import {inferFontVariant} from "../axes.js";
import {maybeAutoTickFormat} from "../axis.js";
import {Context, create} from "../context.js";
import {isNoneish, maybeColorChannel, maybeNumberChannel} from "../options.js";
import {isOrdinalScale, isThresholdScale} from "../scales.js";
import {applyInlineStyles, impliedString, maybeClassName} from "../style.js";
import { path } from "d3";
import { inferFontVariant } from "../axes.js";
import { maybeAutoTickFormat } from "../axis.js";
import { Context, create } from "../context.js";
import { isNoneish, maybeColorChannel, maybeNumberChannel } from "../options.js";
import { isOrdinalScale, isThresholdScale } from "../scales.js";
import { applyInlineStyles, impliedString, maybeClassName } from "../style.js";

function maybeScale(scale, key) {
if (key == null) return key;
Expand Down Expand Up @@ -88,6 +88,9 @@ function legendItems(scale, options = {}, swatch, swatchStyle) {
swatchSize = 15,
swatchWidth = swatchSize,
swatchHeight = swatchSize,
marginTop = 0,
marginRight = 0,
marginBottom = 0,
marginLeft = 0,
className,
style,
Expand Down Expand Up @@ -170,18 +173,22 @@ function legendItems(scale, options = {}, swatch, swatchStyle) {
div.insert("style", "*").text(`
.${className} {
font-family: system-ui, sans-serif;
font-size: 10px;
margin-bottom: 0.5em;${
marginLeft === undefined
? ""
: `
margin-left: ${+marginLeft}px;`
}${
width === undefined
font-size: 10px;${marginTop === undefined
? ""
: `
width: ${width}px;`
}
: `margin-top: ${+marginTop}px;`
}${marginRight === undefined
? ""
: `margin-right: ${+marginRight}px;`
}${marginBottom === undefined
? `margin-bottom: 0.5em;`
: `margin-bottom: ${+marginBottom}px;`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this mix seems like a problem, not sure how to unify that properly. Should we default to the equivalent number of pixels, on line 93?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated it to default to 8px which should be the equivalent. What do you think?

}${marginLeft === undefined
? ""
: `margin-left: ${+marginLeft}px;`
}${width === undefined
? ""
: `width: ${width}px;`
}
}
${swatchStyle(className)}
${extraStyle}
Expand Down