bbc / peaks.js

JavaScript UI component for interacting with audio waveforms
https://waveform.prototyping.bbc.co.uk
GNU Lesser General Public License v3.0
3.2k stars 279 forks source link

Additional attributes to the Segment object #336

Closed msjaber closed 4 years ago

msjaber commented 4 years ago

Hey,

Is it possible to add additional attributes to the Segment object?

{
    startTime: 1,
    endTime: 3,
    editable: true,
    color: "#ff0000",
    labelText: "My label",
    foo: "bar",  // additional attributes
}

If no, can I make a pull request for it?

My use case is that I wanna add an attribute of shouldSkip, and listen to the cue events in order to behave based on the attribute's value.

Thanks

chrisn commented 4 years ago

This is currently not possible, but I think it should be. I'll have a look into it, as implementing this will require some changes to the way the point/segment attributes are handled.

chrisn commented 4 years ago

Please take a look at the segment-attributes branch. You can now set custom attributes using peaks.segments.add() and segment.update():

peaks.segments.add({
  startTime: 1,
  endTime: 3,
  editable: true,
  color: "#ff0000",
  labelText: "My label",
  foo: "bar"  // additional attributes
});

segment.update({ foo: "baz" });
msjaber commented 4 years ago

Thank you so much @chrisn! 🙏🏻

It works perfectly.

chrisn commented 4 years ago

Thank you :-) I'll merge this and publish a new release to npm.