From fb23c8d47f6dcef429423256d8dddcc0f7184fc4 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Sun, 4 Jun 2023 13:02:14 +0200 Subject: Further advances in nuklear port. Rendering now looks similar to Qt version, needs a few tweaks: * Proper multisampling * Background Missing features: * Barcharts * Interactivity (e.g. brushing/linking in all objects) * History view of interactions --- continuouscolorscale.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'continuouscolorscale.cpp') diff --git a/continuouscolorscale.cpp b/continuouscolorscale.cpp index c729c6b..b7f2c93 100644 --- a/continuouscolorscale.cpp +++ b/continuouscolorscale.cpp @@ -9,8 +9,12 @@ ContinuousColorScale::ContinuousColorScale(std::initializer_list colors) QColor ContinuousColorScale::color(float t) const { - if (t < m_min || t > m_max) { - return Color(); + if (t <= m_min) { + return m_colors.front(); + } + + if (t >= m_max) { + return m_colors.back(); } // normalize t @@ -18,14 +22,10 @@ QColor ContinuousColorScale::color(float t) const // find which colors in the scale are adjacent to ours float step = 1.0 / m_colors.size(); - int i = static_cast(t / step); - - if (i >= m_colors.size() - 1) { - return m_colors.back(); - } + size_t i = static_cast(t * m_colors.size()); // normalize t between the two colors - int j = i + 1; + size_t j = i + 1; t = (t - i*step) / (j*step - i*step); return m_colors[i + round(t)]; } -- cgit v1.2.3