# -------------- # convert_graphs # -------------- # This subroutine runs only one time if node system.maintenance.convert_graphs does not exist # The subroutine converts existing graph settings (up to version 7.0.10x) to the new 7.0.11 graph settings # The old graph settings will be left in the profile as they are so that settings exist in case that a user # keeps a 7.0.10x or lower version rather than the 7.0.11 version subroutine(convert_graphs, ( debug_message("#### #### ======================\n"); debug_message("#### #### Running convert graphs\n"); debug_message("#### #### ======================\n"); node profile; node report; node reports_node; node report_element; node report_elements_node; node graph_node; node graph_field; node graph_fields_node; node column; node columns_node; string graph_field_name; string field_name; bool graph_is_set; string graph_type; int image_width; int image_height; int x_axis_length; int y_axis_height; string new_graphs_subnode_name; foreach profile "profiles" ( if (node_name(profile) ne "default_profile") then ( reports_node = profile . ".statistics.reports"; foreach report reports_node ( report_elements_node = subnode_by_name(report, "report_elements"); foreach report_element report_elements_node ( if (subnode_exists(report_element, "show_graph") and node_value(subnode_by_name(report_element, "show_graph"))) then ( # There is a graph to convert # Note, we only conbert graphs where show_graph is set to true # debug_message("@@@@ convert graphs of: " . node_name(profile) . " " . node_name(report) . " " . node_name(report_element) . "\n"); # --------------- # Set graph nodes # --------------- if (node_exists(report_element . ".graph") and node_exists(report_element . ".graph.numerical_fields")) then ( graph_node = subnode_by_name(report_element, "graph"); graph_fields_node = subnode_by_name(graph_node, "numerical_fields"); columns_node = subnode_by_name(report_element, "columns"); graph_is_set = false; foreach graph_field graph_fields_node ( if (node_value(graph_field)) then ( graph_field_name = node_name(graph_field); # ---------------------------------- # Set new show_graph in columns node # ---------------------------------- foreach column columns_node ( field_name = node_value(subnode_by_name(column, "field_name")); if (field_name eq graph_field_name) then ( # debug_message("@@@@ set column of field: " . field_name . "\n"); column . ".show_graph" = true; graph_is_set = true; last; ); ); # foreach column ); ); # foreach graph_field if (graph_is_set) then ( # -------------------------------------------- # Set specific report element graph parameters # -------------------------------------------- if (subnode_exists(graph_node, "pie_chart") and node_value(subnode_by_name(graph_node, "pie_chart"))) then ( graph_type = "pie" ) else if (subnode_exists(graph_node, "line_graph") and node_value(subnode_by_name(graph_node, "line_graph"))) then ( graph_type = "line" ) else ( graph_type = "bar" ); if (graph_type ne "bar") then ( # specify type in report element name report_element . ".graphs.graph_type" = graph_type; ); if (graph_type ne "pie") then ( new_graphs_subnode_name = "bar_line_graph"; ) else ( new_graphs_subnode_name = "pie_chart"; ); if (subnode_exists(graph_node, "image_width")) then ( image_width = node_value(subnode_by_name(graph_node, "image_width")); if (image_width > 0) then ( if (graph_type eq "pie") then (image_width -= 10); report_element . ".graphs." . new_graphs_subnode_name . ".x_axis_length" = image_width; ); ); if (subnode_exists(graph_node, "image_height")) then ( image_height = node_value(subnode_by_name(graph_node, "image_height")); if (image_height > 0) then ( if (graph_type eq "pie") then (image_height -= 10); report_element . ".graphs." . new_graphs_subnode_name . ".y_axis_height" = image_height; ); ); if (subnode_exists(graph_node, "maximum_bars")) then ( report_element . ".graphs." . new_graphs_subnode_name . ".max_variables" = node_value(subnode_by_name(graph_node, "maximum_bars")); ); if (subnode_exists(graph_node, "use_legend") and graph_type ne "pie") then ( report_element . ".graphs." . new_graphs_subnode_name . ".show_legend" = node_value(subnode_by_name(graph_node, "use_legend")); ); if (subnode_exists(graph_node, "maximum_legend_rows")) then ( report_element . ".graphs." . new_graphs_subnode_name . ".max_legend_rows" = node_value(subnode_by_name(graph_node, "maximum_legend_rows")); ); ); # graph_is_set ); # if graph_fields exits ); # if show_graph ); # foreach report_element ); # foreach report ); # if not default profile # save_changes(); ); # foreach profile save_changes(); # debug_message("\n" . node_as_string("profiles.temp.statistics.reports") . "\n"); system.maintenance.convert_graphs = true; save_node("system"); ));