indexing description: "[ Exhibit box showcasing diagrams ]" author: "" date: "$Date$" revision: "$Revision$" class EXHIBIT_DIAGRAMS_BOX inherit EXHIBIT_BOX create make feature -- Access title: STRING is -- Title "Diagram Components" description: STRING is -- Description "Last but not least, there are several classes that provide data-visualization facilities. % %To keep things modular and extensible, developers using the Viz-library will need to assemble % %most charts (with the exception of the pie-chart) themselves. This means arranging plots and % % axes, e.g. with a table-box and specifying the plotter that should be used.%N% %Currently, there's only support for two types of 2D-plots:%N% %DATA-plots take their values from a linear sequence of explicitly user-specified data.%N% %SAMPLING-plots take their values directly from a sample-source, e.g. a simple 1d function.%N% %%N% %Customization can be done by providing your own:%N% %- EM_VIZ_LABELER for the axes%N% %- EM_VIZ_PLOTTER for the plot%N% %- plot/chart by deriving from EM_VIZ_PLOT or EM_VIZ_RENDERER_BOX%N% %" pie_chart: EM_VIZ_PIE_CHART -- Pie chart pie_slices: DS_ARRAYED_LIST [EM_VIZ_PIE_SLICE] -- Slices of the pie (absolute value, label text, color) data_chart: EM_VIZ_BOX -- Data plot and axes data_plot: EM_VIZ_DATA_PLOT_2D -- 2D Plot of user specified data data_source: DS_ARRAYED_LIST [EM_VECTOR2D] -- User specified data sampling_chart: EM_VIZ_BOX -- Sampling plots and axes perlin_sampling_plot: EM_VIZ_SAMPLING_PLOT_2D -- 2D Plot of a 1D perlin noise function perlin_sample_source: PERLIN_NOISE_SOURCE -- Perlin noise source cosine_sampling_plot: EM_VIZ_SAMPLING_PLOT_2D -- 2D Plot of a cosine function cosine_sample_source: COSINE_SOURCE -- Cosine sample source illuminator: EM_VIZ_LIGHT_BOX [EM_VIZ_BOX] -- Light box to illuminate the scene bar_plotter: EM_VIZ_BAR_PLOTTER -- Plotter for plots box_plotter: EM_VIZ_BOX_PLOTTER -- Plotter for plots line_plotter: EM_VIZ_LINE_PLOTTER -- Plotter for plots ribbon_plotter: EM_VIZ_RIBBON_PLOTTER -- Plotter for plots point_plotter: EM_VIZ_POINT_PLOTTER -- Plotter for plots feature -- Manufacturing create_plotters is -- Create plotters that will be used by the plots to -- render the data do create point_plotter.make (5.0, [255, 0, 0]) create line_plotter.make (1.0, [0, 255, 0]) create bar_plotter.make (2.0, [0, 0, 0]) create ribbon_plotter.make ([0, 0, 255]) create box_plotter.make (4.0, [0, 255, 255]) end create_pie_slices is -- Create pie slices for pie chart local c: EM_COLOR do create pie_slices.make (8) c := [255, 0, 0] pie_slices.put_last ([1.0, "Redone", c]) pie_slices.put_last ([1.0, "1"]) pie_slices.put_last ([2.0, "Uhm"]) pie_slices.put_last ([1.0, "2"]) pie_slices.put_last ([1.5, "Good"]) pie_slices.put_last ([1.0, "3"]) pie_slices.put_last ([0.666, "Evil"]) pie_slices.put_last ([1.0, "4"]) end create_pie_chart is -- Create pie chart local chart_size: EM_VECTOR3D do chart_size := [column_layout.column_width (1),120.0,10.0] create pie_chart.make (chart_size) pie_chart.set_hue_range ([0.0, 360.0]) create_pie_slices animate_pie (0) end create_data_source is -- Create data source for data plot local i: INTEGER do create data_source.make (11) from i := 0 until data_source.is_full loop data_source.put_last ([10*i,20*i-100]) i := i + 1 end end create_data_chart is -- Assemble a chart by putting together plot and axes local grid: EM_VIZ_TABLE_BOX [EM_VIZ_BOX] plot_size: EM_VECTOR3D x_axis, y_axis, z_axis: EM_VIZ_LINEAR_AXIS_BOX x_interval, y_interval: EM_INTERVAL do plot_size := [100.0, 100.0, 20.0] x_interval := [0.0, 100.0] y_interval := [-100.0, 100.0] create grid.make ([0.0, 0.0, 0.0], [3,2]) grid.set_border_hidden (True) create x_axis.make_x (plot_size.x, x_interval) x_axis.create_simple_labeler ("", " foo") x_axis.set_blip_spacing (5.0) x_axis.set_label_start (25.0) x_axis.set_label_spacing (50.0) create y_axis.make_y (plot_size.y, y_interval) y_axis.create_simple_labeler ("", "%%") y_axis.set_blip_spacing (10.0) y_axis.set_label_spacing (100.0) y_axis.put_tail_arrow create z_axis.make_z (plot_size.z, [-1.0, 0.0]) z_axis.create_simple_labeler ("", "") z_axis.set_axis_inverted (False) z_axis.set_label_distance (10.0) create data_plot.make (plot_size, x_interval, y_interval) create_data_source data_plot.set_data_source (data_source) data_plot.set_plotter (box_plotter) data_plot.set_clipping_enabled (False, False, False) grid.put (y_axis, [1,1]) grid.put (data_plot, [2,1]) grid.put (x_axis, [2,2]) grid.put (z_axis, [3,2]) data_chart := grid end create_sampling_charts is -- Assemble a chart by putting together plots and axes local grid: EM_VIZ_TABLE_BOX [EM_VIZ_BOX] sampling_plots: EM_VIZ_DEPTH_BOX [EM_VIZ_SAMPLING_PLOT_2D] plot_size: EM_VECTOR3D x_axis, y_axis: EM_VIZ_LINEAR_AXIS_BOX x_interval, y_interval: EM_INTERVAL do plot_size := [100.0, 100.0, 10.0] x_interval := [0.0, 100.0] y_interval := [0.0, 1.0] create grid.make ([0.0, 0.0, 0.0], [2,2]) grid.set_border_hidden (True) create x_axis.make_x (plot_size.x, x_interval) x_axis.create_simple_labeler ("$", "") x_axis.set_blip_spacing (10.0) x_axis.set_label_spacing (20.0) x_axis.set_label_alignment ([Align_center, Align_top]) x_axis.set_label_distance (20.0) x_axis.set_label_rotation (45.0) x_axis.prune_head_arrow create y_axis.make_y (plot_size.y, y_interval) y_axis.create_simple_labeler ("", " U") y_axis.set_blip_spacing (0.1) y_axis.set_label_spacing (0.5) y_axis.set_label_alignment ([Align_left, Align_center]) y_axis.put_tail_arrow create perlin_sampling_plot.make (plot_size, x_interval, y_interval) create perlin_sample_source.make perlin_sampling_plot.set_sampling_rate (x_interval.size / 10) perlin_sampling_plot.set_sample_source (perlin_sample_source) perlin_sampling_plot.set_plotter (box_plotter) create cosine_sampling_plot.make (plot_size, x_interval, y_interval) create cosine_sample_source.make cosine_sample_source.set_amplitude (y_interval.size / 2) cosine_sample_source.set_y_offset (y_interval.size / 2) cosine_sample_source.set_period (x_interval.size) cosine_sampling_plot.set_sampling_rate (x_interval.size / 20) cosine_sampling_plot.set_sample_source (cosine_sample_source) cosine_sampling_plot.set_plotter (line_plotter) create sampling_plots.make sampling_plots.put_last (perlin_sampling_plot) sampling_plots.put_last (cosine_sampling_plot) grid.put (y_axis, [2,1]) grid.put (x_axis, [1,2]) grid.put (sampling_plots, [1,1]) sampling_chart := grid end create_exhibit is -- Create contents do create_column_layout (3) put_column_title ("Pie chart", 1) put_column_title ("Data plot%N(user defined)", 2) put_column_title ("Sampling plots%N(perlin noise and cosine)", 3) create_plotters create_pie_chart put_column_content (pie_chart, 1) create_data_chart put_column_content (data_chart, 2) create_sampling_charts put_column_content (sampling_chart, 3) create illuminator.make illuminator.put (column_layout) exhibit := illuminator end feature -- Animation animate_data_source (a_time: INTEGER) is -- local i: INTEGER v: EM_VECTOR2D x: DOUBLE do i := a_time \\ data_source.count + 1 -- Only change one point at a time v := data_source.item (i) x := a_time / 1000.0 + Pi * v.x / 100.0 data_source.replace ([v.x, 120*cosine (3*x)*cosine (4*x)], i) data_plot.set_data_source (data_source) end animate_plotter (plot: EM_VIZ_PLOT_2D; a_time: INTEGER) is -- do inspect (a_time // 2000) \\ 5 when 0 then plot.set_plotter (point_plotter) when 1 then plot.set_plotter (line_plotter) when 2 then plot.set_plotter (ribbon_plotter) when 3 then plot.set_plotter (bar_plotter) else plot.set_plotter (box_plotter) end end animate_sample_sources (a_time: INTEGER) is -- do perlin_sample_source.set_seed (a_time) cosine_sample_source.set_x_offset (a_time/1000.0) end animate_pie (a_time: INTEGER) is -- It's alive! local c: DOUBLE do pie_chart.set_rotation_axis ([0.3, 0.4, 0.5]) pie_chart.set_rotation_angle (a_time / 1000.0 * 72.0) c := cosine (a_time/10000.0) pie_chart.set_hue_range ([c*360.0, (c+1)*360.0]) c := cosine (a_time/1000.0) pie_slices.item (1).set_value (c + 1) c := cosine (a_time/1400.0 + 1) pie_slices.item (3).set_value (c + 2) c := cosine (a_time/ 500.0 + 2) pie_slices.item (5).set_value (c + 3) c := cosine (a_time/1900.0 + 3) pie_slices.item (7).set_value (c + 5) pie_chart.set_slices (pie_slices) end go_to_time (a_time: INTEGER) is -- Animate do animate_pie (a_time) animate_data_source (a_time) animate_sample_sources (a_time) animate_plotter (data_plot, a_time) animate_plotter (perlin_sampling_plot, a_time + 1500) animate_plotter (cosine_sampling_plot, a_time + 2500) end end