アラートダイアログ上にWkWebViewを作成し、その上でAMChartsによるWord Cloudを表示するAppleScriptです。
–> Download am_wordcloud.zip(AppleScript Bundle with Library and HTML)
AMChartsのワードクラウドの表示ロジックがちょっと「?」な仕様でした。英文のテキスト(単語がスペースで区切られている)をそのまま渡すとJavaScript側でParseして度数集計を行なって表示するようになっています。
集計済みのデータを渡して表示させる仕様ではなかったので、集計したデータをわざとテキストに展開して渡しています。非効率的な仕組みですが、スピードは遅くないので使っています。
ただし、その仕様の影響で「Script Editor」といった半角スペースを含む単語についてはスペースをハイフンに置換して「Script-Editor」のようにして処理しています。
→ と、自分で書いておいて「そんなバカな」と感じたので、再度AMChartsのドキュメントを読んでみたら、ちゃんとstructured dataを使うという項目があり、集計済みデータを処理できるとのこと。
AppleScript名:AMChartsでワードクラウドをダイアログ上に表示 v2.scptd |
— – Created by: Takaaki Naganoya – Created on: 2020/06/23 — – Copyright © 2020 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions use webD : script "webDialogLib" script tagStorage property aList : {} end script set aRecArray to {{|word|:"NSString", |count|:97}, {|word|:"NSURL", |count|:78}, {|word|:"Keynote", |count|:52}, {|word|:"NSMutableArray", |count|:51}, {|word|:"NSAlert", |count|:50}, {|word|:"NSRunningApplication", |count|:49}, {|word|:"NSArray", |count|:48}, {|word|:"CotEditor", |count|:44}, {|word|:"NSColor", |count|:44}, {|word|:"Finder", |count|:41}, {|word|:"NSImage", |count|:39}, {|word|:"Numbers", |count|:38}, {|word|:"NSPredicate", |count|:34}, {|word|:"NSView", |count|:32}, {|word|:"NSButton", |count|:28}, {|word|:"Safari", |count|:28}, {|word|:"NSScreen", |count|:27}, {|word|:"iTunes", |count|:25}, {|word|:"NSUTF8StringEncoding", |count|:24}, {|word|:"NSDictionary", |count|:22}, {|word|:"NSScrollView", |count|:21}, {|word|:"NSBitmapImageRep", |count|:20}, {|word|:"NSFileManager", |count|:20}, {|word|:"NSMutableDictionary", |count|:19}, {|word|:"NSURLRequest", |count|:18}, {|word|:"NSUUID", |count|:18}, {|word|:"NSWindow", |count|:17}, {|word|:"NSBezierPath", |count|:16}, {|word|:"NSFont", |count|:16}, {|word|:"WKWebView", |count|:16}, {|word|:"WKWebViewConfiguration", |count|:16}, {|word|:"NSWorkspace", |count|:15}, {|word|:"Pages", |count|:15}, {|word|:"Script Editor", |count|:15}, {|word|:"System Events", |count|:15}, {|word|:"WKUserContentController", |count|:15}, {|word|:"WKUserScript", |count|:15}, {|word|:"NSAlertSecondButtonReturn", |count|:14}, {|word|:"NSJSONSerialization", |count|:14}, {|word|:"NSSortDescriptor", |count|:14}} set (aList of tagStorage) to {} repeat with i in aRecArray set aW to |word| of i set aCount to |count| of i set bW to repChar(aW, " ", "-") of me repeat aCount times set the end of (aList of tagStorage) to bW end repeat end repeat set tRes to retDelimedText((aList of tagStorage), " ") of me –https://www.amcharts.com/demos/word-cloud/ set mePath to path to me set resPath to (mePath as string) & "Contents:Resources:index.html" set myStr to read (resPath as alias) as «class utf8» set aString to current application’s NSString’s stringWithFormat_(myStr, tRes) as string set paramObj to {myMessage:"Word Cloud", mySubMessage:"This is a AMCharts test", htmlStr:aString, jsDelimiters:{"<script>", "</script>"}, viewSize:{800, 520}} webD’s displayWebDialog(paramObj) on retDelimedText(aList, aDelim) set aText to "" set curDelim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to aDelim set aText to aList as text set AppleScript’s text item delimiters to curDelim return aText end retDelimedText –文字置換 on repChar(origText as string, targChar as string, repChar as string) set curDelim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to targChar set tmpList to text items of origText set AppleScript’s text item delimiters to repChar set retText to tmpList as string set AppleScript’s text item delimiters to curDelim return retText end repChar |
More from my site
(Visited 117 times, 1 visits today)