Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Allow changing stroke width
Browse files Browse the repository at this point in the history
  • Loading branch information
cheshire137 committed Mar 15, 2015
1 parent f90ae2a commit 4245af1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
34 changes: 28 additions & 6 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ var LineItem = React.createClass({
$('.popover').remove();
});
},
lineStyle: function() {
getScaledStrokeWidth: function(x) {
if (x === 0) {
return x;
}
var maxDisplayWidth = 7;
var maxAllowedWidth = 20;
return Math.ceil((maxDisplayWidth * x) / maxAllowedWidth);
},
getLineStyle: function() {
var line = this.props.line;
return {
borderColor: line.stroke,
backgroundColor: line.fill,
borderWidth: line.strokeWidth
borderWidth: this.getScaledStrokeWidth(line.strokeWidth)
};
},
getLineTitle: function() {
Expand All @@ -35,10 +43,10 @@ var LineItem = React.createClass({
return (
<li className="line-item">
<a data-toggle="popover" data-trigger="click" title={this.getLineTitle()}>
<span className="line-representation" style={this.lineStyle()}></span>
<span className="line-representation" style={this.getLineStyle()}></span>
</a>
<div className="line-settings">
Color: {this.props.line.fill}<br />
Fill: {this.props.line.fill}<br />
Border color: {this.props.line.stroke}<br />
Border width: {this.props.line.strokeWidth}<br />
</div>
Expand Down Expand Up @@ -76,7 +84,7 @@ var LinesList = React.createClass({
{
visibleLines.map(function(line) {
return (
<LineItem line={line} />
<LineItem key={line.id} line={line} />
);
})
}
Expand Down Expand Up @@ -181,7 +189,7 @@ var SvgScribblerApp = React.createClass({
points: [],
stroke: lastLine.stroke,
fill: lastLine.fill,
strokeWidth: 3,
strokeWidth: lastLine.strokeWidth,
id: this.state.lines.length + 1
};
this.setState({lines: this.state.lines.concat(newLine)});
Expand Down Expand Up @@ -293,6 +301,12 @@ var SvgScribblerApp = React.createClass({
clearFill: function() {
this.setLineColor('fill', 'transparent');
},
setStrokeWidth: function(e) {
var slider = $(e.target);
var line = this.getCurrentLine();
line.strokeWidth = slider.val();
this.updateCurrentLine(line);
},
render: function() {
var self = this;
return (
Expand Down Expand Up @@ -343,6 +357,14 @@ var SvgScribblerApp = React.createClass({
<i className="fa fa-remove"></i>
</button>
</div>
<div className="form-group">
<label htmlFor="stroke-width-slider">Border width:</label>
<span className="range-input-wrapper">
<span className="help-inline">0</span>
<input onInput={this.setStrokeWidth} type="range" id="stroke-width-slider" min="0" value={this.getCurrentLine().strokeWidth} step="1" max="20" />
<span className="help-inline">20</span>
</span>
</div>
</div>
</div>
<div className="svg-container clearfix">
Expand Down
11 changes: 11 additions & 0 deletions app/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ a {
margin-left: 3px;
}

.range-input-wrapper {
white-space: nowrap;

input[type="range"] {
display: inline-block;
margin: 0 5px;
width: 5em;
vertical-align: middle;
}
}

.lines-list {
.line-item {
.line-settings {
Expand Down

0 comments on commit 4245af1

Please sign in to comment.