Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
dbd263f765
@ -516,7 +516,7 @@ $(document).ready(function() {
|
||||
title: PMA_messages['strDataPointContent'],
|
||||
modal: true,
|
||||
buttons: buttonOptions,
|
||||
width: $('#dataDisplay').width() + 24,
|
||||
width: $('#dataDisplay').width() + 80,
|
||||
open: function () {
|
||||
$(this).find('input[type=checkbox]').css('margin', '0.5em');
|
||||
}
|
||||
|
||||
@ -1,260 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Generates the SVG needed for the plot
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
|
||||
require_once 'pma_svg_data_point.php';
|
||||
|
||||
class PMA_Scatter_Plot
|
||||
{
|
||||
/**
|
||||
* @var array Raw data for the plot
|
||||
*/
|
||||
private $_data;
|
||||
|
||||
/**
|
||||
* @var array Data points of the plot
|
||||
*/
|
||||
private $_dataPoints;
|
||||
|
||||
/**
|
||||
* @var array Set of default settigs values are here.
|
||||
*/
|
||||
private $_settings = array(
|
||||
|
||||
// Array of colors to be used for plot.
|
||||
'colors' => array(
|
||||
'#BCE02E',
|
||||
'#E0642E',
|
||||
'#E0D62E',
|
||||
'#2E97E0',
|
||||
'#B02EE0',
|
||||
'#E02E75',
|
||||
'#5CE02E',
|
||||
'#E0B02E',
|
||||
'#000000',
|
||||
'#0022E0',
|
||||
'#726CB1',
|
||||
'#481A36',
|
||||
'#BAC658',
|
||||
'#127224',
|
||||
'#825119',
|
||||
'#238C74',
|
||||
'#4C489B',
|
||||
'#87C9BF',
|
||||
),
|
||||
// Plot background color.
|
||||
'bgColor' => '#84AD83',
|
||||
|
||||
// The width of the plot.
|
||||
'width' => 520,
|
||||
|
||||
// The height of the plot.
|
||||
'height' => 325,
|
||||
|
||||
// Default X Axis label. If empty, label will be taken from the data.
|
||||
'xLabel' => '',
|
||||
|
||||
// Default Y Axis label. If empty, label will be taken from the data.
|
||||
'yLabel' => '',
|
||||
|
||||
// Data point label. If empty, label will be taken from the data.
|
||||
'dataLabel' => '',
|
||||
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array Options that the user has specified.
|
||||
*/
|
||||
private $_userSpecifiedSettings = null;
|
||||
|
||||
/**
|
||||
* Returns the settings array
|
||||
*
|
||||
* @return the settings array.
|
||||
*/
|
||||
public function getSettings()
|
||||
{
|
||||
return $this->_settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data array
|
||||
*
|
||||
* @return the data array.
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor. Stores user specified options.
|
||||
*
|
||||
* @param array $data Data for the visualization
|
||||
* @param array $options Users specified options
|
||||
*/
|
||||
public function __construct($data, $options)
|
||||
{
|
||||
$this->_userSpecifiedSettings = $options;
|
||||
$this->_data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* All the variable initialization, options handling has to be done here.
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
$this->_handleOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* A function which handles passed parameters. Useful if desired
|
||||
* chart needs to be a little bit different from the default one.
|
||||
*/
|
||||
private function _handleOptions()
|
||||
{
|
||||
$this->_dataPoints = array();
|
||||
if (! is_null($this->_userSpecifiedSettings)) {
|
||||
foreach (array_keys($this->_userSpecifiedSettings) as $key) {
|
||||
$this->_settings[$key] = $this->_userSpecifiedSettings[$key];
|
||||
}
|
||||
}
|
||||
if ($this->_settings['dataLabel'] == '') {
|
||||
$labels = array_keys($this->_data[0]);
|
||||
$this->_settings['dataLabel'] = $labels[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the visualization in SVG format.
|
||||
*
|
||||
* @return the generated image resource
|
||||
*/
|
||||
private function _svg()
|
||||
{
|
||||
$this->init();
|
||||
|
||||
$output = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . "\n";
|
||||
$output .= '<svg version="1.1" xmlns:svg="http://www.w3.org/2000/svg"'
|
||||
. ' xmlns="http://www.w3.org/2000/svg" width="' . $this->_settings['width'] . '"'
|
||||
. ' height="' . $this->_settings['height'] . '">';
|
||||
$output .= '<g id="groupPanel">';
|
||||
$output .= '<defs>
|
||||
<path id="myTextPath1"
|
||||
d="M10,190 L10,50"/>
|
||||
<path id="myTextPath2"
|
||||
d="M250,10 L370,10"/>
|
||||
</defs>';
|
||||
$output .= '<text x="6" y="190" style="font-family: Arial; font-size : 54; stroke:none; fill:#000000;" >
|
||||
<textPath xlink:href="#myTextPath1" >';
|
||||
$output .= $this->_settings['yLabel'];
|
||||
$output .= '</textPath>
|
||||
</text>';
|
||||
|
||||
$output .= '<text x="250" y="10" style="font-family: Arial; font-size : 54; stroke:none; fill:#000000;" >
|
||||
<textPath xlink:href="#myTextPath2" >';
|
||||
$output .= $this->_settings['xLabel'];
|
||||
$output .= '</textPath>
|
||||
</text>';
|
||||
|
||||
|
||||
$scale_data = $this->_scaleDataSet($this->_data, $this->_settings['xLabel'], $this->_settings['yLabel']);
|
||||
$output .= $this->_prepareDataSet($this->_data, 0, $scale_data, $this->_settings['dataLabel']);
|
||||
|
||||
$output .= '</g>';
|
||||
$output .= '</svg>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the visualization as a SVG.
|
||||
*
|
||||
* @return the visualization as a SVG
|
||||
*/
|
||||
public function asSVG()
|
||||
{
|
||||
$output = $this->_svg();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the scale, horizontal and vertical offset that should be used.
|
||||
*
|
||||
* @param array $data Row data
|
||||
*
|
||||
* @return an array containing the scale, x and y offsets
|
||||
*/
|
||||
private function _scaleDataSet($data, $xField, $yField)
|
||||
{
|
||||
|
||||
// Currently assuming only numeric fields are selected
|
||||
$coordinates = array();
|
||||
foreach ($data as $row) {
|
||||
$coordinates[0][] = $row[$xField];
|
||||
$coordinates[1][] = $row[$yField];
|
||||
}
|
||||
for ($i = 0 ; $i < 2 ; $i++) {
|
||||
$maxC = ($i == 0) ? 500 : 320;
|
||||
|
||||
if ( !is_numeric($coordinates[$i][0])) {
|
||||
$uniqueC = array_unique($coordinates[$i]);
|
||||
$countC = count(array_unique($coordinates[$i]));
|
||||
$map = $tmp = array();
|
||||
foreach ($uniqueC as $uc) {
|
||||
$tmp[] = $uc;
|
||||
}
|
||||
for ($j = 0 ; $j < $countC ; $j++) {
|
||||
$map[$tmp[$j]] = 20 + $j * $maxC / $countC;
|
||||
}
|
||||
for ($j = 0 ; $j < count($coordinates[$i]) ; $j++) {
|
||||
$coordinates[$i][$j] = $map[$coordinates[$i][$j]];
|
||||
}
|
||||
} else if (is_numeric($coordinates[$i][0])) {
|
||||
$maxC = max($coordinates[$i]);
|
||||
for ($j = 0 ; $j < count($coordinates[$i]) ; $j++) {
|
||||
if ($i == 0) {
|
||||
$coordinates[$i][$j] = 20 + 500 * $coordinates[$i][$j] / $maxC;
|
||||
} else {
|
||||
$coordinates[$i][$j] = 20 + 320 * (1 - $coordinates[$i][$j] / $maxC);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $coordinates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares and return the dataset as needed by the visualization.
|
||||
*
|
||||
* @param array $data Raw data
|
||||
* @param int $color_number Start index to the color array
|
||||
* @param array $scale_data Data related to scaling
|
||||
* @param string $label Label for the data points
|
||||
* @return string the formatted array of data.
|
||||
*/
|
||||
private function _prepareDataSet($data, $color_number, $scale_data, $label)
|
||||
{
|
||||
$result = '';
|
||||
// loop through the rows
|
||||
for ($i = 0 ; $i < count($data) ; $i++) {
|
||||
|
||||
$index = $color_number % sizeof($this->_settings['colors']);
|
||||
|
||||
$data_element = new PMA_SVG_Data_Point($scale_data[0][$i], $scale_data[1][$i], $data[$i][$label], $data[$i]);
|
||||
|
||||
$options = array('color' => $this->_settings['colors'][$index], 'id' => $i);
|
||||
$this->_dataPoints[] = $data_element;
|
||||
|
||||
$result .= $data_element->prepareRowAsSVG($options);
|
||||
$color_number++;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Base class for the plot data type classes.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
abstract class PMA_SVG_Data_Element
|
||||
{
|
||||
protected $label = '';
|
||||
|
||||
protected $dataRow = array();
|
||||
|
||||
/**
|
||||
* Store user specified label and dataRow
|
||||
* @param string $label users specified label
|
||||
* @param array $dataRow A data row from the query result
|
||||
*/
|
||||
function __construct($label,$dataRow)
|
||||
{
|
||||
$this->label = $label;
|
||||
$this->dataRow = $dataRow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the generation of each Data Row/Element as a SVG element
|
||||
* @return the code related to a row in the GIS dataset
|
||||
*/
|
||||
public abstract function prepareRowAsSVG($options);
|
||||
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setLabel($label)
|
||||
{
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
public function getDataRow()
|
||||
{
|
||||
return $this->dataRow;
|
||||
}
|
||||
|
||||
public function setDataRow($dataRow)
|
||||
{
|
||||
$this->dataRow = $dataRow;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,83 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Handles the visualization of Data Point objects.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
|
||||
require_once 'pma_svg_data_element.php';
|
||||
|
||||
class PMA_SVG_Data_Point extends PMA_SVG_Data_Element
|
||||
{
|
||||
/*
|
||||
* X-Coordinate of the point
|
||||
*/
|
||||
private $cx;
|
||||
|
||||
/*
|
||||
* Y-Coordinate of the point
|
||||
*/
|
||||
private $cy;
|
||||
|
||||
/*
|
||||
* A private constructor; prevents direct creation of object.
|
||||
*/
|
||||
public function __construct($cx, $cy, $label, $dataRow)
|
||||
{
|
||||
parent::__construct($label, $dataRow);
|
||||
$this->cx = $cx;
|
||||
$this->cy = $cy;
|
||||
}
|
||||
|
||||
public function prepareRowAsSVG($options)
|
||||
{
|
||||
return $this->prepareSvg($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares and returns the code related to a row in the query result as SVG.
|
||||
*
|
||||
* @param array $options Array containing options related to properties of the point
|
||||
* @return the code related to a row in the query result.
|
||||
*/
|
||||
protected function prepareSvg($options)
|
||||
{
|
||||
$point_options = array(
|
||||
'name' => $this->label . '_' .$options['id'],
|
||||
'id' => $this->label . 'id' . '_' . $options['id'],
|
||||
'class' => 'point',
|
||||
'fill' => 'white',
|
||||
'stroke' => $options['color'],
|
||||
'stroke-width'=> 2,
|
||||
);
|
||||
|
||||
$row = '<circle cx="' . $this->cx . '" cy="' . $this->cy . '" r=".1"';
|
||||
foreach ($point_options as $option => $val) {
|
||||
$row .= ' ' . $option . '="' . trim($val) . '"';
|
||||
}
|
||||
$row .= '/>';
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function getCx()
|
||||
{
|
||||
return $this->cx;
|
||||
}
|
||||
|
||||
public function setCx($cx)
|
||||
{
|
||||
$this->cx = $cx;
|
||||
}
|
||||
|
||||
public function getCy()
|
||||
{
|
||||
return $this->cy;
|
||||
}
|
||||
|
||||
public function setCy($cy)
|
||||
{
|
||||
$this->cy = $cy;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -129,7 +129,7 @@ function PMA_tbl_getSubTabs()
|
||||
* @param int $foreignMaxLimit Max limit of displaying foreign elements
|
||||
* @param array $fields Array of search criteria inputs
|
||||
* @param bool $in_fbs Whether we are in 'function based search'
|
||||
* @param bool $in_zoom_search_edit Whether we are in zoom search edit
|
||||
* @param bool $in_zoom_search_edit Whether we are in zoom search edit
|
||||
*
|
||||
* @return string HTML content for viewing foreing data and elements
|
||||
* for search criteria input.
|
||||
@ -382,33 +382,4 @@ function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, $fu
|
||||
|
||||
return $w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a SVG plot for the query results.
|
||||
*
|
||||
* @param array $data Data for the status chart
|
||||
* @param array &$settings Settings used to generate the chart
|
||||
*
|
||||
* @return string HTML and JS code for the SVG plot
|
||||
*/
|
||||
function PMA_SVG_scatter_plot($data, &$settings)
|
||||
{
|
||||
include_once './libraries/svg_plot/pma_scatter_plot.php';
|
||||
|
||||
if (empty($data)) {
|
||||
// empty data
|
||||
return '';
|
||||
} else {
|
||||
$scatter_plot = new PMA_Scatter_Plot($data, $settings);
|
||||
|
||||
if ($settings != null) {
|
||||
foreach ($scatter_plot->getSettings() as $setting => $val) {
|
||||
if (! isset($settings[$setting])) {
|
||||
$settings[$setting] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $scatter_plot->asSVG();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user