Skip to content

Commit

Permalink
Several changes:
Browse files Browse the repository at this point in the history
    - Make WAxis a virtual class so that it can be specialized (#3317)
    - Fix for #3580
    - Modify example's CMakeLists.txt to allow building examples in SDK
  • Loading branch information
Koen Deforche committed Sep 18, 2014
1 parent 1646a7c commit 2682e35
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 20 deletions.
58 changes: 58 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
# Normally, this is not a toplevel CMakeLists.txt file. Except when it is
# used in combination with the Windows SDK, then it is prefixed with the
# required configuration settings to allow building the examples of the
# binary Wt distribution as a standalone project.
#
# This CMakeLists.txt is complex because it supports all different modes
# of building Wt on all supported platforms. Your own CMakeLists.txt can
# be much simpler. For example (for Windows):
#
# CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
# Project(myproject)
#
# INCLUDE_DIRECTORIES(c:/wt-installation-path/include)
# LINK_DIRECTORIES(c:/wt-installation-path/lib)
#
# ADD_DEFINITIONS(-DHPDF_DLL)
#
# ADD_EXECUTABLE(myprog.wt
# MyProg1.cpp
# OtherFile.cpp
# AndEvenMoreCode.cpp
# )
#
# TARGET_LINK_LIBRARIES(myprog.wt
# debug wtd optimized wt
# debug wthttpd optimized wthttp
# debug libhpdfd optimized libhpdf # only required for if you write pdfs
# )

IF("${CMAKE_CURRENT_LIST_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
IF(WIN32)
# preamble to make this a toplevel CMakeLists.txt for Windows, intended
# for being used
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)

Project(WtExamples)

# build widgetgallery, if supported
IF(MSVC_VERSION GREATER 1600)
SET(HAS_CXX11 ON)
ENDIF(MSVC_VERSION GREATER 1600)

SET(EXAMPLES_CONNECTOR
debug wthttpd optimized wthttp
debug libhpdfd optimized libhpdf
)

INCLUDE_DIRECTORIES($(CMAKE_SOURCE_DIR)/../../../include)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/../../../lib)

# We ship libharu as DLL. Compiling/linking against libharu DLL requires
# this definition to be set.
ADD_DEFINITIONS(-DHPDF_DLL)
ENDIF(WIN32)
ENDIF("${CMAKE_CURRENT_LIST_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")


# Normal example CMakeLists.txt starts here
IF(BOOST_WT_MT_FOUND)
IF(MULTI_THREADED)
ADD_DEFINITIONS(-DWT_THREADED -D_REENTRANT -DBOOST_SPIRIT_THREADSAFE)
Expand Down
9 changes: 7 additions & 2 deletions src/Wt/Chart/WAxis
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ public:
*/
static const double AUTO_MAXIMUM;

/*! \brief Destructor
*/
virtual ~WAxis();

/*! \brief Returns the axis id.
*
* \sa chart(), WCartesianChart::axis()
Expand Down Expand Up @@ -553,7 +557,7 @@ public:
*/
const WFont& labelFont() const { return labelFont_; }

WString label(double u) const;
virtual WString label(double u) const;

