| 36 | |
| 37 | template<typename T> |
| 38 | fg_chart setup_histogram(fg_window const window, const af_array in, |
| 39 | const double minval, const double maxval, |
| 40 | const af_cell* const props) { |
| 41 | ForgeModule& _ = forgePlugin(); |
| 42 | |
| 43 | const Array<T> histogramInput = getArray<T>(in); |
| 44 | dim_t nBins = histogramInput.elements(); |
| 45 | |
| 46 | // Retrieve Forge Histogram with nBins and array type |
| 47 | ForgeManager& fgMngr = forgeManager(); |
| 48 | |
| 49 | // Get the chart for the current grid position (if any) |
| 50 | fg_chart chart = NULL; |
| 51 | if (props->col > -1 && props->row > -1) { |
| 52 | chart = fgMngr.getChart(window, props->row, props->col, FG_CHART_2D); |
| 53 | } else { |
| 54 | chart = fgMngr.getChart(window, 0, 0, FG_CHART_2D); |
| 55 | } |
| 56 | |
| 57 | // Create a histogram for the chart |
| 58 | fg_histogram hist = fgMngr.getHistogram(chart, nBins, getGLType<T>()); |
| 59 | |
| 60 | // Set histogram bar colors to ArrayFire's orange |
| 61 | FG_CHECK(_.fg_set_histogram_color(hist, 0.929f, 0.486f, 0.2745f, 1.0f)); |
| 62 | |
| 63 | // If chart axes limits do not have a manual override |
| 64 | // then compute and set axes limits |
| 65 | if (!fgMngr.getChartAxesOverride(chart)) { |
| 66 | float xMin, xMax, yMin, yMax, zMin, zMax; |
| 67 | FG_CHECK(_.fg_get_chart_axes_limits(&xMin, &xMax, &yMin, &yMax, &zMin, |
| 68 | &zMax, chart)); |
| 69 | T freqMax = |
| 70 | getScalar<T>(detail::reduce_all<af_max_t, T, T>(histogramInput)); |
| 71 | |
| 72 | // For histogram, xMin and xMax should always be the first |
| 73 | // and last bin respectively and should not be rounded |
| 74 | if (xMin == 0 && xMax == 0 && yMin == 0 && yMax == 0) { |
| 75 | // No previous limits. Set without checking |
| 76 | xMin = static_cast<float>(minval); |
| 77 | xMax = static_cast<float>(maxval); |
| 78 | yMax = static_cast<float>(step_round(freqMax, true)); |
| 79 | // For histogram, always set yMin to 0. |
| 80 | yMin = 0; |
| 81 | } else { |
| 82 | if (xMin > minval) { |
| 83 | xMin = static_cast<float>(minval); |
| 84 | } |
| 85 | if (xMax < maxval) { |
| 86 | xMax = static_cast<float>(maxval); |
| 87 | } |
| 88 | if (yMax < freqMax) { |
| 89 | yMax = static_cast<float>(step_round(freqMax, true)); |
| 90 | } |
| 91 | // For histogram, always set yMin to 0. |
| 92 | yMin = 0; |
| 93 | } |
| 94 | FG_CHECK(_.fg_set_chart_axes_limits(chart, xMin, xMax, yMin, yMax, zMin, |
| 95 | zMax)); |
nothing calls this directly
no test coverage detected