Coder Social home page Coder Social logo

pswordcloud's Introduction

PSWordCloud

Create pretty word clouds with PowerShell!

Installation

Install-Module PSWordCloud

Usage

# Simply provide a list of words (in this case, supplied with a simple hashtable depicting words and
# their relative sizes.

New-WordCloud -Path .\wordcloud.svg -Typeface Consolas -WordSizes @{
    dragon = Get-Random -Maximum 10 -Minimum 1 
    rabbit = Get-Random -Maximum 15 -Minimum 1 
    horse = Get-Random -Maximum 18 -Minimum 1 
    cow = Get-Random -Maximum 20 -Minimum 1 
    cat = Get-Random -Maximum 8 -Minimum 1 
    fox = Get-Random -Maximum 12 -Minimum 1 
}

# Alternately, get a chunk of text (doesn't matter where), and pipe it directly to the cmdlet to create
# a word-frequency word cloud.
Get-ClipBoard | New-WordCloud -Path .\wordcloud.svg -Typeface Georgia

Get-Content .\words.txt | New-WordCloud -Path .\wordcloud2.svg -ImageSize 1080p

Get-ClipBoard | New-WordCloud -Path .\wordcloud3.svg -Typeface Consolas -ImageSize 1000x1000

Examples

See the Gallery for some example usage and output!

pswordcloud's People

Contributors

1redone avatar dependabot-preview[bot] avatar dependabot[bot] avatar tylerleonhardt avatar vexx32 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pswordcloud's Issues

Make collision detection better using GraphicsPath

System.Drawing.GraphicsPath has an AddString method to create tight paths from the string shape itself.

Using these paths to create Region objects should allow us to check for much more accurate intersections than we are currently able to do, permitting way more parking in the word clouds,

GdipCombineRegionPath assertion failed

Hello, when trying to run PSWordCloud on my Mac I am running into this issue:

  • installed mono-libgdiplus
  • on macOS Mojave (10.14.2)
  • pwsh version (6.1.1)

Running the following:

$get_domain = Get-Content -Path /Users/josh.rickard/get_domain.json
New-WordCloud -Path /Users/josh.rickard/Desktop/get_domain.png -Input $get_domain

I receive the following error, which dumps me out of my pwsh session and provides the following information:

** (process:19320): WARNING **: 14:34:29.106: Path conversion requested 0 bytes (8388608 x 8388608). Maximum size is 8388608 bytes.       
** ERROR:region.c:1155:GdipCombineRegionPath: assertion failed: (region->bitmap)   Abort trap: 6 

Any ideas?

New-WordCloud is non-functional in PowerShell 7 release candidates

Currently, the libSkiaSharp.dll (and equivalents for other platforms) is not being loaded correctly by the SkiaSharp.dll library we load directly. This can be remedied in PowerShell 7 by modifying the load context.

There is no proper fix for PowerShell 6.x.x, though some versions may work acceptably, I'm not considering really supporting them, the native library loader went through a few stages of changes along the way, so there's no good way to support everything. 5.1 should still work out OK, but we'll need to make adjustments for PowerShell 7.

See here for information on how this works by default in PowerShell 7: PowerShell/PowerShell#11032

This may mean we need to ship an additional copy of the SkiaSharp.dll main library and adjust the path we load it from for PowerShell 7 -- for PowerShell 6 and below, the behaviour (usually) works, except for some of the more recent versions in the 6.2.x branch, I believe. Windows PowerShell doesn't currently have issues loading it, so I'd prefer to avoid breaking that if we can.

2.0.x won't import in Windows PowerShell

(n.b. not sure if current releases are meant to drop support for Windows PowerShell?)

The latest release uses a syntax on Join-Path that won't work in Windows PowerShell, and and automatic variable that also doesn't exist in Windows PowerShell.

Trying to import the module results in:

Join-Path : A positional parameter cannot be found that accepts argument 'SkiaSharp.dll'.
At C:\Users\Windos\Documents\WindowsPowerShell\Modules\pswordcloud\2.0.1\PSWordCloud.psm1:13 char:16
+ ... iaDllPath = Join-Path -Path $PSScriptRoot -ChildPath $PlatformFolder  ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Join-Path], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.JoinPathCommand

Add-Type : Cannot bind argument to parameter 'Path' because it is null.
At C:\Users\Windos\Documents\WindowsPowerShell\Modules\pswordcloud\2.0.1\PSWordCloud.psm1:15 char:16
+ Add-Type -Path $SkiaDllPath
+                ~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-Type], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddTypeCommand

Import-Module : Could not load file or assembly 'SkiaSharp, Version=1.68.0.0, Culture=neutral,
PublicKeyToken=0738eb9f132ed756' or one of its dependencies. The system cannot find the file specified.
At C:\Users\Windos\Documents\WindowsPowerShell\Modules\pswordcloud\2.0.1\PSWordCloud.psm1:16 char:1
+ Import-Module  "$PSScriptRoot\PSWordCloudCmdlet.dll"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand

