Skip to content

Commit

Permalink
Make charts flow theme color #120
Browse files Browse the repository at this point in the history
  • Loading branch information
doroudi committed Dec 18, 2024
1 parent 1d9d712 commit 07fbe99
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ watch(() => layout.isDark, (newValue) => {
}, { immediate: true })
watch(() => layout.themeColor, (newValue) => {
if (customTheme.value.common && newValue !== '')
if (customTheme.value.common && newValue !== '') {
customTheme.value.common.primaryColor = newValue
customTheme.value.common.actionColor = newValue
document.documentElement.style.setProperty('--primary-color', newValue)
}
}, { immediate: true })
</script>

Expand Down
6 changes: 6 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ declare module 'vue' {
NBreadcrumb: typeof import('naive-ui')['NBreadcrumb']
NBreadcrumbItem: typeof import('naive-ui')['NBreadcrumbItem']
NButton: typeof import('naive-ui')['NButton']
NColorPicker: typeof import('naive-ui')['NColorPicker']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDataTable: typeof import('naive-ui')['NDataTable']
NDialogProvider: typeof import('naive-ui')['NDialogProvider']
NDrawer: typeof import('naive-ui')['NDrawer']
NDrawerContent: typeof import('naive-ui')['NDrawerContent']
NDropdown: typeof import('naive-ui')['NDropdown']
NForm: typeof import('naive-ui')['NForm']
NFormItem: typeof import('naive-ui')['NFormItem']
NGlobalStyle: typeof import('naive-ui')['NGlobalStyle']
NIcon: typeof import('naive-ui')['NIcon']
NInput: typeof import('naive-ui')['NInput']
Expand All @@ -50,6 +53,7 @@ declare module 'vue' {
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
NModal: typeof import('naive-ui')['NModal']
NNotificationProvider: typeof import('naive-ui')['NNotificationProvider']
Notifications: typeof import('./components/Navbar/Notifications.vue')['default']
NPageHeader: typeof import('naive-ui')['NPageHeader']
Expand All @@ -58,6 +62,8 @@ declare module 'vue' {
NSwitch: typeof import('naive-ui')['NSwitch']
NTag: typeof import('naive-ui')['NTag']
NTooltip: typeof import('naive-ui')['NTooltip']
NTreeSelect: typeof import('naive-ui')['NTreeSelect']
NUpload: typeof import('naive-ui')['NUpload']
OrderManagement: typeof import('./components/Orders/OrderManagement.vue')['default']
PersianIcon: typeof import('./components/CountryIcons/PersianIcon.vue')['default']
ProductsManagement: typeof import('./components/Products/ProductsManagement.vue')['default']
Expand Down
21 changes: 19 additions & 2 deletions src/components/BarChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const chartOptions = ref({
dataLabels: {
enabled: false,
},
colors: buildThemeSeries(),
colors: ['var(--primary-color)', ...buildThemeSeries()],
plotOptions: {
bar: {
columnWidth: '17%',
Expand Down Expand Up @@ -73,7 +73,24 @@ const series = ref([
])
function buildThemeSeries() {
return ['#3db9af', '#37938d', '#276e6b', '#7fcdca']
return createThemeColors(useLayoutStore().themeColor, 4)
}
function createThemeColors(color, count) {
const result = []
for (let i = 0; i < count; i++)
result.push(makeLighter(color))
return result
}
function makeLighter(color) {
const colorHex = color.replace('#', '')
const colorR = Number.parseInt(colorHex.substring(0, 2), 16)
const colorG = Number.parseInt(colorHex.substring(2, 4), 16)
const colorB = Number.parseInt(colorHex.substring(4, 6), 16)
const lighterColor = `rgba(${colorR}, ${colorG}, ${colorB}, .4)`
return lighterColor
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/components/CustomizeDialog/CustomizeDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function setDark() {
}
const colors = [
'#00ad4c', '#ef4848', '#FC0', '#FF8000', '#22d3ee',
'#00ad4c', '#cb2025', '#f8b334', '#FF8000', '#00a096',
]
const selectedColorIndex = ref(0)
function setColor(index) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/LineChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ const barChartOptions = ref({
stroke: {
width: 3,
},
colors: ['#377d71', '#fc0'],
colors: ['var(--primary-color)'],
markers: {
size: 3,
colors: ['#377d71', '#fc0'],
strokeColors: ['#377d71', '#fc0'],
colors: ['var(--primary-color)'],
strokeColors: ['var(--primary-color)'],
strokeWidth: 3,
strokeOpacity: 1,
strokeDashArray: 0,
Expand Down
3 changes: 2 additions & 1 deletion src/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

:root {
--sidebar-width: 20rem;
--primary-color: #00ad4c;
}

html,
Expand Down Expand Up @@ -47,7 +48,7 @@ body {
}

#nprogress .bar {
background: rgb(13,148,136);
background: var(--primary-color);
opacity: 0.75;
position: fixed;
z-index: 1031;
Expand Down

0 comments on commit 07fbe99

Please sign in to comment.