/*! \brief Returns the chart to which this axis belongs.
*
Expand Down Expand Up @@ -595,6 +599,8 @@ protected:
TickLabel(double v, TickLength length, const WString& l = WString());
};

WAxis();

virtual void getLabelTicks(std::vector<TickLabel>& ticks, int segment) const;

private:
Expand Down Expand Up @@ -636,7 +642,6 @@ private:

mutable double renderInterval_;

WAxis();
void init(WAbstractChartImplementation* chart, Axis axis);
void update();

Expand Down
9 changes: 5 additions & 4 deletions src/Wt/Chart/WAxis.C
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ WAxis::WAxis()
segments_.push_back(Segment());
}

WAxis::~WAxis()
{ }

void WAxis::init(WAbstractChartImplementation* chart,
Axis axis)
{
Expand Down Expand Up @@ -965,14 +968,12 @@ void WAxis::getLabelTicks(std::vector<TickLabel>& ticks, int segment) const

const Segment& s = segments_[segment];

int rc;
switch (scale_) {
case CategoryScale: {
rc = chart_->numberOfCategories(axis_);
int renderInterval = std::max(1, static_cast<int>(renderInterval_));
if (renderInterval == 1) {
ticks.push_back(TickLabel(s.renderMinimum, TickLabel::Long));
for (int i = s.renderMinimum + 0.5; i < s.renderMaximum; ++i) {
for (int i = (int)(s.renderMinimum + 0.5); i < s.renderMaximum; ++i) {
ticks.push_back(TickLabel(i + 0.5, TickLabel::Long));
ticks.push_back(TickLabel(i, TickLabel::Zero,
label(static_cast<double>(i))));
Expand All @@ -981,7 +982,7 @@ void WAxis::getLabelTicks(std::vector<TickLabel>& ticks, int segment) const
/*
* We could do a special effort for date X series here...
*/
for (int i = s.renderMinimum + 0.5; i < s.renderMaximum;
for (int i = (int)(s.renderMinimum + 0.5); i < s.renderMaximum;
i += renderInterval) {
ticks.push_back(TickLabel(i, TickLabel::Long,
label(static_cast<double>(i))));
Expand Down
10 changes: 9 additions & 1 deletion src/Wt/Chart/WCartesianChart
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,14 @@ public:
*/
const WAxis& axis(Axis axis) const;

/*! \brief set and init axis
*
* Will replace the existing (default axis) with user axis.
*
* \sa axis(Axis axis)
*/
void setAxis(WAxis *waxis, Axis axis);

/*! \brief Sets the margin between bars of different series.
*
* Use this method to change the margin that is set between bars of
Expand Down Expand Up @@ -625,7 +633,7 @@ private:
int XSeriesColumn_;
ChartType type_;
std::vector<WDataSeries> series_;
WAxis axes_[3];
WAxis *axes_[3];
double barMargin_;
WLegend legend_;
int axisPadding_;
Expand Down
27 changes: 17 additions & 10 deletions src/Wt/Chart/WCartesianChart.C
Original file line number Diff line number Diff line change
Expand Up @@ -776,20 +776,21 @@ WCartesianChart::WCartesianChart(ChartType type, WContainerWidget *parent)

WCartesianChart::~WCartesianChart()
{
for (int i = 2; i > -1; i--)
delete axes_[i];
delete interface_;
}

void WCartesianChart::init()
{
setPalette(new WStandardPalette(WStandardPalette::Muted));

#ifdef WT_TARGET_JAVA

for (int i = 0; i < 3; ++i)
axes_[i] = WAxis();
#endif //WT_TARGET_JAVA
axes_[XAxis].init(interface_, XAxis);
axes_[YAxis].init(interface_, YAxis);
axes_[Y2Axis].init(interface_, Y2Axis);
axes_[i] = new WAxis();

axes_[XAxis]->init(interface_, XAxis);
axes_[YAxis]->init(interface_, YAxis);
axes_[Y2Axis]->init(interface_, Y2Axis);

setPlotAreaPadding(40, Left | Right);
setPlotAreaPadding(30, Top | Bottom);
Expand All @@ -815,7 +816,7 @@ void WCartesianChart::setType(ChartType type)
{
if (type_ != type) {
type_ = type;
axes_[XAxis].init(interface_, XAxis);
axes_[XAxis]->init(interface_, XAxis);
update();
}
}
Expand Down Expand Up @@ -880,12 +881,18 @@ void WCartesianChart::setSeries(const std::vector<WDataSeries>& series)

WAxis& WCartesianChart::axis(Axis axis)
{
return axes_[axis];
return *axes_[axis];
}

const WAxis& WCartesianChart::axis(Axis axis) const
{
return axes_[axis];
return *axes_[axis];
}

void WCartesianChart::setAxis(WAxis *waxis, Axis axis)
{
axes_[axis] = waxis;
axes_[axis]->init(interface_, axis);
}

void WCartesianChart::setBarMargin(double margin)
Expand Down
4 changes: 4 additions & 0 deletions src/Wt/WEnvironment
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,16 @@ public:
bool webGL() const { return webGLsupported_; }

/*! \brief Returns the horizontal resolution of the client's screen.
*
* Returns -1 if screen width is not known.
*
* \sa screenHeight()
*/
int screenWidth() const { return screenWidth_; }

/*! \brief Returns the vertical resolution of the client's screen.
*
* Returns -1 if screen height is not known.
*
* \sa screenWidth()
*/
Expand Down
22 changes: 19 additions & 3 deletions src/Wt/WEnvironment.C
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*
* See the LICENSE file for terms of use.
*/
#include "Wt/WEnvironment"

#include "Wt/Utils"
#include "Wt/WEnvironment"
#include "Wt/WException"
#include "Wt/WLogger"
#include "Wt/WSslInfo"
Expand Down Expand Up @@ -34,6 +34,8 @@ WEnvironment::WEnvironment()
doesAjax_(false),
doesCookies_(false),
hashInternalPaths_(false),
screenWidth_(-1),
screenHeight_(-1),
dpiScale_(1),
webGLsupported_(false),
timeZoneOffset_(0)
Expand All @@ -47,6 +49,8 @@ WEnvironment::WEnvironment(WebSession *session)
doesAjax_(false),
doesCookies_(false),
hashInternalPaths_(false),
screenWidth_(-1),
screenHeight_(-1),
dpiScale_(1),
webGLsupported_(false),
timeZoneOffset_(0)
Expand Down Expand Up @@ -233,8 +237,20 @@ void WEnvironment::enableAjax(const WebRequest& request)
}


screenWidth_=boost::lexical_cast<int>(*request.getParameter("scrW"));
screenHeight_=boost::lexical_cast<int>(*request.getParameter("scrH"));
const std::string *scrWE = request.getParameter("scrW");
if (scrWE) {
try {
screenWidth_ = boost::lexical_cast<int>(*scrWE);
} catch (boost::bad_lexical_cast &) {
}
}
const std::string *scrHE = request.getParameter("scrH");
if (scrHE) {
try {
screenHeight_ = boost::lexical_cast<int>(*scrHE);
} catch (boost::bad_lexical_cast &) {
}
}
}

void WEnvironment::setUserAgent(const std::string& userAgent)
Expand Down

0 comments on commit 2682e35

Please sign in to comment.