Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEST #559

Closed
wants to merge 10 commits into from
Closed

TEST #559

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/apps/qutils/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void BaseCanvas::rectangle(const Geom::Rect &rect)
painter.drawRect(toQRect(rect));
}

void BaseCanvas::text(const Geom::Rect &rect, const std::string &text)
void BaseCanvas::text(const Geom::Rect &rect, const char *text)
{
painter.setPen(textPen);
painter.drawText(toQRect(rect),
Expand Down Expand Up @@ -227,7 +227,7 @@ QPen BaseCanvas::brushToPen(const QBrush &brush)
}

Geom::Size Gfx::ICanvas::textBoundary(const Gfx::Font &font,
const std::string &text)
const char *text)
{
auto res =
QFontMetrics{BaseCanvas::fromGfxFont(font)}.boundingRect(
Expand Down Expand Up @@ -262,7 +262,8 @@ QFont BaseCanvas::fromGfxFont(const Gfx::Font &newFont, QFont font)
font.setPixelSize(static_cast<int>(newFont.size));

if (!newFont.family.empty())
font.setFamily(QString::fromStdString(newFont.family));
font.setFamily(
QString::fromStdString(newFont.family.toString()));

font.setWeight(newFont.weight == Gfx::Font::Weight::Bold()
? QFont::Bold
Expand Down
3 changes: 1 addition & 2 deletions src/apps/qutils/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class BaseCanvas : public Gfx::ICanvas, public Vizzu::Draw::Painter
void circle(const Geom::Circle &circle) override;
void line(const Geom::Line &line) override;

void text(const Geom::Rect &rect,
const std::string &text) override;
void text(const Geom::Rect &rect, const char *text) override;

void setBrushGradient(const Geom::Line &line,
const Gfx::ColorGradient &gradient) override;
Expand Down
3 changes: 2 additions & 1 deletion src/apps/weblib/cinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ const Value *record_getValue(const Vizzu::Data::RowWrapper *record,
thread_local Value val{{}, {}};
if (auto &&cval = Interface::getRecordValue(*record, column);
(val.dimension = cval.index())) {
auto &&dim = *std::get_if<const std::string *>(&cval);
auto &&dim =
*std::get_if<const Text::immutable_string *>(&cval);
new (&val.dimensionValue)
const char *{dim ? dim->c_str() : nullptr};
}
Expand Down
4 changes: 2 additions & 2 deletions src/apps/weblib/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ void Interface::setChartFilter(ObjectRegistryHandle chart,
getChart(chart)->getOptions().dataFilter = {};
}

std::variant<double, const std::string *> Interface::getRecordValue(
const Data::RowWrapper &record,
std::variant<double, const Text::immutable_string *>
Interface::getRecordValue(const Data::RowWrapper &record,
const char *column)
{
return record.get_value(column);
Expand Down
4 changes: 2 additions & 2 deletions src/apps/weblib/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class Interface
const char *path,
const char *value);

static std::variant<double, const std::string *> getRecordValue(
const Data::RowWrapper &record,
static std::variant<double, const Text::immutable_string *>
getRecordValue(const Data::RowWrapper &record,
const char *column);

private:
Expand Down
11 changes: 4 additions & 7 deletions src/apps/weblib/jscriptcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,14 @@ void JScriptCanvas::line(const Geom::Line &line)
line.end.y);
}

void JScriptCanvas::text(const Geom::Rect &rect,
const std::string &text)
void JScriptCanvas::text(const Geom::Rect &rect, const char *text)
{
::canvas_text(this,
rect.pos.x,
rect.pos.y,
rect.size.x,
rect.size.y,
text.c_str());
text);
}

void JScriptCanvas::setBrushGradient(const Geom::Line &line,
Expand Down Expand Up @@ -236,11 +235,9 @@ void JScriptCanvas::resetStates()
}

Geom::Size Gfx::ICanvas::textBoundary(const Gfx::Font &font,
const std::string &text)
const char *text)
{
thread_local std::string fontCache;
fontCache = font.toCSS();
Geom::Size res;
::textBoundary(fontCache.c_str(), text.c_str(), &res.x, &res.y);
::textBoundary(font.toCSS().c_str(), text, &res.x, &res.y);
return res;
}
3 changes: 1 addition & 2 deletions src/apps/weblib/jscriptcanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class JScriptCanvas : public Gfx::ICanvas, public Draw::Painter
void circle(const Geom::Circle &circle) override;
void line(const Geom::Line &line) override;

void text(const Geom::Rect &rect,
const std::string &text) override;
void text(const Geom::Rect &rect, const char *text) override;

void setBrushGradient(const Geom::Line &line,
const Gfx::ColorGradient &gradient) override;
Expand Down
2 changes: 1 addition & 1 deletion src/apps/weblib/ts-api/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export interface Marker extends Element {
categories: Data.Record
values: Data.Record
/** Unique index of the marker. */
index: number
index: string
}

/** Label element of a marker element. */
Expand Down
8 changes: 4 additions & 4 deletions src/apps/weblib/ts-api/plugins/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export class Tooltip implements Plugin {
private _vizzu?: Vizzu
private _id = 0
private _animating = false
private _lastMarkerId: number | null = null
private _overedMarkerId: number | null = null
private _lastMarkerId: string | null = null
private _overedMarkerId: string | null = null
private _lastMove = new Date().getTime()

get hooks(): PluginHooks {
Expand Down Expand Up @@ -83,7 +83,7 @@ export class Tooltip implements Plugin {
}
}

_getMarkerId(target: Element | null): number | null {
_getMarkerId(target: Element | null): string | null {
if (target && this._isMarker(target)) {
return target.index
} else if (target && this._isMarkerLabel(target)) {
Expand All @@ -101,7 +101,7 @@ export class Tooltip implements Plugin {
return target.tagName === 'plot-marker-label'
}

_in(id: number, markerId: number): void {
_in(id: number, markerId: string): void {
if (this._id === id) {
if (!this._animating) {
this._lastMarkerId = markerId
Expand Down
8 changes: 4 additions & 4 deletions src/apps/weblib/typeschema-api/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ definitions:
type: boolean
tooltip:
description: |
Index of the marker, the tooltip should be turned on. This parameter is not needed
to set manually, tooltip will be taken care of autamatically when `tooltip` feature
is enabled.
type: number
Unique identifier of the marker, the tooltip should be turned on. This parameter is
not needed to set manually, tooltip will be taken care of automatically when
`tooltip` feature is enabled.
type: string
nullable: true
3 changes: 2 additions & 1 deletion src/base/anim/interpolated.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/conv/tostring.h"
#include "base/math/floating.h"
#include "base/math/interpolation.h"
#include "base/text/immutable_string.h"

namespace Anim
{
Expand Down Expand Up @@ -274,7 +275,7 @@ Interpolated<Type> interpolate(const Interpolated<Type> &op0,
return res;
}

using String = Interpolated<std::string>;
using String = Interpolated<Text::immutable_string>;

}

Expand Down
12 changes: 11 additions & 1 deletion src/base/conv/auto_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,22 @@ struct JSON
&& !std::is_same_v<std::remove_cvref_t<T>, std::nullptr_t>
&& !std::is_same_v<std::remove_cvref_t<T>, std::nullopt_t>
&& !Optional<T> && !StringConvertable<T>
&& !SerializableRange<T> && !Tuple<T>)
&& !SerializableRange<T> && !Tuple<T>
&& !Type::is_reference_wrapper_v<T>)
inline void any(const T &val) const
{
staticObj(val);
}

template <class T>
requires(!JSONSerializable<T> && !SerializableRange<T>
&& !StringConvertable<T>
&& Type::is_reference_wrapper_v<T>)
inline void any(const T &val) const
{
any(val.get());
}

explicit inline JSON(std::string &json) : json(json) {}

std::string &json;
Expand Down
2 changes: 1 addition & 1 deletion src/base/conv/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ template <typename To> To parse(const std::string &string)
else if constexpr (Parsable<To>) {
return To::fromString(string);
}
else if constexpr (Type::isoptional<To>::value) {
else if constexpr (Type::is_optional_v<To>) {
if (string == "null") return std::nullopt;
return parse<typename To::value_type>(string);
}
Expand Down
4 changes: 2 additions & 2 deletions src/base/conv/tostring.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ concept ToStringMember =

template <typename From>
requires(ToStringMember<From> || std::is_enum_v<From>
|| Type::isoptional<From>::value
|| Type::is_optional_v<From>
|| std::is_constructible_v<std::string, From>
|| std::is_arithmetic_v<From>)
std::string toString(const From &value)
{
if constexpr (std::is_enum_v<From>) {
return Refl::enum_name<std::string>(value);
}
else if constexpr (Type::isoptional<From>::value) {
else if constexpr (Type::is_optional_v<From>) {
if (!value) return "null";
return toString(*value);
}
Expand Down
75 changes: 61 additions & 14 deletions src/base/geom/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,56 @@ struct Point
double x{0.0};
double y{0.0};

static Point Invalid() { return {NAN, NAN}; }
[[nodiscard]] static Point Invalid() { return {NAN, NAN}; }

static Point Max()
[[nodiscard]] static Point Max()
{
return {std::numeric_limits<double>::max(),
std::numeric_limits<double>::max()};
}

static Point Min()
[[nodiscard]] static Point Min()
{
return {std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest()};
}

static Point Ident(bool horizontal)
[[nodiscard]] static Point Ident(bool horizontal)
{
return {horizontal ? 1.0 : 0.0, horizontal ? 0.0 : 1.0};
}

static Point Polar(double radius, double angle)
[[nodiscard]] static Point Polar(double radius, double angle)
{
return {radius * cos(angle), radius * sin(angle)};
}

static Point X(double x) { return {x, 0}; }
[[nodiscard]] static Point X(double x) { return {x, 0}; }

static Point Y(double y) { return {0, y}; }
[[nodiscard]] static Point Y(double y) { return {0, y}; }

Point operator*(double factor) const
[[nodiscard]] Point operator*(double factor) const
{
return {x * factor, y * factor};
}

Point operator/(double divisor) const
[[nodiscard]] Point operator/(double divisor) const
{
if (Math::Floating::is_zero(divisor)) return Invalid();
return {x / divisor, y / divisor};
}

Point operator+(const Point &other) const
[[nodiscard]] Point operator+(const Point &other) const
{
return {x + other.x, y + other.y};
}

Point operator-(const Point &other) const
[[nodiscard]] Point operator-(const Point &other) const
{
return {x - other.x, y - other.y};
}

Point operator*(const Point &other) const
[[nodiscard]] Point operator*(const Point &other) const
{
return {x * other.x, y * other.y};
}
Expand All @@ -77,18 +77,65 @@ struct Point
return x * other.x + y * other.y;
}

Point operator/(const Point &other) const
[[nodiscard]] Point operator/(const Point &other) const
{
using Math::Floating::is_zero;
if (is_zero(other.x) || is_zero(other.y)) return Invalid();
return {x / other.x, y / other.y};
}

double operator^(const Point &p) const
[[nodiscard]] double operator^(const Point &p) const
{
return x * p.y - y * p.x;
}

Point &operator+=(const Point &other)
{
x += other.x;
y += other.y;
return *this;
}

Point &operator-=(const Point &other)
{
x -= other.x;
y -= other.y;
return *this;
}

Point &operator*=(double factor)
{
x *= factor;
y *= factor;
return *this;
}

Point &operator/=(double divisor)
{
if (Math::Floating::is_zero(divisor))
return *this = Invalid();
x /= divisor;
y /= divisor;
return *this;
}

Point &operator*=(const Point &other)
{
x *= other.x;
y *= other.y;
return *this;
}

Point &operator/=(const Point &other)
{
using Math::Floating::is_zero;
if (is_zero(other.x) || is_zero(other.y))
return *this = Invalid();
x /= other.x;
y /= other.y;
return *this;
}

[[nodiscard]] Point flip() const { return {y, x}; }

[[nodiscard]] Point flipX() const { return {-x, y}; }
Expand Down
10 changes: 0 additions & 10 deletions src/base/geom/quadrilateral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@
namespace Geom
{

ConvexQuad::ConvexQuad(const Rect &rect)
{
points[0] = rect.pos;
points[1] = rect.pos + Point{rect.size.x, 0.0};
points[2] = rect.pos + rect.size;
points[3] = rect.pos + Point{0.0, rect.size.y};
}

Rect ConvexQuad::boundary() const { return Rect::Boundary(points); }

ConvexQuad ConvexQuad::Square(Point p0, Point p2)
{
auto center = (p0 + p2) / 2;
Expand Down
Loading