Skip to content

Commit

Permalink
finished transformation into a standalone library
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Sikora committed Jun 14, 2011
1 parent 90c2726 commit 870e1c7
Show file tree
Hide file tree
Showing 39 changed files with 377 additions and 387 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.project
.buildpath

This comment has been minimized.

Copy link
@stof

stof Jun 14, 2011

These folder should be ignored locally, not in the repo as they are specific to your IDE

This comment has been minimized.

Copy link
@martinsik

martinsik Jun 14, 2011

Owner

yes, that's right

Examples/cache/*
3 changes: 3 additions & 0 deletions .settings/org.eclipse.php.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Tue Jun 14 10:10:34 CEST 2011
eclipse.preferences.version=1
include_path=

This comment has been minimized.

Copy link
@stof

stof Jun 14, 2011

This file has nothing to do in the repo. You should add the .setting folder in you .git/info/exclude file to ignore it locally

This comment has been minimized.

Copy link
@martinsik

martinsik Jun 14, 2011

Owner

agree

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Bundle\GoogleChartBundle\Tests\Library;
namespace GoogleChartGenerator\Test;


abstract class AbstractChartDataTest extends \PHPUnit_Framework_TestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Bundle\GoogleChartBundle\Tests\Library;
namespace GoogleChartGenerator\Test;


abstract class AbstractChartTest extends \PHPUnit_Framework_TestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

namespace Bundle\GoogleChartBundle\Tests\LineChart;
namespace GoogleChartGenerator\Test;

use Bundle\GoogleChartBundle\Tests\Library\AbstractChartDataTest;
use Bundle\GoogleChartBundle\Library\LineChart\Line;
include_once '../../loader.php';

use GoogleChartGenerator\Test\AbstractChartDataTest;
use GoogleChartGenerator\Library\LineChart\Line;

class LineTest extends AbstractChartDataTest {

Expand Down
File renamed without changes
File renamed without changes.
52 changes: 52 additions & 0 deletions Examples/barchart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

include_once '../loader.php';

use GoogleChartGenerator\Library\BarChart\BarChart;
use GoogleChartGenerator\Library\BarChart\Bar;


function getRandomData($size, $min = 0, $max = 100) {
$values = $keys = array();
for ($i=0; $i < $size; $i++) {
$values[] = rand($min, $max);
$keys[] = $i;
}
return array_combine($keys, $values);
}

$charts = array();

$chart = new BarChart(array('title' => 'Default settings'));
$chart->addData(new Bar(getRandomData(6)));
$charts[] = $chart;

$chart = new BarChart(array('size' => '620x200', 'legend' => true));
$chart->addData(new Bar(getRandomData(6), array('title' => 'Bar #1')));
$chart->addData(new Bar(getRandomData(6), array('title' => 'Bar #2')));
$chart->addData(new Bar(getRandomData(6), array('title' => 'Bar #3')));
$charts[] = $chart;

$chart = new BarChart(array('stacked' => true));
$chart->addData(new Bar(getRandomData(6)));
$chart->addData(new Bar(getRandomData(6)));
$charts[] = $chart;

$chart = new BarChart(array('position' => 'horizontal', 'size' => '300x230'));
$chart->addData(new Bar(getRandomData(6)));
$charts[] = $chart;

$chart = new BarChart(array('position' => 'horizontal', 'size' => '300x210'));
$chart->addData(new Bar(getRandomData(3)));
$chart->addData(new Bar(getRandomData(3)));
//$chart->addData(new Bar(getRandomData(6)));
$charts[] = $chart;

$chart = new BarChart(array('position' => 'horizontal', 'size' => '300x210'));
$chart->setStacked(true);
$chart->addData(new Bar(getRandomData(6)));
$chart->addData(new Bar(getRandomData(6)));
$chart->addData(new Bar(getRandomData(6)));
$charts[] = $chart;

include 'view.php';
104 changes: 104 additions & 0 deletions Examples/linechart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

include_once '../loader.php';

use GoogleChartGenerator\Library\LineChart\LineChart;
use GoogleChartGenerator\Library\LineChart\Line;

function getRandomData($size, $min = 0, $max = 100) {
$values = $keys = array();
for ($i=0; $i < $size; $i++) {
$values[] = rand($min, $max);
$keys[] = $i;
}
return array_combine($keys, $values);
}

$charts = array();

// default settings
$chart = new LineChart(array('title' => 'Default settings'));
$chart->addLine(new Line(getRandomData(20)));
$charts[] = $chart;

// size, y axis
$chart = new LineChart(array('title' => 'Size, y axis'));
$chart->setSize('500x200');
$chart->getYAxis()->setMax(150)->setMin(-50);
$line = new Line(array(72.932,74.812,74.436,78.195,66.917,73.308,68.045,66.165,64.286,77.068,65.789,57.895,67.669,64.286,71.429,81.579,85.338,64.662,67.293,75.188,60.902,66.917,74.812,85.338,72.932,73.308,72.556,75.564,75.564,74.812,77.82,78.947,77.444));
$chart->addLine($line);
$charts[] = $chart;

// size, more lines, colours, widths
$chart = new LineChart(array('title' => 'Size, more lines, colors, widths'));
$chart->setSize('800x200');
$chart->getYAxis()->setMax(100);
$chart->setLegend('b');
$line = new Line(getRandomData(20, 40, 60), array('title' => 'Line #1'));
$line->setWidth(4);
$line2 = new Line(getRandomData(20, 20, 80), array('title' => 'Line #2'));
$line2->setWidth(3);
$line3 = new Line(getRandomData(20, 20, 80), array('title' => 'Line #3'));
$line3->setWidth(2);
$line4 = new Line(getRandomData(20), array('title' => 'grey line'));
$line4->setColour('eeeeee');
$chart->addLine($line4);
$chart->addLine($line);
$chart->addLine($line2);
$chart->addLine($line3);
try {
$dir = __DIR__ . '/cache';
if (!is_dir($dir)) {
mkdir($dir);
}
$chart->download($dir . '/' . time() . '.png');
} catch (Exception $e) { }
$charts[] = $chart;

// custom x values
$chart = new LineChart(array('legend' => true));
$chart->addLine(new Line(getRandomData(10, 10, 60), array('title' => 'Line #1')));
$chart->addLine(new Line(array(4 => 50, 5 => 30, 7 => 30, 8 => 45), array('title' => 'Line #2')));
$chart->addLine(new Line(array(2 => 50, 3 => 30, 4 => 35, 5 => 45, 6 => 20), array('title' => 'Line #3')));
$chart->getXAxis()->setMin(0)->setMax(10);
$chart->getYAxis()->setMin(10)->setMax(60);
$charts[] = $chart;

// sparkline #1
$chart = new LineChart();
$chart->setTitle(null);
$chart->setSize('180x120');
$chart->setSparkline(true);
$chart->addLine(new Line(array(5,6,14,8,11,3,2,29,35,26,40,29,51,60,57,6,2,1), array('color' => '000088')));
$charts[] = $chart;

// sparkline #2
$chart = new LineChart(array('title' => null, 'size' => '180x120', 'sparkline' => true));
$chart->addLine(new Line(array(5,6,14,8,11,3,2,29,35,26,40,29,51,60,57,6,2,1), array('color' => '880000')));
$charts[] = $chart;

// legend position
$chart = new LineChart(array('title' => null, 'size' => '180x120', 'legend' => 'b'));
$chart->addLine(new Line(array(2 => 50, 3 => 30, 4 => 35, 5 => 45, 6 => 20), array('title' => 'hello!')));
$charts[] = $chart;

$chart = new LineChart(array('title' => null, 'size' => '180x120'/*, 'legend' => 'b'*/));
$chart->getXAxis()->setEnabled(false);
$chart->getYAxis()->setEnabled(false);
$chart->addLine(new Line(array(5,24,18,8,11,27,26,29,35,20), array('width' => 3, 'title' => 'blue', 'color' => '0070C0')));
$chart->addLine(new Line(array(8,11,25,2,29,35,8,40,29,23), array('width' => 3, 'title' => 'orange', 'color' => 'F07200')));
$charts[] = $chart;

