Skip to content

Add events to polar plots #1

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ function plotPolar(gd, data, layout) {
gd._context.setBackground(gd, gd._fullLayout.paper_bgcolor);
Plots.addLinks(gd);

return Promise.resolve();
return Promise.resolve(gd);
}

// convenience function to force a full redraw, mostly for use by plotly.js
Expand Down
2 changes: 2 additions & 0 deletions src/plots/polar/micropolar_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var Color = require('../../components/color');
var micropolar = require('./micropolar');
var UndoManager = require('./undo_manager');
var extendDeepAll = Lib.extendDeepAll;
var initInteractions = require('./polar_interact');

var manager = module.exports = {};

Expand All @@ -38,6 +39,7 @@ manager.framework = function(_gd) {
_gd.data = config.data;
_gd.layout = config.layout;
manager.fillLayout(_gd);
initInteractions(_gd);
return config;
}
exports.isPolar = true;
Expand Down
57 changes: 57 additions & 0 deletions src/plots/polar/polar_interact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var d3 = require('d3');

module.exports = function initInteractions(gd) {
var fullLayout = gd._fullLayout;

fullLayout._paper.selectAll('.chart-group .geometry')
.each(function(d, i) {
var curveNumber = i;
d3.select(this).selectAll('path')
.each(function(d, i) {
var valueIndex = i;

d3.select(this).on('mouseout', function(pt) {
var args = {
event: d3.event,
points: [pt],
curveNumber: curveNumber,
pointNumber: valueIndex,
};

gd.emit('plotly_unhover', args);
});

d3.select(this).on('mouseover', function(pt) {
var args = {
event: d3.event,
points: [pt],
curveNumber: curveNumber,
pointNumber: valueIndex,
};

gd.emit('plotly_hover', args);
});

d3.select(this).on('click', function(pt) {
var args = {
event: d3.event,
points: [pt],
curveNumber: curveNumber,
pointNumber: valueIndex,
};
gd.emit('plotly_click', args);
});
});
});
};
1 change: 1 addition & 0 deletions tasks/util/strict_d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = transformTools.makeRequireTransform('requireTransform',

if(pathIn === 'd3' && opts.file !== pathToStrictD3Module) {
pathOut = 'require(\'' + pathToStrictD3Module + '\')';
pathOut = pathOut.replace(/\\/g, '/');
}

if(pathOut) return cb(null, pathOut);
Expand Down