Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support ranges for Value Mappings #421

Merged
merged 11 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/locales/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,6 @@ const msg = {
tabExpressions: "Tab Expressions",
hierarchyNodeMetrics: "Metrics for Hierarchy Graph Node",
hierarchyNodeDashboard: "As dashboard for Hierarchy Graph Node",
contentDecorations: "Content Decorations",
valueMappings: "Value Mappings",
};
export default msg;
2 changes: 1 addition & 1 deletion src/locales/lang/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,6 @@ const msg = {
tabExpressions: "Tab Expressions",
hierarchyNodeMetrics: "Metrics for Hierarchy Graph Node",
hierarchyNodeDashboard: "As dashboard for Hierarchy Graph Node",
contentDecorations: "Content Decorations",
valueMappings: "Value Mappings",
};
export default msg;
2 changes: 1 addition & 1 deletion src/locales/lang/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,6 @@ const msg = {
tabExpressions: "Tab表达式",
hierarchyNodeMetrics: "层次图节点的指标",
hierarchyNodeDashboard: "作为层次图节点的dashboard",
contentDecorations: "内容装饰",
valueMappings: "值映射",
};
export default msg;
2 changes: 1 addition & 1 deletion src/types/dashboard.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export interface CardConfig {
fontSize?: number;
showUnit?: boolean;
textAlign?: "center" | "right" | "left";
decorations?: { [key: string]: string };
valueMappings?: { [key: string]: string };
}

export interface TextConfig {
Expand Down
2 changes: 1 addition & 1 deletion src/views/dashboard/Widget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ limitations under the License. -->
:config="{
i: 0,
...graph,
decorations: graph?.decorations,
valueMappings: graph?.valueMappings,
metricConfig: config.metricConfig,
expressions: config.expressions || [],
typesOfMQE: typesOfMQE || [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License. -->
<template>
<div>
<span class="label">{{ t("contentDecorations") }}</span>
<content-decorations />
<span class="label">{{ t("valueMappings") }}</span>
<value-mappings />
</div>
<div>
<span class="label">{{ t("fontSize") }}</span>
Expand All @@ -39,7 +39,7 @@ limitations under the License. -->
import { ref } from "vue";
import { useI18n } from "vue-i18n";
import { useDashboardStore } from "@/store/modules/dashboard";
import ContentDecorations from "./components/ContentDecorations.vue";
import ValueMappings from "./components/ValueMappings.vue";

const { t } = useI18n();
const dashboardStore = useDashboardStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License. -->
<template>
<div>
<span class="label">{{ t("contentDecorations") }}</span>
<content-decorations />
<span class="label">{{ t("valueMappings") }}</span>
<value-mappings />
</div>
<div class="item">
<span class="label">{{ t("showValues") }}</span>
Expand All @@ -41,7 +41,7 @@ limitations under the License. -->
import { ref } from "vue";
import { useI18n } from "vue-i18n";
import { useDashboardStore } from "@/store/modules/dashboard";
import ContentDecorations from "./components/ContentDecorations.vue";
import ValueMappings from "./components/ValueMappings.vue";

const { t } = useI18n();
const dashboardStore = useDashboardStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License. -->
</div>
<div class="ml-5 mr-10">:</div>
<div class="content-decoration" contenteditable="true" @blur="changeValues($event, key)">
{{ decorations[key] }}
{{ valueMappings[key] }}
</div>
<div v-if="index === keys.length - 1">
<Icon class="cp mr-5" iconName="add_circle_outlinecontrol_point" size="middle" @click="addDecoration" />
Expand All @@ -39,23 +39,23 @@ limitations under the License. -->

const dashboardStore = useDashboardStore();
const graph = dashboardStore.selectedGrid.graph;
const decorations = ref<{ [key: string]: string }>(graph?.decorations || {});
const keys = ref<string[]>(graph.decorations ? Object.keys(decorations.value) : [""]);
const valueMappings = ref<{ [key: string]: string }>(graph?.valueMappings || {});
const keys = ref<string[]>(graph.valueMappings ? Object.keys(valueMappings.value) : [""]);

function changeKeys(event: any, index: number) {
const params = event.target.textContent || "";
const list = Object.keys(decorations.value);
const list = Object.keys(valueMappings.value);
if (params) {
decorations.value[params] = decorations.value[list[index]];
valueMappings.value[params] = valueMappings.value[list[index]];
}
delete decorations.value[list[index]];
keys.value = Object.keys(decorations.value);
updateConfig({ decorations: decorations.value });
delete valueMappings.value[list[index]];
keys.value = Object.keys(valueMappings.value);
updateConfig();
}

function changeValues(event: any, key: string) {
decorations.value[key] = event.target.textContent || "";
updateConfig({ decorations: decorations.value });
valueMappings.value[key] = event.target.textContent || "";
updateConfig();
}

function addDecoration() {
Expand All @@ -66,18 +66,15 @@ limitations under the License. -->
if (!keys.value.length) {
return;
}
if (!keys.value[index]) {
return;
}
delete decorations.value[keys.value[index]];
delete valueMappings.value[keys.value[index]];
keys.value.splice(index, 1);
updateConfig({ decorations: decorations.value });
updateConfig();
}

function updateConfig(param: { [key: string]: unknown }) {
function updateConfig() {
const graph = {
...dashboardStore.selectedGrid.graph,
...param,
valueMappings: valueMappings.value,
};
dashboardStore.selectWidget({ ...dashboardStore.selectedGrid, graph });
}
Expand Down
33 changes: 30 additions & 3 deletions src/views/dashboard/graphs/Card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ limitations under the License. -->
justifyContent: config.textAlign || 'center',
}"
>
{{ decorations[singleVal] || singleVal }}
{{ getValue() }}
<span class="unit" v-show="config.showUnit && unit">
{{ decodeURIComponent(unit) }}
</span>
Expand All @@ -48,18 +48,45 @@ limitations under the License. -->
showUnit: true,
textAlign: "center",
metricConfig: [],
decorations: {},
valueMappings: {},
}),
},
});
const { t } = useI18n();
const metricConfig = computed(() => props.config.metricConfig || []);
const decorations = computed(() => props.config.decorations || {});
const valueMappings = computed(() => props.config.valueMappings || {});
const key = computed(() => Object.keys(props.data)[0]);
const singleVal = computed(() =>
Array.isArray(props.data[key.value]) ? props.data[key.value][0] : props.data[key.value],
);
const unit = computed(() => metricConfig.value[0] && encodeURIComponent(metricConfig.value[0].unit || ""));

