Coder Social home page Coder Social logo

Conditional colors? about jasperphp HOT 24 CLOSED

quilhasoft avatar quilhasoft commented on June 20, 2024
Conditional colors?

from jasperphp.

Comments (24)

Rctnet avatar Rctnet commented on June 20, 2024

use is_integer($F{rowIndex}/2) into printWhen property on band, create a two bands

from jasperphp.

gamadoleo avatar gamadoleo commented on June 20, 2024

I understand is because I don't have this rowIndex in the select, wouldn't it be more interesting to support this conditional no?:
($V{COLUMN_COUNT}% 2) == 0

from jasperphp.

Rctnet avatar Rctnet commented on June 20, 2024

You can add here

$obj->arrayVariable['REPORT_COUNT']["ans"] = $rowIndex;

from jasperphp.

gamadoleo avatar gamadoleo commented on June 20, 2024

As you guide requires two bands, I tried something simpler using a rectangle and applying the print condition on it, but it didn't work... are these conditionings also ready for rectangle?

from jasperphp.

gamadoleo avatar gamadoleo commented on June 20, 2024

but mind you, jasper report has style functionality and in a style we can add conditional formatting, where can i be testing and modifying to support conditional formatting of the style?

from jasperphp.

Rctnet avatar Rctnet commented on June 20, 2024

I understand now, but i´m sorry, i never use it, where in jasperstudio can be access it ?

from jasperphp.

Rctnet avatar Rctnet commented on June 20, 2024

I found styles, i think what a way to support this
in

$this->group_handler($ObjElement);

add a function to read each style and store into a global array, and all objects what you want to use styles, load style property into a object, (all objects are a separate Class) and use styles properties to decore that element, but yet no locate conditional styles, help me about this and i help you to think a way to do this.

from jasperphp.

gamadoleo avatar gamadoleo commented on June 20, 2024

thanks for the support, come on I'll demonstrate what I've achieved so far

from jasperphp.

gamadoleo avatar gamadoleo commented on June 20, 2024

in Report.php on line 68 I added the following debugging:

            //echo $className."<br/>";               
            if(ucfirst($obj)=='Style'){
            echo "<br/><br/>".$className."<br/>";
            print_r($value);
            echo "<br/><br/>";     
            if(isset($value->conditionalStyle)){
                echo "conditionExpression: ".$value->conditionalStyle->conditionExpression;
                echo "<br/>";                
                //get definition style condicional
                $style= $value->conditionalStyle->style->attributes();
                var_dump($style);   
                echo "<br/>";         
                echo "mode: ".$style['mode']."<br/>";
                echo "backcolor: ".$style['backcolor']."<br/><br/>";   
                
            }
            } 

e o result is:

JasperPHP\Style
SimpleXMLElement Object ( [@attributes] => Array ( [name] => Title [fontName] => Times New Roman [fontSize] => 50 [isBold] => true ) )