This is coming from this line in the psm1 file:

$SkiaDllPath = Join-Path -Path $PSScriptRoot -ChildPath $PlatformFolder "SkiaSharp.dll"

Possible fixes are to change the child path to "$PlatformFolder\SkiaSharp.dll"or two swap outJoin-Pathfor[http://System.IO .Path]::Combine()`

However, this change highlights a second issue, the switch statement for Platform Folder selection relies on PowerShell Core as $IsWindows isn't a thing in Windows PowerShell.

Add-Type : Cannot bind parameter 'Path' to the target. Exception setting "Path": "Cannot find path
'C:\Users\Windos\Documents\WindowsPowerShell\Modules\pswordcloud\2.0.1\SkiaSharp.dll' because it does not exist."
At C:\Users\Windos\Documents\WindowsPowerShell\Modules\pswordcloud\2.0.1\PSWordCloud.psm1:15 char:16
+ Add-Type -Path $SkiaDllPath
+                ~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Add-Type], ParameterBindingException
    + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.AddTypeCommand

Import-Module : Could not load file or assembly 'SkiaSharp, Version=1.68.0.0, Culture=neutral,
PublicKeyToken=0738eb9f132ed756' or one of its dependencies. The system cannot find the file specified.
At C:\Users\Windos\Documents\WindowsPowerShell\Modules\pswordcloud\2.0.1\PSWordCloud.psm1:16 char:1
+ Import-Module  "$PSScriptRoot\PSWordCloudCmdlet.dll"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand

How we dealt with this in PoshNotify is putting the Windows PowerShell specific stuff in a "default" stanza (even though it duplicates the "IsWindows" stanza) so that we can do specific stuff for that platform in future if required.

Provide more examples for novice

Update the README.md file to include the command you used to generate the word cloud.
Include an Examples folder, and a set of examples. I've seen some great images on twitter from the creator.

New-WordCloud hangs in MyBinder (Dotnet Interactive)

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

Add option to box / encircle each word in the cloud

We can compute a word's total path (we are already doing this to draw the word with a stroke) and create a rectangle (SKRect) object from the generated path. This object can be enlarged via the SKRect.Inflate() method to give it a bit of padding, and we can either use such a rectangle directly, or compute the larger side and use it to draw a circle around the word instead.

Suggestions for parameter names are welcome! Currently thinking something like -WordContainer with options Rectangle, Square, Circle, and None.

This would actually likely make word processing slightly faster, as it is easier to compute possible collisions against simple shapes than complex paths.

We might also want to have a separate option for -FocusWordContainer

-InputObject not taking my... Object Input

This is just a result of trying to re-run some older code (from before the SVG update) and running into an issue off the bat. I'd previously used -InputObject, but this isn't working and piping data in is working perfectly.

image

Much like my issue about importing on Windows, I'm not sure if this is intentional or not as I notice all the examples show piping data in.

This is Windows PowerShell on Windows 10 1809. Version 2.1.0 of PSWordCloud.

Ability to define different type of Word Clouds

I thought I would be having some nice output if I would use

function Get-ComputerDisk {
    param(
        $ComputerName = $Env:COMPUTERNAME
    )
    $Data2 = Get-WmiObject win32_DiskDrive -ComputerName $ComputerName | Select Index, Model, Caption, SerialNumber, Description, MediaType, FirmwareRevision, Partitions, @{Expression = {$_.Size / 1Gb -as [int]}; Label = "Total Size(GB)"}, PNPDeviceID
    return $Data2
}

as my data for words. I suspected it may not work :-)

get-clipboard | New-WordCloud -Path wordcloud.png -FontFamily Georgia

I kept waiting for minutes and it didn't do anything :-) What I actually wanted is to create some nice output for blogs pictures, especially for featured photo. It takes a lot of effort to create a good blog post and it's even harder to maintain quality photos for Featured Photos so that it doesn't look like a complete trash.

What I was looking to create was something like this:

image

It would be so cool if this project could generate pictures like that. Where it would take some PowerShell code or another type of code and mix it up in colors and produce nice looking featured picture with chosen size.

I imagine this may be a bit out of the scope of this project thou ;-)

Something like this - would be cool too

image

Or this:

image

Improve word placements

Currently, if a word cannot find a suitable place, the code "gives up" and doesn't care if the word overlaps.
It would be better if the word were simply hidden.

In line with this, there are a couple other improvements to placement we can do:

  • Allow words to extend to the bounds of the image. Currently, they're limited to approximately 3/4 of a rectangular image at the very outside. Note: this may require increasing the maximum word size.
  • Skip checking for points that are themselves already outside image bounds.
  • Check both possible rotations for words that don't seem to fit at a scan point. This should allow for words to be filled into the gaps a bit better.
  • Add optional switch -IgnoreImageBounds (name subject to change) to allow users to opt to ignore image bounds checks completely

