Skip to content

Commit 03ab75b

Browse files
committed
curve-editor: add background
1 parent 0157d95 commit 03ab75b

File tree

10 files changed

+103
-108
lines changed

10 files changed

+103
-108
lines changed

app/build/mojs-curve-editor.js

Lines changed: 55 additions & 63 deletions
Large diffs are not rendered by default.

app/build/mojs-curve-editor.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/css/blocks/curve.postcss.css

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/css/blocks/curve.postcss.css.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"curve":"_curve_1y7gw_5","curve__svg-wrapper":"_curve__svg-wrapper_1y7gw_1","curve__svg":"_curve__svg_1y7gw_1","curve__svg-segment":"_curve__svg-segment_1y7gw_1"}
1+
{"curve":"_curve_19x0u_5","curve__svg-wrapper":"_curve__svg-wrapper_19x0u_1","curve__svg":"_curve__svg_19x0u_1","curve__svg-segment":"_curve__svg-segment_19x0u_1"}

app/js/app.babel.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ require('../css/main');
33

44
import store from './store';
55

6+
// TODO
7+
// - init points with function
8+
// - move bunch of points at once
9+
// - add grid background
10+
611
document.addEventListener('DOMContentLoaded', () => {
712
riot.mount('curve-editor', { store });
813
});

app/js/reducers/points-reducer.babel.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ const pointsReducer = (state = INITIAL_STATE, action) => {
3636
}
3737

