Skip to content

Child window revert #829

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

Merged
merged 2 commits into from
Aug 5, 2016
Merged
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
8 changes: 7 additions & 1 deletion build/plotcss.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'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 @@ -53,4 +54,9 @@ var rules = {
"Y .notifier-close:hover": "color:#444;text-decoration:none;cursor:pointer;"
};

module.exports = rules;
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]);
}
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(gd);
dragCover = coverSlip();

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 = gd._document.createEvent('MouseEvents');
var e2 = 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(gd) {
var cover = gd._document.createElement('div');
function coverSlip() {
var cover = document.createElement('div');

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

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

return cover;
}
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(gd, 'Taking snapshot - this may take a few seconds', 'long');
Lib.notifier('Taking snapshot - this may take a few seconds', 'long');

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

downloadImage(gd, {'format': format})
.then(function(filename) {
Lib.notifier(gd, 'Snapshot succeeded - ' + filename, 'long');
Lib.notifier('Snapshot succeeded - ' + filename, 'long');
})
.catch(function() {
Lib.notifier(gd, 'Sorry there was a problem downloading your snapshot!', 'long');
Lib.notifier('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 = gd._document.createElementNS(svgNS, 'g');
var slider = 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 = gd._document.createElementNS(svgNS, 'rect'),
var sliderBg = 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 = gd._document.createElementNS(svgNS, 'rect');
var maskMin = document.createElementNS(svgNS, 'rect');
helpers.setAttributes(maskMin, {
'x': 0,
'width': minStart,
Expand All @@ -65,7 +65,7 @@ module.exports = function createSlider(gd) {
});


var maskMax = gd._document.createElementNS(svgNS, 'rect');
var maskMax = 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 = gd._document.createElementNS(svgNS, 'g'),
grabAreaMin = gd._document.createElementNS(svgNS, 'rect'),
handleMin = gd._document.createElementNS(svgNS, 'rect');
var grabberMin = document.createElementNS(svgNS, 'g'),
grabAreaMin = document.createElementNS(svgNS, 'rect'),
handleMin = 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 = gd._document.createElementNS(svgNS, 'g'),
grabAreaMax = gd._document.createElementNS(svgNS, 'rect'),
handleMax = gd._document.createElementNS(svgNS, 'rect');
var grabberMax = document.createElementNS(svgNS, 'g'),
grabAreaMax = document.createElementNS(svgNS, 'rect'),
handleMax = 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 = gd._document.createElementNS(svgNS, 'rect');
var slideBox = 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');

gd._document.defaultView.addEventListener('mousemove', mouseMove);
gd._document.defaultView.addEventListener('mouseup', mouseUp);
window.addEventListener('mousemove', mouseMove);
window.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() {
gd._document.defaultView.removeEventListener('mousemove', mouseMove);
gd._document.defaultView.removeEventListener('mouseup', mouseUp);
window.removeEventListener('mousemove', mouseMove);
window.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(gd._document.defaultView.requestAnimationFrame) {
gd._document.defaultView.requestAnimationFrame(function() {
if(window.requestAnimationFrame) {
window.requestAnimationFrame(function() {
Plotly.relayout(gd, 'xaxis.range', [dataMin, dataMax]);
});
} else {
Expand Down
27 changes: 24 additions & 3 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ lib.log = loggersModule.log;
lib.warn = loggersModule.warn;
lib.error = loggersModule.error;

var cssModule = require('./plotcss_utils');
lib.injectStyles = cssModule.injectStyles;

lib.notifier = require('./notifier');

/**
Expand Down Expand Up @@ -392,6 +389,30 @@ lib.removeElement = function(el) {
if(elParent) elParent.removeChild(el);
};

/**
* for dynamically adding style rules
* makes one stylesheet that contains all rules added
* by all calls to this function
*/
lib.addStyleRule = function(selector, styleString) {
if(!lib.styleSheet) {
var style = document.createElement('style');
// WebKit hack :(
style.appendChild(document.createTextNode(''));
document.head.appendChild(style);
lib.styleSheet = style.sheet;
}
var styleSheet = lib.styleSheet;

if(styleSheet.insertRule) {
styleSheet.insertRule(selector + '{' + styleString + '}', 0);
}
else if(styleSheet.addRule) {
styleSheet.addRule(selector, styleString, 0);
}
else lib.warn('addStyleRule failed');
};

lib.getTranslate = function(element) {

var re = /.*\btranslate\((\d*\.?\d*)[^\d]*(\d*\.?\d*)[^\d].*/,
Expand Down
5 changes: 2 additions & 3 deletions src/lib/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ var NOTEDATA = [];

/**
* notifier
* @param {object} gd figure Object
* @param {String} text The person's user name
* @param {Number} [delay=1000] The delay time in milliseconds
* or 'long' which provides 2000 ms delay time.
* @return {undefined} this function does not return a value
*/
module.exports = function(gd, text, displayLength) {
module.exports = function(text, displayLength) {
if(NOTEDATA.indexOf(text) !== -1) return;

NOTEDATA.push(text);
Expand All @@ -31,7 +30,7 @@ module.exports = function(gd, text, displayLength) {
if(isNumeric(displayLength)) ts = displayLength;
else if(displayLength === 'long') ts = 3000;

var notifierContainer = d3.select(gd._document.body)
var notifierContainer = d3.select('body')
.selectAll('.plotly-notifier')
.data([0]);
notifierContainer.enter()
Expand Down
81 changes: 0 additions & 81 deletions src/lib/plotcss_utils.js

This file was deleted.

16 changes: 4 additions & 12 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ Plotly.plot = function(gd, data, layout, config) {

gd = getGraphDiv(gd);

// Get the document the graph div lives in, so we can make sure things like
// drag covers are attached to the correct document
gd._document = gd.ownerDocument || window.document;

// Inject the plot styles into the document where we're plotting, bails if
// already styled
Lib.injectStyles(gd);

// Events.init is idempotent and bails early if gd has already been init'd
Events.init(gd);

Expand Down Expand Up @@ -2575,12 +2567,12 @@ function plotAutoSize(gd, aobj) {
// embedded in an iframe - just take the full iframe size
// if we get to this point, with no aspect ratio restrictions
if(gd._context.fillFrame) {
newWidth = gd._document.defaultView.innerWidth;
newHeight = gd._document.defaultView.innerHeight;
newWidth = window.innerWidth;
newHeight = window.innerHeight;

// somehow we get a few extra px height sometimes...
// just hide it
gd._document.body.style.overflow = 'hidden';
document.body.style.overflow = 'hidden';
}
else if(isNumeric(context.frameMargins) && context.frameMargins > 0) {
var reservedMargins = calculateReservedMargins(gd._boundingBoxMargins),
Expand All @@ -2597,7 +2589,7 @@ function plotAutoSize(gd, aobj) {
// provide height and width for the container div,
// specify size in layout, or take the defaults,
// but don't enforce any ratio restrictions
computedStyle = gd._document.defaultView.getComputedStyle(gd);
computedStyle = window.getComputedStyle(gd);
newHeight = parseFloat(computedStyle.height) || fullLayout.height;
newWidth = parseFloat(computedStyle.width) || fullLayout.width;
}
Expand Down
3 changes: 3 additions & 0 deletions src/plotly.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ var Lib = exports.Lib = require('./lib');
exports.util = require('./lib/svg_text_utils');
exports.Queue = require('./lib/queue');

// plot css
require('../build/plotcss');

// configuration
exports.MathJaxConfig = require('./fonts/mathjax_config');
exports.defaultConfig = require('./plot_api/plot_config');
Expand Down
2 changes: 1 addition & 1 deletion src/plots/cartesian/dragbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
dragTail(zoomMode);

if(SHOWZOOMOUTTIP && gd.data && gd._context.showTips) {
Lib.notifier(gd, 'Double-click to<br>zoom back out', 'long');
Lib.notifier('Double-click to<br>zoom back out', 'long');
SHOWZOOMOUTTIP = false;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ module.exports = function setConvert(ax) {

if(!isFinite(ax._m) || !isFinite(ax._b)) {
Lib.notifier(
ax._gd,
'Something went wrong with axis scaling',
'long');
ax._gd._replotting = false;
Expand Down
Loading