Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add className option for marks #1098

Merged
merged 9 commits into from
Jul 3, 2024
Next Next commit
add className to style options
RLesser committed Oct 22, 2022
commit 7a01a34539b06751f3fcc0de74780d119281dfb4
3 changes: 2 additions & 1 deletion src/plot.js
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ import {
} from "./options.js";
import {Scales, ScaleFunctions, autoScaleRange, exposeScales} from "./scales.js";
import {position, registry as scaleRegistry} from "./scales/index.js";
import {applyInlineStyles, maybeClassName, maybeClip, styles} from "./style.js";
import {applyInlineStyles, maybeClassName, maybeClassNameOptional, maybeClip, styles} from "./style.js";
import {basic, initializer} from "./transforms/basic.js";
import {maybeInterval} from "./transforms/interval.js";
import {consumeWarnings, warn} from "./warnings.js";
@@ -683,6 +683,7 @@ export class Mark {
this.dx = +dx || 0;
this.dy = +dy || 0;
this.clip = maybeClip(clip);
this.className = maybeClassNameOptional(options.className);
}
initialize(facets, facetChannels) {
let data = arrayify(this.data);
5 changes: 5 additions & 0 deletions src/style.js
Original file line number Diff line number Diff line change
@@ -297,6 +297,7 @@ export function applyIndirectStyles(selection, mark, scales, dimensions) {
applyAttr(selection, "aria-label", mark.ariaLabel);
applyAttr(selection, "aria-description", mark.ariaDescription);
applyAttr(selection, "aria-hidden", mark.ariaHidden);
applyAttr(selection, "class", mark.className);
applyAttr(selection, "fill", mark.fill);
applyAttr(selection, "fill-opacity", mark.fillOpacity);
applyAttr(selection, "stroke", mark.stroke);
@@ -378,6 +379,10 @@ export function maybeClassName(name) {
return name;
}

export function maybeClassNameOptional(name) {
return name === undefined ? undefined : maybeClassName(name);
}

export function applyInlineStyles(selection, style) {
if (typeof style === "string") {
selection.property("style", style);