RomanL 8 лет назад
Родитель
Сommit
abe5484cd4

+ 6 - 6
modules/boonex/charts/classes/BxChartsModule.php

@@ -102,7 +102,7 @@ class BxChartsModule extends BxDolModule
      */
     public function serviceGetChartTopContentsByLikes()
     {
-        return $this->_oTemplate->getChart('TopContentsByLikes');
+        return $this->_oTemplate->getChart('TopContentsByLikes', 400);
     }
     
     /**
@@ -124,7 +124,7 @@ class BxChartsModule extends BxDolModule
      */
     public function serviceGetChartMostActiveProfiles()
     {
-        return $this->_oTemplate->getChart('MostActiveProfiles');
+        return $this->_oTemplate->getChart('MostActiveProfiles', 500);
     }
     
     public function actionGetChartData($Id = 0)
@@ -141,7 +141,7 @@ class BxChartsModule extends BxDolModule
               
             }
             $aValues['colors'] = array_slice($this->aColors, 0, count($aValues['values']));
-            echo  '{"type": "doughnut", "data":{"labels":' . json_encode($aValues['labels']) . ',"datasets":[{"data":' . json_encode($aValues['values']) . ',"backgroundColor":' . json_encode($aValues['colors']) . '}]}, "links": ' . json_encode($aValues['links']) . '}';
+            echo  '{"type": "doughnut", "data":{"labels":' . json_encode($aValues['labels']) . ',"datasets":[{"data":' . json_encode($aValues['values']) . ',"backgroundColor":' . json_encode($aValues['colors']) . '}]}, "options": {"legend": {"position": "bottom"}}, "links": ' . json_encode($aValues['links']) . '}';
         }
         
         if ($Id == 'MostActiveProfiles'){
@@ -149,13 +149,13 @@ class BxChartsModule extends BxDolModule
             $aData = $this->_oDb->getMostActiveProfiles();
             foreach ($aData as $aValue) {
                 $oModule = BxDolModule::getInstance($aValue['module']);
-                array_push($aValues['labels'], $this->getItemName($oModule->serviceGetTitle($aValue['object_id'])) . ' (' . $oModule->_aModule['title'].')');
+                array_push($aValues['labels'], $this->getItemName($oModule->serviceGetTitle($aValue['object_id'])));
                 array_push($aValues['values1'], $aValue['create_count']);
                 array_push($aValues['values2'], $aValue['views_count']);
                 array_push($aValues['links'], $oModule->serviceGetLink($aValue['object_id']));
               
             }
-            echo  '{"type":"bar",  "data": {"labels":' . json_encode($aValues['labels']) . ',"datasets": [{"label": "' . _t('_bx_charts_most_active_profiles_legend_posts') . '","backgroundColor": "' . $this->aColors[0] . '","borderColor": "' . $this->aColors[0] . '","borderWidth": 1,"data": ' . json_encode($aValues['values1']) . '}, {"label": "' . _t('_bx_charts_most_active_profiles_legend_views') . '","backgroundColor": "' . $this->aColors[1] . '","borderColor":"' . $this->aColors[1] . '","borderWidth": 1,"data": ' . json_encode($aValues['values2']) . '}]},"links": ' . json_encode($aValues['links']) . '}';
+            echo  '{"type":"horizontalBar",  "data": {"labels":' . json_encode($aValues['labels']) . ',"datasets": [{"label": "' . _t('_bx_charts_most_active_profiles_legend_posts') . '","backgroundColor": "' . $this->aColors[0] . '","borderColor": "' . $this->aColors[0] . '","borderWidth": 1,"data": ' . json_encode($aValues['values1']) . '}, {"label": "' . _t('_bx_charts_most_active_profiles_legend_views') . '","backgroundColor": "' . $this->aColors[1] . '","borderColor":"' . $this->aColors[1] . '","borderWidth": 1,"data": ' . json_encode($aValues['values2']) . '}]}, "options": {"legend": {"position": "bottom"}}, "links": ' . json_encode($aValues['links']) . '}';
         }
     }
     
