# # # build_html_graphs_util.cfv # Graph utilities used in build_html_standard() # The utilities build the html part of a graph # # # # get_y_label_table_width() # # get_x_label_table_with_labels_on_ticks() # get_x_label_table_with_single_label_on_tick() # get_x_label_table_with_labels_between_ticks() # get_x_label_table() # # get_y_label_spacer_image_fileref() # get_left_and_right_y_label_tables() # # build_graph_legend_table() # # # include "templates.util.encoding"; include "templates.util.colors"; include "templates.util.date_time.date_time_formatting"; include "templates.statistics.graph_images.graph_image_util"; # # # # get_y_label_table_width() # # Gets the width for the y_label table among all displayed graphs. # subroutine(get_y_label_table_width( node query_fields, string profile_name, node raw_report_element_graphs), ( debug_message("\n\n#### get_y_label_table_width \n\n"); node raw_report_element_graph_item; string graph_id; node raw_graph; string report_field_name; string display_format_type; node y_ticks; node tick; string tick_label; int tick_label_length; int max_character_in_y_label_among_all_graphs = 0; foreach raw_report_element_graph_item raw_report_element_graphs ( graph_id = @raw_report_element_graph_item; raw_graph = "profiles_cache." . profile_name . ".raw_graphs." . graph_id; report_field_name = @raw_graph{"report_field_name"}; display_format_type = @query_fields{report_field_name}{"display_format_type"}; y_ticks = raw_graph . ".y_data.ticks"; foreach tick y_ticks ( tick_label = format(@tick{"label"}, display_format_type); debug_message("#### get_y_label_table_width() - tick_label: " . tick_label . "\n"); tick_label_length = length(tick_label); if (tick_label_length > max_character_in_y_label_among_all_graphs) then ( max_character_in_y_label_among_all_graphs = tick_label_length; ); ); ); int y_label_table_width = (6 * max_character_in_y_label_among_all_graphs) + 18; # 6px for char width and 18px left margin y_label_table_width; )); # # # # get_x_label_table_with_labels_on_ticks() # # # subroutine(get_x_label_table_with_labels_on_ticks( int y_label_table_width, node x_ticks_with_labels, int number_of_x_ticks_with_labels), ( debug_message("\n\n#### get_x_label_table_with_labels_on_ticks() \n"); # Note, the distance between the x-ticks may vary depending on the chronological # granularity. So the table cell width may vary from x-tick to x-tick node current_tick; node next_tick; string the_label; int current_tick_position; int next_tick_position; int distance_between_two_ticks; int a = 0; # The left side of a tick we use for the table cell int b = 0; # The right side of a tick we use for the table cell int cell_width; # a + b int table_width; int spacer_cell_width; '
'; ); ) else ( # This is the last x-tick, so there is no next_tick a = current_tick_position - table_width; cell_width = 2 * a; ); # debug_message("#### cell_width: " . cell_width . "\n"); ' | '; '' . the_label . ''; ' | '; ); '
' . the_label . ' | '; '
'; node left_tick_position_node; node right_tick_position_node; int left_tick_position; int right_tick_position; int cell_width; string the_label; for (int count = 0; count < (number_of_x_ticks_with_labels - 1); count++) ( left_tick_position_node = subnode_by_number(x_ticks_with_labels, count); right_tick_position_node = subnode_by_number(x_ticks_with_labels, count + 1); left_tick_position = node_value(subnode_by_name(left_tick_position_node, "position")); right_tick_position = node_value(subnode_by_name(right_tick_position_node, "position")); cell_width = right_tick_position - left_tick_position; the_label = get_expanded_label(@left_tick_position_node{"label"}); ' | ' . the_label . ' | '; ); '
' . y_tick_label . ' |
' . y_tick_percentage . ' % |
0 |
0 % |
' . (row_count + 1) . ' | \n'; ); if (show_color_icon) then ( r = node_value(mixed_colors_node . "." . color_count . ".red"); g = node_value(mixed_colors_node . "." . color_count . ".green"); b = node_value(mixed_colors_node . "." . color_count . ".blue"); '';
# '';
# KHP 13/Mar/2013 - border-color does not work in Gmail and Outlook, start using background-color.
if (!is_static_email) then (
'';
)
else (
# Use images for legend colors in emails.
image_file_ref = get_rectangular_graphs_image_fileref(web_server_root_path, profile_name, image_width, image_height, r, g, b);
' | \n';
);
if (show_percent_in_legend) then (
'' . format(@variables_in_percent{row_count}, "%.1f") . ' % | \n'; ); if (show_values_in_legend) then ( '' . format(@variables{row_count}, main_report_field_display_format_type) . ' | \n'; ); column_count = 0; legend_label = ""; foreach column legend_header ( report_field_name = @column{"report_field_name"}; query_field_item = query_fields{report_field_name}; display_format_type = @query_field_item{"display_format_type"}; skip_escaping = @query_field_item{"skip_escaping"}; # debug_message("#### build_graph_legend_table() - report_field_name: " . report_field_name . "\n"); # debug_message("#### build_graph_legend_table() - display_format_type: " . display_format_type . "\n"); if (display_format_type ne "date_time") then ( legend_label .= format(node_value(subnode_by_number(row, column_count)), display_format_type); ) else ( legend_label .= format_date_time(node_value(subnode_by_number(row, column_count))); ); if (is_multiple_legend_columns and (column_count != last_column_number)) then ( legend_label .= ", "; ); column_count++; ); ''; if (!skip_escaping) then ( string_to_html(legend_label); ) else ( legend_label; ); ' | '; if (show_color_icon) then ( color_count++; if (color_count == number_of_colors) then ( # start repeating the colors color_count = 0; ); ); '
---|---|---|---|---|
' . number_of_variables . ' | \n'; ); if (show_color_icon) then ( r = @remainder_color_node{"red"}; g = @remainder_color_node{"green"}; b = @remainder_color_node{"blue"}; ''; # KHP 04/Apr/2013 - Colored div does not work in Outlook email client, # use images in email. ''; ' | \n'; ); if (show_percent_in_legend) then ( '' . format(@variables_in_percent{(number_of_variables - 1)}, "%.1f") . ' % | \n'; ); if (show_values_in_legend) then ( '' . format(@variables{(number_of_variables - 1)}, main_report_field_display_format_type) . ' | \n'; ); '' . expand(lang_stats.graph.remaining_items) . ' | \n'; '