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

Output Settings Primary Color Picker #5802

Merged
merged 11 commits into from
Dec 13, 2024
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="chart-settings-item">
<div class="chart-settings-item" :style="{ 'border-left': primaryColor }">
<h6>{{ settings.name }}</h6>
<div class="btn-group">
<Button icon="pi pi-cog" rounded text @click="$emit('open')" />
Expand All @@ -10,14 +10,17 @@

<script setup lang="ts">
import Button from 'primevue/button';
import { computed } from 'vue';

defineProps({
const props = defineProps({
settings: {
type: Object,
default: () => ({})
}
});
defineEmits(['open', 'remove']);

const primaryColor = computed(() => (props.settings.primaryColor ? `4px solid ${props.settings.primaryColor}` : ''));
asylves1 marked this conversation as resolved.
Show resolved Hide resolved
</script>

<style scoped>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@
/>
</div>
</div>
<section v-if="activeSettings.type !== 'error-distribution'">
<h6>Color Picker</h6>
<input type="color" :value="primaryColor" @change="onColorChange($event)" />
</section>
</div>
</div>
</transition>
</template>

<script setup lang="ts">
import _ from 'lodash';
import { ref, computed } from 'vue';
import { ref, computed, watch } from 'vue';
import Button from 'primevue/button';
import { ChartSetting } from '@/types/common';
import { ChartAnnotation } from '@/types/Types';
Expand All @@ -69,7 +73,13 @@ const props = defineProps<{
generateAnnotation?: (setting: ChartSetting, query: string) => Promise<ChartAnnotation | null>;
}>();

const emit = defineEmits(['close', 'update-settings-scale', 'delete-annotation', 'create-annotation']);
const emit = defineEmits([
'close',
'update-settings-scale',
'delete-annotation',
'create-annotation',
'update-settings-color'
]);

const useLog = computed(() => props.activeSettings?.scale === 'log');

Expand All @@ -86,6 +96,12 @@ const chartAnnotations = computed(() => {
const isGeneratingAnnotation = ref(false);
const generateAnnotationQuery = ref<string>('');
const showAnnotationInput = ref<Boolean>(false);
const primaryColor = ref(props.activeSettings?.primaryColor ?? '#1B8073');

const onColorChange = (event) => {
primaryColor.value = event.target?.value;
emit('update-settings-color', event.target?.value);
};

const createAnnotation = async () => {
if (props.generateAnnotation === undefined || props.activeSettings === null) {
Expand All @@ -105,6 +121,15 @@ const cancelGenerateAnnotation = () => {
generateAnnotationQuery.value = '';
showAnnotationInput.value = false;
};

watch(
() => props.activeSettings,
() => {
if (props.activeSettings?.primaryColor) {
primaryColor.value = props.activeSettings.primaryColor;
}
}
);
</script>

<style scoped>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@
:active-settings="activeChartSettings"
:generate-annotation="generateAnnotation"
@delete-annotation="deleteAnnotation"
@update-settings-color="onColorChange"
@close="activeChartSettings = null"
/>
</template>
Expand Down Expand Up @@ -757,6 +758,7 @@ const {
comparisonChartsSettingsSelection,
removeChartSettings,
updateChartSettings,
updateChartPrimaryColor,
addComparisonChartSettings
} = useChartSettings(props, emit);

Expand Down Expand Up @@ -1018,6 +1020,10 @@ const getConfiguredModelConfig = async () => {
}
};

const onColorChange = (color: string) => {
if (activeChartSettings.value) updateChartPrimaryColor(activeChartSettings.value, color);
};

onMounted(async () => {
initialize();
});
Expand Down
14 changes: 14 additions & 0 deletions packages/client/hmi-client/src/composables/useChartSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ export function useChartSettings(
});
};

const updateChartPrimaryColor = (settings: ChartSetting, color: string) => {
const index = chartSettings.value.findIndex((chart) => chart.id === settings.id);
if (index !== -1) {
const charts = cloneDeep(chartSettings.value);
charts[index].primaryColor = color;

emit('update-state', {
...props.node.state,
chartSettings: charts
});
}
};

return {
chartSettings,
activeChartSettings,
Expand All @@ -114,6 +127,7 @@ export function useChartSettings(
selectedSensitivityChartSettings,
removeChartSettings,
updateChartSettings,
updateChartPrimaryColor,
updateChartSettingsScale,
addComparisonChartSettings,
updateEnsembleVariableSettingOption
Expand Down
7 changes: 3 additions & 4 deletions packages/client/hmi-client/src/composables/useCharts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ export function useCharts(
showBaseLines = false
) => {
const ensembleVarName = setting.selectedVariables[0];

const options: ForecastChartOptions = {
title: getModelConfigName(<ModelConfiguration[]>modelConfig?.value ?? [], modelConfigId) || ensembleVarName,
legend: true,
Expand All @@ -143,7 +142,7 @@ export function useCharts(
xAxisTitle: '',
yAxisTitle: '',
autosize: AUTOSIZE.FIT,
colorscheme: multiVariable ? CATEGORICAL_SCHEME : [BASE_GREY, PRIMARY_COLOR]
colorscheme: multiVariable ? CATEGORICAL_SCHEME : [BASE_GREY, setting.primaryColor ?? PRIMARY_COLOR]
};

const variables: string[] = [];
Expand Down Expand Up @@ -200,7 +199,7 @@ export function useCharts(
xAxisTitle: getUnit('_time') || 'Time',
yAxisTitle: _.uniq(variables.map(getUnit).filter((v) => !!v)).join(',') || '',
dateOptions,
colorscheme: [BASE_GREY, PRIMARY_COLOR],
colorscheme: [BASE_GREY, setting.primaryColor ?? PRIMARY_COLOR],
scale: setting.scale
};

Expand Down Expand Up @@ -588,7 +587,7 @@ export function useCharts(
maxBins: 10,
variables: [
{ field: beforeFieldName, label: labelBefore, width: 54, color: BASE_GREY },
{ field: fieldName, label: labelAfter, width: 24, color: PRIMARY_COLOR }
{ field: fieldName, label: labelAfter, width: 24, color: setting.primaryColor ?? PRIMARY_COLOR }
]
});
const toDisplayNumber = (num?: number) => (num ? displayNumber(num.toString()) : '');
Expand Down
1 change: 1 addition & 0 deletions packages/client/hmi-client/src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export interface ChartSettingBase {
name: string;
selectedVariables: string[];
type: ChartSettingType;
primaryColor?: string;
scale?: string;
}

Expand Down