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

New-WordCloud hangs in MyBinder (Dotnet Interactive) #36

Open
vexx32 opened this issue Mar 16, 2020 · 3 comments
Open

New-WordCloud hangs in MyBinder (Dotnet Interactive) #36

vexx32 opened this issue Mar 16, 2020 · 3 comments
Labels
🐛 bug Confirmed bugs or pull requests resolving them 🏳 help wanted Any and all help is more than welcome

Comments

@vexx32
Copy link
Owner

vexx32 commented Mar 16, 2020

Currently the module is not usable in Jupyter Notebooks. Unsure as to exactly why this is at the moment.

No progress bars appear, so I can only assume it's hanging somewhere during text processing, possibly as a result of it spinning out different threads to handle text processing and waiting on them.

More investigation needed.

/cc @TylerLeonhardt

@vexx32 vexx32 added 🐛 bug Confirmed bugs or pull requests resolving them 🏳 help wanted Any and all help is more than welcome labels Mar 16, 2020
@vexx32
Copy link
Owner Author

vexx32 commented Mar 17, 2020

After installing v3.0.1 and showing the debug messages, it looks like the cmdlet is hanging somewhere in this block of code:

WriteDebug($"Adding focus word '{FocusWord}' to the dictionary.");
wordScaleDictionary[FocusWord] = highestWordFreq *= FOCUS_WORD_SCALE;
}
sortedWordList = new List<string>(SortWordList(wordScaleDictionary, MaxRenderedWords));
try
{
if (MyInvocation.BoundParameters.ContainsKey(nameof(BackgroundImage)))
{
WriteDebug($"Importing background image from '{_backgroundFullPath}'.");
backgroundImage = SKBitmap.Decode(_backgroundFullPath);
drawableBounds = new SKRectI(0, 0, backgroundImage.Width, backgroundImage.Height);
}
else
{
drawableBounds = new SKRectI(0, 0, ImageSize.Width, ImageSize.Height);
}
wordPath = new SKPath();
clipRegion = new SKRegion();
clipRegion.SetRect(SKRectI.Round(drawableBounds));
_fontScale = FontScale(
clipRegion.Bounds,
WordScale,
wordScaleDictionary.Values.Average(),
Math.Min(wordScaleDictionary.Count, MaxRenderedWords),
Typeface);
scaledWordSizes = new Dictionary<string, float>(
sortedWordList.Count,
StringComparer.OrdinalIgnoreCase);
maxWordWidth = AllowRotation == WordOrientations.None
? drawableBounds.Width * MAX_WORD_WIDTH_PERCENT
: Math.Max(drawableBounds.Width, drawableBounds.Height) * MAX_WORD_WIDTH_PERCENT;
using SKPaint brush = new SKPaint
{
Typeface = Typeface
};
SKRect rect = SKRect.Empty;
float adjustedWordSize;
bool retry;
do
{
// Pre-test and adjust global scale based on the largest word.
retry = false;
adjustedWordSize = ScaleWordSize(
wordScaleDictionary[sortedWordList[0]],
_fontScale,
wordScaleDictionary);
brush.NextWord(adjustedWordSize, StrokeWidth);
var textRect = brush.GetTextPath(sortedWordList[0], 0, 0).ComputeTightBounds();
var adjustedTextWidth = textRect.Width * (1 + _paddingMultiplier) + StrokeWidth * 2 * STROKE_BASE_SCALE;
if (adjustedTextWidth > maxWordWidth
|| textRect.Width * textRect.Height < drawableBounds.Width * drawableBounds.Height * MAX_WORD_AREA_PERCENT)
{
retry = true;
_fontScale *= 1.05f;
}
} while (retry);
// Apply manual scaling from the user
_fontScale *= WordScale;
WriteDebug($"Global font scale: {_fontScale}");

(The first WriteDebug() call shows, the second is never reached.)

@vexx32
Copy link
Owner Author

vexx32 commented Mar 17, 2020

I suspect the issue is the SKRegion object as allocating the memory for that is most likely to be the one that causes issues. However, SKRect has been a problem point in the past, so all bets are really off.

As far as I can tell, it seems like it's hanging somewhere on the native library calls used by SkiaSharp, and I don't know nearly enough to understand why.

I'm reasonably confident it's not something I can fix, but it's possible we might find a workaround sooner or later.

@TylerLeonhardt
Copy link
Contributor

This seems to really just be the container... not Jupyter Notebooks specifically.

@vexx32 vexx32 changed the title New-WordCloud hangs in Jupyter Notebooks New-WordCloud hangs in MyBinder (Dotnet Interactive) Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Confirmed bugs or pull requests resolving them 🏳 help wanted Any and all help is more than welcome
Projects
None yet
Development

No branches or pull requests

2 participants