3838
case 'POINT_TRANSLATE_END': {
39-
const {data} = action,
40-
{index} = data,
39+
const index = action.data,
4140
oldPoint = state[index],
4241
newState = [ ...state ];
4342

44-
newState[ data.index ] = {
43+
newState[ index ] = {
4544
...oldPoint,
46-
tempX: 0, tempY: 0,
47-
x: data.x, y: data.y
45+
x: oldPoint.x + oldPoint.tempX,
46+
y: oldPoint.y + oldPoint.tempY,
47+
tempX: 0, tempY: 0
4848
}
4949

5050
return newState;
@@ -126,7 +126,6 @@ const pointsReducer = (state = INITIAL_STATE, action) => {
126126
// if item was selected - set the new `type`
127127
( selected.indexOf(i) !== -1 ) && (newState[i].type = type);
128128

129-
130129
const index = i;
131130
const point = newState[index];
132131
const sibPoint = (index === newState.length-1)

app/js/tags/curve-editor.tag

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ require('./icon-divider');
77
require('./resize-handle');
88
require('./point-controls');
99

10-
<!--
11-
TODO:
12-
- move bunch of points at once
13-
-->
14-
1510
<curve-editor class={this.CLASSES['curve-editor']} style={this.getStyle()}>
1611
<code-panel />
1712
<icons />
@@ -38,7 +33,10 @@ require('./point-controls');
3833
import C from '../constants';
3934

4035
const {store} = opts;
41-
store.subscribe(this.update.bind(this));
36+
store.subscribe( () => {
37+
this.resize = store.getState().resize;
38+
this.update();
39+
});
4240

4341
import Hammer from 'hammerjs';
4442
import propagating from 'propagating-hammerjs';

app/js/tags/curve.tag

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ require('./point');
66

77
<point
88
each={ point, _index in points }
9-
points-count={parent.points.length} />
9+
points-count={parent.points.length}
10+
resize = {parent.state.resize} />
1011

1112
<svg height="350"
1213
viewBox="0 0 100 100"

app/js/tags/little-handle.tag

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import Hammer from 'hammerjs';
4444
import propagating from 'propagating-hammerjs';
4545
this.on('mount', () => {
46+
// const mc = propagating(new Hammer.Manager(this.root));
47+
// mc.add(new Hammer.Pan({ threshold: 0, pointers: 0 }));
4648
var hammertime = propagating(new Hammer(this.root))
4749
.on('pan', (e) => {
4850
const point = angleToPoint( this.angle, this.radius ),

app/js/tags/point.tag

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ require('./little-handle');
2424
// dont set the handle2 for end point
2525
(this._index !== this.opts.pointsCount-1) && this.handles.push(this.point.handle2);
2626
}
27-
27+
28+
this.resize = this.opts.resize;
2829
this.getHandles();
29-
store.subscribe(() => { this.getHandles(); this.update(); });
30+
store.subscribe(() => {
31+
this.resize = this.opts.resize;
32+
this.getHandles(); this.update();
33+
});
3034

3135
this.getClass = () => {
3236
const isSelected = (this.point.isSelected)
@@ -38,10 +42,8 @@ require('./little-handle');
3842
}
3943

4044
this.getStyle = () => {
41-
// console.log(this.point.tempX, this.point.handle1, this.point.handle2);
42-
const {resize} = store.getState(),
43-
x = clamp(this.point.x + this.point.tempX, 0, 100),
44-
cleanX = x * resize.scalerX;
45+
const x = clamp(this.point.x + this.point.tempX, 0, 100),
46+
cleanX = x * this.resize.scalerX;
4547

4648
let y = this.point.y + this.point.tempY;
4749

@@ -55,44 +57,44 @@ require('./little-handle');
5557
import roundTo from '../helpers/round-to';
5658

5759
const getTempX = (e) => {
58-
const {resize} = store.getState();
5960

6061
// if point is not locked to x axes ->
6162
// calculate delta regarding scaler
6263
if ( this.point.isLockedX ) { return 0 };
6364

64-
const x = e.deltaX/resize.scalerX;
65+
const x = e.deltaX/this.resize.scalerX;
6566
if ( this.point.x + x < 0 ) { return 0 - this.point.x; }
6667
else if ( this.point.x + x > 100 ) { return 100 - this.point.x; }
6768
return roundTo( x, 5, 1.5 );
6869
}
6970

7071
const getY = (e) => {
71-
const {resize} = store.getState();
7272
const y = this.point.y + e.deltaY
7373
// clamp y to the size of curve
74-
return clamp( y, resize.top, C.CURVE_SIZE + resize.bottom );
74+
return clamp( y, this.resize.top, C.CURVE_SIZE + this.resize.bottom );
7575
}
7676

7777
// get y delta reagarding curve bounds
7878
const getTempY = (e) => {
79-
let {resize} = store.getState(),
80-
y = this.point.y + e.deltaY;
79+
let y = this.point.y + e.deltaY;
8180

8281
let returnValue = y;
83-
if ( y < resize.top ) {
84-
returnValue = (resize.top - this.point.y);
85-
} else if ( y > C.CURVE_SIZE + resize.bottom ) { returnValue = C.CURVE_SIZE + resize.bottom - this.point.y
82+
if ( y < this.resize.top ) {
83+
returnValue = (this.resize.top - this.point.y);
84+
} else if ( y > C.CURVE_SIZE + this.resize.bottom ) {
85+
returnValue = C.CURVE_SIZE + this.resize.bottom - this.point.y;
8686
} else {
8787
returnValue = e.deltaY;
8888
}
8989

90-
return roundTo( returnValue, 10*C.CURVE_PERCENT, 2*C.CURVE_PERCENT );
91-
90+
return roundTo( returnValue, 5*C.CURVE_PERCENT, 1*C.CURVE_PERCENT );
9291
}
9392

9493
this.on('mount', () => {
95-
var hammertime = propagating(new Hammer(this.root))
94+
const mc = propagating(new Hammer.Manager(this.root));
95+
mc.add(new Hammer.Pan({ threshold: 5, pointers: 0 }));
96+
// var hammertime = propagating(new Hammer(this.root, { threshold: 0, pointers: 0 }))
97+
mc
9698
.on('pan', (e) => {
9799
store.dispatch({
98100
type: 'POINT_TRANSLATE',
@@ -101,16 +103,10 @@ require('./little-handle');
101103
e.stopPropagation();
102104
})
103105
.on('panend', (e) => {
104-
// reset temporary deltas
105-
store.dispatch({ type: 'POINT_TRANSLATE', data: { x: 0, y: 0, index: this._index } });
106106
// fire translate end and save it to the store
107107
store.dispatch({
108108
type: 'POINT_TRANSLATE_END',
109-
data: {
110-
x: this.point.x + getTempX(e),
111-
y: getY(e),
112-
index: this._index
113-
},
109+
data: this._index,
114110
isRecord: true
115111
});
116112

0 commit comments

Comments
 (0)