Skip to content
Open
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
46 changes: 32 additions & 14 deletions src/Wt/Chart/WCartesianChart.C
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,7 @@ WCartesianChart::WCartesianChart()
onDemandLoadingEnabled_(false),
loadingBackground_(StandardColor::LightGray),
cObjCreated_(false),
hasAjax_(false),
jsSeriesSelected_(this, "seriesSelected"),
loadTooltip_(this, "loadTooltip")
{
Expand Down Expand Up @@ -1425,6 +1426,7 @@ WCartesianChart::WCartesianChart(ChartType type)
onDemandLoadingEnabled_(false),
loadingBackground_(StandardColor::LightGray),
cObjCreated_(false),
hasAjax_(false),
jsSeriesSelected_(this, "seriesSelected"),
loadTooltip_(this, "loadTooltip")
{
Expand All @@ -1442,6 +1444,33 @@ WCartesianChart::~WCartesianChart()
}
}

void WCartesianChart::enableAjax()
{
WAbstractChart::enableAjax();
if (!hasAjax_) {
enableEventHandlers();
}
hasAjax_ = true;
}

// Needs ajax enabled
void WCartesianChart::enableEventHandlers()
{
mouseWentDown().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.mouseDown(o, e);}}");
mouseWentUp().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.mouseUp(o, e);}}");
mouseDragged().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.mouseDrag(o, e);}}");
mouseMoved().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.mouseMove(o, e);}}");
mouseWheel().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.mouseWheel(o, e);}}");
mouseWentOut().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.mouseOut(o, e);}}");
touchStarted().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.touchStart(o, e);}}");
touchEnded().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.touchEnd(o, e);}}");
touchMoved().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.touchMoved(o, e);}}");
clicked().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.clicked(o, e);}}");
jsSeriesSelected_.connect(this, &WCartesianChart::jsSeriesSelected);
loadTooltip_.connect(this, &WCartesianChart::loadTooltip);
voidEventSignal("dragstart", true)->preventDefaultAction(true);
}

void WCartesianChart::init()
{
setPalette(std::make_shared<WStandardPalette>(PaletteFlavour::Muted));
Expand Down Expand Up @@ -1475,20 +1504,9 @@ void WCartesianChart::init()
yAxes_[i].transformChanged.reset(new JSignal<>(this, "yTransformChanged" + std::to_string(i)));
}

if (WApplication::instance() && WApplication::instance()->environment().ajax()) {
mouseWentDown().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.mouseDown(o, e);}}");
mouseWentUp().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.mouseUp(o, e);}}");
mouseDragged().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.mouseDrag(o, e);}}");
mouseMoved().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.mouseMove(o, e);}}");
mouseWheel().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.mouseWheel(o, e);}}");
mouseWentOut().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.mouseOut(o, e);}}");
touchStarted().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.touchStart(o, e);}}");
touchEnded().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.touchEnd(o, e);}}");
touchMoved().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.touchMoved(o, e);}}");
clicked().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.clicked(o, e);}}");
jsSeriesSelected_.connect(this, &WCartesianChart::jsSeriesSelected);
loadTooltip_.connect(this, &WCartesianChart::loadTooltip);
voidEventSignal("dragstart", true)->preventDefaultAction(true);
hasAjax_ = WApplication::instance() && WApplication::instance()->environment().ajax();
if (hasAjax_) {
enableEventHandlers();
}

wheelActions_[KeyboardModifier::None] = InteractiveAction::PanMatching;
Expand Down
3 changes: 3 additions & 0 deletions src/Wt/Chart/WCartesianChart.h
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,7 @@ class WT_API WCartesianChart : public WAbstractChart
bool onDemandLoadingEnabled_;
WBrush loadingBackground_;
bool cObjCreated_;
bool hasAjax_;

Signal<const WDataSeries *, WPointF> seriesSelected_;
JSignal<double, double> jsSeriesSelected_;
Expand Down Expand Up @@ -1764,6 +1765,8 @@ class WT_API WCartesianChart : public WAbstractChart
mutable std::vector<BarTooltip> barTooltips_;

void init();
void enableEventHandlers();
virtual void enableAjax() override;
static std::string wheelActionsToJson(WheelActions wheelActions);

static WColor lightenColor(const WColor &in);
Expand Down