{"id":19863934,"url":"https://github.com/sandialabs/coloring","last_synced_at":"2025-05-02T05:30:31.302Z","repository":{"id":175346340,"uuid":"626754967","full_name":"sandialabs/coloring","owner":"sandialabs","description":"A self-contained C++ plotting library","archived":false,"fork":false,"pushed_at":"2023-06-14T17:07:06.000Z","size":77,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-06T22:38:50.935Z","etag":null,"topics":["cpp","plot","plotting","scr-2894","snl-visualization"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sandialabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-04-12T05:15:01.000Z","updated_at":"2024-02-21T11:20:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"e3d9adcd-0dca-4b31-a998-16664c45f946","html_url":"https://github.com/sandialabs/coloring","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"357ce2e1e64540c4b6f9e524e6ef07c019fd1557"},"previous_names":["sandialabs/coloring"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandialabs%2Fcoloring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandialabs%2Fcoloring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandialabs%2Fcoloring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandialabs%2Fcoloring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sandialabs","download_url":"https://codeload.github.com/sandialabs/coloring/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251992568,"owners_count":21677018,"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","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":["cpp","plot","plotting","scr-2894","snl-visualization"],"created_at":"2024-11-12T15:16:42.102Z","updated_at":"2025-05-02T05:30:30.952Z","avatar_url":"https://github.com/sandialabs.png","language":"C++","readme":"# coloring\n\n`coloring` is a C++ library to do a simple subset of what\nthe popular Python plotting library [matplotlib](https://matplotlib.org/)\ndoes.\nIt does not call `matplotlib`, it does not call `gnuplot`, and it has\nno external dependencies (`lodepng` is built internally, which also builds `zlib`).\n\n`coloring` exists because there are use cases where you want to generate\nnice plots and you prefer not to (or cannot) bring in Python to do it.\n\nBecause of its pure C++ nature, `coloring` should be widely portable and\ncan be used in computing environments with special restrictions where\nPython is not readily available.\n\n## Building\n\n`coloring` tries to be a canonical CMake-built package, and the normal\nway of building things with [CMake](https://cmake.org/) should work.\n\n## Example\n\nThe example executable whose source is found in `example.cpp` and also copied here:\n\n```c++\n#include \"coloring.hpp\"\n\nint main()\n{\n  std::vector\u003cfloat\u003e x = {0.0f, 1.0f, 2.0f, 3.0f};\n  std::vector\u003cfloat\u003e me_y = {0.0f, 1.0f, 1.0f, 2.0f};\n  std::vector\u003cfloat\u003e dog_y = {0.0f, 0.8f, 1.6f, 2.0f};\n  coloring::plot_dataset me_dataset;\n  me_dataset.x = x;\n  me_dataset.y = me_y;\n  coloring::plot_group me_group;\n  me_group.datasets = {me_dataset};\n  me_group.name = \"me\";\n  coloring::plot_dataset dog_dataset;\n  dog_dataset.x = {x};\n  dog_dataset.y = {dog_y};\n  coloring::plot_group dog_group;\n  dog_group.name = \"my dog\";\n  dog_group.datasets = {dog_dataset};\n  coloring::plot_data data;\n  data.groups = {me_group, dog_group};\n  data.xlabel = \"Time (hr)\";\n  data.ylabel = \"Distance (km)\";\n  data.title = \"Hiking Trip\";\n  data.legend_location = coloring::legend_location::upper_left;\n  coloring::plot(\"example.png\", data);\n}\n```\n\nShould generate the PNG file below:\n\n![example picture](example.png)\n\n## How It Works\n\nThe `coloring` library gets its name because it is all based on \"coloring inside the lines\".\nIn particular, the primitive operation in `coloring` is to fill in the pixels that are inside an outline, where the outline can be a mixture of straight lines and quadratic Bezier curves.\nEach pixel is assigned a number between zero and one, which an approximation of how much of that pixel is inside the outline.\n\nThe way that number is assigned is based on bounding circles, and treating the outline as a signed distance function.\nGiven a square in the image, we can compute its bounding circle and ask whether that circle is:\n\n1. fully inside the outline\n2. fully outside the outline\n3. partially inside the outline\n\nIf the bounding circle is only partially inside the outline, we break the square into four smaller squares and ask the question again. This recursion continues until an arbitrary depth (3 levels of recursion) is hit.\nAt that point, we treat any partly-inside squares as half-filled and tally up the total.\n\n`coloring` uses this primitive \"fill in the outline\" operation to draw letters, numbers, lines, and dots onto the screen.\nLetters and numbers are described by a hardcoded font which is [Liberation Mono](https://www.fontsquirrel.com/fonts/liberation-mono).\nThis font data describes each letter, number, and special character as a set of straight lines and quadratic Bezier curves.\nEach character then is translated into one outline and drawn on the screen.\n\nDrawing a \"line\" onto the image actually draws an outline which is like a rectangle capped at both ends with circles (the rounded shape that a ballpoint pen would trace on paper).\nDrawing a \"dot\" actually draws a circle.\n`coloring` then goes one step further and approximates a circle as four quadratic Bezier curves. This is not a great approximation, but the circles are usually only a few pixels across so the error isn't very noticeable.\n\nWith those basic operations we have enough to draw the\nX and Y axes, ticks, tick labels, axis tables, plot title, legend outline,\nlegend entries, and the curves themselves.\n\n`coloring` also uses a system for\nassigning default colors to plot members that is based on a set of 8 colors\nidentified by [Okabe and Ito](https://mikemol.github.io/technique/colorblind/2018/02/11/color-safe-palette.html)\nthat people with various forms of color blindness can still differentiate.\n\nAt Sandia, `coloring` is SCR#2894.0\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandialabs%2Fcoloring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsandialabs%2Fcoloring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandialabs%2Fcoloring/lists"}