function getValue() {
if (valueMappings.value[singleVal.value]) {
return valueMappings.value[singleVal.value];
}
const regex = /-?\d+(\.\d+)?/g;
const list = Object.keys(valueMappings.value);
for (const i of list) {
const k = i.replace(/\s+/g, "");
let withinRange = false;
const ranges = k.match(regex)?.map(Number) || [];
if (k.startsWith("[")) {
withinRange = k.startsWith("[-∞") || Number(singleVal.value) >= ranges[0];
} else {
withinRange = k.startsWith("(-∞") || Number(singleVal.value) > ranges[0];
}
if (k.endsWith("]")) {
withinRange = withinRange && (k.endsWith("+∞]") || Number(singleVal.value) <= (ranges[1] || ranges[0]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, +∞ and -∞ are supported if we need no upper or lower boundary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a little concern of , it is hard to input from the keyboard. How about infinite+ and infinite-

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this supports writing regular expressions directly, how about that. For example, ^(10|[0-9])$ matches 0-10.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to write 25-34 in regex? Regex is better in string pattern match I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\b(2[5-9]|3[0-4])\b could catch up, regex may not be as intuitive as the current method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fine0830 Could you try to change the format to include a regex?

} else {
withinRange = withinRange && (k.endsWith("+∞)") || Number(singleVal.value) < (ranges[1] || ranges[0]));
}
if (withinRange) {
return valueMappings.value[i] || singleVal.value;
}
}
return singleVal.value;
}
</script>
<style lang="scss" scoped>
.chart-card {
Expand Down
32 changes: 28 additions & 4 deletions src/views/dashboard/graphs/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ limitations under the License. -->
showTableValues: boolean;
tableHeaderCol2: string;
typesOfMQE: string[];
decorations: {};
valueMappings: {};
}>,
default: () => ({ showTableValues: true }),
},
});

const { t } = useI18n();
const decorations = computed<{ [key: number]: string }>(() => props.config.decorations || {});
const valueMappings = computed<{ [key: string]: string }>(() => props.config.valueMappings || {});
const nameWidth = computed(() => (props.config.showTableValues ? 80 : 100));
const dataKeys = computed(() => {
const keys = Object.keys(props.data || {}).filter(
Expand All @@ -75,9 +75,33 @@ limitations under the License. -->

return list;
});

function getColValue(keys: string[]) {
const val = props.data[(keys as string[]).join(",")][props.data[(keys as string[]).join(",")].length - 1 || 0];
return decorations.value[val] || val;
const source = props.data[(keys as string[]).join(",")][props.data[(keys as string[]).join(",")].length - 1 || 0];
if (valueMappings.value[source]) {
return valueMappings.value[source];
}
const regex = /-?\d+(\.\d+)?/g;
const list = Object.keys(valueMappings.value);
for (const i of list) {
const k = i.replace(/\s+/g, "");
let withinRange = false;
const ranges = k.match(regex)?.map(Number) || [];
if (k.startsWith("[")) {
withinRange = k.startsWith("[-∞") || Number(source) >= ranges[0];
} else {
withinRange = k.startsWith("(-∞") || Number(source) > ranges[0];
}
if (k.endsWith("]")) {
withinRange = withinRange && (k.endsWith("+∞]") || Number(source) <= (ranges[1] || ranges[0]));
} else {
withinRange = withinRange && (k.endsWith("+∞)") || Number(source) < (ranges[1] || ranges[0]));
}
if (withinRange) {
return valueMappings.value[i];
}
}
return source;
}
</script>
<style lang="scss" scoped>
Expand Down
Loading