LiveShot Core
Provides low-level renderering support for LiveShot. Implements rendering of
targets and shots.
Should not be used directly in webapps, use LiveShot DOM instead. This core
library is to be extended only when new targets are needed.
General components
Renderer
Super class for various implementations of target and shot renderers.
var renderer = new Renderer();
renderer.setContext(ctx)
.setRect({
x:100,
y:150,
width:400,
height:300
})
.render();
Public properties
Access and modify directly or through setter methods.
- < CanvasRenderingContext2D >
context
, the canvas 2d drawing context to render into - < object >
rect
Describes the rectangle to render within
- < number >
x
- < number >
y
- < number >
width
- < number >
height
Public methods
- render() - ( void )
Renders into context
, within the rectangle defined by x
, y
,
width
and height
, scaled to scale
.
Setters
Return pointer to the renderer for convenience.
- setContext(< CanvasRenderingContext2D >context) - ( Renderer )
- setPosition(< number >x, < number >y) - ( Renderer )
- setSize(< number >width, < number >height) - ( Renderer )
- setRect(< object >rect) - ( Renderer )
rect
should be as described above
Scaler
Calculates a scale (zoom level) given a set of shots.
Public properties
Public methods
- setShots(< object >shots) - ( Scaler )
- getScale() - ( number )
TargetRenderer
This abstract class is mostly convention, and should be used as base for all
implementations of different targets. Inherits all properties and methods of
Renderer.
Public properties
- < object >
style
- < string >
backColor
, the background color of the target (normally
white) - < string >
frontColor
, the front color of the target (normally
black)
- < number >
scale
, the scale (zoom) at which to render
Setters
Return pointer to the renderer for convenience.
- setStyle(< object >style) - ( TargetRenderer )
style
should an object containing some (or all) of the style keywords
described above - setScale(< number >scale) - ( TargetRenderer )
Subclassing notes
Subclasses should override the following methods:
- drawTarget() - ( void )
Draws the target into context
, into a width x height
-sized rectangle with center in
(0, 0)
. Target should be scaled according to scale
, for instance, if
scale = 2
the target should fit exactly into the rectangle with size
2*width x 2*height
.
TriangleRenderer
Handles rendering of upper-right hand triangles, used for non-marking series.
Inherits all properties and methods of Renderer
.
var renderer = new TriangleRenderer();
renderer.setContext(ctx)
.setStyle({
color:'rgb(150, 150, 150)',
borderColor:'rgb(50, 50, 50)',
size:.2
})
.setRect({
x:100,
y:150,
width:400,
height:300
})
.render();
Public properties
- < object >
style
- < string >
color
, the color of the triangle - < string >
borderColor
, the color of the border (facing the target) of
the triangle - < number >
size
, the size of the triangle relative to the width of the
rect
Setters
Return pointer to the renderer for convenience.
- setStyle(< object >style) - ( TriangleRenderer )
style
should an object containing some (or all) of the style keywords
described above
ShotRenderer
Handles rendering of shots. Inherits all properties and methods of Renderer
.
var renderer = new ShotRenderer();
renderer.setContext(ctx)
.setStyle({
gaugeSize:.1,
gaugeColor:'rgb(255, 0, 0)',
markerColor:'rgb(0, 0, 255)',
lastMarkerColor:'rgb(0, 255, 0)'
})
.setScale(2)
.setRect({
x:100,
y:150,
width:400,
height:300
})
.setShots(shots)
.render();
Public properties
- < object >
style
- < number >
gaugeSize
default value is .015
- < string >
gaugeColor
default value is 'rgb(0, 0, 0)'
- < string >
markerColor
default value is 'rgb(0, 255, 0)'
- < string >
lastMarkerColor
default value is 'rgb(255, 0, 0)'
- < object >
shots
, should be object created by ShotListBuilder - < number >
scale
, the scale (zoom) at which to render
default value is 1
Setters
Return pointer to the renderer for convenience.
- setStyle(< object >style) - ( ShotRenderer )
style
should an object containing some (or all) of the style keywords
described above - setShots(< object >shots) - ( ShotRenderer )
- setScale(< number >scale) - ( ShotRenderer )
Components for ring targets
RingTargetRenderer
Super class for various implementations of ring-target renderers. Inherits all
properties and methods of TargetRenderer.
var renderer = new RingTargetRenderer();
renderer.setContext(ctx)
.setStyle({backColor:'rgb(255, 0, 0)', frontColor:'rgb(0, 0, 255)'})
.setScale(2)
.setRect({
x:100,
y:150,
width:400,
height:300
})
.setTarget(target)
.render();
Public properties
- < object >
style
Extended from TargetRenderer
- < boolean >
drawFullTarget
, true
if the entire target should be
drawn, even if it extends outside the drawing rectangle. false
if only
rings that fully fit inside the rectangle should be drawn. - < number >
ringLineWidth
, the rendered line width of the rings
default value is 1
- < object >
target
, should be object created by RingTargetBuilder
Setters
Return pointer to the renderer for convenience.
- setTarget(< object >target) - ( RingTargetRenderer )
target
should be object created by RingTargetBuilder
RingTargetScaler
Super class for various implementations of ring-target scalers. Inherits all
propterties and methods of Scaler
.
var scale = new RingTargetScaler()
.setTarget(target)
.setShots(shots)
.getScale();
Public properties
- < object >
target
, should be object created by RingTargetBuilder
Public methods
- setTarget(< object >target) - ( RingTargetScaler )
target
should be object created by RingTargetBuilder
RingTargetBuilder
Builds RingTarget
objects needed by RingTargetScaler
and
RingTargetRenderer
.
var target = new RingTargetBuilder()
.setRingSizes([1., .9, .8, .7, .6, .5, .4, .3, .2, .1, .05])
.setFrontSize(.4)
.setNumbersFrom(1)
.setNumbersTo(9)
.getTarget();
- (static method) RingTargetBuilder.createBlankTarget() - ( object )
Creates and returns a new empty target, with all fields present, but set to
empty placeholder values. - reset() - ( RingTargetBuilder )
Resets the current target. Returns pointer to the builder for convenience. - getTarget() - ( object )
Returns pointer to the current target - setRingSizes(< array >ringSizes) - ( RingTargetBuilder )
ringSizes
should be a stricly decreasing positive sequence of
numbers. Each number represents the radius of a ring on the target. The
largest should ring always have size 1
. - setFrontSize(< number >frontSize) - ( RingTargetBuilder )
frontSize
is the size of the black disc with repect to the target size.
For instance, a target with radius 300mm
and a black disc with radius
120mm
, frontSize
should be 120mm / 300mm = .4
. - setNumbersFrom(< number >numbersFrom) - ( RingTargetBuilder )
- setNumbersTo(< number >numbersFrom) - ( RingTargetBuilder )
List of implemented targets
All of the following targets are accesible through the targets
object on the
root object of the package. You can either access the directly using their
targetID
as a key:
var target = require('liveshot-core').targets.NO_DFS_300M;
Or by using the convenience method getTarget
:
var target = require('liveshot-core').targets.getTarget('NO_DFS_300M');
When targets are needed to setup scalers and renderers, the convenience methods
getRenderer
and getScaler
should be used. These will create new instances
of Renderer
and Scaler
(or the appropriate subclass of these), and set them
up with the correct target:
var LiveShot = require('liveshot-core');
var targetID = 'NO_DFS_100M';
var renderer = LiveShot.targets.getRenderer(targetID);
var scaler LiveShot.targets.getScaler(targetID);
DFS range targets
All DFS range targets are ring targets and should be rendered with
RingTargetRenderer and scaled with RingTargetScaler.
This list show the targetID key in targets
object, and description.
NO_DFS_300M
: DFS 300m targetNO_DFS_200M
: DFS 200m targetNO_DFS_100M
: DFS 100m targetNO_DFS_15M
: DFS 15m target