Canvas 白板
https://github.com/webfactorymk/ng2-canvas-whiteboard/pull/112
CanvasWhiteboardService and CanvasWhiteboardShapeService will now be using providedIn: 'root' instead of being provided in the CanvasWhiteboardModule directly.https://github.com/webfactorymk/ng2-canvas-whiteboard/pull/110
https://github.com/webfactorymk/ng2-canvas-whiteboard/pull/68
Exports all existing canvas shapes, so that they can be easily unregistered from the canvas. (see README for unregistering the shapes).
Also, this version introduces two new Inputs, strokeColorPickerEnabled: boolean and fillColorPickerEnabled: boolean, also deprecates the colorPickerEnabled Input.
For the sake of reverse-compat, the colorPickerEnabled input is still there and it will be used in combination with the two new variables. (ex: colorPickerEnabled || fillColorPickerEnabled).
rxjs-compat library and adds rxjs^6. This means that older versions will not be supported if they upgrade to ng2-canvas-whiteboard^3.0.0.Features:
Install npm module:
npm install ng2-canvas-whiteboard --saveIf you are using system.js you may want to add this into map and package config:
{
"map": {
"ng2-canvas-whiteboard": "node_modules/ng2-canvas-whiteboard"
},
"packages": {
"ng2-canvas-whiteboard": { "main": "index.js", "defaultExtension": "js" }
}
}Add the module to your project
@NgModule({
imports: [
CanvasWhiteboardModule
]
...
)}In your component, you should add the CanvasWhiteboardComponent as a view provider
@Component({
selector: '...',
viewProviders: [CanvasWhiteboardComponent],
templateUrl: '...'
})In the html file, you can insert the Canvas Whiteboard
If there is too much overhead with inputs, you can just specify the [options] input, and specify the options from the typescript code
Example:
Code:
…The canvas drawing is triggered when the user touches the canvas, draws (moves the mouse or finger) and then stops drawing. When the drawing is started, after 100 ms all the signals in between are added to a list and are sent as a batch signal which is emitted by the onBatchUpdate emitter. If received, the user can then manipulate with the sent signals.
batchUpdateTimeoutDuration: number (default: 100)The time in milliseconds that a batch update should be sent after drawing.
imageUrl: string (optional)The path to the image. If not specified, the drawings will be placed on the background color of the canvas. This path can either be a base64 string or an actual path to a resource
aspectRatio: number (optional)If specified, the canvas will be resized according to this ratio
drawButtonClass: stringclearButtonClass: string
undoButtonClass: string
redoButtonClass: string
saveDataButtonClass: string
The classes of the draw, clear, undo and redo buttons. These classes are used in "" tags.
Example:
[drawButtonClass]="'fa fa-pencil fa-2x'"
[clearButtonClass]="'fa fa-eraser fa-2x canvas_whiteboard_button-clear'"drawButtonEnabled: boolean (default: true)clearButtonEnabled: boolean (default: true)
undoButtonEnabled: boolean (default: false)
redoButtonEnabled: boolean (default: false)
saveDataButtonEnabled: boolean (default: false)
Specifies whether or not the button for drawing or clearing the canvas should be shown.
drawButtonText, clearButtonText, undoButtonText, redoButtonText, saveDataButtonTextSpecify the text to add to the buttons, default is no text
[drawButtonText]="'Draw'"
[clearButtonText]="'Clear'"##Use the options: CanvasWhiteboardOptions to send the inputs Changes to this object will be detected by the canvas in the OnChange listener and will be changed accordingly
//Component
canvasOptions: CanvasWhiteboardOptions = {
drawButtonEnabled: true,
drawButtonClass: 'drawButtonClass',
drawButtonText: 'Draw',
clearButtonEnabled: true,
clearButtonClass: 'clearButtonClass',
clearButtonText: 'Clear',
undoButtonText: 'Undo',
undoButtonEnabled: true,
redoButtonText: 'Redo',
redoButtonEnabled: true,
colorPickerEnabled: true,
saveDataButtonEnabled: true,
saveDataButtonText: 'Save',
lineWidth: 4,
scaleFactor: 1
};
//View
NOTE: In order for the changeDetection to pick up the options changes, you must change the options reference whenever you want to change a value. Example:
public changeOptions(): void {
this.canvasOptions = {
...this.canvasOptions,
fillColorPickerEnabled: true,
colorPickerEnabled: false
};
}Each button has its on class (example: Draw button -> .canvas_whiteboard_button-draw)
This button can be customized by overriding its css
.canvas_whiteboard_button-draw:before {
content: "Draw";
}will add the "Draw" text to the button.
If using component-only styles, for this to work the viewEncapsulation must be set to None.
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
encapsulation: ViewEncapsulation.None
})You can also use the ::ng-deep selector if you do not want to change the ViewEncapsulation property on the component.
colorPickerEnabled: boolean (default: false)This allows the adding of a colorPickers that the user can choose to draw with (stroke and fill color), and the original colors will be used when redrawing
fillColorPickerEnabled: boolean (default: false)This shows/hides the fill color picker. Note: if this field has been to false, but the colorPickerEnabled field has been to true, the color picker will be shown, as per reverse-compat needs.
fillColorPickerText: string (default: 'Fill')Specify the text to add to the fill color picker button. Default is 'Fill' for reverse-compat needs.
strokeColorPickerEnabled: boolean (default: false)This shows/hides the stroke color picker. Note: if this field has been to false, but the colorPickerEnabled field has been set to true, the color picker will be shown, as per reverse-compat needs.
strokeColorPickerText: string (default: 'Stroke')Specify the text to add to the stroke color picker button. Default is 'Stroke' for reverse-compat needs.
lineWidth: number (default: 2)This input controls the drawing pencil size
strokeColor: string (default: "rgba(0, 0, 0, 1)")This input control the color of the brush
fillColor: string (default: "rgba(0, 0, 0, 0) -> transparent")This input control the background color of the shapes
shouldDownloadDrawing: boolean (default: true)This input control if the image created when clicking the save button should be downloaded right away.
startingColor: string (default: "#fff")This input control is used to fill the canvas with the specified color at initialization and on resize events.
scaleFactor: number (default: 0)This input controls the generation of the X and Y coordinates with a given scaleOffset. If not provided, the current with and height of the bounding rect and the canvas object will be used so that it works when transforming the canvas with css.
drawingEnabled: boolean (default: false)This input controls if the drawing should be enabled from the start, instead of waiting for the user to click draw
showStrokeColorPicker: boolean (default: false)This input controls if the CanvasWhiteboardColorPickerComponent for the strokeColor should be shown programmatically
showFillColorPicker: boolean (default: false)This input controls if the CanvasWhiteboardColorPickerComponent for the fillColor should be shown programmatically
downloadedFileName: string (no default value)This input controls the name of the file that will be downloaded when an image is saved.
If the downloadCanvasImage method is called with a fileName as a third parameter, then it will have priority over everything
If the fileName is not provided, then this Input will have priority. If this input is not provided as well,
the image will be saved as canvas_drawing_" + new Date().valueOf();
At the end the file extension will be added so that it can be opened by a particular app.
lineJoin: string (default: "round")The lineJoin property sets or returns the type of corner created, when two lines meet.
lineCap: string (default: "round")The lineCap property sets or returns the style of the end caps for a line.
shapeSelectorEnabled: boolean (default: true)This input controls if the CanvasWhiteboardShapeSelectorComponent will be enabled so that the user can pick other shapes via the View
showShapeSelector: boolean (default: false)This input controls if the CanvasWhiteboardShapeSelectorComponent should be shown programmatically
@Output() onClear = new EventEmitter();
@Output() onBatchUpdate = new EventEmitter();
@Output() onImageLoaded = new EventEmitter();
@Output() onUndo = new EventEmitter();
@Output() onRedo = new EventEmitter();
@Output() onSave = new EventEmitter();onClear is emitted when the canvas has been cleared.
onImageLoaded is emitted if the user specified an image and it has successfully been drawn on the canvas.
onUndo is emitted when the canvas has done an UNDO function, emits an UUID (string) for the continuous last drawn shape undone.
onClear is emitted when the canvas has done a REDO function, emits an UUID (string) for the continuous shape redrawn.
onSave is emitted when the canvas has done a SAVE function, emits a Data URL or a Blob (IE).
Every shape in the application extends the abstract class CanvasWhiteboardShape. This class adds predefined methods so that
the creator of the shape can follow them and decide how his shape should be drawn.
Each shape is made of a starting position point of type CanvasWhiteboardPoint, and an options object
which may be different for each shape, and it's of type CanvasWhiteboardShapeOptions.
Each predefined shape must know how to:
暂无开放 Issues,或尚未同步最近议题。