Skip to content

Commit 8d1a647

Browse files
committed
docs: extract gauge configuration into a separate function for better maintainability
1 parent 800ed06 commit 8d1a647

File tree

1 file changed

+101
-147
lines changed

1 file changed

+101
-147
lines changed

docs/src/views/PlaygroundView.vue

Lines changed: 101 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -914,85 +914,89 @@ const presets = [
914914
{ key: 'advanced', title: 'Advanced' },
915915
];
916916
917+
function getBaseConfig() {
918+
return {
919+
// Basic Values
920+
value: 67,
921+
min: 0,
922+
max: 100,
923+
decimals: 0,
924+
symbol: '',
925+
reverse: false,
926+
927+
// Dimensions
928+
width: 400,
929+
height: 320,
930+
relativeGaugeSize: false,
931+
gaugeWidthScale: 1.0,
932+
933+
// Colors
934+
gaugeColor: '#edebeb',
935+
valueFontColor: '#010101',
936+
labelFontColor: '#b3b3b3',
937+
levelColors: ['#a9d70b', '#f9c802', '#ff0000'],
938+
noGradient: false,
939+
showSectorColors: false,
940+
customSectors: {
941+
percents: false,
942+
ranges: [
943+
{ lo: 0, hi: 50, color: '#a9d70b' },
944+
{ lo: 50, hi: 80, color: '#f9c802' },
945+
{ lo: 80, hi: 100, color: '#ff0000' },
946+
],
947+
},
948+
949+
// Labels and Text
950+
title: '',
951+
titleFontColor: '#010101',
952+
titleFontFamily: 'Arial',
953+
titleFontWeight: 'bold',
954+
titlePosition: 'above',
955+
label: 'units',
956+
minTxt: '',
957+
maxTxt: '',
958+
hideValue: false,
959+
hideMinMax: false,
960+
humanFriendly: false,
961+
formatNumber: false,
962+
963+
// Gauge Types
964+
donut: false,
965+
donutStartAngle: 90,
966+
differential: false,
967+
displayRemaining: false,
968+
969+
// Pointer
970+
pointer: false,
971+
pointerOptions: {
972+
color: '#8e2de2',
973+
toplength: 14,
974+
bottomlength: 27,
975+
bottomwidth: 4,
976+
},
977+
978+
// Target Line
979+
showTargetLine: false,
980+
targetLine: null as number | null,
981+
targetLineColor: '#000000',
982+
targetLineWidth: 1.5,
983+
984+
// Animation
985+
startAnimationTime: 700,
986+
startAnimationType: '>',
987+
refreshAnimationTime: 700,
988+
counter: false,
989+
990+
// Shadow
991+
showInnerShadow: false,
992+
shadowOpacity: 0.2,
993+
shadowSize: 5,
994+
shadowVerticalOffset: 3,
995+
};
996+
}
997+
917998
// Comprehensive Configuration (all features from visual-diff-tool)
918-
const config = reactive({
919-
// Basic Values
920-
value: 67,
921-
min: 0,
922-
max: 100,
923-
decimals: 0,
924-
symbol: '',
925-
reverse: false,
926-
927-
// Dimensions
928-
width: 400,
929-
height: 320,
930-
relativeGaugeSize: false,
931-
gaugeWidthScale: 1.0,
932-
933-
// Colors
934-
gaugeColor: '#edebeb',
935-
valueFontColor: '#010101',
936-
labelFontColor: '#b3b3b3',
937-
levelColors: ['#a9d70b', '#f9c802', '#ff0000'],
938-
noGradient: false,
939-
showSectorColors: false,
940-
customSectors: {
941-
percents: false,
942-
ranges: [
943-
{ lo: 0, hi: 50, color: '#a9d70b' },
944-
{ lo: 50, hi: 80, color: '#f9c802' },
945-
{ lo: 80, hi: 100, color: '#ff0000' },
946-
],
947-
},
948-
949-
// Labels and Text
950-
title: '',
951-
titleFontColor: '#010101',
952-
titleFontFamily: 'Arial',
953-
titleFontWeight: 'bold',
954-
titlePosition: 'above',
955-
label: 'units',
956-
minTxt: '',
957-
maxTxt: '',
958-
hideValue: false,
959-
hideMinMax: false,
960-
humanFriendly: false,
961-
formatNumber: false,
962-
963-
// Gauge Types
964-
donut: false,
965-
donutStartAngle: 90,
966-
differential: false,
967-
displayRemaining: false,
968-
969-
// Pointer
970-
pointer: false,
971-
pointerOptions: {
972-
color: '#8e2de2',
973-
toplength: 14,
974-
bottomlength: 27,
975-
bottomwidth: 4,
976-
},
977-
978-
// Target Line
979-
showTargetLine: false,
980-
targetLine: null as number | null,
981-
targetLineColor: '#000000',
982-
targetLineWidth: 1.5,
983-
984-
// Animation
985-
startAnimationTime: 700,
986-
startAnimationType: '>',
987-
refreshAnimationTime: 700,
988-
counter: false,
989-
990-
// Shadow
991-
showInnerShadow: false,
992-
shadowOpacity: 0.2,
993-
shadowSize: 5,
994-
shadowVerticalOffset: 3,
995-
});
999+
let config = reactive(getBaseConfig());
9961000
9971001
const animationTypes = [
9981002
{ title: 'Linear', value: 'linear' },
@@ -1032,18 +1036,20 @@ const gauge = new JustGage(config);`;
10321036
const loadPreset = (preset: string) => {
10331037
switch (preset) {
10341038
case 'donut':
1035-
Object.assign(config, {
1039+
config = {
1040+
...getBaseConfig(),
10361041
donut: true,
10371042
donutStartAngle: 90,
10381043
hideMinMax: true,
10391044
value: 75,
10401045
label: 'Progress',
10411046
levelColors: ['#00ff66', '#ffcc00', '#ff3300'],
1042-
});
1047+
};
10431048
break;
10441049
10451050
case 'pointer':
1046-
Object.assign(config, {
1051+
config = {
1052+
...getBaseConfig(),
10471053
pointer: true,
10481054
donut: false,
10491055
value: 60,
@@ -1054,42 +1060,46 @@ const loadPreset = (preset: string) => {
10541060
bottomlength: 30,
10551061
bottomwidth: 6,
10561062
},
1057-
});
1063+
};
10581064
break;
10591065
10601066
case 'differential':
1061-
Object.assign(config, {
1067+
config = {
1068+
...getBaseConfig(),
10621069
differential: true,
10631070
min: -50,
10641071
max: 50,
10651072
value: 25,
10661073
label: 'Differential',
10671074
levelColors: ['#ff0000', '#ffff00', '#00ff00'],
1068-
});
1075+
};
10691076
break;
10701077
10711078
case 'custom-sectors':
1072-
Object.assign(config, {
1079+
config = {
1080+
...getBaseConfig(),
10731081
noGradient: true,
10741082
showSectorColors: true,
10751083
pointer: true,
10761084
value: 80,
10771085
label: 'Custom Sectors',
1078-
});
1086+
};
10791087
break;
10801088
10811089
case 'minimal':
1082-
Object.assign(config, {
1090+
config = {
1091+
...getBaseConfig(),
10831092
hideMinMax: true,
10841093
title: '',
10851094
label: '',
10861095
showInnerShadow: false,
10871096
levelColors: ['#999999'],
1088-
});
1097+
};
10891098
break;
10901099
10911100
case 'advanced':
1092-
Object.assign(config, {
1101+
config = {
1102+
...getBaseConfig(),
10931103
pointer: true,
10941104
showTargetLine: true,
10951105
targetLine: 75,
@@ -1098,67 +1108,11 @@ const loadPreset = (preset: string) => {
10981108
humanFriendly: true,
10991109
title: 'Advanced Gauge',
11001110
label: 'Performance',
1101-
});
1111+
};
11021112
break;
11031113
11041114
default: // 'default'
1105-
Object.assign(config, {
1106-
value: 67,
1107-
min: 0,
1108-
max: 100,
1109-
decimals: 0,
1110-
symbol: '',
1111-
reverse: false,
1112-
width: 400,
1113-
height: 320,
1114-
relativeGaugeSize: false,
1115-
gaugeWidthScale: 1.0,
1116-
gaugeColor: '#edebeb',
1117-
valueFontColor: '#010101',
1118-
labelFontColor: '#b3b3b3',
1119-
levelColors: ['#a9d70b', '#f9c802', '#ff0000'],
1120-
noGradient: false,
1121-
title: '',
1122-
label: 'units',
1123-
minTxt: '',
1124-
maxTxt: '',
1125-
hideValue: false,
1126-
hideMinMax: false,
1127-
humanFriendly: false,
1128-
formatNumber: false,
1129-
donut: false,
1130-
donutStartAngle: 90,
1131-
differential: false,
1132-
displayRemaining: false,
1133-
pointer: false,
1134-
pointerOptions: {
1135-
color: '#8e2de2',
1136-
toplength: 14,
1137-
bottomlength: 27,
1138-
bottomwidth: 4,
1139-
},
1140-
showTargetLine: false,
1141-
targetLine: null,
1142-
targetLineColor: '#000000',
1143-
targetLineWidth: 1.5,
1144-
startAnimationTime: 700,
1145-
startAnimationType: '>',
1146-
refreshAnimationTime: 700,
1147-
counter: false,
1148-
showInnerShadow: false,
1149-
shadowOpacity: 0.2,
1150-
shadowSize: 5,
1151-
shadowVerticalOffset: 3,
1152-
showSectorColors: false,
1153-
customSectors: {
1154-
percents: false,
1155-
ranges: [
1156-
{ lo: 0, hi: 50, color: '#a9d70b' },
1157-
{ lo: 50, hi: 80, color: '#f9c802' },
1158-
{ lo: 80, hi: 100, color: '#ff0000' },
1159-
],
1160-
},
1161-
});
1115+
config = getBaseConfig();
11621116
}
11631117
11641118
// Trigger immediate update

0 commit comments

Comments
 (0)