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

Revision 22857, 3.6 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 主に空白・空白行の調整。
  • 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-2013 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    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    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    function drawBar($line_no)
56    {
57        $arrPointList = $this->arrPointList[$line_no];
58        // データ数を数える
59        $count = count($arrPointList);
60        // 半目盛りの幅を求める
61        $half_scale = intval($this->area_width / ($count + 1) / 2);
62        // 目盛りの幅を求める
63        $scale_width = intval($this->area_width / ($count + 1));
64        // 棒グラフのサイズを求める
65        $bar_width = intval(($scale_width - (BAR_PAD * 2)) / $this->line_max);
66        // 色数の取得
67        $c_max = count($this->arrColor);
68        for ($i = 0; $i < $count; $i++) {
69            $left = $arrPointList[$i][0] - $half_scale + BAR_PAD + ($bar_width * $line_no);
70            $top = $arrPointList[$i][1];
71            $right = $left + $bar_width;
72            $bottom = $this->top + $this->area_height;
73
74            // 影の描画
75            if ($this->shade_on) {
76                imagefilledrectangle($this->image, $left + 2, $top + 2, $right + 2, $bottom, $this->shade_color);
77            }
78            //imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[($i % $c_max)]);
79            imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[$line_no]);
80            imagerectangle($this->image, $left, $top, $right, $bottom, $this->flame_color);
81        }
82    }
83
84    // ラベルを描画する
85    function drawLabel($line_no)
86    {
87        $arrData = $this->arrDataList[$line_no];
88        $arrPointList = $this->arrPointList[$line_no];
89        $count = count($arrPointList);
90        for ($i = 0; $i < $count; $i++) {
91            $x = $arrPointList[$i][0];
92            $y = $arrPointList[$i][1];
93            $text_width = $this->getTextWidth(number_format($arrData[$i]), FONT_SIZE);
94            $y_pos = $y - FONT_SIZE - 5;
95            $x_pos = $x - $text_width / 2;
96            $this->setText(FONT_SIZE, $x_pos, $y_pos, number_format($arrData[$i]));
97        }
98    }
99}
Note: See TracBrowser for help on using the repository browser.