Skip to content

Commit

Permalink
fix(visualize): Update MonthlyChart for new stacked line visual
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey committed Jun 2, 2024
1 parent 29829b6 commit 169c6bf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ladybug_grasshopper/json/LB_Monthly_Chart.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.0",
"version": "1.8.2",
"nickname": "MonthlyChart",
"outputs": [
[
Expand Down Expand Up @@ -141,7 +141,7 @@
}
],
"subcategory": "2 :: Visualize Data",
"code": "\ntry:\n from ladybug_geometry.geometry2d.pointvector import Point2D\n from ladybug_geometry.geometry3d.pointvector import Vector3D, Point3D\n from ladybug_geometry.geometry3d.plane import Plane\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_geometry:\\n\\t{}'.format(e))\n\ntry:\n from ladybug.monthlychart import MonthlyChart\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.config import conversion_to_meters, tolerance\n from ladybug_{{cad}}.color import color_to_color\n from ladybug_{{cad}}.togeometry import to_point2d\n from ladybug_{{cad}}.fromgeometry import from_mesh2d, from_mesh2d_to_outline, \\\n from_polyline2d, from_linesegment2d\n from ladybug_{{cad}}.text import text_objects\n from ladybug_{{cad}}.colorize import ColoredPolyline\n from ladybug_{{cad}}.fromobjects import legend_objects\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, objectify_output, \\\n schedule_solution\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component) and None not in _data:\n # set default values for the chart dimensions\n z_val = _base_pt_.Z if _base_pt_ is not None else 0\n z_val_tol = z_val + tolerance\n _base_pt_ = to_point2d(_base_pt_) if _base_pt_ is not None else Point2D()\n _x_dim_ = _x_dim_ if _x_dim_ is not None else 10.0 / conversion_to_meters()\n _y_dim_ = _y_dim_ if _y_dim_ is not None else 40.0 / conversion_to_meters()\n stack_ = stack_ if stack_ is not None else False\n percentile_ = percentile_ if percentile_ is not None else 34.0\n lpar = legend_par_[0] if len(legend_par_) != 0 else None\n\n # create the monthly chart object and get the main pieces of geometry\n month_chart = MonthlyChart(_data, lpar, _base_pt_, _x_dim_, _y_dim_,\n stack_, percentile_)\n if len(legend_par_) > 1:\n if legend_par_[1].min is not None:\n month_chart.set_minimum_by_index(legend_par_[1].min, 1)\n if legend_par_[1].max is not None:\n month_chart.set_maximum_by_index(legend_par_[1].max, 1)\n\n # get the main pieces of geometry\n data_lines = []\n d_meshes = month_chart.data_meshes\n if d_meshes is not None:\n data_mesh = [from_mesh2d(msh, z_val_tol) for msh in d_meshes]\n if month_chart.time_interval == 'Monthly':\n data_lines += [l for msh in d_meshes for l in\n from_mesh2d_to_outline(msh, z_val_tol)]\n d_lines = month_chart.data_polylines\n if d_lines is not None:\n data_lines += [from_polyline2d(lin, z_val_tol) for lin in d_lines]\n borders = [from_polyline2d(month_chart.chart_border, z_val)] + \\\n [from_linesegment2d(line, z_val) for line in month_chart.y_axis_lines] + \\\n [from_linesegment2d(line, z_val_tol) for line in month_chart.month_lines]\n leg = month_chart.legend\n if z_val != 0 and leg.legend_parameters.is_base_plane_default:\n nl_par = leg.legend_parameters.duplicate()\n m_vec = Vector3D(0, 0, z_val)\n nl_par.base_plane = nl_par.base_plane.move(m_vec)\n leg._legend_par = nl_par\n legend = legend_objects(leg)\n\n # process all of the text-related outputs\n title_txt = month_chart.title_text if global_title_ is None else global_title_\n txt_hgt = month_chart.legend_parameters.text_height\n font = month_chart.legend_parameters.font\n ttl_tp = month_chart.lower_title_location\n if z_val != 0:\n ttl_tp = Plane(n=ttl_tp.n, o=Point3D(ttl_tp.o.x, ttl_tp.o.y, z_val), x=ttl_tp.x)\n title = text_objects(title_txt, ttl_tp, txt_hgt, font)\n\n # process the first y axis\n y1_txt = month_chart.y_axis_title_text1 if len(y_axis_title_) == 0 else y_axis_title_[0]\n y1_tp = month_chart.y_axis_title_location1\n if z_val != 0:\n y1_tp = Plane(n=y1_tp.n, o=Point3D(y1_tp.o.x, y1_tp.o.y, z_val), x=y1_tp.x)\n y_title = text_objects(y1_txt, y1_tp, txt_hgt, font)\n if time_marks_:\n txt_h = _x_dim_ / 20 if _x_dim_ / 20 < txt_hgt * 0.75 else txt_hgt * 0.75\n label1 = [text_objects(txt, Plane(o=Point3D(pt.x, pt.y, z_val)), txt_h, font, 1, 0)\n for txt, pt in zip(month_chart.time_labels, month_chart.time_label_points)]\n borders.extend([from_linesegment2d(line, z_val_tol) for line in month_chart.time_ticks])\n else:\n label1 = [text_objects(txt, Plane(o=Point3D(pt.x, pt.y, z_val)), txt_hgt, font, 1, 0)\n for txt, pt in zip(month_chart.month_labels, month_chart.month_label_points)]\n label2 = [text_objects(txt, Plane(o=Point3D(pt.x, pt.y, z_val)), txt_hgt, font, 2, 3)\n for txt, pt in zip(month_chart.y_axis_labels1, month_chart.y_axis_label_points1)]\n labels = label1 + label2\n\n # process the second y axis if it exists\n if month_chart.y_axis_title_text2 is not None:\n y2_txt = month_chart.y_axis_title_text2 if len(y_axis_title_) <= 1 else y_axis_title_[1]\n y2_tp = month_chart.y_axis_title_location2\n if z_val != 0:\n y2_tp = Plane(n=y2_tp.n, o=Point3D(y2_tp.o.x, y2_tp.o.y, z_val), x=y2_tp.x)\n y_title2 = text_objects(y2_txt, y2_tp, txt_hgt, font)\n y_title = [y_title, y_title2]\n label3 = [text_objects(txt, Plane(o=Point3D(pt.x, pt.y, z_val)), txt_hgt, font, 0, 3)\n for txt, pt in zip(month_chart.y_axis_labels2, month_chart.y_axis_label_points2)]\n labels = labels + label3\n\n # if there are colored lines, then process them to be output from the component\n if month_chart.time_interval == 'MonthlyPerHour':\n cols = [color_to_color(col) for col in month_chart.colors]\n col_lines, month_count = [], len(data_lines) / len(_data)\n for i, pline in enumerate(data_lines):\n col_line = ColoredPolyline(pline)\n col_line.color = cols[int(i / month_count)]\n col_line.thickness = 3\n col_lines.append(col_line)\n # CWM: I don't know why we have to re-schedule the solution but this is the\n # only way I found to get the colored polylines to appear (redraw did not work).\n schedule_solution(ghenv.Component, 2)\n\n # output arguments for the visualization set\n vis_set = [month_chart, z_val, time_marks_, global_title_, y_axis_title_]\n vis_set = objectify_output('VisualizationSet Aruments [MonthlyChart]', vis_set)\n",
"code": "\ntry:\n from ladybug_geometry.geometry2d.pointvector import Point2D\n from ladybug_geometry.geometry3d.pointvector import Vector3D, Point3D\n from ladybug_geometry.geometry3d.plane import Plane\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_geometry:\\n\\t{}'.format(e))\n\ntry:\n from ladybug.monthlychart import MonthlyChart\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.config import conversion_to_meters, tolerance\n from ladybug_{{cad}}.color import color_to_color\n from ladybug_{{cad}}.togeometry import to_point2d\n from ladybug_{{cad}}.fromgeometry import from_mesh2d, from_mesh2d_to_outline, \\\n from_polyline2d, from_linesegment2d\n from ladybug_{{cad}}.text import text_objects\n from ladybug_{{cad}}.colorize import ColoredPolyline\n from ladybug_{{cad}}.fromobjects import legend_objects\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, objectify_output, \\\n schedule_solution\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component) and None not in _data:\n # set default values for the chart dimensions\n z_val = _base_pt_.Z if _base_pt_ is not None else 0\n z_val_tol = z_val + tolerance\n _base_pt_ = to_point2d(_base_pt_) if _base_pt_ is not None else Point2D()\n _x_dim_ = _x_dim_ if _x_dim_ is not None else 10.0 / conversion_to_meters()\n _y_dim_ = _y_dim_ if _y_dim_ is not None else 40.0 / conversion_to_meters()\n stack_ = stack_ if stack_ is not None else False\n percentile_ = percentile_ if percentile_ is not None else 34.0\n lpar = legend_par_[0] if len(legend_par_) != 0 else None\n\n # create the monthly chart object and get the main pieces of geometry\n month_chart = MonthlyChart(_data, lpar, _base_pt_, _x_dim_, _y_dim_,\n stack_, percentile_)\n if len(legend_par_) > 1:\n if legend_par_[1].min is not None:\n month_chart.set_minimum_by_index(legend_par_[1].min, 1)\n if legend_par_[1].max is not None:\n month_chart.set_maximum_by_index(legend_par_[1].max, 1)\n\n # get the main pieces of geometry\n data_lines = []\n d_meshes = month_chart.data_meshes\n if d_meshes is not None:\n data_mesh = [from_mesh2d(msh, z_val_tol) for msh in d_meshes]\n if month_chart.time_interval == 'Monthly':\n data_lines += [l for msh in d_meshes for l in\n from_mesh2d_to_outline(msh, z_val_tol)]\n line_results = month_chart.data_polylines_with_colors\n if line_results is not None:\n d_lines, d_cols = line_results\n data_lines += [from_polyline2d(lin, z_val_tol) for lin in d_lines]\n borders = [from_polyline2d(month_chart.chart_border, z_val)] + \\\n [from_linesegment2d(line, z_val) for line in month_chart.y_axis_lines] + \\\n [from_linesegment2d(line, z_val_tol) for line in month_chart.month_lines]\n leg = month_chart.legend\n if z_val != 0 and leg.legend_parameters.is_base_plane_default:\n nl_par = leg.legend_parameters.duplicate()\n m_vec = Vector3D(0, 0, z_val)\n nl_par.base_plane = nl_par.base_plane.move(m_vec)\n leg._legend_par = nl_par\n legend = legend_objects(leg)\n\n # process all of the text-related outputs\n title_txt = month_chart.title_text if global_title_ is None else global_title_\n txt_hgt = month_chart.legend_parameters.text_height\n font = month_chart.legend_parameters.font\n ttl_tp = month_chart.lower_title_location\n if z_val != 0:\n ttl_tp = Plane(n=ttl_tp.n, o=Point3D(ttl_tp.o.x, ttl_tp.o.y, z_val), x=ttl_tp.x)\n title = text_objects(title_txt, ttl_tp, txt_hgt, font)\n\n # process the first y axis\n y1_txt = month_chart.y_axis_title_text1 if len(y_axis_title_) == 0 else y_axis_title_[0]\n y1_tp = month_chart.y_axis_title_location1\n if z_val != 0:\n y1_tp = Plane(n=y1_tp.n, o=Point3D(y1_tp.o.x, y1_tp.o.y, z_val), x=y1_tp.x)\n y_title = text_objects(y1_txt, y1_tp, txt_hgt, font)\n if time_marks_:\n txt_h = _x_dim_ / 20 if _x_dim_ / 20 < txt_hgt * 0.75 else txt_hgt * 0.75\n label1 = [text_objects(txt, Plane(o=Point3D(pt.x, pt.y, z_val)), txt_h, font, 1, 0)\n for txt, pt in zip(month_chart.time_labels, month_chart.time_label_points)]\n borders.extend([from_linesegment2d(line, z_val_tol) for line in month_chart.time_ticks])\n else:\n label1 = [text_objects(txt, Plane(o=Point3D(pt.x, pt.y, z_val)), txt_hgt, font, 1, 0)\n for txt, pt in zip(month_chart.month_labels, month_chart.month_label_points)]\n label2 = [text_objects(txt, Plane(o=Point3D(pt.x, pt.y, z_val)), txt_hgt, font, 2, 3)\n for txt, pt in zip(month_chart.y_axis_labels1, month_chart.y_axis_label_points1)]\n labels = label1 + label2\n\n # process the second y axis if it exists\n if month_chart.y_axis_title_text2 is not None:\n y2_txt = month_chart.y_axis_title_text2 if len(y_axis_title_) <= 1 else y_axis_title_[1]\n y2_tp = month_chart.y_axis_title_location2\n if z_val != 0:\n y2_tp = Plane(n=y2_tp.n, o=Point3D(y2_tp.o.x, y2_tp.o.y, z_val), x=y2_tp.x)\n y_title2 = text_objects(y2_txt, y2_tp, txt_hgt, font)\n y_title = [y_title, y_title2]\n label3 = [text_objects(txt, Plane(o=Point3D(pt.x, pt.y, z_val)), txt_hgt, font, 0, 3)\n for txt, pt in zip(month_chart.y_axis_labels2, month_chart.y_axis_label_points2)]\n labels = labels + label3\n\n # if there are colored lines, then process them to be output from the component\n if month_chart.time_interval == 'MonthlyPerHour':\n cols = [color_to_color(col) for col in d_cols]\n col_lines = []\n for pline, line_col in zip(data_lines, cols):\n col_line = ColoredPolyline(pline)\n col_line.color = line_col\n col_line.thickness = 3\n col_lines.append(col_line)\n # CWM: I don't know why we have to re-schedule the solution but this is the\n # only way I found to get the colored polylines to appear (redraw did not work).\n schedule_solution(ghenv.Component, 2)\n\n # output arguments for the visualization set\n vis_set = [month_chart, z_val, time_marks_, global_title_, y_axis_title_]\n vis_set = objectify_output('VisualizationSet Aruments [MonthlyChart]', vis_set)\n",
"category": "Ladybug",
"name": "LB Monthly Chart",
"description": "Create a chart in the Rhino scene with data organized by month.\n_\nData will display as a bar chart if the input data is monthly or daily. If the\ndata is hourly or sub-hourly, it will be plotted with lines and/or a colored\nmesh that shows the range of the data within specific percentiles.\n-"
Expand Down
15 changes: 8 additions & 7 deletions ladybug_grasshopper/src/LB Monthly Chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

