2 /* vim: set expandtab sw=4 ts=4 sts=4: */
5 * functions for displaying chart
7 * @usedby tbl_chart.php
11 if (! defined('PHPMYADMIN')) {
16 * Function to get html for pma_token and url_query
18 * @param string $url_query url query
22 function PMA_getHtmlForPmaTokenAndUrlQuery($url_query)
24 $htmlString = '<script type="text/javascript">'
25 . "pma_token = '" . $_SESSION[' PMA_token '] . "';"
26 . "url_query = '" . $url_query . "';"
32 * Function to get html for the chart type options
36 function PMA_getHtmlForChartTypeOptions()
38 $html = '<input type="radio" name="chartType" value="bar" id="radio_bar" />'
39 . '<label for ="radio_bar">' . _pgettext('Chart type', 'Bar') . '</label>'
40 . '<input type="radio" name="chartType" value="column" id="radio_column" />'
41 . '<label for ="radio_column">' . _pgettext('Chart type', 'Column')
43 . '<input type="radio" name="chartType" value="line" id="radio_line"'
44 . ' checked="checked" />'
45 . '<label for ="radio_line">' . _pgettext('Chart type', 'Line') . '</label>'
46 . '<input type="radio" name="chartType" value="spline" id="radio_spline" />'
47 . '<label for ="radio_spline">' . _pgettext('Chart type', 'Spline')
49 . '<input type="radio" name="chartType" value="area" id="radio_area" />'
50 . '<label for ="radio_area">' . _pgettext('Chart type', 'Area') . '</label>'
51 . '<span class="span_pie" style="display:none;">'
52 . '<input type="radio" name="chartType" value="pie" id="radio_pie" />'
53 . '<label for ="radio_pie">' . _pgettext('Chart type', 'Pie') . '</label>'
55 . '<span class="span_timeline" style="display:none;">'
56 . '<input type="radio" name="chartType" '
57 . 'value="timeline" id="radio_timeline" />'
58 . '<label for ="radio_timeline">' . _pgettext('Chart type', 'Timeline')
61 . '<span class="span_scatter" style="display:none;">'
62 . '<input type="radio" name="chartType" '
63 . 'value="scatter" id="radio_scatter" />'
64 . '<label for ="radio_scatter">' . _pgettext('Chart type', 'Scatter')
73 * Function to get html for the bar stacked option
77 function PMA_getHtmlForStackedOption()
79 $html = '<span class="barStacked" style="display:none;">'
80 . '<input type="checkbox" name="barStacked" value="1"'
81 . ' id="checkbox_barStacked" />'
82 . '<label for ="checkbox_barStacked">' . __('Stacked') . '</label>'
90 * Function to get html for the chart x axis options
92 * @param array $keys keys
93 * @param int &$xaxis x axis
97 function PMA_getHtmlForChartXAxisOptions($keys, &$xaxis)
99 $htmlString = '<div style="float:left; padding-left:40px;">'
100 . '<label for="select_chartXAxis">' . __('X-Axis:') . '</label>'
101 . '<select name="chartXAxis" id="select_chartXAxis">';
103 foreach ($keys as $idx => $key) {
104 if ($xaxis === null) {
105 $htmlString .= '<option value="' . htmlspecialchars($idx)
106 . '" selected="selected">' . htmlspecialchars($key) . '</option>';
109 $htmlString .= '<option value="' . htmlspecialchars($idx) . '">'
110 . htmlspecialchars($key) . '</option>';
113 $htmlString .= '</select>';
119 * Function to get html for chart series options
121 * @param array $keys keys
122 * @param array $fields_meta fields meta
123 * @param array $numeric_types numeric types
124 * @param int $xaxis x axis
125 * @param int $numeric_column_count numeric column count
129 function PMA_getHtmlForChartSeriesOptions($keys, $fields_meta, $numeric_types,
130 $xaxis, $numeric_column_count
132 $htmlString = '<br />'
133 . '<label for="select_chartSeries">' . __('Series:') . '</label>'
134 . '<select name="chartSeries" id="select_chartSeries" multiple="multiple">';
136 foreach ($keys as $idx => $key) {
137 if (in_array($fields_meta[$idx]->type
, $numeric_types)) {
138 if ($idx == $xaxis && $numeric_column_count > 1) {
139 $htmlString .= '<option value="' . htmlspecialchars($idx) . '">'
140 . htmlspecialchars($key) . '</option>';
142 $htmlString .= '<option value="' . htmlspecialchars($idx)
143 . '" selected="selected">' . htmlspecialchars($key)
148 $htmlString .= '</select>';
153 * Function to get html for date time columns
155 * @param array $keys keys
156 * @param array $fields_meta fields meta
160 function PMA_getHtmlForDateTimeCols($keys, $fields_meta)
162 $htmlString = '<input type="hidden" name="dateTimeCols" value="';
164 $date_time_types = array('date', 'datetime', 'timestamp');
165 foreach ($keys as $idx => $key) {
166 if (in_array($fields_meta[$idx]->type
, $date_time_types)) {
167 $htmlString .= $idx . " ";
170 $htmlString .= '" />';
176 * Function to get html for date time columns
178 * @param array $keys keys
179 * @param array $fields_meta fields meta
180 * @param array $numeric_types numeric types
184 function PMA_getHtmlForNumericCols($keys, $fields_meta, $numeric_types)
186 $htmlString = '<input type="hidden" name="numericCols" value="';
187 foreach ($keys as $idx => $key) {
188 if (in_array($fields_meta[$idx]->type
, $numeric_types)) {
189 $htmlString .= $idx . " ";
192 $htmlString .= '" />';
198 * Function to get html for the table axis label options
200 * @param int $xaxis x axis
201 * @param array $keys keys
205 function PMA_getHtmlForTableAxisLabelOptions($xaxis, $keys)
207 $htmlString = '<div style="float:left; padding-left:40px;">'
208 . '<label for="xaxis_label">' . __('X-Axis label:') . '</label>'
209 . '<input style="margin-top:0;" type="text" name="xaxis_label" id="xaxis_label"'
211 . (($xaxis == -1) ?
__('X Values') : htmlspecialchars($keys[$xaxis]))
213 . '<label for="yaxis_label">' . __('Y-Axis label:') . '</label>'
214 . '<input type="text" name="yaxis_label" id="yaxis_label" value="'
215 . __('Y Values') . '" /><br />'
222 * Function to get html for switching to alternative data format
224 * @param array $keys keys
225 * @param array $fields_meta fields meta
226 * @param array $numeric_types numeric types
227 * @param int $xaxis x axis
231 function PMA_getHtmlForAlternativeDataFormat($keys, $fields_meta, $numeric_types,
234 $htmlString = '<p style="clear:both;"> </p>'
235 . '<div><input type="checkbox" id="chkAlternative" '
236 . 'name="chkAlternative" value="alternativeFormat">'
237 . __('Series names are in a column') . '</input>';
239 $htmlString .= '<br />'
240 . '<label for="select_seriesColumn">' . __('Series column:') . '</label>'
241 . '<select name="chartSeriesColumn" id="select_seriesColumn" disabled>';
242 foreach ($keys as $idx => $key) {
243 $htmlString .= '<option value="' . htmlspecialchars($idx) . '"';
245 $htmlString .= ' selected="selected"';
246 $seriesColumn = $idx;
248 $htmlString .= '>' . htmlspecialchars($key) . '</option>';
250 $htmlString .= '</select>';
252 $htmlString .= '<label for="select_valueColumn">'
253 . __('Value column:') . '</label>'
254 . '<select name="chartValueColumn" id="select_valueColumn" disabled>';
257 foreach ($keys as $idx => $key) {
258 if (in_array($fields_meta[$idx]->type
, $numeric_types)) {
259 if (! $selected && $idx != $xaxis && $idx != $seriesColumn) {
260 $htmlString .= '<option value="' . htmlspecialchars($idx)
261 . '" selected="selected">' . htmlspecialchars($key)
265 $htmlString .= '<option value="' . htmlspecialchars($idx) . '">'
266 . htmlspecialchars($key) . '</option>';
270 $htmlString .= '</select></div>';
275 * Function to get html for the start row and number of rows options
277 * @param string $sql_query sql query
281 function PMA_getHtmlForStartAndNumberOfRowsOptions($sql_query)
283 $htmlString = '<p style="clear:both;"> </p>'
286 . '<label for="pos">' . __('Start row:') . '</label>'
287 . '<input type="text" name="pos" size="3" value="'
288 . $_SESSION['tmpval']['pos'] . '" />'
289 . '<label for="session_max_rows">'
290 . __('Number of rows:') . '</label>'
291 . '<input type="text" name="session_max_rows" size="3" value="'
292 . (($_SESSION['tmpval']['max_rows'] != 'all')
293 ?
$_SESSION['tmpval']['max_rows']
294 : $GLOBALS['cfg']['MaxRows'])
296 . '<input type="submit" name="submit" class="Go" value="' . __('Go')
298 . '<input type="hidden" name="sql_query" value="'
299 . htmlspecialchars($sql_query) . '" />'
307 * Function to get html for the chart area div
311 function PMA_getHtmlForChartAreaDiv()
313 $htmlString = '<p style="clear:both;"> </p>'
314 . '<div id="resizer" style="width:600px; height:400px;">'
315 . '<div id="saveChart"'
316 . ' style="position: absolute; right: 10px;'
317 . ' top: 10px; cursor: pointer; z-index: 1000;">'
318 . PMA_Util
::getImage('b_saveimage', __('Save chart as image'))
320 . '<div id="querychart">'
328 * Function to get html for displaying table chart
330 * @param string $url_query url query
331 * @param array $url_params url parameters
332 * @param array $keys keys
333 * @param array $fields_meta fields meta
334 * @param array $numeric_types numeric types
335 * @param int $numeric_column_count numeric column count
336 * @param string $sql_query sql query
340 function PMA_getHtmlForTableChartDisplay($url_query, $url_params, $keys,
341 $fields_meta, $numeric_types, $numeric_column_count, $sql_query
343 // pma_token/url_query needed for chart export
344 $htmlString = PMA_getHtmlForPmaTokenAndUrlQuery($url_query);
345 $htmlString .= '<!-- Display Chart options -->'
346 . '<div id="div_view_options">'
347 . '<form method="post" id="tblchartform" action="tbl_chart.php" '
349 . PMA_URL_getHiddenInputs($url_params)
351 . '<legend>' . __('Display chart') . '</legend>'
352 . '<div style="float:left; width:420px;">';
353 $htmlString .= PMA_getHtmlForChartTypeOptions();
354 $htmlString .= PMA_getHtmlForStackedOption();
356 $htmlString .= '<input type="text" name="chartTitle" value="'
361 $htmlString .= PMA_getHtmlForChartXAxisOptions($keys, $xaxis);
362 $htmlString .= PMA_getHtmlForChartSeriesOptions(
363 $keys, $fields_meta, $numeric_types, $xaxis, $numeric_column_count
365 $htmlString .= PMA_getHtmlForDateTimeCols($keys, $fields_meta);
366 $htmlString .= PMA_getHtmlForNumericCols($keys, $fields_meta, $numeric_types);
367 $htmlString .= '</div>';
369 $htmlString .= PMA_getHtmlForTableAxisLabelOptions($xaxis, $keys);
370 $htmlString .= PMA_getHtmlForAlternativeDataFormat(
371 $keys, $fields_meta, $numeric_types, $xaxis
373 $htmlString .= PMA_getHtmlForStartAndNumberOfRowsOptions($sql_query);
375 $htmlString .= PMA_getHtmlForChartAreaDiv();
377 $htmlString .= '</fieldset>'