[MediaWiki-commits] [Gerrit] Added d3 js chart loaded with celerity/javelin - change (phabricator...Sprint)

2014-10-26 Thread Christopher Johnson (WMDE) (Code Review)
Christopher Johnson (WMDE) has submitted this change and it was merged.

Change subject: Added d3 js chart loaded with celerity/javelin
..


Added d3 js chart loaded with celerity/javelin

Change-Id: I03e0755911d583678e1607d509af9ad848747029
---
M src/query/SprintQuery.php
M src/view/BurndownDataView.php
M src/view/SprintReportBurndownView.php
3 files changed, 308 insertions(+), 173 deletions(-)

Approvals:
  Christopher Johnson (WMDE): Verified; Looks good to me, approved



diff --git a/src/query/SprintQuery.php b/src/query/SprintQuery.php
index b8c9aae..c312643 100644
--- a/src/query/SprintQuery.php
+++ b/src/query/SprintQuery.php
@@ -22,6 +22,13 @@
 return $this;
   }
 
+  public function getViewerHandles($request, array $phids) {
+return id(new PhabricatorHandleQuery())
+->setViewer($request->getUser())
+->withPHIDs($phids)
+->execute();
+  }
+
   public function getAuxFields() {
 $field_list = PhabricatorCustomField::getObjectFields($this->project, 
PhabricatorCustomField::ROLE_EDIT);
 $field_list->setViewer($this->viewer);
diff --git a/src/view/BurndownDataView.php b/src/view/BurndownDataView.php
index ee05124..5e962df 100644
--- a/src/view/BurndownDataView.php
+++ b/src/view/BurndownDataView.php
@@ -40,7 +40,7 @@
 
   public function render() {
 
-$chart = $this->buildBurnDownChart();
+$chart = $this->buildC3Chart();
 $tasks_table = $this->buildTasksTable();
 $burndown_table = $this->buildBurnDownTable();
 $event_table = $this->buildEventTable();
@@ -78,7 +78,6 @@
 
 
 $data = array(array(
-pht('Date'),
 pht('Total Points'),
 pht('Remaining Points'),
 pht('Ideal Points'),
@@ -91,7 +90,6 @@
 $future = new DateTime($date->getDate()) > id(new 
DateTime())->setTime(0, 0);
   }
   $data[] = array(
-  $date->getDate(),
   $future ? null : $date->points_total,
   $future ? null : $date->points_remaining,
   $date->points_ideal_remaining,
@@ -99,9 +97,25 @@
   );
 
 }
+$data = $this->transposeArray($data);
 return $data;
-
   }
+
+  private function transposeArray($array) {
+$transposed_array = array();
+if ($array) {
+  foreach ($array as $row_key => $row) {
+if (is_array($row) && !empty($row)) { //check to see if there is a 
second dimension
+  foreach ($row as $column_key => $element) {
+$transposed_array[$column_key][$row_key] = $element;
+  }
+} else {
+  $transposed_array[0][$row_key] = $row;
+}
+  }
+ return $transposed_array;
+ }
+   }
 
   // Now loop through the events and build the data for each day
   private function buildDailyData($events, $start, $end) {
@@ -198,6 +212,39 @@
 }
   }
 
