Skip to content

Commit c0b85af

Browse files
committed
make font-size config props for consistency
1 parent 723f5a9 commit c0b85af

File tree

4 files changed

+60
-21
lines changed

4 files changed

+60
-21
lines changed

lib/components/SChartBar.vue

+11-5
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,28 @@ const props = withDefaults(defineProps<{
1313
type?: 'horizontal' | 'vertical'
1414
debug?: boolean
1515
ticks?: number
16+
tickFontSize?: string
1617
animate?: boolean
1718
tooltip?: boolean
1819
tooltipFormat?: (d: KV, color: string) => string
1920
xLabel?: string
2021
yLabel?: string
2122
xLabelOffset?: number
2223
yLabelOffset?: number
24+
xLabelFontSize?: string
25+
yLabelFontSize?: string
2326
maxBandwidth?: number
2427
}>(), {
2528
colors: () => ['blue'],
2629
type: 'vertical',
2730
debug: false,
2831
ticks: 5,
32+
tickFontSize: '14px',
2933
animate: true,
3034
tooltip: true,
3135
tooltipFormat: (d: KV) => `${d.key} – ${d.value}`,
36+
xLabelFontSize: '14px',
37+
yLabelFontSize: '14px',
3238
maxBandwidth: 100
3339
})
3440
@@ -110,7 +116,7 @@ function renderChart({
110116
.call(vertical ? d3.axisBottom(paddedScale) : d3.axisBottom(y).ticks(props.ticks))
111117
.selectAll('text')
112118
.attr('fill', c.text2)
113-
.style('font-size', 'var(--chart-tick-font-size)')
119+
.style('font-size', props.tickFontSize)
114120
.style('text-anchor', 'middle')
115121
116122
// Remove X axis line
@@ -124,7 +130,7 @@ function renderChart({
124130
.call(vertical ? d3.axisLeft(y).ticks(props.ticks) : d3.axisLeft(paddedScale))
125131
.selectAll('text')
126132
.attr('fill', c.text2)
127-
.style('font-size', 'var(--chart-tick-font-size)')
133+
.style('font-size', props.tickFontSize)
128134
129135
// Remove Y axis line
130136
svg
@@ -161,7 +167,7 @@ function renderChart({
161167
.attr('x', width / 2)
162168
.attr('y', height + xLabelOffset)
163169
.attr('fill', c.text2)
164-
.style('font-size', 'var(--chart-label-font-size)')
170+
.style('font-size', props.xLabelFontSize)
165171
.style('text-anchor', 'middle')
166172
.html(props.xLabel)
167173
}
@@ -172,7 +178,7 @@ function renderChart({
172178
.attr('y', -yLabelOffset)
173179
.attr('transform', 'rotate(-90)')
174180
.attr('fill', c.text2)
175-
.style('font-size', 'var(--chart-label-font-size)')
181+
.style('font-size', props.yLabelFontSize)
176182
.style('text-anchor', 'middle')
177183
.html(props.yLabel)
178184
}
@@ -359,7 +365,7 @@ watch(
359365
background-color: var(--c-bg-elv-2);
360366
border: 1px solid var(--c-divider);
361367
border-radius: 6px;
362-
font-size: var(--chart-tooltip-font-size);
368+
font-size: 12px;
363369
}
364370
365371
:deep(.tick line) {

lib/components/SChartPie.vue

+8-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ const props = withDefaults(defineProps<{
2222
legendFormatKey?: (d: KV) => string
2323
legendFormatValue?: (d: KV) => string
2424
legendPadding?: number
25+
legendFontSize?: string
2526
labels?: boolean
2627
labelFormat?: (d: KV) => string
28+
labelFontSize?: string
2729
}>(), {
2830
type: 'donut',
2931
half: false,
@@ -35,8 +37,10 @@ const props = withDefaults(defineProps<{
3537
legendFormatKey: (d: KV) => d.key,
3638
legendFormatValue: (d: KV) => d.value.toString(),
3739
legendPadding: 70,
40+
legendFontSize: '14px',
3841
labels: false,
39-
labelFormat: (d: KV) => `${d.key} – ${d.value}`
42+
labelFormat: (d: KV) => `${d.key} – ${d.value}`,
43+
labelFontSize: '14px'
4044
})
4145
4246
const chartRef = useTemplateRef('chart')
@@ -116,7 +120,7 @@ function renderChart({
116120
.enter()
117121
.append('g')
118122
.attr('transform', (d, i) => `translate(0,${i * 24})`)
119-
.style('font-size', 'var(--chart-legend-font-size)')
123+
.style('font-size', props.legendFontSize)
120124
121125
// Add colored rectangles to the legend
122126
legend
@@ -259,7 +263,7 @@ function renderChart({
259263
.attr('dy', '0.35em')
260264
.attr('fill', c.text2)
261265
.attr('text-anchor', (d) => leftOrRight(d) === 1 ? 'start' : 'end')
262-
.style('font-size', 'var(--chart-label-font-size)')
266+
.style('font-size', props.labelFontSize)
263267
.html((d) => props.labelFormat(d.data))
264268
265269
if (animate) {
@@ -357,6 +361,6 @@ watch(
357361
background-color: var(--c-bg-elv-2);
358362
border: 1px solid var(--c-divider);
359363
border-radius: 6px;
360-
font-size: var(--chart-tooltip-font-size);
364+
font-size: 12px;
361365
}
362366
</style>

lib/styles/variables.css

-11
Original file line numberDiff line numberDiff line change
@@ -878,14 +878,3 @@
878878
--input-switch-disabled-toggle-color: var(--c-fg-gray-1);
879879
--input-switch-disabled-bg-color: var(--c-bg-mute-1);
880880
}
881-
882-
/**
883-
* Component: Charts
884-
* -------------------------------------------------------------------------- */
885-
886-
:root {
887-
--chart-tick-font-size: 14px;
888-
--chart-legend-font-size: 14px;
889-
--chart-label-font-size: 14px;
890-
--chart-tooltip-font-size: 12px;
891-
}

stories/components/SChart.01_Playground.story.vue

+41-1
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ function state() {
4646
barMarginBottom: undefined,
4747
barMarginLeft: undefined,
4848
barTicks: undefined,
49+
barTickFontSize: undefined,
4950
barMaxBandwidth: undefined,
5051
barAnimate: true,
5152
barTooltip: true,
5253
barXLabel: undefined,
5354
barYLabel: undefined,
5455
barXLabelOffset: undefined,
5556
barYLabelOffset: undefined,
57+
barXLabelFontSize: undefined,
58+
barYLabelFontSize: undefined,
5659
5760
pieType: 'donut',
5861
pieHalf: false,
@@ -66,7 +69,9 @@ function state() {
6669
pieActiveKey: undefined,
6770
pieLegend: true,
6871
pieLegendPadding: undefined,
69-
pieLabels: false
72+
pieLegendFontSize: undefined,
73+
pieLabels: false,
74+
pieLabelFontSize: undefined
7075
}
7176
}
7277
</script>
@@ -114,6 +119,12 @@ function state() {
114119
:min="0"
115120
:max="20"
116121
/>
122+
<HstSlider
123+
title="tick-font-size"
124+
v-model="state.barTickFontSize"
125+
:min="10"
126+
:max="20"
127+
/>
117128
<HstSlider
118129
title="max-bandwidth"
119130
v-model="state.barMaxBandwidth"
@@ -148,6 +159,18 @@ function state() {
148159
:min="-10"
149160
:max="60"
150161
/>
162+
<HstSlider
163+
title="x-label-font-size"
164+
v-model="state.barXLabelFontSize"
165+
:min="10"
166+
:max="20"
167+
/>
168+
<HstSlider
169+
title="y-label-font-size"
170+
v-model="state.barYLabelFontSize"
171+
:min="10"
172+
:max="20"
173+
/>
151174
<div class="s-p-8 s-font-14 s-font-w-500">Pie Chart</div>
152175
<HstSelect
153176
title="type"
@@ -212,10 +235,22 @@ function state() {
212235
:min="50"
213236
:max="150"
214237
/>
238+
<HstSlider
239+
title="legend-font-size"
240+
v-model="state.pieLegendFontSize"
241+
:min="10"
242+
:max="20"
243+
/>
215244
<HstCheckbox
216245
title="labels"
217246
v-model="state.pieLabels"
218247
/>
248+
<HstSlider
249+
title="label-font-size"
250+
v-model="state.pieLabelFontSize"
251+
:min="10"
252+
:max="20"
253+
/>
219254
</template>
220255
<template #default="{ state }">
221256
<Board :title="title">
@@ -251,13 +286,16 @@ function state() {
251286
:type="state.barType"
252287
:debug="state.barDebug"
253288
:ticks="state.barTicks"
289+
:tick-font-size="state.barTickFontSize"
254290
:animate="state.barAnimate"
255291
:tooltip="state.barTooltip"
256292
:tooltip-format
257293
:x-label="state.barXLabel"
258294
:y-label="state.barYLabel"
259295
:x-label-offset="state.barXLabelOffset"
260296
:y-label-offset="state.barYLabelOffset"
297+
:x-label-font-size="state.barXLabelFontSize"
298+
:y-label-font-size="state.barYLabelFontSize"
261299
:max-bandwidth="state.barMaxBandwidth"
262300
/>
263301
</div>
@@ -302,8 +340,10 @@ function state() {
302340
:active-key="state.pieActiveKey"
303341
:legend="state.pieLegend"
304342
:legend-padding="state.pieLegendPadding"
343+
:legend-font-size="state.pieLegendFontSize"
305344
:labels="state.pieLabels"
306345
:label-format="labelFormat"
346+
:label-font-size="state.pieLabelFontSize"
307347
/>
308348
</div>
309349
</SCardBlock>

0 commit comments

Comments
 (0)