arrayValores = $arrayValores; $this->maxVal = $maxVal; $this->maxWidth = $maxWidth; $this->deslocamentos = array(); $this->titulo = $titulo; $this->totalGeral = $totalGeral; } function geraHTML() { $colspan = ( $this->totalGeral ) ? 4: 3; $getLinhas = $this->getLinha( $this->arrayValores, 0, 0 ); $retorno = " Gráfico \n"; if( $this->titulo ) { $retorno .= ""; } $retorno .= $getLinhas; if( $this->titulo ) { $retorno .= ""; } $retorno .= "
{$this->titulo}
ValoresPercentagem
Total
{$this->totalGeral}100%
 
"; return $retorno; } function printHTML() { echo $this->geraHTML(); } // monta as linhas recursivamente function getLinha( $arr, $nivel, $nmPai ) { $retorno = ""; $identacao = str_repeat( $this->charIdentacao, max( $nivel - 1, 0 ) ); if( ! isset( $this->deslocamentos[$nivel] ) ) { $this->deslocamentos[$nivel] = 0; } // primeiro verifica o campo graf_default if( isset( $arr["graf_default"] ) ) { if ( is_numeric( $arr["graf_default"] ) ) { if( $nmPai ) { // exibe o campo com a barra correspondente $porcentagem = ""; $proporcao = round( ( $arr["graf_default"] / $this->maxVal ) * $this->maxWidth ); $retorno .= "{$identacao}{$nmPai}"; $retorno .= "deslocamentos[$nivel]}\" height=\"5\" border=\"0\" title=\"". number_format( $arr["graf_default"], 2, ",", "." ) . "\">"; if( $this->totalGeral ) { $porcentagem = number_format( ( $arr["graf_default"] / $this->totalGeral ) * 100, 2, ",", "." ); } $complete = 0; if( $nivel > 1 ) { $this->deslocamentos[$nivel] += $proporcao; if( $this->deslocamentos[( $nivel -1 )] ) { $complete = $this->deslocamentos[( $nivel -1 )] - $this->deslocamentos[$nivel]; } } else { $this->deslocamentos = array(); } $retorno .= ""; if( $complete ) { $retorno .= ""; } $retorno .= "". number_format( $arr["graf_default"], 2, ",", "." ); if( $this->totalGeral ) { $retorno .= "({$porcentagem}%)"; } $retorno .= "\n"; } } else { // exibe apenas um rotulo vazio $retorno .= "{$identacao}{$nmPai} \n"; } } $identacao = str_repeat( $this->charIdentacao, $nivel ); //$deslocamentoLinha = 0; // passa todos os itens foreach ( $arr AS $key => $value ) { if( $key != "graf_default" ) { if( is_array( $value ) ) { // chama recursivamente o metodo $retorno .= $this->getLinha( $value, $nivel + 1, $key ); } else if ( is_numeric( $value ) ) { // exibe o campo com a barra correspondente $proporcao = round( ( $value / $this->maxVal ) * $this->maxWidth ); $retorno .= "{$identacao}{$key}"; $retorno .= "deslocamentos[$nivel]}\" height=\"5\" border=\"0\" title=\"". number_format( $arr["graf_default"], 2, ",", "." ) . "\">"; $retorno .= "". number_format( $value, 2, ",", "." ) . "\n"; $this->deslocamentos[$nivel] += $proporcao; } } } $retorno .= " "; return $retorno; } } ?>