Skip to content

Commit

Permalink
fix: use normal font weight during PDF export to prevent serif font s…
Browse files Browse the repository at this point in the history
…tyle
  • Loading branch information
HendrikThePendric committed Oct 10, 2024
1 parent d3a3133 commit 21de660
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
8 changes: 8 additions & 0 deletions src/__demo__/SingleValue.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,14 @@ storiesOf('SingleValue', module).add('default', () => {
if (newChartRef.current) {
const currentBackgroundColor =
newChartRef.current.userOptions.chart.backgroundColor

newChartRef.current.update({
exporting: {
chartOptions: {
isPDF: exportAsPdf,
},
},
})
newChartRef.current.exportChartLocal(
{
sourceHeight: 768,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DynamicStyles } from './styles.js'
export function renderSingleValueSVG() {
const { formattedValue, icon, subText, fontColor } =
this.userOptions.customSVGOptions
const dynamicStyles = new DynamicStyles()
const dynamicStyles = new DynamicStyles(this.userOptions?.isPDF)
const valueElement = this.renderer
.text(formattedValue)
.css({ color: fontColor, visibility: 'hidden' })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
const baseStyle = {
value: {
'font-weight': 300,
},
subText: {},
}

const valueStyles = [
{ 'font-size': '200px', 'letter-spacing': '-6px' },
{ 'font-size': '182px', 'letter-spacing': '-5.5px' },
Expand Down Expand Up @@ -50,16 +43,17 @@ const spacings = [
export const MIN_SIDE_WHITESPACE = 4

export class DynamicStyles {
constructor() {
constructor(isExportingToPDF) {
this.currentIndex = 0
this.isExportingToPDF = isExportingToPDF
}
getStyle() {
return {
value: { ...baseStyle.value, ...valueStyles[this.currentIndex] },
subText: {
...baseStyle.subText,
...subTextStyles[this.currentIndex],
value: {
...valueStyles[this.currentIndex],
'font-weight': this.isExportingToPDF ? 'normal' : '300',
},
subText: subTextStyles[this.currentIndex],
spacing: spacings[this.currentIndex],
}
}
Expand Down

0 comments on commit 21de660

Please sign in to comment.