Skip to content

Commit

Permalink
Brings default line style in line with my recent papers.
Browse files Browse the repository at this point in the history
  • Loading branch information
pazmivaniye committed Jun 16, 2024
1 parent b3f9334 commit e2fb07d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 19 deletions.
52 changes: 40 additions & 12 deletions axis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,30 @@ static const std::string Suffix = "_plot_data";

static std::string convert_marker(char marker)
{
if(!marker)
if(marker <= 0)
{
return "none";
throw std::runtime_error("Tried to convert unprintable marker.");
}
if(marker == '^')
{
return "triangle";
}
if(marker == '.')
{
return "*, mark options = {scale = 0.5}";
}
if(marker == 's')
{
return "square";
}
if(marker == 'S')
{
return "square*";
}
if(marker == 'd')
{
return "square, mark options = {rotate = 45, scale = 0.6}";
}
if(marker == 'D')
{
return "square*, mark options = {rotate = 45, scale = 0.6}";
}
return std::string() + marker;
}

Expand Down Expand Up @@ -457,8 +465,7 @@ void pgfplotter::Axis::draw(const DrawStyle& style, const std::vector<double>&
vector<double>& w, const std::string& name)
{
data.push_back({x, y, z, w});
markers.emplace_back(convert_marker(style.markStyle.mark), style.markStyle.
size, style.markStyle.spacing);
markers.push_back(style.markStyle);
names.push_back(name);
colors.push_back(style.color);
lineStyles.push_back(style.lineStyle);
Expand Down Expand Up @@ -1133,7 +1140,6 @@ std::string pgfplotter::Axis::plot_src(const std::string& path, int subplot) con
}

const bool hasLines = lineStyles[i] != LineStyle::None;
const bool hasMarks = std::get<0>(markers[i]) != "none";

src += is3D ? "\\addplot3+[" : "\\addplot+[";
if(lineStyles[i] == LineStyle::Dashed)
Expand All @@ -1148,8 +1154,30 @@ std::string pgfplotter::Axis::plot_src(const std::string& path, int subplot) con
{
src += "only marks, ";
}
src += "mark = " + std::get<0>(markers[i]) + ", mark size = " +
ToString(3.*std::get<1>(markers[i]));
if(markers[i].mark > 0)
{
src += "mark = " + convert_marker(markers[i].mark) + ", mark size ="
" " + ToString(3.*markers[i].size);
if(markers[i].spacing)
{
src += ", mark repeat = " + std::to_string(markers[i].spacing);
}
}
else if(markers[i].mark < 0)
{
const std::size_t idx = i%DefaultMarks.size();
src += "mark = " + convert_marker(DefaultMarks[idx].mark) + ", mark"
" size = " + ToString(3.*DefaultMarks[idx].size*markers[i].
size);
if(markers[i].spacing)
{
src += ", mark repeat = " + std::to_string(markers[i].spacing);
}
}
else
{
src += "mark = none";
}
if(colors[i][0] >= 0)
{
src += ", rgb color = {" + std::to_string(colors[i][0]) + ", " +
Expand All @@ -1162,7 +1190,7 @@ std::string pgfplotter::Axis::plot_src(const std::string& path, int subplot) con
{
src += ", mesh, point meta = explicit, shader = interp";
}
if(hasMarks)
if(markers[i].mark)
{
src += ", scatter, scatter src = explicit, scatter/use mapped c"
"olor = {draw = mapped color, fill = mapped color}";
Expand Down
25 changes: 18 additions & 7 deletions pgfplotter
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,29 @@ namespace pgfplotter
char mark;
double size;
int spacing;
static constexpr MarkStyle Default()
static constexpr MarkStyle Point()
{
return {'.', 1., 1};
return {'*', 0.5, 1};
}
static constexpr MarkStyle None()
{
return {};
}
static constexpr MarkStyle Auto()
{
return {-1, 0., 0};
return {-1, 1., 0};
}
};

static constexpr std::array<MarkStyle, 5> DefaultMarks =
{{
{'S', 2./3., 0},
{'*', 2./3., 0},
{'D', 2./3., 0},
{'|', 2./3., 0},
MarkStyle::None()
}};

struct DrawStyle
{
std::array<int, 3> color;
Expand All @@ -87,10 +96,12 @@ namespace pgfplotter
double lineWidth;
double opacity;
};
static constexpr DrawStyle DefaultLine = {Color::Auto, MarkStyle::None(),
static constexpr DrawStyle BasicLine = {Color::Auto, MarkStyle::None(),
LineStyle::Solid, 1., 1.};
static constexpr DrawStyle BasicScatter = {Color::Auto, MarkStyle::Point(),
LineStyle::None, 1., 1.};
static constexpr DrawStyle Default = {Color::Auto, MarkStyle::Auto(),
LineStyle::Solid, 1., 1.};
static constexpr DrawStyle DefaultScatter = {Color::Auto, MarkStyle::
Default(), LineStyle::None, 1., 1.};

class Axis
{
Expand All @@ -108,7 +119,7 @@ namespace pgfplotter
std::vector<bool> matrixSurf;
std::vector<unsigned int> numContours;
std::vector<std::string> names;
std::vector<std::tuple<std::string, double, int>> markers;
std::vector<MarkStyle> markers;
std::vector<std::array<int, 3>> colors;
std::vector<LineStyle> lineStyles;
std::vector<double> lineWidths;
Expand Down

0 comments on commit e2fb07d

Please sign in to comment.