ghenv.Component.Name = 'LB Monthly Chart'
ghenv.Component.NickName = 'MonthlyChart'
ghenv.Component.Message = '1.8.0'
ghenv.Component.Message = '1.8.2'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '2 :: Visualize Data'
ghenv.Component.AdditionalHelpFromDocStrings = '1'
Expand Down Expand Up @@ -137,8 +137,9 @@
if month_chart.time_interval == 'Monthly':
data_lines += [l for msh in d_meshes for l in
from_mesh2d_to_outline(msh, z_val_tol)]
d_lines = month_chart.data_polylines
if d_lines is not None:
line_results = month_chart.data_polylines_with_colors
if line_results is not None:
d_lines, d_cols = line_results
data_lines += [from_polyline2d(lin, z_val_tol) for lin in d_lines]
borders = [from_polyline2d(month_chart.chart_border, z_val)] + \
[from_linesegment2d(line, z_val) for line in month_chart.y_axis_lines] + \
Expand Down Expand Up @@ -192,11 +193,11 @@

# if there are colored lines, then process them to be output from the component
if month_chart.time_interval == 'MonthlyPerHour':
cols = [color_to_color(col) for col in month_chart.colors]
col_lines, month_count = [], len(data_lines) / len(_data)
for i, pline in enumerate(data_lines):
cols = [color_to_color(col) for col in d_cols]
col_lines = []
for pline, line_col in zip(data_lines, cols):
col_line = ColoredPolyline(pline)
col_line.color = cols[int(i / month_count)]
col_line.color = line_col
col_line.thickness = 3
col_lines.append(col_line)
# CWM: I don't know why we have to re-schedule the solution but this is the
Expand Down
Binary file modified ladybug_grasshopper/user_objects/LB Monthly Chart.ghuser
Binary file not shown.

0 comments on commit 169c6bf

Please sign in to comment.