idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
45,100
public function create ( string $ className , string $ typeName ) : Type { $ identifiers = $ this -> entityManager -> getClassMetadata ( $ className ) -> getIdentifier ( ) ; if ( count ( $ identifiers ) > 1 ) { throw new Exception ( 'Entities with composite identifiers are not supported by graphql-doctrine. The entity `' . $ className . '` cannot be used as input type.' ) ; } return new EntityIDType ( $ this -> entityManager , $ className , $ typeName ) ; }
Create an EntityIDType from a Doctrine entity
45,101
public function createAliasName ( string $ className ) : string { $ alias = lcfirst ( preg_replace ( '~^.*\\\\~' , '' , $ className ) ) ; if ( ! isset ( $ this -> aliasCount [ $ alias ] ) ) { $ this -> aliasCount [ $ alias ] = 1 ; } return $ alias . $ this -> aliasCount [ $ alias ] ++ ; }
Return a string to be used as alias name in a query
45,102
public function create ( string $ className ) : array { $ this -> findIdentityField ( $ className ) ; $ class = $ this -> metadata -> getReflectionClass ( ) ; $ methods = $ class -> getMethods ( ReflectionMethod :: IS_PUBLIC ) ; $ fieldConfigurations = [ ] ; foreach ( $ methods as $ method ) { if ( $ method -> isAbstract ( ) || $ method -> isStatic ( ) ) { continue ; } $ name = $ method -> getName ( ) ; if ( ! preg_match ( $ this -> getMethodPattern ( ) , $ name ) ) { continue ; } if ( $ this -> isExcluded ( $ method ) ) { continue ; } $ configuration = $ this -> methodToConfiguration ( $ method ) ; if ( $ configuration ) { $ fieldConfigurations [ ] = $ configuration ; } } return $ fieldConfigurations ; }
Create a configuration for all fields of Doctrine entity
45,103
private function isExcluded ( ReflectionMethod $ method ) : bool { $ exclude = $ this -> getAnnotationReader ( ) -> getMethodAnnotation ( $ method , Exclude :: class ) ; return $ exclude !== null ; }
Returns whether the getter is excluded
45,104
final protected function getTypeFromPhpDeclaration ( ReflectionMethod $ method , ? string $ typeDeclaration , bool $ isEntityId = false ) : ? Type { if ( ! $ typeDeclaration ) { return null ; } $ isNullable = 0 ; $ name = preg_replace ( '~(^\?|^null\||\|null$)~' , '' , $ typeDeclaration , - 1 , $ isNullable ) ; $ isList = 0 ; $ name = preg_replace ( '~^(.*)\[\]$~' , '$1' , $ name , - 1 , $ isList ) ; $ name = $ this -> adjustNamespace ( $ method , $ name ) ; $ type = $ this -> getTypeFromRegistry ( $ name , $ isEntityId ) ; if ( $ isList ) { $ type = Type :: listOf ( $ type ) ; } if ( ! $ isNullable ) { $ type = Type :: nonNull ( $ type ) ; } return $ type ; }
Get instance of GraphQL type from a PHP class name
45,105
private function adjustNamespace ( ReflectionMethod $ method , string $ type ) : string { $ namespace = $ method -> getDeclaringClass ( ) -> getNamespaceName ( ) ; if ( $ namespace ) { $ namespace = $ namespace . '\\' ; } $ namespacedType = $ namespace . $ type ; return class_exists ( $ namespacedType ) ? $ namespacedType : $ type ; }
Prepend namespace of the method if the class actually exists
45,106
final protected function getTypeFromReturnTypeHint ( ReflectionMethod $ method , string $ fieldName ) : ? Type { $ returnType = $ method -> getReturnType ( ) ; if ( ! $ returnType ) { return null ; } $ returnTypeName = ( string ) $ returnType ; if ( is_a ( $ returnTypeName , Collection :: class , true ) || $ returnTypeName === 'array' ) { $ targetEntity = $ this -> getTargetEntity ( $ fieldName ) ; if ( ! $ targetEntity ) { throw new Exception ( 'The method ' . $ this -> getMethodFullName ( $ method ) . ' is type hinted with a return type of `' . $ returnTypeName . '`, but the entity contained in that collection could not be automatically detected. Either fix the type hint, fix the doctrine mapping, or specify the type with `@API\Field` annotation.' ) ; } $ type = Type :: listOf ( $ this -> getTypeFromRegistry ( $ targetEntity , false ) ) ; if ( ! $ returnType -> allowsNull ( ) ) { $ type = Type :: nonNull ( $ type ) ; } return $ type ; } return $ this -> reflectionTypeToType ( $ returnType ) ; }
Get a GraphQL type instance from PHP type hinted type possibly looking up the content of collections
45,107
final protected function reflectionTypeToType ( ReflectionType $ reflectionType , bool $ isEntityId = false ) : Type { $ name = $ reflectionType -> getName ( ) ; if ( $ name === 'self' ) { $ name = $ this -> metadata -> name ; } $ type = $ this -> getTypeFromRegistry ( $ name , $ isEntityId ) ; if ( ! $ reflectionType -> allowsNull ( ) ) { $ type = Type :: nonNull ( $ type ) ; } return $ type ; }
Convert a reflected type to GraphQL Type
45,108
private function findIdentityField ( string $ className ) : void { $ this -> metadata = $ this -> entityManager -> getClassMetadata ( $ className ) ; foreach ( $ this -> metadata -> fieldMappings as $ meta ) { if ( $ meta [ 'id' ] ?? false ) { $ this -> identityField = $ meta [ 'fieldName' ] ; } } }
Look up which field is the ID
45,109
final protected function throwIfArray ( ReflectionParameter $ param , ? string $ type ) : void { if ( $ type === 'array' ) { throw new Exception ( 'The parameter `$' . $ param -> getName ( ) . '` on method ' . $ this -> getMethodFullName ( $ param -> getDeclaringFunction ( ) ) . ' is type hinted as `array` and is not overridden via `@API\Argument` annotation. Either change the type hint or specify the type with `@API\Argument` annotation.' ) ; } }
Throws exception if type is an array
45,110
final protected function getPropertyDefaultValue ( string $ fieldName ) { $ property = $ this -> metadata -> getReflectionProperties ( ) [ $ fieldName ] ?? null ; if ( ! $ property ) { return null ; } return $ property -> getDeclaringClass ( ) -> getDefaultProperties ( ) [ $ fieldName ] ?? null ; }
Return the default value if any of the property for the current entity
45,111
private function getTypeFromRegistry ( string $ type , bool $ isEntityId ) : Type { if ( $ this -> types -> isEntity ( $ type ) && $ isEntityId ) { return $ this -> types -> getId ( $ type ) ; } if ( $ this -> types -> isEntity ( $ type ) && ! $ isEntityId ) { return $ this -> types -> getOutput ( $ type ) ; } return $ this -> types -> get ( $ type ) ; }
Returns a type from our registry
45,112
final protected function nonNullIfHasDefault ( AbstractAnnotation $ annotation ) : void { $ type = $ annotation -> getTypeInstance ( ) ; if ( $ type instanceof NonNull && $ annotation -> hasDefaultValue ( ) ) { $ annotation -> setTypeInstance ( $ type -> getWrappedType ( ) ) ; } }
Input with default values cannot be non - null
45,113
final protected function throwIfNotInputType ( ReflectionParameter $ param , AbstractAnnotation $ annotation ) : void { $ type = $ annotation -> getTypeInstance ( ) ; $ class = new ReflectionClass ( $ annotation ) ; $ annotationName = $ class -> getShortName ( ) ; if ( ! $ type ) { throw new Exception ( 'Could not find type for parameter `$' . $ param -> name . '` for method ' . $ this -> getMethodFullName ( $ param -> getDeclaringFunction ( ) ) . '. Either type hint the parameter, or specify the type with `@API\\' . $ annotationName . '` annotation.' ) ; } if ( $ type instanceof WrappingType ) { $ type = $ type -> getWrappedType ( true ) ; } if ( ! ( $ type instanceof InputType ) ) { throw new Exception ( 'Type for parameter `$' . $ param -> name . '` for method ' . $ this -> getMethodFullName ( $ param -> getDeclaringFunction ( ) ) . ' must be an instance of `' . InputType :: class . '`, but was `' . get_class ( $ type ) . '`. Use `@API\\' . $ annotationName . '` annotation to specify a custom InputType.' ) ; } }
Throws exception if argument type is invalid
45,114
private function completeFieldDefaultValue ( Input $ field , ReflectionParameter $ param , string $ fieldName ) : void { if ( ! $ field -> hasDefaultValue ( ) && $ param -> isDefaultValueAvailable ( ) ) { $ field -> setDefaultValue ( $ param -> getDefaultValue ( ) ) ; } if ( ! $ field -> hasDefaultValue ( ) ) { $ defaultValue = $ this -> getPropertyDefaultValue ( $ fieldName ) ; if ( $ defaultValue !== null ) { $ field -> setDefaultValue ( $ defaultValue ) ; } } }
Complete field default value from argument and property
45,115
public function create ( string $ className , string $ typeName ) : Type { $ type = new InputObjectType ( [ 'name' => $ typeName , 'description' => 'Type to specify conditions on fields' , 'fields' => function ( ) use ( $ className , $ typeName ) : array { $ filters = [ ] ; $ metadata = $ this -> entityManager -> getClassMetadata ( $ className ) ; $ this -> readCustomOperatorsFromAnnotation ( $ metadata -> reflClass ) ; foreach ( $ metadata -> fieldMappings as $ mapping ) { if ( $ mapping [ 'id' ] ?? false ) { $ leafType = Type :: id ( ) ; } else { $ leafType = $ this -> types -> get ( $ mapping [ 'type' ] ) ; } $ fieldName = $ mapping [ 'fieldName' ] ; $ operators = $ this -> getOperators ( $ fieldName , $ leafType , false , false ) ; $ filters [ ] = $ this -> getFieldConfiguration ( $ typeName , $ fieldName , $ operators ) ; } foreach ( $ metadata -> associationMappings as $ mapping ) { $ fieldName = $ mapping [ 'fieldName' ] ; $ operators = $ this -> getOperators ( $ fieldName , Type :: id ( ) , true , $ metadata -> isCollectionValuedAssociation ( $ fieldName ) ) ; $ filters [ ] = $ this -> getFieldConfiguration ( $ typeName , $ fieldName , $ operators ) ; } foreach ( $ this -> customOperators as $ fieldName => $ customOperators ) { $ operators = [ ] ; foreach ( $ customOperators as $ customOperator ) { $ leafType = $ this -> types -> get ( $ customOperator -> type ) ; $ operators [ $ customOperator -> operator ] = $ leafType ; } $ filters [ ] = $ this -> getFieldConfiguration ( $ typeName , $ fieldName , $ operators ) ; } return $ filters ; } , ] ) ; return $ type ; }
Create an InputObjectType from a Doctrine entity to specify condition on fields .
45,116
public function getField ( string $ className ) : array { $ conditionFieldsType = $ this -> types -> getFilterGroupCondition ( $ className ) ; $ field = [ 'name' => 'conditions' , 'description' => 'Conditions to be applied on fields' , 'type' => Type :: listOf ( Type :: nonNull ( $ conditionFieldsType ) ) , ] ; return $ field ; }
Get the field for conditions on all fields
45,117
private function readCustomOperatorsFromAnnotation ( ReflectionClass $ class ) : void { $ allFilters = Utils :: getRecursiveClassAnnotations ( $ this -> getAnnotationReader ( ) , $ class , Filters :: class ) ; $ this -> customOperators = [ ] ; foreach ( $ allFilters as $ classWithAnnotation => $ filters ) { foreach ( $ filters -> filters as $ filter ) { $ className = $ filter -> operator ; $ this -> throwIfInvalidAnnotation ( $ classWithAnnotation , 'Filter' , AbstractOperator :: class , $ className ) ; if ( ! isset ( $ this -> customOperators [ $ filter -> field ] ) ) { $ this -> customOperators [ $ filter -> field ] = [ ] ; } $ this -> customOperators [ $ filter -> field ] [ ] = $ filter ; } } }
Get the custom operators declared on the class via annotations indexed by their field name
45,118
private function getFieldConfiguration ( string $ typeName , string $ fieldName , array $ operators ) : array { return [ 'name' => $ fieldName , 'type' => $ this -> getFieldType ( $ typeName , $ fieldName , $ operators ) , ] ; }
Get configuration for field
45,119
private function getOperators ( string $ fieldName , LeafType $ leafType , bool $ isAssociation , bool $ isCollection ) : array { $ scalarOperators = [ BetweenOperatorType :: class , EqualOperatorType :: class , GreaterOperatorType :: class , GreaterOrEqualOperatorType :: class , InOperatorType :: class , LessOperatorType :: class , LessOrEqualOperatorType :: class , LikeOperatorType :: class , NullOperatorType :: class , GroupOperatorType :: class , ] ; $ associationOperators = [ HaveOperatorType :: class , EmptyOperatorType :: class , ] ; $ operatorKeys = [ ] ; if ( $ isAssociation ) { $ operatorKeys = array_merge ( $ operatorKeys , $ associationOperators ) ; } if ( ! $ isCollection ) { $ operatorKeys = array_merge ( $ operatorKeys , $ scalarOperators ) ; } $ operators = array_fill_keys ( $ operatorKeys , $ leafType ) ; if ( isset ( $ this -> customOperators [ $ fieldName ] ) ) { foreach ( $ this -> customOperators [ $ fieldName ] as $ filter ) { $ leafType = $ this -> types -> get ( $ filter -> type ) ; $ operators [ $ filter -> operator ] = $ leafType ; } unset ( $ this -> customOperators [ $ fieldName ] ) ; } return $ operators ; }
Return a map of operator class name and their leaf type including custom operator for the given fieldName
45,120
private function getFieldType ( string $ typeName , string $ fieldName , array $ operators ) : InputObjectType { $ fieldType = new InputObjectType ( [ 'name' => $ typeName . ucfirst ( $ fieldName ) , 'description' => 'Type to specify a condition on a specific field' , 'fields' => $ this -> getOperatorConfiguration ( $ operators ) , ] ) ; $ this -> types -> registerInstance ( $ fieldType ) ; return $ fieldType ; }
Get the type for a specific field
45,121
private function getOperatorConfiguration ( array $ operators ) : array { $ conf = [ ] ; foreach ( $ operators as $ operator => $ leafType ) { $ instance = $ this -> types -> getOperator ( $ operator , $ leafType ) ; $ field = [ 'name' => $ this -> getOperatorFieldName ( $ operator ) , 'type' => $ instance , ] ; $ conf [ ] = $ field ; } return $ conf ; }
Get operators configuration for a specific leaf type
45,122
private function getOperatorFieldName ( string $ className ) : string { $ name = preg_replace ( '~OperatorType$~' , '' , Utils :: getTypeName ( $ className ) ) ; return lcfirst ( $ name ) ; }
Get the name for the operator to be used as field name
45,123
private function getGroupType ( string $ className , string $ typeName ) : InputObjectType { $ fields = [ [ 'name' => 'groupLogic' , 'type' => $ this -> types -> get ( 'LogicalOperator' ) , 'description' => 'The logic operator to be used to append this group' , 'defaultValue' => 'AND' , ] , [ 'name' => 'conditionsLogic' , 'type' => $ this -> types -> get ( 'LogicalOperator' ) , 'description' => 'The logic operator to be used within all conditions in this group' , 'defaultValue' => 'AND' , ] , $ this -> filterGroupConditionTypeFactory -> getField ( $ className ) , ] ; if ( $ this -> filterGroupJoinTypeFactory -> canCreate ( $ className ) ) { $ fields [ ] = $ this -> filterGroupJoinTypeFactory -> getField ( $ className ) ; } $ conditionType = new InputObjectType ( [ 'name' => $ typeName . 'Group' , 'description' => 'Specify a set of joins and conditions to filter `' . Utils :: getTypeName ( $ className ) . '`' , 'fields' => $ fields , ] ) ; $ this -> types -> registerInstance ( $ conditionType ) ; return $ conditionType ; }
Get the type for condition
45,124
public function create ( string $ className , string $ typeName ) : Type { $ typeName = Utils :: getTypeName ( $ className ) ; $ description = $ this -> getDescription ( $ className ) ; $ fieldsGetter = function ( ) use ( $ className ) : array { $ factory = new OutputFieldsConfigurationFactory ( $ this -> types , $ this -> entityManager ) ; $ configuration = $ factory -> create ( $ className ) ; return $ configuration ; } ; return new ObjectType ( [ 'name' => $ typeName , 'description' => $ description , 'fields' => $ fieldsGetter , ] ) ; }
Create an ObjectType from a Doctrine entity
45,125
private function resolveObject ( $ source , array $ args , string $ fieldName ) { $ getter = $ this -> getGetter ( $ source , $ fieldName ) ; if ( $ getter ) { $ args = $ this -> orderArguments ( $ getter , $ args ) ; return $ getter -> invoke ( $ source , ... $ args ) ; } if ( isset ( $ source -> { $ fieldName } ) ) { return $ source -> { $ fieldName } ; } return null ; }
Resolve for an object
45,126
private function orderArguments ( ReflectionMethod $ method , array $ args ) : array { $ result = [ ] ; if ( ! $ args ) { return $ result ; } foreach ( $ method -> getParameters ( ) as $ param ) { if ( array_key_exists ( $ param -> getName ( ) , $ args ) ) { $ arg = $ args [ $ param -> getName ( ) ] ; if ( $ arg instanceof EntityID ) { $ arg = $ arg -> getEntity ( ) ; } $ result [ ] = $ arg ; } } return $ result ; }
Re - order associative args to ordered args
45,127
public function serialize ( $ value ) : string { $ id = $ this -> entityManager -> getClassMetadata ( $ this -> className ) -> getIdentifierValues ( $ value ) ; return ( string ) reset ( $ id ) ; }
Serializes an internal value to include in a response .
45,128
private function createEntityID ( string $ id ) : EntityID { return new EntityID ( $ this -> entityManager , $ this -> className , $ id ) ; }
Create EntityID to retrieve entity from DB later on
45,129
public function create ( string $ className , string $ typeName ) : Type { $ type = clone $ this -> types -> getInput ( $ className ) ; $ fieldsGetter = $ type -> config [ 'fields' ] ; $ optionalFieldsGetter = function ( ) use ( $ fieldsGetter ) : array { $ optionalFields = [ ] ; foreach ( $ fieldsGetter ( ) as $ field ) { if ( $ field [ 'type' ] instanceof NonNull ) { $ field [ 'type' ] = $ field [ 'type' ] -> getWrappedType ( ) ; } unset ( $ field [ 'defaultValue' ] ) ; $ optionalFields [ ] = $ field ; } return $ optionalFields ; } ; $ type -> config [ 'fields' ] = $ optionalFieldsGetter ; $ type -> name = $ typeName ; return $ type ; }
Create an InputObjectType from a Doctrine entity but will all fields as optional and without default values .
45,130
public static function getOperatorTypeName ( string $ className , LeafType $ type ) : string { return preg_replace ( '~Type$~' , '' , self :: getTypeName ( $ className ) ) . ucfirst ( $ type -> name ) ; }
Get the GraphQL type name for a Filter type from the PHP class
45,131
public static function getRecursiveClassAnnotations ( Reader $ reader , ReflectionClass $ class , string $ annotationName ) : array { $ result = [ ] ; $ annotation = $ reader -> getClassAnnotation ( $ class , $ annotationName ) ; if ( $ annotation ) { $ result [ $ class -> getName ( ) ] = $ annotation ; } foreach ( $ class -> getTraits ( ) as $ trait ) { $ result = array_merge ( $ result , self :: getRecursiveClassAnnotations ( $ reader , $ trait , $ annotationName ) ) ; } $ parent = $ class -> getParentClass ( ) ; if ( $ parent ) { $ result = array_merge ( $ result , self :: getRecursiveClassAnnotations ( $ reader , $ parent , $ annotationName ) ) ; } return $ result ; }
Return an array of all annotations found in the class hierarchy including its traits indexed by the class name
45,132
public function getUrl ( ) { $ urlParts = array_filter ( [ $ this -> domain , $ this -> getNickname ( ) ] ) ; return count ( $ urlParts ) ? implode ( '/' , $ urlParts ) : null ; }
Get resource owner url
45,133
public function setSliceColor ( $ SliceID , array $ Format = [ ] ) { $ R = isset ( $ Format [ "R" ] ) ? $ Format [ "R" ] : 0 ; $ G = isset ( $ Format [ "G" ] ) ? $ Format [ "G" ] : 0 ; $ B = isset ( $ Format [ "B" ] ) ? $ Format [ "B" ] : 0 ; $ Alpha = isset ( $ Format [ "Alpha" ] ) ? $ Format [ "Alpha" ] : 100 ; $ this -> pDataObject -> Palette [ $ SliceID ] [ "R" ] = $ R ; $ this -> pDataObject -> Palette [ $ SliceID ] [ "G" ] = $ G ; $ this -> pDataObject -> Palette [ $ SliceID ] [ "B" ] = $ B ; $ this -> pDataObject -> Palette [ $ SliceID ] [ "Alpha" ] = $ Alpha ; }
Set the color of the specified slice
45,134
public function shift ( $ StartAngle , $ EndAngle , $ Offset , $ Reversed ) { if ( $ Reversed ) { $ Offset = - $ Offset ; } foreach ( $ this -> LabelPos as $ Key => $ Settings ) { if ( $ Settings [ "Angle" ] > $ StartAngle && $ Settings [ "Angle" ] <= $ EndAngle ) { $ this -> LabelPos [ $ Key ] [ "YTop" ] = $ Settings [ "YTop" ] + $ Offset ; $ this -> LabelPos [ $ Key ] [ "YBottom" ] = $ Settings [ "YBottom" ] + $ Offset ; $ this -> LabelPos [ $ Key ] [ "Y2" ] = $ Settings [ "Y2" ] + $ Offset ; } } }
Internally used to shift label positions
45,135
public function writeShiftedLabels ( ) { if ( ! count ( $ this -> LabelPos ) ) { return 0 ; } foreach ( $ this -> LabelPos as $ Settings ) { $ X1 = $ Settings [ "X1" ] ; $ Y1 = $ Settings [ "Y1" ] ; $ X2 = $ Settings [ "X2" ] ; $ Y2 = $ Settings [ "Y2" ] ; $ X3 = $ Settings [ "X3" ] ; $ Angle = $ Settings [ "Angle" ] ; $ Label = $ Settings [ "Label" ] ; $ this -> pChartObject -> drawArrow ( $ X2 , $ Y2 , $ X1 , $ Y1 , [ "Size" => 8 ] ) ; if ( $ Angle <= 180 ) { $ this -> pChartObject -> drawLine ( $ X2 , $ Y2 , $ X3 , $ Y2 ) ; $ this -> pChartObject -> drawText ( $ X3 + 2 , $ Y2 , $ Label , [ "Align" => TEXT_ALIGN_MIDDLELEFT ] ) ; } else { $ this -> pChartObject -> drawLine ( $ X2 , $ Y2 , $ X3 , $ Y2 ) ; $ this -> pChartObject -> drawText ( $ X3 - 2 , $ Y2 , $ Label , [ "Align" => TEXT_ALIGN_MIDDLERIGHT ] ) ; } } }
Internally used to write the re - computed labels
45,136
public function arrayReverse ( array $ Plots ) { $ Result = [ ] ; for ( $ i = count ( $ Plots ) - 1 ; $ i >= 0 ; $ i = $ i - 2 ) { $ Result [ ] = $ Plots [ $ i - 1 ] ; $ Result [ ] = $ Plots [ $ i ] ; } return $ Result ; }
Reverse an array
45,137
public function clean0Values ( array $ Data , array $ Palette , $ DataSerie , $ AbscissaSerie ) { $ NewPalette = [ ] ; $ NewData = [ ] ; $ NewAbscissa = [ ] ; foreach ( array_keys ( $ Data [ "Series" ] ) as $ SerieName ) { if ( $ SerieName != $ DataSerie && $ SerieName != $ AbscissaSerie ) { unset ( $ Data [ "Series" ] [ $ SerieName ] ) ; } } foreach ( $ Data [ "Series" ] [ $ DataSerie ] [ "Data" ] as $ Key => $ Value ) { if ( $ Value != 0 ) { $ NewData [ ] = $ Value ; $ NewAbscissa [ ] = $ Data [ "Series" ] [ $ AbscissaSerie ] [ "Data" ] [ $ Key ] ; if ( isset ( $ Palette [ $ Key ] ) ) { $ NewPalette [ ] = $ Palette [ $ Key ] ; } } } $ Data [ "Series" ] [ $ DataSerie ] [ "Data" ] = $ NewData ; $ Data [ "Series" ] [ $ AbscissaSerie ] [ "Data" ] = $ NewAbscissa ; return [ $ Data , $ NewPalette ] ; }
Remove unused series & values
45,138
public function setGraphArea ( $ X1 , $ Y1 , $ X2 , $ Y2 ) { if ( $ X2 < $ X1 || $ X1 == $ X2 || $ Y2 < $ Y1 || $ Y1 == $ Y2 ) { return - 1 ; } $ this -> GraphAreaX1 = $ X1 ; $ this -> DataSet -> Data [ "GraphArea" ] [ "X1" ] = $ X1 ; $ this -> GraphAreaY1 = $ Y1 ; $ this -> DataSet -> Data [ "GraphArea" ] [ "Y1" ] = $ Y1 ; $ this -> GraphAreaX2 = $ X2 ; $ this -> DataSet -> Data [ "GraphArea" ] [ "X2" ] = $ X2 ; $ this -> GraphAreaY2 = $ Y2 ; $ this -> DataSet -> Data [ "GraphArea" ] [ "Y2" ] = $ Y2 ; }
Set the graph area position
45,139
public function render ( $ FileName ) { if ( $ this -> TransparentBackground ) { imagealphablending ( $ this -> Picture , false ) ; imagesavealpha ( $ this -> Picture , true ) ; } imagepng ( $ this -> Picture , $ FileName ) ; }
Render the picture to a file
45,140
public function stroke ( $ BrowserExpire = false ) { if ( $ this -> TransparentBackground ) { imagealphablending ( $ this -> Picture , false ) ; imagesavealpha ( $ this -> Picture , true ) ; } if ( $ BrowserExpire ) { header ( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ) ; header ( "Cache-Control: no-cache" ) ; header ( "Pragma: no-cache" ) ; } header ( 'Content-type: image/png' ) ; imagepng ( $ this -> Picture ) ; }
Render the picture to a web browser stream
45,141
public function getLength ( $ X1 , $ Y1 , $ X2 , $ Y2 ) { return sqrt ( pow ( max ( $ X1 , $ X2 ) - min ( $ X1 , $ X2 ) , 2 ) + pow ( max ( $ Y1 , $ Y2 ) - min ( $ Y1 , $ Y2 ) , 2 ) ) ; }
Return the length between two points
45,142
public function setFontProperties ( $ Format = [ ] ) { $ R = isset ( $ Format [ "R" ] ) ? $ Format [ "R" ] : - 1 ; $ G = isset ( $ Format [ "G" ] ) ? $ Format [ "G" ] : - 1 ; $ B = isset ( $ Format [ "B" ] ) ? $ Format [ "B" ] : - 1 ; $ Alpha = isset ( $ Format [ "Alpha" ] ) ? $ Format [ "Alpha" ] : 100 ; $ FontName = isset ( $ Format [ "FontName" ] ) ? $ Format [ "FontName" ] : null ; $ FontSize = isset ( $ Format [ "FontSize" ] ) ? $ Format [ "FontSize" ] : null ; if ( $ R != - 1 ) { $ this -> FontColorR = $ R ; } if ( $ G != - 1 ) { $ this -> FontColorG = $ G ; } if ( $ B != - 1 ) { $ this -> FontColorB = $ B ; } if ( $ Alpha != null ) { $ this -> FontColorA = $ Alpha ; } if ( $ FontName != null ) { $ this -> FontName = $ this -> loadFont ( $ FontName , 'fonts' ) ; } if ( $ FontSize != null ) { $ this -> FontSize = $ FontSize ; } }
Set current font properties
45,143
public function initialiseImageMap ( $ Name = "pChart" , $ StorageMode = IMAGE_MAP_STORAGE_SESSION , $ UniqueID = "imageMap" , $ StorageFolder = "tmp" ) { $ this -> ImageMapIndex = $ Name ; $ this -> ImageMapStorageMode = $ StorageMode ; if ( $ StorageMode == IMAGE_MAP_STORAGE_SESSION ) { if ( ! isset ( $ _SESSION ) ) { session_start ( ) ; } $ _SESSION [ $ this -> ImageMapIndex ] = null ; } elseif ( $ StorageMode == IMAGE_MAP_STORAGE_FILE ) { $ this -> ImageMapFileName = $ UniqueID ; $ this -> ImageMapStorageFolder = $ StorageFolder ; $ path = sprintf ( "%s/%s.map" , $ StorageFolder , $ UniqueID ) ; if ( file_exists ( $ path ) ) { unlink ( $ path ) ; } } }
Initialise the image map methods
45,144
public function addToImageMap ( $ Type , $ Plots , $ Color = null , $ Title = null , $ Message = null , $ HTMLEncode = false ) { if ( $ this -> ImageMapStorageMode == null ) { $ this -> initialiseImageMap ( ) ; } $ Title = htmlentities ( str_replace ( "&#8364;" , "\u20AC" , $ Title ) , ENT_QUOTES , "ISO-8859-15" ) ; if ( $ HTMLEncode ) { $ Message = str_replace ( "&gt;" , ">" , str_replace ( "&lt;" , "<" , htmlentities ( $ Message , ENT_QUOTES , "ISO-8859-15" ) ) ) ; } if ( $ this -> ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION ) { if ( ! isset ( $ _SESSION ) ) { $ this -> initialiseImageMap ( ) ; } $ _SESSION [ $ this -> ImageMapIndex ] [ ] = [ $ Type , $ Plots , $ Color , $ Title , $ Message ] ; } elseif ( $ this -> ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE ) { $ Handle = fopen ( sprintf ( "%s/%s.map" , $ this -> ImageMapStorageFolder , $ this -> ImageMapFileName ) , 'a' ) ; fwrite ( $ Handle , sprintf ( "%s%s%s%s%s%s%s%s%s\r\n" , $ Type , IMAGE_MAP_DELIMITER , $ Plots , IMAGE_MAP_DELIMITER , $ Color , IMAGE_MAP_DELIMITER , $ Title , IMAGE_MAP_DELIMITER , $ Message ) ) ; fclose ( $ Handle ) ; } }
Add a zone to the image map
45,145
public function removeVOIDFromArray ( $ SerieName , array $ Values ) { if ( ! isset ( $ this -> DataSet -> Data [ "Series" ] [ $ SerieName ] ) ) { return - 1 ; } $ Result = [ ] ; foreach ( $ this -> DataSet -> Data [ "Series" ] [ $ SerieName ] [ "Data" ] as $ Key => $ Value ) { if ( $ Value != VOID && isset ( $ Values [ $ Key ] ) ) { $ Result [ ] = $ Values [ $ Key ] ; } } return $ Result ; }
Remove VOID values from an imagemap custom values array
45,146
public function replaceImageMapValues ( $ Title , array $ Values ) { if ( $ this -> ImageMapStorageMode == null ) { return - 1 ; } $ Values = $ this -> removeVOIDFromArray ( $ Title , $ Values ) ; $ ID = 0 ; if ( $ this -> ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION ) { if ( ! isset ( $ _SESSION ) ) { return - 1 ; } foreach ( $ _SESSION [ $ this -> ImageMapIndex ] as $ Key => $ Settings ) { if ( $ Settings [ 3 ] == $ Title ) { if ( isset ( $ Values [ $ ID ] ) ) { $ _SESSION [ $ this -> ImageMapIndex ] [ $ Key ] [ 4 ] = $ Values [ $ ID ] ; } $ ID ++ ; } } } elseif ( $ this -> ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE ) { $ TempArray = [ ] ; $ Handle = $ this -> openFileHandle ( ) ; if ( $ Handle ) { while ( ( $ Buffer = fgets ( $ Handle , 4096 ) ) !== false ) { $ Fields = preg_split ( "/" . IMAGE_MAP_DELIMITER . "/" , str_replace ( [ chr ( 10 ) , chr ( 13 ) ] , "" , $ Buffer ) ) ; $ TempArray [ ] = [ $ Fields [ 0 ] , $ Fields [ 1 ] , $ Fields [ 2 ] , $ Fields [ 3 ] , $ Fields [ 4 ] ] ; } fclose ( $ Handle ) ; foreach ( $ TempArray as $ Key => $ Settings ) { if ( $ Settings [ 3 ] == $ Title ) { if ( isset ( $ Values [ $ ID ] ) ) { $ TempArray [ $ Key ] [ 4 ] = $ Values [ $ ID ] ; } $ ID ++ ; } } $ Handle = $ this -> openFileHandle ( "w" ) ; foreach ( $ TempArray as $ Key => $ Settings ) { fwrite ( $ Handle , sprintf ( "%s%s%s%s%s%s%s%s%s\r\n" , $ Settings [ 0 ] , IMAGE_MAP_DELIMITER , $ Settings [ 1 ] , IMAGE_MAP_DELIMITER , $ Settings [ 2 ] , IMAGE_MAP_DELIMITER , $ Settings [ 3 ] , IMAGE_MAP_DELIMITER , $ Settings [ 4 ] ) ) ; } fclose ( $ Handle ) ; } } }
Replace the values of the image map contents
45,147
public function dumpImageMap ( $ Name = "pChart" , $ StorageMode = IMAGE_MAP_STORAGE_SESSION , $ UniqueID = "imageMap" , $ StorageFolder = "tmp" ) { $ this -> ImageMapIndex = $ Name ; $ this -> ImageMapStorageMode = $ StorageMode ; if ( $ this -> ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION ) { if ( ! isset ( $ _SESSION ) ) { session_start ( ) ; } if ( $ _SESSION [ $ Name ] != null ) { foreach ( $ _SESSION [ $ Name ] as $ Key => $ Params ) { echo $ Params [ 0 ] . IMAGE_MAP_DELIMITER . $ Params [ 1 ] . IMAGE_MAP_DELIMITER . $ Params [ 2 ] . IMAGE_MAP_DELIMITER . $ Params [ 3 ] . IMAGE_MAP_DELIMITER . $ Params [ 4 ] . "\r\n" ; } } } elseif ( $ this -> ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE ) { if ( file_exists ( $ StorageFolder . "/" . $ UniqueID . ".map" ) ) { $ Handle = @ fopen ( $ StorageFolder . "/" . $ UniqueID . ".map" , "r" ) ; if ( $ Handle ) { while ( ( $ Buffer = fgets ( $ Handle , 4096 ) ) !== false ) { echo $ Buffer ; } } fclose ( $ Handle ) ; if ( $ this -> ImageMapAutoDelete ) { unlink ( $ StorageFolder . "/" . $ UniqueID . ".map" ) ; } } } exit ( ) ; }
Dump the image map
45,148
public function toHTMLColor ( $ R , $ G , $ B ) { $ R = intval ( $ R ) ; $ G = intval ( $ G ) ; $ B = intval ( $ B ) ; $ R = dechex ( $ R < 0 ? 0 : ( $ R > 255 ? 255 : $ R ) ) ; $ G = dechex ( $ G < 0 ? 0 : ( $ G > 255 ? 255 : $ G ) ) ; $ B = dechex ( $ B < 0 ? 0 : ( $ B > 255 ? 255 : $ B ) ) ; $ Color = "#" . ( strlen ( $ R ) < 2 ? '0' : '' ) . $ R ; $ Color .= ( strlen ( $ G ) < 2 ? '0' : '' ) . $ G ; $ Color .= ( strlen ( $ B ) < 2 ? '0' : '' ) . $ B ; return $ Color ; }
Return the HTML converted color from the RGB composite values
45,149
public function reversePlots ( array $ Plots ) { $ Result = [ ] ; for ( $ i = count ( $ Plots ) - 2 ; $ i >= 0 ; $ i = $ i - 2 ) { $ Result [ ] = $ Plots [ $ i ] ; $ Result [ ] = $ Plots [ $ i + 1 ] ; } return $ Result ; }
Reverse an array of points
45,150
protected function loadFont ( $ name , $ type ) { if ( file_exists ( $ name ) ) { return $ name ; } $ path = sprintf ( '%s/%s/%s' , $ this -> resourcePath , $ type , $ name ) ; if ( file_exists ( $ path ) ) { return $ path ; } throw new Exception ( sprintf ( 'The requested resource %s (%s) has not been found!' , $ name , $ type ) ) ; }
Check if requested resource exists and return the path to it if yes .
45,151
public function allocateColor ( $ Picture , $ R , $ G , $ B , $ Alpha = 100 ) { if ( $ R < 0 ) { $ R = 0 ; } if ( $ R > 255 ) { $ R = 255 ; } if ( $ G < 0 ) { $ G = 0 ; } if ( $ G > 255 ) { $ G = 255 ; } if ( $ B < 0 ) { $ B = 0 ; } if ( $ B > 255 ) { $ B = 255 ; } if ( $ Alpha < 0 ) { $ Alpha = 0 ; } if ( $ Alpha > 100 ) { $ Alpha = 100 ; } $ Alpha = $ this -> convertAlpha ( $ Alpha ) ; return imagecolorallocatealpha ( $ Picture , $ R , $ G , $ B , $ Alpha ) ; }
Allocate a color with transparency
45,152
public function computeScale ( $ XMin , $ XMax , $ MaxDivs , array $ Factors , $ AxisID = 0 ) { $ Results = [ ] ; foreach ( $ Factors as $ Key => $ Factor ) { $ Results [ $ Factor ] = $ this -> processScale ( $ XMin , $ XMax , $ MaxDivs , [ $ Factor ] , $ AxisID ) ; } $ GoodScaleFactors = [ ] ; foreach ( $ Results as $ Key => $ Result ) { $ Decimals = preg_split ( "/\./" , $ Result [ "RowHeight" ] ) ; if ( ( ! isset ( $ Decimals [ 1 ] ) ) || ( strlen ( $ Decimals [ 1 ] ) < 6 ) ) { $ GoodScaleFactors [ ] = $ Key ; } } if ( ! count ( $ GoodScaleFactors ) ) { return $ Results [ $ Factors [ 0 ] ] ; } $ MaxRows = 0 ; $ BestFactor = 0 ; foreach ( $ GoodScaleFactors as $ Key => $ Factor ) { if ( $ Results [ $ Factor ] [ "Rows" ] > $ MaxRows ) { $ MaxRows = $ Results [ $ Factor ] [ "Rows" ] ; $ BestFactor = $ Factor ; } } return $ Results [ $ BestFactor ] ; }
Compute the scale check for the best visual factors
45,153
public function countDrawableSeries ( ) { $ count = 0 ; $ Data = $ this -> DataSet -> getData ( ) ; foreach ( $ Data [ "Series" ] as $ SerieName => $ Serie ) { if ( $ Serie [ "isDrawable" ] == true && $ SerieName != $ Data [ "Abscissa" ] ) { $ count ++ ; } } return $ count ; }
Returns the number of drawable series
45,154
public function fixBoxCoordinates ( $ Xa , $ Ya , $ Xb , $ Yb ) { return [ min ( $ Xa , $ Xb ) , min ( $ Ya , $ Yb ) , max ( $ Xa , $ Xb ) , max ( $ Ya , $ Yb ) ] ; }
Fix box coordinates
45,155
public function offsetCorrection ( $ Value , $ Mode ) { $ Value = round ( $ Value , 1 ) ; if ( $ Value == 0 && $ Mode != 1 ) { return 0 ; } if ( $ Mode == 1 ) { if ( $ Value == .5 ) { return .5 ; } if ( $ Value == .8 ) { return .6 ; } if ( in_array ( $ Value , [ .4 , .7 ] ) ) { return .7 ; } if ( in_array ( $ Value , [ .2 , .3 , .6 ] ) ) { return .8 ; } if ( in_array ( $ Value , [ 0 , 1 , .1 , .9 ] ) ) { return .9 ; } } if ( $ Mode == 2 ) { if ( $ Value == .1 ) { return .1 ; } if ( $ Value == .2 ) { return .2 ; } if ( $ Value == .3 ) { return .3 ; } if ( $ Value == .4 ) { return .4 ; } if ( $ Value == .5 ) { return .5 ; } if ( $ Value == .7 ) { return .7 ; } if ( in_array ( $ Value , [ .6 , .8 ] ) ) { return .8 ; } if ( in_array ( $ Value , [ 1 , .9 ] ) ) { return .9 ; } } if ( $ Mode == 3 ) { if ( in_array ( $ Value , [ 1 , .1 ] ) ) { return .1 ; } if ( $ Value == .2 ) { return .2 ; } if ( $ Value == .3 ) { return .3 ; } if ( in_array ( $ Value , [ .4 , .8 ] ) ) { return .4 ; } if ( $ Value == .5 ) { return .9 ; } if ( $ Value == .6 ) { return .6 ; } if ( $ Value == .7 ) { return .7 ; } if ( $ Value == .9 ) { return .5 ; } } if ( $ Mode == 4 ) { if ( $ Value == 1 ) { return - 1 ; } if ( in_array ( $ Value , [ .1 , .4 , .7 , .8 , .9 ] ) ) { return .1 ; } if ( $ Value == .2 ) { return .2 ; } if ( $ Value == .3 ) { return .3 ; } if ( $ Value == .5 ) { return - .1 ; } if ( $ Value == .6 ) { return .8 ; } } }
Apply AALias correction to the rounded box boundaries
45,156
public function scaleFormat ( $ Value , $ Mode = null , $ Format = null , $ Unit = null ) { if ( $ Value == VOID ) { return "" ; } if ( $ Mode == AXIS_FORMAT_TRAFFIC ) { if ( $ Value == 0 ) { return "0B" ; } $ Units = [ "B" , "KB" , "MB" , "GB" , "TB" , "PB" ] ; $ Sign = "" ; if ( $ Value < 0 ) { $ Value = abs ( $ Value ) ; $ Sign = "-" ; } $ Value = number_format ( $ Value / pow ( 1024 , ( $ Scale = floor ( log ( $ Value , 1024 ) ) ) ) , 2 , "," , "." ) ; return $ Sign . $ Value . " " . $ Units [ $ Scale ] ; } if ( $ Mode == AXIS_FORMAT_CUSTOM ) { if ( is_callable ( $ Format ) ) { return call_user_func ( $ Format , $ Value ) ; } } if ( $ Mode == AXIS_FORMAT_DATE ) { $ Pattern = "d/m/Y" ; if ( $ Format !== null ) { $ Pattern = $ Format ; } return gmdate ( $ Pattern , $ Value ) ; } if ( $ Mode == AXIS_FORMAT_TIME ) { $ Pattern = "H:i:s" ; if ( $ Format !== null ) { $ Pattern = $ Format ; } return gmdate ( $ Pattern , $ Value ) ; } if ( $ Mode == AXIS_FORMAT_CURRENCY ) { return $ Format . number_format ( $ Value , 2 ) ; } if ( $ Mode == AXIS_FORMAT_METRIC ) { if ( abs ( $ Value ) > 1000000000 ) { return round ( $ Value / 1000000000 , $ Format ) . "g" . $ Unit ; } if ( abs ( $ Value ) > 1000000 ) { return round ( $ Value / 1000000 , $ Format ) . "m" . $ Unit ; } elseif ( abs ( $ Value ) >= 1000 ) { return round ( $ Value / 1000 , $ Format ) . "k" . $ Unit ; } } return $ Value . $ Unit ; }
Format the axis values
45,157
public function addPoints ( $ Values , $ SerieName = "Serie1" ) { if ( ! isset ( $ this -> Data [ "Series" ] [ $ SerieName ] ) ) { $ this -> initialise ( $ SerieName ) ; } if ( is_array ( $ Values ) ) { foreach ( $ Values as $ Value ) { $ this -> Data [ "Series" ] [ $ SerieName ] [ "Data" ] [ ] = $ Value ; } } else { $ this -> Data [ "Series" ] [ $ SerieName ] [ "Data" ] [ ] = $ Values ; } if ( $ Values != VOID ) { $ StrippedData = $ this -> stripVOID ( $ this -> Data [ "Series" ] [ $ SerieName ] [ "Data" ] ) ; if ( empty ( $ StrippedData ) ) { $ this -> Data [ "Series" ] [ $ SerieName ] [ "Max" ] = 0 ; $ this -> Data [ "Series" ] [ $ SerieName ] [ "Min" ] = 0 ; return 0 ; } $ this -> Data [ "Series" ] [ $ SerieName ] [ "Max" ] = max ( $ StrippedData ) ; $ this -> Data [ "Series" ] [ $ SerieName ] [ "Min" ] = min ( $ StrippedData ) ; } }
Add a single point or an array to the given serie
45,158
public function stripVOID ( $ Values ) { if ( ! is_array ( $ Values ) ) { return [ ] ; } $ Result = [ ] ; foreach ( $ Values as $ Value ) { if ( $ Value != VOID ) { $ Result [ ] = $ Value ; } } return $ Result ; }
Strip VOID values
45,159
public function getSerieCount ( $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] ) ) { return sizeof ( $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] ) ; } return 0 ; }
Return the number of values contained in a given serie
45,160
public function removeSerie ( $ Series ) { if ( ! is_array ( $ Series ) ) { $ Series = $ this -> convertToArray ( $ Series ) ; } foreach ( $ Series as $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] ) ) { unset ( $ this -> Data [ "Series" ] [ $ Serie ] ) ; } } }
Remove a serie from the pData object
45,161
public function getValueAt ( $ Serie , $ Index = 0 ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] [ $ Index ] ) ) { return $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] [ $ Index ] ; } return null ; }
Return a value from given serie & index
45,162
public function getValues ( $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] ) ) { return $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] ; } return null ; }
Return the values array
45,163
public function reverseSerie ( $ Series ) { if ( ! is_array ( $ Series ) ) { $ Series = $ this -> convertToArray ( $ Series ) ; } foreach ( $ Series as $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] ) ) { $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] = array_reverse ( $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] ) ; } } }
Reverse the values in the given serie
45,164
public function getSum ( $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] ) ) { return array_sum ( $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] ) ; } return null ; }
Return the sum of the serie values
45,165
public function getMax ( $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] [ "Max" ] ) ) { return $ this -> Data [ "Series" ] [ $ Serie ] [ "Max" ] ; } return null ; }
Return the max value of a given serie
45,166
public function setSerieDrawable ( $ Series , $ Drawable = true ) { if ( ! is_array ( $ Series ) ) { $ Series = $ this -> convertToArray ( $ Series ) ; } foreach ( $ Series as $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] ) ) { $ this -> Data [ "Series" ] [ $ Serie ] [ "isDrawable" ] = $ Drawable ; } } }
Set a serie as drawable while calling a rendering public function
45,167
public function setSeriePicture ( $ Series , $ Picture = null ) { if ( ! is_array ( $ Series ) ) { $ Series = $ this -> convertToArray ( $ Series ) ; } foreach ( $ Series as $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] ) ) { $ this -> Data [ "Series" ] [ $ Serie ] [ "Picture" ] = $ Picture ; } } }
Set the icon associated to a given serie
45,168
public function setXAxisDisplay ( $ Mode , $ Format = null ) { $ this -> Data [ "XAxisDisplay" ] = $ Mode ; $ this -> Data [ "XAxisFormat" ] = $ Format ; }
Set the display mode of the X Axis
45,169
public function setScatterSerie ( $ SerieX , $ SerieY , $ ID = 0 ) { if ( isset ( $ this -> Data [ "Series" ] [ $ SerieX ] ) && isset ( $ this -> Data [ "Series" ] [ $ SerieY ] ) ) { $ this -> initScatterSerie ( $ ID ) ; $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "X" ] = $ SerieX ; $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Y" ] = $ SerieY ; } }
Create a scatter group specified in X and Y data series
45,170
public function setScatterSerieShape ( $ ID , $ Shape = SERIE_SHAPE_FILLEDCIRCLE ) { if ( isset ( $ this -> Data [ "ScatterSeries" ] [ $ ID ] ) ) { $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Shape" ] = $ Shape ; } }
Set the shape of a given sctatter serie
45,171
public function setScatterSerieDescription ( $ ID , $ Description = "My serie" ) { if ( isset ( $ this -> Data [ "ScatterSeries" ] [ $ ID ] ) ) { $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Description" ] = $ Description ; } }
Set the description of a given scatter serie
45,172
public function setScatterSeriePicture ( $ ID , $ Picture = null ) { if ( isset ( $ this -> Data [ "ScatterSeries" ] [ $ ID ] ) ) { $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Picture" ] = $ Picture ; } }
Set the icon associated to a given scatter serie
45,173
public function setScatterSerieDrawable ( $ ID , $ Drawable = true ) { if ( isset ( $ this -> Data [ "ScatterSeries" ] [ $ ID ] ) ) { $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "isDrawable" ] = $ Drawable ; } }
Set a scatter serie as drawable while calling a rendering public function
45,174
public function setScatterSerieTicks ( $ ID , $ Width = 0 ) { if ( isset ( $ this -> Data [ "ScatterSeries" ] [ $ ID ] ) ) { $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Ticks" ] = $ Width ; } }
Define if a scatter serie should be draw with ticks
45,175
public function setScatterSerieWeight ( $ ID , $ Weight = 0 ) { if ( isset ( $ this -> Data [ "ScatterSeries" ] [ $ ID ] ) ) { $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Weight" ] = $ Weight ; } }
Define if a scatter serie should be draw with a special weight
45,176
public function setScatterSerieColor ( $ ID , array $ Format ) { $ R = isset ( $ Format [ "R" ] ) ? $ Format [ "R" ] : 0 ; $ G = isset ( $ Format [ "G" ] ) ? $ Format [ "G" ] : 0 ; $ B = isset ( $ Format [ "B" ] ) ? $ Format [ "B" ] : 0 ; $ Alpha = isset ( $ Format [ "Alpha" ] ) ? $ Format [ "Alpha" ] : 100 ; if ( isset ( $ this -> Data [ "ScatterSeries" ] [ $ ID ] ) ) { $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Color" ] [ "R" ] = $ R ; $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Color" ] [ "G" ] = $ G ; $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Color" ] [ "B" ] = $ B ; $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Color" ] [ "Alpha" ] = $ Alpha ; } }
Associate a color to a scatter serie
45,177
public function limits ( ) { $ GlobalMin = ABSOLUTE_MAX ; $ GlobalMax = ABSOLUTE_MIN ; foreach ( array_keys ( $ this -> Data [ "Series" ] ) as $ Key ) { if ( $ this -> Data [ "Abscissa" ] != $ Key && $ this -> Data [ "Series" ] [ $ Key ] [ "isDrawable" ] == true ) { if ( $ GlobalMin > $ this -> Data [ "Series" ] [ $ Key ] [ "Min" ] ) { $ GlobalMin = $ this -> Data [ "Series" ] [ $ Key ] [ "Min" ] ; } if ( $ GlobalMax < $ this -> Data [ "Series" ] [ $ Key ] [ "Max" ] ) { $ GlobalMax = $ this -> Data [ "Series" ] [ $ Key ] [ "Max" ] ; } } } $ this -> Data [ "Min" ] = $ GlobalMin ; $ this -> Data [ "Max" ] = $ GlobalMax ; return [ $ GlobalMin , $ GlobalMax ] ; }
Compute the series limits for an individual and global point of view
45,178
public function drawAll ( ) { foreach ( array_keys ( $ this -> Data [ "Series" ] ) as $ Key ) { if ( $ this -> Data [ "Abscissa" ] != $ Key ) { $ this -> Data [ "Series" ] [ $ Key ] [ "isDrawable" ] = true ; } } }
Mark all series as drawable
45,179
public function getSerieAverage ( $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] ) ) { $ SerieData = $ this -> stripVOID ( $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] ) ; return array_sum ( $ SerieData ) / sizeof ( $ SerieData ) ; } return null ; }
Return the average value of the given serie
45,180
public function getGeometricMean ( $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] ) ) { $ SerieData = $ this -> stripVOID ( $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] ) ; $ Seriesum = 1 ; foreach ( $ SerieData as $ Value ) { $ Seriesum = $ Seriesum * $ Value ; } return pow ( $ Seriesum , 1 / sizeof ( $ SerieData ) ) ; } return null ; }
Return the geometric mean of the given serie
45,181
public function getHarmonicMean ( $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] ) ) { $ SerieData = $ this -> stripVOID ( $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] ) ; $ Seriesum = 0 ; foreach ( $ SerieData as $ Value ) { $ Seriesum = $ Seriesum + 1 / $ Value ; } return sizeof ( $ SerieData ) / $ Seriesum ; } return null ; }
Return the harmonic mean of the given serie
45,182
public function getStandardDeviation ( $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] ) ) { $ Average = $ this -> getSerieAverage ( $ Serie ) ; $ SerieData = $ this -> stripVOID ( $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] ) ; $ DeviationSum = 0 ; foreach ( $ SerieData as $ Key => $ Value ) { $ DeviationSum = $ DeviationSum + ( $ Value - $ Average ) * ( $ Value - $ Average ) ; } return sqrt ( $ DeviationSum / count ( $ SerieData ) ) ; } return null ; }
Return the standard deviation of the given serie
45,183
public function getCoefficientOfVariation ( $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] ) ) { $ Average = $ this -> getSerieAverage ( $ Serie ) ; $ StandardDeviation = $ this -> getStandardDeviation ( $ Serie ) ; if ( $ StandardDeviation != 0 ) { return $ StandardDeviation / $ Average ; } } return null ; }
Return the Coefficient of variation of the given serie
45,184
public function getSerieMedian ( $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] ) ) { $ SerieData = $ this -> stripVOID ( $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] ) ; sort ( $ SerieData ) ; $ SerieCenter = floor ( sizeof ( $ SerieData ) / 2 ) ; if ( isset ( $ SerieData [ $ SerieCenter ] ) ) { return $ SerieData [ $ SerieCenter ] ; } } return null ; }
Return the median value of the given serie
45,185
public function getSeriePercentile ( $ Serie = "Serie1" , $ Percentil = 95 ) { if ( ! isset ( $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] ) ) { return null ; } $ Values = count ( $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] ) - 1 ; if ( $ Values < 0 ) { $ Values = 0 ; } $ PercentilID = floor ( ( $ Values / 100 ) * $ Percentil + .5 ) ; $ SortedValues = $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] ; sort ( $ SortedValues ) ; if ( is_numeric ( $ SortedValues [ $ PercentilID ] ) ) { return $ SortedValues [ $ PercentilID ] ; } return null ; }
Return the x th percentil of the given serie
45,186
public function addRandomValues ( $ SerieName = "Serie1" , array $ Options = [ ] ) { $ Values = isset ( $ Options [ "Values" ] ) ? $ Options [ "Values" ] : 20 ; $ Min = isset ( $ Options [ "Min" ] ) ? $ Options [ "Min" ] : 0 ; $ Max = isset ( $ Options [ "Max" ] ) ? $ Options [ "Max" ] : 100 ; $ withFloat = isset ( $ Options [ "withFloat" ] ) ? $ Options [ "withFloat" ] : false ; for ( $ i = 0 ; $ i <= $ Values ; $ i ++ ) { $ Value = $ withFloat ? rand ( $ Min * 100 , $ Max * 100 ) / 100 : rand ( $ Min , $ Max ) ; $ this -> addPoints ( $ Value , $ SerieName ) ; } }
Add random values to a given serie
45,187
public function containsData ( ) { if ( ! isset ( $ this -> Data [ "Series" ] ) ) { return false ; } foreach ( array_keys ( $ this -> Data [ "Series" ] ) as $ Key ) { if ( $ this -> Data [ "Abscissa" ] != $ Key && $ this -> Data [ "Series" ] [ $ Key ] [ "isDrawable" ] == true ) { return true ; } } return null ; }
Test if we have valid data
45,188
public function setAxisDisplay ( $ AxisID , $ Mode = AXIS_FORMAT_DEFAULT , $ Format = null ) { if ( isset ( $ this -> Data [ "Axis" ] [ $ AxisID ] ) ) { $ this -> Data [ "Axis" ] [ $ AxisID ] [ "Display" ] = $ Mode ; if ( $ Format != null ) { $ this -> Data [ "Axis" ] [ $ AxisID ] [ "Format" ] = $ Format ; } } }
Set the display mode of an Axis
45,189
public function setAxisPosition ( $ AxisID , $ Position = AXIS_POSITION_LEFT ) { if ( isset ( $ this -> Data [ "Axis" ] [ $ AxisID ] ) ) { $ this -> Data [ "Axis" ] [ $ AxisID ] [ "Position" ] = $ Position ; } }
Set the position of an Axis
45,190
public function setAxisUnit ( $ AxisID , $ Unit ) { if ( isset ( $ this -> Data [ "Axis" ] [ $ AxisID ] ) ) { $ this -> Data [ "Axis" ] [ $ AxisID ] [ "Unit" ] = $ Unit ; } }
Associate an unit to an axis
45,191
public function setAxisName ( $ AxisID , $ Name ) { if ( isset ( $ this -> Data [ "Axis" ] [ $ AxisID ] ) ) { $ this -> Data [ "Axis" ] [ $ AxisID ] [ "Name" ] = $ Name ; } }
Associate a name to an axis
45,192
public function setAxisColor ( $ AxisID , array $ Format ) { $ R = isset ( $ Format [ "R" ] ) ? $ Format [ "R" ] : 0 ; $ G = isset ( $ Format [ "G" ] ) ? $ Format [ "G" ] : 0 ; $ B = isset ( $ Format [ "B" ] ) ? $ Format [ "B" ] : 0 ; $ Alpha = isset ( $ Format [ "Alpha" ] ) ? $ Format [ "Alpha" ] : 100 ; if ( isset ( $ this -> Data [ "Axis" ] [ $ AxisID ] ) ) { $ this -> Data [ "Axis" ] [ $ AxisID ] [ "Color" ] [ "R" ] = $ R ; $ this -> Data [ "Axis" ] [ $ AxisID ] [ "Color" ] [ "G" ] = $ G ; $ this -> Data [ "Axis" ] [ $ AxisID ] [ "Color" ] [ "B" ] = $ B ; $ this -> Data [ "Axis" ] [ $ AxisID ] [ "Color" ] [ "Alpha" ] = $ Alpha ; } }
Associate a color to an axis
45,193
public function setAxisXY ( $ AxisID , $ Identity = AXIS_Y ) { if ( isset ( $ this -> Data [ "Axis" ] [ $ AxisID ] ) ) { $ this -> Data [ "Axis" ] [ $ AxisID ] [ "Identity" ] = $ Identity ; } }
Design an axis as X or Y member
45,194
public function setSerieOnAxis ( $ Series , $ AxisID ) { if ( ! is_array ( $ Series ) ) { $ Series = $ this -> convertToArray ( $ Series ) ; } foreach ( $ Series as $ Serie ) { $ PreviousAxis = $ this -> Data [ "Series" ] [ $ Serie ] [ "Axis" ] ; if ( ! isset ( $ this -> Data [ "Axis" ] [ $ AxisID ] ) ) { $ this -> Data [ "Axis" ] [ $ AxisID ] [ "Position" ] = AXIS_POSITION_LEFT ; $ this -> Data [ "Axis" ] [ $ AxisID ] [ "Identity" ] = AXIS_Y ; } $ this -> Data [ "Series" ] [ $ Serie ] [ "Axis" ] = $ AxisID ; $ Found = false ; foreach ( $ this -> Data [ "Series" ] as $ Values ) { if ( $ Values [ "Axis" ] == $ PreviousAxis ) { $ Found = true ; } } if ( ! $ Found ) { unset ( $ this -> Data [ "Axis" ] [ $ PreviousAxis ] ) ; } } }
Associate one data serie with one axis
45,195
public function setSerieTicks ( $ Series , $ Width = 0 ) { if ( ! is_array ( $ Series ) ) { $ Series = $ this -> convertToArray ( $ Series ) ; } foreach ( $ Series as $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] ) ) { $ this -> Data [ "Series" ] [ $ Serie ] [ "Ticks" ] = $ Width ; } } }
Define if a serie should be draw with ticks
45,196
public function setSerieWeight ( $ Series , $ Weight = 0 ) { if ( ! is_array ( $ Series ) ) { $ Series = $ this -> convertToArray ( $ Series ) ; } foreach ( $ Series as $ Serie ) { if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] ) ) { $ this -> Data [ "Series" ] [ $ Serie ] [ "Weight" ] = $ Weight ; } } }
Define if a serie should be draw with a special weight
45,197
public function getSeriePalette ( $ Serie ) { if ( ! isset ( $ this -> Data [ "Series" ] [ $ Serie ] ) ) { return null ; } $ Result = [ ] ; $ Result [ "R" ] = $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] [ "R" ] ; $ Result [ "G" ] = $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] [ "G" ] ; $ Result [ "B" ] = $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] [ "B" ] ; $ Result [ "Alpha" ] = $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] [ "Alpha" ] ; return $ Result ; }
Returns the palette of the given serie
45,198
public function setPalette ( $ Series , array $ Format = [ ] ) { if ( ! is_array ( $ Series ) ) { $ Series = $ this -> convertToArray ( $ Series ) ; } foreach ( $ Series as $ Key => $ Serie ) { $ R = isset ( $ Format [ "R" ] ) ? $ Format [ "R" ] : 0 ; $ G = isset ( $ Format [ "G" ] ) ? $ Format [ "G" ] : 0 ; $ B = isset ( $ Format [ "B" ] ) ? $ Format [ "B" ] : 0 ; $ Alpha = isset ( $ Format [ "Alpha" ] ) ? $ Format [ "Alpha" ] : 100 ; if ( isset ( $ this -> Data [ "Series" ] [ $ Serie ] ) ) { $ OldR = $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] [ "R" ] ; $ OldG = $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] [ "G" ] ; $ OldB = $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] [ "B" ] ; $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] [ "R" ] = $ R ; $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] [ "G" ] = $ G ; $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] [ "B" ] = $ B ; $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] [ "Alpha" ] = $ Alpha ; foreach ( $ this -> Palette as $ Key => $ Value ) { if ( $ Value [ "R" ] == $ OldR && $ Value [ "G" ] == $ OldG && $ Value [ "B" ] == $ OldB ) { $ this -> Palette [ $ Key ] [ "R" ] = $ R ; $ this -> Palette [ $ Key ] [ "G" ] = $ G ; $ this -> Palette [ $ Key ] [ "B" ] = $ B ; $ this -> Palette [ $ Key ] [ "Alpha" ] = $ Alpha ; } } } } }
Set the color of one serie
45,199
public function loadPalette ( $ FileName , $ Overwrite = false ) { $ path = file_exists ( $ FileName ) ? $ FileName : sprintf ( '%s/../resources/palettes/%s' , __DIR__ , ltrim ( $ FileName , '/' ) ) ; $ fileHandle = @ fopen ( $ path , "r" ) ; if ( ! $ fileHandle ) { throw new Exception ( sprintf ( 'The requested palette "%s" was not found at path "%s"!' , $ FileName , $ path ) ) ; } if ( $ Overwrite ) { $ this -> Palette = [ ] ; } while ( ! feof ( $ fileHandle ) ) { $ line = fgets ( $ fileHandle , 4096 ) ; if ( false === $ line ) { continue ; } $ row = explode ( ',' , $ line ) ; if ( empty ( $ row ) ) { continue ; } if ( count ( $ row ) !== 4 ) { throw new RuntimeException ( sprintf ( 'A palette row must supply R, G, B and Alpha components, %s given!' , var_export ( $ row , true ) ) ) ; } list ( $ R , $ G , $ B , $ Alpha ) = $ row ; $ ID = count ( $ this -> Palette ) ; $ this -> Palette [ $ ID ] = [ "R" => trim ( $ R ) , "G" => trim ( $ G ) , "B" => trim ( $ B ) , "Alpha" => trim ( $ Alpha ) ] ; } fclose ( $ fileHandle ) ; $ ID = 0 ; if ( isset ( $ this -> Data [ "Series" ] ) ) { foreach ( $ this -> Data [ "Series" ] as $ Key => $ Value ) { if ( ! isset ( $ this -> Palette [ $ ID ] ) ) { $ this -> Data [ "Series" ] [ $ Key ] [ "Color" ] = [ "R" => 0 , "G" => 0 , "B" => 0 , "Alpha" => 0 ] ; } else { $ this -> Data [ "Series" ] [ $ Key ] [ "Color" ] = $ this -> Palette [ $ ID ] ; } $ ID ++ ; } } }
Load a palette file