Skip to content

Commit

Permalink
Add attribute for eachrts, default to 1000ms [#102]
Browse files Browse the repository at this point in the history
  • Loading branch information
Gk0Wk committed Oct 18, 2023
1 parent 4ca1209 commit 3e3dbe3
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 128 deletions.
26 changes: 20 additions & 6 deletions src/echarts/addons/Gk0Wk/GitHubHeatMap/GitHubHeatMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,29 @@ const checkIfDarkMode = () =>
'color-scheme'
] === 'dark';

const GitHubHeatMapAddon: IScriptAddon<any> = {
shouldUpdate: (_, changedTiddlers) => $tw.utils.count(changedTiddlers) > 0,
onUpdate: (myChart, _state, addonAttributes) => {
const GitHubHeatMapAddon: IScriptAddon<{ filter: string }> = {
onMount: (_, attr) => {
return {
filter: attr.subfilter || '[all[tiddlers]!is[shadow]!is[system]]',
};
},
shouldUpdate: (state, changedTiddlers, changedAttributes, attributes) => {
state.filter =
attributes.subfilter ||
state.filter ||
'[all[tiddlers]!is[shadow]!is[system]]';
const t = ($tw.wiki as any).makeTiddlerIterator(
Object.keys(changedTiddlers),
);
return (
$tw.utils.count($tw.wiki.filterTiddlers(state.filter, undefined, t)) > 0
);
},
onUpdate: (myChart, state, addonAttributes) => {
const year = parseInt(addonAttributes.year, 10) || new Date().getFullYear();
const subfilter =
addonAttributes.subfilter || '[all[tiddlers]!is[shadow]!is[system]]';
/** Use subfilter to narrow down tiddler pool before the array.map on dates */
const tiddlerSourceIterator = ($tw.wiki as any).makeTiddlerIterator(
$tw.wiki.filterTiddlers(subfilter),
$tw.wiki.filterTiddlers(state.filter),
);
const [data, total] = getData(year, tiddlerSourceIterator);
const tooltipFormatter = (dateValue: string, count: number) => {
Expand Down
49 changes: 23 additions & 26 deletions src/echarts/addons/Gk0Wk/TheBrain/TheBrain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,19 @@ interface ITheBrainState {
unmount: () => void;
}

const TheBrainAddon: IScriptAddon<ITheBrainState> = {
interface ITheBrainAttributes {
focussedTiddler?: string;
levels?: string;
graphTitle?: string;
aliasField?: string;
excludeFilter?: string;
previewDelay?: string;
focusBlur?: string;
previewTemplate?: string;
zoom?: string;
}

const TheBrainAddon: IScriptAddon<ITheBrainState, ITheBrainAttributes> = {
onMount: (myChart, attributes) => {
myChart.on('click', { dataType: 'node' }, (event: any) => {
new $tw.Story().navigateTiddler(event.data.name);
Expand Down Expand Up @@ -202,35 +214,20 @@ const TheBrainAddon: IScriptAddon<ITheBrainState> = {
);
},
// eslint-disable-next-line complexity
onUpdate: (
myCharts,
state,
addonAttributes: {
focussedTiddler?: string;
levels?: number;
graphTitle?: string;
aliasField?: string;
excludeFilter?: string;
previewDelay?: string;
focusBlur?: string;
previewTemplate?: string;
zoom?: string;
},
) => {
onUpdate: (myCharts, state, addonAttributes) => {
/** 参数:focussedTiddler 是图的中央节点 */
let focussedTiddlers = new Set<string>();
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);
const titles = addonAttributes.focussedTiddler
? $tw.wiki.filterTiddlers(addonAttributes.focussedTiddler)
: [$tw.wiki.getTiddlerText('$:/temp/focussedTiddler') ?? ''];
for (const title of titles) {
// 跳过正在编辑的条目
if ($tw.wiki.getTiddler(title)?.fields?.['draft.of']) {
continue;
}
focussedTiddlers.add(title);
}

if (focussedTiddlers.size === 0) {
return;
}
Expand Down
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.6",
"version": "0.2.7",
"type": "application/json",
"title": "$:/plugins/Gk0Wk/echarts",
"plugin-type": "plugin",
Expand Down
16 changes: 8 additions & 8 deletions src/echarts/scriptAddon.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ECharts } from 'echarts';
import type { Widget } from 'tiddlywiki';
import type { Widget, IChangedTiddlers } from 'tiddlywiki';

export interface IScriptAddon<
StateType = any,
Expand All @@ -22,17 +22,17 @@ export interface IScriptAddon<
* @param {StateType} state 组件的状态,就是onMount返回的那个
* @param {IChangedTiddlers} changedTiddlers 刷新是由TW系统监听到有条目发生变化才会触发的,这是一个包含所有变更条目标题的字符串数组
* @param {Record<string, true>} changedAttributes 哪些参数被改变了,包括$开头的参数
* @param {AttributesType} addonAttributes <$echarts> 控件传入的所有参数
* @return {boolean} 如果需要刷新就返回true,反之
*
* shouldRefresh 也可以是一个字符串,那就和 echarts-refresh-trigger 字段一样
*/
shouldUpdate?:
| ((
state: StateType,
changedTiddlers: IChangedTiddlers,
changedAttributes: Record<string, true>,
) => boolean)
| boolean;
shouldUpdate?: (
state: StateType,
changedTiddlers: IChangedTiddlers,
changedAttributes: Record<keyof AttributesType, true>,
addonAttributes: AttributesType,
) => boolean;
/**
* 当组件被更新时调用的函数
* @param {ECharts} myChart echarts实例,详见echarts的API文档
Expand Down
Loading

0 comments on commit 3e3dbe3

Please sign in to comment.