JasperPHP\Style
SimpleXMLElement Object ( [@attributes] => Array ( [name] => SubTitle [forecolor] => #736343 [fontName] => Arial [fontSize] => 18 ) )



JasperPHP\Style
SimpleXMLElement Object ( [@attributes] => Array ( [name] => Column header [forecolor] => #666666 [fontName] => Arial [fontSize] => 12 [isBold] => true ) )



JasperPHP\Style
SimpleXMLElement Object ( [@attributes] => Array ( [name] => Detail [fill] => Solid [scaleImage] => FillFrame [markup] => none [fontName] => Arial [fontSize] => 12 ) [conditionalStyle] => SimpleXMLElement Object ( [style] => SimpleXMLElement Object ( ) ) )

conditionExpression:
object(SimpleXMLElement)#9 (0) { }
mode:
backcolor:



JasperPHP\Style
SimpleXMLElement Object ( [@attributes] => Array ( [name] => Row [mode] => Transparent [backcolor] => #EDE8E8 [pattern] => ) [conditionalStyle] => SimpleXMLElement Object ( [conditionExpression] => $V{COLUMN_COUNT}%2 == 0 [style] => SimpleXMLElement Object ( [@attributes] => Array ( [mode] => Opaque [backcolor] => #F0F0F0 ) ) ) )

conditionExpression: $V{COLUMN_COUNT}%2 == 0
object(SimpleXMLElement)#8 (1) { ["@attributes"]=> array(2) { ["mode"]=> string(6) "Opaque" ["backcolor"]=> string(7) "#F0F0F0" } }
mode: Opaque
backcolor: #F0F0F0

from jasperphp.

gamadoleo avatar gamadoleo commented on June 20, 2024

however, for this to be possible, it is necessary to make an adjustment in the initialization of the xml, I see that I modified it, I would have to see if this affects your structure used so far, but this way it displays the conditional expression of the style:

$xml = simplexml_load_string($xmlFile,null,LIBXML_NOCDATA);

from jasperphp.

gamadoleo avatar gamadoleo commented on June 20, 2024

as in the definition of objects, for example, in TextField there is the property style with the name of the style, I believe it is possible to search the definition of the style and apply the conditional

from jasperphp.

Rctnet avatar Rctnet commented on June 20, 2024

i hope what the best way is it

// atribui o conteúdo do label

if(ucfirst($obj)=='Style'){
$this->addStyle($obj); // create a new method into Report.php
}
puclic function addStyle($style){
$this->arrayStyles[] = $style; // here you can trate all parameter of style
}

make this, for example in texfield you get the style property and this line you can get the report object

$obj = is_array($obj) ? $obj[0] : $obj;

you can get $obj->arrayStyles and use it to decorate a element

from jasperphp.

gamadoleo avatar gamadoleo commented on June 20, 2024

following your idea I created methods and I can apply exactly the style definitions, all the definitions: background, color and etc... this in TextFiel for now... now I need to see how to apply the conditional style...

in Report.php
add
public $arrayStyles;

add

          //echo $className."<br/>"; 
            // atribui o conteúdo do label
            if(ucfirst($obj)=='Style'){
            $this->addStyle($value); // create a new method into Report.php
            }    

new methods

public function addStyle($style){
//print_r($style);return;
$attributes = $style->attributes();
$key = $attributes['name'];
$this->arrayStyles["{$key}"] = $style; // here you can trate all parameter of style
}

public function getStyle($key){
    if(isset($this->arrayStyles["{$key}"])){
    return $this->arrayStyles["{$key}"];
    }
}
public function applyStyle($key, &$reportElement){
    $style = $this->getStyle($key);
    if($style){
        $attributes = $style->attributes();
        foreach($attributes as $key => $value){
            //ignore
            if(!in_array($key,array('name'))){
                //echo "{$key} - {$value}<br/>";    
                $reportElement[$key]=$value;                             
            }   
        }
    }

in TextField.php

` //print_r( $data["@attributes"]);

    //exist style
    if(isset($data->reportElement['style'])){
    $name = $data->reportElement['style'];
    $obj->applyStyle($name, $data->reportElement);
    }`

from jasperphp.

gamadoleo avatar gamadoleo commented on June 20, 2024

that is, now when applying the style, you first need to check the conditional expression to choose which definition to apply the default or the conditional style...

from jasperphp.

Rctnet avatar Rctnet commented on June 20, 2024

this code help you to load and execute expression, i think it is same as printWhenExpression

$print_expression_result = false;

from jasperphp.

gamadoleo avatar gamadoleo commented on June 20, 2024

get it here by modifying a little, so it checks and gets the style according to the conditional, it even accepts more than one conditional in the same style... I just can't say if this will affect the generator's performance... at the same here I haven't seen any effect, but everything can be improved.

from jasperphp.

gamadoleo avatar gamadoleo commented on June 20, 2024

modify for

`public function applyStyle($key, &$reportElement, $rowData){
        $style = $this->getStyle($key);
        if($style){
            //default
            $attributes = $style->attributes();
            if(isset($style->conditionalStyle)){ 
                //percore os styles
                foreach($style->conditionalStyle as $styleNew){                
                    $expression = $styleNew->conditionExpression;             
                    //echo $expression;
                    $resultExpression = false;
                    $expression = $this->get_expression($expression, $rowData);
                    //echo 'if(' . $expression . '){$resultExpression=true;}<br/>';
                    eval('if(' . $expression . '){$resultExpression=true;}'); 
                    //echo $resultExpression."<br/>";
                    if($resultExpression){
                        //get definition style condicional
                        $attributCondicional= $styleNew->style->attributes();
                        $attributes = $attributCondicional;
                        break;
                        //var_dump($attributCondicional);  
                    }      
                }
            }           
           //change propriedades 
            foreach($attributes as $key => $value){
                //ignore
                if(!in_array($key,array('name'))){
                    //echo "{$key} - {$value}<br/>";    
                    $reportElement[$key]=$value;                             
                }   
            }
           
        }        
    }`

from jasperphp.

Rctnet avatar Rctnet commented on June 20, 2024

great!!

from jasperphp.

gamadoleo avatar gamadoleo commented on June 20, 2024

about adding new variables I added in
Report.php
$obj->arrayVariable['COLUMN_COUNT'] = $rowIndex;//by gamadoleo

however to work the replace I had to make a small adjustment in the getValOfVariable method in the last one else

//by gamadoleo
if($ans==''){
return str_ireplace(array('$V{' . $variable . '}'), $val, $text);
}
return str_ireplace(array('$V{' . $variable . '}'), array($ans), $text);

from jasperphp.

gamadoleo avatar gamadoleo commented on June 20, 2024

the way I did the application of the style, it performs the conditional check on each TextField object, I don't know if I would be able to reduce this check, you who are more inside can analyze my function and see if you can improve the performance. but in the test here a 71 page report generates in less than 10s, but as I said everything can be improved.

from jasperphp.

Rctnet avatar Rctnet commented on June 20, 2024

ok, send a Pull Request with yours updates

from jasperphp.

Rctnet avatar Rctnet commented on June 20, 2024

add zebra style to cities sample

from jasperphp.

gamadoleo avatar gamadoleo commented on June 20, 2024

OK, just confirm about adding new variables for replication if I did something wrong? to not need to modify a getValOfVariable function

no details I added like this:
$obj->arrayVariable['COLUMN_COUNT'] = $rowIndex; // by gamma oil

however, tweak the getValOfVariable function

from jasperphp.

gamadoleo avatar gamadoleo commented on June 20, 2024

I will provide the example and send

ignore the aforementioned setting of Variable, actually the REPORT_COUNT works for me

from jasperphp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.