Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change mask color for nan/inf values to light grey for contour plots #180

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/wex/plot/plcolourmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "wex/plot/plplot.h"

#define wxCONTOUR_BG wxStockGDI::GetColour(wxStockGDI::COLOUR_LIGHTGREY)

class wxPLColourMap : public wxPLSideWidgetBase {
public:
wxPLColourMap(double min = 0, double max = 1);
Expand Down
2 changes: 1 addition & 1 deletion src/plot/plcolourmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void wxPLColourMap::Render(wxPLOutputDevice &dc, const wxPLRealRect &geom) {
}

wxColour wxPLColourMap::ColourForValue(double val) {
if (m_colourList.size() == 0 || !(wxFinite(val))) return *wxBLACK;
if (m_colourList.size() == 0 || !(wxFinite(val))) return *wxCONTOUR_BG;

int position =
(int) (((double) m_colourList.size()) * (
Expand Down
22 changes: 17 additions & 5 deletions src/plot/plcontourplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,20 @@ void wxPLContourPlot::RebuildContours() {
}
}
} else {
for (size_t k = 0; k < m_levels.size() - 1; k++) {
double zlow = m_levels[k];
double zhigh = m_levels[k + 1];
for (size_t k = 0; k < m_levels.size(); k++) {
double zlow = 0;
double zhigh = 0;
if (k == 0) {
zlow = m_levels[k] - (m_levels[1] - m_levels[0]);
zhigh = m_levels[k];
}
else {
zlow = m_levels[k-1];
zhigh = m_levels[k];
}

//double zlow = m_levels[k];
//double zhigh = m_levels[k + 1];

std::vector<QuadContourGenerator::VertexCodes *> list;
qcg.create_filled_contour(zlow, zhigh, list);
Expand Down Expand Up @@ -250,16 +261,17 @@ void wxPLContourPlot::Draw(wxPLOutputDevice &dc, const wxPLDeviceMapping &map) {
dc.NoPen();
// background set to min
// assume RebuildMask has been called
wxColor bgc(m_cmap->ColourForValue(m_zMin));
//wxColor bgc(m_cmap->ColourForValue(m_zMin));
wxColor bgc(*wxCONTOUR_BG);
dc.Brush(bgc);
wxRealPoint pos, size;
map.GetDeviceExtents(&pos, &size);
dc.Rect(pos.x, pos.y, size.x, size.y);
// end background

// int ipoly = 0;
for (size_t i = 0; i < m_cPolys.size(); i++) {
double zmid = 0.5 * (m_cPolys[i].z + m_cPolys[i].zmax);
//double zmid = m_cPolys[i].z;
wxColour color(m_cmap->ColourForValue(zmid));
dc.Pen(color, 2);
dc.Brush(color);
Expand Down