Skip to content

Commit afd78d0

Browse files
committed
emitter 添加来源
1 parent e645018 commit afd78d0

File tree

4 files changed

+31
-30
lines changed

4 files changed

+31
-30
lines changed

src/editor/datum.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ function graphTypeChange(dataItem: InternalDatum) {
181181
if (dataItem.graphType === "scatter") {
182182
if (!scatteredSet.has(dataItem)) {
183183
scatteredSet.add(dataItem);
184-
emitter.emit("require-full-update");
184+
emitter.emit("require-full-update",'scatter appear');
185185
}
186186
} else {
187187
if (scatteredSet.has(dataItem)) {
188188
scatteredSet.delete(dataItem);
189-
emitter.emit("require-full-update");
189+
emitter.emit("require-full-update",'scatter disappear');
190190
}
191191
}
192192
}

src/graph/graph.vue

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<s-tooltip align="right">
55
<s-icon-button
66
slot="trigger"
7-
@click="emitter.emit('require-full-update')"
7+
@click="emitter.emit('require-full-update', 'manual')"
88
>
99
<SIconRefresh />
1010
</s-icon-button>
@@ -27,15 +27,17 @@ import SIconRefresh from "@/ui/icons/refresh.vue";
2727
import SIconWarn from "@/ui/icons/warn.vue";
2828
2929
import { onMounted, ref, watch } from "vue";
30-
import { cloneDeep, throttle } from "lodash-es";
30+
import { throttle } from "lodash-es";
3131
import type { FunctionPlotDatum } from "function-plot";
3232
import { getFnType } from "../consts";
33-
const { data, width, height } = defineProps<{
34-
data: FunctionPlotDatum[];
33+
const { width, height } = defineProps<{
3534
width: number;
3635
height: number;
3736
}>();
3837
38+
import { useProfile } from "@/states";
39+
const profile = useProfile();
40+
3941
import emitter from "@/mitt";
4042
const fullUpdateState = defineModel<boolean>();
4143
@@ -55,9 +57,10 @@ function findError(graphData: FunctionPlotDatum[]) {
5557
onMounted(async () => {
5658
const functionPlot = (await import("function-plot")).default;
5759
watch(
58-
[() => width, () => height, () => data],
60+
[() => width, () => height, profile],
5961
throttle(() => {
60-
const graphData = cloneDeep(data);
62+
if (import.meta.env.DEV) console.log("graph update");
63+
const graphData = profile.getOriginalData();
6164
const flag = findError(graphData);
6265
if (flag) {
6366
errorMsg.value = `Invalid input in function ${flag + 1}`;
@@ -67,20 +70,19 @@ onMounted(async () => {
6770
plotRef.value &&
6871
functionPlot({
6972
target: plotRef.value,
70-
data: <FunctionPlotDatum[]>(
71-
// (flag ? graphData.slice(0, flag) : graphData)
72-
graphData
73-
),
73+
data: <FunctionPlotDatum[]>graphData,
7474
width: width - 20,
7575
height: height - 20,
76+
annotations: profile.getOriginalAnnotaion(),
7677
});
7778
if (fullUpdateState.value) {
7879
fullUpdateState.value = false;
79-
emitter.emit("require-post-update");
80+
emitter.emit("require-post-update", "once after error");
8081
} else errorMsg.value = undefined;
8182
} catch (e) {
8283
// console.log(e);
83-
if (!fullUpdateState.value) emitter.emit("require-full-update");
84+
if (!fullUpdateState.value)
85+
emitter.emit("require-full-update", "error");
8486
errorMsg.value = (e as Error).message;
8587
}
8688
}, 200),
@@ -104,13 +106,17 @@ onMounted(async () => {
104106
transition: filter 1ms;
105107
}
106108
109+
:root {
110+
--graph-filter: invert(100%) hue-rotate(180deg) contrast(0.8) brightness(1.3);
111+
}
112+
107113
@media (prefers-color-scheme: dark) {
108114
s-page.auto #graphRender {
109-
filter: invert(100%) hue-rotate(180deg) brightness(133%);
115+
filter: var(--graph-filter);
110116
}
111117
}
112118
s-page.dark #graphRender {
113-
filter: invert(100%) hue-rotate(180deg) brightness(133%);
119+
filter: var(--graph-filter);
114120
}
115121
116122
.onresize #graphRender {

src/graph/index.vue

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<template>
22
<div id="graph" ref="shellRef">
33
<Graph
4-
:data="graphData"
54
:width="graphWidth"
65
:height="graphHeight"
76
:key="graphKey"
@@ -12,9 +11,8 @@
1211

1312
<script setup lang="ts">
1413
import Graph from "./graph.vue";
15-
import { computed, onMounted, ref } from "vue";
14+
import { onMounted, ref } from "vue";
1615
import { throttle } from "lodash-es";
17-
import { useProfile } from "@/states";
1816
1917
const graphWidth = ref(0),
2018
graphHeight = ref(0);
@@ -32,20 +30,17 @@ onMounted(() => {
3230
observer.observe(shellRef.value!);
3331
});
3432
35-
const profile = useProfile();
36-
37-
const graphData = computed(() => {
38-
void profile.data;
39-
return profile.getOriginalCopy();
40-
});
41-
4233
import emitter from "@/mitt";
4334
44-
emitter.on("require-full-update", () => {
35+
emitter.on("require-full-update", (str) => {
4536
fullUpdateState.value = true;
4637
graphKey.value++;
38+
if (import.meta.env.DEV)
39+
console.log(`fullUpdateState: ${fullUpdateState.value}, ${str}`);
4740
});
48-
emitter.on("require-post-update", () => {
41+
emitter.on("require-post-update", (str) => {
4942
graphKey.value++;
43+
if (import.meta.env.DEV)
44+
console.log(`postUpdateState: ${fullUpdateState.value}, ${str}`);
5045
});
5146
</script>

src/mitt.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import mitt from "mitt";
22

33
const emitter = mitt<Events>();
44
type Events = {
5-
"require-full-update": void;
6-
"require-post-update": void;
5+
"require-full-update": string;
6+
"require-post-update": string;
77
};
88
export default emitter;

0 commit comments

Comments
 (0)