digitaljs icon indicating copy to clipboard operation
digitaljs copied to clipboard

Allow customization of cell attributes

Open malmeloo opened this issue 1 year ago • 1 comments

Exposes a new constructor argument to HeadlessCircuit that allows customization of attributes for specific cells. These attributes extend or overwrite the attributes that are set by default for the various models.

As an example, the below code would make the fill color for all And gates light green:

const cellAttrs = {
    'And': {
        'body': {'fill': 'lightgreen'}
    }
}

const circuit = new digitaljs.Circuit(input, {cellAttributes: cellAttrs});

A current limitation of this feature is that it relies on the types as passed to the JointJS cells, which makes it more difficult to specify the attributes for specific Yosys prims (e.g. And instead of $and). It would be possible to split off the current lookup table used in getCellType, but another solution (which I would prefer) is to convert the current .define('type', ...) structures into proper class inheritance, similar to what the tutorial does here. That would allow users to get the type using getCellType(...).type, and even allow getting rid of that lookup table altogether by making the Yosys primitive a static field on the models.

Let me know what you think 🙂

malmeloo avatar Jan 10 '24 23:01 malmeloo

I've just pushed a commit that implements the first solution to the limitation discussed above. That allows for the following syntax:

const cellAttrs = {
    [digitaljs.getCellTypeStr('$and')]: {
        'body': {'fill': 'lightgreen'}
    }
}

malmeloo avatar Jan 11 '24 10:01 malmeloo