Skip to content

Commit

Permalink
[Fix-14171] Add dynamic font sizes to dashboards (#14260)
Browse files Browse the repository at this point in the history
* feat: Add dynamic font sizes to dashboards

* feat: code review

* feat: change initChart params

* feat: code review

* feat: code review

* feat: build fix
  • Loading branch information
pppppjcc authored Jun 15, 2023
1 parent c1a6790 commit f840b17
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
7 changes: 6 additions & 1 deletion dolphinscheduler-ui/src/components/chart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import type { ECBasicOption } from 'echarts/types/dist/shared'

function initChart<Opt extends ECBasicOption>(
domRef: Ref<HTMLDivElement | null>,
option: Opt
option: Opt,
resizeFun?: any
): ECharts | null {
let chart: ECharts | null = null
const themeStore = useThemeStore()
Expand All @@ -44,6 +45,10 @@ function initChart<Opt extends ECBasicOption>(
}

const resize = throttle(() => {
if (resizeFun) {
resizeFun(chart)
return
}
chart && chart.resize()
}, 20)

Expand Down
48 changes: 44 additions & 4 deletions dolphinscheduler-ui/src/components/chart/modules/Gauge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
* limitations under the License.
*/

import { defineComponent, PropType, ref } from 'vue'
import {
defineComponent,
onMounted,
onBeforeUnmount,
PropType,
ref
} from 'vue'
import initChart from '@/components/chart'
import type { Ref } from 'vue'

Expand All @@ -38,6 +44,9 @@ const GaugeChart = defineComponent({
props,
setup(props) {
const gaugeChartRef: Ref<HTMLDivElement | null> = ref(null)
const windowWidth = window.innerWidth
// The original size was based on the screen width of 2560
const defaultFontSize = windowWidth > 2560 ? 20 : (windowWidth / 2560) * 20

const option = {
series: [
Expand Down Expand Up @@ -72,12 +81,13 @@ const GaugeChart = defineComponent({
axisLabel: {
color: 'auto',
distance: 40,
fontSize: 20
fontSize: defaultFontSize
},
detail: {
valueAnimation: true,
formatter: '{value} %',
color: 'auto'
color: 'auto',
fontSize: defaultFontSize * 1.5
},
data: [
{
Expand All @@ -88,7 +98,37 @@ const GaugeChart = defineComponent({
]
}

initChart(gaugeChartRef, option)
const resize = (chart: any) => {
const clientWidth = gaugeChartRef.value?.clientWidth || 400
const axisLabelFontSize =
clientWidth > 400
? defaultFontSize
: (clientWidth / 400) * defaultFontSize
chart &&
chart.setOption({
series: [
{
axisLabel: {
fontSize: axisLabelFontSize
},
detail: {
fontSize: axisLabelFontSize * 1.5
}
}
]
})
chart && chart.resize()
}

initChart(gaugeChartRef, option, resize)

onMounted(() => {
addEventListener('resize', resize)
})

onBeforeUnmount(() => {
removeEventListener('resize', resize)
})

return { gaugeChartRef }
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

@mixin base {
font-size: 100px;
font-size: 5vw;
display: flex;
justify-content: center;
align-items: center;
Expand Down

0 comments on commit f840b17

Please sign in to comment.