source: branches/version-2_13-dev/data/class/graph/SC_Graph_Bar.php @ 23605

Revision 23605, 3.7 KB checked in by kimoto, 12 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

Scrutinizer Auto-Fixes

This patch was automatically generated as part of the following inspection:
 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/d8722894-69a6-4b1b-898d-43618035c60d

Enabled analysis tools:

  • PHP Analyzer
  • PHP PDepend
  • PHP Similarity Analyzer
  • PHP Change Tracking Analyzer
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2014 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// 棒グラフ生成クラス
25class SC_Graph_Bar extends SC_Graph_Line_Ex
26{
27    // コンストラクタ
28    public function __construct(
29        $bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left = LINE_LEFT, $top = LINE_TOP,
30        $area_width = LINE_AREA_WIDTH, $area_height = LINE_AREA_HEIGHT) {
31        parent::__construct($bgw, $bgh, $left, $top, $area_width, $area_height);
32    }
33
34    // グラフの描画
35    public function drawGraph()
36    {
37        $this->drawYLine();
38        $this->drawXLine(true);
39
40        // 棒グラフの描画
41        for ($i = 0; $i < $this->line_max; $i++) {
42            $this->drawBar($i);
43        }
44
45        // ラベルの描画
46        for ($i = 0; $i < $this->line_max; $i++) {
47            $this->drawLabel($i);
48        }
49
50        // 凡例の描画
51        $this->drawLegend();
52    }
53
54    // 棒グラフの描画
55
56    /**
57     * @param integer $line_no
58     */
59    public function drawBar($line_no)
60    {
61        $arrPointList = $this->arrPointList[$line_no];
62        // データ数を数える
63        $count = count($arrPointList);
64        // 半目盛りの幅を求める
65        $half_scale = intval($this->area_width / ($count + 1) / 2);
66        // 目盛りの幅を求める
67        $scale_width = intval($this->area_width / ($count + 1));
68        // 棒グラフのサイズを求める
69        $bar_width = intval(($scale_width - (BAR_PAD * 2)) / $this->line_max);
70        // 色数の取得
71        $c_max = count($this->arrColor);
72        for ($i = 0; $i < $count; $i++) {
73            $left = $arrPointList[$i][0] - $half_scale + BAR_PAD + ($bar_width * $line_no);
74            $top = $arrPointList[$i][1];
75            $right = $left + $bar_width;
76            $bottom = $this->top + $this->area_height;
77
78            // 影の描画
79            if ($this->shade_on) {
80                imagefilledrectangle($this->image, $left + 2, $top + 2, $right + 2, $bottom, $this->shade_color);
81            }
82            //imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[($i % $c_max)]);
83            imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[$line_no]);
84            imagerectangle($this->image, $left, $top, $right, $bottom, $this->flame_color);
85        }
86    }
87
88    // ラベルを描画する
89
90    /**
91     * @param integer $line_no
92     */
93    public function drawLabel($line_no)
94    {
95        $arrData = $this->arrDataList[$line_no];
96        $arrPointList = $this->arrPointList[$line_no];
97        $count = count($arrPointList);
98        for ($i = 0; $i < $count; $i++) {
99            $x = $arrPointList[$i][0];
100            $y = $arrPointList[$i][1];
101            $text_width = $this->getTextWidth(number_format($arrData[$i]), FONT_SIZE);
102            $y_pos = $y - FONT_SIZE - 5;
103            $x_pos = $x - $text_width / 2;
104            $this->setText(FONT_SIZE, $x_pos, $y_pos, number_format($arrData[$i]));
105        }
106    }
107}
Note: See TracBrowser for help on using the repository browser.