You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/layerchart/src/lib/utils/canvas.ts
+30-21Lines changed: 30 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -22,10 +22,10 @@ export type ComputedStylesOptions = {
22
22
23
23
constsupportedStyles=[
24
24
'fill',
25
-
'stroke',
26
-
'opacity',
27
25
'fillOpacity',
26
+
'stroke',
28
27
'strokeWidth',
28
+
'opacity',
29
29
'fontWeight',
30
30
'fontSize',
31
31
'fontFamily',
@@ -109,7 +109,12 @@ function render(
109
109
stroke: (ctx: CanvasRenderingContext2D)=>void;
110
110
fill: (ctx: CanvasRenderingContext2D)=>void;
111
111
},
112
-
styleOptions: ComputedStylesOptions={}
112
+
styleOptions: ComputedStylesOptions={},
113
+
{
114
+
applyText,
115
+
}: {
116
+
applyText?: boolean;
117
+
}={}
113
118
){
114
119
// console.count('render');
115
120
@@ -155,26 +160,29 @@ function render(
155
160
ctx.globalAlpha=Number(resolvedStyles?.opacity);
156
161
}
157
162
158
-
// Text properties
159
-
ctx.font=`${resolvedStyles.fontWeight}${resolvedStyles.fontSize}${resolvedStyles.fontFamily}`;// build string instead of using `computedStyles.font` to fix/workaround `tabular-nums` returning `null`
163
+
// font/text properties can be expensive to set (not sure why), so only apply if needed (renderText())
164
+
if(applyText){
165
+
// Text properties
166
+
ctx.font=`${resolvedStyles.fontWeight}${resolvedStyles.fontSize}${resolvedStyles.fontFamily}`;// build string instead of using `computedStyles.font` to fix/workaround `tabular-nums` returning `null`
167
+
168
+
// TODO: Hack to handle `textAnchor` with canvas. Try to find a better approach
169
+
if(resolvedStyles.textAnchor==='middle'){
170
+
ctx.textAlign='center';
171
+
}elseif(resolvedStyles.textAnchor==='end'){
172
+
ctx.textAlign='right';
173
+
}else{
174
+
ctx.textAlign=resolvedStyles.textAlignasCanvasTextAlign;// TODO: Handle/map `justify` and `match-parent`?
175
+
}
160
176
161
-
// TODO: Hack to handle `textAnchor` with canvas. Try to find a better approach
162
-
if(resolvedStyles.textAnchor==='middle'){
163
-
ctx.textAlign='center';
164
-
}elseif(resolvedStyles.textAnchor==='end'){
165
-
ctx.textAlign='right';
166
-
}else{
167
-
ctx.textAlign=resolvedStyles.textAlignasCanvasTextAlign;// TODO: Handle/map `justify` and `match-parent`?
0 commit comments