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

Change marker id to string #563

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9907118
own string v1
schaumb Jul 25, 2024
4f829ec
Merge remote-tracking branch 'origin/review' into review_after_merge
schaumb Jul 26, 2024
a8d5ce9
Fix clang tidy
schaumb Jul 26, 2024
7f91382
handler ref_wr, simplify optional typetrait + some review, implicit s…
schaumb Jul 29, 2024
d2718b9
self review
schaumb Jul 29, 2024
781c271
Self review 2
schaumb Jul 29, 2024
89a7653
Fix ts build with set markerId to string everywhere
schaumb Jul 29, 2024
2cc01f1
Fix clang-format/clang-tidy/tests
schaumb Jul 30, 2024
a0fe3ff
Merge remote-tracking branch 'origin/main' into markerId-to-string
schaumb Jul 30, 2024
d97718b
Self-review + changelog
schaumb Jul 30, 2024
81354a6
Merge remote-tracking branch 'origin/main' into markerId-to-string
schaumb Aug 12, 2024
3e762f8
Fix merge
schaumb Aug 12, 2024
3d3fc0a
Add translateY style parameter to legend + test
schaumb Aug 26, 2024
6e7f5d4
Fix clang-tidy
schaumb Aug 26, 2024
71a03f2
add yOverflow in Legend event
schaumb Aug 26, 2024
0fb5a01
fix test hash
schaumb Aug 26, 2024
2a432c6
Revert length yaml definition
schaumb Aug 28, 2024
2da093e
Merge branch 'legend_bottom'
schaumb Aug 28, 2024
5d9e432
Merge remote-tracking branch 'origin/main'
schaumb Aug 28, 2024
d42fb9e
Rm textColor, change offsetY testcase, add ColorGradientSetter
schaumb Aug 28, 2024
f53c8ef
gradient only the fade area
schaumb Aug 29, 2024
8697892
Fix testcases
schaumb Aug 29, 2024
9a24410
Add changelog + fix format
schaumb Aug 29, 2024
89090ef
Remove marker labels at intermediate steps
schaumb Aug 29, 2024
5af761a
Merge remote-tracking branch 'refs/remotes/origin/intermediate_steps_…
schaumb Aug 30, 2024
baa3936
Remove Text::immutable_string
schaumb Aug 30, 2024
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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

## [Unreleased]

### Fixed

- Legend title bottomPadding extended.
- Remove marker labels at intermediate steps.
- Markers are the same even if new record added.

### Added

- New style parameter for the legend scrolling.
- Changed MarkerId to be a string instead of a number.

## [0.12.1] - 2024-08-22

### Fixed
Expand Down
21 changes: 8 additions & 13 deletions src/apps/qutils/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ void BaseCanvas::init(QPaintDevice *device)

void BaseCanvas::setBrushColor(const Gfx::Color &color)
{
brush = QBrush(toQColor(color));
painter.setBrush(brush);
painter.setBrush(toQColor(color));
painter.setPen(brushToPen(painter.brush()));
}

void BaseCanvas::setLineColor(const Gfx::Color &color)
Expand Down Expand Up @@ -162,12 +162,6 @@ void BaseCanvas::setFont(const Gfx::Font &newFont)
painter.setFont(fromGfxFont(newFont, painter.font()));
}

void BaseCanvas::setTextColor(const Gfx::Color &color)
{
textPen = colorToPen(color);
painter.setPen(textPen);
}

void BaseCanvas::beginDropShadow() {}

void BaseCanvas::setDropShadowBlur(double) {}
Expand Down Expand Up @@ -197,9 +191,9 @@ 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.setPen(brushToPen(painter.brush()));
painter.drawText(toQRect(rect),
Qt::AlignLeft,
QString::fromStdString(text));
Expand All @@ -214,22 +208,23 @@ void BaseCanvas::setBrushGradient(const Geom::Line &line,
qGradient.setColorAt(stop.pos, toQColor(stop.value));
}
painter.setBrush(QBrush(qGradient));
painter.setPen(brushToPen(painter.brush()));
}

QPen BaseCanvas::colorToPen(const Gfx::Color &color)
QPen BaseCanvas::colorToPen(const Gfx::Color &color) const
{
return brushToPen(QBrush(toQColor(color)));
}

QPen BaseCanvas::brushToPen(const QBrush &brush)
QPen BaseCanvas::brushToPen(const QBrush &brush) const
{
auto pen = painter.pen();
pen.setBrush(brush);
return pen;
}

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
10 changes: 3 additions & 7 deletions src/apps/qutils/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class BaseCanvas : public Gfx::ICanvas, public Vizzu::Draw::Painter
void setLineColor(const Gfx::Color &color) override;
void setLineWidth(double width) override;
void setFont(const Gfx::Font &newFont) override;
void setTextColor(const Gfx::Color &color) override;

void beginDropShadow() override;
void setDropShadowBlur(double radius) override;
Expand All @@ -44,8 +43,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 All @@ -70,11 +68,9 @@ class BaseCanvas : public Gfx::ICanvas, public Vizzu::Draw::Painter
QFont font;
QPainterPath polygon;
QPen linePen;
QPen textPen;
QBrush brush;

