Skip to content

Commit

Permalink
fix for [#83] [#84] [#88] [#89]
Browse files Browse the repository at this point in the history
  • Loading branch information
Gk0Wk committed Sep 21, 2023
1 parent 7f9f81c commit b15d786
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 187 deletions.
2 changes: 1 addition & 1 deletion src/echarts/addons/Gk0Wk/GitHubHeatMap.ts.meta
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
title: $:/plugins/Gk0Wk/echarts/addons/GitHubHeatMap.ts
type: application/javascript
module-type: echarts-component
Modern.TiddlyDev#IncludeSource: true
Modern.TiddlyDev#IncludeSource: false
2 changes: 1 addition & 1 deletion src/echarts/addons/Gk0Wk/TagCloud.ts.meta
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
title: $:/plugins/Gk0Wk/echarts/addons/TagCloud.ts
type: application/javascript
module-type: echarts-component
Modern.TiddlyDev#IncludeSource: true
Modern.TiddlyDev#IncludeSource: false
20 changes: 20 additions & 0 deletions src/echarts/addons/Gk0Wk/TheBrain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ interface ITheBrainState {
historyTiddlers: string[];
viewingTiddlers: Set<string>;
focusing?: string;
zoomTimer: NodeJS.Timer;
}

const TheBrainAddon: IScriptAddon<ITheBrainState> = {
Expand All @@ -112,8 +113,24 @@ const TheBrainAddon: IScriptAddon<ITheBrainState> = {
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;
}
const newShow = zoom >= 1;
if (option.series[0].label.show !== newShow) {
option.series[0].label.show = newShow;
myChart.setOption(option);
}
}, 200),
};
},
onUnmount: ({ zoomTimer }) => {
clearInterval(zoomTimer);
},
shouldUpdate: (
{ viewingTiddlers, focusing, currentlyFocused },
changedTiddlers,
Expand Down Expand Up @@ -577,6 +594,9 @@ const TheBrainAddon: IScriptAddon<ITheBrainState> = {
labelLayout: {
moveOverlap: true,
},
edgeLabel: {
show: false,
},
force: {
repulsion: 50,
},
Expand Down
2 changes: 1 addition & 1 deletion src/echarts/addons/Gk0Wk/TheBrain.ts.meta
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
title: $:/plugins/Gk0Wk/echarts/addons/TheBrain.ts
type: application/javascript
module-type: echarts-component
Modern.TiddlyDev#IncludeSource: true
Modern.TiddlyDev#IncludeSource: false
45 changes: 0 additions & 45 deletions src/echarts/echarts.v5.4.1.min.js

This file was deleted.

32 changes: 32 additions & 0 deletions src/echarts/echarts.v5.4.3.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ title: $:/plugins/Gk0Wk/echarts/echarts.min.js
type: application/javascript
module-type: library
Modern.TiddlyDev#Minify: false
version: 5.4.1
version: 5.4.3
2 changes: 1 addition & 1 deletion src/echarts/plugin.info
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.2.4",
"version": "0.2.5",
"type": "application/json",
"title": "$:/plugins/Gk0Wk/echarts",
"plugin-type": "plugin",
Expand Down
104 changes: 0 additions & 104 deletions src/echarts/renderHeadless.ts

This file was deleted.

57 changes: 30 additions & 27 deletions src/echarts/widget.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* eslint-disable @typescript-eslint/lines-between-class-members */
/* eslint-disable max-lines */
/* eslint-disable max-lines, no-bitwise */
import type {
IParseTreeNode,
IWidgetInitialiseOptions,
IChangedTiddlers,
} from 'tiddlywiki';
// import { renderHeadless } from './renderHeadless';
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';
Expand Down Expand Up @@ -164,26 +163,12 @@ class EChartsWidget extends Widget {
) {
throw new Error('Widget need either $tiddler or $text attribute!');
}
const ssr = (parent as any).isTiddlyWikiFakeDom;
const ssr = Boolean((parent as any).isTiddlyWikiFakeDom);
this.rebuildInstance(ssr);
this.initAddon();
this.renderAddon();
if (ssr) {
// 如果是非浏览器环境,使用 SSR
// const node = renderHeadless(
// this.text,
// this.tiddlerTitle,
// this.attributes,
// this.theme,
// this.uuid,
// this.renderer,
// this.fillSidebar,
// this.document,
// );
// if (node) {
// this.containerDom.setAttribute('id', this.uuid);
// parent.appendChild(node);
// }
// https://echarts.apache.org/handbook/zh/how-to/cross-platform/server
if (
!Number.isSafeInteger(Number(this.width.replace('px', ''))) ||
Expand Down Expand Up @@ -231,7 +216,6 @@ class EChartsWidget extends Widget {
}
});
if (counter > 0) {
// eslint-disable-next-line no-bitwise
refreshFlag |= 2;
}
if (changedAttributes.$class) {
Expand All @@ -250,25 +234,25 @@ class EChartsWidget extends Widget {
this.containerDom.style.height = this.height;
}
if ($tw.utils.count(changedAttributes) > counter) {
// eslint-disable-next-line no-bitwise
refreshFlag |= 1;
}
}
if (
this.text === undefined &&
// eslint-disable-next-line no-bitwise
!(refreshFlag & 1) &&
((this.tiddlerTitle && changedTiddlers[this.tiddlerTitle]) ||
this.askForAddonUpdate(changedTiddlers, changedAttributes))
) {
// eslint-disable-next-line no-bitwise
refreshFlag |= 1;
}
// 检查自动主题时,黑暗模式是否切换了
const oldTheme = this.theme;
this.execute();
// eslint-disable-next-line no-bitwise
if (oldTheme !== this.theme) {
refreshFlag |= 2;
}
if (refreshFlag & 2) {
const oldOption = this.rebuildInstance();
// eslint-disable-next-line no-bitwise
if (!oldOption || refreshFlag & 1) {
unmountAddon(
this.text !== undefined ? undefined : oldAddonTitle,
Expand All @@ -280,7 +264,6 @@ class EChartsWidget extends Widget {
} else {
this.echartsInstance!.setOption(oldOption);
}
// eslint-disable-next-line no-bitwise
} else if (refreshFlag & 1) {
this.renderAddon();
}
Expand All @@ -297,6 +280,13 @@ class EChartsWidget extends Widget {
return false;
}
const tiddler = $tw.wiki.getTiddler(this.tiddlerTitle)!.fields;
// 懒加载模式,还在加载,要等待
if (
'_is_skinny' in tiddler &&
$tw.wiki.getTiddlerText(this.tiddlerTitle) === null
) {
return false;
}
const type = tiddler.type || 'text/vnd.tiddlywiki';
if (type === 'text/vnd.tiddlywiki' || type === 'application/json') {
this._state = JSON.stringify(
Expand Down Expand Up @@ -398,6 +388,13 @@ class EChartsWidget extends Widget {
return;
}
const tiddler = $tw.wiki.getTiddler(this.tiddlerTitle)!.fields;
// 懒加载模式,还在加载,要等待
if (
'_is_skinny' in tiddler &&
$tw.wiki.getTiddlerText(this.tiddlerTitle) === null
) {
return;
}
const type = tiddler.type || 'text/vnd.tiddlywiki';
if (type === 'text/vnd.tiddlywiki' || type === 'application/json') {
this.state =
Expand Down Expand Up @@ -439,6 +436,13 @@ class EChartsWidget extends Widget {
return;
}
const tiddler = $tw.wiki.getTiddler(this.tiddlerTitle)!.fields;
// 懒加载模式,还在加载,要等待
if (
'_is_skinny' in tiddler &&
$tw.wiki.getTiddlerText(this.tiddlerTitle) === null
) {
return;
}
const type = tiddler.type || 'text/vnd.tiddlywiki';
if (type === 'text/vnd.tiddlywiki') {
const plainTextContent = $tw.wiki.renderTiddler(
Expand All @@ -449,8 +453,7 @@ class EChartsWidget extends Widget {
},
);
// Allow using js style key without `""`, and allow list to have tailing comma, and allow having `//`
// eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func
const executedJSContent = new Function(
const executedJSContent = new Function_(
`return (${plainTextContent})`,
)();
this.echartsInstance.setOption(executedJSContent);
Expand Down Expand Up @@ -493,5 +496,5 @@ class EChartsWidget extends Widget {
}

exports.echarts = EChartsWidget;
/* eslint-enable max-lines */
/* eslint-enable max-lines, no-bitwise */
/* eslint-enable @typescript-eslint/lines-between-class-members */
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
created: 20211012184428513
creator: Sttot
modified: 20230115065048122
modified: 20230921073200670
modifier: Sttot
title: $:/themes/tiddlywiki/vanilla/metrics/sidebarwidth
type: text/vnd.tiddlywiki

36.29910223963303vw
50.27441134346608vw
8 changes: 4 additions & 4 deletions wiki/tiddlers/Index.tid
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
created: 20211225111332641
icon: $:/favicon.ico
modified: 20230115082351288
modified: 20230921071025797
page-cover: banner.png
tags: ECharts Readme
title: Index
type: text/vnd.tiddlywiki

<div style="max-width: 800px; height: 230px; margin: 0 auto;">
<center style="font-size:20px;">
<div style="max-width: 800px; height: 230px; margin: 0 auto; position: relative;">
<center style="font-size:20px; position: absolute; bottom: 28px; z-index: 1000; width: 100%; left: 0; right: 0; display: flex; align-items: center; justify-content: center;">
<$button
set="$:/state/heatmap!!year"
setTo={{{ [{$:/state/heatmap!!year}subtract[1]!match[-1]] ~[<now YYYY>subtract[1]] }}}
class="tc-btn-invisible tc-tiddlylink"

>
</$button> ''<$text text={{{[{$:/state/heatmap!!year}match[]then<now YYYY>else{$:/state/heatmap!!year}]}}}/>'' <$button
</$button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<$button
set="$:/state/heatmap!!year"
setTo={{{ [{$:/state/heatmap!!year}add[1]!match[1]] ~[<now YYYY>add[1]] }}}
class="tc-btn-invisible tc-tiddlylink"
Expand Down

0 comments on commit b15d786

Please sign in to comment.