Skip to content

Child window fixes #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

Closed
wants to merge 61 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
e94eec3
add Lib.validate function:
etpinard Jun 23, 2016
9814edf
make is-valid colorscale array more strict
etpinard Jun 27, 2016
0b3040b
make string val type more strict:
etpinard Jun 27, 2016
a5bc7fe
add a few test cases for coerce + 'info_array'
etpinard Jun 27, 2016
6c1938c
add validateFunction for info_array
etpinard Jun 27, 2016
d304864
make 'dflt' a required opts for 'subplotid' val types
etpinard Jun 27, 2016
877077b
add validate function for 'subplotid' val types
etpinard Jun 27, 2016
1958dc6
add Plotly.validate:
etpinard Jun 27, 2016
f620a22
validate: add support for is isSubplotObj attributes
etpinard Jul 6, 2016
a2c52fe
validate: add 'container' error code
etpinard Jul 6, 2016
ad8db59
on 2nd thought, only coerce numbers to strings
etpinard Jul 12, 2016
09ed024
clean up is-valid-colorscale logic
etpinard Jul 12, 2016
a2f2160
make info_array validate func more strict:
etpinard Jul 12, 2016
5d7904e
Ensure the dragcover is rendered on the proper element.
nielsenb-jf Jul 12, 2016
d69b72d
Be consistent with use of ownerDocument.
nielsenb-jf Jul 12, 2016
02ac18f
Merge branch 'master' into coverslip_fix
nielsenb-jf Jul 12, 2016
54a6ed0
validate: flatten Plotly.validate output
etpinard Jul 13, 2016
f10706d
Ensure range sliders use the correct child document / window.
nielsenb-jf Jul 13, 2016
926bfd5
Merge pull request #697 from plotly/validate
etpinard Jul 13, 2016
0bec933
Properly resize plot based on plot parent window.
nielsenb-jf Jul 13, 2016
bac79fe
Merge branch 'master' into child_window_fixes
nielsenb-jf Jul 14, 2016
4dacf4d
Add a z-index to js-plotly-tester as a workaround for a chrome bug (#…
Jul 14, 2016
f96101c
Only inject Plotly CSS into the document a plot is being rendered in.
nielsenb-jf Jul 14, 2016
5f57f08
Don't hardcode CSS in plotcss_injector, instead use the generated style
nielsenb-jf Jul 14, 2016
2d8a0da
Merge pull request #745 from benjeffery/zindex
etpinard Jul 14, 2016
56f1182
When injecting styles, don't inject a duplicate selector.
nielsenb-jf Jul 14, 2016
0a77844
Fix formatting.
nielsenb-jf Jul 14, 2016
6fb9bfd
Don't keep a reference to the stylesheet in lib.
nielsenb-jf Jul 14, 2016
58cd9ae
Be consistent with comment style.
nielsenb-jf Jul 14, 2016
a1204ec
Merge branch 'master' into child_window_fixes
nielsenb-jf Jul 15, 2016
353272a
Merge branch 'child_window_fixes' into child_css
nielsenb-jf Jul 15, 2016
645541f
Fix formatting.
nielsenb-jf Jul 15, 2016
e19f8d8
Fix formatting.
nielsenb-jf Jul 15, 2016
212d5f8
Merge branch 'child_window_fixes' into child_css
nielsenb-jf Jul 15, 2016
f94accc
scattermapbox: override hash item if undefined (in case === 0)
etpinard Jul 15, 2016
7ae437b
Merge pull request #747 from plotly/mapbox-repeated-vals
etpinard Jul 15, 2016
a7760e5
Make injectStyles take the graph div (gd) as the argument.
nielsenb-jf Jul 15, 2016
bbf9300
Move addStyleRule code to injectStyles, delete lib.addStyleRule.
nielsenb-jf Jul 15, 2016
0a64d55
Only injectStyles if they haven't already been injected.
nielsenb-jf Jul 15, 2016
df43e70
Graph div now keeps a _document reference to the document it's render…
nielsenb-jf Jul 15, 2016
6aa4516
Keep linter happy.
nielsenb-jf Jul 15, 2016
9dff9cf
Merge branch 'master' into child_window_fixes
nielsenb-jf Jul 18, 2016
f14640d
Make sure graph div _document property is set for drag element tests.
nielsenb-jf Jul 18, 2016
4f01a05
Add some tests to make sure CSS injection is happening correctly.
nielsenb-jf Jul 18, 2016
9f72850
Move some common code to a helpers file so they can be used in tests.
nielsenb-jf Jul 18, 2016
6a47d7f
Use CSS helper functions.
nielsenb-jf Jul 18, 2016
cbe866f
Notifier now requires a graph div as the first argument.
nielsenb-jf Jul 19, 2016
75a5799
Placate the linter.
nielsenb-jf Jul 19, 2016
55181b9
Move CSS injection tests to plt_css_test.js.
nielsenb-jf Jul 19, 2016
5de7127
Use @src and @build macros.
nielsenb-jf Jul 19, 2016
9a47a38
Clean up linter complaints / typos.
nielsenb-jf Jul 19, 2016
25dc1d9
Cleanup _document and _plotCSSLoaded in plots.purge.
nielsenb-jf Jul 19, 2016
064c888
Add issue and pr template from CONTRIBUTING.md
rreusser Jul 19, 2016
cd7e8b3
Fix naming of PR template
rreusser Jul 19, 2016
8b03d39
Actually include the PR template
rreusser Jul 19, 2016
f8b35f8
Merge pull request #752 from plotly/issue-pr-templates
rreusser Jul 19, 2016
6cc5f5b
Guideline cleanup
rreusser Jul 19, 2016
2d95b41
Punctuation detail
rreusser Jul 19, 2016
6571586
Merge pull request #753 from plotly/issue-pr-template-fix
rreusser Jul 19, 2016
f115781
Merge branch 'notifier_fixes' into child_window_fixes
nielsenb-jf Jul 19, 2016
a91428f
Merge branch 'master' into child_window_fixes
nielsenb-jf Jul 20, 2016
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
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Thanks for your interest in plotly.js!

Before opening an issue, please search for existing and closed issues. If your problem or idea is not addressed yet, [please open a new issue](https://github.com/plotly/plotly.js/issues/new).

Bug reports must be accompanied with a reproducible example. We recommend using [codepen](http://codepen.io/), [jsfiddle](https://jsfiddle.net/) or [jsbin](https://jsbin.com) to share your example.

Note that GitHub issues are reserved for bug reports and feature requests only. Implementation questions should be asked on community.plot.ly (tagged [`plotly-js`](http://community.plot.ly/c/plotly-js)) or on Stack Overflow (tagged [`plotly`](https://stackoverflow.com/questions/tagged/plotly)).

Comments on GitHub issues or pull requests should add content to the discussions. Approbation comments such as *+1* or *I would like this feature to be implemented as well* will be deleted by the maintainers. Please use [GitHub reactions](https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments) instead.
7 changes: 7 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Thanks for your interest in plotly.js!

Developers are strongly encouraged to first make a PR to their own plotly.js fork and ask one of the maintainers to review the modifications there. Once the pull request is deemed satisfactory, the developer will be asked to make a pull request to the main plotly.js repo and may be asked to squash some commits before doing so.

Developers should `git rebase` their local branch off the latest `master` before opening a pull request.

Note that it is forbidden to force push (i.e. `git push -f`) to remote branches associated with opened pull requests. Force pushes make it hard for maintainers to keep track of updates. Therefore, if required, please `git merge master` into your PR branch instead of `git rebase master`.
33 changes: 2 additions & 31 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,11 @@

## Opening issues

Search for existing and closed issues. If your problem or idea is not addressed
yet, [please open a new issue](https://github.com/plotly/plotly.js/issues/new).

Bug reports must be accompanied with a reproducible example. We recommend using
[codepen](http://codepen.io/), [jsfiddle](https://jsfiddle.net/) or
[jsbin](https://jsbin.com) to share your example.

Note that GitHub issues are reserved for bug reports and feature requests only.
Implementation questions should be asked on
community.plot.ly (tagged [`plotly-js`](http://community.plot.ly/c/plotly-js)) or on Stack Overflow (tagged
[`plotly`](https://stackoverflow.com/questions/tagged/plotly)).

Comments on GitHub issues or pull requests should add content to the discussions.
Approbation comments such as *+1* or *I would like this feature to be implemented as well*
will be deleted by the maintainers. Please use
[GitHub reactions](https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments)
instead.
Please read the [issue guidelines](./.github/ISSUE_TEMPLATE.md).

## Making pull requests

Developers are strongly encouraged to first make a PR to their own plotly.js
fork and ask one of the maintainers to review the modifications there. Once the
pull request is deemed satisfactory, the developer will be asked to make a pull
request to the main plotly.js repo and may be asked to squash some commits
before doing so.

Developers should `git rebase` their local branch off the latest `master` before
opening a pull request.

Note that it is forbidden to force push (i.e. `git push -f`) to remote branches
associated with opened pull requests. Force pushes make it hard for maintainers
to keep track of updates. Therefore, if required, please
`git merge master` into your PR branch instead of `git rebase master`.

Please read the [pull request guidelines](./.github/PULL_REQUEST_TEMPLATE.md).

## GitHub labels

Expand Down
8 changes: 1 addition & 7 deletions build/plotcss.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

var Plotly = require('../src/plotly');
var rules = {
"X,X div": "font-family:'Open Sans', verdana, arial, sans-serif;margin:0;padding:0;",
"X input,X button": "font-family:'Open Sans', verdana, arial, sans-serif;",
Expand Down Expand Up @@ -54,9 +53,4 @@ var rules = {
"Y .notifier-close:hover": "color:#444;text-decoration:none;cursor:pointer;"
};

for(var selector in rules) {
var fullSelector = selector.replace(/^,/,' ,')
.replace(/X/g, '.js-plotly-plot .plotly')
.replace(/Y/g, '.plotly-notifier');
Plotly.Lib.addStyleRule(fullSelector, rules[selector]);
}
module.exports = rules;
32 changes: 17 additions & 15 deletions src/components/colorscale/is_valid_scale_array.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ var tinycolor = require('tinycolor2');


module.exports = function isValidScaleArray(scl) {
var isValid = true,
highestVal = 0,
si;

if(!Array.isArray(scl)) return false;
else {
if(+scl[0][0] !== 0 || +scl[scl.length - 1][0] !== 1) return false;
for(var i = 0; i < scl.length; i++) {
si = scl[i];
if(si.length !== 2 || +si[0] < highestVal || !tinycolor(si[1]).isValid()) {
isValid = false;
break;
}
highestVal = +si[0];
var highestVal = 0;

if(!Array.isArray(scl) || scl.length < 2) return false;

if(!scl[0] || !scl[scl.length - 1]) return false;

if(+scl[0][0] !== 0 || +scl[scl.length - 1][0] !== 1) return false;

for(var i = 0; i < scl.length; i++) {
var si = scl[i];

if(si.length !== 2 || +si[0] < highestVal || !tinycolor(si[1]).isValid()) {
return false;
}
return isValid;

highestVal = +si[0];
}

return true;
};
10 changes: 5 additions & 5 deletions src/components/dragelement/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ dragElement.init = function init(options) {

if(options.prepFn) options.prepFn(e, startX, startY);

dragCover = coverSlip();
dragCover = coverSlip(gd);

dragCover.onmousemove = onMove;
dragCover.onmouseup = onDone;
Expand Down Expand Up @@ -139,7 +139,7 @@ dragElement.init = function init(options) {
if(options.doneFn) options.doneFn(gd._dragged, numClicks);

if(!gd._dragged) {
var e2 = document.createEvent('MouseEvents');
var e2 = gd._document.createEvent('MouseEvents');
e2.initEvent('click', true, true);
initialTarget.dispatchEvent(e2);
}
Expand All @@ -159,8 +159,8 @@ dragElement.init = function init(options) {
options.element.style.pointerEvents = 'all';
};

function coverSlip() {
var cover = document.createElement('div');
function coverSlip(gd) {
var cover = gd._document.createElement('div');

cover.className = 'dragcover';
var cStyle = cover.style;
Expand All @@ -172,7 +172,7 @@ function coverSlip() {
cStyle.zIndex = 999999999;
cStyle.background = 'none';

document.body.appendChild(cover);
gd._document.body.appendChild(cover);

return cover;
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ drawing.makeTester = function(gd) {
left: '-10000px',
top: '-10000px',
width: '9000px',
height: '9000px'
height: '9000px',
'z-index': '1'
});

// browsers differ on how they describe the bounding rect of
Expand Down
8 changes: 4 additions & 4 deletions src/components/modebar/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ modeBarButtons.toImage = {
click: function(gd) {
var format = 'png';

Lib.notifier('Taking snapshot - this may take a few seconds', 'long');
Lib.notifier(gd, 'Taking snapshot - this may take a few seconds', 'long');

if(Lib.isIE()) {
Lib.notifier('IE only supports svg. Changing format to svg.', 'long');
Lib.notifier(gd, 'IE only supports svg. Changing format to svg.', 'long');
format = 'svg';
}

downloadImage(gd, {'format': format})
.then(function(filename) {
Lib.notifier('Snapshot succeeded - ' + filename, 'long');
Lib.notifier(gd, 'Snapshot succeeded - ' + filename, 'long');
})
.catch(function() {
Lib.notifier('Sorry there was a problem downloading your snapshot!', 'long');
Lib.notifier(gd, 'Sorry there was a problem downloading your snapshot!', 'long');
});
}
};
Expand Down
34 changes: 17 additions & 17 deletions src/components/rangeslider/create_slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function createSlider(gd) {
var minStart = 0,
maxStart = width;

var slider = document.createElementNS(svgNS, 'g');
var slider = gd._document.createElementNS(svgNS, 'g');
helpers.setAttributes(slider, {
'class': 'range-slider',
'data-min': minStart,
Expand All @@ -43,7 +43,7 @@ module.exports = function createSlider(gd) {
});


var sliderBg = document.createElementNS(svgNS, 'rect'),
var sliderBg = gd._document.createElementNS(svgNS, 'rect'),
borderCorrect = options.borderwidth % 2 === 0 ? options.borderwidth : options.borderwidth - 1;
helpers.setAttributes(sliderBg, {
'fill': options.bgcolor,
Expand All @@ -56,7 +56,7 @@ module.exports = function createSlider(gd) {
});


var maskMin = document.createElementNS(svgNS, 'rect');
var maskMin = gd._document.createElementNS(svgNS, 'rect');
helpers.setAttributes(maskMin, {
'x': 0,
'width': minStart,
Expand All @@ -65,7 +65,7 @@ module.exports = function createSlider(gd) {
});


var maskMax = document.createElementNS(svgNS, 'rect');
var maskMax = gd._document.createElementNS(svgNS, 'rect');
helpers.setAttributes(maskMax, {
'x': maxStart,
'width': width - maxStart,
Expand All @@ -74,9 +74,9 @@ module.exports = function createSlider(gd) {
});


var grabberMin = document.createElementNS(svgNS, 'g'),
grabAreaMin = document.createElementNS(svgNS, 'rect'),
handleMin = document.createElementNS(svgNS, 'rect');
var grabberMin = gd._document.createElementNS(svgNS, 'g'),
grabAreaMin = gd._document.createElementNS(svgNS, 'rect'),
handleMin = gd._document.createElementNS(svgNS, 'rect');
helpers.setAttributes(grabberMin, { 'transform': 'translate(' + (minStart - handleWidth - 1) + ')' });
helpers.setAttributes(grabAreaMin, {
'width': 10,
Expand All @@ -97,9 +97,9 @@ module.exports = function createSlider(gd) {
helpers.appendChildren(grabberMin, [handleMin, grabAreaMin]);


var grabberMax = document.createElementNS(svgNS, 'g'),
grabAreaMax = document.createElementNS(svgNS, 'rect'),
handleMax = document.createElementNS(svgNS, 'rect');
var grabberMax = gd._document.createElementNS(svgNS, 'g'),
grabAreaMax = gd._document.createElementNS(svgNS, 'rect'),
handleMax = gd._document.createElementNS(svgNS, 'rect');
helpers.setAttributes(grabberMax, { 'transform': 'translate(' + maxStart + ')' });
helpers.setAttributes(grabAreaMax, {
'width': 10,
Expand All @@ -120,7 +120,7 @@ module.exports = function createSlider(gd) {
helpers.appendChildren(grabberMax, [handleMax, grabAreaMax]);


var slideBox = document.createElementNS(svgNS, 'rect');
var slideBox = gd._document.createElementNS(svgNS, 'rect');
helpers.setAttributes(slideBox, {
'x': minStart,
'width': maxStart - minStart,
Expand All @@ -137,8 +137,8 @@ module.exports = function createSlider(gd) {
minVal = slider.getAttribute('data-min'),
maxVal = slider.getAttribute('data-max');

window.addEventListener('mousemove', mouseMove);
window.addEventListener('mouseup', mouseUp);
gd._document.defaultView.addEventListener('mousemove', mouseMove);
gd._document.defaultView.addEventListener('mouseup', mouseUp);

function mouseMove(e) {
var delta = +e.clientX - startX,
Expand Down Expand Up @@ -189,8 +189,8 @@ module.exports = function createSlider(gd) {
}

function mouseUp() {
window.removeEventListener('mousemove', mouseMove);
window.removeEventListener('mouseup', mouseUp);
gd._document.defaultView.removeEventListener('mousemove', mouseMove);
gd._document.defaultView.removeEventListener('mouseup', mouseUp);
slider.style.cursor = 'auto';
}
});
Expand Down Expand Up @@ -222,8 +222,8 @@ module.exports = function createSlider(gd) {

function setDataRange(dataMin, dataMax) {

if(window.requestAnimationFrame) {
window.requestAnimationFrame(function() {
if(gd._document.defaultView.requestAnimationFrame) {
gd._document.defaultView.requestAnimationFrame(function() {
Plotly.relayout(gd, 'xaxis.range', [dataMin, dataMax]);
});
} else {
Expand Down
1 change: 1 addition & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ exports.setPlotConfig = require('./plot_api/set_plot_config');
exports.register = Plotly.register;
exports.toImage = require('./plot_api/to_image');
exports.downloadImage = require('./snapshot/download');
exports.validate = require('./plot_api/validate');

// plot icons
exports.Icons = require('../build/ploticon');
Expand Down
38 changes: 38 additions & 0 deletions src/css/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright 2012-2016, 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';

// expands a plotcss selector
exports.buildFullSelector = function buildFullSelector(selector) {
var fullSelector = selector.replace(/,/, ', ')
.replace(/:after/g, '::after')
.replace(/:before/g, '::before')
.replace(/X/g, '.js-plotly-plot .plotly')
.replace(/Y/g, '.plotly-notifier');

return fullSelector;
};

// Gets all the rules currently attached to the document
exports.getAllRuleSelectors = function getAllRuleSelectors(sourceDocument) {
var allSelectors = [];

for(var i = 0; i < sourceDocument.styleSheets.length; i++) {
var styleSheet = sourceDocument.styleSheets[i];

for(var j = 0; j < styleSheet.cssRules.length; j++) {
var cssRule = styleSheet.cssRules[j];

allSelectors.push(cssRule.selectorText);
}
}

return allSelectors;
};
52 changes: 52 additions & 0 deletions src/css/plotcss_injector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright 2012-2016, 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 helpers = require('./helpers');
var lib = require('../lib');
var plotcss = require('../../build/plotcss');

// Inject styling information into the document containing the graph div
module.exports = function injectStyles(gd) {
// If the graph div has already been styled, bail
if(gd._plotCSSLoaded) return;

var targetSelectors = helpers.getAllRuleSelectors(gd._document);
var targetStyleSheet = null;

if(gd._document.getElementsByTagName('style').length === 0) {
var style = gd._document.createElement('style');
// WebKit hack :(
style.appendChild(gd._document.createTextNode(''));
gd._document.head.appendChild(style);
targetStyleSheet = style.sheet;
}
else {
// Just grab the first style element to append to
targetStyleSheet = gd._document.getElementsByTagName('style')[0].sheet;
}

for(var selector in plotcss) {
var fullSelector = helpers.buildFullSelector(selector);

// Don't duplicate selectors
if(targetSelectors.indexOf(fullSelector) === -1) {
if(targetStyleSheet.insertRule) {
targetStyleSheet.insertRule(fullSelector + '{' + plotcss[selector] + '}', 0);
}
else if(targetStyleSheet.addRule) {
targetStyleSheet.addRule(fullSelector, plotcss[selector], 0);
}
else lib.warn('injectStyles failed');
}
}

gd._plotCSSLoaded = true;
};
Loading