1
1
import { h , Component } from 'preact' ;
2
2
import angleToPoint from '../helpers/angle-to-point' ;
3
3
import ProgressLine from './progress-line' ;
4
+ import Pattern from './pattern' ;
4
5
import Ruler from './ruler' ;
5
6
import Point from './point' ;
6
7
import mod from '../helpers/resize-mod' ;
@@ -19,58 +20,13 @@ class Curve extends Component {
19
20
segments = this . _renderSegments ( state ) ,
20
21
progressLines = this . _renderProgressLines ( state ) ;
21
22
23
+ const curveHeight = this . _getCurveHeight ( state ) ;
22
24
return < div className = { CLASSES [ 'curve' ] } >
23
25
< div id = "js-background"
24
- className = { CLASSES [ 'curve__background' ] }
25
- style = { styles . background } >
26
- < svg preserveAspectRatio = "none" height = { `${ styles . height } px` } viewBox = { `0 0 ${ 350 + Math . random ( ) * 0.0001 } ${ styles . height } ` } >
27
- < pattern id = "rect-paper" x = "0" y = { `${ - styles . svgTop } ` } height = "350" width = "350" patternUnits = "userSpaceOnUse" >
28
- < g id = "Group" transform = "translate(-1.000000, 0.000000)" stroke = "#FFFFFF" stroke-width = "1" fill = "none" >
29
- < path vector-effect = "non-scaling-stroke" d = "M333.497821,350.501088 L333.497821,0.501088302" opacity = "0.25" > </ path >
30
- < path vector-effect = "non-scaling-stroke" d = "M315.997821,350.501088 L315.997821,0.501088302" opacity = "0.25" > </ path >
31
- < path vector-effect = "non-scaling-stroke" d = "M298.497821,350.501088 L298.497821,0.501088302" opacity = "0.25" > </ path >
32
- < path vector-effect = "non-scaling-stroke" d = "M280.997821,350.501088 L280.997821,0.501088302" opacity = "0.25" > </ path >
33
- < path vector-effect = "non-scaling-stroke" d = "M245.997821,350.501088 L245.997821,0.501088302" opacity = "0.25" > </ path >
34
- < path vector-effect = "non-scaling-stroke" d = "M228.497821,350.501088 L228.497821,0.501088302" opacity = "0.25" > </ path >
35
- < path vector-effect = "non-scaling-stroke" d = "M210.997821,350.501088 L210.997821,0.501088302" opacity = "0.25" > </ path >
36
- < path vector-effect = "non-scaling-stroke" d = "M193.497821,350.501088 L193.497821,0.501088302" opacity = "0.25" > </ path >
37
- < path vector-effect = "non-scaling-stroke" d = "M159.372821,350.501088 L159.372821,0.501088302" opacity = "0.25" > </ path >
38
- < path vector-effect = "non-scaling-stroke" d = "M141.872821,350.501088 L141.872821,0.501088302" opacity = "0.25" > </ path >
39
- < path vector-effect = "non-scaling-stroke" d = "M124.372821,350.501088 L124.372821,0.501088302" opacity = "0.25" > </ path >
40
- < path vector-effect = "non-scaling-stroke" d = "M106.872821,350.501088 L106.872821,0.501088302" opacity = "0.25" > </ path >
41
- < path vector-effect = "non-scaling-stroke" d = "M71.8728207,350.501088 L71.8728207,0.501088302" opacity = "0.25" > </ path >
42
- < path vector-effect = "non-scaling-stroke" d = "M54.3728207,350.501088 L54.3728207,0.501088302" opacity = "0.25" > </ path >
43
- < path vector-effect = "non-scaling-stroke" d = "M36.8728207,350.501088 L36.8728207,0.501088302" opacity = "0.25" > </ path >
44
- < path vector-effect = "non-scaling-stroke" d = "M19.3728207,350.501088 L19.3728207,0.501088302" opacity = "0.25" > </ path >
45
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,19.0021793 L1.0010883,19.0021793" opacity = "0.25" > </ path >
46
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,36.5021793 L1.0010883,36.5021793" opacity = "0.25" > </ path >
47
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,54.0021793 L1.0010883,54.0021793" opacity = "0.25" > </ path >
48
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,71.5021793 L1.0010883,71.5021793" opacity = "0.25" > </ path >
49
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,106.502179 L1.0010883,106.502179" opacity = "0.25" > </ path >
50
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,124.002179 L1.0010883,124.002179" opacity = "0.25" > </ path >
51
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,141.502179 L1.0010883,141.502179" opacity = "0.25" > </ path >
52
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,159.002179 L1.0010883,159.002179" opacity = "0.25" > </ path >
53
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,193.127179 L1.0010883,193.127179" opacity = "0.25" > </ path >
54
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,210.627179 L1.0010883,210.627179" opacity = "0.25" > </ path >
55
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,228.127179 L1.0010883,228.127179" opacity = "0.25" > </ path >
56
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,245.627179 L1.0010883,245.627179" opacity = "0.25" > </ path >
57
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,280.627179 L1.0010883,280.627179" opacity = "0.25" > </ path >
58
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,298.127179 L1.0010883,298.127179" opacity = "0.25" > </ path >
59
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,315.627179 L1.0010883,315.627179" opacity = "0.25" > </ path >
60
- < path vector-effect = "non-scaling-stroke" d = "M351.001088,333.127179 L1.0010883,333.127179" opacity = "0.25" > </ path >
61
- < path vector-effect = "non-scaling-stroke" d = "M88.0641352,1 L88.0641352,351" id = "path8215" opacity = "0.5" > </ path >
62
- < path vector-effect = "non-scaling-stroke" d = "M175.12827,1 L175.12827,351" id = "path8215" opacity = "0.5" > </ path >
63
- < path vector-effect = "non-scaling-stroke" d = "M262.192406,1 L262.192406,351" id = "path8215" opacity = "0.5" > </ path >
64
- < path vector-effect = "non-scaling-stroke" d = "M350.563591,88.0646793 L0.563591022,88.0646793" id = "path8215" opacity = "0.5" > </ path >
65
- < path vector-effect = "non-scaling-stroke" d = "M350.563591,175.564679 L0.563591022,175.564679" id = "path8215" opacity = "0.5" > </ path >
66
- < path vector-effect = "non-scaling-stroke" d = "M350.563591,263.064679 L0.563591022,263.064679" id = "path8215" opacity = "0.5" > </ path >
67
- < rect id = "rect10078" opacity = "0.75" x = "0.872817955" y = "1" width = "350" height = "350" > </ rect >
68
- </ g >
69
- </ pattern >
70
-
71
- < rect width = "350" height = { styles . height } fill = "url(#rect-paper)" />
72
- </ svg >
73
-
26
+ className = { CLASSES [ 'curve__background' ] } >
27
+
28
+ < Pattern styles = { styles } />
29
+
74
30
</ div >
75
31
76
32
{ progressLines }
@@ -84,7 +40,7 @@ class Curve extends Component {
84
40
{ points }
85
41
86
42
< svg height = { C . CURVE_SIZE }
87
- viewBox = " 0 0 100 100"
43
+ viewBox = { ` 0 0 100 ${ curveHeight } ` }
88
44
preserveAspectRatio = "none"
89
45
id = "js-svg"
90
46
class = { CLASSES [ 'curve__svg' ] } >
@@ -104,26 +60,36 @@ class Curve extends Component {
104
60
</ div > ;
105
61
}
106
62
63
+ _getCurveHeight ( state ) {
64
+ const { resize} = state ;
65
+ if ( ! state . controls . isMinimize ) { return 100 ; }
66
+
67
+ return C . CURVE_SIZE * 8 ;
68
+ }
69
+
107
70
_getStyle ( state ) {
108
71
const { resize} = state ;
109
72
let { temp_top, temp_bottom, temp_right, panTempY} = resize ;
110
73
let height = C . CURVE_SIZE - ( temp_top + resize . top )
111
74
+ ( temp_bottom + resize . bottom ) ;
112
75
113
76
panTempY += resize . panY ;
114
-
115
77
temp_top += resize . top - panTempY ;
116
78
temp_right += resize . right ;
117
79
80
+ const yShift = ( state . controls . isMinimize )
81
+ ? - ( temp_top / C . CURVE_SIZE ) * ( 20 / ( height / C . CURVE_SIZE ) )
82
+ : - temp_top ;
83
+
118
84
const scaleX = ( C . CURVE_SIZE + Math . max ( temp_right , 0 ) ) / C . CURVE_SIZE ;
119
85
const scale = `width: ${ C . CURVE_SIZE * scaleX } px` ,
120
86
bgTransform = `${ scale } ;` ,
121
- background = `background-position: 0 ${ - temp_top - 1 } px; ${ bgTransform } ` ,
122
- transform = `transform: translate(0px, ${ - temp_top } px)` ;
87
+ // background = `background-position: 0 ${-temp_top - 1}px; ${bgTransform}`,
88
+ transform = `transform: translate(0px, ${ yShift } px)` ;
123
89
124
90
return {
125
91
transform : `${ mojs . h . prefix . css } ${ transform } ; ${ transform } ;` ,
126
- background,
92
+ // background,
127
93
height,
128
94
svgTop : temp_top
129
95
} ;
0 commit comments