完善数据可视化的详细展示功能,修改dbh类中得bug,增加Uuid类

This commit is contained in:
Li Jianxuan 2014-05-28 06:44:19 +00:00
parent c261d567be
commit d746b7b313
12 changed files with 1687 additions and 1418 deletions

View File

@ -36,7 +36,9 @@
</div>
</div>
<?php }else{ ?>
<?php $vars = explode(",",$this->info['vars']) ?>
<?php $vars = array() ?>
<?php $encoder = new \Westdc\Visual\VariableEncoder; ?>
<?php $vars = $encoder->decode($this->info['vars']);?>
<?php foreach($vars as $k=>$v) { ?>
<div class="control-group">
<label class="control-label" for="inputVariable">可视化要素 <small><a href="javascript:void(0);" onclick="delVar(this)">删除</a></small></label>

View File

@ -680,6 +680,9 @@ class DataController extends Zend_Controller_Action
$fund = new Fund($this->db);
$this->view->fund = $fund->fetch($uuid);
$visual = new \Westdc\Visual\Visual;
$this->view->visual = $visual->getVisualVars($uuid);
//判断特殊数据服务
$this->view->dataService= $this->checkDataService($uuid);

View File

@ -1,5 +1,7 @@
<?php
use Westdc\Visual\Factory;
use Westdc\Visual;
use Westdc\Metadata;
use Helpers\View as view;
class VisualController extends Zend_Controller_Action
{
@ -51,7 +53,7 @@ class VisualController extends Zend_Controller_Action
if(empty($record_type))
return true;
$record = Factory::Bootstrap($record_type);
$record = Visual\Factory::Bootstrap($record_type);
if(!empty($record_subset))
{
@ -64,6 +66,34 @@ class VisualController extends Zend_Controller_Action
}//dataAction() Ajax获取数据
//viewAction
public function viewAction()
{
$uuid = $this->_getParam('uuid');
if(empty($uuid) || \Helpers\Uuid::test($uuid) == false)
{
view::Post($this,"参数错误",-1);
return;
}
$visual = new Visual\Visual;
$this->view->data = $visual->getVisualVars($uuid);
if(empty($this->view->data))
{
view::Post($this,"此数据不支持可视化",-1);
return;
}
$metadata = new Metadata\Metadata;
$this->view->info = $metadata->view($uuid);
}
/*
* jsonexit() 退出并返回json数据

View File

@ -403,9 +403,14 @@ endforeach;
放入数据篮
</a>
<?php endif;endif; ?>
<a href="javascript:void(0);" class="btn btn-block" title="喜欢此数据可以将它放到收藏夹中下次浏览">
收藏此数据
<?php if(isset($this->visual['vars'])) { ?>
<a href="/visual/view/uuid/<?= $md->uuid ?>" class="btn btn-block" title="此数据支持在线可视化查看">
可视化查看
</a>
<?php } ?>
<!-- <a href="javascript:void(0);" class="btn btn-block" title="喜欢此数据可以将它放到收藏夹中下次浏览">
收藏此数据
</a> -->
</div>
</div>
<hr />

View File

@ -404,6 +404,11 @@ endforeach;
放入数据篮
</a>
<?php endif;endif; ?>
<?php if(isset($this->visual['vars'])) { ?>
<a href="/visual/view/uuid/<?= $md->uuid ?>" class="btn btn-block" title="此数据支持在线可视化查看">
可视化查看
</a>
<?php } ?>
<!--
<a href="javascript:void(0);" onclick="method.like('<?php echo $md->uuid; ?>',this)" class="btn btn-block" title="喜欢此数据可以将它放到收藏夹中下次浏览">
收藏此数据

View File

@ -0,0 +1,104 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle($this->config->title->data);
$this->headTitle()->setSeparator(' - ');
$theme = new Theme;
$theme->appendPlus($this,'highstock');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/data">数据与服务</a>');
$this->breadcrumb('数据可视化');
$this->breadcrumb()->setSeparator(' > ');
?>
<div class="row">
<div class="span12">
<h3><?= $this->info['title'] ?> <small>数据可视化查看</small></h3>
<hr />
<?php $vars = (new \Westdc\Visual\VariableEncoder)->normaldecode($this->data['vars']);?>
<?php foreach($vars as $k=>$v) { ?>
<a class="btn btn-default control-btn" href="javascript:void(0);" data-dataset="<?= $v['dataset'] ?>" data-subdataset="<?= $v['subdataset'] ?>" data-seriename="<?= $v['seriename'] ?>">
<?= $v['seriename'] ?>
</a>
<?php } ?>
</div>
<!-- 页面内容 -->
<div class="span12">
<div id="datachart" style="width:100%;height:500px;"></div>
<a class="btn btn-primary control-btn-cls" href="javascript:void(0);">
清除图像
</a>
</div>
<!-- //页面内容 -->
</div>
<script>
_this = {};
$(function() {
$('#datachart').highcharts('StockChart', {
rangeSelector : {
selected : 1,
inputEnabled: $('#container').width() > 480
},
credits : {
enabled : false
}
});
var chart = $('#datachart').highcharts();
$(".control-btn").click(function(){
dataset = $(this).data('dataset');
subdataset = $(this).data('subdataset');
seriename = $(this).data('seriename');
for(i in chart.series)
{
if(chart.series[i].name == seriename)
{
chart.series[i].remove();
return;
}
}
$.ajax({
'url': '/visual/data',
'data': 'dataset=' + dataset + '&subdataset=' + subdataset,
'method': 'GET',
'dataType': 'json',
'success': function(data){
chart.addSeries({
name: seriename,
data: data,
type : 'column'
});
},
'timeout': 30000,
'global' : true
});
});
$(".control-btn-cls").click(function(e) {
for(i in chart.series)
{
chart.series[i].remove();
}
});
});
$( document ).ajaxSend(function() {
$('#loading').css('display','none');
});
$( document ).ajaxSend(function() {
$('#loading').css('display','block');
});
$( document ).ajaxSend(function() {
$('#loading').css('display','none');
});
</script>

View File

@ -0,0 +1,48 @@
<?php
namespace Helpers;
// 三段
// 一段是微秒 一段是地址 一段是随机数
class Uuid
{
private $valueBeforeMD5;
private $valueAfterMD5;
function __construct()
{
$address = $this->getLocalHost();
$this->valueBeforeMD5 = $address.':'.$this->currentTimeMillis().':'.$this->nextLong();
$this->valueAfterMD5 = md5($this->valueBeforeMD5);
}
function toString()
{
$raw = strtoupper($this->valueAfterMD5);
return substr($raw,0,8).'-'.substr($raw,8,4).'-'.substr($raw,12,4).'-'.substr($raw,16,4).'-'.substr($raw,20);
}
private function nextLong()
{
$tmp = rand(0,1)?'-':'';
return $tmp.rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(100, 999).rand(100, 999);
}
private function currentTimeMillis()
{
list($usec, $sec) = explode(" ",microtime());
return $sec.substr($usec, 2, 3);
}
private function getLocalHost()
{
$address = isset($_ENV["COMPUTERNAME"]) ? $_ENV["COMPUTERNAME"]."/":"".'/';
$address.= $_SERVER["SERVER_ADDR"];
return strtolower($address);
}
static function test($uuid)
{
if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
return false;
}else{
return true;
}
}
}

View File

@ -105,7 +105,7 @@ class dbh
}
if(preg_match("/\"/",$v))
{
$v = preg_replace("/\"/","''",$v);
$v = preg_replace("/\"/","\"",$v);
}
$ups[] = '"'.$k.'"=\''.$v."'";
}

View File

@ -0,0 +1,28 @@
<?php
namespace Westdc\Metadata;
class Metadata
{
private $db; //传入PDO对象.
//使用到的公共变量
public $tbl_metadata = "metadata";
function __construct()
{
$this->db = \Zend_Registry::get('db');
}
function view($uuid)
{
if(\Helpers\Uuid::test($uuid) !== true)
{
return "参数错误";
}
$sql = "SELECT * FROM ".$this->tbl_metadata." WHERE uuid='$uuid'";
$rs = $this->db->query($sql);
return $rs->fetch();
}
}

View File

@ -6,7 +6,7 @@ use \Helpers\View as view;
use \Helpers\Table;
//事件中存在的操作
class VisualHandle
class VisualHandle extends \Westdc\Visual\VariableEncoder
{
private $db; //传入PDO对象误
private $config; //全局配置
@ -40,7 +40,7 @@ class VisualHandle
{
$data = $e->getParam('data');
$data['vars'] = join(",",$data['vars']);
$data['vars'] = $this->encode($data['vars']);
if(!isset($data['status']))
{

View File

@ -0,0 +1,44 @@
<?php
namespace Westdc\Visual;
class VariableEncoder
{
function __construct()
{
}
public function __invoke($json)
{
$this->decode($json);
}
public function encode($vars)
{
$arr = [];
foreach($vars as $k=>$v)
{
$names = explode("|",$v);
$arr[] = [ 'dataset' => $names[0], 'subdataset' => $names[1],'seriename' => $names[2]];
}
return json_encode($arr);
}
public function decode($json)
{
$arr = json_decode($json,true);
//var_dump($arr);
$data = [];
foreach($arr as $k=>$v)
{
$data[$k] = join("|",$v);
}
return $data;
}
public function normaldecode($json)
{
return json_decode($json,true);
}
}

View File

@ -95,6 +95,6 @@ class Visual
{
$sql = "SELECT * FROM {$this->mainTable} WHERE uuid='$uuid' LIMIT 1";
$rs = $this->db->query($sql);
return $rs->fetch();
return $rs->fetch(\PDO::FETCH_ASSOC);
}
}