OcttKB/Wiki-OcttKB/plugins/echarts/$__plugins_Gk0Wk_echarts_ad...

8 lines
18 KiB
JSON
Raw Normal View History

2023-06-11 22:14:59 +02:00
[
{
"title": "$:/plugins/Gk0Wk/echarts/addons/TheBrain.ts",
"text": "/* eslint-disable max-lines */\nimport type { IParseTreeNode } from 'tiddlywiki';\nimport type { IScriptAddon } from '../../scriptAddon';\n\nconst colors = [\n '#5470c6',\n '#91cc75',\n '#fac858',\n '#ee6666',\n '#73c0de',\n '#3ba272',\n '#fc8452',\n '#9a60b4',\n '#ea7ccc',\n];\nconst CategoriesEn = [\n 'Focusing',\n 'History',\n 'Link To',\n 'Backlink From',\n 'Tag To',\n 'Tag By',\n 'Transclude',\n].map((name, index) => ({\n name,\n itemStyle: { color: colors[index % colors.length] },\n}));\nconst CategoriesZh = [\n '聚焦',\n '历史',\n '链接',\n '反链',\n '标签',\n '作为标签',\n '嵌套',\n].map((name, index) => ({\n name,\n itemStyle: { color: colors[index % colors.length] },\n}));\nconst attributes = new Set<string>([\n 'focussedTiddler',\n 'levels',\n 'graphTitle',\n 'aliasField',\n 'excludeFilter',\n 'previewDelay',\n]);\nconst getPlatteColor = (name: string) =>\n $tw.wiki.renderText(\n 'text/plain',\n 'text/vnd.tiddlywiki',\n `<$transclude tiddler={{$:/palette}} index=\"${name}\"><$transclude tiddler=\"$:/palettes/Vanilla\" index=\"${name}\"><$transclude tiddler=\"$:/config/DefaultColourMappings/${name}\"/></$transclude></$transclude>`,\n {},\n );\n\nconst findIcon = (title: string) => {\n const fields = $tw.wiki.getTiddler(title)?.fields;\n if (!fields?.icon) {\n return undefined;\n }\n const iconFields = $tw.wiki.getTiddler(fields.icon as string)?.fields;\n if (!iconFields) {\n if (/^https?:\\/\\//.test(fields.icon as string)) {\n return `image://${fields.icon as string}`;\n }\n return undefined;\n }\n if (iconFields._canonical_uri) {\n return `image://${iconFields._canonical_uri}`;\n } else if (iconFields.title.startsWith('$:/core/images/')) {\n return undefined;\n } else {\n return `image://data:${iconFields.type};base64,${iconFields.text}`;\n }\n};\nconst getAliasOrTitle = (\n tiddlerTitle: string,\n aliasField: string | undefined,\n): [string, boolean] => {\n if (aliasField === undefined || aliasField === 'title') {\n return [tiddlerTitle, Boolean($tw.wiki.getTiddler(tiddlerTitle))];\n }\n const tiddler = $tw.wiki.getTiddler(tiddlerTitle);\n if (tiddler) {\n const aliasValue = tiddler.fields[aliasField];\n return [\n typeof aliasValue === 'string'\n ? $tw.wiki.renderText('text/plain', 'text/vnd.tiddlywiki', aliasValue, {\n variables: { currentTiddler: tiddlerTitle },\n })\n : tiddlerTitle,\n true,\n ];\n } else {\n return [tiddlerTitle, false];\n }\n};\n\ninterface ITheBrainState {\n currentlyFocused?: string;\n historyTiddlers: string[];\n viewingTiddlers: Set<string>;\n focusing?: string;\n}\n\nconst TheBrainAddon: IScriptAddon<ITheBrainState> = {\n onMount: (myChart, attributes) => {\n myChart.on('click', { dataType: 'node' }, (event: any) => {\n new $tw.Story().navigateTiddler(event.data.name);\n });\n return {\n historyTiddlers: [],\n viewingTiddlers: new Set(),\n focusing: attributes.focussedTiddler,\n };\n },\n shouldUpdate: (\n { viewingTiddlers, focusing, currentlyFocused },\n changedTiddlers,\n changedAttributes,\n ) => {\n return (\n Object.keys(changedTiddlers).some(title => viewingTiddlers.has(title)) ||\n Object.keys(changedAttributes).some(attribute =>\n attributes.has(attribute),\n ) ||\n (focusing === undefined &&\n $tw.wiki.getTiddlerText('$:/temp/focussedTiddler') !== currentlyFocused)\n );\n },\n // eslint-disable-next-line complexity\n onUpdate: (\n myCharts,\n state,\n addonAttributes: {\n focussedTiddler?: string;\n levels?: number;\n graphTitle?: string;\n aliasField?: string;\n excludeFilter?: string;\n previewDelay?: string;\n },\n ) => {\n /** 参数focussedTiddler 是图的中央节点 */\n let focussedTiddler =\n addonAttributes.focussedTiddler ||\n $tw.wiki.getTiddlerText('$:/temp/focussedTiddler')!;\n state.viewingTiddlers.clear();\n state.fo
"Modern.TiddlyDev#IncludeSource": "true",
"type": "application/javascript"
}
]