Skip to content

Commit 507f39a

Browse files
authored
Merge pull request #572 from vizzuhq/Translate_legend
Remove text bg + Fix alphas
2 parents 8b336c3 + c08844c commit 507f39a

34 files changed

+1704
-1819
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66

77
- Legend title bottomPadding extended.
88
- ColorGradient fromString not increasing position prohibited.
9+
- Fix alpha settings to linear by default:
10+
- Axis: line, title, labels, guides, interlacing, ticks
11+
- Legend: title, dimension markers, measure extrema labels
12+
- Marker: line with connections
913

1014
### Added
1115

1216
- New style parameter for the legend scrolling.
17+
- Remove background settings for all text, including title, subtitle and caption.
1318

1419
## [0.12.1] - 2024-08-22
1520

docs/tutorial/chart_layout.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ Promise.all([dataLoaded, mdChartLoaded]).then((results) => {
2525
(chart) => {
2626
return chart.animate({
2727
style: {
28-
title: {
29-
backgroundColor: '#A0A0A0'
30-
},
28+
backgroundColor: '#A0A0A0',
3129
plot: {
3230
backgroundColor: '#D2D2D2'
3331
},

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ definitions:
123123
type: string
124124
enum: [center, left, right]
125125
nullable: true
126-
backgroundColor:
127-
description: The background color of the displayed text.
128-
$ref: Color
129-
nullable: true
130126
numberFormat:
131127
description: |
132128
The format of the number. Only applicable for texts showing numerical

src/base/gfx/colorgradient.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,26 @@
1111
namespace Gfx
1212
{
1313

14-
ColorGradient::ColorGradient(const std::string &stoplist)
14+
ColorGradient ColorGradient::fromString(const std::string &stoplist)
1515
{
16+
ColorGradient res;
1617
for (const auto &stopString :
1718
Text::SmartString::split(stoplist, ',', true)) {
1819
if (auto &&parts =
1920
Text::SmartString::split(stopString, ' ', true);
2021
parts.size() == 2)
2122
if (auto pos = std::stod(parts[1]);
2223
std::isfinite(pos)
23-
&& (stops.empty() || pos >= stops.back().pos)) {
24-
stops.emplace_back(pos, Color::fromString(parts[0]));
24+
&& (res.stops.empty()
25+
|| pos >= res.stops.back().pos)) {
26+
res.stops.emplace_back(pos,
27+
Color::fromString(parts[0]));
2528
continue;
2629
}
2730
throw std::logic_error(
2831
"invalid gradient stop: " + stopString);
2932
}
33+
return res;
3034
}
3135

3236
ColorGradient::operator std::string() const
@@ -42,26 +46,22 @@ ColorGradient::operator std::string() const
4246

4347
ColorGradient ColorGradient::HeatMap5Color()
4448
{
45-
ColorGradient res;
46-
res.stops.emplace_back(0.0 / 4.0, Gfx::Color(0.0, 0.0, 1.0));
47-
res.stops.emplace_back(1.0 / 4.0, Gfx::Color(0.0, 1.0, 1.0));
48-
res.stops.emplace_back(2.0 / 4.0, Gfx::Color(0.0, 1.0, 0.0));
49-
res.stops.emplace_back(3.0 / 4.0, Gfx::Color(1.0, 1.0, 0.0));
50-
res.stops.emplace_back(4.0 / 4.0, Gfx::Color(1.0, 0.0, 0.0));
51-
return res;
49+
return {{0.0 / 4.0, Color(0.0, 0.0, 1.0)},
50+
{1.0 / 4.0, Color(0.0, 1.0, 1.0)},
51+
{2.0 / 4.0, Color(0.0, 1.0, 0.0)},
52+
{3.0 / 4.0, Color(1.0, 1.0, 0.0)},
53+
{4.0 / 4.0, Color(1.0, 0.0, 0.0)}};
5254
}
5355

5456
ColorGradient ColorGradient::HeatMap7Color()
5557
{
56-
ColorGradient res;
57-
res.stops.emplace_back(0.0 / 6.0, Gfx::Color(0.0, 0.0, 0.0));
58-
res.stops.emplace_back(1.0 / 6.0, Gfx::Color(0.0, 0.0, 1.0));
59-
res.stops.emplace_back(2.0 / 6.0, Gfx::Color(0.0, 1.0, 1.0));
60-
res.stops.emplace_back(3.0 / 6.0, Gfx::Color(0.0, 1.0, 0.0));
61-
res.stops.emplace_back(4.0 / 6.0, Gfx::Color(1.0, 1.0, 0.0));
62-
res.stops.emplace_back(5.0 / 6.0, Gfx::Color(1.0, 0.0, 0.0));
63-
res.stops.emplace_back(6.0 / 6.0, Gfx::Color(1.0, 1.0, 1.0));
64-
return res;
58+
return {{0.0 / 6.0, Color(0.0, 0.0, 0.0)},
59+
{1.0 / 6.0, Color(0.0, 0.0, 1.0)},
60+
{2.0 / 6.0, Color(0.0, 1.0, 1.0)},
61+
{3.0 / 6.0, Color(0.0, 1.0, 0.0)},
62+
{4.0 / 6.0, Color(1.0, 1.0, 0.0)},
63+
{5.0 / 6.0, Color(1.0, 0.0, 0.0)},
64+
{6.0 / 6.0, Color(1.0, 1.0, 1.0)}};
6565
}
6666

6767
}

src/base/gfx/colorgradient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ struct ColorGradient : Math::SegmentedFunction<Color, ColorGradient>
1717

1818
using SegmentedFunction::SegmentedFunction;
1919

20-
explicit ColorGradient(
21-
const std::string &stoplist = std::string());
20+
[[nodiscard]] static ColorGradient fromString(
21+
const std::string &stoplist);
2222

2323
explicit operator std::string() const;
2424
};

src/base/gfx/colortransform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ColorTransform ColorTransform::Opacity(double factor)
6868
{
6969
return {[=](const Color &color)
7070
{
71-
return color.transparent(factor);
71+
return color * factor;
7272
},
7373
"opacity(" + std::to_string(factor) + ")"};
7474
}

src/base/math/fuzzybool.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ class FuzzyBool
124124
return FuzzyBool(std::max(0.0, 1 - 2 * value));
125125
}
126126

127+
[[nodiscard]] FuzzyBool moreOrLess() const
128+
{
129+
return FuzzyBool(std::abs(2 * value - 1));
130+
}
131+
127132
[[nodiscard]] FuzzyBool very() const
128133
{
129134
return FuzzyBool(value * value);
@@ -134,6 +139,43 @@ class FuzzyBool
134139
return FuzzyBool(sqrt(value));
135140
}
136141

142+
template <class>
143+
struct CommonOrFuzzyImpl : std::type_identity<FuzzyBool>
144+
{};
145+
146+
template <class T>
147+
requires(requires { typename T::type; })
148+
struct CommonOrFuzzyImpl<T> : T
149+
{};
150+
151+
template <class Res, class... Args>
152+
using CommonOrFuzzy = std::conditional_t<std::is_void_v<Res>,
153+
typename CommonOrFuzzyImpl<std::common_type<Args...>>::type,
154+
Res>;
155+
156+
template <class Res = void, class Arg, class... Args>
157+
[[nodiscard]] static CommonOrFuzzy<Res, Arg, Args...>
158+
And(Arg &&arg, Args &&...args)
159+
{
160+
return static_cast<CommonOrFuzzy<Res, Arg, Args...>>(
161+
(FuzzyBool{std::forward<Arg>(arg)} && ...
162+
&& FuzzyBool{std::forward<Args>(args)}));
163+
}
164+
165+
template <class Res = void, class Arg, class... Args>
166+
[[nodiscard]] static CommonOrFuzzy<Res, Arg, Args...>
167+
Or(Arg &&arg, Args &&...args)
168+
{
169+
return static_cast<CommonOrFuzzy<Res, Arg, Args...>>(
170+
(FuzzyBool{std::forward<Arg>(arg)} || ...
171+
|| FuzzyBool{std::forward<Args>(args)}));
172+
}
173+
174+
template <class T> [[nodiscard]] static T more(const T &v)
175+
{
176+
return static_cast<T>(FuzzyBool{v}.more());
177+
}
178+
137179
private:
138180
double value{0.0};
139181
};

src/base/math/segmentedfunc.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef MATH_SEGMENTEDFUNC
22
#define MATH_SEGMENTEDFUNC
33

4+
#include <initializer_list>
45
#include <vector>
56

67
#include "interpolation.h"
@@ -24,10 +25,8 @@ template <typename T, class CRTP> struct SegmentedFunction
2425
std::vector<Stop> stops;
2526

2627
SegmentedFunction() noexcept = default;
27-
explicit SegmentedFunction(std::size_t init) : stops(init) {}
28-
explicit SegmentedFunction(std::vector<Stop> &&stops) noexcept :
29-
stops(std::move(stops))
30-
{}
28+
29+
SegmentedFunction(std::initializer_list<Stop> il) : stops(il) {}
3130

3231
[[nodiscard]] friend CRTP operator*(const CRTP &self,
3332
double value)
@@ -84,6 +83,9 @@ template <typename T, class CRTP> struct SegmentedFunction
8483
std::next(it)->value,
8584
Range{it->pos, std::next(it)->pos}.rescale(pos));
8685
}
86+
87+
protected:
88+
explicit SegmentedFunction(std::size_t init) : stops(init) {}
8789
};
8890

