Skip to content

Commit

Permalink
Merge pull request #63 from concord-consortium/183527061-canvas-only
Browse files Browse the repository at this point in the history
Add canvas-only rendering when client provides empty button list, support canvas scaling
  • Loading branch information
pjanik authored Oct 14, 2022
2 parents 85ba717 + 378ad4d commit 8935c1d
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 648 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# HTML5 Drawing Tool

Demo: http://concord-consortium.github.io/drawing-tool/examples/
Demo: https://models-resources.concord.org/drawing-tool/branch/master/examples/index.html

## Using as a library

Expand All @@ -27,13 +27,6 @@ const drawingTool = new DrawingTool("#drawing-tool-container");
* Code!!
* Before you commit, run `webpack` to update `dist` directory and add it to git index.

### Deploying to Github Pages

Use `push-gh-pages.sh` script. It (re)generates `dist` dir using `webpack`, updates `gh-pages` branch
and pushes changes to Github.

Note that you may deploy uncommitted changes, as this script uses current working directory state.

### Undo / redo feature

If you are planning to add new feature that will be exposed in UI or via main API, you should consider whether
Expand Down
21 changes: 20 additions & 1 deletion app/scripts/drawing-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ function DrawingTool(selector, options, settings) {
this._initTools();
this._initStateHistory();

new UIManager(this);
if (!this.canvasOnly()) {
new UIManager(this);
}

this.historyPaused = this.options.startWithHistoryPaused;

Expand Down Expand Up @@ -261,6 +263,13 @@ DrawingTool.prototype.load = function (jsonOrObject, callback, noHistoryUpdate)
}
};

DrawingTool.prototype.canvasOnly = function () {
const buttons = this.options.buttons;
// Buttons are explicitly disabled. This means that Drawing Tool can be only used for presenting an existing drawing.
// It'll be rendered in the most basic basic way - no space for buttons panel and no styling (like canvas border).
return buttons !== undefined && (buttons === null || buttons.length === 0);
}

DrawingTool.prototype.pauseHistory = function () {
this.historyPaused = true;
}
Expand Down Expand Up @@ -745,8 +754,18 @@ DrawingTool.prototype._initDOM = function () {
var $canvasContainer = $('<div class="dt-canvas-container">')
.attr('tabindex', 0) // makes the canvas focusable for keyboard events
.appendTo(this.$element);
if (!this.canvasOnly()) {
$canvasContainer.addClass("with-border");
}
if (this.options.canvasScale) {
$canvasContainer.css({
"transform-origin": "top left",
"transform": `scale(${this.options.canvasScale})`,
})
}
this.$canvas = $('<canvas>')
.appendTo($canvasContainer);

};

DrawingTool.prototype._initFabricJS = function () {
Expand Down
10 changes: 6 additions & 4 deletions app/styles/drawing-tool.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ $text: Arial, sans-serif;
.dt-canvas-container {
vertical-align: top; // not needed but why not
display: inline-block;
border: $border;
border-radius: 0 $borderRadius $borderRadius 0;
outline: 0;

canvas {
&.with-border {
border: $border;
border-radius: 0 $borderRadius $borderRadius 0;
canvas {
border-radius: 0 $borderRadius $borderRadius 0;
}
}
}

Expand Down Expand Up @@ -334,4 +336,4 @@ $text: Arial, sans-serif;
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
}
2 changes: 1 addition & 1 deletion dist/drawing-tool.css

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

2 changes: 1 addition & 1 deletion dist/drawing-tool.js

Large diffs are not rendered by default.

Loading

0 comments on commit 8935c1d

Please sign in to comment.