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

fix: BarNote getSVGElement always returning undefined #1618

Merged
merged 3 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 9 additions & 3 deletions src/barnote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class BarNote extends Note {
protected metrics: { widths: Record<string, number> };
// Initialized by the constructor via this.setType(type)
protected type!: BarlineType;
public barline!: Barline;

constructor(type: string | BarlineType = BarlineType.SINGLE) {
super({ duration: 'b' });
Expand All @@ -52,6 +53,7 @@ export class BarNote extends Note {
// Tell the formatter that bar notes have no duration.
this.ignore_ticks = true;
this.setType(type);
this.barline = new Barline(type);
}

/** Get the type of bar note.*/
Expand Down Expand Up @@ -86,9 +88,13 @@ export class BarNote extends Note {
const ctx = this.checkContext();
L('Rendering bar line at: ', this.getAbsoluteX());
this.applyStyle(ctx);
const barline = new Barline(this.type);
barline.setX(this.getAbsoluteX());
barline.draw(this.checkStave());

ctx.openGroup('barnote', this.getAttribute('id'));
this.barline.setType(this.type);
this.barline.setX(this.getAbsoluteX());
this.barline.draw(this.checkStave());
ctx.closeGroup();

this.restoreStyle(ctx);
this.setRendered();
}
Expand Down
7 changes: 7 additions & 0 deletions tests/barline_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { TestOptions, VexFlowTests } from './vexflow_test_helpers';

import { Renderer } from '../src';
import { Barline, BarlineType } from '../src/stavebarline';

const BarlineTests = {
Expand Down Expand Up @@ -44,6 +45,12 @@ function simple(options: TestOptions): void {
f.Formatter().joinVoices([voice]).formatToStave([voice], stave);
f.draw();

if (options.backend === Renderer.Backends.SVG) {
notes.forEach((note) => {
options.assert.notEqual(note.getSVGElement(), undefined);
});
}

options.assert.ok(true, 'Simple Test');
}

Expand Down
Loading