fix: render graphs

This commit is contained in:
Qiuxia Fan 2022-01-06 16:10:15 +08:00
parent c282655369
commit f19b69d050
8 changed files with 56 additions and 49 deletions

View File

@ -43,7 +43,6 @@ const props = defineProps({
onMounted(() => { onMounted(() => {
setTimeout(() => { setTimeout(() => {
console.log(chart.value);
drawEcharts(); drawEcharts();
window.addEventListener("resize", state.instanceChart.resize); window.addEventListener("resize", state.instanceChart.resize);
}, 50); }, 50);

View File

@ -23,7 +23,7 @@ export const ConfigData: LayoutConfig = {
i: "0", i: "0",
metrics: ["service_resp_time"], metrics: ["service_resp_time"],
queryMetricType: "readMetricsValues", queryMetricType: "readMetricsValues",
visualization: "Line", visualization: "Bar",
widget: { widget: {
title: "Title", title: "Title",
tips: "Tooltip", tips: "Tooltip",

View File

@ -86,7 +86,7 @@ limitations under the License. -->
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { reactive, defineComponent, ref } from "vue"; import { reactive, defineComponent } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";

View File

@ -13,10 +13,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<Graph ref="chart" :option="option" :autoResize="true" /> <Graph :option="option" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { defineProps, ref, computed } from "vue"; import { defineProps, computed } from "vue";
import type { PropType } from "vue"; import type { PropType } from "vue";
import { Event } from "@/types/events"; import { Event } from "@/types/events";
@ -37,8 +37,6 @@ const props = defineProps({
default: () => ({ theme: "light", showBackground: true, barWidth: 20 }), default: () => ({ theme: "light", showBackground: true, barWidth: 20 }),
}, },
}); });
/*global Nullable */
const chart = ref<Nullable<HTMLElement>>(null);
const option = computed(() => getOption()); const option = computed(() => getOption());
function getOption() { function getOption() {

View File

@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<Graph ref="chart" :option="option" :autoResize="true" /> <Graph :option="option" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { defineProps, ref, computed } from "vue"; import { defineProps, ref, computed } from "vue";

View File

@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<Graph ref="chart" :option="option" :autoResize="true" /> <Graph :option="option" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { defineProps, ref, computed } from "vue"; import { defineProps, ref, computed } from "vue";
@ -30,8 +30,6 @@ const props = defineProps({
theme: { type: String, default: "light" }, theme: { type: String, default: "light" },
itemEvents: { type: Array as PropType<Event[]>, default: () => [] }, itemEvents: { type: Array as PropType<Event[]>, default: () => [] },
}); });
/*global Nullable */
const chart = ref<Nullable<HTMLElement>>(null);
const option = computed(() => getOption()); const option = computed(() => getOption());
function getOption() { function getOption() {
const keys = Object.keys(props.data || {}).filter( const keys = Object.keys(props.data || {}).filter(

View File

@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<Graph ref="chart" :option="option" :autoResize="true" /> <Graph :option="option" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { defineProps, ref, computed } from "vue"; import { defineProps, ref, computed } from "vue";

View File

@ -35,50 +35,62 @@ limitations under the License. -->
</div> </div>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts">
import { defineProps, reactive, onMounted } from "vue"; import { toRefs, reactive, defineComponent } from "vue";
import type { PropType } from "vue"; import type { PropType } from "vue";
import { LayoutConfig } from "@/types/dashboard"; import { LayoutConfig } from "@/types/dashboard";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";
import graphs from "../graphs";
const state = reactive({ const props = {
source: {},
});
const props = defineProps({
item: { type: Object as PropType<LayoutConfig>, default: () => ({}) }, item: { type: Object as PropType<LayoutConfig>, default: () => ({}) },
}); };
const appStoreWithOut = useAppStoreWithOut(); export default defineComponent({
const dashboardStore = useDashboardStore(); name: "Widget",
onMounted(() => { components: { ...graphs },
queryMetrics(); props,
}); setup(props) {
async function queryMetrics() { const state = reactive({
const json = await dashboardStore.fetchMetricValue(props.item); source: {},
});
const { item } = toRefs(props);
const appStoreWithOut = useAppStoreWithOut();
const dashboardStore = useDashboardStore();
queryMetrics();
async function queryMetrics() {
const json = await dashboardStore.fetchMetricValue(props.item);
if (json.error) { if (json.error) {
return; return;
} }
const metricVal = json.data.readMetricsValues.values.values.map( const metricVal = json.data.readMetricsValues.values.values.map(
(d: any) => d.value (d: any) => d.value
); );
const m = props.item.metrics && props.item.metrics[0]; const m = props.item.metrics && props.item.metrics[0];
if (!m) { if (!m) {
return; return;
} }
state.source = { state.source = {
[m]: metricVal, [m]: metricVal,
}; };
console.log(state.source); }
}
function removeWidget() { function removeWidget() {
dashboardStore.removeWidget(props.item); dashboardStore.removeWidget(props.item);
} }
function setConfig() { function setConfig() {
dashboardStore.setConfigPanel(true); dashboardStore.setConfigPanel(true);
dashboardStore.selectWidget(props.item); dashboardStore.selectWidget(props.item);
} }
return {
state,
appStoreWithOut,
removeWidget,
setConfig,
item,
};
},
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.widget { .widget {