+  private function buildC3Chart() {
+$this->data = $this->buildChartDataSet();
+$totalpoints = $this->data[0];
+$remainingpoints = $this->data[1];
+$idealpoints = $this->data[2];
+$pointstoday = $this->data[3];
+$timeseries = array_keys($this->dates);
+
+require_celerity_resource('d3');
+require_celerity_resource('c3-css');
+require_celerity_resource('c3');
+
+$id = 'chart';
+Javelin::initBehavior('c3-chart', array(
+'hardpoint' => $id,
+'timeseries' => $timeseries,
+'totalpoints' => $totalpoints,
+'remainingpoints' => $remainingpoints,
+'idealpoints' =>   $idealpoints,
+'pointstoday' =>   $pointstoday
+));
+
+$chart= id(new PHUIObjectBoxView())
+->setHeaderText(pht('Burndown for ' . $this->project->getName()))
+ ->appendChild(phutil_tag('div',
+array(
+'id' => 'chart',
+'style' => 'width: 100%; height:400px'
+), ''));
+
+return $chart;
+  }
+
   private function buildBurnDownChart() {
 
 $this->data = $this->buildChartDataSet();
diff --git a/src/view/SprintReportBurndownView.php 
b/src/view/SprintReportBurndownView.php
index 5494d82..eda52eb 100644
--- a/src/view/SprintReportBurndownView.php
+++ b/src/view/SprintReportBurndownView.php
@@ -16,198 +16,265 @@
 
   public function render() {
 
-  $handle = null;
+$filter = $this->BuildFilter();
+$chart = $this->buildBurnDownChart();
+$table = $this->buildStatsTable();
+return array($filter, $chart, $table);
+  }
 
-  $project_phid = $this->request->getStr('project');
-  if ($project_phid) {
-$phids = array($project_phid);
-$handles = $this->loadViewerHandles($phids);
-$handle = $handles[$project_phid];
-  }
+  private function getXactionData($project_phid) {
+ $query = id(new SprintQuery())
+->setPHID($project_phid);
+  $data = $query->getXactionData(ManiphestTransaction::TYPE_STATUS);
+return $data;
+  }
 
-  $query = id(new SprintQuery())
+  private function buildFilter() {
+$handle = null;
+

[MediaWiki-commits] [Gerrit] Added d3 js chart loaded with celerity/javelin - change (phabricator...Sprint)

2014-10-26 Thread Christopher Johnson (WMDE) (Code Review)
Christopher Johnson (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/168824

Change subject: Added d3 js chart loaded with celerity/javelin
..

Added d3 js chart loaded with celerity/javelin

Change-Id: I03e0755911d583678e1607d509af9ad848747029
---
M src/query/SprintQuery.php
M src/view/BurndownDataView.php
M src/view/SprintReportBurndownView.php
3 files changed, 308 insertions(+), 173 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/phabricator/extensions/Sprint 
refs/changes/24/168824/1

diff --git a/src/query/SprintQuery.php b/src/query/SprintQuery.php
index b8c9aae..c312643 100644
--- a/src/query/SprintQuery.php
+++ b/src/query/SprintQuery.php
@@ -22,6 +22,13 @@
 return $this;
   }
 
+  public function getViewerHandles($request, array $phids) {
+return id(new PhabricatorHandleQuery())
+->setViewer($request->getUser())
+->withPHIDs($phids)
+->execute();
+  }
+
   public function getAuxFields() {
 $field_list = PhabricatorCustomField::getObjectFields($this->project, 
PhabricatorCustomField::ROLE_EDIT);
 $field_list->setViewer($this->viewer);
diff --git a/src/view/BurndownDataView.php b/src/view/BurndownDataView.php
index ee05124..5e962df 100644
--- a/src/view/BurndownDataView.php
+++ b/src/view/BurndownDataView.php
@@ -40,7 +40,7 @@
 
   public function render() {
 
-$chart = $this->buildBurnDownChart();
+$chart = $this->buildC3Chart();
 $tasks_table = $this->buildTasksTable();
 $burndown_table = $this->buildBurnDownTable();
 $event_table = $this->buildEventTable();
@@ -78,7 +78,6 @@
 
 
 $data = array(array(
-pht('Date'),
 pht('Total Points'),
 pht('Remaining Points'),
 pht('Ideal Points'),
@@ -91,7 +90,6 @@
 $future = new DateTime($date->getDate()) > id(new 
DateTime())->setTime(0, 0);
   }
   $data[] = array(
-  $date->getDate(),
   $future ? null : $date->points_total,
   $future ? null : $date->points_remaining,
   $date->points_ideal_remaining,
@@ -99,9 +97,25 @@
   );
 
 }
+$data = $this->transposeArray($data);
 return $data;
-
   }
+
+  private function transposeArray($array) {
+$transposed_array = array();
+if ($array) {
+  foreach ($array as $row_key => $row) {
+if (is_array($row) && !empty($row)) { //check to see if there is a 
second dimension
+  foreach ($row as $column_key => $element) {
+$transposed_array[$column_key][$row_key] = $element;
+  }
+} else {
+  $transposed_array[0][$row_key] = $row;
+}
+  }
+ return $transposed_array;
+ }
+   }
 
   // Now loop through the events and build the data for each day
   private function buildDailyData($events, $start, $end) {
@@ -198,6 +212,39 @@
 }
   }
 
+  private function buildC3Chart() {
+$this->data = $this->buildChartDataSet();
+$totalpoints = $this->data[0];
+$remainingpoints = $this->data[1];
+$idealpoints = $this->data[2];
+$pointstoday = $this->data[3];
+$timeseries = array_keys($this->dates);
+
+require_celerity_resource('d3');
+require_celerity_resource('c3-css');
+require_celerity_resource('c3');
+
+$id = 'chart';
+Javelin::initBehavior('c3-chart', array(
+'hardpoint' => $id,
+'timeseries' => $timeseries,
+'totalpoints' => $totalpoints,
+'remainingpoints' => $remainingpoints,
+'idealpoints' =>   $idealpoints,
+'pointstoday' =>   $pointstoday
+));
+
+$chart= id(new PHUIObjectBoxView())
+->setHeaderText(pht('Burndown for ' . $this->project->getName()))
+ ->appendChild(phutil_tag('div',
+array(
+'id' => 'chart',
+'style' => 'width: 100%; height:400px'
+), ''));
+
+return $chart;
+  }
+
   private function buildBurnDownChart() {
 
 $this->data = $this->buildChartDataSet();
diff --git a/src/view/SprintReportBurndownView.php 
b/src/view/SprintReportBurndownView.php
index 5494d82..eda52eb 100644
--- a/src/view/SprintReportBurndownView.php
+++ b/src/view/SprintReportBurndownView.php
@@ -16,198 +16,265 @@
 
   public function render() {
 
-  $handle = null;
+$filter = $this->BuildFilter();
+$chart = $this->buildBurnDownChart();
+$table = $this->buildStatsTable();
+return array($filter, $chart, $table);
+  }
 
-  $project_phid = $this->request->getStr('project');
-  if ($project_phid) {
-$phids = array($project_phid);
-$handles = $this->loadViewerHandles($phids);
-$handle = $handles[$project_phid];
-  }
+  private function getXactionData($project_phid) {
+ $query = id(new SprintQuery())
+->setPHID($project_phid);
+  $data = $query->getXactionData(ManiphestTransaction::TYPE_STATUS);
+return $data;
+  }
 
-  $query = id(new SprintQuery())
+  p