3D rotations and filters

What I was looking to create was something like this:

image

It would be so cool if this project could generate pictures like that. Where it would take some PowerShell code or another type of code and mix it up in colors and produce nice looking featured picture with chosen size.

Your comment:

3D rotations should be possible using the .NET classes, but I've no idea if they actually are. Will have to research.

I'm pretty sure I've seen filters and can experiment there, though.

Linked to: #3

How can I use multibyte letters

โ“ Question

I'm text mining with Japanese and Chinese charactors and I'm looking for a way to display multibyte letters in a word cloud.
I thought changing the fonts would work.
But 'FontFamily' doesn't seem to be working, and whatever fonts I put, Arial, Scriptina, etc, the output comes the same.
Is there any special way to use multibyte? and change the fonts?

๐Ÿ’ป Environment Data

    $PSVersionTable

Name Value


PSVersion 7.1.5
PSEdition Core
GitCommitId 7.1.5
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0โ€ฆ}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

    Get-Module -Name PSWordCloud -ListAvailable

ModuleType Version PreRelease Name PSEdition ExportedCommands


Binary 4.0.0 PSWordCloud Core,Desk {New-WordCloud, wordcloud, wcloud, nwc}


Arbitrary object input

I thought I would be having some nice output if I would use

function Get-ComputerDisk {
    param(
        $ComputerName = $Env:COMPUTERNAME
    )
    $Data2 = Get-WmiObject win32_DiskDrive -ComputerName $ComputerName | Select Index, Model, Caption, SerialNumber, Description, MediaType, FirmwareRevision, Partitions, @{Expression = {$_.Size / 1Gb -as [int]}; Label = "Total Size(GB)"}, PNPDeviceID
    return $Data2
}

as my data for words. I suspected it may not work :-)

get-clipboard | New-WordCloud -Path wordcloud.png -FontFamily Georgia

I kept waiting for minutes and it didn't do anything :-) What I actually wanted is to create some nice output for blogs pictures, especially for featured photo. It takes a lot of effort to create a good blog post and it's even harder to maintain quality photos for Featured Photos so that it doesn't look like complete trash.

Pipe in random streams of objects at get usable output for the word cloud.

I think the most pragmatic solution would be to simply take whatever the console would render and attempt to make that work by sending it through Out-String to get the string representation. In fact, you can do that already, but it would be nice if this just handled it.

Linked to: #3

Confusing error when provided input is empty/not convertable to string/otherwise invalid

๐Ÿ› Bug Report

๐Ÿ’ป Environment Data

PS C:\Users\joelp>         $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0โ€ฆ}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS C:\Users\joelp>         Get-Module -Name PSWordCloud -ListAvailable


    Directory: C:\Users\joelp\Documents\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Binary     4.0.0                 PSWordCloud                         Core,Desk {New-WordCloud, wordcloud, wcloud, nwc}
Binary     3.2.1                 PSWordCloud                         Core,Desk {New-WordCloud, wordcloud, wcloud, nwc}

๐Ÿ“ Summary

When providing input that is not valid (i.e., is completely empty or cannot be converted to usable strings at all), New-WordCloud emits a confusing error: New-WordCloud: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')

๐Ÿ”ข Reproduction Steps

'' | New-WordCloud -Path ./test.svg

โœ… Expected Behaviour

A more coherent error suggesting what the user actually did wrong.

โŒ Actual Behaviour

Highly confusing error that doesn't really tell the user what they need to do to resolve it.

Feature Req: Choose orientation of focus word

It would be pretty cool if you could choose the orientation of the focus word. Maybe even more than just making it horizontal or vertical, but diagonal or something custom. That'd be a ton of fun ๐Ÿ˜

Feature: Add Custom Input mode

A fairly common feature request is to allow users to input a simple(r) list of words, and optionally allow specifying some size restrictions.

I would imagine something along these lines:

# parameter names not set; if you have better ideas, I'm all ears!
New-WordCloud -WordList <string[]> [-MinSize <double>] [-MaxSize <double>]
New-WordCloud -WordTable <IDictionary> [-MinSize <double>] [-MaxSize <double>]

This would allow the user to specify the list of words, and the cmdlet would apply a random scaling value to each according to the minimum and maximum size constraints. Default scaling values could be somewhere around 2.0 to 10.0. This would be a separate parameter set from the current sets, but also allow the input of things like a title word and color selection (both of which I think should be in all parameter sets currently, and can stay that way).

When using -WordTable, the user would input a single hashtable/dictionary object that uses the following format:

@{
    Apple = 10
    Potato = 5
    Lemon = 3
}

Each key will be treated as a word, and the numeric value of that key will be treated as the scale factor for that word.

Corrupt image output

๐Ÿ› Bug Report

๐Ÿ’ป Environment Data


๐Ÿ“ Summary

๐Ÿ”ข Reproduction Steps

โœ… Expected Behaviour

โŒ Actual Behaviour

unknown

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.