Skip to content

Commit

Permalink
fix: delete width props from MonthlyCostWidget & set custom xaxis for…
Browse files Browse the repository at this point in the history
…mat (#3094)

* chore: change xaxis label when width is less than 370

* fix(use-widget-lifecycle): delete unnecessary condition
  • Loading branch information
yuda110 authored Feb 15, 2024
1 parent fe9ba6c commit f041157
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const useWidgetLifecycle = <Data = any>({
}, { deep: true });

const stopVariablesSchemaWatch = watch(() => props.dashboardVariablesSchema, (after, before) => {
if (!initiated.value || !props.editMode || !widgetState.inheritOptions || !widgetState.schemaProperties || !widgetState.options
if (!initiated.value || !widgetState.inheritOptions || !widgetState.schemaProperties || !widgetState.options
|| isEqual(after, before) || props.disableRefreshOnVariableChange) return;

const { isWidgetUpdated, isValid, updatedWidgetInfo } = validateWidgetByVariablesSchemaUpdate({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<script setup lang="ts">
import {
computed, defineExpose, defineProps, nextTick, reactive, ref, toRef,
computed, defineExpose, defineProps, nextTick, reactive, ref, toRef, watch,
} from 'vue';
import type { AxisRenderer, DateAxis } from '@amcharts/amcharts5/xy';
import {
PDivider, PDataLoader, PI, PSkeleton,
} from '@spaceone/design-system';
Expand Down Expand Up @@ -45,6 +46,7 @@ const DATE_FORMAT = 'YYYY-MM';
const DATE_FIELD_NAME = 'date';
const VALUE_FIELD_NAME = 'value';
const STROKE_FIELD_NAME = 'strokeSettings';
const CHART_XAXIS_CHANGE_THRESHOLD_WIDTH = 370;
const props = defineProps<WidgetProps>();
const emit = defineEmits<WidgetEmit>();
Expand Down Expand Up @@ -136,6 +138,7 @@ const displayState = reactive({
return displayState.isDecreased ? green[600] : red[500];
}),
currencySymbol: computed<CurrencySymbol>(() => (widgetState.currency ? CURRENCY_SYMBOL[widgetState.currency] : CURRENCY_SYMBOL.USD)),
chartXAxis: undefined as undefined|DateAxis<AxisRenderer>,
});
/* Api */
Expand Down Expand Up @@ -261,6 +264,9 @@ const drawChart = (chartData: ChartData[]) => {
}),
});
});
// for responsive design
displayState.chartXAxis = xAxis;
};
const initWidget = async (data?: Data[]): Promise<Data[]> => {
Expand Down Expand Up @@ -303,11 +309,18 @@ defineExpose<WidgetExpose<Data[]>>({
initWidget,
refreshWidget,
});
watch(() => props.width, (_width) => {
if (_width && (_width < CHART_XAXIS_CHANGE_THRESHOLD_WIDTH)) {
displayState.chartXAxis.get('dateFormats').month = 'M';
} else {
displayState.chartXAxis.get('dateFormats').month = 'MMM';
}
});
</script>

<template>
<widget-frame v-bind="widgetFrameProps"
:width="props.disableFullMode ? undefined : 542"
v-on="widgetFrameEventHandlers"
>
<div class="monthly-cost">
Expand Down

1 comment on commit f041157

@vercel
Copy link

@vercel vercel bot commented on f041157 Feb 15, 2024

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

console – ./

console-cloudforet.vercel.app
console-git-master-cloudforet.vercel.app

Please sign in to comment.