Skip to content

Commit

Permalink
Add lineWidth option
Browse files Browse the repository at this point in the history
  • Loading branch information
remcoder committed Oct 19, 2019
1 parent d02bf7b commit 4bf32b7
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 46 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## next
- fully typed
- added `lineWidth` option

## 1.0.0
- ported to typescript
- added distributable library build in dist folder
- some minor fixes
9 changes: 7 additions & 2 deletions src/demo/demo.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@


let gcodePreview;

const slider = document.getElementById('layers');
const scaleSlider = document.getElementById('scale');
const rotationSlider = document.getElementById('rotation');
const toggleAnimation = document.getElementById('toggle-animation');
const toggleZoneColors = document.getElementById('zone-colors');
const lineWidth = document.getElementById('line-width');

function initDemo() {
const preview = new GCodePreview.Preview({
targetId : 'renderer',
scale: 7,
lineWidth: 0.6
});

info(preview.canvas);
Expand All @@ -31,6 +31,11 @@ function initDemo() {
preview.render();
})

lineWidth.addEventListener('input', function(evt) {
preview.lineWidth = +lineWidth.value;
preview.render();
})

window.addEventListener('resize', function() {
preview.resize();
preview.render();
Expand Down
1 change: 1 addition & 0 deletions src/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ <h1>GCode Previewer</h1>
<label>Render layers:&nbsp;<input type="range" min="0" value="0" id="layers" /></label>
<label>Scale:&nbsp;<input type="range" min="1" value="3" max="10" step="0.1" id="scale" /></label>
<label>Rotate:&nbsp;<input type="range" min="0" value="0" max="360" id="rotation" /></label>
<label>Line width:&nbsp;<input type="range" min="0.1" value="0" max="2" step="0.1" id="line-width" /></label>
<button id="toggle-animation">toggle animation</button>
<label>Color zones:&nbsp;<input type="checkbox" id="zone-colors" value="test" /></label>
<br>
Expand Down
13 changes: 6 additions & 7 deletions src/dist/gcode-parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ export declare class MoveCommand extends GCodeCommand {
params: MoveCommandParams;
constructor(gcode: string, params: MoveCommandParams, comment?: string);
}
declare type MoveCommandParamName = "x" | "y" | "z" | "e";
declare type MoveCommandParams = {
x?: number;
y?: number;
z?: number;
e?: number;
[key in MoveCommandParamName]?: number;
};
export interface Layer {
export declare class Layer {
layer: number;
commands: GCodeCommand[];
constructor(layer: number, commands: GCodeCommand[]);
}
export declare class Parser {
parseCommand(line: string, keepComments?: boolean): GCodeCommand | null;
parseMove(params: string[]): MoveCommandParams;
groupIntoLayers(commands: GCodeCommand[], header: any): Layer[];
parseGcode(input: any): {
groupIntoLayers(commands: GCodeCommand[]): Layer[];
parseGcode(input: string): {
header: {
slicer: string;
};
Expand Down
32 changes: 21 additions & 11 deletions src/dist/gcode-preview.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import Colors from "./gcode-colors";
import { Parser, Layer } from "./gcode-parser";
export { Colors };
export declare class Preview {
declare type PreviewOptions = Partial<{
limit: number;
scale: number;
lineWidth: number;
rotation: number;
rotationAnimation: boolean;
zoneColors: boolean;
canvas: HTMLCanvasElement | string;
targetId: string;
}>;
export declare class Preview implements PreviewOptions {
limit: number;
rotation: number;
rotationAnimation: Boolean;
lineWidth: number;
rotationAnimation: boolean;
scale: number;
zoneColors: Boolean;
zoneColors: boolean;
canvas: HTMLCanvasElement;
ctx: CanvasRenderingContext2D;
targetId: string;
Expand All @@ -23,14 +34,13 @@ export declare class Preview {
x: number;
y: number;
};
constructor(opts: any);
constructor(opts: PreviewOptions);
clear(): void;
resize(): void;
getZoneColor(zone: any, layerIndex: any): any;
renderWithColor(l: Layer, layerIndex: number, color?: any): void;
drawLayer(index: any, limit: any): void;
renderWithColor(l: Layer, layerIndex: number, color?: string): void;
drawLayer(index: number, limit: number): void;
render(): void;
processGCode(gcode: any): void;
processGCode(gcode: string): void;
animationLoop(): void;
startAnimation(): void;
stopAnimation(): void;
Expand All @@ -40,7 +50,7 @@ export declare class Preview {
minY: number;
maxY: number;
};
getCenter(layer: any): {
getCenter(layer: Layer): {
x: number;
y: number;
};
Expand All @@ -52,8 +62,8 @@ export declare class Preview {
sizeX: number;
sizeY: number;
};
drawBounds(layer: any, color: any): void;
autoscale(): any;
drawBounds(layer: Layer, color: string): void;
autoscale(): number;
projectIso(point: {
x: number;
y: number;
Expand Down
2 changes: 1 addition & 1 deletion src/dist/gcode-preview.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4bf32b7

Please sign in to comment.