Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
snip
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
irp
snip
Commits
82f938d8
Commit
82f938d8
authored
1 week ago
by
Sebastian Mohr
Browse files
Options
Downloads
Patches
Plain Diff
Added a drawScale function
parent
c7446a2d
No related branches found
Branches containing commit
Tags
2.0.0
Tags containing commit
No related merge requests found
Pipeline
#591220
skipped
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/snips/src/uprp/stampy.ts
+108
-4
108 additions, 4 deletions
packages/snips/src/uprp/stampy.ts
with
108 additions
and
4 deletions
packages/snips/src/uprp/stampy.ts
+
108
−
4
View file @
82f938d8
...
@@ -190,16 +190,120 @@ export class StampySnip extends BaseSnip {
...
@@ -190,16 +190,120 @@ export class StampySnip extends BaseSnip {
return
this
.
stampy
.
measurement
.
volume
;
return
this
.
stampy
.
measurement
.
volume
;
}
}
// TODO:
Implement this method
// TODO:
Make this dynamic
get
width
():
number
{
get
width
():
number
{
return
0
;
return
70
0
;
}
}
get
height
():
number
{
get
height
():
number
{
return
0
;
return
700
;
}
private
computeScale
():
number
{
// compute scale from given data to fit into
// the width and height of the canvas
// TODO: Implement this
return
150
;
}
}
public
render
(
ctx
:
RenderContext
):
void
{
public
render
(
ctx
:
RenderContext
):
void
{
throw
new
Error
(
"
Render method not implemented.
"
);
// Draw rect around the area
ctx
.
rect
(
0
,
0
,
this
.
width
,
this
.
height
);
ctx
.
stroke
();
// Render sample circle
const
s
=
this
.
computeScale
();
this
.
drawCircle
(
ctx
,
this
.
width
/
2
,
this
.
height
/
2
,
(
this
.
volume
.
diameter
/
2
)
*
s
,
{
stroke
:
"
black
"
,
fill
:
"
red
"
,
fill_alpha
:
0.5
,
},
);
// Render scale
this
.
drawScale
(
ctx
,
s
);
}
private
drawCircle
(
ctx
:
RenderContext
,
x
:
number
,
y
:
number
,
radius
:
number
,
style
:
{
stroke
:
string
;
fill
?:
string
;
fill_alpha
?:
number
;
stroke_alpha
?:
number
;
},
)
{
if
(
style
.
fill_alpha
===
undefined
)
{
style
.
fill_alpha
=
1
;
}
if
(
style
.
stroke_alpha
===
undefined
)
{
style
.
stroke_alpha
=
1
;
}
// Draw fill if fill color is defined
if
(
style
.
fill
)
{
ctx
.
save
();
ctx
.
beginPath
();
ctx
.
globalAlpha
=
style
.
fill_alpha
;
ctx
.
fillStyle
=
style
.
fill
;
ctx
.
arc
(
x
,
y
,
radius
,
0
,
2
*
Math
.
PI
);
ctx
.
fill
();
ctx
.
restore
();
}
// Draw stroke
ctx
.
save
();
ctx
.
globalAlpha
=
style
.
stroke_alpha
;
ctx
.
strokeStyle
=
style
.
stroke
;
ctx
.
beginPath
();
ctx
.
arc
(
x
,
y
,
radius
,
0
,
2
*
Math
.
PI
);
ctx
.
closePath
();
ctx
.
stroke
();
ctx
.
restore
();
}
/** Draws a 1mm scale
* @param ctx - The rendering context.
* @param scale - The scale factor to use (i.e. how many pixels is 1mm).
*
* If the scale is too small, the scale will be multiplied until it is
* at least 150px.
*/
private
drawScale
(
ctx
:
RenderContext
,
scale
:
number
)
{
let
mm
=
1
;
let
s
=
scale
;
while
(
s
<
150
)
{
mm
*=
2
;
s
*=
2
;
}
// pos
const
padding
=
10
;
const
rectHeight
=
5
;
const
x
=
this
.
width
-
s
-
padding
;
const
y
=
this
.
height
-
rectHeight
-
padding
-
18
;
//18=font size
// Render scale rect
ctx
.
globalAlpha
=
0.8
;
ctx
.
fillStyle
=
"
#000
"
;
ctx
.
beginPath
();
ctx
.
fillRect
(
x
,
y
,
s
,
rectHeight
);
ctx
.
stroke
();
// Render text
ctx
.
globalAlpha
=
1
;
ctx
.
fillStyle
=
"
#000
"
;
ctx
.
font
=
"
18px Arial
"
;
ctx
.
textBaseline
=
"
top
"
;
const
ts
=
ctx
.
measureText
(
`
${
mm
}
mm`
);
ctx
.
fillText
(
`
${
mm
}
mm`
,
x
+
s
/
2
-
ts
.
width
/
2
,
y
+
rectHeight
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment