Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: KohPoll/vgraph
base: 35be2f6f16
...
head fork: KohPoll/vgraph
compare: e35eaba7b0
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 60 additions and 31 deletions.
  1. +1 −0  css/vgraph-main.css
  2. +6 −3 index.html
  3. +53 −28 js/graph.js
View
1  css/vgraph-main.css
@@ -412,6 +412,7 @@ body {
padding: 5px;
background: #fee;
color: white;
+ width: 100px;
}
#datainfo ul {
list-style: none;
View
9 index.html
@@ -85,6 +85,10 @@ <h1 class="title">
dataCache: {},
init: function() {
this.bindEvent();
+ this.graph = null;
+ },
+ searchGraph: function(s) {
+ this.graph && this.graph.search(s);
},
drawGraphByJson: function(jsonData, type, level) {
level = level || '0';
@@ -92,6 +96,7 @@ <h1 class="title">
var graph = new Graph('#placeHolder', '#dataContainer', type);
graph.render(jsonData);
graph.levelMapper[level]();
+ this.graph = graph;
},
drawGraph: function(type, level) {
//console.log(this.dataCache);
@@ -150,9 +155,7 @@ <h1 class="title">
var input = $('#search-key'),
search_key = input.val();
- console.log(search_key);
-
- //
+ self.searchGraph(search_key);
});
}
};
View
81 js/graph.js
@@ -249,11 +249,8 @@
// if(! $.browser.msie) console.timeEnd('renderData');
};
- Graph.prototype.hoverTip = function() {
- // if(! $.browser.msie) console.time('hoverTip');
- var prevPoint = null, self = this,
- placeHolder = this.placeHolder,
- tmpl = function(str, data) {
+ function showDataInfo(mouseX, mouseY, num, bgColor, fToText, container) {
+ var tmpl = function(str, data) {
var rst = '', reg = /\{(\w+)\}/g;
rst = str.replace(reg, function(match, dataKey) {
return data[dataKey];
@@ -263,28 +260,41 @@
tmplStr = '<ul><li><em>编号: </em>{n}</li>' +
'<li><em>内容: </em>{d}</li>' +
'<li><em>频数: </em>{f}</li>' +
- '<li><em>级别: </em>{l}</li></ul>',
+ '<li><em>级别: </em>{l}</li></ul>';
+
+ var idx = parseInt(num, 10) - 1;
+ var info = tmpl(tmplStr, {
+ n: num,
+ d: this.dataInfo[idx].d,
+ f: this.dataInfo[idx].f,
+ l: fToText[this.dataInfo[idx].l - 1]
+ });
+ //console.log(this.dataInfo[idx]);
+ //console.log(info);
+
+ var top, left;
+ if (container) {
+ mouseY = 400 - (mouseY / this.dataInfo[0].f * 400);
+ mouseX = (mouseX / this.dataInfo.length * 700) + 40;
+ }
+ top = mouseY - 20;
+ left = mouseX + 5;
+
+ $('<div id="datainfo">')
+ .html(info)
+ .css({
+ backgroundColor: bgColor,
+ top: top,
+ left: left
+ }).appendTo(container || 'body').fadeIn(200);
+ };
+
+ Graph.prototype.hoverTip = function() {
+ // if(! $.browser.msie) console.time('hoverTip');
+ var prevPoint = null, self = this,
+ placeHolder = this.placeHolder,
fToText = ['', '', '', ''],
- showDataInfo = function(mouseX, mouseY, num, bgColor) {
- var idx = parseInt(num, 10) - 1;
- var info = tmpl(tmplStr, {
- n: num,
- d: this.dataInfo[idx].d,
- f: this.dataInfo[idx].f,
- l: fToText[this.dataInfo[idx].l - 1]
- });
- //console.log(this.dataInfo[idx]);
- //console.log(info);
-
- $('<div id="datainfo">')
- .html(info)
- .css({
- backgroundColor: bgColor,
- top: mouseY - 20,
- left: mouseX + 5
- }).appendTo('body').fadeIn(200);
- },
- clearDataRangeList = function ()
+ clearDataRangeList = function ()
{
if ($('#data-table'))
{
@@ -334,7 +344,7 @@
$('#datainfo').remove();
var num = item.datapoint[0]; //编号
- showDataInfo.apply(self, [item.pageX, item.pageY, num, item.series.color]);
+ showDataInfo.apply(self, [item.pageX, item.pageY, num, item.series.color, fToText]);
// console.log(item);
// showDataRangeList(num, 5);
@@ -509,7 +519,22 @@
// if(! $.browser.msie) console.timeEnd('getRangeByCenter');
return ret_arr;
- }
+ };
+
+ Graph.prototype.search = function(key) {
+ $('#datainfo').remove();
+
+ var dataInfo = this.dataInfo,
+ color = Graph.__color;
+
+ for (var i=0, len=dataInfo.length; i<len; ++i) {
+ if (dataInfo[i].d === key) {
+ this.scrollTo(i+1, color[dataInfo[i].l-1]);
+
+ showDataInfo.apply(this, [i, dataInfo[i].f, i+1, color[dataInfo[i].l-1], ['','','',''], this.placeHolder]);
+ }
+ }
+ };
window.Graph = Graph;
})(jQuery);

No commit comments for this range

Something went wrong with that request. Please try again.