$chart = new LineChart(array('title' => null, 'size' => '180x120'/*, 'legend' => 'b'*/));
$chart->getXAxis()->setEnabled(false);
$chart->getYAxis()->setEnabled(false);
$chart->addLine(new Line(array(8,11,25,2,29,35,8,40,29,23), array('width' => 3, 'title' => 'orange', 'color' => 'F07200')));
$chart->addLine(new Line(array(5,24,18,8,11,27,26,29,35,20), array('width' => 3, 'title' => 'blue', 'color' => '0070C0')));
$charts[] = $chart;

// data plain text encoding
$chart = new LineChart(array('title' => 'Plain text encoding'));
$chart->addLine(new Line(getRandomData(20)));
$charts[] = $chart;

include 'view.php';
34 changes: 34 additions & 0 deletions Examples/piechart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

include_once '../loader.php';

use GoogleChartGenerator\Library\PieChart\PieChart;
use GoogleChartGenerator\Library\PieChart\Arc;

$charts = array();

$chart = new PieChart(array('title' => 'Default settings'));
$chart->addData(new Arc(40));
$chart->addData(new Arc(60));
$chart->addData(new Arc(30));
$charts[] = $chart;

$chart = new PieChart();
$chart->addData(array(new Arc(40), new Arc(60, array('color' => 'BBBBBB')), new Arc(30)));
$chart->setOrientation(0.5);
$charts[] = $chart;

