Skip to content

Commit 717d4ef

Browse files
authored
Merge pull request #618 from vizzuhq/axis_refactor_v11c2
Axis refactor v11f - Add split style parameter for plot.axes
2 parents 3c6b916 + 0b09de3 commit 717d4ef

File tree

29 files changed

+209
-154
lines changed

29 files changed

+209
-154
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
- Add meaning to crossing interlacing.
3232
- Do not draw dimension axis labels when the middle of the text is off the plot.
3333

34+
### Added
35+
36+
- Add spacing property for plot axis style structure.
37+
3438
## [0.15.0] - 2024-10-28
3539

3640
### Fixed

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/chart/generator/axis.cpp

Lines changed: 0 additions & 1 deletion
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>

src/chart/generator/axis.h

Lines changed: 2 additions & 2 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)
@@ -47,7 +47,7 @@ struct ChannelStats
4747
template <ChannelIdLike Id>
4848
void setIfRange(Id at, const Math::Range<> &range)
4949
{
50-
if (auto *r = std::get_if<0>(&tracked[-at])) *r = range;
50+
if (auto *r = std::get_if<0>(&tracked[+at])) *r = range;
5151
}
5252
};
5353

src/chart/generator/marker.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "marker.h"
22

3+
#include <cmath>
34
#include <cstdint>
45
#include <optional>
56
#include <utility>
@@ -31,10 +32,10 @@ Marker::Marker(const Options &options,
3132
bool needMarkerInfo) :
3233
cellInfo(data.cellInfo(index, needMarkerInfo)),
3334
mainId(data.getId(mainAxisList,
34-
options.dimLabelIndex(-options.mainAxisType()),
35+
options.dimLabelIndex(+options.mainAxisType()),
3536
index)),
3637
subId(data.getId(subAxisList,
37-
options.dimLabelIndex(-options.subAxisType()),
38+
options.dimLabelIndex(+options.subAxisType()),
3839
index)),
3940
sizeId(data.getId(
4041
options.getChannels().at(ChannelId::size).dimensions(),
@@ -76,7 +77,7 @@ Marker::Marker(const Options &options,
7677
if (subAxisList != options.subAxis().dimensions())
7778
subId.label =
7879
data.getId(options.subAxis().dimensions(),
79-
options.dimLabelIndex(-options.subAxisType()),
80+
options.dimLabelIndex(+options.subAxisType()),
8081
index)
8182
.label;
8283

@@ -223,14 +224,14 @@ void Marker::fromRectangle(const Geom::Rect &rect)
223224

224225
Math::Range<> Marker::getSizeBy(AxisId axisId) const
225226
{
226-
return isHorizontal(+axisId) ? toRectangle().hSize()
227-
: toRectangle().vSize();
227+
return isHorizontal(orientation(axisId)) ? toRectangle().hSize()
228+
: toRectangle().vSize();
228229
}
229230

230231
void Marker::setSizeBy(AxisId axisId, const Math::Range<> range)
231232
{
232233
auto rect = toRectangle();
233-
if (isHorizontal(+axisId))
234+
if (isHorizontal(orientation(axisId)))
234235
rect.setHSize(range);
235236
else
236237
rect.setVSize(range);

0 commit comments

Comments
 (0)