Commit a24f9c6e158c152305be632e9deded022f625e4e

Authored by Edmar Moretti
1 parent 45416058

$1

admin/admin.db
No preview for this file type
admin/js/estat_variavel.js
@@ -426,19 +426,21 @@ i3GEOadmin.variaveis = { @@ -426,19 +426,21 @@ i3GEOadmin.variaveis = {
426 if(redesenha){tree.draw();} 426 if(redesenha){tree.draw();}
427 }, 427 },
428 classesAuto: function(id_classificacao,id_medida_variavel){ 428 classesAuto: function(id_classificacao,id_medida_variavel){
429 - core_montaEditor("","450px","200px","","Criar classes");  
430 - var ins = "<p class='paragrafo' >Utilize um dos m&eacute;todos abaixo para gerar as classes que ser&atilde;o utilizadas para representar os dados no cartograma</p>" +  
431 - "&nbsp;<input id=i3GEOFmetaestatEditorBotao8 type='button' value='Escolher cores' />" +  
432 - "<br><br>";  
433 - ins += "&nbsp;<input id=i3GEOFmetaestatEditorBotao6 type='button' value='Divis&atilde;o em quartis' />" +  
434 - "&nbsp;<input id=i3GEOFmetaestatEditorBotao7 type='button' value='5 intervalos iguais' />";  
435 - ins += '<input type=hidden value="" id="listaColourRampEditor" />'; //utilizado pelo seletor de colourramp; 429 + core_montaEditor("","450px","230px","","Criar classes");
  430 + var ins = "" +
  431 + "<p class='paragrafo' >&nbsp;N&uacute;mero de intervalos de classes: <input type=text value=5 id=i3GEOFmetaestatEditorNumInt size=5 /></p>" +
  432 + "&nbsp;<input id=i3GEOFmetaestatEditorBotao8 type='button' value='Escolher cores' />" +
  433 + "<p class='paragrafo' >Utilize um dos m&eacute;todos abaixo para gerar as classes que ser&atilde;o utilizadas para representar os dados no cartograma</p>" +
  434 + "&nbsp;<input id=i3GEOFmetaestatEditorBotao6 type='button' value='Divis&atilde;o em quartis' />" +
  435 + "&nbsp;<input id=i3GEOFmetaestatEditorBotao7 type='button' value='Intervalos iguais' />" +
  436 + "&nbsp;<input id=i3GEOFmetaestatEditorBotaoQN type='button' value='Quebras naturais' />" +
  437 + '<input type=hidden value="" id="listaColourRampEditor" />'; //utilizado pelo seletor de colourramp;
436 $i("editor_bd").innerHTML = ins; 438 $i("editor_bd").innerHTML = ins;
437 new YAHOO.widget.Button( 439 new YAHOO.widget.Button(
438 "i3GEOFmetaestatEditorBotao8", 440 "i3GEOFmetaestatEditorBotao8",
439 {onclick:{fn: 441 {onclick:{fn:
440 function(){ 442 function(){
441 - i3GEO.util.abreColourRamp("","listaColourRampEditor",5); 443 + i3GEO.util.abreColourRamp("","listaColourRampEditor",$i("i3GEOFmetaestatEditorNumInt").value);
442 } 444 }
443 }} 445 }}
444 ); 446 );
@@ -476,7 +478,36 @@ i3GEOadmin.variaveis = { @@ -476,7 +478,36 @@ i3GEOadmin.variaveis = {
476 {onclick:{fn: 478 {onclick:{fn:
477 function(){ 479 function(){
478 var cores = $i("listaColourRampEditor").value, 480 var cores = $i("listaColourRampEditor").value,
479 - p = i3GEO.configura.locaplic+"/admin/php/metaestat.php?funcao=calculaClassificacao&tipo=intiguais5&cores="+cores+"&id_classificacao="+id_classificacao+"&id_medida_variavel="+id_medida_variavel, 481 + p = i3GEO.configura.locaplic+"/admin/php/metaestat.php?funcao=calculaClassificacao&tipo=intiguais&cores="+cores+"&id_classificacao="+id_classificacao+"&id_medida_variavel="+id_medida_variavel+"&numintervalos="+$i("i3GEOFmetaestatEditorNumInt").value,
  482 + callback;
  483 + if(cores == ""){
  484 + alert("Escolha as cores primeiro");
  485 + return;
  486 + }
  487 + callback = {
  488 + success:function(o){
  489 + try {
  490 + core_carregando("desativa");
  491 + var no = tree.getNodeByProperty("id_classificacao",id_classificacao);
  492 + tree.removeChildren(no) ;
  493 + no.expand();
  494 + }
  495 + catch(e){core_handleFailure(e,o.responseText);}
  496 + },
  497 + failure:core_handleFailure,
  498 + argument: { foo:"foo", bar:"bar" }
  499 + };
  500 + core_carregando("ativa");
  501 + core_makeRequest(p,callback);
  502 + }
  503 + }}
  504 + );
  505 + new YAHOO.widget.Button(
  506 + "i3GEOFmetaestatEditorBotaoQN",
  507 + {onclick:{fn:
  508 + function(){
  509 + var cores = $i("listaColourRampEditor").value,
  510 + p = i3GEO.configura.locaplic+"/admin/php/metaestat.php?funcao=calculaClassificacao&tipo=quebrasnaturais&cores="+cores+"&id_classificacao="+id_classificacao+"&id_medida_variavel="+id_medida_variavel+"&numintervalos="+$i("i3GEOFmetaestatEditorNumInt").value,
480 callback; 511 callback;
481 if(cores == ""){ 512 if(cores == ""){
482 alert("Escolha as cores primeiro"); 513 alert("Escolha as cores primeiro");
admin/php/classe_metaestat.php
@@ -425,7 +425,10 @@ class Metaestat{ @@ -425,7 +425,10 @@ class Metaestat{
425 $sqlDadosMedidaVariavel = "SELECT $sqlWMST as dimtempo,".$dados["colunaidgeo"]." AS cod_regiao,".$dados["colunavalor"]." AS valorcalculado FROM ".$dados["esquemadb"].".".$dados["tabela"]; 425 $sqlDadosMedidaVariavel = "SELECT $sqlWMST as dimtempo,".$dados["colunaidgeo"]." AS cod_regiao,".$dados["colunavalor"]." AS valorcalculado FROM ".$dados["esquemadb"].".".$dados["tabela"];
426 } 426 }
427 if(!empty ($filtro)){ 427 if(!empty ($filtro)){
428 - $sqlDadosMedidaVariavel .= " WHERE ".$filtro; 428 + $sqlDadosMedidaVariavel .= " WHERE ".$filtro . "AND ".$dados["colunavalor"]." IS NOT NULL ";
  429 + }
  430 + else{
  431 + $sqlDadosMedidaVariavel .= " WHERE ".$dados["colunavalor"]." IS NOT NULL ";
429 } 432 }
430 if($suportaWMST != true){ 433 if($suportaWMST != true){
431 $sqlDadosMedidaVariavel .= " /*FA*//*FA*/ /*FAT*//*FAT*/ GROUP BY cod_regiao "; 434 $sqlDadosMedidaVariavel .= " /*FA*//*FA*/ /*FAT*//*FAT*/ GROUP BY cod_regiao ";
admin/php/metaestat.php
@@ -499,6 +499,42 @@ switch (strtoupper($funcao)) @@ -499,6 +499,42 @@ switch (strtoupper($funcao))
499 if(empty($limite)){ 499 if(empty($limite)){
500 $limite = 10000; 500 $limite = 10000;
501 } 501 }
  502 + if($tipo == "quebrasnaturais"){
  503 + $m = new Metaestat();
  504 + $dados = $m->dadosMedidaVariavel($id_medida_variavel,"",0,"",$limite);
  505 + $metaVariavel = $m->listaMedidaVariavel("",$id_medida_variavel);
  506 + $colunavalor = $metaVariavel["colunavalor"];
  507 + $valores = array();
  508 +
  509 + foreach($dados as $d){
  510 + if($d[$colunavalor]){
  511 + $valores[] = $d[$colunavalor];
  512 + }
  513 + }
  514 + include(dirname(__FILE__)."/../../pacotes/jenks-master/jenks.php");
  515 + $intervalos = getJenksClasses($numintervalos, $valores);
  516 + $m->excluirRegistro("i3geoestat_classes","id_classificacao",$id_classificacao);
  517 + for ($i=0; $i < $numintervalos; ++$i){
  518 + if ($i == $numintervalos - 1){
  519 + $expressao = "(([".$colunavalor."]>=".$intervalos[$i].")";
  520 + $titulo = ">= ".$intervalos[$i];
  521 + }
  522 + else{
  523 + $expressao = "(([".$colunavalor."]>=".$intervalos[$i].")and([".$colunavalor."]<".$intervalos[$i+1]."))";
  524 + $titulo = ">= ".$intervalos[$i]." e < que ".($intervalos[$i+1]);
  525 + }
  526 + $id_classe = $m->alteraClasseClassificacao($id_classificacao);
  527 + if(!empty($cores)){
  528 + $cor = explode(",",$cores[$i]);
  529 + $vermelho = $cor[0];
  530 + $verde = $cor[1];
  531 + $azul = $cor[2];
  532 + }
  533 + $m->alteraClasseClassificacao("",$id_classe,$titulo,$expressao,$vermelho,$verde,$azul,"","","255","255","255","2");
  534 + }
  535 + retornaJSON("ok");
  536 + exit;
  537 + }
502 if($tipo == "quartil"){ 538 if($tipo == "quartil"){
503 $m = new Metaestat(); 539 $m = new Metaestat();
504 $dados = $m->sumarioMedidaVariavel($id_medida_variavel,"","",$limite); 540 $dados = $m->sumarioMedidaVariavel($id_medida_variavel,"","",$limite);
@@ -521,8 +557,14 @@ switch (strtoupper($funcao)) @@ -521,8 +557,14 @@ switch (strtoupper($funcao))
521 } 557 }
522 $m->alteraClasseClassificacao("",$id_classe,$titulo,$expressao,$vermelho,$verde,$azul,"","","255","255","255","2"); 558 $m->alteraClasseClassificacao("",$id_classe,$titulo,$expressao,$vermelho,$verde,$azul,"","","255","255","255","2");
523 } 559 }
  560 + retornaJSON("ok");
  561 + exit;
  562 + }
  563 + //para efeitos de compatibilidade com o nome de $tipo
  564 + if(empty($numintervalos) || $tipo == "intiguais5"){
  565 + $numintervalos = 5;
524 } 566 }
525 - if($tipo == "intiguais5"){ 567 + if($tipo == "intiguais5" || $tipo == "intiguais"){
526 $m = new Metaestat(); 568 $m = new Metaestat();
527 $dados = $m->sumarioMedidaVariavel($id_medida_variavel,"","",$limite); 569 $dados = $m->sumarioMedidaVariavel($id_medida_variavel,"","",$limite);
528 if($dados == false){ 570 if($dados == false){
@@ -532,12 +574,12 @@ switch (strtoupper($funcao)) @@ -532,12 +574,12 @@ switch (strtoupper($funcao))
532 $min = $dados["menor"]; 574 $min = $dados["menor"];
533 $max = $dados["maior"]; 575 $max = $dados["maior"];
534 $item = $dados["colunavalor"]; 576 $item = $dados["colunavalor"];
535 - $intervalo = ($max - $min) / 5; 577 + $intervalo = ($max - $min) / $numintervalos;
536 //adiciona as classes novas 578 //adiciona as classes novas
537 $intatual = $min; 579 $intatual = $min;
538 $m->excluirRegistro("i3geoestat_classes","id_classificacao",$id_classificacao); 580 $m->excluirRegistro("i3geoestat_classes","id_classificacao",$id_classificacao);
539 - for ($i=0; $i < 5; ++$i){  
540 - if ($i == 5 - 1){ 581 + for ($i=0; $i < $numintervalos; ++$i){
  582 + if ($i == $numintervalos - 1){
541 $expressao = "(([".$item."]>=".$intatual.")and([".$item."]<=".($intatual+$intervalo)."))"; 583 $expressao = "(([".$item."]>=".$intatual.")and([".$item."]<=".($intatual+$intervalo)."))";
542 } 584 }
543 else{ 585 else{
@@ -554,18 +596,24 @@ switch (strtoupper($funcao)) @@ -554,18 +596,24 @@ switch (strtoupper($funcao))
554 } 596 }
555 $m->alteraClasseClassificacao("",$id_classe,$titulo,$expressao,$vermelho,$verde,$azul,"","","255","255","255","2"); 597 $m->alteraClasseClassificacao("",$id_classe,$titulo,$expressao,$vermelho,$verde,$azul,"","","255","255","255","2");
556 } 598 }
  599 + retornaJSON("ok");
  600 + exit;
557 } 601 }
558 //o menor e o maior valor sao enviados como parametro ($min e $max) 602 //o menor e o maior valor sao enviados como parametro ($min e $max)
559 - if($tipo == "intiguais5mm"){ 603 + //para efeitos de compatibilidade com o nome de $tipo
  604 + if(empty($numintervalos) || $tipo == "intiguais5mm"){
  605 + $numintervalos = 5;
  606 + }
  607 + if($tipo == "intiguais5mm" || $tipo == "intiguaismm"){
560 $m = new Metaestat(); 608 $m = new Metaestat();
561 $metaVariavel = $m->listaMedidaVariavel("",$id_medida_variavel); 609 $metaVariavel = $m->listaMedidaVariavel("",$id_medida_variavel);
562 $item = $metaVariavel["colunavalor"]; 610 $item = $metaVariavel["colunavalor"];
563 - $intervalo = ($max - $min) / 5; 611 + $intervalo = ($max - $min) / $numintervalos;
564 //adiciona as classes novas 612 //adiciona as classes novas
565 $intatual = $min; 613 $intatual = $min;
566 $m->excluirRegistro("i3geoestat_classes","id_classificacao",$id_classificacao); 614 $m->excluirRegistro("i3geoestat_classes","id_classificacao",$id_classificacao);
567 - for ($i=0; $i < 5; ++$i){  
568 - if ($i == 5 - 1){ 615 + for ($i=0; $i < $numintervalos; ++$i){
  616 + if ($i == $numintervalos - 1){
569 $expressao = "(([".$item."]>=".$intatual.")and([".$item."]<=".($intatual+$intervalo)."))"; 617 $expressao = "(([".$item."]>=".$intatual.")and([".$item."]<=".($intatual+$intervalo)."))";
570 } 618 }
571 else{ 619 else{
@@ -581,9 +629,11 @@ switch (strtoupper($funcao)) @@ -581,9 +629,11 @@ switch (strtoupper($funcao))
581 $azul = $cor[2]; 629 $azul = $cor[2];
582 } 630 }
583 $m->alteraClasseClassificacao("",$id_classe,$titulo,$expressao,$vermelho,$verde,$azul,"","","255","255","255","2"); 631 $m->alteraClasseClassificacao("",$id_classe,$titulo,$expressao,$vermelho,$verde,$azul,"","","255","255","255","2");
584 - } 632 + }
  633 + retornaJSON("ok");
  634 + exit;
585 } 635 }
586 - retornaJSON("ok"); 636 + retornaJSON("ok");
587 exit; 637 exit;
588 break; 638 break;
589 /* 639 /*
classesphp/classe_alteraclasse.php
@@ -97,8 +97,8 @@ function: salva @@ -97,8 +97,8 @@ function: salva
97 Salva o mapfile atual 97 Salva o mapfile atual
98 98
99 */ 99 */
100 - function salva()  
101 - { 100 + function salva()
  101 + {
102 if (connection_aborted()){exit();} 102 if (connection_aborted()){exit();}
103 $this->mapa->save($this->arquivo); 103 $this->mapa->save($this->arquivo);
104 } 104 }
@@ -286,7 +286,7 @@ $ignorar - valor que ser&amp;aacute; ignorado na listagem final @@ -286,7 +286,7 @@ $ignorar - valor que ser&amp;aacute; ignorado na listagem final
286 {return ("erro. Nenhum valor numerico no item");} 286 {return ("erro. Nenhum valor numerico no item");}
287 } 287 }
288 /* 288 /*
289 - function: quantil 289 + function: quantil
290 290
291 Cria classes em um objeto layer com intervalos baseados no calculo de quantil 291 Cria classes em um objeto layer com intervalos baseados no calculo de quantil
292 292
@@ -355,6 +355,69 @@ $ignorar - valor que ser&amp;aacute; ignorado na listagem final @@ -355,6 +355,69 @@ $ignorar - valor que ser&amp;aacute; ignorado na listagem final
355 return ("erro. Nenhum valor numerico no item"); 355 return ("erro. Nenhum valor numerico no item");
356 } 356 }
357 } 357 }
  358 + /*
  359 + function: quebrasnaturais
  360 +
  361 + Cria classes em um objeto layer com intervalos baseados no calculo de quebras naturais
  362 +
  363 + Parametros:
  364 +
  365 + $item - item da tabela de atributos
  366 +
  367 + $nclasses - n&uacute;mero de classes
  368 +
  369 + $ignorar - valor que ser&aacute; ignorado na listagem final
  370 + */
  371 + function quebrasnaturais($item,$nclasses,$ignorar)
  372 + {
  373 + if(!$this->layer){return "erro";}
  374 + $valores = $this->pegaValores($this->mapa,$this->layer,$item,true,$ignorar);
  375 + if (count($valores) > 0){
  376 + include(dirname(__FILE__)."/../pacotes/jenks-master/jenks.php");
  377 + $classBreaks = getJenksClasses($nclasses, $valores);
  378 + //echo "<pre>";var_dump($classBreaks);exit;
  379 + $numclassesatual = $this->layer->numclasses;
  380 + //apaga todas as classes existentes
  381 + $classetemp = $this->layer->getClass(0);
  382 + $estilotemp = $classetemp->getStyle(0);
  383 + for ($i=0; $i < $numclassesatual; ++$i){
  384 + $classe = $this->layer->getClass($i);
  385 + $classe->set("status",MS_DELETE);
  386 + }
  387 + //adiciona as classes novas
  388 + for ($i=0; $i < $nclasses; ++$i){
  389 + $expressao = "(([".$item."]>".$classBreaks[$i].")and([".$item."]<=".$classBreaks[$i + 1]."))";
  390 + $nomeclasse = "> ".$classBreaks[$i]." e <= que ".($classBreaks[$i + 1]);
  391 + if($i == 0){
  392 + $expressao = "([".$item."]<=".$classBreaks[$i + 1].")";
  393 + $nomeclasse = "<= que ".($classBreaks[$i + 1]);
  394 + }
  395 + if($i == ($nclasses - 1)){
  396 + $expressao = "([".$item."] >=".$classBreaks[$i].")";
  397 + $nomeclasse = ">= que ".($classBreaks[$i]);
  398 + }
  399 + $classe = ms_newClassObj($this->layer);
  400 + $novoestilo = ms_newStyleObj($classe);
  401 + if ($this->layer->type == 0){
  402 + $novoestilo->set("symbolname","ponto");
  403 + $novoestilo->set("size","6");
  404 + }
  405 + $ncor = $novoestilo->color;
  406 + $ncor->setrgb((mt_rand(0,255)),(mt_rand(0,255)),(mt_rand(0,255)));
  407 + $ncor = $novoestilo->outlinecolor;
  408 + $ncor->setrgb(255,255,255);
  409 + $classe->setexpression($expressao);
  410 + $classe->set("name",$nomeclasse);
  411 + //$classe->set("title",($this->layer->name)."+".$i);
  412 + }
  413 + $this->layer->setMetaData("cache","");
  414 + return ("ok");
  415 + }
  416 + else{
  417 + return ("erro. Nenhum valor numerico no item");
  418 + }
  419 + }
  420 +
358 /* 421 /*
359 function: quartis 422 function: quartis
360 423
@@ -378,10 +441,10 @@ Include: @@ -378,10 +441,10 @@ Include:
378 $valores = $this->pegaValores($this->mapa,$this->layer,$item,true,$ignorar); 441 $valores = $this->pegaValores($this->mapa,$this->layer,$item,true,$ignorar);
379 if (count($valores) > 0) 442 if (count($valores) > 0)
380 { 443 {
381 - if(file_exists($this->locaplic."/classe_estatistica.php"))  
382 - include_once($this->locaplic."/classe_estatistica.php");  
383 - else  
384 - include_once("classe_estatistica.php"); 444 + if(file_exists($this->locaplic."/classe_estatistica.php"))
  445 + include_once($this->locaplic."/classe_estatistica.php");
  446 + else
  447 + include_once("classe_estatistica.php");
385 $estat = new estatistica(); 448 $estat = new estatistica();
386 $estat->calcula($valores); 449 $estat->calcula($valores);
387 $calc = $estat->resultado; 450 $calc = $estat->resultado;
classesphp/mapa_controle.php
@@ -1114,6 +1114,8 @@ Altera uma classe de um tema, aplicando uma nova classifica&amp;ccedil;&amp;atilde;o ou @@ -1114,6 +1114,8 @@ Altera uma classe de um tema, aplicando uma nova classifica&amp;ccedil;&amp;atilde;o ou
1114 {$retorno = $m->intervalosiguais($item,$nclasses,$ignorar);} 1114 {$retorno = $m->intervalosiguais($item,$nclasses,$ignorar);}
1115 if ($opcao == "quantil") 1115 if ($opcao == "quantil")
1116 {$retorno = $m->quantil($item,$nclasses,$ignorar);} 1116 {$retorno = $m->quantil($item,$nclasses,$ignorar);}
  1117 + if ($opcao == "quebrasnaturais")
  1118 + {$retorno = $m->quebrasnaturais($item,$nclasses,$ignorar);}
1117 if ($opcao == "quartis") 1119 if ($opcao == "quartis")
1118 { 1120 {
1119 if(!isset($tipoLegenda)) 1121 if(!isset($tipoLegenda))
ferramentas/legenda/dicionario.js
@@ -563,5 +563,11 @@ i3GEOF.legenda.dicionario = { @@ -563,5 +563,11 @@ i3GEOF.legenda.dicionario = {
563 en:"", 563 en:"",
564 es:"", 564 es:"",
565 it:"" 565 it:""
  566 + }],
  567 + 95: [{
  568 + pt:"Quebras naturais",
  569 + en:"",
  570 + es:"",
  571 + it:""
566 }] 572 }]
567 }; 573 };
568 \ No newline at end of file 574 \ No newline at end of file
ferramentas/legenda/index.js
@@ -211,23 +211,30 @@ i3GEOF.legenda = { @@ -211,23 +211,30 @@ i3GEOF.legenda = {
211 {onclick:{fn: i3GEOF.legenda.representacao}} 211 {onclick:{fn: i3GEOF.legenda.representacao}}
212 ); 212 );
213 $i("i3GEOlegendabotao7-button").style.width = "200px"; 213 $i("i3GEOlegendabotao7-button").style.width = "200px";
  214 +
214 new YAHOO.widget.Button( 215 new YAHOO.widget.Button(
215 "i3GEOlegendabotao8", 216 "i3GEOlegendabotao8",
216 {onclick:{fn: i3GEOF.legenda.valorC}} 217 {onclick:{fn: i3GEOF.legenda.valorC}}
217 ); 218 );
218 - $i("i3GEOlegendabotao8-button").style.width = "200px"; 219 + $i("i3GEOlegendabotao8-button").style.width = "120px";
219 220
220 new YAHOO.widget.Button( 221 new YAHOO.widget.Button(
221 "i3GEOlegendabotao9", 222 "i3GEOlegendabotao9",
222 {onclick:{fn: i3GEOF.legenda.valorQ}} 223 {onclick:{fn: i3GEOF.legenda.valorQ}}
223 ); 224 );
224 - $i("i3GEOlegendabotao9-button").style.width = "200px"; 225 + $i("i3GEOlegendabotao9-button").style.width = "120px";
225 226
226 new YAHOO.widget.Button( 227 new YAHOO.widget.Button(
227 "i3GEOlegendabotaoQuantil", 228 "i3GEOlegendabotaoQuantil",
228 {onclick:{fn: i3GEOF.legenda.valorQu}} 229 {onclick:{fn: i3GEOF.legenda.valorQu}}
229 ); 230 );
230 - $i("i3GEOlegendabotaoQuantil-button").style.width = "200px"; 231 + $i("i3GEOlegendabotaoQuantil-button").style.width = "120px";
  232 +
  233 + new YAHOO.widget.Button(
  234 + "i3GEOlegendabotaoQN",
  235 + {onclick:{fn: i3GEOF.legenda.valorQN}}
  236 + );
  237 + $i("i3GEOlegendabotaoQN-button").style.width = "120px";
231 238
232 new YAHOO.widget.Button( 239 new YAHOO.widget.Button(
233 "i3GEOlegendabotao10", 240 "i3GEOlegendabotao10",
@@ -235,6 +242,7 @@ i3GEOF.legenda = { @@ -235,6 +242,7 @@ i3GEOF.legenda = {
235 ); 242 );
236 if(navm) 243 if(navm)
237 {$i("i3GEOlegendabotao10-button").style.width = "0px";} 244 {$i("i3GEOlegendabotao10-button").style.width = "0px";}
  245 +
238 new YAHOO.widget.Button( 246 new YAHOO.widget.Button(
239 "i3GEOlegendabotao17", 247 "i3GEOlegendabotao17",
240 {onclick:{fn: i3GEOF.legenda.alteraGeometriaTema}} 248 {onclick:{fn: i3GEOF.legenda.alteraGeometriaTema}}
@@ -401,6 +409,7 @@ i3GEOF.legenda = { @@ -401,6 +409,7 @@ i3GEOF.legenda = {
401 ' <p class=paragrafo >'+$trad(40,i3GEOF.legenda.dicionario)+':'+ 409 ' <p class=paragrafo >'+$trad(40,i3GEOF.legenda.dicionario)+':'+
402 $inputText("","","i3GEOlegendanclasses","",3,"5") + 410 $inputText("","","i3GEOlegendanclasses","",3,"5") +
403 ' <p class=paragrafo ><input id=i3GEOlegendabotao8 size="25" type="button" value="'+$trad(41,i3GEOF.legenda.dicionario)+'">'+ 411 ' <p class=paragrafo ><input id=i3GEOlegendabotao8 size="25" type="button" value="'+$trad(41,i3GEOF.legenda.dicionario)+'">'+
  412 + ' &nbsp;<input id=i3GEOlegendabotaoQN size="25" type="button" value="'+$trad(95,i3GEOF.legenda.dicionario)+'">'+
404 ' &nbsp;<input id=i3GEOlegendabotaoQuantil size="25" type="button" value="Quantil">'+ 413 ' &nbsp;<input id=i3GEOlegendabotaoQuantil size="25" type="button" value="Quantil">'+
405 ' <hr><p class=paragrafo >'+$trad(42,i3GEOF.legenda.dicionario)+'</p>'+ 414 ' <hr><p class=paragrafo >'+$trad(42,i3GEOF.legenda.dicionario)+'</p>'+
406 ' <p class=paragrafo ><input id=i3GEOlegendabotao9 size="25" type="button" value="Quartis">'+ 415 ' <p class=paragrafo ><input id=i3GEOlegendabotao9 size="25" type="button" value="Quartis">'+
@@ -1133,6 +1142,36 @@ i3GEOF.legenda = { @@ -1133,6 +1142,36 @@ i3GEOF.legenda = {
1133 catch(e){i3GEO.janela.tempoMsg("Erro: "+ e);i3GEOF.legenda.aguarde.visibility = "hidden";} 1142 catch(e){i3GEO.janela.tempoMsg("Erro: "+ e);i3GEOF.legenda.aguarde.visibility = "hidden";}
1134 }, 1143 },
1135 /* 1144 /*
  1145 + Function: valorQN
  1146 +
  1147 + Altera a legenda do tema por meio do calculo de quebras naturais
  1148 +
  1149 + Veja:
  1150 +
  1151 + <ALTERACLASSE>
  1152 + */
  1153 + valorQN: function(){
  1154 + try{
  1155 + if(i3GEOF.legenda.aguarde.visibility === "visible")
  1156 + {return;}
  1157 + var item = $i("i3GEOlegendaSelItem").value,
  1158 + nclasses = $i("i3GEOlegendanclasses").value,
  1159 + p = i3GEO.configura.locaplic+"/classesphp/mapa_controle.php?g_sid="+i3GEO.configura.sid+"&funcao=alteraclasse&nclasses="+nclasses+"&tema="+i3GEOF.legenda.tema+"&item="+item+"&opcao=quebrasnaturais&ignorar="+$i("i3GEOlegendaignorar").value+"&ext="+i3GEO.parametros.mapexten,
  1160 + cp = new cpaint(),
  1161 + fim = function(){
  1162 + i3GEOF.legenda.aposAlterarLegenda();
  1163 + i3GEOF.legenda.aguarde.visibility = "hidden";
  1164 + };
  1165 + if (item == "")
  1166 + {i3GEO.janela.tempoMsg($trad(81,i3GEOF.legenda.dicionario));return;}
  1167 + i3GEOF.legenda.aguarde.visibility = "visible";
  1168 + cp.set_response_type("JSON");
  1169 + cp.call(p,"alteraclasse",fim);
  1170 + }
  1171 + catch(e){i3GEO.janela.tempoMsg("Erro: "+ e);i3GEOF.legenda.aguarde.visibility = "hidden";}
  1172 + },
  1173 +
  1174 + /*
1136 Function: representacao 1175 Function: representacao
1137 1176
1138 Altera o tipo de representa&ccedil;&atilde;o do tema (linear ou poligonoal) 1177 Altera o tipo de representa&ccedil;&atilde;o do tema (linear ou poligonoal)
ferramentas/metaestat/index.js
@@ -1825,7 +1825,8 @@ i3GEOF.metaestat = { @@ -1825,7 +1825,8 @@ i3GEOF.metaestat = {
1825 var id_medida_variavel = $i("i3geoCartoComboMedidaVariavelEditor").value, 1825 var id_medida_variavel = $i("i3geoCartoComboMedidaVariavelEditor").value,
1826 id_classificacao = $i("i3geoCartoComboClassificacoesEditor").value, 1826 id_classificacao = $i("i3geoCartoComboClassificacoesEditor").value,
1827 cores = $i("listaColourRampEditor").value, 1827 cores = $i("listaColourRampEditor").value,
1828 - p = i3GEO.configura.locaplic+"/admin/php/metaestat.php?funcao=calculaClassificacao&tipo=intiguais5mm" + 1828 + p = i3GEO.configura.locaplic+"/admin/php/metaestat.php?funcao=calculaClassificacao&tipo=intiguaismm" +
  1829 + "&numintervalos="+$i("i3GEOFmetaestatEditorNumInt").value +
1829 "&cores="+cores+"&id_classificacao="+id_classificacao+"&id_medida_variavel="+id_medida_variavel+ 1830 "&cores="+cores+"&id_classificacao="+id_classificacao+"&id_medida_variavel="+id_medida_variavel+
1830 "&min="+$i("i3GEOFmetaestatEditorVmin").value + 1831 "&min="+$i("i3GEOFmetaestatEditorVmin").value +
1831 "&max="+$i("i3GEOFmetaestatEditorVmax").value + 1832 "&max="+$i("i3GEOFmetaestatEditorVmax").value +
@@ -1854,7 +1855,7 @@ i3GEOF.metaestat = { @@ -1854,7 +1855,7 @@ i3GEOF.metaestat = {
1854 var id_medida_variavel = $i("i3geoCartoComboMedidaVariavelEditor").value, 1855 var id_medida_variavel = $i("i3geoCartoComboMedidaVariavelEditor").value,
1855 id_classificacao = $i("i3geoCartoComboClassificacoesEditor").value, 1856 id_classificacao = $i("i3geoCartoComboClassificacoesEditor").value,
1856 cores = $i("listaColourRampEditor").value, 1857 cores = $i("listaColourRampEditor").value,
1857 - p = i3GEO.configura.locaplic+"/admin/php/metaestat.php?funcao=calculaClassificacao&tipo=intiguais5&cores="+cores+"&id_classificacao="+id_classificacao+"&id_medida_variavel="+id_medida_variavel+"&g_sid="+i3GEO.configura.sid, 1858 + p = i3GEO.configura.locaplic+"/admin/php/metaestat.php?funcao=calculaClassificacao&tipo=intiguais&numintervalos="+$i("i3GEOFmetaestatEditorNumInt").value+"&cores="+cores+"&id_classificacao="+id_classificacao+"&id_medida_variavel="+id_medida_variavel+"&g_sid="+i3GEO.configura.sid,
1858 temp = function(retorno){ 1859 temp = function(retorno){
1859 core_carregando("desativa"); 1860 core_carregando("desativa");
1860 if(retorno == "erro"){ 1861 if(retorno == "erro"){
@@ -2116,7 +2117,9 @@ i3GEOF.metaestat = { @@ -2116,7 +2117,9 @@ i3GEOF.metaestat = {
2116 "<br><p class='paragrafo' >" + $trad(10,i3GEOF.metaestat.dicionario1) + "</p>"; 2117 "<br><p class='paragrafo' >" + $trad(10,i3GEOF.metaestat.dicionario1) + "</p>";
2117 if(soma == 1 || media == 1){ 2118 if(soma == 1 || media == 1){
2118 ins += "&nbsp;<input id=i3GEOFmetaestatEditorBotao6 type='button' value='"+$trad(11,i3GEOF.metaestat.dicionario1)+"' />" + 2119 ins += "&nbsp;<input id=i3GEOFmetaestatEditorBotao6 type='button' value='"+$trad(11,i3GEOF.metaestat.dicionario1)+"' />" +
2119 - "&nbsp;<input id=i3GEOFmetaestatEditorBotao7 type='button' value='"+$trad(12,i3GEOF.metaestat.dicionario1)+"' />"; 2120 + "&nbsp;<input id=i3GEOFmetaestatEditorBotao7 type='button' value='"+$trad(12,i3GEOF.metaestat.dicionario1)+"' />" +
  2121 + "<div style='display:inline-block;position:relative;top:-10px;width:200px;' >&nbsp;intervalos: <input type=text value=5 id=i3GEOFmetaestatEditorNumInt size=5 /></div>";
  2122 +
2120 } 2123 }
2121 ins += '<input type=hidden value="" id="listaColourRampEditor" />' + //utilizado pelo seletor de colourramp; 2124 ins += '<input type=hidden value="" id="listaColourRampEditor" />' + //utilizado pelo seletor de colourramp;
2122 "<br><p class='paragrafo' >" + $trad(17,i3GEOF.metaestat.dicionario1) + "</p>" + 2125 "<br><p class='paragrafo' >" + $trad(17,i3GEOF.metaestat.dicionario1) + "</p>" +
@@ -2130,7 +2133,7 @@ i3GEOF.metaestat = { @@ -2130,7 +2133,7 @@ i3GEOF.metaestat = {
2130 new YAHOO.widget.Button( 2133 new YAHOO.widget.Button(
2131 "i3GEOFmetaestatEditorBotao8", 2134 "i3GEOFmetaestatEditorBotao8",
2132 {onclick:{fn: function(){ 2135 {onclick:{fn: function(){
2133 - i3GEO.util.abreColourRamp("","listaColourRampEditor",5); 2136 + i3GEO.util.abreColourRamp("","listaColourRampEditor",$i("i3GEOFmetaestatEditorNumInt").value);
2134 }}} 2137 }}}
2135 ); 2138 );
2136 $i("i3GEOFmetaestatEditorBotao8-button").style.width = (i3GEOF.metaestat.LARGURA / 2) + "px"; 2139 $i("i3GEOFmetaestatEditorBotao8-button").style.width = (i3GEOF.metaestat.LARGURA / 2) + "px";
pacotes/jenks-master/LICENSE-APACHE 0 → 100755
@@ -0,0 +1,175 @@ @@ -0,0 +1,175 @@
  1 +
  2 + Apache License
  3 + Version 2.0, January 2004
  4 + http://www.apache.org/licenses/
  5 +
  6 + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
  7 +
  8 + 1. Definitions.
  9 +
  10 + "License" shall mean the terms and conditions for use, reproduction,
  11 + and distribution as defined by Sections 1 through 9 of this document.
  12 +
  13 + "Licensor" shall mean the copyright owner or entity authorized by
  14 + the copyright owner that is granting the License.
  15 +
  16 + "Legal Entity" shall mean the union of the acting entity and all
  17 + other entities that control, are controlled by, or are under common
  18 + control with that entity. For the purposes of this definition,
  19 + "control" means (i) the power, direct or indirect, to cause the
  20 + direction or management of such entity, whether by contract or
  21 + otherwise, or (ii) ownership of fifty percent (50%) or more of the
  22 + outstanding shares, or (iii) beneficial ownership of such entity.
  23 +
  24 + "You" (or "Your") shall mean an individual or Legal Entity
  25 + exercising permissions granted by this License.
  26 +
  27 + "Source" form shall mean the preferred form for making modifications,
  28 + including but not limited to software source code, documentation
  29 + source, and configuration files.
  30 +
  31 + "Object" form shall mean any form resulting from mechanical
  32 + transformation or translation of a Source form, including but
  33 + not limited to compiled object code, generated documentation,
  34 + and conversions to other media types.
  35 +
  36 + "Work" shall mean the work of authorship, whether in Source or
  37 + Object form, made available under the License, as indicated by a
  38 + copyright notice that is included in or attached to the work
  39 + (an example is provided in the Appendix below).
  40 +
  41 + "Derivative Works" shall mean any work, whether in Source or Object
  42 + form, that is based on (or derived from) the Work and for which the
  43 + editorial revisions, annotations, elaborations, or other modifications
  44 + represent, as a whole, an original work of authorship. For the purposes
  45 + of this License, Derivative Works shall not include works that remain
  46 + separable from, or merely link (or bind by name) to the interfaces of,
  47 + the Work and Derivative Works thereof.
  48 +
  49 + "Contribution" shall mean any work of authorship, including
  50 + the original version of the Work and any modifications or additions
  51 + to that Work or Derivative Works thereof, that is intentionally
  52 + submitted to Licensor for inclusion in the Work by the copyright owner
  53 + or by an individual or Legal Entity authorized to submit on behalf of
  54 + the copyright owner. For the purposes of this definition, "submitted"
  55 + means any form of electronic, verbal, or written communication sent
  56 + to the Licensor or its representatives, including but not limited to
  57 + communication on electronic mailing lists, source code control systems,
  58 + and issue tracking systems that are managed by, or on behalf of, the
  59 + Licensor for the purpose of discussing and improving the Work, but
  60 + excluding communication that is conspicuously marked or otherwise
  61 + designated in writing by the copyright owner as "Not a Contribution."
  62 +
  63 + "Contributor" shall mean Licensor and any individual or Legal Entity
  64 + on behalf of whom a Contribution has been received by Licensor and
  65 + subsequently incorporated within the Work.
  66 +
  67 + 2. Grant of Copyright License. Subject to the terms and conditions of
  68 + this License, each Contributor hereby grants to You a perpetual,
  69 + worldwide, non-exclusive, no-charge, royalty-free, irrevocable
  70 + copyright license to reproduce, prepare Derivative Works of,
  71 + publicly display, publicly perform, sublicense, and distribute the
  72 + Work and such Derivative Works in Source or Object form.
  73 +
  74 + 3. Grant of Patent License. Subject to the terms and conditions of
  75 + this License, each Contributor hereby grants to You a perpetual,
  76 + worldwide, non-exclusive, no-charge, royalty-free, irrevocable
  77 + (except as stated in this section) patent license to make, have made,
  78 + use, offer to sell, sell, import, and otherwise transfer the Work,
  79 + where such license applies only to those patent claims licensable
  80 + by such Contributor that are necessarily infringed by their
  81 + Contribution(s) alone or by combination of their Contribution(s)
  82 + with the Work to which such Contribution(s) was submitted. If You
  83 + institute patent litigation against any entity (including a
  84 + cross-claim or counterclaim in a lawsuit) alleging that the Work
  85 + or a Contribution incorporated within the Work constitutes direct
  86 + or contributory patent infringement, then any patent licenses
  87 + granted to You under this License for that Work shall terminate
  88 + as of the date such litigation is filed.
  89 +
  90 + 4. Redistribution. You may reproduce and distribute copies of the
  91 + Work or Derivative Works thereof in any medium, with or without
  92 + modifications, and in Source or Object form, provided that You
  93 + meet the following conditions:
  94 +
  95 + (a) You must give any other recipients of the Work or
  96 + Derivative Works a copy of this License; and
  97 +
  98 + (b) You must cause any modified files to carry prominent notices
  99 + stating that You changed the files; and
  100 +
  101 + (c) You must retain, in the Source form of any Derivative Works
  102 + that You distribute, all copyright, patent, trademark, and
  103 + attribution notices from the Source form of the Work,
  104 + excluding those notices that do not pertain to any part of
  105 + the Derivative Works; and
  106 +
  107 + (d) If the Work includes a "NOTICE" text file as part of its
  108 + distribution, then any Derivative Works that You distribute must
  109 + include a readable copy of the attribution notices contained
  110 + within such NOTICE file, excluding those notices that do not
  111 + pertain to any part of the Derivative Works, in at least one
  112 + of the following places: within a NOTICE text file distributed
  113 + as part of the Derivative Works; within the Source form or
  114 + documentation, if provided along with the Derivative Works; or,
  115 + within a display generated by the Derivative Works, if and
  116 + wherever such third-party notices normally appear. The contents
  117 + of the NOTICE file are for informational purposes only and
  118 + do not modify the License. You may add Your own attribution
  119 + notices within Derivative Works that You distribute, alongside
  120 + or as an addendum to the NOTICE text from the Work, provided
  121 + that such additional attribution notices cannot be construed
  122 + as modifying the License.
  123 +
  124 + You may add Your own copyright statement to Your modifications and
  125 + may provide additional or different license terms and conditions
  126 + for use, reproduction, or distribution of Your modifications, or
  127 + for any such Derivative Works as a whole, provided Your use,
  128 + reproduction, and distribution of the Work otherwise complies with
  129 + the conditions stated in this License.
  130 +
  131 + 5. Submission of Contributions. Unless You explicitly state otherwise,
  132 + any Contribution intentionally submitted for inclusion in the Work
  133 + by You to the Licensor shall be under the terms and conditions of
  134 + this License, without any additional terms or conditions.
  135 + Notwithstanding the above, nothing herein shall supersede or modify
  136 + the terms of any separate license agreement you may have executed
  137 + with Licensor regarding such Contributions.
  138 +
  139 + 6. Trademarks. This License does not grant permission to use the trade
  140 + names, trademarks, service marks, or product names of the Licensor,
  141 + except as required for reasonable and customary use in describing the
  142 + origin of the Work and reproducing the content of the NOTICE file.
  143 +
  144 + 7. Disclaimer of Warranty. Unless required by applicable law or
  145 + agreed to in writing, Licensor provides the Work (and each
  146 + Contributor provides its Contributions) on an "AS IS" BASIS,
  147 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  148 + implied, including, without limitation, any warranties or conditions
  149 + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
  150 + PARTICULAR PURPOSE. You are solely responsible for determining the
  151 + appropriateness of using or redistributing the Work and assume any
  152 + risks associated with Your exercise of permissions under this License.
  153 +
  154 + 8. Limitation of Liability. In no event and under no legal theory,
  155 + whether in tort (including negligence), contract, or otherwise,
  156 + unless required by applicable law (such as deliberate and grossly
  157 + negligent acts) or agreed to in writing, shall any Contributor be
  158 + liable to You for damages, including any direct, indirect, special,
  159 + incidental, or consequential damages of any character arising as a
  160 + result of this License or out of the use or inability to use the
  161 + Work (including but not limited to damages for loss of goodwill,
  162 + work stoppage, computer failure or malfunction, or any and all
  163 + other commercial damages or losses), even if such Contributor
  164 + has been advised of the possibility of such damages.
  165 +
  166 + 9. Accepting Warranty or Additional Liability. While redistributing
  167 + the Work or Derivative Works thereof, You may choose to offer,
  168 + and charge a fee for, acceptance of support, warranty, indemnity,
  169 + or other liability obligations and/or rights consistent with this
  170 + License. However, in accepting such obligations, You may act only
  171 + on Your own behalf and on Your sole responsibility, not on behalf
  172 + of any other Contributor, and only if You agree to indemnify,
  173 + defend, and hold each Contributor harmless for any liability
  174 + incurred by, or claims asserted against, such Contributor by reason
  175 + of your accepting any such warranty or additional liability.
pacotes/jenks-master/README.md 0 → 100755
@@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
  1 +jenks
  2 +=====
  3 +
  4 +PHP Implementation of Jenks Natural Breaks Optimization for Choropleth Mapping
  5 +-----
  6 +
  7 +About:
  8 +=====
  9 +The Jenks natural breaks optimization method allows you to break up data points into the best possible number of groupings, with the best possible contents of each group for choropleth mapping.
  10 +
  11 +![Choroplethic Map](http://randomdrake.com/map.png "An example of a choropleth map.")
  12 +
  13 +http://en.wikipedia.org/wiki/Choropleth_map
  14 +
  15 +Here's how it works (from [Wikipedia](http://en.wikipedia.org/wiki/Jenks_natural_breaks_optimization)):
  16 +
  17 +>The method requires an iterative process. That is, calculations must be repeated using different breaks in the dataset to determine which set of breaks has the smallest in-class variance. The process is started by dividing the ordered data into groups. Initial group divisions can be arbitrary. There are four steps that must be repeated:
  18 +>
  19 +>1. Calculate the sum of squared deviations between classes (SDBC).
  20 +>2. Calculate the sum of squared deviations from the array mean (SDAM).
  21 +>3. Subtract the SDBC from the SDAM (SDAM-SDBC). This equals the sum of the squared deviations from the class means.
  22 +>4. After inspecting each of the SDBC, a decision is made to move one unit from the class with the largest SDBC toward the class with the lowest SDBC.
  23 +>
  24 +>New class deviations are then calculated, and the process is repeated until the sum of the within class deviations reaches a minimal value.
  25 +
  26 +![Jenks Algorithm](http://randomdrake.com/jenks.gif "Source - http://www.biomedware.com/files/documentation/spacestat/interface/map/classify/About_natural_breaks.htm")
  27 +
  28 +or
  29 +
  30 +![Jenks Algorithm Alternate](http://randomdrake.com/jenks2.gif "Source - http://www.biomedware.com/files/documentation/spacestat/interface/map/classify/About_natural_breaks.htm")
  31 +
  32 +Where...
  33 +* A is the set of values that have been ordered from 1 to N.
  34 +* 1 ≤ i < j < N
  35 +* Mean i..j is the mean of the class bounded by i and j.
  36 +
  37 +Development:
  38 +=====
  39 +I studied up on this and wrote it while working [for a startup](http://grupthinkpowered.com/) a few years ago, in 2009. I found that all of the available choroplethic mapping solutions available had inadequate splits of data when asked to create a map. Unfortunately, very few implementations of Jenks exist outside of professional cartography packages.
  40 +
  41 +When re-writing this, I had chosen to use the Google Charts API for our maps so, you should be able to use this to simply output a map assuming you provide all the necessary parameters.
  42 +
  43 +This was kind of based on [another script](http://www.forumsig.org/showthread.php?t=22055) that was in French (which I don't speak very well, at all). The original script had many issues and bugs and wasn't as flexible as I wanted it to be. So, I re-wrote it.
  44 +
  45 +This one works well and is flexible in terms of the datasets. It has been tested pretty thoroughly and, as far as I can tell, is correct.
  46 +
  47 +To Do:
  48 +=====
  49 +* Need a chance to go over it again and make improvements and/or more comments.
  50 +* Bug test.
  51 +* Write example usage.
  52 +* See if the Google Maps stuff even works anymore.
  53 +* Make a blog post / homepage.
  54 +
  55 +License:
  56 +=====
  57 +Open-source and free for use.
  58 +>Copyright 2012 David Drake
  59 +>
  60 +>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  61 +>
  62 +>http://www.apache.org/licenses/LICENSE-2.0
  63 +>
  64 +>Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  65 +
  66 +Author:
  67 +=====
  68 +David Drake
  69 +
  70 +[@randomdrake](https://twitter.com/#!/randomdrake) | [http://randomdrake.com](http://randomdrake.com) | [LinkedIn](http://www.linkedin.com/pub/david-drake/52/247/465)
pacotes/jenks-master/jenks.php 0 → 100755
@@ -0,0 +1,626 @@ @@ -0,0 +1,626 @@
  1 +<?php
  2 +/**
  3 + * Copyright (c) 2012 David Drake
  4 + *
  5 + * Licensed under the Apache License, Version 2.0 (the "License");
  6 + * you may not use this file except in compliance with the License.
  7 + * You may obtain a copy of the License at
  8 + *
  9 + * http://www.apache.org/licenses/LICENSE-2.0
  10 + *
  11 + * Unless required by applicable law or agreed to in writing, software
  12 + * distributed under the License is distributed on an "AS IS" BASIS,
  13 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14 + * See the License for the specific language governing permissions and
  15 + * limitations under the License.
  16 + */
  17 +
  18 +/**
  19 + * Jenk's Natural Breaks Classification Scheme with Google Charts API
  20 + *
  21 + * Some of this code is a translation / reworking of a script from French to English. The source script
  22 + * was written by Dominique Ollivier, Luc Guillemot and Dominique Pelage and can be found here:
  23 + * http://www.forumsig.org/showthread.php?t=22055
  24 + *
  25 + * Many bug fixes and significant improvements as well as the tie in to the Google Charts API were done by
  26 + * David Drake.
  27 + */
  28 +
  29 +/**
  30 + * This function will determine which classNumber a particular value rank/key falls in
  31 + *
  32 + * @param int $valueRank - the rank of value in the sorted list of values
  33 + * @param int $numberOfClasses - the number of classes desired
  34 + * @param array $numberOfElementsPerClassArray - the array of classes holding the number of elements per class
  35 + */
  36 +function determineClass ($valueRank, $numberOfClasses, $numberOfElementsPerClassArray) {
  37 + $minimum = 0;
  38 + $maximum = $numberOfElementsPerClassArray[0] - 1;
  39 + for ($ii = 0; $ii < $numberOfClasses; $ii++) {
  40 + if ($valueRank >= $minimum && $valueRank <= $maximum) {
  41 + $classNumber = $ii;
  42 + }
  43 +
  44 + $minimum = $minimum + $numberOfElementsPerClassArray[$ii];
  45 + $maximum = $minimum + $numberOfElementsPerClassArray[$ii + 1] - 1;
  46 + }
  47 +
  48 + return $classNumber;
  49 +}
  50 +
  51 +/**
  52 + * This function will determine the maximum values for the classes
  53 + *
  54 + * @param array $values - the values
  55 + * @param array $classes - the classes
  56 + */
  57 +function getClassMaximums ($values, $classes) {
  58 + $numberValues = count($values);
  59 + $numberOfClasses = count($classes);
  60 + $maximumValues = array();
  61 +
  62 + // Make sure our values are sorted
  63 + array_multisort($values);
  64 +
  65 + $valueIndex = 0;
  66 + for ($classNumber = 0; $classNumber < $numberOfClasses; $classNumber++) {
  67 + $maximumValues[$classNumber] = $values[$valueIndex];
  68 + $valueIndex = $valueIndex + $classes[$classNumber];
  69 + }
  70 +
  71 + $maximumValues[$numberOfClasses] = $values[$numberValues - 1];
  72 +
  73 + return $maximumValues;
  74 +}
  75 +
  76 +/**
  77 + * This function will determine the number of values that belong in each class
  78 + *
  79 + * @param array $values - the values
  80 + * @param array $maximumValues - the maximum values of each class
  81 + */
  82 +function getNumberOfValuesPerClass ($values, $maximumValues) {
  83 + $numberOfClasses = count($maximumValues) - 1;
  84 + $numberOfValues = count($values);
  85 + $class = array();
  86 +
  87 + // Make sure our values are sorted
  88 + array_multisort($values);
  89 +
  90 + $firstValueOfClass = 0;
  91 +
  92 + for ($classNumber = 1; $classNumber < $numberOfClasses; $classNumber++) {
  93 + $crossIndex = 0;
  94 + while ($values[$crossIndex] < $maximumValues[$classNumber] && $crossIndex < $numberOfValues) {
  95 + $crossIndex++;
  96 + }
  97 + $lastClassIndex = $crossIndex - 1;
  98 +
  99 + $class[$classNumber - 1] = $lastClassIndex - $firstValueOfClass + 1;
  100 + $firstValueOfClass = $lastClassIndex + 1;
  101 + }
  102 +
  103 + $class[$classNumber - 1] = $numberOfValues - $firstValueOfClass;
  104 +
  105 + return $class;
  106 +}
  107 +
  108 +/**
  109 + * Calculates an average of the values in an array
  110 + *
  111 + * @param array $values - the array of values you want an average calculated for
  112 + */
  113 +function calculateAverage ($values) {
  114 + if (!is_array($values) || count($values) == 0) {
  115 + return 0;
  116 + }
  117 + return array_sum($values) / count($values);
  118 +}
  119 +
  120 +/**
  121 + * The Jenks Algorithm
  122 + *
  123 + * This function will determine the optimal natural breaks for a set of values given a number of classes. It will return
  124 + * an array of classes with the number of elements for each class.
  125 + *
  126 + * @param int $numberOfClasses - the number of classes you want
  127 + * @param array $values - the values you are working with
  128 + */
  129 +function getJenksClasses ($numberOfClasses, $values) {
  130 + // Make sure our values are sorted
  131 + array_multisort($values);
  132 +
  133 + // Determine the number of values
  134 + $numberOfValues = count($values);
  135 +
  136 + // If we have the same number of unique values as classes
  137 + if (count(array_unique($values)) == $numberOfClasses) {
  138 + // Then we can just count up the number of values in each of the classes and we are finished
  139 + $classes = array_values(array_count_values($values));
  140 + return getClassMaximums($values, $classes);
  141 + }
  142 +
  143 + // We need a starting point for Jenks. Let's start with a simple quantile split
  144 + $classSize = floor($numberOfValues / $numberOfClasses);
  145 + for ($ii = 0; $ii < $numberOfClasses; $ii++) {
  146 + $classes[] = $classSize;
  147 + }
  148 + $classes[$ii - 1] = $numberOfValues - ($numberOfClasses - 1) * $classSize;
  149 +
  150 + /**
  151 + * Now that we have our simple quantile split, we'll do our first round of adjustments. It's very likely the quantile split
  152 + * caused equal values to be split into two different classes. This will not work for our classes. We will go through each
  153 + * class and determine if any of the values in the classes exist in another class. If they do, we will see which class
  154 + * would be best for that set of values by creating feaux classes as if all of the values have been moved and determine which
  155 + * move would provide the lowest sum of squared differences for that value. We will then move those values into that class.
  156 + */
  157 + $valueCounts = array_count_values($values);
  158 + $changeOccurred = true;
  159 + $firstIterationCounter = 0;
  160 + do {
  161 + $changeOccurred = false;
  162 + if ($numberOfClasses == 6) {
  163 + $numsixcounter++;
  164 + if ($numsixcounter == 20) {
  165 + exit;
  166 + }
  167 + }
  168 + $startingValuesKey = 0;
  169 + $currentClassesArray = array();
  170 + foreach ($classes as $numberValuesInClass) {
  171 + $currentClassesArray[] = array_slice($values, $startingValuesKey, $numberValuesInClass);
  172 + $startingValuesKey += $numberValuesInClass;
  173 + }
  174 + foreach ($currentClassesArray as $key => $class) {
  175 + if ($key == $numberOfClasses - 1) {
  176 + break;
  177 + }
  178 + /**
  179 + * Go through each class. If the class only has one number, we are good. Let's move the rest of the numbers
  180 + * into this class if they exist elsewhere
  181 + */
  182 + if (count(array_unique($class)) == 1) {
  183 + $onlyValueInClass = $class[0];
  184 + if ($classes[$key] != $valueCounts[$onlyValueInClass]) {
  185 + // Then there are other classes with this value. We've got some moving to do.
  186 + $numberOfValuesToMove = $valueCounts[$onlyValueInClass] - $classes[$key];
  187 + $classKeyToTry = $key + 1;
  188 + while ($numberOfValuesToMove > 0) {
  189 + // We have to start subtracting from classes that are suitable
  190 + if ($classes[$classKeyToTry] <= 1) {
  191 + do {
  192 + $classKeyToTry++;
  193 + if ($classKeyToTry > $numberOfClasses - 1) {
  194 + $classKeyToTry = 0;
  195 + }
  196 + } while ($classKeyToTry == $key);
  197 + }
  198 + $classes[$classKeyToTry]--;
  199 + $classes[$key]++;
  200 + $numberOfValuesToMove--;
  201 + }
  202 + $changeOccurred = true;
  203 + break;
  204 + }
  205 + } else {
  206 + // There are more than one value in this class
  207 + $valuesInThisClass = array_count_values($class);
  208 + $value = max($class);
  209 + $numberTimesValueInClass = $valuesInThisClass[$value];
  210 + if ($numberTimesValueInClass != $valueCounts[$value]) {
  211 + /**
  212 + * Then there are more of these in a different class. If the next class is nothing but this value, we
  213 + * know we will just move the values to that class.
  214 + */
  215 + if (count(array_unique($currentClassesArray[$key + 1])) == 1) {
  216 + // The next class up is made up entirely of this class. We will move the numbers to it.
  217 + $numberValuesToMove = $numberTimesValueInClass;
  218 + for ($ii = 0; $ii < $numberValuesToMove; $ii++) {
  219 + $classes[$key]--;
  220 + $classes[$key + 1]++;
  221 + }
  222 + if ($classes[$key + 1] != $valueCounts[$value]) {
  223 + // Then we may have moved all the values out of this class into the next, but there are still more
  224 + $numberLeftToMove = $valueCounts[$value] - $classes[$key + 1];
  225 + $classKeyToTry = $key + 2;
  226 + while ($numberLeftToMove > 0) {
  227 + // We have to start subtracting from classes that are suitable
  228 + if ($classes[$classKeyToTry] <= 1) {
  229 + $classKeyToTry++;
  230 + }
  231 + $classes[$classKeyToTry]--;
  232 + $classes[$key + 1]++;
  233 + $numberLeftToMove--;
  234 + }
  235 + }
  236 + } else {
  237 + /**
  238 + * There are other numbers in the next class besides the one we are working with. Let's create
  239 + * the two classes as if we had put all of the values in the class. Then, we'll find out which
  240 + * provides the best SSD for our current $value.
  241 + */
  242 + $firstComparisonClass = $currentClassesArray[$key];
  243 + $secondComparisonClass = $currentClassesArray[$key + 1];
  244 + $numberValuesForClass = array_count_values($firstComparisonClass);
  245 + $numberValuesToAddFirstClass = $valueCounts[$value] - $numberValuesForClass[$value];
  246 + for ($ii = 0; $ii < $numberValuesToAddFirstClass; $ii++) {
  247 + $firstComparisonClass[] = $value;
  248 + }
  249 + $firstClassAverage = calculateAverage($firstComparisonClass);
  250 + $numberValuesForClass = array_count_values($secondComparisonClass);
  251 + $numberValuesToAddSecondClass = $valueCounts[$value] - $numberValuesForClass[$value];
  252 + for ($ii = 0; $ii < $numberValuesToAddSecondClass; $ii++) {
  253 + $secondComparisonClass[] = $value;
  254 + }
  255 + $secondClassAverage = calculateAverage($secondComparisonClass);
  256 +
  257 + // Now that we have built our two feaux classes, let's see which provides us with the best SSD for the value
  258 + $firstSSD = pow($value - $firstClassAverage, 2);
  259 + $secondSSD = pow($value - $secondClassAverage, 2);
  260 + if ($firstSSD < $secondSSD) {
  261 + $classKeyToAddTo = $key;
  262 + $classKeyToSubtractFrom = $key + 1;
  263 + $numberValuesToMove = $numberValuesToAddFirstClass;
  264 + } else {
  265 + $classKeyToAddTo = $key + 1;
  266 + $classKeyToSubtractFrom = $key;
  267 + $numberValuesToMove = $numberValuesToAddSecondClass;
  268 + }
  269 + for ($ii = 0; $ii < $numberValuesToMove; $ii++) {
  270 + $classes[$classKeyToAddTo]++;
  271 + $classes[$classKeyToSubtractFrom]--;
  272 + }
  273 + }
  274 + $changeOccurred = true;
  275 + break;
  276 + }
  277 + }
  278 + }
  279 + } while ($changeOccurred == true);
  280 +
  281 + /**
  282 + * Now that we are sure our classes have been split in a way that values are not spread amongst different classes,
  283 + * we can do work optimizing our classes further. We will look at the highest and lowest values for each class and
  284 + * determine if those sets of values would be better suited in the class above, below, or if they are good where
  285 + * they are at. We do not need to look at values in the middle of each class because moving a value in the middle
  286 + * to a class above or below it would put our classes out of numeric order and does not make sense. We also do not
  287 + * look at the largest or smallest values because those should stay in their lowest and highest class respsectively.
  288 + */
  289 + $changeOccurred = 1;
  290 + $iterationCounter = 0;
  291 + $distinctValues = array_keys($valueCounts);
  292 + $numberDistinctValues = count($distinctValues);
  293 + $currentClassesArray = array();
  294 + $startingValuesKey = 0;
  295 + foreach ($classes as $numberValuesInClass) {
  296 + $currentClassesArray[] = array_slice($values, $startingValuesKey, $numberValuesInClass);
  297 + $startingValuesKey += $numberValuesInClass;
  298 + }
  299 +
  300 + do {
  301 + $changeOccurred = 0;
  302 +
  303 + // We only want to work on the minimums and maximums of the classes
  304 + $minimumValue = min($values);
  305 + $maximumValue = max($values);
  306 + $valuesToWorkWith = array();
  307 + foreach ($currentClassesArray as $class) {
  308 + // We don't want to check values that are in classes by themselves because we cannot improve them
  309 + if (count(array_unique($class)) != 1) {
  310 + $minValueForArray = min($class);
  311 + if ($minValueForArray != $minimumValue && $minValueForArray != $maximumValue) {
  312 + $valuesToWorkWith[] = $minValueForArray;
  313 + }
  314 + $maxValueForArray = max($class);
  315 + if ($maxValueForArray != $minimumValue && $maxValueForArray != $maximumValue) {
  316 + $valuesToWorkWith[] = $maxValueForArray;
  317 + }
  318 + }
  319 + }
  320 +
  321 + $numberOfValuesToWorkWith = count($valuesToWorkWith);
  322 + if ($numberOfValuesToWorkWith > 0) {
  323 + for ($ii = 0; $ii < $numberOfValuesToWorkWith; $ii++) {
  324 + $iterationCounter++;
  325 + $thisValue = $valuesToWorkWith[$ii];
  326 +
  327 + /**
  328 + * We will need to create feaux classes above and below the current class to see if the squared deviation decreases.
  329 + * If it does, we'll move the values into that class.
  330 + */
  331 + $currentClassKeyForValue = determineClass(array_search($thisValue, $values), $numberOfClasses, $classes);
  332 +
  333 + $firstComparisonClassKey = $currentClassKeyForValue - 1;
  334 + $secondComparisonClassKey = $currentClassKeyForValue + 1;
  335 + $squaredDeviationsArray = array();
  336 + if ($firstComparisonClassKey > 0) {
  337 + $firstComparisonClass = $currentClassesArray[$firstComparisonClassKey];
  338 + $numberValuesForClass = array_count_values($firstComparisonClass);
  339 + $numberValuesToAddFirstClass = $valueCounts[$thisValue] - $numberValuesForClass[$thisValue];
  340 + for ($jj = 0; $jj < $numberValuesToAddFirstClass; $jj++) {
  341 + $firstComparisonClass[] = $thisValue;
  342 + }
  343 + $firstClassAverage = calculateAverage($firstComparisonClass);
  344 + $squaredDeviationsArray[$firstComparisonClassKey] = pow($thisValue - $firstClassAverage, 2);
  345 + }
  346 + if ($secondComparisonClassKey < $numberOfClasses) {
  347 + $secondComparisonClass = $currentClassesArray[$secondComparisonClassKey];
  348 + $numberValuesForClass = array_count_values($secondComparisonClass);
  349 + $numberValuesToAddSecondClass = $valueCounts[$thisValue] - $numberValuesForClass[$thisValue];
  350 + for ($jj = 0; $jj < $numberValuesToAddSecondClass; $jj++) {
  351 + $secondComparisonClass[] = $thisValue;
  352 + }
  353 + $secondClassAverage = calculateAverage($secondComparisonClass);
  354 + $squaredDeviationsArray[$secondComparisonClassKey] = pow($thisValue - $secondClassAverage, 2);
  355 + }
  356 +
  357 + $currentClassAverage = calculateAverage($currentClassesArray[$currentClassKeyForValue]);
  358 + $currentSquaredDeviation = $squaredDeviationsArray[$currentClassKeyForValue] = pow($thisValue - $currentClassAverage, 2);
  359 +
  360 + $minSquaredDeviation = min($squaredDeviationsArray);
  361 + if ($minSquaredDeviation != $currentSquaredDeviation) {
  362 + $minSquaredDeviationKey = array_search($minSquaredDeviation, $squaredDeviationsArray);
  363 +
  364 + // Then we need to move these values from the class they are in to the class they should be in
  365 + $numberOfThisValue = $valueCounts[$thisValue];
  366 + $classes[$minSquaredDeviationKey] += $numberOfThisValue;
  367 + $classes[$currentClassKeyForValue] -= $numberOfThisValue;
  368 + $changeOccurred = 1;
  369 +
  370 + // Regenerate our classes as they currently are
  371 + $startingValuesKey = 0;
  372 + $currentClassesArray = array();
  373 + foreach ($classes as $numberValuesInClass) {
  374 + $currentClassesArray[] = array_slice($values, $startingValuesKey, $numberValuesInClass);
  375 + $startingValuesKey += $numberValuesInClass;
  376 + }
  377 + }
  378 + }
  379 + }
  380 + } while ($changeOccurred == 1);
  381 +
  382 + return getClassMaximums($values, $classes);
  383 +}
  384 +
  385 +/**
  386 + * This function determines the optimum number of classes for a given set of values by calculating the goodness of variance fit (GVF)
  387 + * for class sizes 4 - 7. It will return the maximum values for each class and the number of values for each class in an array for the
  388 + * number of classes that best fits the data.
  389 + *
  390 + * @param array $values - the values you want to determine the optimum deviation for
  391 + * @param int $minimumNumberOfClasses - the minimum number of classes you want to try
  392 + * @param int $maximumNumberOfClasses - the maximum number of classes you want to try
  393 + * @return array - the maximum values for each array and the number of values for each class
  394 + */
  395 +function getOptimalClassInformation ($values, $minimumNumberOfClasses = 4, $maximumNumberOfClasses = 7) {
  396 + // Make sure our values are sorted
  397 + array_multisort($values);
  398 +
  399 + $numberOfUniqueValues = count(array_unique($values));
  400 + if ($numberOfUniqueValues <= $maximumNumberOfClasses) {
  401 + $maximumValues = getJenksClasses ($numberOfUniqueValues, $values);
  402 + $numberOfValuesPerClass = getNumberOfValuesPerClass ($values, $maximumValues);
  403 + return array ($maximumValues, $numberOfValuesPerClass);
  404 + } else {
  405 + $valuesAverage = calculateAverage($values);
  406 + $SDAM = 0;
  407 + foreach ($values as $value) {
  408 + $SDAM += pow ($value - $valuesAverage, 2);
  409 + }
  410 +
  411 + for ($classNumber = $minimumNumberOfClasses; $classNumber <= $maximumNumberOfClasses; $classNumber++) {
  412 + $maximumValues = getJenksClasses ($classNumber, $values);
  413 + $numberOfValuesPerClass = getNumberOfValuesPerClass ($values, $maximumValues);
  414 + $arraySliceIndex = 0;
  415 + $SDCM = 0;
  416 + foreach ($numberOfValuesPerClass as $numberOfValues) {
  417 + $thisClass = array_slice($values, $arraySliceIndex, $numberOfValues);
  418 + $thisClassAverage = calculateAverage($thisClass);
  419 + $deviationsSumForClass = 0;
  420 + foreach ($thisClass as $thisValue) {
  421 + $deviationsSumForClass += pow ($thisValue - $thisClassAverage, 2);
  422 + }
  423 + $SDCM += $deviationsSumForClass;
  424 + $arraySliceIndex += $numberOfValues;
  425 + }
  426 + $gvfsArray[$classNumber] = 1 - ($SDCM / $SDAM);
  427 + $returnArraysToClassNumbers[$classNumber] = array ($maximumValues, $numberOfValuesPerClass);
  428 + }
  429 + }
  430 +
  431 + return $returnArraysToClassNumbers[array_search(max($gvfsArray), $gvfsArray)];
  432 +}
  433 +
  434 +/**
  435 + * Takes an array of values and an array of numbers per class from Jenks to provide us with a nice list of what the ranges are
  436 + *
  437 + * @param array $values - the original array of values
  438 + * @param array $jenksArray - the array of how many values should go in each class from Jenks
  439 + */
  440 +function getMapKeys ($values, $jenksArray) {
  441 + // Make sure our values are sorted
  442 + array_multisort($values);
  443 +
  444 + if (count($jenksArray) == 2) {
  445 + // If the Jenks array just contains a single value and the max, then we can just return that value
  446 + return array (0 => $jenksArray[1]);
  447 + }
  448 + $returnArray = array();
  449 + $startingValue = $jenksArray[0];
  450 + $arrayCount = count($jenksArray);
  451 + $rangeString = 1;
  452 + $stoppingValue = $jenksArray[$arrayCount - 1];
  453 + for ($ii = 1; $ii < $arrayCount; $ii++) {
  454 + $maxValue = $jenksArray[$ii];
  455 + if ($maxValue == $stoppingValue) {
  456 + if ($rangeString == $maxValue) {
  457 + $rangeString = $maxValue;
  458 + } else {
  459 + foreach ($values as $value) {
  460 + if ($value < $maxValue) {
  461 + $max = $value;
  462 + } else if ($rangeString == $max) {
  463 + break;
  464 + } else {
  465 + $rangeString .= ' - ' . $max;
  466 + break;
  467 + }
  468 + }
  469 + }
  470 + } else {
  471 + foreach ($values as $value) {
  472 + if ($value < $maxValue) {
  473 + $max = $value;
  474 + } else if ($max == $rangeString) {
  475 + break;
  476 + } else {
  477 + $rangeString .= ' - ' . $max;
  478 + break;
  479 + }
  480 + }
  481 + }
  482 +
  483 + $returnArray[] = $rangeString;
  484 + $rangeString = $jenksArray[$ii];
  485 + }
  486 +
  487 + return $returnArray;
  488 +}
  489 +
  490 +/**
  491 + * This function will display a map using the Google Charts API. Information about the API can be found
  492 + * here: http://code.google.com/apis/chart/types.html#maps
  493 + *
  494 + * We are using Jenks Natural Breaks Classification Scheme to create our breaks in our data and our keys
  495 + * for our maps.
  496 + *
  497 + * The output for this will be a URI that looks like this: http://chart.apis.google.com/chart?cht=t
  498 + * &chs=440x220&chco=DCDCDC,FDFAD1,FFE9B0,FFBB7D,E5280C,A61900&chtm=usa&chd=t:20,20,20,20,20,20,20,20,
  499 + * 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,40,40,40,40,40,40,40,40,40,40,40,40,60,60,60,60,60,60,
  500 + * 60,60,60,80,80,80,80,100,100&chld=VTHIDESDWVDCMERIWYARNENHAKNMMSLAOKIDIANVALUTSCCTKYTNINMDWIMNMOOR
  501 + * MANCAZVAGAMIOHCOPANJILWAFLTXNYKSCAMT&chf=bg,s,EAF7FE
  502 + *
  503 + * Due to the limits of the numbers and formats of numbers that can be sent to the charting API, we break
  504 + * our classes up into even numbers that have the most distance between them as possible but still remain
  505 + * within 100. The rest of the arguments are fully explained in the API documentaiton.
  506 + *
  507 + * @param array $values - the values of the map you are trying to create
  508 + * @param array $locations - either an array of 2-digit state codes or an array of ISO 3166-1-alpha-2 country
  509 + * codes. This array should correspond to the $values in the way it is sorted.
  510 + * @param string $map_type - the type of map you would like. Should be from this list:
  511 + * 'africa', 'asia', 'europe', 'middle_east', 'south_america', 'usa', 'world'
  512 + * @param boolean $return_data - if return data is set to true, this function will return the URI and the
  513 + * colors and data needed to display the map key
  514 + * @return mixed - either nothing or an array containing the return data
  515 + */
  516 +function displayGoogleMap($values, $locations, $map_type, $return_data = false) {
  517 + // Color of locations with no values
  518 + $empty_color = 'DCDCDC';
  519 +
  520 + // Color of the water behind the maps
  521 + $water_color = 'FAFAFA';
  522 +
  523 + // Make sure our values are sorted
  524 + array_multisort($values);
  525 +
  526 + // We will grab the maximum values from each class as determined by the Jenks algorithm
  527 + $class_information = getOptimalClassInformation($values);
  528 + $jenks_max_values_per_class = $class_information[0];
  529 + $number_values_per_class = $class_information[1];
  530 + $number_of_classes = count($number_values_per_class);
  531 + $valid_map_types = array('africa', 'asia', 'europe', 'middle_east', 'south_america', 'usa', 'world');
  532 + $display_map_types = array ('Africa', 'Asia', 'Europe', 'Middle East', 'South America', 'USA', 'World');
  533 +
  534 + // With this information, we will get our map keys
  535 + $breaks_array = getMapKeys($values, $jenks_max_values_per_class);
  536 +
  537 + if ($number_of_classes <= 5) {
  538 + $map_colors = array ($empty_color, 'FDFAD1', 'FFE9B0', 'FFBB7D', 'E5280C', 'A61900');
  539 + $google_colors = array ($empty_color, 'FEECB6', 'FECC91', 'F4804F', 'D82509', 'A51900');
  540 +
  541 + // Google renders the colors for 2 classes in a particular way
  542 + if ($number_of_classes == 2) {
  543 + $google_colors = array ($empty_color, 'FEECB6', 'FECD91');
  544 + }
  545 +
  546 + $class_multiplier = 20;
  547 + } else if ($number_of_classes > 5) {
  548 + $map_colors = array ($empty_color, 'FFFFFF', 'FDFAD1', 'FFE9B0', 'FFBB7D', 'FF7A3D', 'E5280C', 'A61900');
  549 + $google_colors = array ($empty_color, 'FDFAD1', 'FDEDB9', 'FED095', 'FEA265', 'F96933', 'E2270B', 'AD1A01');
  550 +
  551 + // Google renders the colors for 6 classes in a particular way
  552 + if ($number_of_classes == 6) {
  553 + $google_colors = array ($empty_color, 'FDECB8', 'FCD095', 'FDA165', 'F86732', 'E2280B', 'AD1A01');
  554 + }
  555 + $map_colors = $google_colors;
  556 + $class_multiplier = round(100 / $number_of_classes, 2);
  557 + }
  558 +
  559 + // Let's build our URI
  560 + $uri = 'http://chart.apis.google.com/chart?cht=t&chs=440x220&chco=';
  561 + foreach ($map_colors as $color) {
  562 + $uri .= $color . ',';
  563 + }
  564 + $uri = substr($uri, 0, -1);
  565 + $uri .= '&chtm=' . $map_type;
  566 +
  567 + // Here we will build the location abbreviations and location values to go in the URI
  568 + $max_value = $values[0];
  569 + $key = 0;
  570 + foreach ($locations as $location_abbrev => $number_from_location) {
  571 + $location_codes .= $location_abbrev;
  572 + $class_number = round((determineClass($key, $number_of_classes, $number_values_per_class) + 1) * $class_multiplier);
  573 + $location_values .= $class_number . ',';
  574 + $key++;
  575 + }
  576 + $location_values = substr($location_values, 0, -1);
  577 +
  578 + // Finish off our URI by tacking on the values, codes, and color for the water
  579 + $uri .= '&chd=t:' . $location_values .
  580 + '&chld=' . $location_codes .
  581 + '&chf=bg,s,' . $water_color;
  582 +
  583 + // We need to check and see if they just wanted data returned or if they wanted the map displayed
  584 + if ($return_data) {
  585 + // Let's build our array for the map colors and data and return our data
  586 + $map_key_array[$empty_color] = 'No Data';
  587 + for ($ii = 1; $ii <= $number_of_classes; $ii++) {
  588 + $color = $google_colors[$ii];
  589 + $text = $breaks_array[$ii - 1];
  590 + $map_key_array[$color] = $text;
  591 + }
  592 + return array ($uri, $map_key_array);
  593 + } else {
  594 + // Let's display it
  595 + $empty_color = $google_colors[0];
  596 + echo <<<HTML
  597 +<div class="map_legend">
  598 + <table>
  599 + <tr>
  600 + <td class="mapcolor" bgcolor="#<?php echo $map_colors[0]; ?>">
  601 + &nbsp;&nbsp;&nbsp;
  602 + </td>
  603 + <td>
  604 + No Data
  605 + </td>
  606 + </tr>
  607 +HTML;
  608 + for ($ii = 1; $ii <= $number_of_classes; $ii++) {
  609 + $color = $google_colors[$ii];
  610 + $text = $breaks_array[$ii - 1];
  611 + echo <<<HTML
  612 + <tr>
  613 + <td class="mapcolor" bgcolor="#{$color}" border="1">&nbsp;&nbsp;&nbsp;</td>
  614 + <td>{$text}</td>
  615 + </tr>
  616 +HTML;
  617 +
  618 + }
  619 + echo <<<HTML
  620 + </table>
  621 +</div>
  622 +<img {$margin}src="{$uri}">
  623 +HTML;
  624 + }
  625 +}
  626 +?>