1+ module fplot_plot_data_box_whisker
2+ use iso_fortran_env
3+ use fplot_plot_data
4+ use fplot_errors
5+ use fplot_colors
6+ use ferror
7+ use strings
8+ implicit none
9+ private
10+ public :: plot_data_box_whisker
11+
12+ type, extends(plot_data_colored) :: plot_data_box_whisker
13+ ! ! A container for box-whisker plot data.
14+ type (string), private , allocatable , dimension (:) :: m_x
15+ ! ! The x-coordinate data.
16+ real (real64), private , allocatable , dimension (:) :: m_boxMin
17+ ! ! The minimum y-values for each box.
18+ real (real64), private , allocatable , dimension (:) :: m_boxMax
19+ ! ! The maximum y-values for each box.
20+ real (real64), private , allocatable , dimension (:) :: m_whiskerMin
21+ ! ! The minimum y-values for each whisker.
22+ real (real64), private , allocatable , dimension (:) :: m_whiskerMax
23+ ! ! The maximum y-values for each whisker.
24+ logical , private :: m_useY2 = .false.
25+ ! ! Plot against the secondary y-axis?
26+ contains
27+ procedure , public :: define_data = > pdbw_define_data_xstring
28+ procedure , public :: get_command_string = > pdbw_get_cmd
29+ procedure , public :: get_data_string = > pdbw_get_data_cmd
30+ procedure , public :: get_draw_against_y2 = > pdbw_get_use_y2
31+ procedure , public :: set_draw_against_y2 = > pdbw_set_use_y2
32+ end type
33+
34+ contains
35+ ! ------------------------------------------------------------------------------
36+ subroutine pdbw_define_data_xstring (this , x , boxmin , boxmax , whiskermin , &
37+ whiskermax , err )
38+ ! ! Defines the data set to plot.
39+ class(plot_data_box_whisker), intent (inout ) :: this
40+ ! ! The plot_data_box_whisker object.
41+ type (string), intent (in ), dimension (:) :: x
42+ ! ! The x-coordinate data.
43+ real (real64), intent (in ), dimension (size (x)) :: boxmin
44+ ! ! The minimum y-values for each box.
45+ real (real64), intent (in ), dimension (size (x)) :: boxmax
46+ ! ! The maximum y-values for each box.
47+ real (real64), intent (in ), dimension (size (x)) :: whiskermin
48+ ! ! The minimum y-values for each whisker.
49+ real (real64), intent (in ), dimension (size (x)) :: whiskermax
50+ ! ! The maximum y-values for each whisker.
51+ class(errors), intent (inout ), optional , target :: err
52+ ! ! An error handling object.
53+
54+ ! Local Variables
55+ integer (int32) :: n, flag
56+ class(errors), pointer :: errmgr
57+ type (errors), target :: deferr
58+
59+ ! Initialization
60+ if (present (err)) then
61+ errmgr = > err
62+ else
63+ errmgr = > deferr
64+ end if
65+ n = size (x)
66+
67+ ! Allocations
68+ if (allocated (this% m_x)) deallocate (this% m_x)
69+ if (allocated (this% m_boxMin)) deallocate (this% m_boxMin)
70+ if (allocated (this% m_boxMax)) deallocate (this% m_boxMax)
71+ if (allocated (this% m_whiskerMin)) deallocate (this% m_whiskerMin)
72+ if (allocated (this% m_whiskerMax)) deallocate (this% m_whiskerMax)
73+
74+ allocate (this% m_x(n), source = x, stat = flag)
75+ if (flag == 0 ) allocate (this% m_boxMin(n), source = boxmin, stat = flag)
76+ if (flag == 0 ) allocate (this% m_boxMax(n), source = boxmax, stat = flag)
77+ if (flag == 0 ) allocate (this% m_whiskerMin(n), source = whiskermin, stat = flag)
78+ if (flag == 0 ) allocate (this% m_whiskerMax(n), source = whiskermax, stat = flag)
79+ if (flag /= 0 ) then
80+ call report_memory_error(errmgr, " pdbw_define_data_xstring" , flag)
81+ return
82+ end if
83+ end subroutine
84+
85+ ! ------------------------------------------------------------------------------
86+ function pdbw_get_cmd (this ) result(rst)
87+ ! ! Gets the GNUPLOT command string for this object.
88+ class(plot_data_box_whisker), intent (in ) :: this
89+ ! ! The plot_data_box_whisker object.
90+ character (len = :), allocatable :: rst
91+ ! ! The command string.
92+
93+ ! Local Variables
94+ type (string_builder) :: str
95+ integer (int32) :: n, nname
96+ type (color) :: clr
97+
98+ ! Title
99+ nname = len_trim (this% get_name())
100+ if (n > 0 ) then
101+ call str% append (' "-" title "' )
102+ call str% append (this% get_name())
103+ call str% append (' "' )
104+ else
105+ call str% append (' "-" notitle' )
106+ end if
107+
108+ ! Style
109+ call str% append (" using ($0+1):2:3:4:5:xtic(1) with candlesticks" )
110+
111+ ! Whisker bars
112+
113+ ! Color
114+ clr = this% get_line_color()
115+ call str% append (' lc rgb "#' )
116+ call str% append (clr% to_hex_string())
117+ call str% append (' "' )
118+ end function
119+
120+ ! ------------------------------------------------------------------------------
121+ function pdbw_get_data_cmd (this ) result(rst)
122+ ! ! Gets the GNUPLOT command string defining the data for this object.
123+ class(plot_data_box_whisker), intent (in ) :: this
124+ ! ! The plot_data_box_whisker object.
125+ character (len = :), allocatable :: rst
126+ ! ! The command string.
127+
128+ ! Local Variables
129+ type (string_builder) :: str
130+ integer (int32) :: i, n
131+ character :: delimiter, nl
132+
133+ ! Initialization
134+ delimiter = achar (9 )
135+ nl = new_line(nl)
136+ n = size (this% m_x)
137+
138+ ! Process
139+ do i = 1 , n
140+ call str% append (this% m_x(i))
141+ call str% append (delimiter)
142+ call str% append (to_string(this% m_boxMin(i)))
143+ call str% append (delimiter)
144+ call str% append (to_string(this% m_whiskerMin(i)))
145+ call str% append (delimiter)
146+ call str% append (to_string(this% m_whiskerMax(i)))
147+ call str% append (delimiter)
148+ call str% append (to_string(this% m_boxMax(i)))
149+ call str% append (nl)
150+ end do
151+
152+ ! End
153+ rst = char (str% to_string())
154+ end function
155+
156+ ! ------------------------------------------------------------------------------
157+ function pdbw_get_axes_cmd (this ) result(rst)
158+ ! ! Gets the GNUPLOT command string defining which axes the data is to be
159+ ! ! plotted against.
160+ class(plot_data_box_whisker), intent (in ) :: this
161+ ! ! The plot_data_box_whisker object.
162+ character (len = :), allocatable :: rst
163+ ! ! The command string.
164+
165+ ! Define which axes the data is to be plotted against
166+ if (this% get_draw_against_y2()) then
167+ rst = " axes x1y2"
168+ else
169+ rst = " axes x1y1"
170+ end if
171+ end function
172+
173+ ! ------------------------------------------------------------------------------
174+ pure function pdbw_get_use_y2 (this ) result(rst)
175+ ! ! Gets a value determining if the data is to be plotted against the
176+ ! ! secondary y axis.
177+ class(plot_data_box_whisker), intent (in ) :: this
178+ ! ! The plot_data_box_whisker object.
179+ logical :: rst
180+ ! ! Returns true if the data is to be plotted against the secondary y
181+ ! ! axis; else, false for the primary y axis.
182+ rst = this% m_useY2
183+ end function
184+
185+ ! --------------------
186+ subroutine pdbw_set_use_y2 (this , x )
187+ ! ! Sets a value determining if the data is to be plotted against the
188+ ! ! secondary y axis.
189+ class(plot_data_box_whisker), intent (inout ) :: this
190+ ! ! The plot_data_box_whisker object.
191+ logical , intent (in ) :: x
192+ ! ! Set to true if the data is to be plotted against the secondary y
193+ ! ! axis; else, false for the primary y axis.
194+ this% m_useY2 = x
195+ end subroutine
196+
197+ ! ------------------------------------------------------------------------------
198+
199+ ! ------------------------------------------------------------------------------
200+
201+ ! ------------------------------------------------------------------------------
202+ end module
0 commit comments