diff --git a/classesphp/classe_alteraclasse.php b/classesphp/classe_alteraclasse.php index 0ef7f55..9cf7d78 100644 --- a/classesphp/classe_alteraclasse.php +++ b/classesphp/classe_alteraclasse.php @@ -319,6 +319,109 @@ class Alteraclasse {return ("erro. Nenhum valor numerico no item"); } } + /* + function: metade + + Classifica os dados em duas classes, a primeira concentra os registros que somados correspondem à primeira metade do total e a segunda classe corresponde à segunda metade + + Parametros: + + $item - item da tabela de atributos + + $itemid - item que identifica unicamente cada registro + + $ignorar - valor que será ignorado na listagem final + */ + function metade($item,$itemid,$ignorar) + { + if(!$this->layer){ + return "erro"; + } + //cria um array contendo o id como chave e o valor + $valores = $this->pegaValores($this->mapa,$this->layer,$item,true,$ignorar); + $ids = $this->pegaValores($this->mapa,$this->layer,$itemid,false,$ignorar); + $lista = array(); + for ($i = 0; $i < count($valores); ++$i){ + $lista[$ids[$i]] = $valores[$i]; + } + + if (count($lista) > 0){ + asort($lista); + //$valores = array_unique($valores); + $numValues = count($lista); + //soma os valores + $total = array_sum($lista); + //metade + $metade = $total / 2; + //separa os dados em dois conjuntos + $metadeInf = array(); + $metadeSup = array(); + $IdNumerico = true; + $soma = 0; + $somaInf = 0; + $somaSup = 0; + $maxMetade1 = 0; + foreach ($lista as $k => $v) { + $soma = $soma + $v; + if($soma < $metade){ + $metadeInf[] = $k; + $somaInf = $soma; + $maxMetade1 = $v; + } + else{ + $metadeSup[] = $k; + $somaSup = $somaSup + $v; + } + } + $percInf = ($somaInf * 100) / $total; + $percSup = ($somaSup * 100) / $total; + + $numclassesatual = $this->layer->numclasses; + //apaga todas as classes existentes + $classetemp = $this->layer->getClass(0); + $estilotemp = $classetemp->getStyle(0); + for ($i=0; $i < $numclassesatual; ++$i){ + $classe = $this->layer->getClass($i); + $classe->set("status",MS_DELETE); + } + //adiciona as classes novas + $expressao = "('[".$itemid."]'in'".implode(",",$metadeInf)."')"; + $nomeclasse = "Tot ".$somaInf.' ('.round($percInf,2).'%) Max: '.$maxMetade1; + $classe = ms_newClassObj($this->layer); + $novoestilo = ms_newStyleObj($classe); + if ($this->layer->type == 0){ + $novoestilo->set("symbolname","ponto"); + $novoestilo->set("size","6"); + } + $ncor = $novoestilo->color; + $ncor->setrgb(246,183,134); + $ncor = $novoestilo->outlinecolor; + $ncor->setrgb(255,255,255); + $classe->setexpression($expressao); + $classe->set("name",$nomeclasse); + + $expressao = "('[".$itemid."]'in'".implode(",",$metadeSup)."')"; + $nomeclasse = "Tot ".$somaSup.' ('.round($percSup,2).'%) '; + $classe = ms_newClassObj($this->layer); + $novoestilo = ms_newStyleObj($classe); + if ($this->layer->type == 0){ + $novoestilo->set("symbolname","ponto"); + $novoestilo->set("size","6"); + } + $ncor = $novoestilo->color; + $ncor->setrgb(210,111,111); + $ncor = $novoestilo->outlinecolor; + $ncor->setrgb(255,255,255); + $classe->setexpression($expressao); + $classe->set("name",$nomeclasse); + + $this->layer->setMetaData("cache",""); + return ("ok"); + } + else{ + return ("erro. Nenhum valor numerico no item"); + } + } /* function: quantil diff --git a/classesphp/mapa_controle.php b/classesphp/mapa_controle.php index 7b83713..d5ebd7d 100644 --- a/classesphp/mapa_controle.php +++ b/classesphp/mapa_controle.php @@ -1215,6 +1215,9 @@ switch (strtoupper($funcao)) if ($opcao == "quebrasnaturais"){ $retorno = $m->quebrasnaturais($item,$nclasses,$ignorar); } + if ($opcao == "metade"){ + $retorno = $m->metade($item,$itemid,$ignorar); + } if ($opcao == "quartis"){ if(!isset($tipoLegenda)) { diff --git a/ferramentas/legenda/dicionario.js b/ferramentas/legenda/dicionario.js index 3a9a2ec..684dfd4 100644 --- a/ferramentas/legenda/dicionario.js +++ b/ferramentas/legenda/dicionario.js @@ -758,5 +758,26 @@ i3GEOF.legenda.dicionario = en : "", es : "" } - ] + ], + "metade" : [ + { + pt : "Metade", + en : "", + es : "" + } + ], + "duasmetades" : [ + { + pt : "Classifica os dados em duas classes, a primeira concentra os registros que somados correspondem à primeira metade do total e a segunda classe corresponde à segunda metade", + en : "", + es : "" + } + ], + "iunico" : [ + { + pt : "Coluna que identifica cada registro de forma única", + en : "", + es : "" + } + ] }; diff --git a/ferramentas/legenda/index.js b/ferramentas/legenda/index.js index 1026be9..54c10b3 100644 --- a/ferramentas/legenda/index.js +++ b/ferramentas/legenda/index.js @@ -208,6 +208,12 @@ i3GEOF.legenda = } }); b.addClass("rodar"); + b = new YAHOO.widget.Button("i3GEOlegendabotaoMetade", { + onclick : { + fn : i3GEOF.legenda.metade + } + }); + b.addClass("rodar"); b = new YAHOO.widget.Button("i3GEOlegendabotao7", { onclick : { fn : i3GEOF.legenda.representacao @@ -346,6 +352,12 @@ i3GEOF.legenda = if ($i("i3GEOlegendaClassesValorUnico")) { $i("i3GEOlegendaClassesValorUnico").innerHTML = retorno.dados; } + if ($i("i3GEOlegendaitensMetade")) { + $i("i3GEOlegendaitensMetade").innerHTML = retorno.dados; + } + if ($i("i3GEOlegendaitensMetadeId")) { + $i("i3GEOlegendaitensMetadeId").innerHTML = retorno.dados; + } if ($i("i3GEOlegendaitensValorClass")) { $i("i3GEOlegendaitensValorClass").innerHTML = retorno.dados; } @@ -1297,6 +1309,67 @@ i3GEOF.legenda = i3GEO.janela.tempoMsg("Selecione um item!"); return; } + if ($i("i3GEOFlegendaaplicaextent").checked === true) { + p += "&ext=" + i3GEO.util.extOSM2Geo(i3GEO.parametros.mapexten); + } else { + p += "&ext=" + i3GEO.util.extOSM2Geo(i3GEO.parametros.extentTotal); + } + i3GEOF.legenda.aguarde.visibility = "visible"; + cp.set_response_type("JSON"); + cp.call(p, "alteraclasse", fim); + } catch (e) { + i3GEO.janela.tempoMsg("Erro: " + e); + i3GEOF.legenda.aguarde.visibility = "hidden"; + } + }, + /* + * Function: metade + * + * Duas classes concentrando a soma das metades + * + * Veja: + * + * + */ + metade : function() { + try { + if (i3GEOF.legenda.aguarde.visibility === "visible") { + return; + } + var item = $i("i3GEOlegendaitensMetade").getElementsByTagName("select")[0].value, + itemid = $i("i3GEOlegendaitensMetadeId").getElementsByTagName("select")[0].value, + ext = i3GEO.util.extOSM2Geo(i3GEO.parametros.mapexten), + p = i3GEO.configura.locaplic + "/classesphp/mapa_controle.php?g_sid=" + + i3GEO.configura.sid + + "&funcao=alteraclasse" + + "&tema=" + + i3GEOF.legenda.tema + + "&item=" + + item + + "&itemid=" + + itemid + + "&opcao=metade&ignorar=" + + $i("i3GEOlegendaignorar").value + + "&ext=" + + ext, + cp = new cpaint(), + fim = function() { + i3GEOF.legenda.aposAlterarLegenda(); + i3GEOF.legenda.aguarde.visibility = "hidden"; + }; + if (item == "") { + i3GEO.janela.tempoMsg("Selecione um item!"); + return; + } + if (itemid == "") { + i3GEO.janela.tempoMsg("Selecione um item!"); + return; + } + if ($i("i3GEOFlegendaaplicaextent").checked === true) { + p += "&ext=" + i3GEO.util.extOSM2Geo(i3GEO.parametros.mapexten); + } else { + p += "&ext=" + i3GEO.util.extOSM2Geo(i3GEO.parametros.extentTotal); + } i3GEOF.legenda.aguarde.visibility = "visible"; cp.set_response_type("JSON"); cp.call(p, "alteraclasse", fim); diff --git a/ferramentas/legenda/template_mst.html b/ferramentas/legenda/template_mst.html index 7bfad4f..e61277e 100644 --- a/ferramentas/legenda/template_mst.html +++ b/ferramentas/legenda/template_mst.html @@ -187,6 +187,19 @@
+ {{{metade}}} +

{{{duasmetades}}}

+
+
+

{{{iunico}}}

+
+
+

+ +

+
+
+
{{{calcularQuartil}}}

{{{criaQuartis}}}

-- libgit2 0.21.2