Skip to content

Commit

Permalink
Replace label_delimiter with label_style #120
Browse files Browse the repository at this point in the history
  • Loading branch information
mph- committed Dec 29, 2023
1 parent adf37e1 commit 25bbb2c
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 33 deletions.
File renamed without changes
2 changes: 2 additions & 0 deletions doc/examples/schematics/label_aligned.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
R1 1 2 10; right
; label_style=aligned
2 changes: 0 additions & 2 deletions doc/examples/schematics/label_delimiter1.sch

This file was deleted.

2 changes: 0 additions & 2 deletions doc/examples/schematics/label_delimiter2.sch

This file was deleted.

2 changes: 0 additions & 2 deletions doc/examples/schematics/label_delimiter3.sch

This file was deleted.

Binary file added doc/examples/schematics/label_name.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions doc/examples/schematics/label_name.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
R1 1 2 10; right
; label_style=name
File renamed without changes
2 changes: 2 additions & 0 deletions doc/examples/schematics/label_split.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
R1 1 2 10; right
; label_style=split
File renamed without changes
2 changes: 2 additions & 0 deletions doc/examples/schematics/label_stacked.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
R1 1 2 10; right
; label_style=stacked
Binary file added doc/examples/schematics/label_value.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions doc/examples/schematics/label_value.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
R1 1 2 10; right
; label_style=value
46 changes: 32 additions & 14 deletions doc/schematics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1423,26 +1423,44 @@ Label formatting

Component labels are comprised of a component name and a component value. If the names are the same, the component value is not shown. Display of the component name is controlled by the `label_ids` attribute and display of the component value is controlled by the `label_values` attribute.

If both the component name and component value are displayed, they are separated by the `label_delimiter` attribute. This can be any string and defaults to '='. For example:
There are several label formatting styles controlled by the
`label_style` attribute:

.. literalinclude:: examples/schematics/label_delimiter1.sch
- 'aligned': The component name and component value are separated by
'=':

.. image:: examples/schematics/label_delimiter1.png
:width: 3cm
.. literalinclude:: examples/schematics/label_aligned.sch

The component name and value can be stacked using '\\\\' as the delimiter, for example:
.. image:: examples/schematics/label_aligned.png
:width: 2.5cm

.. literalinclude:: examples/schematics/label_delimiter3.sch
- 'stacked': The component name is displayed above the component value:

.. image:: examples/schematics/label_delimiter3.png
:width: 3cm
.. literalinclude:: examples/schematics/label_stacked.sch

The component name and value can be displayed on either side of the component using the 'a' (annotate) delimiter, for example,
.. image:: examples/schematics/label_stacked.png
:width: 2.5cm

.. literalinclude:: examples/schematics/label_delimiter2.sch
- 'split': The component name and value are displayed on either side of the component using the 'split' style:

.. image:: examples/schematics/label_delimiter2.png
:width: 3cm
.. literalinclude:: examples/schematics/label_split.sch

.. image:: examples/schematics/label_split.png
:width: 2.5cm

- 'name': Only the component name is displayed:

.. literalinclude:: examples/schematics/label_name.sch

.. image:: examples/schematics/label_name.png
:width: 2.5cm

- 'value': Only the component value is displayed.

.. literalinclude:: examples/schematics/label_value.sch

.. image:: examples/schematics/label_value.png
:width: 2.5cm

The component name and value can be overridden with the 'l' attribute.

Expand All @@ -1459,14 +1477,14 @@ component and the voltage label is placed above the component, for example:
.. literalinclude:: examples/schematics/labels_loop.sch

.. image:: examples/schematics/labels_loop.png
:width: 3cm
:width: 4cm

This labels position be swapped using the `label_flip` attribute, for example:

.. literalinclude:: examples/schematics/labels_loop_flip.sch

.. image:: examples/schematics/labels_loop_flip.png
:width: 3cm
:width: 4cm

The annotation label is placed on the other side of the component to the component label. However, this can conflict with the voltage label.

Expand Down
3 changes: 2 additions & 1 deletion lcapy/schematic.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self):
{'draw_nodes': 'primary',
'label_values': True,
'label_ids': True,
'label_delimiter': '=',
'label_style': 'aligned',
'label_flip': False,
'annotate_values': False,
'label_nodes': 'primary',
Expand Down Expand Up @@ -633,6 +633,7 @@ def draw(self, filename=None, **kwargs):
'label_ids': True to show component ids
'label_values': True to display component values
'label_delimiter': Delimiter between component name and value
'label_flip': Place label on other side of component
'annotate_values': True to display component values as separate label
'draw_nodes': True to show all nodes,
False or 'none' to show no nodes,
Expand Down
27 changes: 18 additions & 9 deletions lcapy/schemcpts.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class Cpt(object):
'mirrorinputs', 'autoground', 'xoffset', 'yoffset',
'anchor', 'def', 'nodes')
label_opt_keys = ('label_values', 'label_ids', 'annotate_values',
'label_delimiter', 'label_flip')
'label_style', 'label_flip')

all_label_keys = voltage_keys + current_keys + flow_keys + \
label_keys + label2_keys + inner_label_keys + \
Expand Down Expand Up @@ -1581,24 +1581,33 @@ def label_make(self, **kwargs):
label = None
annotation = None

# TODO merge with label

label_values = check_boolean(kwargs.get('label_values', True))
label_ids = check_boolean(kwargs.get('label_ids', True))
annotate_values = check_boolean(kwargs.get('annotate_values', False))
delimiter = kwargs.get('label_delimiter', '=')
style = kwargs.get('label_style', '=')

if style == 'stacked':
delimiter = '\\\\'
elif style == 'aligned':
delimiter = '='
elif style == 'split':
pass
elif style == 'name':
label_ids = True
label_values = False
elif style == 'value':
label_ids = False
label_values = True
else:
raise ValueError('Unknown label_style ' + style)

id_label = latex_format_label(self.id_label)
value_label = latex_format_label(self.value_label)

# Avoid unexpected behaviour
if delimiter == '\\':
delimiter = '\\\\'

# Generate default label.
if (label_ids and label_values and id_label != ''
and value_label != '' and id_label != value_label):
if annotate_values or delimiter == 'a':
if annotate_values or style == 'split':
label = Label('l', id_label)
annotation = Label('a', value_label)
else:
Expand Down
6 changes: 3 additions & 3 deletions lcapy/scripts/schtex.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def main(argv=None):
dest='label_values', default=None,
help="label values")

parser.add_argument('--label-delimiter', type=str,
parser.add_argument('--label-style', type=str,
default=None,
help='delimiter between component name and value')
help='label style: aligned, stacked, split, value, or name')

parser.add_argument('--label-flip', action='store_true',
dest='label_flip', default=None,
Expand Down Expand Up @@ -286,7 +286,7 @@ def main(argv=None):
draw_nodes=args.draw_nodes,
label_ids=args.label_ids,
label_values=args.label_values,
label_delimiter=args.label_delimiter,
label_style=args.label_style,
label_flip=args.label_flip,
autoground=args.autoground,
annotate_values=args.annotate_values,
Expand Down

0 comments on commit 25bbb2c

Please sign in to comment.