source: branches/comu-ver2/data/class/graph/SC_GraphBar.php @ 16741

Revision 16741, 3.7 KB checked in by adachi, 15 years ago (diff)

set eol-style:LF

  • 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-2007 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$SC_GRAPHBAR_DIR = realpath(dirname( __FILE__));
24require_once($SC_GRAPHBAR_DIR . "/SC_GraphLine.php");
25
26// 棒グラフ生成クラス
27class SC_GraphBar extends SC_GraphLine{
28    // コンストラクタ
29    function SC_GraphLine(
30        $bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left = LINE_LEFT, $top = LINE_TOP,
31        $area_width = LINE_AREA_WIDTH, $area_height = LINE_AREA_HEIGHT) {
32        parent::SC_GraphLine($bgw, $bgh, $left, $top, $area_width, $area_height);
33    }
34
35    // グラフの描画
36    function drawGraph() {
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        $arrPointList = $this->arrPointList[$line_no];
57        // データ数を数える
58        $count = count($arrPointList);
59        // 半目盛りの幅を求める
60        $half_scale = intval($this->area_width / ($count + 1) / 2);
61        // 目盛りの幅を求める
62        $scale_width = intval($this->area_width / ($count + 1));
63        // 棒グラフのサイズを求める
64        $bar_width = intval(($scale_width - (BAR_PAD * 2)) / $this->line_max);
65        // 色数の取得
66        $c_max = count($this->arrColor);
67        for($i = 0; $i < $count; $i++) {
68            $left = $arrPointList[$i][0] - $half_scale + BAR_PAD + ($bar_width * $line_no);
69            $top = $arrPointList[$i][1];
70            $right = $left + $bar_width;
71            $bottom = $this->top + $this->area_height;
72
73            // 影の描画
74            if($this->shade_on) {
75                imagefilledrectangle($this->image, $left + 2, $top + 2, $right + 2, $bottom, $this->shade_color);
76            }
77            //imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[($i % $c_max)]);
78            imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[$line_no]);
79            imagerectangle($this->image, $left, $top, $right, $bottom, $this->flame_color);
80        }
81    }
82
83    // ラベルを描画する
84    function drawLabel($line_no) {
85        $arrData = $this->arrDataList[$line_no];
86        $arrPointList = $this->arrPointList[$line_no];
87        $count = count($arrPointList);
88        for($i = 0; $i < $count; $i++) {
89            $x = $arrPointList[$i][0];
90            $y = $arrPointList[$i][1];
91            $text_width = $this->getTextWidth(number_format($arrData[$i]), FONT_SIZE);
92            $y_pos = $y - FONT_SIZE - 5;
93            $x_pos = $x - $text_width / 2;
94            $this->setText(FONT_SIZE, $x_pos, $y_pos, number_format($arrData[$i]));
95        }
96    }
97
98}
99?>
Note: See TracBrowser for help on using the repository browser.