Skip to content

Commit

Permalink
Merge pull request #1618 from judocode/master
Browse files Browse the repository at this point in the history
fix: BarNote getSVGElement always returning undefined
  • Loading branch information
AaronDavidNewman committed Apr 20, 2024
2 parents 8ddc8fa + 44f769f commit c1d8ac2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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

0 comments on commit c1d8ac2

Please sign in to comment.