@pie-lib/plot 2.1.10-next.351 → 2.1.10-next.548
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/lib/draggable.js +17 -26
- package/lib/draggable.js.map +1 -1
- package/lib/graph-props.js +2 -2
- package/lib/graph-props.js.map +1 -1
- package/lib/grid-draggable.js +42 -71
- package/lib/grid-draggable.js.map +1 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/root.js +124 -65
- package/lib/root.js.map +1 -1
- package/lib/trig.js +2 -2
- package/lib/trig.js.map +1 -1
- package/lib/types.js +2 -2
- package/lib/types.js.map +1 -1
- package/lib/utils.js +2 -2
- package/lib/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/root.jsx +136 -39
package/src/root.jsx
CHANGED
|
@@ -1,35 +1,25 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ChildrenType } from './types';
|
|
3
3
|
import { withStyles } from '@material-ui/core/styles';
|
|
4
|
-
import Typography from '@material-ui/core/Typography';
|
|
5
4
|
import { select, mouse } from 'd3-selection';
|
|
6
5
|
import PropTypes from 'prop-types';
|
|
7
6
|
import { GraphPropsType } from './types';
|
|
8
|
-
import { color } from '@pie-lib/render-ui';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
title: {
|
|
12
|
-
color: color.text(),
|
|
13
|
-
textAlign: 'center',
|
|
14
|
-
paddingTop: theme.spacing.unit * 2,
|
|
15
|
-
fontSize: theme.typography.fontSize + 6
|
|
16
|
-
}
|
|
17
|
-
}))(({ value, classes }) => (
|
|
18
|
-
<Typography
|
|
19
|
-
className={classes.title}
|
|
20
|
-
color="primary"
|
|
21
|
-
variant="h5"
|
|
22
|
-
dangerouslySetInnerHTML={{ __html: value }}
|
|
23
|
-
/>
|
|
24
|
-
));
|
|
7
|
+
import { color, Readable } from '@pie-lib/render-ui';
|
|
8
|
+
import EditableHtml from '@pie-lib/editable-html';
|
|
9
|
+
import cn from 'classnames';
|
|
25
10
|
|
|
26
11
|
export class Root extends React.Component {
|
|
27
12
|
static propTypes = {
|
|
28
13
|
title: PropTypes.string,
|
|
29
14
|
children: ChildrenType,
|
|
15
|
+
disabledTitle: PropTypes.bool,
|
|
30
16
|
graphProps: GraphPropsType.isRequired,
|
|
17
|
+
onChangeTitle: PropTypes.func,
|
|
31
18
|
onMouseMove: PropTypes.func,
|
|
32
19
|
classes: PropTypes.object.isRequired,
|
|
20
|
+
showLabels: PropTypes.bool,
|
|
21
|
+
showTitle: PropTypes.bool,
|
|
22
|
+
showPixelGuides: PropTypes.bool,
|
|
33
23
|
rootRef: PropTypes.func
|
|
34
24
|
};
|
|
35
25
|
|
|
@@ -64,48 +54,155 @@ export class Root extends React.Component {
|
|
|
64
54
|
}
|
|
65
55
|
|
|
66
56
|
render() {
|
|
67
|
-
const {
|
|
57
|
+
const {
|
|
58
|
+
disabledTitle,
|
|
59
|
+
graphProps,
|
|
60
|
+
children,
|
|
61
|
+
classes,
|
|
62
|
+
onChangeTitle,
|
|
63
|
+
showLabels,
|
|
64
|
+
showPixelGuides,
|
|
65
|
+
showTitle,
|
|
66
|
+
title,
|
|
67
|
+
rootRef
|
|
68
|
+
} = this.props;
|
|
68
69
|
const {
|
|
69
70
|
size: { width = 500, height = 500 },
|
|
70
71
|
domain,
|
|
71
72
|
range
|
|
72
73
|
} = graphProps;
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
const
|
|
74
|
+
|
|
75
|
+
const padding = showLabels ? 70 : 40;
|
|
76
|
+
const extraPadding = showLabels ? 16 : 40;
|
|
77
|
+
const finalWidth = width + padding * 2 + (domain.padding || 0) * 2 + extraPadding;
|
|
78
|
+
const finalHeight = height + padding * 2 + (range.padding || 0) * 2;
|
|
79
|
+
|
|
80
|
+
const activeTitlePlugins = [
|
|
81
|
+
'bold',
|
|
82
|
+
'italic',
|
|
83
|
+
'underline',
|
|
84
|
+
'strikethrough',
|
|
85
|
+
'math'
|
|
86
|
+
// 'languageCharacters'
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
const nbOfVerticalLines = parseInt(width / 100);
|
|
90
|
+
const nbOfHorizontalLines = parseInt(height / 100);
|
|
91
|
+
const sideGridlinesPadding = parseInt(height % 100);
|
|
77
92
|
|
|
78
93
|
return (
|
|
79
94
|
<div className={classes.root}>
|
|
80
|
-
{
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
{showPixelGuides && (
|
|
96
|
+
<div className={classes.topPixelGuides}>
|
|
97
|
+
{[...Array(nbOfVerticalLines + 1).keys()].map(value => (
|
|
98
|
+
<Readable false key={`top-guide-${value}`}>
|
|
99
|
+
<div className={classes.topPixelIndicator}>
|
|
100
|
+
<div>{value * 100}px</div>
|
|
101
|
+
<div>|</div>
|
|
102
|
+
</div>
|
|
103
|
+
</Readable>
|
|
104
|
+
))}
|
|
105
|
+
</div>
|
|
106
|
+
)}
|
|
107
|
+
{showTitle && (
|
|
108
|
+
<EditableHtml
|
|
109
|
+
className={cn(
|
|
110
|
+
{
|
|
111
|
+
[classes.disabledTitle]: disabledTitle
|
|
112
|
+
},
|
|
113
|
+
classes.graphTitle
|
|
114
|
+
)}
|
|
115
|
+
markup={title || ''}
|
|
116
|
+
width={finalWidth}
|
|
117
|
+
onChange={onChangeTitle}
|
|
118
|
+
placeholder={!disabledTitle && 'Click here to add a title for this graph'}
|
|
119
|
+
toolbarOpts={{ noBorder: true }}
|
|
120
|
+
activePlugins={activeTitlePlugins}
|
|
121
|
+
/>
|
|
122
|
+
)}
|
|
123
|
+
<div className={classes.wrapper}>
|
|
124
|
+
<svg width={finalWidth} height={finalHeight} className={classes.svg}>
|
|
125
|
+
<g
|
|
126
|
+
ref={r => {
|
|
127
|
+
this.g = r;
|
|
128
|
+
if (rootRef) {
|
|
129
|
+
rootRef(r);
|
|
130
|
+
}
|
|
131
|
+
}}
|
|
132
|
+
className={classes.graphBox}
|
|
133
|
+
transform={`translate(${padding}, ${padding})`}
|
|
134
|
+
>
|
|
135
|
+
{children}
|
|
136
|
+
</g>
|
|
137
|
+
</svg>
|
|
138
|
+
{showPixelGuides && (
|
|
139
|
+
<div className={classes.sidePixelGuides} style={{ paddingTop: sideGridlinesPadding }}>
|
|
140
|
+
{[...Array(nbOfHorizontalLines + 1).keys()].reverse().map(value => (
|
|
141
|
+
<Readable false key={`top-guide-${value}`}>
|
|
142
|
+
<div className={classes.sidePixelIndicator}>━ {value * 100}px</div>
|
|
143
|
+
</Readable>
|
|
144
|
+
))}
|
|
145
|
+
</div>
|
|
146
|
+
)}
|
|
147
|
+
</div>
|
|
95
148
|
</div>
|
|
96
149
|
);
|
|
97
150
|
}
|
|
98
151
|
}
|
|
99
|
-
const styles =
|
|
152
|
+
const styles = theme => ({
|
|
100
153
|
root: {
|
|
101
154
|
border: `solid 1px ${color.primaryLight()}`,
|
|
102
155
|
color: color.text(),
|
|
103
156
|
backgroundColor: color.background()
|
|
104
157
|
},
|
|
158
|
+
wrapper: {
|
|
159
|
+
display: 'flex'
|
|
160
|
+
},
|
|
105
161
|
svg: {},
|
|
106
162
|
graphBox: {
|
|
107
163
|
cursor: 'pointer',
|
|
108
164
|
userSelect: 'none'
|
|
165
|
+
},
|
|
166
|
+
graphTitle: {
|
|
167
|
+
color: color.text(),
|
|
168
|
+
fontSize: theme.typography.fontSize + 2,
|
|
169
|
+
padding: '12px 4px 0',
|
|
170
|
+
textAlign: 'center'
|
|
171
|
+
},
|
|
172
|
+
disabledTitle: {
|
|
173
|
+
pointerEvents: 'none'
|
|
174
|
+
},
|
|
175
|
+
topPixelGuides: {
|
|
176
|
+
display: 'flex',
|
|
177
|
+
paddingTop: '6px',
|
|
178
|
+
marginLeft: '10px'
|
|
179
|
+
},
|
|
180
|
+
topPixelIndicator: {
|
|
181
|
+
color: color.primaryLight(),
|
|
182
|
+
display: 'flex',
|
|
183
|
+
flexDirection: 'column',
|
|
184
|
+
alignItems: 'center',
|
|
185
|
+
width: '100px',
|
|
186
|
+
pointerEvents: 'none',
|
|
187
|
+
userSelect: 'none'
|
|
188
|
+
},
|
|
189
|
+
sidePixelGuides: {
|
|
190
|
+
width: '70px',
|
|
191
|
+
display: 'flex',
|
|
192
|
+
flexDirection: 'column',
|
|
193
|
+
marginTop: '40px',
|
|
194
|
+
marginRight: '6px'
|
|
195
|
+
},
|
|
196
|
+
sidePixelIndicator: {
|
|
197
|
+
color: color.primaryLight(),
|
|
198
|
+
textAlign: 'right',
|
|
199
|
+
height: '20px',
|
|
200
|
+
pointerEvents: 'none',
|
|
201
|
+
userSelect: 'none',
|
|
202
|
+
|
|
203
|
+
'&:not(:last-child)': {
|
|
204
|
+
marginBottom: '80px'
|
|
205
|
+
}
|
|
109
206
|
}
|
|
110
207
|
});
|
|
111
208
|
|