* @brief Create a new plot configured with default colours and sizes. * * Allocates a zero-initialized Plot via `calloc` and populates it with * sane defaults so it can be drawn immediately even before any series * is attached: * - title / xLabel / yLabel are deep-copied (NULL becomes the literal * "Untitled Plot" / "X Axis" / "Y Axis"), * - the canvas size is 800x600 pixels, * -
| 295 | * @endcode |
| 296 | */ |
| 297 | Plot* plot_create(const char* title, const char* xLabel, const char* yLabel) { |
| 298 | PLOT_LOG("[plot_create]: enter (title=%s, xLabel=%s, yLabel=%s)", title ? title : "(null)", |
| 299 | xLabel ? xLabel : "(null)", |
| 300 | yLabel ? yLabel : "(null)"); |
| 301 | Plot* plot = (Plot*)calloc(1, sizeof(Plot)); |
| 302 | if (!plot) { |
| 303 | PLOT_LOG("[plot_create]: Allocation failed -> NULL"); |
| 304 | return NULL; |
| 305 | } |
| 306 | |
| 307 | plot->title = p_strdup(title ? title : "Untitled Plot"); |
| 308 | plot->xLabel = p_strdup(xLabel ? xLabel : "X Axis"); |
| 309 | plot->yLabel = p_strdup(yLabel ? yLabel : "Y Axis"); |
| 310 | plot->width = 800; |
| 311 | plot->height = 600; |
| 312 | plot->showLegend = true; |
| 313 | plot->showGrid = true; |
| 314 | plot->bgColor = plot_color(255, 255, 255, 255); |
| 315 | plot->gridColor = plot_color(220, 220, 220, 255); |
| 316 | plot->axisColor = plot_color( 0, 0, 0, 255); |
| 317 | plot->legendBgColor = plot_color(245, 245, 245, 220); |
| 318 | plot->legendTextColor = plot_color( 0, 0, 0, 255); |
| 319 | plot->titleFontSize = 28; |
| 320 | plot->labelFontSize = 20; |
| 321 | plot->seriesCount = 0; |
| 322 | plot->xRangeManual = false; /* axes auto-scale to the data until pinned */ |
| 323 | plot->yRangeManual = false; |
| 324 | |
| 325 | PLOT_LOG("[plot_create]: exit -> %p", (void*)plot); |
| 326 | return plot; |
| 327 | } |
| 328 | |
| 329 | |
| 330 | /** |
no test coverage detected