Skip to content
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

Namespaced tooltips for multiple wordclouds #32

Merged
merged 3 commits into from
Jan 14, 2018
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
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.Rproj.user
.Rhistory
.RData
wordcloud2.Rproj
.Rproj.user
.Rhistory
.RData
wordcloud2.Rproj
.DS_Store
3 changes: 1 addition & 2 deletions R/wordcloud2.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ wordcloud2 <- function(data,
)


chart = htmlwidgets::createWidget("wordcloud2", settings,
htmlwidgets::createWidget("wordcloud2", settings,
width = widgetsize[1],
height = widgetsize[2],
sizingPolicy = htmlwidgets::sizingPolicy(
Expand All @@ -158,7 +158,6 @@ wordcloud2 <- function(data,
browser.padding = 0,
browser.fill = TRUE
))
chart
}


Expand Down
29 changes: 13 additions & 16 deletions inst/htmlwidgets/lib/wordcloud2-0.0.1/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,48 @@
function newlabel(el){
var newDiv = document.createElement("div");
var newSpan = document.createElement("span");
newDiv.id = 'wcLabel';
newSpan.id = "wcSpan";
var id = el.id
newDiv.id = id + "wcLabel";
newDiv.className += "wcLabel";
newSpan.id = id + "wcSpan";
newSpan.className += "wcSpan";
el.appendChild(newDiv);
document.getElementById("wcLabel").appendChild(newSpan);
document.getElementById(id + "wcLabel").appendChild(newSpan);
}

// hover function
function cv_handleHover(item, dimension, evt) {
var el = document.getElementById("wcLabel");
var id = evt.path[1].id
var el = document.getElementById(id + "wcLabel");
var target = evt.target || evt.srcElement;
if (!item) {
el.setAttribute('hidden', true);

return;
}

el.removeAttribute('hidden');
// console.log(evt.srcElement.offsetLeft);

el.style.left = dimension.x + evt.srcElement.offsetLeft + 'px';
el.style.top = dimension.y + evt.srcElement.offsetTop + 'px';
el.style.left = dimension.x + target.offsetLeft + 'px';
el.style.top = dimension.y + target.offsetTop + 'px';
el.style.width = dimension.w + 'px';
el.style.height = dimension.h + 'px';

this.hoverDimension = dimension;

document.getElementById("wcSpan").setAttribute(
document.getElementById(id + "wcSpan").setAttribute(
'data-l10n-args', JSON.stringify({ word: item[0], count: item[1] }));
document.getElementById("wcSpan").innerHTML =item[0]+":" + item[1];
document.getElementById(id + "wcSpan").innerHTML =item[0]+":" + item[1];

}

//mask function
function maskInit(el,x){
console.log(1)
str = x.figBase64;
//console.log(str)
var newImg = new Image();
newImg.src = str;
newImg.style.position = 'absolute';
newImg.style.left = 0;
// console.log(el.clientHeight);
newImg.width = el.clientWidth;
newImg.height = el.clientHeight;
// maskCanvas = init(el, x, newImg);
Expand All @@ -55,7 +56,6 @@ function maskInit(el,x){
var imageData = ctx.getImageData(0, 0, maskCanvas.width, maskCanvas.height);
var newImageData = ctx.createImageData(imageData);
// M = 0
console.log(imageData.data.length);
for (var i = 0; i < imageData.data.length; i += 4) {
var tone = imageData.data[i] +
imageData.data[i + 1] +
Expand Down Expand Up @@ -84,12 +84,10 @@ function maskInit(el,x){
bctx.fillStyle = x.backgroundColor || '#fff';
bctx.fillRect(0, 0, 1, 1);
var bgPixel = bctx.getImageData(0, 0, 1, 1).data;
console.log(bgPixel);
var maskCanvasScaled = document.createElement('canvas');
maskCanvasScaled.width = el.clientWidth;
maskCanvasScaled.height = el.clientHeight;
ctx = maskCanvasScaled.getContext('2d');
console.log(maskCanvasScaled);
ctx.drawImage(maskCanvas,
0, 0, maskCanvas.width, maskCanvas.height);

Expand Down Expand Up @@ -136,4 +134,3 @@ function maskInit(el,x){
abortThreshold: 3000
});
}

4 changes: 2 additions & 2 deletions inst/htmlwidgets/lib/wordcloud2-0.0.1/wordcloud.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

#wcLabel {
.wcLabel {
position: absolute;
border: 2px solid #fff;
box-shadow: 0 0 4px 0 #008;
padding: 2px;
/*margin: -4px 0 0 -4px;*/
pointer-events: none; }

#wcSpan {
.wcSpan {
position: absolute;
top: 100%;
left: 0;
Expand Down