Skip to content

Commit a6864bb

Browse files
committed
Several changes:
- Added a feature example demonstrating WServer::postAll() - Fixed spelling error in locale example README - take into account the marker scale-factor for the tooltip area
1 parent 22847f6 commit a6864bb

File tree

5 files changed

+90
-3
lines changed

5 files changed

+90
-3
lines changed

examples/feature/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SUBDIRS(
1111
oauth
1212
oidc
1313
paypal
14+
postall
1415
scrollvisibility
1516
serverpush
1617
socketnotifier
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
WT_ADD_EXAMPLE(postall.wt postall.C)
2+
INCLUDE_DIRECTORIES(${WT_SOURCE_DIR}/src)

examples/feature/postall/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
postAll feature example
2+
-----------------------
3+
4+
This is an example that demonstrates how WServer::postAll can be used
5+
to send a message to all active sessions.
6+
7+
How to run
8+
----------
9+
10+
See the README in the parent directory.
11+
12+
What it illustrates
13+
-------------------
14+
15+
- How WServer::postAll() can be used to send messages to all sessions.
16+
- the user of the server push API

examples/feature/postall/postall.C

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <Wt/WApplication.h>
2+
#include <Wt/WBreak.h>
3+
#include <Wt/WContainerWidget.h>
4+
#include <Wt/WLineEdit.h>
5+
#include <Wt/WPushButton.h>
6+
#include <Wt/WServer.h>
7+
#include <Wt/WString.h>
8+
9+
#include <cassert>
10+
11+
class PostAllExample : public Wt::WApplication {
12+
public:
13+
PostAllExample(const Wt::WEnvironment &env)
14+
: WApplication{env}
15+
{
16+
// Enable server push
17+
enableUpdates(true);
18+
19+
auto msgEdit = root()->addWidget(Wt::cpp14::make_unique<Wt::WLineEdit>());
20+
auto sendBtn = root()->addWidget(
21+
Wt::cpp14::make_unique<Wt::WPushButton>("Send message"));
22+
root()->addWidget(Wt::cpp14::make_unique<Wt::WBreak>());
23+
lastMsg_ = root()->addWidget(
24+
Wt::cpp14::make_unique<Wt::WText>("No messages received yet."));
25+
26+
sendBtn->clicked().connect([msgEdit]{
27+
auto server = Wt::WServer::instance();
28+
Wt::WString msg = msgEdit->text();
29+
30+
// Send msg to all active sessions with WServer::postAll()
31+
server->postAll([msg]{
32+
auto app = dynamic_cast<PostAllExample*>(Wt::WApplication::instance());
33+
assert(app != nullptr);
34+
app->updateMsg(msg);
35+
36+
// Push the changes to the client
37+
app->triggerUpdate();
38+
});
39+
});
40+
}
41+
42+
void updateMsg(Wt::WString msg)
43+
{
44+
lastMsg_->setText(Wt::WString{"Last received message: {1}"}.arg(msg));
45+
}
46+
47+
private:
48+
Wt::WText *lastMsg_;
49+
};
50+
51+
int main(int argc, char *argv[])
52+
{
53+
return Wt::WRun(argc, argv, [](const Wt::WEnvironment &env){
54+
return Wt::cpp14::make_unique<PostAllExample>(env);
55+
});
56+
}

src/Wt/Chart/WCartesianChart.C

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,12 @@ public:
10321032

10331033
std::unique_ptr<WCircleArea> circleArea(new WCircleArea());
10341034
circleArea->setCenter(WPointF(p.x(), p.y()));
1035-
circleArea->setRadius(5);
1035+
const double *scaleFactorP = series.model()
1036+
->markerScaleFactor(yRow, yColumn);
1037+
double scaleFactor = scaleFactorP != 0 ? *scaleFactorP : 1.0;
1038+
if (scaleFactor < 1.0)
1039+
scaleFactor = 1.0;
1040+
circleArea->setRadius(int(scaleFactor * 5.0));
10361041
circleArea->setToolTip(toolTip);
10371042

10381043
const_cast<WCartesianChart&>(chart_)
@@ -1152,13 +1157,20 @@ public:
11521157
if (matchedSeries_)
11531158
return; // we already have a match
11541159
if (!Utils::isNaN(x) && !Utils::isNaN(y)) {
1160+
const double *scaleFactorP = series.model()->markerScaleFactor(yRow, yColumn);
1161+
double scaleFactor = scaleFactorP != 0 ? *scaleFactorP : 1.0;
1162+
if (scaleFactor < 1.0)
1163+
scaleFactor = 1.0;
1164+
double scaledRx = scaleFactor * rX_;
1165+
double scaledRy = scaleFactor * rY_;
1166+
11551167
WPointF p = chart_.map(x, y, series.axis(), currentXSegment(), currentYSegment());
11561168
double dx = p.x() - matchX_;
11571169
double dy = p.y() - matchY_;
11581170
double dx2 = dx * dx;
11591171
double dy2 = dy * dy;
1160-
double rx2 = rX_ * rX_;
1161-
double ry2 = rY_ * rY_;
1172+
double rx2 = scaledRx * scaledRx;
1173+
double ry2 = scaledRy * scaledRy;
11621174
if (dx2/rx2 + dy2/ry2 <= 1) {
11631175
matchedXRow_ = xRow;
11641176
matchedXColumn_ = xColumn;

0 commit comments

Comments
 (0)