Skip to content

Commit

Permalink
Add document bracketing
Browse files Browse the repository at this point in the history
Also, clamp all ruler values to integers on the rulers
  • Loading branch information
Blake-Madden committed Jun 15, 2023
1 parent b777965 commit f9cc35c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 6 deletions.
78 changes: 72 additions & 6 deletions src/graphs/fleschchart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace Wisteria::Graphs

// syllables per 100 words ruler
{
Axis syllableRuler(Wisteria::AxisType::LeftYAxis);
Axis syllableRuler(Wisteria::AxisType::RightYAxis);
syllableRuler.SetCustomXPosition(3.5f);
syllableRuler.SetCustomYPosition(100);
syllableRuler.SetRange(120, 200, 0, 5, 1);
Expand Down Expand Up @@ -180,6 +180,72 @@ namespace Wisteria::Graphs
jitterPoints.insert(std::clamp<double>(syllablesPerWord*100, 120, 200));
}
m_jitterSyllables.CalcSpread(jitterPoints);

if (IsIncludingSyllableRulerDocumentGroups() &&
data->HasValidIdData() && // needed for labels
data->GetRowCount() > 1 &&
data->GetRowCount() <= 50)
{
struct rulerBucket
{
double m_start{ 0 };
double m_end{ 0 };
wxString m_label;
};
rulerBucket bucket1{ 120.0, 139.0, wxString{} };
rulerBucket bucket2{ 140.0, 159.0, wxString{} };
rulerBucket bucket3{ 160.0, 179.0, wxString{} };
rulerBucket bucket4{ 180.0, 200.0, wxString{} };

for (size_t i = 0; i < GetDataset()->GetRowCount(); ++i)
{
if (std::isnan(m_syllablesPerWordColumn->GetValue(i)))
{ continue; }
const auto currentValue{
std::clamp<size_t>(m_syllablesPerWordColumn->GetValue(i) * 100, 120, 200)
};

if (currentValue >= bucket1.m_start && currentValue <= bucket1.m_end)
{
bucket1.m_label.append(GetDataset()->GetIdColumn().GetValue(i)).
append(L'\n');
}
else if (currentValue >= bucket2.m_start && currentValue <= bucket2.m_end)
{
bucket2.m_label.append(GetDataset()->GetIdColumn().GetValue(i)).
append(L'\n');
}
else if (currentValue >= bucket3.m_start && currentValue <= bucket3.m_end)
{
bucket3.m_label.append(GetDataset()->GetIdColumn().GetValue(i)).
append(L'\n');
}
else if (currentValue >= bucket4.m_start && currentValue <= bucket4.m_end)
{
bucket4.m_label.append(GetDataset()->GetIdColumn().GetValue(i)).
append(L'\n');
}
}
bucket1.m_label.Trim();
bucket2.m_label.Trim();
bucket3.m_label.Trim();
bucket4.m_label.Trim();

auto& syllableRuler{ GetCustomAxes()[2] };
syllableRuler.MirrorBracketsWhenDoubleSided(false);
syllableRuler.AddBracket(Axis::AxisBracket(bucket1.m_start, bucket1.m_end,
bucket1.m_start + ((bucket1.m_end - bucket1.m_start) * math_constants::half),
bucket1.m_label));
syllableRuler.AddBracket(Axis::AxisBracket(bucket2.m_start, bucket2.m_end,
bucket2.m_start + ((bucket2.m_end - bucket2.m_start) * math_constants::half),
bucket2.m_label));
syllableRuler.AddBracket(Axis::AxisBracket(bucket3.m_start, bucket3.m_end,
bucket3.m_start + ((bucket3.m_end - bucket3.m_start) * math_constants::half),
bucket3.m_label));
syllableRuler.AddBracket(Axis::AxisBracket(bucket4.m_start, bucket4.m_end,
bucket4.m_start + ((bucket4.m_end - bucket4.m_start) * math_constants::half),
bucket4.m_label));
}
}
}

Expand Down Expand Up @@ -220,13 +286,13 @@ namespace Wisteria::Graphs
{ return; }

// plot the points
const auto wordsRuler{ GetCustomAxes()[0] };
const auto& wordsRuler{ GetCustomAxes()[0] };
m_jitterWords.SetJitterWidth(wordsRuler.CalcTickMarkOuterWidth()*2);

const auto middleRuler{ GetCustomAxes()[1] };
const auto& middleRuler{ GetCustomAxes()[1] };
m_jitterScores.SetJitterWidth(middleRuler.CalcTickMarkOuterWidth()*2);

const auto syllablesRuler{ GetCustomAxes()[2] };
const auto& syllablesRuler{ GetCustomAxes()[2] };
m_jitterSyllables.SetJitterWidth(syllablesRuler.CalcTickMarkOuterWidth()*2);

auto points = std::make_shared<GraphItems::Points2D>(wxNullPen);
Expand All @@ -241,11 +307,11 @@ namespace Wisteria::Graphs
{ continue; }

const auto wordsPerSentence =
std::clamp<double>(m_wordsPerSentenceColumn->GetValue(i), 5, 40);
std::clamp<size_t>(m_wordsPerSentenceColumn->GetValue(i), 5, 40);
const auto score =
std::clamp<size_t>(m_scoresColumn->GetValue(i), 0, 100);
const auto syllablesPerWord =
std::clamp<double>(m_syllablesPerWordColumn->GetValue(i)*100, 120, 200);
std::clamp<size_t>(m_syllablesPerWordColumn->GetValue(i)*100, 120, 200);

wxCoord coord1{ 0 }, coord2{ 0 }, coord3{ 0 };
wxASSERT_LEVEL_2(wordsRuler.GetPhysicalCoordinate(wordsPerSentence, coord1));
Expand Down
13 changes: 13 additions & 0 deletions src/graphs/fleschchart.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ namespace Wisteria::Graphs
[[nodiscard]]
bool IsShowingConnectionLine() const noexcept
{ return m_showConnectionLine; }

/** @brief Sets whether to include brackets along the syllables-per-word ruler,
showing the document names under each bracket.
@details This will only be applied if there are 1-50 documents on the
graph, and the document names must be in the dataset's ID column.
@param include Whether to enable this feature.*/
void IncludeSyllableRulerDocumentGroups(const bool include) noexcept
{ m_includeSyllaleRulerDocumentGroups = include; }
/// @returns @c true if document brackets will be shown along the right-side ruler.
[[nodiscard]]
bool IsIncludingSyllableRulerDocumentGroups() const noexcept
{ return m_includeSyllaleRulerDocumentGroups; }
private:
void RecalcSizes(wxDC& dc) final;

Expand All @@ -95,6 +107,7 @@ namespace Wisteria::Graphs
Wisteria::Data::Jitter m_jitterScores{ Wisteria::AxisType::LeftYAxis };
Wisteria::Data::Jitter m_jitterSyllables{ Wisteria::AxisType::LeftYAxis };
bool m_showConnectionLine{ true };
bool m_includeSyllaleRulerDocumentGroups{ false };
};
}

Expand Down

0 comments on commit f9cc35c

Please sign in to comment.