source: branches/version-2_12-dev/data/class/graph/SC_Graph_Bar.php @ 21864

Revision 21864, 3.6 KB checked in by h_yoshimoto, 12 years ago (diff)

#1831 Copyrightを更新

  • 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-2012 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    function __construct(
28        $bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left = LINE_LEFT, $top = LINE_TOP,
29        $area_width = LINE_AREA_WIDTH, $area_height = LINE_AREA_HEIGHT) {
30        parent::__construct($bgw, $bgh, $left, $top, $area_width, $area_height);
31    }
32
33    // グラフの描画
34    function drawGraph() {
35        $this->drawYLine();
36        $this->drawXLine(true);
37
38        // 棒グラフの描画
39        for ($i = 0; $i < $this->line_max; $i++) {
40            $this->drawBar($i);
41        }
42
43        // ラベルの描画
44        for ($i = 0; $i < $this->line_max; $i++) {
45            $this->drawLabel($i);
46        }
47
48        // 凡例の描画
49        $this->drawLegend();
50    }
51
52    // 棒グラフの描画
53    function drawBar($line_no) {
54        $arrPointList = $this->arrPointList[$line_no];
55        // データ数を数える
56        $count = count($arrPointList);
57        // 半目盛りの幅を求める
58        $half_scale = intval($this->area_width / ($count + 1) / 2);
59        // 目盛りの幅を求める
60        $scale_width = intval($this->area_width / ($count + 1));
61        // 棒グラフのサイズを求める
62        $bar_width = intval(($scale_width - (BAR_PAD * 2)) / $this->line_max);
63        // 色数の取得
64        $c_max = count($this->arrColor);
65        for ($i = 0; $i < $count; $i++) {
66            $left = $arrPointList[$i][0] - $half_scale + BAR_PAD + ($bar_width * $line_no);
67            $top = $arrPointList[$i][1];
68            $right = $left + $bar_width;
69            $bottom = $this->top + $this->area_height;
70
71            // 影の描画
72            if ($this->shade_on) {
73                imagefilledrectangle($this->image, $left + 2, $top + 2, $right + 2, $bottom, $this->shade_color);
74            }
75            //imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[($i % $c_max)]);
76            imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[$line_no]);
77            imagerectangle($this->image, $left, $top, $right, $bottom, $this->flame_color);
78        }
79    }
80
81    // ラベルを描画する
82    function drawLabel($line_no) {
83        $arrData = $this->arrDataList[$line_no];
84        $arrPointList = $this->arrPointList[$line_no];
85        $count = count($arrPointList);
86        for ($i = 0; $i < $count; $i++) {
87            $x = $arrPointList[$i][0];
88            $y = $arrPointList[$i][1];
89            $text_width = $this->getTextWidth(number_format($arrData[$i]), FONT_SIZE);
90            $y_pos = $y - FONT_SIZE - 5;
91            $x_pos = $x - $text_width / 2;
92            $this->setText(FONT_SIZE, $x_pos, $y_pos, number_format($arrData[$i]));
93        }
94    }
95
96}
Note: See TracBrowser for help on using the repository browser.