Download the PHP package macocci7/php-lorenz-curve without Composer
On this page you can find all versions of the php package macocci7/php-lorenz-curve. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download macocci7/php-lorenz-curve
More information about macocci7/php-lorenz-curve
Files in macocci7/php-lorenz-curve
Package php-lorenz-curve
Short Description A PHP Library to plot a Lorenz Curve.
License MIT
Informations about the package php-lorenz-curve
PHP Lorenz Curve
A PHP Library to draw a Lorenz Curve.
1. Features
PHP-LorenzCurve
draws a Lorenz Curve and also calculates the Gini's coefficient.
2. Contents
- 1. Features
- 2. Contents
- 3. Requirements
- 4. Installation
- 5. Usage
- 5.1. Basic Usage
- 5.2. Adjusting the Appearance
- 5.2.1. Drawing Grid Lines
- 5.2.2. Drawing an Upward Convex Curve
- 5.2.3. Setting the Image Size
- 5.2.4. Setting the Attributes of Plotarea
- 5.2.5. Setting Caption and Labels
- 5.2.6. Setting Attributes with Array
- 5.2.7. Setting Attributes with Neon File
- 5.2.8. Customisable Attributes
- 5.3. Gini's Coefficient
- 6. Examples
- 7. LICENSE
3. Requirements
- PHP 8.1 or later
-
Imagick PHP Extension
Check with commands:
- Composer
4. Installation
5. Usage
5.1. Basic Usage
To draw a Lorenz Curve, create an instance of LorenzCurve
class at first.
Next, set the data, the class range and save the image into a file.
This results in the image below.
5.2. Adjusting the Appearance
5.2.1. Drawing Grid Lines
You can draw grid lines with grid()
method specifying the width and the color.
Note: Specifying
null
as a color code results in transparent.
This results in the image below.
5.2.2. Drawing an Upward Convex Curve
You can create an upward convex Lorenz Curve by sorting the list of the classes in decending order with reverseClasses()
method.
This results in the image below.
5.2.3. Setting the Image Size
PHP-LorenzCurve
generates images with a width of 400
pixels and a height of 300
pixels by default.
You can change the image size with resize()
method.
- format:
resize(int $width, int $height)
This code results in as below:
5.2.4. Setting the Attributes of Plotarea
By default, PHP-LorenzCurve
sets the Attributes of Plotarea
:
offsetX
: 10% of the image widthoffsetY
: 10% of the image heightwidth
: 80% of the image widthheight
: 70% of the image heightbackgroundColor
:null
(transparent)
You can change them with plotarea()
method.
- format:
Sample code:
This code results in as below:
5.2.5. Setting Caption and Labels
You can set the Caption
and Labels
with caption()
, labelX()
and labelY()
methods.
- Format:
Sample code:
This code results in as below:
5.2.6. Setting Attributes with Array
You can set attributes with the config()
method passing array as an argument.
This code results in as below:
See more: Customizable Attributes
5.2.7. Setting Attributes with Neon File
You can set attributes with config()
method passing the neon file path as an argument.
First, create a Neon File.
Second, specify the path of the neon file as an argument of the config()
method.
This code results in as below:
See more: Customizable Attributes
5.2.8. Customisable Attributes
attribute | type | default | example | description |
---|---|---|---|---|
canvasSize['width'] | int | 400 | 450 | image width |
canvasSize['height'] | int | 300 | 400 | image height |
canvasBackgroundColor | string | '#ffffff' | '#0000ff' | background color of the image |
plotarea['offset'] | int[] | 10% of the image size | [40, 50] | offset of the plotarea |
plotarea['width'] | int | 80% of the image size | 500 | plotarea width |
plotarea['height'] | int | 70% of the image size | 400 | plotarea height |
plotarea['backgroundColor'] | string | null |
'#cccccc' | background color of the plotarea |
showGrid | bool | false |
true |
whether to show grid lines |
gridWidth | int | 1 | 2 | grid line width |
gridColor | string | '#cccccc' | '#0099ff' | grid line color |
axisWidth | int | 2 | 3 | axis width |
axisColor | string | '#000000' | '#ffffff' | axis color |
scaleWidth | int | 1 | 2 | scale width |
scaleLength | int | 3 | 6 | scale length |
scaleColor | string | '#000000' | '#ffffff' | scale color |
scaleFontSize | int | 16 | 14 | scale font size |
scaleFontPath | string | 'fonts/ipaexg.ttf' | 'fonts/myfont.ttf' | scale font path |
scaleFontColor | string | '#000000' | '#ffffff' | scale font color |
lorenzCurveWidth | int | 2 | 1 | Lorenz Curve width |
lorenzCurveColor | string | '#0000ff' | '#ffff00' | Lorenz Curve Color |
lorenzCurveBackgroundColor | string | '#ffcc00' | null |
Lorenz Curve background color |
completeEqualityLineWidth | int | 1 | 2 | complete equality line width |
completeEqualityLineColor | string | '#999999' | '#ffffff' | complete equality line color |
completeEqualityLineDash | int[] | [4, 4] | [8, 8] | complete equality line dash pattern (solid and blank) |
fontPath | string | 'fonts/ipaexg.ttf' | 'fonts/myfont.ttf' | font path |
fontSize | int | 16 | 14 | font size |
fontColor | string | '#333333' | '#ffffff' | font color |
labelX | string | '' | 'Cumulative Relative Frequency' | x label |
labelXOffsetX | int | 0 | -10 | x-offset of x label |
labelXOffsetY | int | 0 | 10 | y-offset of x label |
labelY | string | '' | 'Cumulative Relative Subtotal' | y label |
labelYOffsetX | int | 0 | -10 | x-offset of y label |
labelYOffsetY | int | 0 | -10 | y-offset of y label |
caption | string | '' | 'CAPTION' | caption |
captionOffsetX | int | 0 | 10 | x-offset of caption |
captionOffsetY | int | 0 | -10 | y-offset of caption |
5.3. Gini's Coefficient
You can get the Gini's Coefficient with getGinisCoefficient()
method without generating an image.
This results in as below.
6. Examples
-
BasicUsage.php >> results in:
-
DrawGrid.php >> results in:
-
UpwardConvexCurve.php >> results in:
-
ResizeImage.php >> results in:
-
SetPlotareaAttrs.php >> results in:
-
CaptionLabels.php >> results in:
-
ConfigFromArray.php >> results in:
-
ConfigFromFile.neon >> results in:
-
GinisCoefficient.php >> results in:
-
GinisCoefficient0.php >> results in:
▼Gini's Coefficient:
-
GinisCoefficientAlmost1.php >> results in:
▼Gini's Coefficient:
-
GinisCoefficient1.php >> results in:
▼Gini's Coefficient:
7. LICENSE
MIT
Copyright 2024-2025 macocci7.
All versions of php-lorenz-curve with dependencies
nette/neon Version ^3.4
macocci7/php-frequency-table Version ^1.4
macocci7/php-plotter2d Version ^0.3