Related
<style type="text/css">
#container {***strong text***
/*width: auto;*/
height: auto;
margin:0 auto;
position:relative;
}
#center-container {
/*width:770px;*/
left:200px;
background-color:#FFF;
color:#ccc;
width: 100%;
}
#infovis {
position:center;
width:auto;
margin:auto;
height: 800px !important;
overflow-y:hidden !important;
}
#infovis-canvas,#info-canvas
{
position: absolute;
top: 0px;
left: 0px;
width: 1078px;
height: 800px;
background: white;
}
#info {
position:center;
width:auto;
height: 800px !important;
margin:auto;
overflow-y:hidden !important;
}
#NetworkGraphView {
position: center;
width:100%;
height: 100%;
margin: auto;
overflow: hidden !important;
}
.chartbar{
text-align: center;
display: table-cell;
vertical-align: middle;
height: 34px;
}
.chartbar p {
display: inline-block;
vertical-align: top;
font-size: 10px;
margin: 0px 5px 0px 0px;
float: right;
}
.searchSteps{
float: right;
}
.infobar{
margin-right: 0px;
margin-left: 100px;
text-align: center;
}
</style>
<script language="javascript" type="text/javascript" src="<?php echo BASEURL; ?>app/webroot/jitcharts/js/jit-yc.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo BASEURL; ?>app/webroot/jitcharts/js/jit.js"></script>
<link type="text/css" href="<?php echo BASEURL; ?>app/webroot/jitcharts/css/base.css" rel="stylesheet" />
<link type="text/css" href="<?php echo BASEURL; ?>app/webroot/jitcharts/css/Spacetree.css" rel="stylesheet" />
<script language="javascript" type="text/javascript" src="<?php echo BASEURL; ?>app/webroot/jitcharts/js/jit-yc.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo BASEURL; ?>app/webroot/jitcharts/js/jit.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo BASEURL; ?>app/webroot/jitcharts/js/excanvas.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo BASEURL; ?>app/webroot/d3.min.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo BASEURL; ?>app/webroot/html2canvas.js"></script>
<script language="javascript" type="text/javascript">
var approve_counter = 0;
var pending_counter = 0;
var flag = 0;
var fd = '';
function traverse(arr) {
var len = arr.length;
for(var i=0; i < len; i++) {
$jit.json.each(arr[i], function(n) {
n.data.$orn = arr[i]['status'];
n.data.$shape = arr[i]['shape'];
n.data.$S_status = arr[i]['S_status'];
});
traverse(arr[i].children);
}
}
var labelType, useGradients, nativeTextSupport, animate;
(function() {
var ua = navigator.userAgent,
iStuff = ua.match(/iPhone/i) || ua.match(/iPad/i),
typeOfCanvas = typeof HTMLCanvasElement,
nativeCanvasSupport = (typeOfCanvas == 'object' || typeOfCanvas == 'function'),
textSupport = nativeCanvasSupport
&& (typeof document.createElement('canvas').getContext('2d').fillText == 'function');
labelType = (!nativeCanvasSupport || (textSupport && !iStuff))? 'Native' : 'HTML';
nativeTextSupport = labelType == 'Native';
useGradients = nativeCanvasSupport;
animate = !(iStuff || !nativeCanvasSupport);
})();
var Log = {
elem: false,
write: function(text){
if (!this.elem)
this.elem = document.getElementById('log');
this.elem.innerHTML = text;
this.elem.style.left = (500 - this.elem.offsetWidth / 2) + 'px';
}
};
function init(){
//init data
var json = {
id: "<?php echo $BatchNo . ', ' . $StepName; ?>",
name: "<?php
if ($gtype == 'buffer') {
echo $BatchNo . ': ' . $bufferName;
} else {
echo $BatchNo . ', ' . $StepName;
}
?>",
data: {},
children: [<?php echo $str; ?>]
};
var arr = json.children, len = arr.length;
traverse(arr);
var normal = $jit.id('s-normal');
$j(document).ready(function() {
});
function networkgraph() {
fd = new $jit.ForceDirected({
injectInto: 'infovis',
iterations: 200,
levelDistance: 130,
withLabels:true,
Navigation: {
enable: true,
type: 'Native',
panning: 'avoid nodes',
zooming: 10
},
Label:{
size: 4,
style: 'bold',
color: '#23A4FF',
},
Node: {
overridable: false,
type: 'rectangle',
color: 'Blue',
width:10,
height:10,
dim: 3,
lineWidth: 1,
transform: true,
align: "center",
angularWidth:1,
},
Edge:{
overridable: true,
type: 'line', //'hyperline'
color: '#23A4FF',
lineWidth: 1
},
Events:{
enable: true,
type: 'Native',
enableForEdges: true,
onMouseEnter: function() {
fd.canvas.getElement().style.cursor = 'move';
},
onMouseLeave: function() {
fd.canvas.getElement().style.cursor = '';
},
onDragMove: function(node, eventInfo, e) {
var pos = eventInfo.getPos();
node.pos.setc(pos.x, pos.y);
fd.plot();
},
onTouchMove: function(node, eventInfo, e) {
$jit.util.event.stop(e); //stop default touchmove event
this.onDragMove(node, eventInfo, e);
},
onClick: function (node, eventInfo, e){
if (!node) return;
if (node.nodeFrom && node.nodeTo) {
if(node.selected){
node.setDataset('current', {
lineWidth: 1,
color: '#23a4ff',
});
node.selected = false;
}else{
node.setDataset('current', {
lineWidth: 4,
color: '#ff0000'
});
node.selected = true;
}
} else {
if(!node.selected) {
node.selected = true;
node.setData('dim', 3, 'end');
node.eachAdjacency(function(adj) {
adj.setDataset('current', {
lineWidth: 4,
color: '#ff0000'
});
adj.selected=true;
});
} else {
delete node.selected;
node.setData('dim', 7, 'end');
node.eachAdjacency(function(adj) {
adj.setDataset('current', {
lineWidth: 1,
color: '#23a4ff',
});
adj.selected=false;
});
}
}
fd.fx.animate({
modes: ['node-property:dim','edge-property:lineWidth:color'],
duration: 5
});
}
},
onCreateLabel: function(label, node){
console.log(label);
console.log(node);
console.log(node.id);
label.id = node.id;
label.innerHTML = node.name;
var style = label.style;
style.color = "#ff0000";
<?php if ($gtype != 'buffer') {?>
if(flag==0){
Selected_batch_status = '<?php echo $Selected_batch_status;?>'
if(Selected_batch_status == 'approved'){
style.color = '#333';
approve_counter = approve_counter + 1;
}else{
style.color = '#ff0000';
pending_counter = pending_counter + 1;
}
flag=1;
}else{
if(node.data.$S_status=='approved'){
style.color = '#333';
approve_counter = approve_counter + 1;
}else if(node.data.$S_status == 'no record'){
style.color = '#00F';
}else{
style.color = '#ff0000';
pending_counter = pending_counter + 1;
}
}
<?php }
else{
?>
style.color = '#333';
<?php }?>
style.fontSize = '11px';
// style.background = 'lightgreen';
style.cursor = 'pointer';
style.textAlign= 'center';
style.paddingTop = '5px';
},
onBeforePlotNode: function(node){
function setLabelScaling() {
var x = fd.canvas.scaleOffsetX,
y = fd.canvas.scaleOffsetY;
$j(".node").css("-moz-transform", "scale(" + x +"," + y + ")");
$j(".node").css("-webkit-transform", "scale(" + x +"," + y + ")");
$j(".node").css("-ms-transform", "scale(" + x +"," + y + ")");
$j(".node").css("-o-transform", "scale(" + x +"," + y + ")");
}
setLabelScaling();
if(node.data.$shape=='circle') {
node.data.$type = "circle";
node.data.$radius = "50";
node.data.$color = "#990000";
}
if (node.selected) {
node.data.$color = "#990000";
node.data.$radius = "50";
node.Label.style.color = "#990000";
}
else {
if(node.data.$shape !='circle') {
delete node.data.$color;
}
if(!node.anySubnode("exist") && node.data.$shape !='circle') {
var count = 0;
node.eachSubnode(function(n) { count++; });
}
}
},
// onPlaceLabel: function(domElement, node){
// var style = domElement.style;
// var left = parseInt(style.left);
// var top = parseInt(style.top);
// var w = domElement.offsetWidth;
// style.left = (left - w / 2) + 'px';
// style.top = (top + 10) + 'px';
// style.display = '';
// }
});
fd.loadJSON(json);
// compute positions incrementally and animate.
fd.computeIncremental({
iter: 40,
property: 'end',
onStep: function(perc){
},
onComplete: function(){
// Log.write('done');
fd.animate({
modes: ['linear'],
transition: $jit.Trans.Elastic.easeOut,
duration: 2500
});
}
});
$j("#searchSteps").keyup(function(){
var src_str = $j("#infovis").html();
var term = $j("#searchSteps").val().toLowerCase();
term = term.replace(/(\s+)/,"(<[^>]+>)*$1(<[^>]+>)*");
var pattern = new RegExp("("+term+")", "gi");
src_str = src_str.replace(pattern, "<mark>$1</mark>");
src_str = src_str.replace(/(<mark>[^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/,"$1</mark>$2<mark>$4");
$j("#infovis").html(src_str);
/*$jit.Graph.Util.eachNode(fd.graph, function(node) {
if(node.name.toLowerCase().indexOf($j("#searchSteps").val().toLowerCase()) > 0){
alert("Hello");
// fd.graph.Label.color="#FFFF00 !important";
// $jit.Graph.Util.labels.getLabel(node.id).backgroud = 'red';
// $j("").css({"background-color": "yellow", "font-size": "200%"});
console.log(fd.graph);
// console.log('Mukesh');
}
}); */
});
}
function spacetree(){
var st = new $jit.ST({
constrained: false,
levelsToShow: 100,
injectInto: 'info',
multitree: true,
withLabels:true,
duration: 400,
transition: $jit.Trans.Quart.easeInOut,
levelDistance: 50,
siblingOffset: 20,
subtreeOffset: 20,
Node: {
height: 60,
width: 120,
type: 'rectangle',
color: '#ffd',
overridable: true,
CanvasStyles: {
shadowColor: '#000',
shadowBlur: 1
}
},
Label:{
size: 6,
style: 'bold',
color: '#23A4FF',
type:'Native'
},
Edge: {
type: 'line',
overridable: true
},
Navigation: {
enable: true,
panning: true,
zooming: 50
},
onCreateLabel: function(label, node){
console.log(label);
console.log(node);
console.log(node.id);
label.id = node.id;
label.innerHTML = node.name;
label.onclick = function(){
return false;
};
var style = label.style;
style.width = 100 + 'px';
style.height = 50 + 'px';
<?php if ($gtype != 'buffer') {?>
if(flag==0){
Selected_batch_status = '<?php echo $Selected_batch_status;?>'
if(Selected_batch_status == 'approved'){
style.color = '#333';
approve_counter = approve_counter + 1;
}else{
style.color = '#ff0000';
pending_counter = pending_counter + 1;
}
flag=1;
}else{
if(node.data.$S_status=='approved'){
style.color = '#333';
approve_counter = approve_counter + 1;
}else if(node.data.$S_status == 'no record'){
style.color = '#00F';
}else{
style.color = '#ff0000';
pending_counter = pending_counter + 1;
}
}
<?php }else{
?>
style.color = '#333';
<?php }?>
style.fontSize = '0.9em';
style.textAlign= 'center';
style.paddingTop = '7.5px';
},
onBeforePlotNode: function(node){
function setLabelScaling() {
var x = st.canvas.scaleOffsetX,
y = st.canvas.scaleOffsetY;
$j(".node").css("-moz-transform", "scale(" + x +"," + y + ")");
$j(".node").css("-webkit-transform", "scale(" + x +"," + y + ")");
$j(".node").css("-ms-transform", "scale(" + x +"," + y + ")");
$j(".node").css("-o-transform", "scale(" + x +"," + y + ")");
}
// setLabelScaling();
if(node.data.$shape=='circle') {
node.data.$color = "#0ff";
}
if (node.selected) {
node.data.$color = "#ffa";
node.Label.style.color = "#333";
}
else {
if(node.data.$shape !='circle') {
delete node.data.$color;
}
if(!node.anySubnode("exist") && node.data.$shape !='circle') {
var count = 0;
node.eachSubnode(function(n) { count++; });
}
}
},
onMouseWheel: function(){
function setLabelScaling() {
var x = st.canvas.scaleOffsetX,
y = st.canvas.scaleOffsetY;
$j(".node").css("-moz-transform", "scale(" + x +"," + y + ")");
$j(".node").css("-webkit-transform", "scale(" + x +"," + y + ")");
$j(".node").css("-ms-transform", "scale(" + x +"," + y + ")");
$j(".node").css("-o-transform", "scale(" + x +"," + y + ")");
}
// setLabelScaling();
},
onBeforePlotLine: function(adj){
if (adj.nodeFrom.selected && adj.nodeTo.selected) {
adj.data.$color = "#eed";
adj.data.$lineWidth = 3;
}
else {
delete adj.data.$color;
delete adj.data.$lineWidth;
}
}
});
st.loadJSON(json);
//compute node positions and layout
st.compute('end');
st.select(st.root);
}
$j(document).ready(function(){
spacetree();
networkgraph();
$j("#info").show();
$j("#infovis").hide();
$j("#ShowSpacetree").hide();
$j(".searchSteps").hide();
$j("#Shownetwork").click(function () {
$j("#info").hide();
$j("#infovis").show();
$j("#Shownetwork").hide();
$j("#ShowSpacetree").show();
$j(".searchSteps").show();
var element = $j("#infovis"); // global variable
var getCanvas; // global variable
html2canvas(element, {
onrendered: function (canvas) {
$j("#previewImage").append(canvas);
getCanvas = canvas;
$j("#previewImage").hide();
}
});
$j("#downloadimage").on('click', function () {
var imgageData = getCanvas.toDataURL("image/jpeg");
var newData = imgageData.replace(/^data:image\/jpeg/, "data:application/octet-stream");
$j("#downloadimage").attr("download", "Networkgrap.jpeg").attr("href", newData);
});
} );
$j("#ShowSpacetree").click(function () {
$j("#info").show();
$j("#infovis").hide();
$j("#Shownetwork").show();
$j("#ShowSpacetree").hide();
$j(".searchSteps").hide();
var element = $j("#info"); // global variable
var getCanvas; // global variable
html2canvas(element, {
onrendered: function (canvas) {
$j("#previewImage").append(canvas);
getCanvas = canvas;
getCanvas.fillStyle = "blue";
$j("#previewImage").hide();
}
});
$j("#downloadimage").on('click', function () {
var imgageData = getCanvas.toDataURL("image/jpeg");
var newData = imgageData.replace(/^data:image\/jpeg/, "data:application/octet-stream");
$j("#downloadimage").attr("download", "Spacetree.jpeg").attr("href", newData);
});
} );
$j("#infovis").click(function () {
var element = $j("#infovis"); // global variable
var getCanvas; // global variable
html2canvas(element, {
onrendered: function (canvas) {
$j("#previewImage").append(canvas);
getCanvas = canvas;
getCanvas.fillStyle = "blue";
$j("#previewImage").hide();
}
});
$j("#downloadimage").on('click', function () {
var imgageData = getCanvas.toDataURL("image/jpeg");
var newData = imgageData.replace(/^data:image\/jpeg/, "data:application/octet-stream");
$j("#downloadimage").attr("download", "Networkgrap.jpeg").attr("href", newData);
});
} );
$j("#info").click(function () {
var element = $j("#info"); // global variable
var getCanvas; // global variable
html2canvas(element, {
onrendered: function (canvas) {
$j("#previewImage").append(canvas);
getCanvas = canvas;
getCanvas.fillStyle = "blue";
$j("#previewImage").hide();
}
});
$j("#downloadimage").on('click', function () {
var imgageData = getCanvas.toDataURL("image/jpeg");
var newData = imgageData.replace(/^data:image\/jpeg/, "data:application/octet-stream");
$j("#downloadimage").attr("download", "Spacetree.jpeg").attr("href", newData);
});
} );
});
var total = pending_counter + approve_counter;
var per_approved = Math.round((approve_counter/total)*100);
var str = '(Current Lot Tree is '+per_approved+'% approved)';
$j('#insight').html(str);
}
setTimeout("init();", 500);
</script>
<div id="chart1">
<?php if ($gtype != 'buffer'){?>
<div class="row container">
<div class="col-lg-12 infobar">
<div class="col-lg-5">
<div class="input-group searchSteps">
<input type="text" class="form-control" id="searchSteps" placeholder="Search">
<span class="input-group-addon"><i class="fa fa-search"></i></span>
</div>
</div>
<div class=" chartbar col-lg-7">
<p id="insight"></p>
<p style="color: #00F">*Blue = Not Recorded</p>
<p style=" color: black">*Black = Approved</p>
<p style=" color: red">*Red = Not Approved</p>
</div>
</div>
</div>
<?php } ?>
<div class="row">
<div class="col-lg-11 col-md-8">
<div id="container">
<div id="center-container">
<div id="info">
</div>
<div id="infovis">
</div>
<!-- <div id="info"></div>
<div id="infovis" hiddden></div> -->
</div>
<div id="log"></div>
</div>
</div>
<div class="col-lg-1 col-md-4">
<ul class="nav nav-stacked navbar-right">
<li class="rpanel_item" id="Shownetwork" title="Show Network">
<a aria-expanded="false"><i class="fa fa-2x fa-table"></i></a>
</li>
<li class="rpanel_item" id="ShowSpacetree" title="Show Space tree">
<a aria-expanded="true"><i class="fa fa-share-alt fa-2x"></i></a>
</li>
<li class="rpanel_item" title="download chart">
<a id="downloadimage">
<i class="fa fa-download fa-2x"></i>
</a>
</li>
</ul>
</div>
</div>
</div>
I am using JIT Graph to generate space tree and force directed graph in switchable 'divs', which is getting populated when switched to corresponding div. The data for nodes are coming from back-end.
while switching to one graph from other the label in the active graph is getting disturb.
How to generate distinct labels for both the graphs.
and thank you once again for your expert support. I have a rather nice implementation of flot, that has one very unfortunate bug. The plot routine works in a loop, so it creates as many plots as there are data files, that pass muster, in the directory. If there is only one data file, then only one plot, the resulting flot plot works fine and the check boxes turn the lines on and off as expected. If I have more than one data file and hence more than one flot plot.. only the bottom one seems to work correctly, the remainder lock up after either one toggle or none.
Can someone give me an idea how to create the flot plots so they do not interfere? I have read elsewhere that the function name does not need to be different, but have not verified this, and I did change the labels, but this added additional weirdness.
Quite a long code.. but it gives you most of what I know...
The first section here actually builds the data sets for flot... then the rest creates the plot...
<script type='text/javascript'>//<![CDATA[
$(function(){
var results = [
<?php
$downsample = 5;
for($k=0;$k<2; $k++){
//$k =0 is Left, $k = 1 is right
if ($k==0){
$side = "L";
$offset = 1;
} elseif ($k==1) {
$side = "R";
$offset = 0;
}
for ($m = 1; $m <= count($trackdata)-1; $m++){
echo "\n{\n\"label\": \"".$m.$side."\",\n"; //echo "\n{\n\"label\": \"".$m." ".$side."\",\n";
echo "\"data\": [";
for ($n=1;$n<=count($PSD[$m*3-2]);$n=$n+$downsample){
$tmp = "[".$PSD[$m*3-2][$n].",".$PSD[$m*3-$offset][$n]."]";
echo $tmp;
if ($n > count($PSD[$m*3-2])-$downsample){
echo "]}";
} else {
echo ",";
}
}
if ($m <> count($trackdata)-1){
echo ",";
} else if ($k<1){
echo ",";
}
}
}
echo "];";
?>
var options = {
legend: {
show: true
},
series: {
points: {
show: false
},
lines: {
show: true
}
},
grid: {
hoverable: true
},
xaxis: {
},
yaxis: {
}
};
var i = 0;
var track = 0;
choiceContainer = $("#labeler<?php echo $i ?>");
var table = $('<table />');
var row = $('<tr/>');
var cell = $('<td width=\"100\"/>');
var temp = $(table);
$.each(results, function(key, val) {
track = track + 1;
val.color = i;
++i;
l = val.label;
if (track == 1){
temp.append(row);
row.append(cell);
cell.append('Left Channel');
} else if(track == <?php echo $tracks ?>){
row = $('<tr/>');
temp.append(row);
cell = $('<td width=\"100\">');
row.append(cell);
cell.append('Right Channel');
} //else if ((track == 7) or (track == 14) or (track == 21) or (track == 28) or (track == 35)){
//}
cell = $('<td width=\"60\"/>');
row.append(cell);
var bar = $('<div style=\"width:18px; white-space:nowrap; float:left\"><bar />');
cell.append(bar);
var inp = $('<input name="' + l + '" id="' + l + '" type="checkbox" checked="checked">');
cell.append(inp);
var bits = $('<label>', {
text: l,
'for': l
});
cell.append(bits);
choiceContainer.append(temp);
});
function plotAccordingToChoices() {
var data = [];
choiceContainer.find("input:checked").each(function() {
var key = this.name;
for (var i = 0; i < results.length; i++) {
if (results[i].label === key) {
data.push(results[i]);
return true;
}
}
});
$.plot($("#placeholder<?php echo $i ?>"), data, options);
}
var previousPoint = null;
$("#placeholder<?php echo $i ?>").bind("plothover", function(event, pos, item) {
$("#x").text(pos.x.toFixed(2));
$("#y").text(pos.y.toFixed(2));
if (item) {
if (previousPoint != item.datapoint) {
previousPoint = item.datapoint;
$("#tooltip").remove();
var x = item.datapoint[0].toFixed(2),
y = item.datapoint[1].toFixed(2);
showTooltip(item.pageX, item.pageY, item.series.label + " $" + y);
}
} else {
$("#tooltip").remove();
previousPoint = null;
}
});
function showTooltip(x, y, contents) {
$('<div id="tooltip">' + contents + '</div>').css({
position: 'absolute',
display: 'none',
top: y + 5,
left: x + 15,
border: '1px solid #fdd',
padding: '2px',
backgroundColor: '#fee',
opacity: 0.80
}).appendTo("body").fadeIn(200);
}
plotAccordingToChoices();
choiceContainer.find("input").change(plotAccordingToChoices);
$('.legendColorBox > div').each(function(i){
$(this).clone().prependTo(choiceContainer.find("bar").eq(i));
});
});//]]>
</script>
Okay.. so the dust settled and I did sort out my issue, along with cleaning up a few things. First of all, I created a function for the plot routine. This uncovered the issue I was having, where I was reusing the same variables for the divs into which the data was going, hence the mixed up results. By creating the function, and then driving the function with custom variables for each iteration, the plots operate independently as they should. – Mark
function flotplot(results, choiceContainer, plotholder, numtracks, legendcontainer){
// pass in results, choicecontainer, plotholder
// results = data
// choiceContainer = $("#labeler1");
// plotholder = $("#placeholder0");
var options = {
legend: {
show: true,
container: legendcontainer,
noColumns: 2,
sorted: false
},
series: {
points: {
show: false
},
lines: {
show: true
}
},
grid: {
hoverable: true
},
xaxes: [{
axisLabel: 'Frequency (Hz)',
}],
yaxes: [{
axisLabel: 'Power (dB)',
}],
crosshair: {
mode: "xy",
color: 001,
lineWidth: .5
}
};
var i = 0;
var track = 0;
var table = $('<table />');
var row = $('<tr/>');
var cell = $('<td width=\"100\"/>');
var temp = $(table);
$.each(results, function(key, val) {
track = track + 1;
val.color = i;
++i;
l = val.label;
if (track == 1){
temp.append(row);
row.append(cell);
cell.append('Left Channel');
} else if(track == numtracks){
row = $('<tr/>');
temp.append(row);
cell = $('<td width=\"100\">');
row.append(cell);
cell.append('Right Channel');
} //else if ((track == 7) or (track == 14) or (track == 21) or (track == 28) or (track == 35)){
//}
cell = $('<td width=\"70\"/>');
row.append(cell);
var bar = $('<div style=\"width:18px; white-space:nowrap; float:left\"><bar />');
cell.append(bar);
var inp = $('<input name="' + l + '" id="' + l + '" type="checkbox" checked="checked">');
cell.append(inp);
var bits = $('<label>', {
text: l,
'for': l
});
cell.append(bits);
choiceContainer.append(temp);
});
function plotAccordingToChoices() {
var data = [];
choiceContainer.find("input:checked").each(function() {
var key = this.name;
for (var i = 0; i < results.length; i++) {
if (results[i].label === key) {
data.push(results[i]);
return true;
}
}
});
$.plot(plotholder, data, options);
}
var previousPoint = null;
plotholder.bind("plothover", function(event, pos, item) {
$("#x").text(pos.x.toFixed(2));
$("#y").text(pos.y.toFixed(2));
if (item) {
if (previousPoint != item.datapoint) {
previousPoint = item.datapoint;
$("#tooltip").remove();
var x = item.datapoint[0].toFixed(2),
y = item.datapoint[1].toFixed(2);
showTooltip(item.pageX, item.pageY, item.series.label + " " + y + "dB");
}
} else {
$("#tooltip").remove();
previousPoint = null;
}
});
function showTooltip(x, y, contents) {
$('<div id="tooltip">' + contents + '</div>').css({
position: 'absolute',
display: 'none',
top: y + 5,
left: x + 15,
border: '1px solid #fdd',
padding: '2px',
backgroundColor: '#fee',
opacity: 0.80
}).appendTo("body").fadeIn(200);
}
plotAccordingToChoices();
choiceContainer.find("input").change(plotAccordingToChoices);
$('.legendColorBox > div').each(function(i){
$(this).clone().prependTo(choiceContainer.find("bar").eq(i));
});
};//]]>
Here is the structure into which it writes:
echo "<div id=\"placeholder".$i."\" class=\"loading\" style=\"width:600px;height:300px;display: inline; position: relative; float: left\"></div>";
echo "<div id=\"legendholder".$i."\" class=\"loading\" style=\"width:200px; height:300px; display: inline; position: relative; float: left\"></div>";
echo "<div id=\"picker1\" style=\"clear: both\"><p id=\"choices".$i."\">Show the following Tracks:</p></div>";
echo "<div id=\"labeler".$i."\"></div>";
I've installed Nivo Slider using the code from the demo included in the free download.
All of the images I am including in the slider are 800 pixels wide.
However, they are being resized to 1440 pixels wide. Extra code is being inserted:
<img src="images/bar.jpg" data-thumb="images/bar.jpg" alt="" title="" style="display: none; width: 1440px;">
I have searched the CSS and JS and can find no mention of 1440.
Where is this width being set?
Nivo Slider is responsive by default, if you want to limit the sliders width, use the below class in your CSS
.slider-wrapper.theme-default {
width: 800px; /* Desired width */
}
The above will work if you are using default theme of nivo slider, if you are using some other theme, than simply change the .theme-default to theme specific class which is assigned to the slider wrapper.
Use my custom nivo script code
/*
* jQuery Nivo Slider v2.5.1
* http://nivo.dev7studios.com
*
* Copyright 2011, Gilbert Pellegrom
* Free to use and abuse under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
* March 2010
*/
(function($) {
var NivoSlider = function(element, options) {
var settings = $.extend({}, $.fn.nivoSlider.defaults, options);
var vars = {
currentSlide : 0,
currentImage : '',
totalSlides : 0,
randAnim : '',
running : false,
paused : false,
stop : false
};
var slider = $(element);
slider.data('nivo:vars', vars);
slider.css('position', 'relative');
slider.addClass('nivoSlider');
var kids = slider.children();
kids.each(function() {
var child = $(this);
var link = '';
if (!child.is('img')) {
if (child.is('a')) {
child.addClass('nivo-imageLink');
link = child;
}
child = child.find('img:first');
}
var childWidth = child.width();
if (childWidth == 0)
childWidth = child.attr('width');
var childHeight = child.height();
if (childHeight == 0)
childHeight = child.attr('height');
if (childWidth > slider.width()) {
slider.width(childWidth);
}
if (childHeight > slider.height()) {
slider.height(childHeight);
}
if (link != '') {
link.css('display', 'none');
}
child.css('display', 'none');
vars.totalSlides++;
});
if (settings.startSlide > 0) {
if (settings.startSlide >= vars.totalSlides)
settings.startSlide = vars.totalSlides - 1;
vars.currentSlide = settings.startSlide;
}
if ($(kids[vars.currentSlide]).is('img')) {
vars.currentImage = $(kids[vars.currentSlide]);
} else {
vars.currentImage = $(kids[vars.currentSlide]).find('img:first');
}
if ($(kids[vars.currentSlide]).is('a')) {
$(kids[vars.currentSlide]).css('display', 'block');
}
slider.css({
'background' : 'url("' + vars.currentImage.attr('src') + '") no-repeat',
'background-size' : settings.backgroundSize
});
slider.append($('<div class="nivo-caption"><p></p></div>').css({
display : 'none',
opacity : settings.captionOpacity
}));
var processCaption = function(settings) {
var nivoCaption = $('.nivo-caption', slider);
if (vars.currentImage.attr('title') != '') {
var title = vars.currentImage.attr('title');
if (title.substr(0, 1) == '#')
title = $(title).html();
if (nivoCaption.css('display') == 'block') {
nivoCaption.find('p').fadeOut(settings.animSpeed, function() {
$(this).html(title);
$(this).fadeIn(settings.animSpeed);
});
} else {
nivoCaption.find('p').html(title);
}
nivoCaption.fadeIn(settings.animSpeed);
} else {
nivoCaption.fadeOut(settings.animSpeed);
}
}
processCaption(settings);
var timer = 0;
if (!settings.manualAdvance && kids.length > 1) {
timer = setInterval(function() {
nivoRun(slider, kids, settings, false);
}, settings.pauseTime);
}
if (settings.directionNav) {
slider.append('<div class="nivo-directionNav"><a class="nivo-prevNav">' + settings.prevText + '</a><a class="nivo-nextNav">' + settings.nextText + '</a></div>');
if (settings.directionNavHide) {
$('.nivo-directionNav', slider).hide();
slider.hover(function() {
$('.nivo-directionNav', slider).show();
}, function() {
$('.nivo-directionNav', slider).hide();
});
}
$('a.nivo-prevNav', slider).live('click', function() {
if (vars.running)
return false;
clearInterval(timer);
timer = '';
vars.currentSlide -= 2;
nivoRun(slider, kids, settings, 'prev');
});
$('a.nivo-nextNav', slider).live('click', function() {
if (vars.running)
return false;
clearInterval(timer);
timer = '';
nivoRun(slider, kids, settings, 'next');
});
}
if (settings.controlNav) {
var nivoControl = $('<div class="nivo-controlNav"></div>');
slider.append(nivoControl);
for (var i = 0; i < kids.length; i++) {
if (settings.controlNavThumbs) {
var child = kids.eq(i);
if (!child.is('img')) {
child = child.find('img:first');
}
if (settings.controlNavThumbsFromRel) {
nivoControl.append('<a class="nivo-control" rel="' + i + '"><img src="' + child.attr('rel') + '" alt="" /></a>');
} else {
nivoControl.append('<a class="nivo-control" rel="' + i + '"><img src="' + child.attr('src').replace(settings.controlNavThumbsSearch, settings.controlNavThumbsReplace) + '" alt="" /></a>');
}
} else {
nivoControl.append('<a class="nivo-control" rel="' + i + '">' + (i + 1) + '</a>');
}
}
$('.nivo-controlNav a:eq(' + vars.currentSlide + ')', slider).addClass('active');
$('.nivo-controlNav a', slider).live('click', function() {
if (vars.running)
return false;
if ($(this).hasClass('active'))
return false;
clearInterval(timer);
timer = '';
slider.css({
'background' : 'url("' + vars.currentImage.attr('src') + '") no-repeat',
'background-size' : settings.backgroundSize
});
vars.currentSlide = $(this).attr('rel') - 1;
nivoRun(slider, kids, settings, 'control');
});
}
if (settings.keyboardNav) {
$(window).keypress(function(event) {
if (event.keyCode == '37') {
if (vars.running)
return false;
clearInterval(timer);
timer = '';
vars.currentSlide -= 2;
nivoRun(slider, kids, settings, 'prev');
}
if (event.keyCode == '39') {
if (vars.running)
return false;
clearInterval(timer);
timer = '';
nivoRun(slider, kids, settings, 'next');
}
});
}
if (settings.pauseOnHover) {
slider.hover(function() {
vars.paused = true;
clearInterval(timer);
timer = '';
}, function() {
vars.paused = false;
if (timer == '' && !settings.manualAdvance) {
timer = setInterval(function() {
nivoRun(slider, kids, settings, false);
}, settings.pauseTime);
}
});
}
slider.bind('nivo:animFinished', function() {
vars.running = false;
$(kids).each(function() {
if ($(this).is('a')) {
$(this).css('display', 'none');
}
});
if ($(kids[vars.currentSlide]).is('a')) {
$(kids[vars.currentSlide]).css('display', 'block');
}
if (timer == '' && !vars.paused && !settings.manualAdvance) {
timer = setInterval(function() {
nivoRun(slider, kids, settings, false);
}, settings.pauseTime);
}
settings.afterChange.call(this);
});
var createSlices = function(slider, settings, vars) {
for (var i = 0; i < settings.slices; i++) {
var sliceWidth = Math.round(slider.width() / settings.slices);
if (i == settings.slices - 1) {
slider.append($('<div class="nivo-slice"></div>').css({
left : (sliceWidth * i) + 'px',
width : (slider.width() - (sliceWidth * i)) + 'px',
height : '0px',
opacity : '0',
background : 'url("' + vars.currentImage.attr('src') + '") no-repeat -' + ((sliceWidth + (i * sliceWidth)) - sliceWidth) + 'px 0%',
'background-size': settings.backgroundSize
}));
} else {
slider.append($('<div class="nivo-slice"></div>').css({
left : (sliceWidth * i) + 'px',
width : sliceWidth + 'px',
height : '0px',
opacity : '0',
background : 'url("' + vars.currentImage.attr('src') + '") no-repeat -' + ((sliceWidth + (i * sliceWidth)) - sliceWidth) + 'px 0%',
'background-size': settings.backgroundSize
}));
}
}
}
var createBoxes = function(slider, settings, vars) {
var boxWidth = Math.round(slider.width() / settings.boxCols);
var boxHeight = Math.round(slider.height() / settings.boxRows);
for (var rows = 0; rows < settings.boxRows; rows++) {
for (var cols = 0; cols < settings.boxCols; cols++) {
if (cols == settings.boxCols - 1) {
slider.append($('<div class="nivo-box"></div>').css({
opacity : 0,
left : (boxWidth * cols) + 'px',
top : (boxHeight * rows) + 'px',
width : (slider.width() - (boxWidth * cols)) + 'px',
height : boxHeight + 'px',
background : 'url("' + vars.currentImage.attr('src') + '") no-repeat -' + ((boxWidth + (cols * boxWidth)) - boxWidth) + 'px -' + ((boxHeight + (rows * boxHeight)) - boxHeight) + 'px',
'background-size': settings.backgroundSize
}));
} else {
slider.append($('<div class="nivo-box"></div>').css({
opacity : 0,
left : (boxWidth * cols) + 'px',
top : (boxHeight * rows) + 'px',
width : boxWidth + 'px',
height : boxHeight + 'px',
background : 'url("' + vars.currentImage.attr('src') + '") no-repeat -' + ((boxWidth + (cols * boxWidth)) - boxWidth) + 'px -' + ((boxHeight + (rows * boxHeight)) - boxHeight) + 'px',
'background-size': settings.backgroundSize
}));
}
}
}
}
var nivoRun = function(slider, kids, settings, nudge) {
var vars = slider.data('nivo:vars');
if (vars && (vars.currentSlide == vars.totalSlides - 1)) {
settings.lastSlide.call(this);
}
if ((!vars || vars.stop) && !nudge)
return false;
settings.beforeChange.call(this);
if (!nudge) {
slider.css({'background':'url("' + vars.currentImage.attr('src') + '") no-repeat','background-size': settings.backgroundSize });
} else {
if (nudge == 'prev') {
slider.css({'background':'url("' + vars.currentImage.attr('src') + '") no-repeat','background-size': settings.backgroundSize });
}
if (nudge == 'next') {
slider.css({'background':'url("' + vars.currentImage.attr('src') + '") no-repeat','background-size': settings.backgroundSize });
}
}
vars.currentSlide++;
if (vars.currentSlide == vars.totalSlides) {
vars.currentSlide = 0;
settings.slideshowEnd.call(this);
}
if (vars.currentSlide < 0)
vars.currentSlide = (vars.totalSlides - 1);
if ($(kids[vars.currentSlide]).is('img')) {
vars.currentImage = $(kids[vars.currentSlide]);
} else {
vars.currentImage = $(kids[vars.currentSlide]).find('img:first');
}
if (settings.controlNav) {
$('.nivo-controlNav a', slider).removeClass('active');
$('.nivo-controlNav a:eq(' + vars.currentSlide + ')', slider).addClass('active');
}
processCaption(settings);
$('.nivo-slice', slider).remove();
$('.nivo-box', slider).remove();
if (settings.effect == 'random') {
var anims = new Array('sliceDownRight', 'sliceDownLeft', 'sliceUpRight', 'sliceUpLeft', 'sliceUpDown', 'sliceUpDownLeft', 'fold', 'fade', 'boxRandom', 'boxRain', 'boxRainReverse', 'boxRainGrow', 'boxRainGrowReverse');
vars.randAnim = anims[Math.floor(Math.random() * (anims.length + 1))];
if (vars.randAnim == undefined)
vars.randAnim = 'fade';
}
if (settings.effect.indexOf(',') != -1) {
var anims = settings.effect.split(',');
vars.randAnim = anims[Math.floor(Math.random() * (anims.length))];
if (vars.randAnim == undefined)
vars.randAnim = 'fade';
}
vars.running = true;
if (settings.effect == 'sliceDown' || settings.effect == 'sliceDownRight' || vars.randAnim == 'sliceDownRight' || settings.effect == 'sliceDownLeft' || vars.randAnim == 'sliceDownLeft') {
createSlices(slider, settings, vars);
var timeBuff = 0;
var i = 0;
var slices = $('.nivo-slice', slider);
if (settings.effect == 'sliceDownLeft' || vars.randAnim == 'sliceDownLeft')
slices = $('.nivo-slice', slider)._reverse();
slices.each(function() {
var slice = $(this);
slice.css({
'top' : '0px'
});
if (i == settings.slices - 1) {
setTimeout(function() {
slice.animate({
height : '100%',
opacity : '1.0'
}, settings.animSpeed, '', function() {
slider.trigger('nivo:animFinished');
});
}, (100 + timeBuff));
} else {
setTimeout(function() {
slice.animate({
height : '100%',
opacity : '1.0'
}, settings.animSpeed);
}, (100 + timeBuff));
}
timeBuff += 50;
i++;
});
} else if (settings.effect == 'sliceUp' || settings.effect == 'sliceUpRight' || vars.randAnim == 'sliceUpRight' || settings.effect == 'sliceUpLeft' || vars.randAnim == 'sliceUpLeft') {
createSlices(slider, settings, vars);
var timeBuff = 0;
var i = 0;
var slices = $('.nivo-slice', slider);
if (settings.effect == 'sliceUpLeft' || vars.randAnim == 'sliceUpLeft')
slices = $('.nivo-slice', slider)._reverse();
slices.each(function() {
var slice = $(this);
slice.css({
'bottom' : '0px'
});
if (i == settings.slices - 1) {
setTimeout(function() {
slice.animate({
height : '100%',
opacity : '1.0'
}, settings.animSpeed, '', function() {
slider.trigger('nivo:animFinished');
});
}, (100 + timeBuff));
} else {
setTimeout(function() {
slice.animate({
height : '100%',
opacity : '1.0'
}, settings.animSpeed);
}, (100 + timeBuff));
}
timeBuff += 50;
i++;
});
} else if (settings.effect == 'sliceUpDown' || settings.effect == 'sliceUpDownRight' || vars.randAnim == 'sliceUpDown' || settings.effect == 'sliceUpDownLeft' || vars.randAnim == 'sliceUpDownLeft') {
createSlices(slider, settings, vars);
var timeBuff = 0;
var i = 0;
var v = 0;
var slices = $('.nivo-slice', slider);
if (settings.effect == 'sliceUpDownLeft' || vars.randAnim == 'sliceUpDownLeft')
slices = $('.nivo-slice', slider)._reverse();
slices.each(function() {
var slice = $(this);
if (i == 0) {
slice.css('top', '0px');
i++;
} else {
slice.css('bottom', '0px');
i = 0;
}
if (v == settings.slices - 1) {
setTimeout(function() {
slice.animate({
height : '100%',
opacity : '1.0'
}, settings.animSpeed, '', function() {
slider.trigger('nivo:animFinished');
});
}, (100 + timeBuff));
} else {
setTimeout(function() {
slice.animate({
height : '100%',
opacity : '1.0'
}, settings.animSpeed);
}, (100 + timeBuff));
}
timeBuff += 50;
v++;
});
} else if (settings.effect == 'fold' || vars.randAnim == 'fold') {
createSlices(slider, settings, vars);
var timeBuff = 0;
var i = 0;
$('.nivo-slice', slider).each(function() {
var slice = $(this);
var origWidth = slice.width();
slice.css({
top : '0px',
height : '100%',
width : '0px'
});
if (i == settings.slices - 1) {
setTimeout(function() {
slice.animate({
width : origWidth,
opacity : '1.0'
}, settings.animSpeed, '', function() {
slider.trigger('nivo:animFinished');
});
}, (100 + timeBuff));
} else {
setTimeout(function() {
slice.animate({
width : origWidth,
opacity : '1.0'
}, settings.animSpeed);
}, (100 + timeBuff));
}
timeBuff += 50;
i++;
});
} else if (settings.effect == 'fade' || vars.randAnim == 'fade') {
createSlices(slider, settings, vars);
var firstSlice = $('.nivo-slice:first', slider);
firstSlice.css({
'height' : '100%',
'width' : slider.width() + 'px'
});
firstSlice.animate({
opacity : '1.0'
}, (settings.animSpeed * 2), '', function() {
slider.trigger('nivo:animFinished');
});
} else if (settings.effect == 'slideInRight' || vars.randAnim == 'slideInRight') {
createSlices(slider, settings, vars);
var firstSlice = $('.nivo-slice:first', slider);
firstSlice.css({
'height' : '100%',
'width' : '0px',
'opacity' : '1'
});
firstSlice.animate({
width : slider.width() + 'px'
}, (settings.animSpeed * 2), '', function() {
slider.trigger('nivo:animFinished');
});
} else if (settings.effect == 'slideInLeft' || vars.randAnim == 'slideInLeft') {
createSlices(slider, settings, vars);
var firstSlice = $('.nivo-slice:first', slider);
firstSlice.css({
'height' : '100%',
'width' : '0px',
'opacity' : '1',
'left' : '',
'right' : '0px'
});
firstSlice.animate({
width : slider.width() + 'px'
}, (settings.animSpeed * 2), '', function() {
firstSlice.css({
'left' : '0px',
'right' : ''
});
slider.trigger('nivo:animFinished');
});
} else if (settings.effect == 'boxRandom' || vars.randAnim == 'boxRandom') {
createBoxes(slider, settings, vars);
var totalBoxes = settings.boxCols * settings.boxRows;
var i = 0;
var timeBuff = 0;
var boxes = shuffle($('.nivo-box', slider));
boxes.each(function() {
var box = $(this);
if (i == totalBoxes - 1) {
setTimeout(function() {
box.animate({
opacity : '1'
}, settings.animSpeed, '', function() {
slider.trigger('nivo:animFinished');
});
}, (100 + timeBuff));
} else {
setTimeout(function() {
box.animate({
opacity : '1'
}, settings.animSpeed);
}, (100 + timeBuff));
}
timeBuff += 20;
i++;
});
} else if (settings.effect == 'boxRain' || vars.randAnim == 'boxRain' || settings.effect == 'boxRainReverse' || vars.randAnim == 'boxRainReverse' || settings.effect == 'boxRainGrow' || vars.randAnim == 'boxRainGrow' || settings.effect == 'boxRainGrowReverse' || vars.randAnim == 'boxRainGrowReverse') {
createBoxes(slider, settings, vars);
var totalBoxes = settings.boxCols * settings.boxRows;
var i = 0;
var timeBuff = 0;
var rowIndex = 0;
var colIndex = 0;
var box2Darr = new Array();
box2Darr[rowIndex] = new Array();
var boxes = $('.nivo-box', slider);
if (settings.effect == 'boxRainReverse' || vars.randAnim == 'boxRainReverse' || settings.effect == 'boxRainGrowReverse' || vars.randAnim == 'boxRainGrowReverse') {
boxes = $('.nivo-box', slider)._reverse();
}
boxes.each(function() {
box2Darr[rowIndex][colIndex] = $(this);
colIndex++;
if (colIndex == settings.boxCols) {
rowIndex++;
colIndex = 0;
box2Darr[rowIndex] = new Array();
}
});
for (var cols = 0; cols < (settings.boxCols * 2); cols++) {
var prevCol = cols;
for (var rows = 0; rows < settings.boxRows; rows++) {
if (prevCol >= 0 && prevCol < settings.boxCols) {
(function(row, col, time, i, totalBoxes) {
var box = $(box2Darr[row][col]);
var w = box.width();
var h = box.height();
if (settings.effect == 'boxRainGrow' || vars.randAnim == 'boxRainGrow' || settings.effect == 'boxRainGrowReverse' || vars.randAnim == 'boxRainGrowReverse') {
box.width(0).height(0);
}
if (i == totalBoxes - 1) {
setTimeout(function() {
box.animate({
opacity : '1',
width : w,
height : h
}, settings.animSpeed / 1.3, '', function() {
slider.trigger('nivo:animFinished');
});
}, (100 + time));
} else {
setTimeout(function() {
box.animate({
opacity : '1',
width : w,
height : h
}, settings.animSpeed / 1.3);
}, (100 + time));
}
})(rows, prevCol, timeBuff, i, totalBoxes);
i++;
}
prevCol--;
}
timeBuff += 100;
}
}
}
var shuffle = function(arr) {
for (var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
return arr;
}
var trace = function(msg) {
if (this.console && typeof console.log != "undefined")
console.log(msg);
}
this.stop = function() {
if (!$(element).data('nivo:vars').stop) {
$(element).data('nivo:vars').stop = true;
trace('Stop Slider');
}
}
this.start = function() {
if ($(element).data('nivo:vars').stop) {
$(element).data('nivo:vars').stop = false;
trace('Start Slider');
}
}
settings.afterLoad.call(this);
return this;
};
$.fn.nivoSlider = function(options) {
return this.each(function(key, value) {
var element = $(this);
if (element.data('nivoslider'))
return element.data('nivoslider');
var nivoslider = new NivoSlider(this, options);
element.data('nivoslider', nivoslider);
});
};
$.fn.nivoSlider.defaults = {
backgroundSize:'',
effect : 'random',
slices : 15,
boxCols : 8,
boxRows : 4,
animSpeed : 500,
pauseTime : 3000,
startSlide : 0,
directionNav : true,
directionNavHide : true,
controlNav : true,
controlNavThumbs : false,
controlNavThumbsFromRel : false,
controlNavThumbsSearch : '.jpg',
controlNavThumbsReplace : '_thumb.jpg',
keyboardNav : true,
pauseOnHover : true,
manualAdvance : false,
captionOpacity : 0.8,
prevText : 'Prev',
nextText : 'Next',
beforeChange : function() {
},
afterChange : function() {
},
slideshowEnd : function() {
},
lastSlide : function() {
},
afterLoad : function() {
}
};
$.fn._reverse = [].reverse;
})(jQuery);
When you initial nivoSlide pass my new parameter backgroundSize:'your width size px your height size px';
Example:
$('#slider').nivoSlider({
backgroundSize:'687px 400px',
effect: 'random',
animSpeed: 500,
pauseTime: 3000,
directionNav: true,
controlNav: true,
controlNavThumbs: false,
pauseOnHover: true});
});
I'm new to d3, but learned it by trial. The following code works fine with the dataset (data/clusterRsult.json) when I do not incorporate any css style. Now that I would like to have css style for header and footer; and for the content, I would like to have a div on the left for the graph,and a div on the right for detail text of the nodes. When I added the css style in the previous codes (that works without any div), the Firefox and Google chrome debugger mode give me the error following error:
[18:09:55.694] TypeError: this[type] is undefined # file:///C:/Users/mcoyne/workspace_d3js/d3_v3/d3.v3.js:372
===========================
My Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Clustering Results - Works</title>
<link href="NSFStyles/nsfstyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="d3_v3/d3.js"></script>
<script type="text/javascript" src="d3_v3/lib/colorbrewer/colorbrewer.js"></script>
<script type="text/javascript" scr="d3_v3/src/layout/layout.js"></script>
<script type="text/javascript" scr="d3_v3/src/geom/geom.js"></script>
<link href="css/nsfstyle.css" rel="stylesheet" type="text/css" />
<link href="css/csEoSVisContent.css" rel="stylesheet" type="text/css"/>
<style>
p {
-webkit-margin-after: 0em;
-webkit-margin-before: 0em;
margin-bottom: 0em;
margin-top: 5em;
}
#h_emphasis01 {
font-weight: bold;
}
</style>
</head>
<body>
<div class="csnsfheader"></div>
<div style="text-align: right; padding-right: 1em; font-family: Verdana; font-size: 60%; top:auto;vertical-align: top; font-weight: bold; padding-top: 1px" id="Help" align="right">
<a style="text-decoration: none" href="helpEos.html"
target="_blank">HELP | </a><a style="text-decoration: none" title="Send us an email"href="mailto:xyz#abc.gov">CONTACT |</a>
</div>
<div class = "svg">
<div class="csnsfbody.svg.containerLeft" id="clusterLeftPanel"> </div>
<div class="csnsfbody.svg.containerRight" id="clusterRightPanel"> </div>
<script type="text/javascript" src="d3_v3/d3.v3.js"></script>
<!--script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script-->
<script>
var width = 620,
height = width,
radius = Math.min(width, height) /2,
node,
link,
root,
x = d3.scale.linear().range([0, 2 * Math.PI]),
y = d3.scale.pow().exponent(1.3).domain([0,1]).range([0, radius]);
// y = d3.scale.linear().range([0, radius]),
padding = 5,
duration = 1000,
color = d3.scale.category20c();
var colorScaleTop = d3.scale.ordinal().domain([101, 1000.0]).range(colorbrewer.Dark2[5]);
var colorScaleMiddle = d3.scale.ordinal().domain([1, 1000.0]).range(colorbrewer.Pastel1[6]);
var colorScaleLeaf = d3.scale.ordinal().domain([1]).range(colorbrewer.Set2[5]);
// set up the left section of the screen for the graph
var vis = d3.select("body")
.append ("csnsfbody.svg.containerLeft")
.attr("class", "csnsfbody.svg.containerLeft")
.style("width", width + "px")
.style("height", height + "px")
.append("svg:svg")
.attr("width", width + padding * 2 )
.attr("height", height + padding * 2)
.append("svg:g")
.attr("transform", "translate(" + [radius + padding, radius + padding] + ")")
;
// set up the right section of the screen for text displaying
var clusterDetails = d3.select("body")
.append("csnsfbody.svg.containerRight")
.attr("class", "csnsfbody.svg.containerRight")
.style("width", width + "px")
.style("height", height + "px")
.style("margin-left", "100px")
.style("background","#F8FBEF")
.style("position", "absolute")
;
// *** Error encounter on this line
// ***
d3.json("data/clusterResult.json", function(error, json) {
if (error) return console.log("there was an error loading the data: " + error);
var force = d3.layout.force()
.size([width, height])
.charge(function(d) { return getCharge(d);})
.linkDistance(function(d) { return getLinkDistance(d); })
.on("tick", tick)
.on("mouseover",mouseover)
.on("mouseout", mouseout)
;
// successfully load data from data.json
console.log("there are " + json.size + " nodes in my dataset");
console.log("there are " + json.children.length + " categories in my dataset");
root = json;
update();
});
function update() {
var nodes = flatten(root),
links = d3.layout.tree().links(nodes),
total = nodes.length || 1;
console.log("nodes.length = " + nodes.length);
console.log("total=" + total);
// Restart the force layout.
force
.gravity(Math.atan(total / 50) / Math.PI * 0.4)
.nodes(nodes)
.links(links)
.start();
// Update the links
// link = vis.selectAll("line.link")
// .data(force.links())
// .attr("class", "link")
link = svg.selectAll('.link')
.data( force.links() )
.enter().append('line')
.attr('class', 'link')
.style("stroke-width", function(d) { return Math.sqrt(d.value); });
;
// Enter any new links.
link.enter().insert("svg:line", ".node")
.attr("class", "link")
.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
// Exit any old links.
link.exit().remove();
// Update the nodes
node = vis.selectAll("circle.node")
.data(force.nodes())
.classed("collapsed", function(d) { return d._children ? 1 : 0; })
.attr("class", "node")
.style("fill", function(d) { return color(d);} )
;
node.select ("circle")
.style("fill", function(d) { return color(d);} );
// Enter any new nodes.
var nodeEnter = node.enter().append("svg:g")
.attr("class", "node")
.call(force.drag)
;
nodeEnter.append("svg:circle")
.attr("class", "node")
.classed('directory', function(d) { return (d._children || d.children) ? 1 : 0; })
.attr("r", function(d) {return getRadius(d); })
.attr("fill", function(d) { return color(d); })
.call(force.drag)
//.on("click",click) // This is NOT working
;
nodeEnter.append("svg:text")
.attr("text-anchor", "middle")
.attr("dy", ".35em")
.style("font-size", function (d) { return d.children ? "12px" : "8px"; })
.style("font-weight", function (d) { return d.children ? "600" : "200"; })
.text(function(d) {return d.children ? (d.name + " (" + d.size + ")") : ""; });
// Exit any old nodes
node.exit().remove();
// reselect for update
link = vis.selectAll("line.link");
node = vis.selectAll("g.node");
force.on("tick", tick);
} // end update function
function tick() {
link.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
node.attr("transform", function(d) {
return "translate(" + Math.max(5, Math.min(width - 5, d.x)) + "," + Math.max(5, Math.min(height - 5, d.y)) + ")";
});
}
// Color leaf nodes orange, and packages white or blue.
function color(d) {
//if (d.type=="root") {return colorScaleTop(d.children);}
//if (d.type == "label") {return colorScaleMiddle (d.children);}
if (d.type == "root" ){return "#FFFF33"; }
if (d.type == "label") {
if (d.size <= 50) { return "#7FBF7B"; } // good color 66C2A5, cute green A1D76A
if (d.size > 50 && d.size <= 100) { return "#FC8D62"; }
if (d.size > 100) { return "#E9A3C9"; }
}
if (d.type == "leaf") {return "#2C7FB8"; } // lavender #BEAED4
// light green ADDD8E
}
function getRadius (d) {
if (d.type == "root") {return 20;}
if (d.type == "label") {return 12; }
if (d.type == "leaf") {return 2;}
}
function getLinkDistance (d) {
if (d.target.type == "label") {return 8; }
if (d.target.type == "leaf") {return 3;}
}
function getCharge (d) {
if (d.type == "root") {return -300; }
if (d.type == "label") {return -600; }
if (d.type == "leaf") {return -40;}
}
// Toggle children on click.
function click(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
update();
}
function mouseover (d) {
if (d.type == "leaf") {
this.text.attr('transform', 'translate(' + d.x + ',' + (d.y - 5 - (d.children ? 3.5 : Math.sqrt(d.size) / 2)) + ')')
.text(d.name)
//.style('display', null)
;
}
}
// Returns a list of all nodes under the root.
function flatten(root) {
var nodes = [], i = 0;
function recurse(node) {
if (node.children) node.children.forEach(recurse);
if (!nodes.id) nodes.id = ++i;
nodes.push(node);
}
recurse(root);
return nodes;
}
function mouseover(d)
{
console.log("mouseouver <" + d.name + ">");
if (d.type == "root") {
console.log("mouseouver, root <" + d.name + ">");
clusterDetais.append("p")
.style("font-weight", 600)
.text(d.name);
}
if (d.type== "label") {
console.log("mouseouver, label <" + d.name + ">");
clusterDetails.append("p")
.style("font-weight", 600)
.text("Cluster Name: " + d.name + " (" + d.size + ")")
;
var myChildren = new Array;
myChildren = getChildrenOf(d, myChildren);
for (var i = 0; i < myChildren.length; i++) {
if (myChildren[i].type === "label" && myChildren[i].children) {
clusterDetails.append("p")
.style("font-weight", 600)
.text ("Sub-cluster name: " + myChildren[i].name + " (" + myChildren[i].size + ")")
;
}
else { clusterDetails.append("p")
.text(myChildren[i].name);
}
} // end for
}
if(d.type=="leaf" ){
clusterDetails.append("p")
.text ("Proposal id: " + d.name)
.text ("Title: " + "TBA")
.text ("PI/CoPi: " + "TBA")
;
}
} // end mouseover
//mouseout function which removes the values and replaces them with a blank space
function mouseout(d)
{
clusterDetails.html(' ');
}
</script>
</div>
<!-- ====================================================================== -->
<!-- Footer -->
<!-- ====================================================================== -->
<div class="csnsffooter" >
<!-- Add footer here -->
<span></span>
</body>
</html>
I was able to create a qtip2 on dayClick (fullcalendar) and it saves data for that event. Now I am trying to click on the event to have qtip2 load up again, but nothing happens. I have set editable to false (otherwise eventClick would never work).
I would like to be able to re-open a qtip2 event so it can be edited....thanks in advance
(NOTE: the DayClick qtip2 works great)
$('#calendar').fullCalendar({
// put your options and callbacks here
aspectRatio: 1.3,
editable: false,
draggable: true,
selectable: true,
selectHelper: true,
unselectAuto: false,
disableResizing:true,
header: {
right: 'today prev,next',
center: 'title',
left: 'agendaDay,agendaWeek,month'
},
events: "json_events.php",
eventClick: function(event, jsEvent, view) {
//alert(event.title);
$(this).qtip({
content: {
title: { text: event.title },
text: "<span class='title'>Start: </span>" + ($.fullCalendar.formatDate(event.start, 'hh:mmtt')) + "<br><span class='title'>Description: </span>" + event.description + "<br /><input type='button' value='Update' class='button' />"
},
position: {
at: 'top center',
// Position the tooltip above the link
my: 'bottom center',
adjust: {
y: -2,
resize: false // We'll handle it manually
},
viewport: calendar,
container: calendar
},
show: {
solo: true
},
style: {
width: 200,
padding: 5,
color: 'black',
textAlign: 'left',
border: {
width: 1,
radius: 3
},
tip: 'bottom-middle',
classes: 'daytooltip ui-tooltip-dark ui-tooltip-shadow',
tip: {
width: 20, height: 8
}
}
}); //element.qtip
},
dayClick: function(date, allDay, jsEvent, view) {
var month=new Array();
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";
var monthNum=new Array();
monthNum[0]="01";
monthNum[1]="02";
monthNum[2]="03";
monthNum[3]="04";
monthNum[4]="05";
monthNum[5]="06";
monthNum[6]="07";
monthNum[7]="08";
monthNum[8]="09";
monthNum[9]="10";
monthNum[10]="11";
monthNum[11]="12";
var allday = "<label for='allday'><input type='checkbox' id='allday' onClick='enabledisable(this.checked)' /><span>All Day Event</span></label>"
var thisDay = month[date.getMonth()] + '/' + date.getDate() + '/' + date.getFullYear();
var thisDayDBFormat = date.getFullYear() + '-' + monthNum[date.getMonth()] + '-' + date.getDate();
var sHours = "<select id='startTimeHour' name='startTimeHour' class='dropdown-menu-time-qtip' >" +
"<option value='01'>01</option>" +
"<option value='02'>02</option>" +
"<option value='03'>03</option>" +
"<option value='04'>04</option>" +
"<option value='05'>05</option>" +
"<option value='06' selected>06</option>" +
"<option value='07'>07</option>" +
"<option value='08'>08</option>" +
"<option value='09'>09</option>" +
"<option value='10'>10</option>" +
"<option value='11'>11</option>" +
"<option value='12'>12</option>" +
"</select>";
var sMins = "<select id='startTimeMin' name='startTimeMin' class='dropdown-menu-time-qtip' >" +
"<option value='00' selected>00</option>" +
"<option value='15'>15</option>" +
"<option value='30'>30</option>" +
"<option value='45'>45</option>" +
"</select>";
var sAM_PM = "<select id='startTimeAMPM' name='startTimeAMPM' class='dropdown-menu-time-qtip' >" +
"<option value='AM'>AM</option>" +
"<option value='PM' selected>PM</option>" +
"</select>";
var eHours = "<select id='endTimeHour' name='endTimeHour' class='dropdown-menu-time-qtip' >" +
"<option value='01'>01</option>" +
"<option value='02'>02</option>" +
"<option value='03'>03</option>" +
"<option value='04'>04</option>" +
"<option value='05'>05</option>" +
"<option value='06'>06</option>" +
"<option value='07' selected>07</option>" +
"<option value='08'>08</option>" +
"<option value='09'>09</option>" +
"<option value='10'>10</option>" +
"<option value='11'>11</option>" +
"<option value='12'>12</option>" +
"</select>";
var eMins = "<select id='endTimeMin' name='endTimeMin' class='dropdown-menu-time-qtip' >" +
"<option value='00' selected>00</option>" +
"<option value='15'>15</option>" +
"<option value='30'>30</option>" +
"<option value='45'>45</option>" +
"</select>";
var eAM_PM = "<select id='endTimeAMPM' name='endTimeAMPM' class='dropdown-menu-time-qtip' >" +
"<option value='AM'>AM</option>" +
"<option value='PM' selected>PM</option>" +
"</select>";
$(this).qtip({
overwrite: true,
content: {
title: {
text: 'Create Event / Add Menu Item: ', // + month[date.getMonth()] + '/' + date.getDate() + '/' + date.getFullYear(),
button: true
},
//text: $('#fxx').html() // this html was on the form
//text: "<span id='event-create' ><ul><li><input type='checkbox' />All Day</li><li><input type='radio' />input:radio</li><li><select><option>Select</option><option>Foo</option><option>Bar</option></select></li><li></li><li><input type='text' value=" + month[date.getMonth()] + '/' + date.getDate() + '/' + date.getFullYear() + "/></li><li><textarea>textarea</textarea></li></ul><input type='button' class='button' value='Create Event' /></span>"
text: "<div id='event-create'>" +
"<fieldset>" +
"Create a Generic Event OR add a Menu (meal) Event from your Personal Menu!" +
"<br />" +
"<label>When:</label><span>" + thisDay + "</span>" +
"<br />" +
"<form action='.' method='post' name='create_event'>" +
"<input type='hidden' name='action' value='save_event' />" +
"<input type='hidden' name='eventDate' value='" + thisDayDBFormat + "' />" +
"<label for='eventName'>Name:</label><input type='text' name='eventName' value='' title='Letters, numbers, and underscore!' size='30' />" +
"<br />" +
"<label for='eventLocation'>Location:</label><input type='text' name='eventLocation' value='' title='Letters, numbers, and underscore!' size='30' />" +
"<div id='event-create-time'>" +
"<input type='checkbox' name='eventAllDay' onClick='enabledisable(this.checked)' /><span> All Day Event</span><br />" +
"Start: " + sHours + " " + sMins + " " + sAM_PM + "<br />" +
"End: " + eHours + " " + eMins + " " + eAM_PM +
"</div>" +
"<br />" +
"<input type='submit' id='event-button' name='btnSaveGenericEvent' class='button150' value='Create Generic Event' />" +
"<input type='submit' id='event-button' name='btnSaveMenuEvent' class='button150' value='Create Menu Event' />" +
"</form>" +
"</fieldset>" +
"</div>"
//"<a href='#' onclick=" + '"' + "document['my_personal_menu'].submit()" + '"' + " >My Personal Menu >></a>" +
},
position: {
at: 'top center',
// Position the tooltip above the link
my: 'bottom center',
adjust: {
y: -2,
resize: false // We'll handle it manually
},
viewport: calendar,
container: calendar
},
// NOTE: originally, tooltip opened as modal (gray background) and had to close with 'x' button
// Settings were "show: Modal: on: true AND hide: 'false'
//
// To have tooltip popup on each day click AND have any previous tooltip go away (like google calendar)
// Settings "show: modal: on: false AND hide: 'true'"
show: {
ready: true,
event: false,
modal: {
// 'true' = Make it modal (darken the rest of the page)...
on: false,
blur: false // ... but don't close the tooltip when clicked
}
},
// 'false' = does not hide when clicking outside
// 'unfocus' = will hide when clicking outside tooltip IF modal 'on: false' (above)
hide: 'unfocus',
style: {
classes: 'daytooltip ui-tooltip-dark ui-tooltip-shadow ui-tooltip-default width400',
tip: { width: 20, height: 8 }
}
})
.qtip('show');
}
I had the same problem and found a solution from Craig:
Try attaching a qTip with overwrite set to false, and update its content at the end of the call:
$('#calendar').fullCalendar({
eventClick: function(calEvent, jsEvent, view) {
$(this).qTip({
overwrite: false,
content: 'Loading...',
show: { ready: true }
})
.qtip('option', 'content.text', newContent);
}
});