QPen colorToPen(const Gfx::Color &color);
QPen brushToPen(const QBrush &brush);
[[nodiscard]] QPen colorToPen(const Gfx::Color &color) const;
[[nodiscard]] QPen brushToPen(const QBrush &brush) const;
};

using Canvas = BaseCanvas;
Expand Down
24 changes: 5 additions & 19 deletions src/apps/weblib/jscriptcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,6 @@ void JScriptCanvas::setFont(const Gfx::Font &font)
}
}

void JScriptCanvas::setTextColor(const Gfx::Color &color)
{
if (color != brushColor) {
brushColor = color;
::canvas_setBrushColor(this,
color.red,
color.green,
color.blue,
color.alpha);
}
}

void JScriptCanvas::beginDropShadow()
{
::canvas_beginDropShadow(this);
Expand Down Expand Up @@ -171,21 +159,21 @@ 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,
const Gfx::ColorGradient &gradient)
{
typedef decltype(gradient.stops)::value_type Stop;
static_assert(sizeof(double) == 8);
static_assert(sizeof(Stop) == sizeof(double) * 5);

static_assert(offsetof(Stop, pos) == 0);
Expand Down Expand Up @@ -248,11 +236,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;
}
4 changes: 1 addition & 3 deletions src/apps/weblib/jscriptcanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class JScriptCanvas : public Gfx::ICanvas, public Draw::Painter
void setLineColor(const Gfx::Color &color) override;
void setLineWidth(double width) override;
void setFont(const Gfx::Font &font) override;
void setTextColor(const Gfx::Color &color) override;

void beginDropShadow() override;
void setDropShadowBlur(double radius) override;
Expand All @@ -42,8 +41,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
4 changes: 3 additions & 1 deletion src/apps/weblib/ts-api/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ export interface Caption extends TextElement {
export interface Legend extends Element {
tagName: 'legend'
channel: string
/** Marker labels y overflow by pixel */
yOverflow: number
}

/** Logo element of the chart. */
Expand All @@ -141,7 +143,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
6 changes: 5 additions & 1 deletion src/apps/weblib/typeschema-api/styles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ definitions:

NumberScale:
description: |
Number scale for human readable big number formats.
Number scale for human-readable big number formats.
There are built in formats:
- SI Symbols: k, M, G, ...
- Short scale with US abbreviations: K, M, B, T
Expand Down Expand Up @@ -524,6 +524,10 @@ definitions:
marker:
$ref: LegendMarker
nullable: true
translateY:
description: Vertical translation of the marker list.
$ref: Length
nullable: true

ColorStop:
description: |
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>)
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 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
14 changes: 2 additions & 12 deletions src/base/gfx/canvas.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
#ifndef GFX_CANVAS
#define GFX_CANVAS

#include <memory>
#include <string>

#include "base/geom/affinetransform.h"
#include "base/geom/circle.h"
#include "base/geom/line.h"
#include "base/geom/point.h"
#include "base/geom/rect.h"
#include "base/gfx/color.h"
#include "base/gfx/colorgradient.h"
#include "base/gfx/colortransform.h"
#include "base/gfx/font.h"

namespace Gfx
{

struct ICanvas;

struct ICanvas
{
virtual ~ICanvas() = default;
Expand All @@ -28,7 +21,6 @@ struct ICanvas
virtual void setClipPolygon() = 0;
virtual void setBrushColor(const Gfx::Color &color) = 0;
virtual void setLineColor(const Gfx::Color &color) = 0;
virtual void setTextColor(const Gfx::Color &color) = 0;
virtual void setLineWidth(double width) = 0;
virtual void setFont(const Gfx::Font &font) = 0;

Expand All @@ -53,8 +45,7 @@ struct ICanvas
virtual void circle(const Geom::Circle &circle) = 0;
virtual void line(const Geom::Line &line) = 0;

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

virtual void setBrushGradient(const Geom::Line &line,
const ColorGradient &gradient) = 0;
Expand All @@ -64,8 +55,7 @@ struct ICanvas

virtual void *getPainter() = 0;

static Geom::Size textBoundary(const Gfx::Font &,
const std::string &);
static Geom::Size textBoundary(const Gfx::Font &, const char *);
};

}
Expand Down
9 changes: 5 additions & 4 deletions src/base/gfx/draw/textbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ void TextBox::draw(ICanvas &canvas, double opacity)
canvas.setLineColor(background);
canvas.rectangle(
{{xpos, ypos}, {text.width, line.height}});
canvas.setTextColor(foreground);
canvas.text({{xpos, ypos}, {10000, 10000}}, text.content);
canvas.setBrushColor(foreground);
canvas.text({{xpos, ypos}, {10000, 10000}},
text.content.c_str());
xpos += text.width;
}
ypos += line.height * line.spacing;
Expand All @@ -176,8 +177,8 @@ Geom::Size TextBox::measure(ICanvas &canvas)
line.height = 0;
for (auto &text : line.texts) {
canvas.setFont(text.font);
auto size =
ICanvas::textBoundary(text.font, text.content);
auto size = ICanvas::textBoundary(text.font,
text.content.c_str());
text.width = size.x;
line.width += size.x;
if (size.y > line.height) line.height = size.y;
Expand Down
Loading