Skip to content

Commit 3145013

Browse files
committed
Merge branch 'main' into axis_refactor_v12
# Conflicts: # CHANGELOG.md
2 parents 03938b8 + af94f9f commit 3145013

File tree

23 files changed

+133
-181
lines changed

23 files changed

+133
-181
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## [Unreleased]
44

5+
### Fixed
6+
7+
- Fix invalid read/write when animation is contiguous (onFinish callback calls setKeyframe).
8+
- Waterfall chart preset not aligned.
9+
- Split chart count negative values too.
10+
511
### Changed
612

713
- Separate Channel properties to AxisChannel properties at config.

docs/assets/javascripts/mdchart.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ class MdChart {
77
this.id = id
88
}
99

10+
async createFromConfig(snippets) {
11+
this.create(await loadAnimations(snippets))
12+
}
13+
1014
async create(snippets) {
11-
const animations = await loadAnimations(snippets)
1215
let chart = Promise.resolve()
13-
for (let i = 0; i < animations.length; i++) {
16+
for (let i = 0; i < snippets.length; i++) {
1417
const number = i + 1
15-
chart = this.animate(('0' + number).slice(-2), animations[i], chart)
18+
chart = this.animate(('0' + number).slice(-2), snippets[i], chart)
1619
}
1720
}
1821

docs/tutorial/assets/snippet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ Promise.all([mdChartLoaded, dataLoaded, configLoaded]).then((results) => {
1212
const config = results[2].default
1313
const MdChart = results[0].default
1414
const mdchart = new MdChart(data, 'tutorial')
15-
mdchart.create(config)
15+
mdchart.createFromConfig(config)
1616
})

src/apps/weblib/interface.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,25 +267,25 @@ void Interface::setAnimControlValue(ObjectRegistryHandle chart,
267267
const char *value)
268268
{
269269
auto &&chartPtr = getChart(chart);
270-
auto &ctrl = chartPtr->getAnimControl();
270+
auto &&ctrl = chartPtr->getAnimControl();
271271

272-
if (path == "seek") { ctrl.seek(value); }
272+
if (path == "seek") { ctrl->seek(value); }
273273
else if (path == "cancel") {
274-
ctrl.cancel();
274+
ctrl->cancel();
275275
}
276276
else if (path == "stop") {
277-
ctrl.stop();
277+
ctrl->stop();
278278
}
279279
else if (auto &&set_accessor =
280280
Refl::Access::getAccessor<::Anim::Control::Option>(
281281
path)
282282
.set) {
283-
set_accessor(ctrl.getOptions(), value);
283+
set_accessor(ctrl->getOptions(), value);
284284
}
285285
else {
286286
throw std::logic_error("invalid animation command");
287287
}
288-
ctrl.update();
288+
ctrl->update();
289289
}
290290

291291
const char *Interface::getAnimControlValue(ObjectRegistryHandle chart,
@@ -294,12 +294,12 @@ const char *Interface::getAnimControlValue(ObjectRegistryHandle chart,
294294
thread_local std::string res;
295295

296296
auto &&chartPtr = getChart(chart);
297-
auto &ctrl = chartPtr->getAnimControl();
297+
auto &&ctrl = chartPtr->getAnimControl();
298298

299299
if (auto &&get_accessor =
300300
Refl::Access::getAccessor<::Anim::Control::Option>(path)
301301
.get) {
302-
res = get_accessor(ctrl.getOptions());
302+
res = get_accessor(ctrl->getOptions());
303303
}
304304
else
305305
throw std::logic_error("invalid animation command");
@@ -396,7 +396,7 @@ void Interface::update(ObjectRegistryHandle chart, double timeInMSecs)
396396
std::chrono::duration_cast<std::chrono::nanoseconds>(
397397
std::chrono::duration<double, std::milli>{timeInMSecs});
398398

399-
widget->getChart().getAnimControl().update(
399+
widget->getChart().getAnimControl()->update(
400400
::Anim::TimePoint{nanoSecs});
401401
}
402402

src/apps/weblib/ts-api/plugins/presetconfigs.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ export const presetConfigs = {
4646
y: { set: [{ name: 'y' }, { name: 'x' }] },
4747
label: { set: [{ name: 'y' }] },
4848
color: { set: [{ name: 'y' }] }
49-
},
50-
align: 'stretch'
49+
}
5150
},
5251
mekko: {
5352
channels: {

src/base/geom/rect.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ struct Rect
9191

9292
void setHSize(const Math::Range<> &range)
9393
{
94-
setLeft(range.getMin());
95-
setRight(range.getMax());
94+
setLeft(range.min);
95+
setRight(range.max);
9696
}
9797

9898
void setVSize(const Math::Range<> &range)
9999
{
100-
setBottom(range.getMin());
101-
setTop(range.getMax());
100+
setBottom(range.min);
101+
setTop(range.max);
102102
}
103103

104104
[[nodiscard]] Rect bottomHalf() const

src/base/math/range.h

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,6 @@ template <std::floating_point T = double> struct Range
2121
constexpr static auto less = Floating::less;
2222
constexpr static auto is_zero = Floating::is_zero;
2323

24-
constexpr static Range<T> Raw(const T &min, const T &max)
25-
{
26-
Range<T> range;
27-
range.min = min;
28-
range.max = max;
29-
return range;
30-
}
31-
32-
constexpr Range() :
33-
min(std::numeric_limits<T>::max()),
34-
max(std::numeric_limits<T>::lowest())
35-
{}
36-
37-
Range(const T &x, const T &y) :
38-
min(std::min(x, y, less)),
39-
max(std::max(x, y, less))
40-
{}
41-
4224
[[nodiscard]] bool isReal() const
4325
{
4426
return min != std::numeric_limits<T>::max()
@@ -52,7 +34,7 @@ template <std::floating_point T = double> struct Range
5234
min = std::min(min, value, less);
5335
}
5436

55-
void include(const Range<T> &range)
37+
void include(const Range &range)
5638
{
5739
include(range.min);
5840
include(range.max);
@@ -63,7 +45,7 @@ template <std::floating_point T = double> struct Range
6345
return !less(value, min) && !less(max, value);
6446
}
6547

66-
[[nodiscard]] bool includes(const Range<T> &range) const
48+
[[nodiscard]] bool includes(const Range &range) const
6749
{
6850
return !less(range.max, min) && !less(max, range.min);
6951
}
@@ -79,57 +61,57 @@ template <std::floating_point T = double> struct Range
7961
return value * size() + min;
8062
}
8163

82-
[[nodiscard]] Range<T> scale(const Range<T> &range) const
64+
[[nodiscard]] Range scale(const Range &range) const
8365
{
84-
return Range<T>(scale(range.min), scale(range.max));
66+
return {scale(range.min), scale(range.max)};
8567
}
8668

8769
[[nodiscard]] T normalize(const T &value) const
8870
{
8971
return is_zero(max) ? 0 : value / max;
9072
}
9173

92-
[[nodiscard]] Range<T> normalize(const Range<T> &range) const
74+
[[nodiscard]] Range normalize(const Range &range) const
9375
{
94-
return Range<T>(normalize(range.min), normalize(range.max));
76+
return {normalize(range.min), normalize(range.max)};
9577
}
9678

97-
bool operator==(const Range<T> &other) const
79+
bool operator==(const Range &other) const
9880
{
9981
return min == other.min && max == other.max;
10082
}
10183

102-
Range<T> operator+(double shift) const
84+
Range operator+(double shift) const
10385
{
104-
return Range<T>(min + shift, max + shift);
86+
return {min + shift, max + shift};
10587
}
10688

107-
Range<T> operator+(const Range<T> &other) const
89+
Range operator+(const Range &other) const
10890
{
109-
return Range<T>(min + other.min, max + other.max);
91+
return {min + other.min, max + other.max};
11092
}
11193

112-
Range<T> operator-(double shift) const
94+
Range operator-(double shift) const
11395
{
114-
return Range<T>(min - shift, max - shift);
96+
return {min - shift, max - shift};
11597
}
11698

117-
Range<T> operator*(double factor) const
99+
Range operator*(double factor) const
118100
{
119-
return Range<T>(min * factor, max * factor);
101+
return {min * factor, max * factor};
120102
}
121103

122-
Range<T> operator/(double factor) const
104+
Range operator/(double factor) const
123105
{
124-
return Range<T>(min / factor, max / factor);
106+
return {min / factor, max / factor};
125107
}
126108

127-
Range<T> operator*(const Transform &transf)
109+
Range operator*(const Transform &transf)
128110
{
129111
return *this * transf.factor + transf.shift;
130112
}
131113

132-
Transform operator/(const Range<T> range)
114+
Transform operator/(const Range range)
133115
{
134116
auto factor = range.size() != 0 ? size() / range.size() : 0;
135117
auto shift = min - range.min * factor;
@@ -140,17 +122,8 @@ template <std::floating_point T = double> struct Range
140122

141123
[[nodiscard]] T size() const { return max - min; }
142124

143-
[[nodiscard]] T getMin() const { return min; }
144-
[[nodiscard]] T getMax() const { return max; }
145-
146-
consteval static auto members()
147-
{
148-
return std::tuple{&Range::min, &Range::max};
149-
}
150-
151-
protected:
152-
T min;
153-
T max;
125+
T min{std::numeric_limits<T>::max()};
126+
T max{std::numeric_limits<T>::lowest()};
154127
};
155128

156129
}

src/base/math/segmentedfunc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ template <typename T, class CRTP> struct SegmentedFunction
8282
});
8383
return interpolate(it->value,
8484
std::next(it)->value,
85-
Range{it->pos, std::next(it)->pos}.rescale(pos));
85+
Range<>{it->pos, std::next(it)->pos}.rescale(pos));
8686
}
8787

