Justin808
Justin808

Reputation: 21522

How do I add a class to a Rect in bonsaijs?

I need to add a class to a Rect. I can't seem to figure out how to do it.

bar = (new Rect(x, ySegment * 10 + 30 + margin, w, 0)
                    .attr('opacity', 0.8)
                    .attr('class', data[i].segments[j].color)
                    .addTo(stage));

the class attr is ignored.

Upvotes: 0

Views: 98

Answers (1)

basecode
basecode

Reputation: 1510

A DisplayObject like Rect isn't the representation of an HTMLElement. That's why custom attributes like "class" don't work. If your intention is to re-use attributes for different DisplayObjects, then try the following:

var myAttrs = {
  fillColor: 'red',
  opacity: 0.5
};

new Rect(20, 20, 100, 100).attr(myAttrs).addTo(stage);
new Rect(20, 130, 100, 100).attr(myAttrs).addTo(stage);

Play with it here: Orbit

Upvotes: 1

Related Questions