Skip to content

Commit

Permalink
Merge pull request #572 from vizzuhq/Translate_legend
Browse files Browse the repository at this point in the history
Remove text bg + Fix alphas
  • Loading branch information
schaumb authored Sep 5, 2024
2 parents 8b336c3 + c08844c commit 507f39a
Show file tree
Hide file tree
Showing 34 changed files with 1,704 additions and 1,819 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@

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

### Added

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

## [0.12.1] - 2024-08-22

Expand Down
4 changes: 1 addition & 3 deletions docs/tutorial/chart_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ Promise.all([dataLoaded, mdChartLoaded]).then((results) => {
(chart) => {
return chart.animate({
style: {
title: {
backgroundColor: '#A0A0A0'
},
backgroundColor: '#A0A0A0',
plot: {
backgroundColor: '#D2D2D2'
},
Expand Down
4 changes: 0 additions & 4 deletions src/apps/weblib/typeschema-api/styles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ definitions:
type: string
enum: [center, left, right]
nullable: true
backgroundColor:
description: The background color of the displayed text.
$ref: Color
nullable: true
numberFormat:
description: |
The format of the number. Only applicable for texts showing numerical
Expand Down
38 changes: 19 additions & 19 deletions src/base/gfx/colorgradient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@
namespace Gfx
{

ColorGradient::ColorGradient(const std::string &stoplist)
ColorGradient ColorGradient::fromString(const std::string &stoplist)
{
ColorGradient res;
for (const auto &stopString :
Text::SmartString::split(stoplist, ',', true)) {
if (auto &&parts =
Text::SmartString::split(stopString, ' ', true);
parts.size() == 2)
if (auto pos = std::stod(parts[1]);
std::isfinite(pos)
&& (stops.empty() || pos >= stops.back().pos)) {
stops.emplace_back(pos, Color::fromString(parts[0]));
&& (res.stops.empty()
|| pos >= res.stops.back().pos)) {
res.stops.emplace_back(pos,
Color::fromString(parts[0]));
continue;
}
throw std::logic_error(
"invalid gradient stop: " + stopString);
}
return res;
}

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

ColorGradient ColorGradient::HeatMap5Color()
{
ColorGradient res;
res.stops.emplace_back(0.0 / 4.0, Gfx::Color(0.0, 0.0, 1.0));
res.stops.emplace_back(1.0 / 4.0, Gfx::Color(0.0, 1.0, 1.0));
res.stops.emplace_back(2.0 / 4.0, Gfx::Color(0.0, 1.0, 0.0));
res.stops.emplace_back(3.0 / 4.0, Gfx::Color(1.0, 1.0, 0.0));
res.stops.emplace_back(4.0 / 4.0, Gfx::Color(1.0, 0.0, 0.0));
return res;
return {{0.0 / 4.0, Color(0.0, 0.0, 1.0)},
{1.0 / 4.0, Color(0.0, 1.0, 1.0)},
{2.0 / 4.0, Color(0.0, 1.0, 0.0)},
{3.0 / 4.0, Color(1.0, 1.0, 0.0)},
{4.0 / 4.0, Color(1.0, 0.0, 0.0)}};
}

ColorGradient ColorGradient::HeatMap7Color()
{
ColorGradient res;
res.stops.emplace_back(0.0 / 6.0, Gfx::Color(0.0, 0.0, 0.0));
res.stops.emplace_back(1.0 / 6.0, Gfx::Color(0.0, 0.0, 1.0));
res.stops.emplace_back(2.0 / 6.0, Gfx::Color(0.0, 1.0, 1.0));
res.stops.emplace_back(3.0 / 6.0, Gfx::Color(0.0, 1.0, 0.0));
res.stops.emplace_back(4.0 / 6.0, Gfx::Color(1.0, 1.0, 0.0));
res.stops.emplace_back(5.0 / 6.0, Gfx::Color(1.0, 0.0, 0.0));
res.stops.emplace_back(6.0 / 6.0, Gfx::Color(1.0, 1.0, 1.0));
return res;
return {{0.0 / 6.0, Color(0.0, 0.0, 0.0)},
{1.0 / 6.0, Color(0.0, 0.0, 1.0)},
{2.0 / 6.0, Color(0.0, 1.0, 1.0)},
{3.0 / 6.0, Color(0.0, 1.0, 0.0)},
{4.0 / 6.0, Color(1.0, 1.0, 0.0)},
{5.0 / 6.0, Color(1.0, 0.0, 0.0)},
{6.0 / 6.0, Color(1.0, 1.0, 1.0)}};
}

}
4 changes: 2 additions & 2 deletions src/base/gfx/colorgradient.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ struct ColorGradient : Math::SegmentedFunction<Color, ColorGradient>

using SegmentedFunction::SegmentedFunction;

explicit ColorGradient(
const std::string &stoplist = std::string());
[[nodiscard]] static ColorGradient fromString(
const std::string &stoplist);

explicit operator std::string() const;
};
Expand Down
2 changes: 1 addition & 1 deletion src/base/gfx/colortransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ColorTransform ColorTransform::Opacity(double factor)
{
return {[=](const Color &color)
{
return color.transparent(factor);
return color * factor;
},
"opacity(" + std::to_string(factor) + ")"};
}
Expand Down
42 changes: 42 additions & 0 deletions src/base/math/fuzzybool.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ class FuzzyBool
return FuzzyBool(std::max(0.0, 1 - 2 * value));
}

[[nodiscard]] FuzzyBool moreOrLess() const
{
return FuzzyBool(std::abs(2 * value - 1));
}

[[nodiscard]] FuzzyBool very() const
{
return FuzzyBool(value * value);
Expand All @@ -134,6 +139,43 @@ class FuzzyBool
return FuzzyBool(sqrt(value));
}

template <class>
struct CommonOrFuzzyImpl : std::type_identity<FuzzyBool>
{};

template <class T>
requires(requires { typename T::type; })
struct CommonOrFuzzyImpl<T> : T
{};

template <class Res, class... Args>
using CommonOrFuzzy = std::conditional_t<std::is_void_v<Res>,
typename CommonOrFuzzyImpl<std::common_type<Args...>>::type,
Res>;

template <class Res = void, class Arg, class... Args>
[[nodiscard]] static CommonOrFuzzy<Res, Arg, Args...>
And(Arg &&arg, Args &&...args)
{
return static_cast<CommonOrFuzzy<Res, Arg, Args...>>(
(FuzzyBool{std::forward<Arg>(arg)} && ...
&& FuzzyBool{std::forward<Args>(args)}));
}

template <class Res = void, class Arg, class... Args>
[[nodiscard]] static CommonOrFuzzy<Res, Arg, Args...>
Or(Arg &&arg, Args &&...args)
{
return static_cast<CommonOrFuzzy<Res, Arg, Args...>>(
(FuzzyBool{std::forward<Arg>(arg)} || ...
|| FuzzyBool{std::forward<Args>(args)}));
}

template <class T> [[nodiscard]] static T more(const T &v)
{
return static_cast<T>(FuzzyBool{v}.more());
}

private:
double value{0.0};
};
Expand Down
10 changes: 6 additions & 4 deletions src/base/math/segmentedfunc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef MATH_SEGMENTEDFUNC
#define MATH_SEGMENTEDFUNC

#include <initializer_list>
#include <vector>

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

SegmentedFunction() noexcept = default;
explicit SegmentedFunction(std::size_t init) : stops(init) {}
explicit SegmentedFunction(std::vector<Stop> &&stops) noexcept :
stops(std::move(stops))
{}

SegmentedFunction(std::initializer_list<Stop> il) : stops(il) {}

[[nodiscard]] friend CRTP operator*(const CRTP &self,
double value)
Expand Down Expand Up @@ -84,6 +83,9 @@ template <typename T, class CRTP> struct SegmentedFunction
std::next(it)->value,
Range{it->pos, std::next(it)->pos}.rescale(pos));
}

protected:
explicit SegmentedFunction(std::size_t init) : stops(init) {}
};

}
Expand Down
15 changes: 2 additions & 13 deletions src/chart/main/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "base/anim/interpolated.h"
#include "base/gfx/color.h"
#include "base/gfx/colorgradient.h"
#include "base/gfx/colorpalette.h"
#include "base/gfx/colortransform.h"
#include "base/gfx/font.h"
Expand Down Expand Up @@ -106,7 +105,7 @@ Chart Chart::def()
.marker = {
DataPoint
{
.colorGradient = Gfx::ColorGradient(
.colorGradient = {
{
{
0.0,
Expand All @@ -128,7 +127,7 @@ Chart Chart::def()
1.0,
Gfx::Color::RGB(0xf3f239)
}
}),
}},
.colorPalette = ::Anim::Interpolated<Gfx::ColorPalette>(getDefaultColorPalette()),
.minLightness = 0.4,
.maxLightness = -0.4,
Expand Down Expand Up @@ -171,7 +170,6 @@ Chart Chart::def()
{
.color = Gfx::Color(),
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::center),
.backgroundColor = Gfx::Color(),
.numberFormat = ::Text::NumberFormat::grouped,
.maxFractionDigits = 3,
.numberScale = ::Text::NumberScale{}
Expand Down Expand Up @@ -215,7 +213,6 @@ Chart Chart::def()
{
.color = Gfx::Color::Gray(0.6),
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::left),
.backgroundColor = Gfx::Color(),
.numberFormat = ::Text::NumberFormat::prefixed,
.maxFractionDigits = 3,
.numberScale = ::Text::NumberScale{}
Expand Down Expand Up @@ -253,7 +250,6 @@ Chart Chart::def()
{
.color = Gfx::Color::Gray(0.6),
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::left),
.backgroundColor = Gfx::Color(),
.numberFormat = ::Text::NumberFormat::prefixed,
.maxFractionDigits = 3,
.numberScale = ::Text::NumberScale{}
Expand Down Expand Up @@ -308,7 +304,6 @@ Chart Chart::def()
{
.color = Gfx::Color::Gray(0.6),
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::left),
.backgroundColor = Gfx::Color(),
.numberFormat = ::Text::NumberFormat::prefixed,
.maxFractionDigits = 3,
.numberScale = ::Text::NumberScale{}
Expand Down Expand Up @@ -346,7 +341,6 @@ Chart Chart::def()
{
.color = Gfx::Color::Gray(0.6),
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::left),
.backgroundColor = Gfx::Color(),
.numberFormat = ::Text::NumberFormat::prefixed,
.maxFractionDigits = 3,
.numberScale = ::Text::NumberScale{}
Expand Down Expand Up @@ -419,7 +413,6 @@ Chart Chart::def()
{
.color = Gfx::Color::Gray(0.6),
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::left),
.backgroundColor = Gfx::Color(),
.numberFormat = ::Text::NumberFormat::prefixed,
.maxFractionDigits = 3,
.numberScale = ::Text::NumberScale{}
Expand All @@ -444,7 +437,6 @@ Chart Chart::def()
{
.color = Gfx::Color::Gray(0.6),
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::left),
.backgroundColor = Gfx::Color(),
.numberFormat = ::Text::NumberFormat::prefixed,
.maxFractionDigits = 3,
.numberScale = ::Text::NumberScale{}
Expand Down Expand Up @@ -476,7 +468,6 @@ Chart Chart::def()
{
.color = Gfx::Color::RGB(0x494949),
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::center),
.backgroundColor = Gfx::Color(),
.numberFormat = ::Text::NumberFormat::prefixed,
.maxFractionDigits = 3,
.numberScale = ::Text::NumberScale{}
Expand All @@ -501,7 +492,6 @@ Chart Chart::def()
{
.color = Gfx::Color::RGB(0x494949),
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::center),
.backgroundColor = Gfx::Color(),
.numberFormat = ::Text::NumberFormat::prefixed,
.maxFractionDigits = 3,
.numberScale = ::Text::NumberScale{}
Expand All @@ -526,7 +516,6 @@ Chart Chart::def()
{
.color = Gfx::Color::Gray(0.65),
.textAlign = Anim::Interpolated<Text::TextAlign>(Text::TextAlign::left),
.backgroundColor = Gfx::Color(),
.numberFormat = ::Text::NumberFormat::prefixed,
.maxFractionDigits = 3,
.numberScale = ::Text::NumberScale{}
Expand Down
1 change: 0 additions & 1 deletion src/chart/main/style.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ struct Text

Param<Gfx::Color> color;
Param<::Anim::Interpolated<TextAlign>> textAlign;
Param<Gfx::Color> backgroundColor;
Param<::Text::NumberFormat> numberFormat;
Param<double> maxFractionDigits;
Param<::Text::NumberScale> numberScale;
Expand Down
Loading

0 comments on commit 507f39a

Please sign in to comment.