Skip to content

Commit d3ce44d

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/main' into axis_refactor_v12
2 parents c4173b0 + 717d4ef commit d3ce44d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+580
-260
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
- Enable dimension axis ticks and interlacing.
2828
- Enable measure axis guides.
2929
- Fix dimension axis guides on sorted chart.
30+
- Fix NaN handling on axes and size measures other aggregators than sum.
31+
- Add meaning to crossing interlacing.
32+
- Do not draw dimension axis labels when the middle of the text is off the plot.
33+
34+
### Added
35+
36+
- Add spacing property for plot axis style structure.
3037

3138
### Changed
3239

src/apps/weblib/typeschema-api/styles.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,10 @@ definitions:
452452
interlacing:
453453
$ref: Interlacing
454454
nullable: true
455+
spacing:
456+
type: string
457+
mask: /:number:%/
458+
nullable: true
455459

456460
Plot:
457461
$extends: [Padding, Box]

src/base/conv/auto_json.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct JSON
7575
else if constexpr (std::is_arithmetic_v<T>) {
7676
json += toString(val);
7777
}
78-
else if constexpr (std::is_enum_v<T>
78+
else if constexpr (Refl::is_enum<T>
7979
|| std::is_same_v<T, bool>) {
8080
json += '\"';
8181
json += toString(val);

src/base/conv/parse.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ concept Parsable = !std::is_void_v<decltype(T::fromString(
1616

1717
template <class To>
1818
constexpr inline static bool IsParsable =
19-
std::is_enum_v<To> || Parsable<To>
19+
Refl::is_enum<To> || Parsable<To>
2020
|| (Type::is_optional_v<To> && IsParsable<Type::optional_t<To>>)
2121
|| std::is_constructible_v<To, std::string>
2222
|| std::is_same_v<To, bool> || std::is_floating_point_v<To>
@@ -28,7 +28,7 @@ template <typename To>
2828
requires IsParsable<To>
2929
[[nodiscard]] decltype(auto) parse(const std::string &string)
3030
{
31-
if constexpr (std::is_enum_v<To>)
31+
if constexpr (Refl::is_enum<To>)
3232
return Refl::get_enum<To>(string);
3333
else if constexpr (Parsable<To>)
3434
return To::fromString(string);

src/base/conv/tostring.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ concept ToStringMember =
1919

2020
template <class From>
2121
constexpr inline static bool IsStringifiable =
22-
ToStringMember<From> || std::is_enum_v<From>
22+
ToStringMember<From> || Refl::is_enum<From>
2323
|| (Type::is_optional_v<From>
2424
&& IsStringifiable<Type::optional_t<From>>)
2525
|| std::is_constructible_v<std::string, From>
@@ -32,7 +32,7 @@ template <typename From>
3232
requires IsStringifiable<From>
3333
[[nodiscard]] decltype(auto) toString(const From &value)
3434
{
35-
if constexpr (std::is_enum_v<From>)
35+
if constexpr (Refl::is_enum<From>)
3636
return Refl::enum_name(value);
3737
else if constexpr (Type::is_optional_v<From>) {
3838
using T = std::remove_cvref_t<decltype(toString(*value))>;

src/base/refl/auto_enum.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,16 @@ template <class E> constexpr E get_enum(const std::string_view &data)
193193
return static_cast<E>(ix + first);
194194
}
195195

196+
template <class E>
197+
concept is_enum = std::is_enum_v<E> && Detail::count<E>() > 0;
198+
196199
template <class E> consteval auto enum_values()
197200
{
198201
constexpr auto first = Detail::from_to<E>().first;
199202
constexpr auto n = std::size(enum_names<E>);
200203
std::array<E, n> res{};
201204
for (std::size_t i = 0; i < n; ++i)
205+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
202206
res[i] = static_cast<E>(i + first);
203207
return res;
204208
}
@@ -258,9 +262,8 @@ struct EnumArray : std::array<V, std::size(enum_names<E>)>
258262
bool operator==(const EnumArray &) const = default;
259263
};
260264

261-
template <class E, class... Args>
262-
requires(std::is_enum_v<E>
263-
&& sizeof...(Args) == Detail::count<E>()
265+
template <is_enum E, class... Args>
266+
requires(sizeof...(Args) == Detail::count<E>()
264267
&& Detail::from_to<E>().first == 0)
265268
struct EnumVariant : std::variant<Args...>
266269
{

src/base/type/physicalvalue.h

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
#ifndef TYPE_PHYSICALVALUE
22
#define TYPE_PHYSICALVALUE
33

4-
#include <cstdint>
4+
#include "base/conv/parse.h"
5+
#include "base/conv/tostring.h"
6+
#include "base/refl/auto_enum.h"
7+
#include "base/text/valueunit.h"
58

69
namespace Type
710
{
811

9-
enum class SimpleUnit : std::uint8_t { none, relative, absolute };
10-
11-
template <typename Value, typename Unit = SimpleUnit>
12-
class PhysicalValue
12+
template <typename Value, Refl::is_enum Unit> struct PhysicalValue
1313
{
14-
public:
15-
Value value;
16-
Unit unit;
17-
18-
constexpr PhysicalValue() : value{}, unit{} {}
19-
constexpr PhysicalValue(Value value, Unit unit) :
20-
value(value),
21-
unit(unit)
22-
{}
14+
Value value{};
15+
Unit unit{};
2316

2417
constexpr bool operator==(const PhysicalValue &) const = default;
18+
19+
template <std::same_as<double> = Value>
20+
[[nodiscard]] static PhysicalValue fromString(
21+
const std::string &str)
22+
{
23+
const Text::ValueUnit vu{str};
24+
return {vu.getValue(), Refl::get_enum<Unit>(vu.getUnit())};
25+
}
26+
27+
[[nodiscard]] std::string toString() const
28+
{
29+
return Conv::toString(value)
30+
+ std::string{Conv::toString(unit)};
31+
}
2532
};
2633

2734
}

src/base/type/uniquelist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ template <class T> class UniqueList
237237
struct CommonIterateVal
238238
{
239239
const T &value;
240-
const std::size_t *othIx;
240+
const std::size_t *otherIx;
241241
};
242242

243243
struct common_iterator

src/chart/generator/axis.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <iterator>
88
#include <limits>
99
#include <optional>
10-
#include <set>
1110
#include <string>
1211
#include <string_view>
1312
#include <tuple>
@@ -287,7 +286,9 @@ bool DimensionAxis::setLabels(double step)
287286
auto currStep = 0.0;
288287

289288
for (auto curr = int{}; auto &&item : sortedItems()) {
290-
if (++curr <= currStep) continue;
289+
if (auto mid = item.get().range.middle();
290+
std::signbit(mid) || mid > 1.0 || ++curr <= currStep)
291+
continue;
291292
currStep += step;
292293
item.get().label = true;
293294
hasLabel = true;

src/chart/generator/axis.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct ChannelStats
2929
template <ChannelIdLike T>
3030
[[nodiscard]] const TrackType &at(const T &id) const
3131
{
32-
return tracked[-id];
32+
return tracked[+id];
3333
}
3434

3535
void track(ChannelId at, const Data::MarkerId &id)
@@ -40,13 +40,14 @@ struct ChannelStats
4040

4141
void track(ChannelId at, const double &value)
4242
{
43-
std::get<0>(tracked[at]).include(value);
43+
if (std::isfinite(value))
44+
std::get<0>(tracked[at]).include(value);
4445
}
4546

4647
template <ChannelIdLike Id>
4748
void setIfRange(Id at, const Math::Range<> &range)
4849
{
49-
if (auto *r = std::get_if<0>(&tracked[-at])) *r = range;
50+
if (auto *r = std::get_if<0>(&tracked[+at])) *r = range;
5051
}
5152
};
5253

0 commit comments

Comments
 (0)