* @brief Replace a series' x/y data while keeping its label, color, type. * * Allocates fresh internal buffers, deep-copies @p xData (if non-NULL) * and @p yData into them, frees the series' previous buffers, and * installs the new ones in place. The series' label, colour, and * drawing style are preserved — only the data and its length change. * * Use this for animated / "live" plots where
| 561 | PLOT_LOG("[plot_add_series]: OOM yCopy -> -1"); |
| 562 | free(xCopy); |
| 563 | |
| 564 | return -1; |
| 565 | } |
| 566 | memcpy(yCopy, yData, sizeof(float) * dataSize); |
| 567 | |
| 568 | char* labelCopy = NULL; |
| 569 | if (label) { |
| 570 | labelCopy = p_strdup(label); |
| 571 | if (!labelCopy) { |
| 572 | PLOT_LOG("[plot_add_series]: OOM labelCopy -> -1"); |
| 573 | free(xCopy); |
| 574 | free(yCopy); |
| 575 | |
| 576 | return -1; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | size_t idx = plot->seriesCount++; |
| 581 | plot->series[idx].xData = xCopy; |
| 582 | plot->series[idx].yData = yCopy; |
| 583 | plot->series[idx].dataSize = dataSize; |
| 584 | plot->series[idx].label = labelCopy; |
| 585 | plot->series[idx].color = color; |
| 586 | plot->series[idx].pltype = pltype; |
| 587 | |
| 588 | PLOT_LOG("[plot_add_series]: exit -> index=%d (%s)", (int)idx, label ? label : "(no label)"); |
| 589 | return (int)idx; |
| 590 | } |
| 591 | |
| 592 | |
| 593 | /** |
| 594 | * @brief Remove the series at @p seriesIndex, shifting later series left. |
| 595 | * |
| 596 | * Frees the targeted series' xData, yData, and label buffers, then |
| 597 | * compacts the series table so that any series that were stored at a |
| 598 | * higher index get shifted down by one. The plot's seriesCount is |
| 599 | * decremented to reflect the removal. |
| 600 | * |
| 601 | * @param plot Target plot. Must be non-NULL. |
nothing calls this directly
no outgoing calls
no test coverage detected