Skip to content

Commit bc2bb3d

Browse files
committed
TickLenght, LegendMarker and LegendWidth styles turned to Gfx::Length.
1 parent d1302e5 commit bc2bb3d

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

src/chart/main/layout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void Layout::setBoundary(const Geom::Rect &boundary,
2121
title = rect.popBottom(titlePos + titleHeight);
2222
title.setBottom(titlePos);
2323

24-
auto legendWidth = *style.legend.width;
24+
auto legendWidth = style.legend.width->get(rect.size.x);
2525

2626
auto legendPos = diagram.getOptions()->legend.get().combine<double>(
2727
[&](const auto &legend) { return legend ? 0 : -legendWidth; });

src/chart/main/style.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Chart Chart::def()
134134
.ticks = {
135135
.color = Gfx::Color::Gray(0.8),
136136
.lineWidth = 1,
137-
.length = 5,
137+
.length = Gfx::Length::Absolute(5),
138138
.position = ::Anim::Interpolated<Tick::Position>
139139
(Tick::Position::outside)
140140
},
@@ -159,7 +159,7 @@ Chart Chart::def()
159159
.borderColor = Gfx::Color(),
160160
.borderWidth = 0,
161161
},
162-
.width = 100,
162+
.width = Gfx::Length::Absolute(100),
163163
.title = {
164164
{
165165
.paddingTop = Gfx::Length::Absolute(5),
@@ -207,7 +207,7 @@ Chart Chart::def()
207207
.marker = {
208208
.type = ::Anim::Interpolated<Legend::Marker::Type>
209209
(Legend::Marker::Type::circle),
210-
.size = 18
210+
.size = Gfx::Length::Absolute(18)
211211
}
212212
},
213213
.title = {

src/chart/main/style.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ struct Tick {
133133

134134
Param<Gfx::Color> color;
135135
Param<double> lineWidth;
136-
Param<double> length;
136+
Param<Gfx::Length> length;
137137
Param<::Anim::Interpolated<Position>> position;
138138

139139
void visit(auto &visitor)
@@ -239,7 +239,7 @@ struct Legend : Padding, Box
239239
class Enum(Type)(circle, square);
240240

241241
Param<::Anim::Interpolated<Type>> type;
242-
Param<double> size;
242+
Param<Gfx::Length> size;
243243

244244
void visit(auto &visitor)
245245
{
@@ -249,7 +249,7 @@ struct Legend : Padding, Box
249249
}
250250
};
251251

252-
Param<double> width;
252+
Param<Gfx::Length> width;
253253
Label title;
254254
Label label;
255255
Marker marker;

src/chart/rendering/drawinterlacing.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,12 @@ void drawInterlacing::drawSticks(double stickIntensity,
194194
{
195195
const auto &tickStyle = style.plot.axis.ticks;
196196

197+
auto tickLength = tickStyle.length->get(
198+
coordSys.getRect().size.getCoord(horizontal)
199+
);
200+
197201
if (tickStyle.color->isTransparent()
198-
|| *tickStyle.length == 0
202+
|| tickLength == 0
199203
|| *tickStyle.lineWidth == 0)
200204
return;
201205

@@ -206,7 +210,7 @@ void drawInterlacing::drawSticks(double stickIntensity,
206210

207211
auto dP = horizontal ? Geom::Point::X(-1) : Geom::Point::Y(-1);
208212
dP = coordSys.convertAt(stickPos, dP);
209-
dP = dP.normalized() * *tickStyle.length;
213+
dP = dP.normalized() * tickLength;
210214

211215
if (*tickStyle.lineWidth > 0)
212216
canvas.setLineWidth(*tickStyle.lineWidth);

src/chart/rendering/drawlegend.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,19 @@ Geom::Rect drawLegend::getItemRect(double index) const
7676

7777
Geom::Rect drawLegend::getMarkerRect(const Geom::Rect &itemRect) const
7878
{
79+
auto markerSize = style.marker.size->get(contentRect.size.y);
7980
Geom::Rect res = itemRect;
80-
res.pos.y += itemHeight / 2.0 - *style.marker.size / 2.0;
81-
res.size = Geom::Size::Square(*style.marker.size);
81+
res.pos.y += itemHeight / 2.0 - markerSize / 2.0;
82+
res.size = Geom::Size::Square(markerSize);
8283
return res;
8384
}
8485

8586
Geom::Rect drawLegend::getLabelRect(const Geom::Rect &itemRect) const
8687
{
88+
auto markerSize = style.marker.size->get(contentRect.size.y);
8789
Geom::Rect res = itemRect;
88-
res.pos.x += *style.marker.size;
89-
res.size.x -= std::max(0.0, res.size.x - *style.marker.size);
90+
res.pos.x += markerSize;
91+
res.size.x -= std::max(0.0, res.size.x - markerSize);
9092
return res;
9193
}
9294

@@ -179,9 +181,10 @@ void drawLegend::sizeBar(const Geom::Rect &rect)
179181

180182
Geom::Rect drawLegend::getBarRect() const
181183
{
184+
auto markerSize = style.marker.size->get(contentRect.size.y);
182185
Geom::Rect res = contentRect;
183186
res.pos.y += titleHeight + itemHeight / 2.0;
184187
res.size.y = 5 * itemHeight;
185-
res.size.x = *style.marker.size;
188+
res.size.x = markerSize;
186189
return res;
187190
}

0 commit comments

Comments
 (0)