{"id":24540665,"url":"https://github.com/mistralys/column-widths-calculator","last_synced_at":"2026-02-24T09:25:41.719Z","repository":{"id":57017654,"uuid":"277576930","full_name":"Mistralys/column-widths-calculator","owner":"Mistralys","description":"Column widths calculator","archived":false,"fork":false,"pushed_at":"2022-06-09T14:11:33.000Z","size":46,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-14T19:05:06.925Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mistralys.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-06T15:17:03.000Z","updated_at":"2022-06-09T14:10:00.000Z","dependencies_parsed_at":"2022-08-22T12:00:21.752Z","dependency_job_id":null,"html_url":"https://github.com/Mistralys/column-widths-calculator","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/Mistralys/column-widths-calculator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fcolumn-widths-calculator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fcolumn-widths-calculator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fcolumn-widths-calculator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fcolumn-widths-calculator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mistralys","download_url":"https://codeload.github.com/Mistralys/column-widths-calculator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fcolumn-widths-calculator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279020641,"owners_count":26086895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-22T18:14:37.099Z","updated_at":"2025-10-14T19:08:14.158Z","avatar_url":"https://github.com/Mistralys.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/Mistralys/column-widths-calculator.svg?branch=master)](https://travis-ci.com/Mistralys/column-widths-calculator)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Mistralys/column-widths-calculator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Mistralys/column-widths-calculator/?branch=master)\n\n# Column widths calculator\n\nSmall utility that can be used to convert arbitrary numeric values to column widths. Given a list of column names and values, it will intelligently convert the values to percentages, and fill empty columns with meaningful values.\n\n**Features:**\n\n  - Fills empty values with meaningful values\n  - Converts any values to percentages, using proportional calculations\n  - Ensures that the total always matches 100% exactly\n\n## Installation\n\nUsing composer, simply require the package.\n\nVia command line:\n\n```\ncomposer require mistralys/column-widths-calculator\n```\n\nVia composer.json:\n\n```\n\"require\" : \n{\n    \"mistralys/column-widths-calculator\": \"^1.0\"\n}\n```\n\n## Usage\n\nUse the factory method to instantiate the calculator:\n\n```php\n\n$columns = array(\n    'Col1' =\u003e 20,\n    'Col2' =\u003e 0,\n    'Col3' =\u003e 40\n);\n\n$calc =  Calculator::create($columns);\n\n$converted = $calc-\u003egetValues();\n```\n\nThis will return an array with the same keys, and the missing column value filled out:\n\n```php\narray(\n    'Col1' =\u003e 20,\n    'Col2' =\u003e 40,\n    'Col3' =\u003e 40\n);\n```\n\n## Switching between integers and floats\n\nBy default, the calculator will produce integer values, even if all internal calculations are float based for precision. This can be turned off to retrieve float values:\n\n```php\n$calc = Calculator::create($columns);\n$calc-\u003esetFloatValues();\n```\n\nIn this case, no rounding is done at all - you will have to manually handle any rounding you wish to apply.\n\n## Handling minimum widths\n\nWhen leaving columns empty to be automatically filled, there may not be enough width left for the columns to fill. Consider this configuration of columns:\n\n```\nCol1 = 80\nCol2 = 20\nCol3 = 0\n```\n\nBy default, the calculator will guarantee that every column has a minimum width of `1`. As a result, the list would be adjusted like this, to allow the third column to have a width:\n\n```\nCol1 = 79\nCol2 = 20\nCol3 = 1\n```\n\nThe surplus is subtracted from all non-empty columns, proportionally to their size (without going below the minimum width). \n\n### Setting the minimum size\n\nThe minimum size can be set like this:\n\n```php\n$calc = Calculator::create($columns);\n$calc-\u003esetMinWidth(20);\n```\n\nThis will ensure that all columns have a minimum size of 20%. \n\nExample:\n \n```\nCol1 = 80\nCol2 = 20\nCol3 = 0\n```\n\nWould give the following result:\n\n```\nCol1 = 60\nCol2 = 20\nCol3 = 20\n```\n \nNOTE: The maximum possible value for the minimum size depends on the amount of columns. Trying to set the minimum size to 40% for 3 columns for example, will throw an exception (40 x 3 is bigger than 100).\n\n\n## Arbitrary numbering\n\nThe calculator can work with any number system, and converts the values proportionally.\n\nConsider the following values:\n\n```\nCol1 = 1400\nCol2 = 900\nCol3 = 700\n```\n\nThis will be converted to the following values:\n\n```\nCol1 = 38\nCol2 = 33\nCol3 = 30\n\n= 100%\n```\n\n### Missing values\n\nAs long as there are more than one column with values, missing values will be filled with a value based on an average of the existing values, to get realistic results.\n\nFor example, the values:\n\n```\nCol1 = 1400\nCol2 = 900\nCol3 = 0\nCol4 = 0 \n```\n\nWill be converted to this:\n\n```\nCol1 = 30\nCol2 = 19\nCol3 = 25\nCol4 = 26\n\n= 100%\n```\n\n## Changing the target value\n\nBy default, the Calculator assumes you want to work with percentages, and has the target value locked to 100. However, it is possible to adjust this value:\n\n```php\n$calc = Calculator::create($columns);\n$calc-\u003esetMaxTotal(1000);\n```\n\nIn the example above, the column widths will be calculated to reach a total of 1000, instead of the default 100.\n\n## Converting to absolute pixel values\n\nFor convenience, the `getPixelValues()` method can convert the column percentages to absolute pixel values, given the maximum target width.\n\nThe following example converts the column widths to reach a width of 600px:\n\n```php\n$cols = array(\n    'Col1' =\u003e 40,\n    'Col2' =\u003e 40,\n    'Col3' =\u003e 20\n);\n\n$calc = Calculator::create($columns);\n\n$pixelWidths = $calc-\u003egetPixelValues(600);\n```\n\nThe resulting widths will be:\n\n```\nCol1 = 207\nCol2 = 207\nCol3 = 186\n\n= 600\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmistralys%2Fcolumn-widths-calculator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmistralys%2Fcolumn-widths-calculator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmistralys%2Fcolumn-widths-calculator/lists"}