8888
protected:

src/chart/generator/axis.cpp

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ MeasureAxis::MeasureAxis(const Math::Range<> &interval,
105105
const std::string_view &unit,
106106
const std::optional<double> &step) :
107107
enabled(true),
108-
range(interval.isReal() ? interval : Math::Range<>::Raw({}, {})),
108+
range(interval.isReal() ? interval : Math::Range<>{{}, {}}),
109109
series(std::move(series)),
110110
unit(std::string{unit}),
111111
step(step ? *step : Math::Renard::R5().ceil(range.size() / 5.0))
@@ -120,7 +120,7 @@ MeasureAxis::MeasureAxis(const Math::Range<> &interval,
120120
double MeasureAxis::origo() const
121121
{
122122
if (range.size() == 0) return 0;
123-
return -range.getMin() / range.size();
123+
return -range.min / range.size();
124124
}
125125

126126
MeasureAxis interpolate(const MeasureAxis &op0,
@@ -140,13 +140,12 @@ MeasureAxis interpolate(const MeasureAxis &op0,
140140

141141
if (auto s0Zero = is_zero(s0), s1Zero = is_zero(s1);
142142
s0Zero && s1Zero) {
143-
res.range = Math::Range<>::Raw(
144-
Math::interpolate(op0.range.getMin(),
145-
op1.range.getMin(),
146-
factor),
147-
Math::interpolate(op0.range.getMax(),
148-
op1.range.getMax(),
149-
factor));
143+
res.range = {Math::interpolate(op0.range.min,
144+
op1.range.min,
145+
factor),
146+
Math::interpolate(op0.range.max,
147+
op1.range.max,
148+
factor)};
150149
res.step = interpolate(op0.step, op1.step, factor);
151150
}
152151
else if (s1Zero) {
@@ -157,18 +156,16 @@ MeasureAxis interpolate(const MeasureAxis &op0,
157156
0.0,
158157
factor);
159158

160-
res.range = Math::Range<>::Raw(op1.range.middle()
161-
- middleAt * size,
159+
res.range = {op1.range.middle() - middleAt * size,
162160
op1.range.middle()
163-
+ (factor == 1.0 ? 0.0 : (1 - middleAt) * size));
161+
+ (factor == 1.0 ? 0.0 : (1 - middleAt) * size)};
164162

165163
auto step = op0.step.get() / s0 * size;
166164
auto max = std::copysign(MAX, step);
167165

168166
res.step = interpolate(op0.step,
169167
Anim::Interpolated{max},
170-
Math::Range<>::Raw(op0.step.get(), max)
171-
.rescale(step));
168+
Math::Range<>{op0.step.get(), max}.rescale(step));
172169
}
173170
else if (s0Zero) {
174171
auto size = factor == 0.0 ? MAX : s1 / factor;
@@ -177,18 +174,16 @@ MeasureAxis interpolate(const MeasureAxis &op0,
177174
op1.range.rescale(op0.range.middle()),
178175
factor);
179176

180-
res.range = Math::Range<>::Raw(op0.range.middle()
181-
- middleAt * size,
177+
res.range = {op0.range.middle() - middleAt * size,
182178
op0.range.middle()
183-
+ (factor == 0.0 ? 0.0 : (1 - middleAt) * size));
179+
+ (factor == 0.0 ? 0.0 : (1 - middleAt) * size)};
184180

185181
auto step = op1.step.get() / s1 * size;
186182
auto max = std::copysign(MAX, step);
187183

188184
res.step = interpolate(op1.step,
189185
Anim::Interpolated{max},
190-
Math::Range<>::Raw(op1.step.get(), max)
191-
.rescale(step));
186+
Math::Range<>{op1.step.get(), max}.rescale(step));
192187
}
193188
else {
194189
auto s0Inv = 1 / s0;
@@ -199,15 +194,14 @@ MeasureAxis interpolate(const MeasureAxis &op0,
199194

200195
const auto size = is_zero(interp) ? MAX : 1 / interp;
201196

202-
res.range = Math::Range<>::Raw(
203-
Math::interpolate(op0.range.getMin() * s0Inv,
204-
op1.range.getMin() * s1Inv,
197+
res.range = {Math::interpolate(op0.range.min * s0Inv,
198+
op1.range.min * s1Inv,
199+
factor)
200+
* size,
201+
Math::interpolate(op0.range.max * s0Inv,
202+
op1.range.max * s1Inv,
205203
factor)
206-
* size,
207-
Math::interpolate(op0.range.getMax() * s0Inv,
208-
op1.range.getMax() * s1Inv,
209-
factor)
210-
* size);
204+
* size};
211205

212206
auto step = Math::interpolate(op0.step.get() * s0Inv,
213207
op1.step.get() * s1Inv,
@@ -218,19 +212,17 @@ MeasureAxis interpolate(const MeasureAxis &op0,
218212
op0sign == std::signbit(op1.step.get()))
219213
res.step = interpolate(op0.step,
220214
op1.step,
221-
Math::Range<>::Raw(op0.step.get(), op1.step.get())
215+
Math::Range<>{op0.step.get(), op1.step.get()}
222216
.rescale(step));
223217
else if (auto max = std::copysign(MAX, step);
224218
op0sign == std::signbit(step))
225219
res.step = interpolate(op0.step,
226220
Anim::Interpolated{max},
227-
Math::Range<>::Raw(op0.step.get(), max)
228-
.rescale(step));
221+
Math::Range<>{op0.step.get(), max}.rescale(step));
229222
else
230223
res.step = interpolate(op1.step,
231224
Anim::Interpolated{max},
232-
Math::Range<>::Raw(op1.step.get(), max)
233-
.rescale(step));
225+
Math::Range<>{op1.step.get(), max}.rescale(step));
234226
}
235227

236228
res.unit = interpolate(op0.unit, op1.unit, factor);

0 commit comments

Comments
 (0)