How to make nodes in sankey diagram clickable using d3.js library

Code Snippet :
We are using d3.js for this.
Sankey diagrams is made up of nodes and links.
Here the data comes from json file.
So how to make all the nodes clickable.
Which methods can we use with the rectangles so that we can make the nodes clickable.



<script>

var margin = {top: 1, right: 1, bottom: 6, left: 1},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;

var formatNumber = d3.format(",.0f"), //decimal places
format = function(d) { return formatNumber(d) + " TWh"; },
color = d3.scale.category20();

var svg = d3.select("#chart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");

var sankey = d3.sankey()
.nodeWidth(15)
.nodePadding(10)
.size([width, height]);

var path = sankey.link();

//d3.json("energy.json", function(energy) {


d3.json("numbers-subset.json", function(energy) {



sankey
.nodes(energy.nodes)
.links(energy.links)
.layout(32);

var link = svg.append("g").selectAll(".link")
.data(energy.links)
.enter().append("path")
.attr("class", "link")
.attr("d", path)
.style("stroke-width", function(d) { return Math.max(1, d.dy); })
.sort(function(a, b) { return b.dy - a.dy; });


link.append("title")
.text(function(d) { return d.source.name + " → " + d.target.name + "\n" + format(d.value); });


var node = svg.append("g").selectAll(".node")
.data(energy.nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
.call(d3.behavior.drag()
.origin(function(d) { return d; })
.on("dragstart", function() { this.parentNode.appendChild(this); })
.on("drag", dragmove));

node.append("rect")
.attr("height", function(d) { return d.dy; })
.attr("width", sankey.nodeWidth())
.style("fill", function(d) { return d.color = color(d.name.split("|")[0]); })
.style("stroke", function(d) { return d3.rgb(d.color).darker(2); })
.append("title")
.text(function(d) { return d.name + "\n" + format(d.value); });

node.append("text")
.attr("x", -6)
.attr("y", function(d) { return d.dy / 2; })
.attr("dy", ".35em")
.attr("text-anchor", "end")
.attr("transform", null)
.text(function(d) { return d.name; })
.filter(function(d) { return d.x < width / 2; })
.attr("x", 6 + sankey.nodeWidth())
.attr("text-anchor", "start");

function dragmove(d) {
d3.select(this).attr("transform", "translate(" + d.x + "," + (d.y = Math.max(0, Math.min(height - d.dy, d3.event.y))) + ")");
sankey.relayout();
link.attr("d", path);
}



});

</script>




Creating a new YII Default page and redirect to it

I am new to YII framework and I am trying to make an application that works like following, when I visit my index it redirects me to this a page called management, I have to create a new page with some list options and I have to redirect to that, but I am not quite sure how to do it with YII.



here is my original action Index:



public function actionIndex()
{
$this->layout = '//layouts/main';
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
if (Yii::app()->user->isGuest)
{
$this->redirect(Yii::app()->createUrl('site/login'));
}
else
{
$this->redirect(array('management/list'));
//$this->redirect(array('site/HomePage'));
//$this->render('index');
}
}


it redirects me to management/list, what I have to do is to redirect to a new page instead of management called home page and in the new page there is an option for management which by clicking on that it takes you to the correct page.



this is my management folder:





this is my view:





what I did is:
inside site I created a page called homepage.php with the following body:



<div class="static_page">
<?php
/* @var $this SiteController */

$this->pageTitle=Yii::app()->name;
?>

<h2>Welcome to <?php echo CHtml::encode(Yii::app()->name); ?></h2>

<p>Congratulations! You have successfully created your Yii application.</p>

<p>You may change the content of this page by modifying the following two files:</p>
<ul>
<li>View file: <code><?php echo __FILE__; ?></code></li>
<li>Layout file: <code><?php echo $this->getLayoutFile('main'); ?></code></li>
</ul>

<p>For more details on how to further develop this application, please read
the <a href="http://www.yiiframework.com/doc/">documentation</a>.
Feel free to ask in the <a href="http://www.yiiframework.com/forum/">forum</a>,
should you have any questions.</p>

</div>


then I changed my actionIndex(), and added the following to the else part:



$this->redirect(array('site/HomePage'));


but when I run that I saw this errors:



The system is unable to find the requested action "HomePage".

/vagrant/vendor/yiisoft/yii/framework/web/CController.php(483)

471 return $this->createActionFromMap($map,$actionID,$requestActionID,$config);
472 }
473
474 /**
475 * Handles the request whose action is not recognized.
476 * This method is invoked when the controller cannot find the requested action.
477 * The default implementation simply throws an exception.
478 * @param string $actionID the missing action name
479 * @throws CHttpException whenever this method is invoked
480 */
481 public function missingAction($actionID)
482 {
483 throw new CHttpException(404,Yii::t('yii','The system is unable to find the requested action "{action}".',
484 array('{action}'=>$actionID==''?$this->defaultAction:$actionID)));
485 }
486
487 /**
488 * @return CAction the action currently being executed, null if no active action.
489 */
490 public function getAction()
491 {
492 return $this->_action;
493 }
494
495 /**


// specify how many levels of call stack should be shown in each log message
15 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
16
17 require_once($yii);
18
19 Yii::createWebApplication($config)->run();
20
21 echo 'temporary add records to the rbac tables';
22
23 //TODO create temporarily the RBAC settings
24 $auth=Yii::app()->authManager;


how can I add the new homepage.php instead of management page??



EDITED NEW VERSION:
So this is how I made it:
I created a new page called homepage.php withing my views\site. then I open the homepage and added the following:



<div class="static_page">
<?php
/* @var $this SiteController */

