Skip to content

Commit 4e90c19

Browse files
committed
fix(cli): Add a feature flag to specify both text and color attributes
1 parent 91ade95 commit 4e90c19

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

honeybee_display/cli/__init__.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,17 @@ def display():
7272
'one another. For example, properties.energy.construction.',
7373
type=click.STRING, multiple=True, default=None, show_default=True)
7474
@click.option(
75-
'--color-attr/--text-attr', help='Flag to note whether to note whether the '
76-
'input room-attr and face-attr should be expressed as a colored AnalysisGeometry '
77-
'or a ContextGeometry as text labels.', default=True, show_default=True)
75+
'--color-attr', 'attr_display', flag_value='color', help='Flag to note whether the '
76+
'input room-attr and face-attr should be expressed as a colored AnalysisGeometry.',
77+
default=True, show_default=True)
78+
@click.option(
79+
'--text-attr', 'attr_display', flag_value='text', help='Flag to note whether the '
80+
'input room-attr and face-attr should be expressed as a ContextGeometry with '
81+
'text labels.')
82+
@click.option(
83+
'--both-attr', 'attr_display', flag_value='both', help='Flag to note whether the '
84+
'input room-attr and face-attr should be expressed as both a colored AnalysisGeometry '
85+
'and a ContextGeometry with text labels.')
7886
@click.option(
7987
'--grid-display-mode', '-m', help='Text that dictates how the ContextGeometry '
8088
'for Model SensorGrids should display in the resulting visualization. The Default '
@@ -127,7 +135,7 @@ def display():
127135
type=click.File('w'), default='-', show_default=True)
128136
def model_to_vis_set_cli(
129137
model_file, color_by, wireframe, mesh, show_color_by,
130-
room_attr, face_attr, color_attr, grid_display_mode, hide_grid,
138+
room_attr, face_attr, attr_display, grid_display_mode, hide_grid,
131139
grid_data, grid_data_display_mode, active_grid_data, output_format, output_file):
132140
"""Translate a Honeybee Model file (.hbjson) to a VisualizationSet file (.vsf).
133141
@@ -145,14 +153,19 @@ def model_to_vis_set_cli(
145153
hide_color_by = not show_color_by
146154
room_attrs = [] if len(room_attr) == 0 or room_attr[0] == '' else room_attr
147155
face_attrs = [] if len(face_attr) == 0 or face_attr[0] == '' else face_attr
148-
text_labels = not color_attr
149156
show_grid = not hide_grid
157+
if attr_display == 'color':
158+
color_attr, text_attr, both_attr = True, False, False
159+
elif attr_display == 'text':
160+
color_attr, text_attr, both_attr = False, True, False
161+
elif attr_display == 'both':
162+
color_attr, text_attr, both_attr = False, False, True
150163

151164
# pass the input to the function in order to convert the model to a visualization
152165
model_to_vis_set(model_file, color_by, exclude_wireframe, faces, hide_color_by,
153-
room_attrs, face_attrs, text_labels, grid_display_mode,
166+
room_attrs, face_attrs, text_attr, both_attr, grid_display_mode,
154167
show_grid, grid_data, grid_data_display_mode, active_grid_data,
155-
output_format, output_file)
168+
output_format, output_file, color_attr=color_attr)
156169
except Exception as e:
157170
_logger.exception('Failed to translate Model to VisualizationSet.\n{}'.format(e))
158171
sys.exit(1)
@@ -163,9 +176,10 @@ def model_to_vis_set_cli(
163176
def model_to_vis_set(
164177
model_file, color_by='type',
165178
exclude_wireframe=False, faces=False, hide_color_by=False,
166-
room_attr=(), face_attr=(), text_attr=False, grid_display_mode='Default',
167-
show_grid=False, grid_data=None, grid_data_display_mode='Surface',
168-
active_grid_data=None, output_format='vsf', output_file=None,
179+
room_attr=(), face_attr=(), text_attr=False, both_attr=False,
180+
grid_display_mode='Default', show_grid=False, grid_data=None,
181+
grid_data_display_mode='Surface', active_grid_data=None,
182+
output_format='vsf', output_file=None,
169183
wireframe=True, mesh=True, show_color_by=True, color_attr=True, hide_grid=True
170184
):
171185
"""Translate a Honeybee Model file (.hbjson) to a VisualizationSet file (.vsf).
@@ -211,8 +225,10 @@ def model_to_vis_set(
211225
here can have . that separates the nested attributes from one another.
212226
For example, properties.energy.construction.
213227
text_attr: Boolean to note whether to note whether the input room_attr
214-
and face_attr should be expressed as a colored AnalysisGeometry
215-
or a ContextGeometry as text labels.
228+
and face_attr should be expressed as a ContextGeometry with text labels.
229+
both_attr: Boolean to note whether to note whether the input room_attr
230+
and face_attr should be expressed as both a colored AnalysisGeometry
231+
and a ContextGeometry as text labels.
216232
grid_display_mode: Text that dictates how the ContextGeometry for Model
217233
SensorGrids should display in the resulting visualization. The Default
218234
option will draw sensor points whenever there is no grid_data_path
@@ -263,10 +279,13 @@ def model_to_vis_set(
263279
face_attrs = [face_attr] if isinstance(face_attr, str) else face_attr
264280
wireframe = not exclude_wireframe
265281
mesh = not faces
266-
color_attr = not text_attr
267282
hide_grid = not show_grid
268283

269284
# load the room and face attributes
285+
if both_attr:
286+
color_attr, text_attr = True, True
287+
elif text_attr:
288+
color_attr = False
270289
face_attributes = []
271290
for fa in face_attrs:
272291
faa = FaceAttribute(name=fa, attrs=[fa], color=color_attr, text=text_attr)

0 commit comments

Comments
 (0)