$chart = new PieChart(array('legend' => true));
$chart->addData(new Arc(rand(1,30), array('title' => 'Arc #1')));
$chart->addData(new Arc(rand(1,30), array('title' => 'Arc #2')));
$chart->addData(new Arc(rand(1,30), array('title' => 'Arc #3')));
$chart->addData(new Arc(rand(1,30), array('title' => 'Arc #4')));
$charts[] = $chart;

$chart = new PieChart(array('legend' => true, '3d' => true));
for ($i=1; $i < 5; $i++) {
$chart->addData(new Arc(rand(1,30), array('title' => 'Arc #' . $i)));
}
$charts[] = $chart;

include 'view.php';
49 changes: 49 additions & 0 deletions Examples/view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
function niceDump($chartUrl) {
$chartUrl = preg_replace('/([\&|\?])(.*)\=/U', '\1<span class="option">\2</span>=', $chartUrl);
return $chartUrl;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GoogleChartGenerator</title>

<style>
body { padding: 0; margin: 0; }
h1 { font-size: 20px; }
.tabs { width: 100%; }
.tabs > div { padding: 5px; }
.tabs > div pre { border: 1px solid #ddd; border-radius: 3px; padding: 5px; background: #eee; }
span.option { color: green; }
.ui-tabs-hide { display: none; }
</style>

</head>
<body>
<?php foreach ($charts as $index => $chart) : ?>
<div class="tabs">
<ul>
<li><a href="#tab-chart<?php echo $index; ?>-image">image</a></li>
<li><a href="#tab-chart<?php echo $index; ?>-url">url</a></li>
<li><a href="#tab-chart<?php echo $index; ?>-data">data</a></li>
<li><a href="#tab-chart<?php echo $index; ?>-options">options</a></li>
</ul>
<div id="tab-chart<?php echo $index; ?>-image"><?php echo $chart->render(); ?></div>
<div id="tab-chart<?php echo $index; ?>-url"><pre><?php echo niceDump($chart->debugUrl()); ?></pre></div>
<div id="tab-chart<?php echo $index; ?>-data"><pre><?php print_r($chart->getData()); ?></pre></div>
<div id="tab-chart<?php echo $index; ?>-options"><pre><?php print_r($chart->getOptions()); ?></pre></div>
</div>
<?php endforeach; ?>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>

<script type="text/javascript">
$(function() {
$('.tabs').tabs();
});
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2011 by Martin Sikora <http://www.martinsikora.com/googlechartbundle>
Copyright (C) 2011 by Martin Sikora <http://www.martinsikora.com/googlechartgenerator>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions lib/Axis.php → Library/Axis.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Bundle\GoogleChartBundle\Library;
namespace GoogleChartGenerator\Library;

use Bundle\GoogleChartBundle\Library\Font;
use GoogleChartGenerator\Library\Font;

This comment has been minimized.

Copy link
@stof

stof Jun 14, 2011

having a Library subnamespace does not make sense. And your library does not follow theconventions. Look at https://github.com/Seldaek/monolog to see how the repo looks like


/**
* Class representing an anix, supports chaining
Expand Down
13 changes: 13 additions & 0 deletions Library/BarChart/Bar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace GoogleChartGenerator\Library\BarChart;

use GoogleChartGenerator\Library\DataCollection\SequenceData;

include_once __DIR__ . '/../DataCollection/SequenceData.php';

This comment has been minimized.

Copy link
@stof

stof Jun 14, 2011

include_once ? really ? You should follow the PSR-0 convention and use an autoloader

This comment has been minimized.

Copy link
@martinsik

martinsik Jun 14, 2011

Owner

calm down, it's v0.1.4 so far...

This comment has been minimized.

Copy link
@stof

stof Jun 14, 2011

well, your commit message is finished transformation into a standalone library. but this transformation is far from being completed

This comment has been minimized.

Copy link
@martinsik

martinsik Jun 14, 2011

Owner

message is perfectly correct, it's a standalone library. Standards are another issue and it makes sence to me so i'll definitely take it into account in the next commit.


class Bar extends SequenceData {



}
32 changes: 25 additions & 7 deletions lib/BarChart/BarChart.php → Library/BarChart/BarChart.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

namespace Bundle\GoogleChartBundle\Library\BarChart;
namespace GoogleChartGenerator\Library\BarChart;

use Bundle\GoogleChartBundle\Library\Chart\AbstractAxisChart;
use Bundle\GoogleChartBundle\Library\Axis;
include_once __DIR__ . '/Bar.php';
include_once __DIR__ . '/../Chart/AbstractAxisChart.php';

use GoogleChartGenerator\Library\Chart\AbstractAxisChart;
use GoogleChartGenerator\Library\Axis;

class BarChart extends AbstractAxisChart {

Expand Down Expand Up @@ -71,26 +74,41 @@ public function isStacked() {

protected function getDataUrlPart() {
//$series = array();
$dataString = 't:';
$dataString = $this->getDataFormatSign() . ':';
//$chartType = $this->getChartTypeUrlPart();
list($min, $max) = /*$this->isVertical() ? */$this->getYDimensions()/* : $this->getXDimensions()*/;
$range = $max - $min;

list($xmin, $xmax) = $this->getXDimensions();
$xrange = $xmax - $xmin;
if ($xmax > 61) {
$this->setDataFormat(self::DATAFORMAT_TEXT);
}

//var_dump($min, $max);

foreach ($this->getData() as $dataCollection) {
$data = array();
foreach ($dataCollection->getData() as $x => $value) {
$data[] = $dataCollection->applyPrintStrategy(($value - $min) / $range);
/*if ($this->getDataFormat() == self::DATAFORMAT_TEXT) {
$data[] = ($value - $min) / $range);
} else {
$data[] = $dataCollection->applyPrintStrategy(($value - $min) / $range);
}*/
$dataString .= $this->encodeValue(($value - $min) / $range);
}

$dataString .= implode(',', $data) . '|';
//$dataString .= /*implode(',', $data) . */ '|';

// add dataset separator
$dataString .= $this->getDataFormat() == self::DATAFORMAT_TEXT ? '|' : ',';

//$series[] = array($keysString ? $keysString : '-1|', substr($valuesString, 0, -1));
}

//$dataString = implode($this->getChartTypeUrlPart() == 'lxy' ? '|-1|' : '|', $series);

return trim($dataString, '|');
return trim($dataString, '|,');

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?php

namespace Bundle\GoogleChartBundle\Library\Chart;
namespace GoogleChartGenerator\Library\Chart;

use Bundle\GoogleChartBundle\Library\Chart\AbstractChart;
use Bundle\GoogleChartBundle\Library\Axis;
use Bundle\GoogleChartBundle\Library\Grid;
include_once __DIR__ . '/AbstractChart.php';
include_once __DIR__ . '/../Axis.php';
include_once __DIR__ . '/../Font.php';
include_once __DIR__ . '/../Grid.php';

use GoogleChartGenerator\Library\Chart\AbstractChart;
use GoogleChartGenerator\Library\Axis;
use GoogleChartGenerator\Library\Grid;

abstract class AbstractAxisChart extends AbstractChart {

Expand Down
Loading

0 comments on commit 870e1c7

Please sign in to comment.