8991
}

src/chart/main/style.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "base/anim/interpolated.h"
66
#include "base/gfx/color.h"
7-
#include "base/gfx/colorgradient.h"
87
#include "base/gfx/colorpalette.h"
98
#include "base/gfx/colortransform.h"
109
#include "base/gfx/font.h"
@@ -106,7 +105,7 @@ Chart Chart::def()
106105
.marker = {
107106
DataPoint
108107
{
109-
.colorGradient = Gfx::ColorGradient(
108+
.colorGradient = {
110109
{
111110
{
112111
0.0,
@@ -128,7 +127,7 @@ Chart Chart::def()
128127
1.0,
129128
Gfx::Color::RGB(0xf3f239)
130129
}
131-
}),
130+
}},
132131
.colorPalette = ::Anim::Interpolated<Gfx::ColorPalette>(getDefaultColorPalette()),
133132
.minLightness = 0.4,
134133
.maxLightness = -0.4,
@@ -171,7 +170,6 @@ Chart Chart::def()
171170
{
172171
.color = Gfx::Color(),
173172
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::center),
174-
.backgroundColor = Gfx::Color(),
175173
.numberFormat = ::Text::NumberFormat::grouped,
176174
.maxFractionDigits = 3,
177175
.numberScale = ::Text::NumberScale{}
@@ -215,7 +213,6 @@ Chart Chart::def()
215213
{
216214
.color = Gfx::Color::Gray(0.6),
217215
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::left),
218-
.backgroundColor = Gfx::Color(),
219216
.numberFormat = ::Text::NumberFormat::prefixed,
220217
.maxFractionDigits = 3,
221218
.numberScale = ::Text::NumberScale{}
@@ -253,7 +250,6 @@ Chart Chart::def()
253250
{
254251
.color = Gfx::Color::Gray(0.6),
255252
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::left),
256-
.backgroundColor = Gfx::Color(),
257253
.numberFormat = ::Text::NumberFormat::prefixed,
258254
.maxFractionDigits = 3,
259255
.numberScale = ::Text::NumberScale{}
@@ -308,7 +304,6 @@ Chart Chart::def()
308304
{
309305
.color = Gfx::Color::Gray(0.6),
310306
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::left),
311-
.backgroundColor = Gfx::Color(),
312307
.numberFormat = ::Text::NumberFormat::prefixed,
313308
.maxFractionDigits = 3,
314309
.numberScale = ::Text::NumberScale{}
@@ -346,7 +341,6 @@ Chart Chart::def()
346341
{
347342
.color = Gfx::Color::Gray(0.6),
348343
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::left),
349-
.backgroundColor = Gfx::Color(),
350344
.numberFormat = ::Text::NumberFormat::prefixed,
351345
.maxFractionDigits = 3,
352346
.numberScale = ::Text::NumberScale{}
@@ -419,7 +413,6 @@ Chart Chart::def()
419413
{
420414
.color = Gfx::Color::Gray(0.6),
421415
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::left),
422-
.backgroundColor = Gfx::Color(),
423416
.numberFormat = ::Text::NumberFormat::prefixed,
424417
.maxFractionDigits = 3,
425418
.numberScale = ::Text::NumberScale{}
@@ -444,7 +437,6 @@ Chart Chart::def()
444437
{
445438
.color = Gfx::Color::Gray(0.6),
446439
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::left),
447-
.backgroundColor = Gfx::Color(),
448440
.numberFormat = ::Text::NumberFormat::prefixed,
449441
.maxFractionDigits = 3,
450442
.numberScale = ::Text::NumberScale{}
@@ -476,7 +468,6 @@ Chart Chart::def()
476468
{
477469
.color = Gfx::Color::RGB(0x494949),
478470
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::center),
479-
.backgroundColor = Gfx::Color(),
480471
.numberFormat = ::Text::NumberFormat::prefixed,
481472
.maxFractionDigits = 3,
482473
.numberScale = ::Text::NumberScale{}
@@ -501,7 +492,6 @@ Chart Chart::def()
501492
{
502493
.color = Gfx::Color::RGB(0x494949),
503494
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::center),
504-
.backgroundColor = Gfx::Color(),
505495
.numberFormat = ::Text::NumberFormat::prefixed,
506496
.maxFractionDigits = 3,
507497
.numberScale = ::Text::NumberScale{}
@@ -526,7 +516,6 @@ Chart Chart::def()
526516
{
527517
.color = Gfx::Color::Gray(0.65),
528518
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::left),
529-
.backgroundColor = Gfx::Color(),
530519
.numberFormat = ::Text::NumberFormat::prefixed,
531520
.maxFractionDigits = 3,
532521
.numberScale = ::Text::NumberScale{}

src/chart/main/style.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ struct Text
135135

136136
Param<Gfx::Color> color;
137137
Param<::Anim::Interpolated<TextAlign>> textAlign;
138-
Param<Gfx::Color> backgroundColor;
139138
Param<::Text::NumberFormat> numberFormat;
140139
Param<double> maxFractionDigits;
141140
Param<::Text::NumberScale> numberScale;

0 commit comments

Comments
 (0)