From 4ca120902a2cbd9ce13750f6fa9f3d8cbe0fdd8f Mon Sep 17 00:00:00 2001 From: Gk0Wk Date: Sat, 23 Sep 2023 13:58:38 +0800 Subject: [PATCH] Update and fix [#88] [#83] --- .../{ => GitHubHeatMap}/GitHubHeatMap.ts | 2 +- .../{ => GitHubHeatMap}/GitHubHeatMap.ts.meta | 3 + .../addons/Gk0Wk/GitHubHeatMap/readme.tid | 53 +++ .../Gk0Wk/{ => PluginsSize}/PluginsSize.tid | 3 + .../addons/Gk0Wk/PluginsSize/readme.tid | 7 + .../{ => SimpleExample}/SimpleExample.tid | 0 .../addons/Gk0Wk/{ => TagCloud}/TagCloud.ts | 2 +- .../Gk0Wk/{ => TagCloud}/TagCloud.ts.meta | 3 + .../Gk0Wk/{ => TagCloud}/TagCloudTagView.tid | 0 src/echarts/addons/Gk0Wk/TagCloud/readme.tid | 7 + .../addons/Gk0Wk/{ => TheBrain}/TheBrain.ts | 338 +++++++++++------- .../Gk0Wk/{ => TheBrain}/TheBrain.ts.meta | 3 + .../Gk0Wk/{ => TheBrain}/TheBrainPopup.tid | 0 src/echarts/addons/Gk0Wk/TheBrain/readme.tid | 58 +++ src/echarts/addons/peterhajas/BrainMap.tid | 5 +- src/echarts/gallary/author-template.tid | 12 + src/echarts/gallary/document-template.tid | 31 ++ src/echarts/gallary/index.tid | 12 + .../{ => lib}/echarts-wordcloud.v2.1.0.min.js | 0 .../echarts-wordcloud.v2.1.0.min.js.meta | 0 src/echarts/{ => lib}/echarts.v5.4.3.min.js | 0 .../{ => lib}/echarts.v5.4.3.min.js.meta | 0 src/echarts/plugin.info | 4 +- src/echarts/{widget.ts => widget/index.ts} | 2 +- .../{widget.ts.meta => widget/index.ts.meta} | 0 src/echarts/{ => widget}/macro.tid | 0 ...iddlywiki_vanilla_metrics_sidebarwidth.tid | 4 +- wiki/tiddlers/Focus.tid | 4 +- wiki/tiddlers/Index.tid | 18 +- 29 files changed, 427 insertions(+), 144 deletions(-) rename src/echarts/addons/Gk0Wk/{ => GitHubHeatMap}/GitHubHeatMap.ts (99%) rename src/echarts/addons/Gk0Wk/{ => GitHubHeatMap}/GitHubHeatMap.ts.meta (55%) create mode 100644 src/echarts/addons/Gk0Wk/GitHubHeatMap/readme.tid rename src/echarts/addons/Gk0Wk/{ => PluginsSize}/PluginsSize.tid (93%) create mode 100644 src/echarts/addons/Gk0Wk/PluginsSize/readme.tid rename src/echarts/addons/Gk0Wk/{ => SimpleExample}/SimpleExample.tid (100%) rename src/echarts/addons/Gk0Wk/{ => TagCloud}/TagCloud.ts (98%) rename src/echarts/addons/Gk0Wk/{ => TagCloud}/TagCloud.ts.meta (56%) rename src/echarts/addons/Gk0Wk/{ => TagCloud}/TagCloudTagView.tid (100%) create mode 100644 src/echarts/addons/Gk0Wk/TagCloud/readme.tid rename src/echarts/addons/Gk0Wk/{ => TheBrain}/TheBrain.ts (69%) rename src/echarts/addons/Gk0Wk/{ => TheBrain}/TheBrain.ts.meta (56%) rename src/echarts/addons/Gk0Wk/{ => TheBrain}/TheBrainPopup.tid (100%) create mode 100644 src/echarts/addons/Gk0Wk/TheBrain/readme.tid create mode 100644 src/echarts/gallary/author-template.tid create mode 100644 src/echarts/gallary/document-template.tid create mode 100644 src/echarts/gallary/index.tid rename src/echarts/{ => lib}/echarts-wordcloud.v2.1.0.min.js (100%) rename src/echarts/{ => lib}/echarts-wordcloud.v2.1.0.min.js.meta (100%) rename src/echarts/{ => lib}/echarts.v5.4.3.min.js (100%) rename src/echarts/{ => lib}/echarts.v5.4.3.min.js.meta (100%) rename src/echarts/{widget.ts => widget/index.ts} (99%) rename src/echarts/{widget.ts.meta => widget/index.ts.meta} (100%) rename src/echarts/{ => widget}/macro.tid (100%) diff --git a/src/echarts/addons/Gk0Wk/GitHubHeatMap.ts b/src/echarts/addons/Gk0Wk/GitHubHeatMap/GitHubHeatMap.ts similarity index 99% rename from src/echarts/addons/Gk0Wk/GitHubHeatMap.ts rename to src/echarts/addons/Gk0Wk/GitHubHeatMap/GitHubHeatMap.ts index 32847b1..53e45a1 100644 --- a/src/echarts/addons/Gk0Wk/GitHubHeatMap.ts +++ b/src/echarts/addons/Gk0Wk/GitHubHeatMap/GitHubHeatMap.ts @@ -1,5 +1,5 @@ import type { SourceIterator } from 'tiddlywiki'; -import { IScriptAddon } from '../../scriptAddon'; +import { IScriptAddon } from '../../../scriptAddon'; import * as ECharts from '$:/plugins/Gk0Wk/echarts/echarts.min.js'; const getFilterByDate = (date: string) => diff --git a/src/echarts/addons/Gk0Wk/GitHubHeatMap.ts.meta b/src/echarts/addons/Gk0Wk/GitHubHeatMap/GitHubHeatMap.ts.meta similarity index 55% rename from src/echarts/addons/Gk0Wk/GitHubHeatMap.ts.meta rename to src/echarts/addons/Gk0Wk/GitHubHeatMap/GitHubHeatMap.ts.meta index 13f24d9..9ca84f3 100644 --- a/src/echarts/addons/Gk0Wk/GitHubHeatMap.ts.meta +++ b/src/echarts/addons/Gk0Wk/GitHubHeatMap/GitHubHeatMap.ts.meta @@ -1,4 +1,7 @@ title: $:/plugins/Gk0Wk/echarts/addons/GitHubHeatMap.ts type: application/javascript module-type: echarts-component +caption: GitHubHeatMap +echarts.author: Gk0Wk(Sttot) +echarts.readme: {{$:/plugins/Gk0Wk/echarts/addons/GitHubHeatMap-readme}} Modern.TiddlyDev#IncludeSource: false diff --git a/src/echarts/addons/Gk0Wk/GitHubHeatMap/readme.tid b/src/echarts/addons/Gk0Wk/GitHubHeatMap/readme.tid new file mode 100644 index 0000000..1be0b51 --- /dev/null +++ b/src/echarts/addons/Gk0Wk/GitHubHeatMap/readme.tid @@ -0,0 +1,53 @@ +title: $:/plugins/Gk0Wk/echarts/addons/GitHubHeatMap-readme + +
+
+ <$button + set="$:/state/heatmap!!year" + setTo={{{ [{$:/state/heatmap!!year}subtract[1]!match[-1]] ~[subtract[1]] }}} + class="tc-btn-invisible tc-tiddlylink" + + > + ◄ +             <$button + set="$:/state/heatmap!!year" + setTo={{{ [{$:/state/heatmap!!year}add[1]!match[1]] ~[add[1]] }}} + class="tc-btn-invisible tc-tiddlylink" + + > + ► + +
+ <$echarts $tiddler="$:/plugins/Gk0Wk/echarts/addons/GitHubHeatMap.js" $width="100%" $height="100%" year={{$:/state/heatmap!!year}} subfilter="[all[tiddlers]!is[shadow]!is[system]!field:calendarEntry[yes]]" /> +
+ +Simple usage: + +```html +<$echarts $tiddler="$:/plugins/Gk0Wk/echarts/addons/GitHubHeatMap.js" /> +``` + +You can add switch buttons like this: + +```html +
+
+ <$button + set="$:/state/heatmap!!year" + setTo={{{ [{$:/state/heatmap!!year}subtract[1]!match[-1]] ~[subtract[1]] }}} + class="tc-btn-invisible tc-tiddlylink" + + > + ◄ +             <$button + set="$:/state/heatmap!!year" + setTo={{{ [{$:/state/heatmap!!year}add[1]!match[1]] ~[add[1]] }}} + class="tc-btn-invisible tc-tiddlylink" + + > + ► + +
+ <$echarts $tiddler="$:/plugins/Gk0Wk/echarts/addons/GitHubHeatMap.js" $width="100%" $height="100%" year={{$:/state/heatmap!!year}} subfilter="[all[tiddlers]!is[shadow]!is[system]!field:calendarEntry[yes]]" /> +
+``` diff --git a/src/echarts/addons/Gk0Wk/PluginsSize.tid b/src/echarts/addons/Gk0Wk/PluginsSize/PluginsSize.tid similarity index 93% rename from src/echarts/addons/Gk0Wk/PluginsSize.tid rename to src/echarts/addons/Gk0Wk/PluginsSize/PluginsSize.tid index 028895e..46ff273 100755 --- a/src/echarts/addons/Gk0Wk/PluginsSize.tid +++ b/src/echarts/addons/Gk0Wk/PluginsSize/PluginsSize.tid @@ -1,5 +1,8 @@ title: $:/plugins/Gk0Wk/echarts/addons/PluginsSize type: text/vnd.tiddlywiki +caption: PluginsSize +echarts.author: Gk0Wk(Sttot) +echarts.readme: {{$:/plugins/Gk0Wk/echarts/addons/PluginsSize-readme}} `{ "tooltip": { diff --git a/src/echarts/addons/Gk0Wk/PluginsSize/readme.tid b/src/echarts/addons/Gk0Wk/PluginsSize/readme.tid new file mode 100644 index 0000000..d15aa5c --- /dev/null +++ b/src/echarts/addons/Gk0Wk/PluginsSize/readme.tid @@ -0,0 +1,7 @@ +title: $:/plugins/Gk0Wk/echarts/addons/PluginsSize-readme + +Visualize plugins size: + +```html +<$echarts $tiddler="$:/plugins/Gk0Wk/echarts/addons/PluginsSize" /> +``` diff --git a/src/echarts/addons/Gk0Wk/SimpleExample.tid b/src/echarts/addons/Gk0Wk/SimpleExample/SimpleExample.tid similarity index 100% rename from src/echarts/addons/Gk0Wk/SimpleExample.tid rename to src/echarts/addons/Gk0Wk/SimpleExample/SimpleExample.tid diff --git a/src/echarts/addons/Gk0Wk/TagCloud.ts b/src/echarts/addons/Gk0Wk/TagCloud/TagCloud.ts similarity index 98% rename from src/echarts/addons/Gk0Wk/TagCloud.ts rename to src/echarts/addons/Gk0Wk/TagCloud/TagCloud.ts index fc3cba7..39f3191 100755 --- a/src/echarts/addons/Gk0Wk/TagCloud.ts +++ b/src/echarts/addons/Gk0Wk/TagCloud/TagCloud.ts @@ -1,4 +1,4 @@ -import type { IScriptAddon } from '../../scriptAddon'; +import type { IScriptAddon } from '../../../scriptAddon'; const getPlatteColor = (name: string) => $tw.wiki.renderText( diff --git a/src/echarts/addons/Gk0Wk/TagCloud.ts.meta b/src/echarts/addons/Gk0Wk/TagCloud/TagCloud.ts.meta similarity index 56% rename from src/echarts/addons/Gk0Wk/TagCloud.ts.meta rename to src/echarts/addons/Gk0Wk/TagCloud/TagCloud.ts.meta index d74c463..7500edb 100644 --- a/src/echarts/addons/Gk0Wk/TagCloud.ts.meta +++ b/src/echarts/addons/Gk0Wk/TagCloud/TagCloud.ts.meta @@ -1,4 +1,7 @@ title: $:/plugins/Gk0Wk/echarts/addons/TagCloud.ts type: application/javascript module-type: echarts-component +caption: TagCloud +echarts.author: Gk0Wk(Sttot) +echarts.readme: {{$:/plugins/Gk0Wk/echarts/addons/TagCloud-readme}} Modern.TiddlyDev#IncludeSource: false diff --git a/src/echarts/addons/Gk0Wk/TagCloudTagView.tid b/src/echarts/addons/Gk0Wk/TagCloud/TagCloudTagView.tid similarity index 100% rename from src/echarts/addons/Gk0Wk/TagCloudTagView.tid rename to src/echarts/addons/Gk0Wk/TagCloud/TagCloudTagView.tid diff --git a/src/echarts/addons/Gk0Wk/TagCloud/readme.tid b/src/echarts/addons/Gk0Wk/TagCloud/readme.tid new file mode 100644 index 0000000..f2c3341 --- /dev/null +++ b/src/echarts/addons/Gk0Wk/TagCloud/readme.tid @@ -0,0 +1,7 @@ +title: $:/plugins/Gk0Wk/echarts/addons/TagCloud-readme + +```html +<$echarts $tiddler="$:/plugins/Gk0Wk/echarts/addons/TagCloud.js" /> +``` + +<$echarts $tiddler="$:/plugins/Gk0Wk/echarts/addons/TagCloud.js" /> diff --git a/src/echarts/addons/Gk0Wk/TheBrain.ts b/src/echarts/addons/Gk0Wk/TheBrain/TheBrain.ts similarity index 69% rename from src/echarts/addons/Gk0Wk/TheBrain.ts rename to src/echarts/addons/Gk0Wk/TheBrain/TheBrain.ts index 39080d2..1a97d14 100755 --- a/src/echarts/addons/Gk0Wk/TheBrain.ts +++ b/src/echarts/addons/Gk0Wk/TheBrain/TheBrain.ts @@ -1,6 +1,6 @@ /* eslint-disable max-lines */ import type { IParseTreeNode } from 'tiddlywiki'; -import type { IScriptAddon } from '../../scriptAddon'; +import type { IScriptAddon } from '../../../scriptAddon'; const colors = [ '#5470c6', @@ -44,6 +44,9 @@ const attributes = new Set([ 'aliasField', 'excludeFilter', 'previewDelay', + 'focusBlur', + 'previewTemplate', + 'zoom', ]); const getPlatteColor = (name: string) => $tw.wiki.renderText( @@ -97,11 +100,11 @@ const getAliasOrTitle = ( }; interface ITheBrainState { - currentlyFocused?: string; + currentlyFocused?: Set; historyTiddlers: string[]; viewingTiddlers: Set; focusing?: string; - zoomTimer: NodeJS.Timer; + unmount: () => void; } const TheBrainAddon: IScriptAddon = { @@ -109,45 +112,78 @@ const TheBrainAddon: IScriptAddon = { myChart.on('click', { dataType: 'node' }, (event: any) => { new $tw.Story().navigateTiddler(event.data.name); }); + // 缩放检测 let fontScale = 4; - return { - historyTiddlers: [], - viewingTiddlers: new Set(), - focusing: attributes.focussedTiddler, - // 缩放检测 - zoomTimer: setInterval(() => { - const option = myChart.getOption() as any; - const zoom = option?.series?.[0]?.zoom; - if (typeof zoom !== 'number') { - return; - } - let needUpdate = false; - const newFontScale = Math.floor(zoom * 4); - const newShow = zoom >= 2.5; - if (option.series[0].label.show !== newShow) { - option.series[0].label.show = newShow; - needUpdate = true; + let originTriggerOn: string | undefined; + let originShowDelay: number | undefined; + const timer = setInterval(() => { + const option = myChart.getOption() as any; + const zoom = option?.series?.[0]?.zoom; + if (typeof zoom !== 'number') { + return; + } + if (!originTriggerOn) { + originTriggerOn = option.tooltip.triggerOn; + originShowDelay = option.tooltip.showDelay; + } + let needUpdate = false; + const newFontScale = Math.floor(zoom * 4); + const newShow = zoom >= 2.5; + const newShowDelay = zoom >= 3 ? originShowDelay : 2 * originShowDelay!; + if (option.series[0].label.show !== newShow) { + option.series[0].label.show = newShow; + option.tooltip.triggerOn = newShow ? originTriggerOn! : 'none'; + needUpdate = true; + } + if (option.tooltip.showDelay !== newShowDelay) { + option.tooltip.showDelay = newShowDelay; + needUpdate = true; + } + if (newFontScale !== fontScale) { + fontScale = newFontScale; + option.series[0].label.fontSize = `${Math.min( + 0.5 * fontScale + 2, + 24, + )}px`; + option.series[0].lineStyle.width = Math.min( + Math.max(0.0625 * fontScale, 0.5), + 6, + ); + if (newFontScale > 160) { + option.series[0].label.position = 'inside'; + } else if (newFontScale > 24) { + option.series[0].label.position = 'bottom'; + } else { + option.series[0].label.position = 'right'; } - if (newFontScale !== fontScale) { - fontScale = newFontScale; - option.series[0].label.fontSize = `${Math.min( - 0.5 * fontScale + 2, - 24, - )}px`; - needUpdate = true; - const root = option.series[0].nodes[0]; + const rootBorderWidth = Math.min(0.75 * fontScale + 3, 30); + const rootFontSize = `${rootBorderWidth}px`; + for (const root of option.series[0].nodes) { if (root.category === 0) { - root.label.fontSize = `${Math.min(0.75 * fontScale + 3, 30)}px`; + root.label.fontSize = rootFontSize; + root.itemStyle.borderWidth = rootBorderWidth; + } else { + break; } } - if (needUpdate) { - myChart.setOption(option); - } - }, 200), + needUpdate = true; + } + if (needUpdate) { + myChart.setOption(option); + } + }, 200); + + return { + historyTiddlers: [], + viewingTiddlers: new Set(), + focusing: attributes.focussedTiddler, + unmount: () => { + clearInterval(timer); + }, }; }, - onUnmount: ({ zoomTimer }) => { - clearInterval(zoomTimer); + onUnmount: ({ unmount }) => { + unmount(); }, shouldUpdate: ( { viewingTiddlers, focusing, currentlyFocused }, @@ -160,7 +196,9 @@ const TheBrainAddon: IScriptAddon = { attributes.has(attribute), ) || (focusing === undefined && - $tw.wiki.getTiddlerText('$:/temp/focussedTiddler') !== currentlyFocused) + currentlyFocused?.has( + $tw.wiki.getTiddlerText('$:/temp/focussedTiddler') ?? '', + ) !== true) ); }, // eslint-disable-next-line complexity @@ -174,24 +212,48 @@ const TheBrainAddon: IScriptAddon = { aliasField?: string; excludeFilter?: string; previewDelay?: string; + focusBlur?: string; + previewTemplate?: string; + zoom?: string; }, ) => { /** 参数:focussedTiddler 是图的中央节点 */ - let focussedTiddler = - addonAttributes.focussedTiddler || - $tw.wiki.getTiddlerText('$:/temp/focussedTiddler')!; - state.viewingTiddlers.clear(); - state.focusing = addonAttributes.focussedTiddler; - state.currentlyFocused = focussedTiddler; - if (!focussedTiddler) { + let focussedTiddlers = new Set(); + if (addonAttributes.focussedTiddler) { + for (const title of $tw.wiki.filterTiddlers( + addonAttributes.focussedTiddler, + )) { + focussedTiddlers.add(title); + } + } else { + const t = $tw.wiki.getTiddlerText('$:/temp/focussedTiddler'); + if (t) { + focussedTiddlers.add(t); + } + } + if (focussedTiddlers.size === 0) { return; } - state.viewingTiddlers.add(focussedTiddler); - if ($tw.wiki.getTiddler(focussedTiddler)?.fields['draft.of']) { - focussedTiddler = $tw.wiki.getTiddler(focussedTiddler)!.fields[ - 'draft.of' - ] as string; + // draft + const t = new Set(); + for (const title of focussedTiddlers) { + const draftOf = $tw.wiki.getTiddler(title)?.fields['draft.of']; + if (draftOf) { + t.add(draftOf as string); + } else { + t.add(title); + } + } + focussedTiddlers = t; + + // State + state.focusing = addonAttributes.focussedTiddler; + state.currentlyFocused = focussedTiddlers; + state.viewingTiddlers.clear(); + for (const tiddler of focussedTiddlers) { + state.viewingTiddlers.add(tiddler); } + const nodes: any[] = []; const edges: any[] = []; const ifChinese = @@ -201,52 +263,56 @@ const TheBrainAddon: IScriptAddon = { if (Number.isNaN(levels)) { levels = 1; } - levels = Math.max(levels, 0); + levels = Math.max(levels, -1); /** 参数:graphTitle 指定右下角显示的标题 */ const graphTitle = addonAttributes.graphTitle || (ifChinese ? '聚焦' : 'Focusing Map'); /** 参数:aliasField 用于指定展示为节点标题的字段,例如 caption */ - const aliasField = - addonAttributes.aliasField === '' - ? undefined - : addonAttributes.aliasField; + const aliasField = addonAttributes.aliasField || 'caption'; /** 参数:excludeFilter 用于排除部分节点 */ const excludeFilter = addonAttributes.excludeFilter === '' ? undefined : $tw.wiki.compileFilter( - addonAttributes.excludeFilter ?? '[prefix[$:/]]', + addonAttributes.excludeFilter ?? '[prefix[$:/]] [is[draft]]', ); const nodeMap: Map = new Map(); // 聚焦点 - nodes.push({ - name: focussedTiddler, - // fixed: true, - category: 0, - label: { - formatter: getAliasOrTitle(focussedTiddler, aliasField)[0], - fontWeight: 'bold', - fontSize: '15px', - }, - symbol: findIcon(focussedTiddler), - symbolSize: 15, - select: { - disabled: true, - }, - itemStyle: { - opacity: 1, - borderColor: `${colors[0]}66`, - borderWidth: 15, - }, - isTag: false, - tooltip: { - show: false, - }, - }); + for (const focussedTiddler of focussedTiddlers) { + nodes.push({ + name: focussedTiddler, + // fixed: true, + category: 0, + label: { + formatter: getAliasOrTitle(focussedTiddler, aliasField)[0], + fontWeight: 'bold', + fontSize: '15px', + }, + symbol: findIcon(focussedTiddler), + symbolSize: 15, + select: { + disabled: true, + }, + itemStyle: { + opacity: 1, + borderColor: `${colors[0]}66`, + borderWidth: 15, + }, + isTag: false, + tooltip: { + show: false, + }, + }); + } // 初始化:当前关注的 Tiddler - let tiddlerQueue = [focussedTiddler]; + let tiddlerQueue: string[] = []; + nodeMap.set('', false); + for (const tiddler of focussedTiddlers) { + tiddlerQueue.push(tiddler); + nodeMap.set(tiddler, true); + } if (excludeFilter) { const tiddlers = new Set(tiddlerQueue); for (const excluded of excludeFilter.call($tw.wiki, tiddlerQueue)) { @@ -254,8 +320,6 @@ const TheBrainAddon: IScriptAddon = { } tiddlerQueue = Array.from(tiddlers); } - nodeMap.set(focussedTiddler, true); - nodeMap.set('', false); const tryPush = ( title: string, @@ -293,7 +357,7 @@ const TheBrainAddon: IScriptAddon = { (label, exist) => ({ name: linksTo, label: { formatter: label }, - itemStyle: { opacity: exist ? 1 : 0.65 }, + itemStyle: { opacity: exist ? 1 : 0.5 }, symbol: findIcon(linksTo), category: 2, isTag: false, @@ -315,7 +379,7 @@ const TheBrainAddon: IScriptAddon = { (label, exist) => ({ name: backlinksFrom, label: { formatter: label }, - itemStyle: { opacity: exist ? 1 : 0.65 }, + itemStyle: { opacity: exist ? 1 : 0.5 }, symbol: findIcon(backlinksFrom), category: 3, isTag: false, @@ -331,14 +395,13 @@ const TheBrainAddon: IScriptAddon = { ); } // 标签 - for (const tag of $tw.wiki.getTiddler(focussedTiddler)?.fields?.tags ?? - []) { + for (const tag of $tw.wiki.getTiddler(tiddler)?.fields?.tags ?? []) { tryPush( tag, (label, exist) => ({ name: tag, label: { formatter: label }, - itemStyle: { opacity: exist ? 1 : 0.65 }, + itemStyle: { opacity: exist ? 1 : 0.5 }, symbol: findIcon(tag), category: 4, isTag: true, @@ -360,7 +423,7 @@ const TheBrainAddon: IScriptAddon = { (label, exist) => ({ name: tagBy, label: { formatter: label }, - itemStyle: { opacity: exist ? 1 : 0.65 }, + itemStyle: { opacity: exist ? 1 : 0.5 }, symbol: findIcon(tagBy), category: 5, isTag: false, @@ -405,7 +468,7 @@ const TheBrainAddon: IScriptAddon = { (label, exist) => ({ name: transcludeTiddler, label: { formatter: label }, - itemStyle: { opacity: exist ? 1 : 0.65 }, + itemStyle: { opacity: exist ? 1 : 0.5 }, symbol: findIcon(transcludeTiddler), category: 6, isTag: false, @@ -426,49 +489,51 @@ const TheBrainAddon: IScriptAddon = { } // 历史路径 - let nextTiddler = focussedTiddler; - const historyMap: Set = new Set(); - for (let index = state.historyTiddlers.length - 2; index >= 0; index--) { - const tiddlerTitle = state.historyTiddlers[index]; - if ( - historyMap.has(tiddlerTitle) || - tiddlerTitle === nextTiddler || - tiddlerTitle.startsWith('$:/') - ) { - continue; + if (focussedTiddlers.size === 1) { + const focussedTiddler = focussedTiddlers.values().next().value; + let nextTiddler = focussedTiddler; + const historyMap: Set = new Set(); + for (let index = state.historyTiddlers.length - 2; index >= 0; index--) { + const tiddlerTitle = state.historyTiddlers[index]; + if ( + historyMap.has(tiddlerTitle) || + tiddlerTitle === nextTiddler || + tiddlerTitle.startsWith('$:/') + ) { + continue; + } + tryPush( + tiddlerTitle, + (label, exist) => ({ + name: tiddlerTitle, + label: { formatter: label }, + category: 1, + symbol: findIcon(tiddlerTitle), + symbolSize: 3, + itemStyle: { opacity: exist ? 0.65 : 0.4 }, + isTag: false, + }), + // eslint-disable-next-line @typescript-eslint/no-loop-func + exist => ({ + source: tiddlerTitle, + target: nextTiddler, + lineStyle: { + color: colors[1], + type: exist ? 'dashed' : 'dotted', + opacity: 0.5, + }, + }), + ); + nextTiddler = tiddlerTitle; } - tryPush( - tiddlerTitle, - (label, exist) => ({ - name: tiddlerTitle, - label: { formatter: label }, - category: 1, - symbol: findIcon(tiddlerTitle), - symbolSize: 3, - itemStyle: { opacity: exist ? 0.65 : 0.4 }, - isTag: false, - }), - // eslint-disable-next-line @typescript-eslint/no-loop-func - exist => ({ - source: tiddlerTitle, - target: nextTiddler, - lineStyle: { - color: colors[1], - type: exist ? 'dashed' : 'dotted', - opacity: 0.5, - }, - }), - ); - nextTiddler = tiddlerTitle; - } - - // 更新历史 - const historyIndex = state.historyTiddlers.indexOf(focussedTiddler); - if (historyIndex > -1) { - state.historyTiddlers.splice(historyIndex, 1); + // 更新历史 + const historyIndex = state.historyTiddlers.indexOf(focussedTiddler); + if (historyIndex > -1) { + state.historyTiddlers.splice(historyIndex, 1); + } + state.historyTiddlers.push(focussedTiddler); + state.historyTiddlers.slice(-10); } - state.historyTiddlers.push(focussedTiddler); - state.historyTiddlers.slice(-10); let lastTitle = ''; let cache: Element[] | undefined; @@ -520,7 +585,8 @@ const TheBrainAddon: IScriptAddon = { $tw.wiki .makeWidget( $tw.wiki.parseTiddler( - '$:/plugins/Gk0Wk/echarts/addons/TheBrainPopup', + addonAttributes.previewTemplate || + '$:/plugins/Gk0Wk/echarts/addons/TheBrainPopup', ), { document, @@ -541,10 +607,15 @@ const TheBrainAddon: IScriptAddon = { return cache; }; + let zoom = Number(addonAttributes.zoom); + if (Number.isNaN(zoom) || Number.isFinite(zoom) || zoom <= 0) { + zoom = 4; + } let previewDelay = Number(addonAttributes.previewDelay || '1000'); if (!Number.isSafeInteger(previewDelay)) { previewDelay = -1; } + const focusBlur = addonAttributes.focusBlur?.toLowerCase?.() !== 'false'; myCharts.setOption({ backgroundColor: 'transparent', legend: [ @@ -576,7 +647,7 @@ const TheBrainAddon: IScriptAddon = { triggerOn: previewDelay >= 0 ? 'mousemove' : 'none', enterable: true, showDelay: Math.max(0, previewDelay), - hideDelay: 800, + hideDelay: 200, confine: true, textStyle: { color: 'inherit', @@ -603,7 +674,7 @@ const TheBrainAddon: IScriptAddon = { categories: ifChinese ? CategoriesZh : CategoriesEn, roam: true, draggable: false, - zoom: 4, + zoom, label: { position: 'right', show: true, @@ -633,8 +704,9 @@ const TheBrainAddon: IScriptAddon = { }, // 高亮聚焦 emphasis: { - disabled: false, + disabled: !focusBlur, focus: 'adjacency', + scale: 1.2, }, blur: { itemStyle: { opacity: 0.3 }, diff --git a/src/echarts/addons/Gk0Wk/TheBrain.ts.meta b/src/echarts/addons/Gk0Wk/TheBrain/TheBrain.ts.meta similarity index 56% rename from src/echarts/addons/Gk0Wk/TheBrain.ts.meta rename to src/echarts/addons/Gk0Wk/TheBrain/TheBrain.ts.meta index 4649dfc..012571a 100755 --- a/src/echarts/addons/Gk0Wk/TheBrain.ts.meta +++ b/src/echarts/addons/Gk0Wk/TheBrain/TheBrain.ts.meta @@ -1,4 +1,7 @@ title: $:/plugins/Gk0Wk/echarts/addons/TheBrain.ts type: application/javascript module-type: echarts-component +caption: FocusMap +echarts.author: Gk0Wk(Sttot) +echarts.readme: {{$:/plugins/Gk0Wk/echarts/addons/TheBrain-readme}} Modern.TiddlyDev#IncludeSource: false diff --git a/src/echarts/addons/Gk0Wk/TheBrainPopup.tid b/src/echarts/addons/Gk0Wk/TheBrain/TheBrainPopup.tid similarity index 100% rename from src/echarts/addons/Gk0Wk/TheBrainPopup.tid rename to src/echarts/addons/Gk0Wk/TheBrain/TheBrainPopup.tid diff --git a/src/echarts/addons/Gk0Wk/TheBrain/readme.tid b/src/echarts/addons/Gk0Wk/TheBrain/readme.tid new file mode 100644 index 0000000..4a24328 --- /dev/null +++ b/src/echarts/addons/Gk0Wk/TheBrain/readme.tid @@ -0,0 +1,58 @@ +title: $:/plugins/Gk0Wk/echarts/addons/TheBrain-readme + +<$echarts $tiddler="$:/plugins/Gk0Wk/echarts/addons/TheBrain.js" focussedTiddler="$:/plugins/Gk0Wk/echarts" excludeFilter="[is[draft]]" $width="100%" $height="300px" /> + +<$list filter="[[$:/language]get[text]removeprefix[$:/languages/]else[en-GB]]" variable="lang"> +<$list filter="[search[zh]]"> + +聚焦图,灵感来源于 <$text text="TheBrain" /> 与知识图谱理论,目的是在用户阅读条目时提供信息侧载,用直观的视觉信息告诉用户与该条目相关的信息,帮助用户在茫茫的知识海洋中自由漫步。 + +因该图关注的是当前条目所发散的信息,因此成为「聚焦」,与Obsidian的全局知识图谱不同(全局图谱正在设计中,欢迎提出建议)。 + +一般的使用方法:将该图放置于侧栏,并下载安装 <$text text="$:/plugins/Gk0Wk/focused-tiddler" /> 插件([[CPL|https://tw-cpl.netlify.app/]]中有)。具体操作为: + +# 创建一个条目,并赋予其 `$:/tags/SideBar` 标签; +# 其中写如下内容:`<$echarts $tiddler="$:/plugins/Gk0Wk/echarts/addons/TheBrain.js" />`; +# 设置一下`caption`字段,作为侧栏的标题 +# 保存,即可以在侧边栏看到它。 + +聚焦图提供了一些参数,可以根据这些参数设定其行为: + +* `focussedTiddler` 用于设定当前聚焦的条目,即从该条目开始向外扩展。默认使用 <$text text="$:/plugins/Gk0Wk/focused-tiddler" /> 提供的当前聚焦的条目。支持使用过滤表达式包含多个条目,如 `[tag[A]]`; +* `levels` 用于设定图的层级,即从当前条目开始,向外扩展几层。默认为 `1`,`Infinity`为无限扩展直到遍历所有关系,@@color:red; 层级越多就越有可能卡死页面,自己当心 @@; +* `graphTitle` 用于设定图的标题,即侧边栏的标题。默认为 `聚焦`; +* `aliasField` 用于设定别名字段,即在聚焦图中,显示的是别名字段的内容。默认为 `caption`; +* `excludeFilter` 用于设定排除的过滤器,即在聚焦图中,排除哪些条目。默认为 `[prefix[$:/]] [is[draft]]`,即排除所有系统条目和被编辑的条目; +* `previewDelay` 用于设定预览延迟,即鼠标悬停在节点上多久后显示预览。默认为 `1000`,即 1000ms,`-1` 表示不显示预览; +* `focusBlur` 在鼠标悬浮在某个节点上时,其他节点是否变淡。默认为 `true`,即变淡; +* `previewTemplate` 用于设定预览模板,渲染预览内容。默认为 `$:/plugins/Gk0Wk/echarts/addons/TheBrainPopup`; +* `zoom` 用于设定初始缩放比例。默认为 `4`。 + + +<$list filter="[!search[zh]]"> + +Focus map, inspired by <$text text="TheBrain" /> and knowledge graph theory, aims to provide information side-loading when users read a tiddler, and use intuitive visual information to tell users the information related to the tiddler, helping users to freely walk in the vast ocean of knowledge. + +Because the graph focuses on the information diverging from the current tiddler, it names "focus", which is different from the global knowledge graph of Obsidian (the global graph is under design, suggestions are welcome). + +General usage: place the graph in the sidebar, and install the <$text text="$:/plugins/Gk0Wk/focused-tiddler" /> plugin (available in [[CPL|https://tw-cpl.netlify.app/]]). The specific operation is: + +# Create a tiddler and assign it the `$:/tags/SideBar` tag; +# Write the following content in it: `<$echarts $tiddler="$:/plugins/Gk0Wk/echarts/addons/TheBrain.js" />`; +# Set the `caption` field as the title of the sidebar; +# Save, and you can see it in the sidebar. + +The focus map provides some parameters, which can be used to set its behavior: + +* `focussedTiddler` is used to set the current focused tiddler, that is, expand from this tiddler. The default is the current focused tiddler provided by <$text text="$:/plugins/Gk0Wk/focused-tiddler" />. Multiple tiddlers can be included in the filter expression, such as `[tag[A]]`; +* `levels` is used to set the level of the graph, that is, expand several levels from the current tiddler. The default is `1`, `Infinity` means unlimited expansion until all relationships are traversed, @@color:red; the more levels, the more likely it is to freeze the page, be careful @@; +* `graphTitle` is used to set the title of the graph, that is, the title of the sidebar. The default is `Focusing Map`; +* `aliasField` is used to set the alias field, that is, the content of the alias field is displayed in the focus map. The default is `caption`; +* `excludeFilter` is used to set the exclude filter, that is, which tiddlers are excluded in the focus map. The default is `[prefix[$:/]] [is[draft]]`, that is, exclude all system tiddlers and editing tiddlers; +* `previewDelay` is used to set the preview delay, that is, how long the preview is displayed after the mouse hovers over the node. The default is `1000`, that is, 1000ms, `-1` means no preview; +* `focusBlur` is used to set whether other nodes become lighter when the mouse hovers over a node. The default is `true`, that is, lighter; +* `previewTemplate` is used to set the preview template to render the preview content. The default is `$:/plugins/Gk0Wk/echarts/addons/TheBrainPopup`; +* `zoom` is used to set the initial zoom ratio. The default is `4`. + + + diff --git a/src/echarts/addons/peterhajas/BrainMap.tid b/src/echarts/addons/peterhajas/BrainMap.tid index c4e8f19..3ef7376 100755 --- a/src/echarts/addons/peterhajas/BrainMap.tid +++ b/src/echarts/addons/peterhajas/BrainMap.tid @@ -1,5 +1,8 @@ title: $:/plugins/Gk0Wk/echarts/addons/BrainMap type: text/vnd.tiddlywiki +caption: BrainMap +echarts.author: peterhajas +echarts.readme: { "tooltip": { @@ -35,4 +38,4 @@ type: text/vnd.tiddlywiki ] }] -} \ No newline at end of file +} diff --git a/src/echarts/gallary/author-template.tid b/src/echarts/gallary/author-template.tid new file mode 100644 index 0000000..f5e0962 --- /dev/null +++ b/src/echarts/gallary/author-template.tid @@ -0,0 +1,12 @@ +title: $:/plugins/Gk0Wk/echarts/addon-author-template +type: text/vnd.tiddlywiki + +
+ <$macrocall + $name="tabs" + tabsList="[all[shadows+tiddlers]field:echarts.authorsort[caption]]" + default={{{ [all[shadows+tiddlers]field:echarts.authorsort[caption]first[]] }}} + class="tc-vertical" + template="$:/plugins/Gk0Wk/echarts/addon-document-template" + /> +
diff --git a/src/echarts/gallary/document-template.tid b/src/echarts/gallary/document-template.tid new file mode 100644 index 0000000..bd69f31 --- /dev/null +++ b/src/echarts/gallary/document-template.tid @@ -0,0 +1,31 @@ +title: $:/plugins/Gk0Wk/echarts/addon-document-template +type: text/vnd.tiddlywiki + +!! <$text text={{{ [get[caption]] }}} /> + +@@background:#0003;padding:5px 10px;border-left:3px solid #03fffc;font-weight:750;background-image:linear-gradient(0,#03fffc12,#03fffc12); +<$list filter="[has[echarts.author]]"> +<$list filter="[[$:/language]get[text]removeprefix[$:/languages/]else[en-GB]]" variable="lang"> +<$list filter="[search[zh]]"> + +作者: <$text text={{{ [get[echarts.author]] }}} /> + +插件: <> + +文档需要改进?希望分享经验?欢迎提 [[Issue|https://github.com/tiddly-gittly/tw-echarts/issues]] 或者 QQ 群里联系我! + + +<$list filter="[!search[zh]]"> + +Author: <$text text={{{ [get[echarts.author]] }}} /> + +Addon: <> + +Need to improve the documentation? Want to share your experience? Feel free for an [[Issue|https://github.com/tiddly-gittly/tw-echarts/issues]]! + + + + +@@ + +<$transclude mode="block" tiddler=<> field="echarts.readme" /> diff --git a/src/echarts/gallary/index.tid b/src/echarts/gallary/index.tid new file mode 100644 index 0000000..4fccd8e --- /dev/null +++ b/src/echarts/gallary/index.tid @@ -0,0 +1,12 @@ +title: $:/plugins/Gk0Wk/echarts/addons +type: text/vnd.tiddlywiki + +
+ <$macrocall + $name="tabs" + tabsList="[all[shadows+tiddlers]has[echarts.author]get[echarts.author]unique[]sort[]]" + default={{{ [all[shadows+tiddlers]has[echarts.author]get[echarts.author]unique[]sort[]first[]] }}} + class="tc-vertical" + template="$:/plugins/Gk0Wk/echarts/addon-author-template" + /> +
diff --git a/src/echarts/echarts-wordcloud.v2.1.0.min.js b/src/echarts/lib/echarts-wordcloud.v2.1.0.min.js similarity index 100% rename from src/echarts/echarts-wordcloud.v2.1.0.min.js rename to src/echarts/lib/echarts-wordcloud.v2.1.0.min.js diff --git a/src/echarts/echarts-wordcloud.v2.1.0.min.js.meta b/src/echarts/lib/echarts-wordcloud.v2.1.0.min.js.meta similarity index 100% rename from src/echarts/echarts-wordcloud.v2.1.0.min.js.meta rename to src/echarts/lib/echarts-wordcloud.v2.1.0.min.js.meta diff --git a/src/echarts/echarts.v5.4.3.min.js b/src/echarts/lib/echarts.v5.4.3.min.js similarity index 100% rename from src/echarts/echarts.v5.4.3.min.js rename to src/echarts/lib/echarts.v5.4.3.min.js diff --git a/src/echarts/echarts.v5.4.3.min.js.meta b/src/echarts/lib/echarts.v5.4.3.min.js.meta similarity index 100% rename from src/echarts/echarts.v5.4.3.min.js.meta rename to src/echarts/lib/echarts.v5.4.3.min.js.meta diff --git a/src/echarts/plugin.info b/src/echarts/plugin.info index 0f0143e..4abbf75 100755 --- a/src/echarts/plugin.info +++ b/src/echarts/plugin.info @@ -1,10 +1,10 @@ { - "version": "0.2.5", + "version": "0.2.6", "type": "application/json", "title": "$:/plugins/Gk0Wk/echarts", "plugin-type": "plugin", "name": "ECharts", - "list": "readme LICENSE", + "list": "readme addons LICENSE", "description": "ECharts for TiddlyWiki5", "author": "Gk0Wk", "source": "https://github.com/tiddly-gittly/tw-echarts/tree/master/plugins/Gk0Wk/echarts", diff --git a/src/echarts/widget.ts b/src/echarts/widget/index.ts similarity index 99% rename from src/echarts/widget.ts rename to src/echarts/widget/index.ts index ac18657..cbc6dc5 100755 --- a/src/echarts/widget.ts +++ b/src/echarts/widget/index.ts @@ -5,7 +5,7 @@ import type { IWidgetInitialiseOptions, IChangedTiddlers, } from 'tiddlywiki'; -import type { IScriptAddon } from './scriptAddon'; +import type { IScriptAddon } from '../scriptAddon'; import { widget as Widget } from '$:/core/modules/widgets/widget.js'; import * as ECharts from '$:/plugins/Gk0Wk/echarts/echarts.min.js'; diff --git a/src/echarts/widget.ts.meta b/src/echarts/widget/index.ts.meta similarity index 100% rename from src/echarts/widget.ts.meta rename to src/echarts/widget/index.ts.meta diff --git a/src/echarts/macro.tid b/src/echarts/widget/macro.tid similarity index 100% rename from src/echarts/macro.tid rename to src/echarts/widget/macro.tid diff --git a/wiki/tiddlers/$__themes_tiddlywiki_vanilla_metrics_sidebarwidth.tid b/wiki/tiddlers/$__themes_tiddlywiki_vanilla_metrics_sidebarwidth.tid index 6b93c0c..0438c35 100755 --- a/wiki/tiddlers/$__themes_tiddlywiki_vanilla_metrics_sidebarwidth.tid +++ b/wiki/tiddlers/$__themes_tiddlywiki_vanilla_metrics_sidebarwidth.tid @@ -1,8 +1,8 @@ created: 20211012184428513 creator: Sttot -modified: 20230921073200670 +modified: 20230922053006906 modifier: Sttot title: $:/themes/tiddlywiki/vanilla/metrics/sidebarwidth type: text/vnd.tiddlywiki -50.27441134346608vw \ No newline at end of file +42.4267835453722vw \ No newline at end of file diff --git a/wiki/tiddlers/Focus.tid b/wiki/tiddlers/Focus.tid index a695a75..415efd6 100644 --- a/wiki/tiddlers/Focus.tid +++ b/wiki/tiddlers/Focus.tid @@ -1,10 +1,10 @@ caption: Focus created: 20211220184056323 creator: Sttot -modified: 20230116134909478 +modified: 20230922171650939 modifier: Sttot tags: $:/tags/SideBar title: Focus type: text/vnd.tiddlywiki -<$echarts $tiddler="$:/plugins/Gk0Wk/echarts/addons/TheBrain.js" aliasField="caption" levels="1" /> \ No newline at end of file +<$echarts $tiddler="$:/plugins/Gk0Wk/echarts/addons/TheBrain.js" /> \ No newline at end of file diff --git a/wiki/tiddlers/Index.tid b/wiki/tiddlers/Index.tid index ec7c1c3..6ae8766 100755 --- a/wiki/tiddlers/Index.tid +++ b/wiki/tiddlers/Index.tid @@ -55,6 +55,12 @@ type: text/vnd.tiddlywiki * [[我该如何使用该插件?]] * [[请与大家分享你的工作!]] +--- + +!! 内置插件(欢迎提交) + +安装 echarts 后,你可以在 设置-插件-echarts-addons 中找到如下的页面: + <$list filter="[!search[zh]]"> @@ -84,5 +90,15 @@ To use this plugin, or if you have any problems using it, please read the follow * [[How do I use the plugin?]] * [[Please share your work with everyone!]] +--- + +!! Built-in plugins (welcome to submit) + +After installing echarts, you can find the following page in Settings-Plugins-echarts-addons: + + - \ No newline at end of file + +<<< +{{$:/plugins/Gk0Wk/echarts/addons}} +<<<