-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Plotting in child window #764
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
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, would you mind moving this file and
src/css/plotcss_injector.js
tosrc/lib/
. I would prefer leaving thesrc/css/
directory for css (and scss) files only.I would also vote for merging the two files into one and naming it something like
plotcss_utils.js
Sorry for the confusion.