$this->pageTitle=Yii::app()->name;
?>

<h2>Welcome to <?php echo CHtml::encode(Yii::app()->name); ?></h2>

<p>You may change the page by clicking on the following pages.</p>
<ul>
<li>For Dossier Management click on: <code><a href="dossiermanagement/list"> dossiers </a></code></li>
<li>For Management Information click on: <code> Management Info</code></li>
<li>For System Management click on: <code> systemBeheer</code></li>
</ul>

<!-- <p>For more details on how to further develop this application, please read
the <a href="http://www.yiiframework.com/doc/">documentation</a>.
Feel free to ask in the <a href="http://www.yiiframework.com/forum/">forum</a>,
should you have any questions.</p> -->

</div>


and also changed my actionIndex to $this->render('HomePage');



it works but now my redirection doesnt work:



for example this part is totally incorrect



<li>For Dossier Management click on: <code><a href="dossiermanagement/list"> dossiers </a></code></li>
<li>For Management Information click on: <code> Management Info</code></li>


how can I solve this one?



Answers

Instead of redirecting to anywhere else please load a view





$this->render('yourview/index',array(
'dataProvider'=>$dataProvider,
'list_arr'=>$this->list
));





Make a folder named yourview inside the view folder. Even if you want to redirect it to management controller, please make sure that you have the controller in name.



Answers

Please write this code in place of " $this->redirect(array('management/list'));"


$list=array('David','Tristup');
$selected_value='';
$this->render('yourview/index',
array('list_arr'=>$list,'selected_value'=>$selected_value
));





Now you write this code in yourview/index.php. Here make_id is field name change it accordingly.





 <?php       
//echo $selected_value;
echo CHtml::dropDownList('make_id',$selected_value,$list_arr,array('empty' => 'Select a Make','class'=>'drop_class'));
?>





Now you can see a dropdown with our name. Please let me know if you have any questions.





Incorrect number of arguments for PROCEDURE

Define procedure:



DELIMITER $$
CREATE PROCEDURE SP_Reporting(IN tablename VARCHAR(20))
proc_label:BEGIN
IF tablename IS NULL THEN
SELECT 'Null detect';
LEAVE proc_label;
END IF;

SELECT 'after';
END;
$$
DELIMITER ;


Call Procedure:



CALL SP_Reporting();


Error :




ERROR 1318 (42000): Incorrect number of arguments for PROCEDURE
cds.SP_Reporting ; expected 1, got 0




How pass var by default like SP_Reporting(IN tablename = 'default value' VARCHAR(20))



Answers

When you are making your stored procedure, you can assign a value to your input, so there is no need to pass parameters while you are calling the proc.



We usually assign NULL and for making parameters optional, we use this method.



tablename VARCHAR(20) = NULL


Your complete script:



DELIMITER $$
CREATE PROCEDURE SP_Reporting(IN tablename VARCHAR(20) = NULL)
proc_label:BEGIN
IF tablename IS NULL THEN
SELECT 'Null detect';
LEAVE proc_label;
END IF;

SELECT 'after';
END;
$$
DELIMITER ;


EDIT



MySQL is not accepting optional parameters. So one way is to pass NULL value in your stored procedure and check it with IF statement inside your proc.



DELIMITER $$
CREATE PROCEDURE SP_Reporting(IN tablename VARCHAR(20))
proc_label:BEGIN
IF tablename IS NULL THEN
-- Do something;
ELSE
-- Do something else;
END IF;
END;
$$
DELIMITER ;


Answers

You have to pass the table name in the procedure call statement like:



CALL SP_Reporting(table_name);



you can't pass default in call statement.
You can assign default value before calling the procedure.
or use OUT instead of IN as a parameter.



Answers

you miss the parameter :tablename
you should like this :
call SP_Reporting('any varchar')

or
call SP_Reporting(null)





↑このページのトップヘ