@@ -166,7 +166,7 @@ class BxChartsModule extends BxDolModule
             $sString = _t('_bx_charts_txt_empty_title_item');
         }
         else{
-            $sString = strmaxtextlen($sString, 10, '...');
+            $sString = strmaxtextlen($sString, 50, '...');
         }
         return $sString;
     }

+ 2 - 2
modules/boonex/charts/classes/BxChartsTemplate.php

@@ -18,11 +18,11 @@ class BxChartsTemplate extends BxBaseModGeneralTemplate
         parent::__construct($oConfig, $oDb);
     }
     
-    function getChart($chartName)
+    function getChart($chartName, $height)
     {
         $this->addJs(array('chart.min.js', 'chart.js'));
         $this->addCss(array('chart.css'));
-        return $this->getJsCode('chart', array('chartName' => $chartName)) . $this->parseHtmlByName('chart.html', array('chart_name' => $chartName));
+        return $this->getJsCode('chart', array('chartName' => $chartName, 'height' => $height)) . $this->parseHtmlByName('chart.html', array('chart_name' => $chartName));
     }
     
     public function getJsCode($sType, $aParams = array(), $bWrap = true)

+ 18 - 7
modules/boonex/charts/js/chart.js

@@ -13,7 +13,7 @@ function BxCharts(oOptions) {
     this._sChartName = oOptions.sChartName == undefined ? '' : oOptions.sChartName;
     this._sActionsUri = oOptions.sActionUri;
     this._sKeyGraph = 'bx_chart_growth_graph_' + this._sChartName;
-    this._oChartOptionsDefault = {};
+    this._oChartOptionsDefault = {  };
     var $this = this;
     $(document).ready(function () {
         $this.loadData();
@@ -42,9 +42,18 @@ BxCharts.prototype.loadData = function () {
     	        oGraphErr.html(oData.error).show();
     	        return;
     	    }
+
+    	    if (oData.links) {
+    	        Chart.defaults.doughnut.legend.onClick = function (e, legendItem) {
+    	            var iIndex = $this._oChart.data.datasets[0].backgroundColor.indexOf(legendItem.fillStyle);
+    	            if (iIndex && oData.links[iIndex]) {
+    	                location.href = oData.links[iIndex];
+    	            }
+    	        };
+    	    }
+
     	    var oDataForChart = oData.data || false;
     	    var oChartOptions = oData.options || {};
-
     	    if ($this._oChart)
     	        $this._oChart.destroy();
     	   
@@ -57,11 +66,13 @@ BxCharts.prototype.loadData = function () {
     	    if (oData.links) {
     	        oGraph.click(function (evt) {
     	            var activePoint = $this._oChart.getElementAtEvent(evt)[0];
-    	            var data = activePoint._chart.data;
-    	            var datasetIndex = activePoint._datasetIndex;
-    	            var label = data.datasets[datasetIndex].label;
-    	            var value = data.datasets[datasetIndex].data[activePoint._index];
-    	            location.href = oData.links[activePoint._index];
+    	            if (activePoint) {
+    	                var data = activePoint._chart.data;
+    	                var datasetIndex = activePoint._datasetIndex;
+    	                var label = data.datasets[datasetIndex].label;
+    	                var value = data.datasets[datasetIndex].data[activePoint._index];
+    	                location.href = oData.links[activePoint._index];
+    	            }
     	        });
     	    }
 

+ 1 - 1
modules/boonex/charts/template/chart.html

@@ -1,5 +1,5 @@
 <div class="bx-chart-growth">
     <div class="bx-chart-growth-graph bx-def-border">
-        <canvas class="bx_chart_growth_graph bx_chart_growth_graph___chart_name__" width="100%"></canvas>
+        <canvas class="bx_chart_growth_graph bx_chart_growth_graph___chart_name__" width="100%" height="__height__"></canvas>
     </div>
 </div>