@pie-lib/plot 3.2.0-next.9 → 4.0.0

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/src/label.jsx CHANGED
@@ -1,4 +1,5 @@
1
1
  import React, { useState } from 'react';
2
+ import { styled } from '@mui/material/styles';
2
3
  import { Readable } from '@pie-lib/render-ui';
3
4
  import EditableHtml from '@pie-lib/editable-html-tip-tap';
4
5
  import PropTypes from 'prop-types';
@@ -44,8 +45,28 @@ const styles = {
44
45
  displayNone: {
45
46
  display: 'none',
46
47
  },
48
+ centerPlaceholder: {
49
+ '& .ProseMirror p.is-editor-empty::before, & .ProseMirror div.is-editor-empty::before': {
50
+ left: 0,
51
+ right: 0,
52
+ width: '100%',
53
+ textAlign: 'center',
54
+ },
55
+ },
47
56
  };
48
57
 
58
+
59
+ const LabelWrapper = styled('div')({
60
+ ...styles.centerPlaceholder,
61
+ });
62
+
63
+ const LabelContent = styled('div')({
64
+ ...styles.disabledLabel,
65
+ '& p': {
66
+ margin: 0,
67
+ },
68
+ });
69
+
49
70
  const LabelComponent = (props) => {
50
71
  const {
51
72
  disabledLabel,
@@ -62,6 +83,7 @@ const LabelComponent = (props) => {
62
83
  mathMlOptions = {},
63
84
  charactersLimit,
64
85
  titleHeight,
86
+ preventNewLines,
65
87
  } = props;
66
88
 
67
89
  const [rotatedToHorizontal, setRotatedToHorizontal] = useState(false);
@@ -109,9 +131,18 @@ const LabelComponent = (props) => {
109
131
  });
110
132
  };
111
133
 
134
+ const onKeyDown = (event) => {
135
+ if (preventNewLines && event.key === 'Enter') {
136
+ // prevent adding new lines - cancelling event
137
+ return true;
138
+ }
139
+
140
+ return false;
141
+ };
142
+
112
143
  return (
113
144
  <Readable false>
114
- <div
145
+ <LabelWrapper
115
146
  onClick={rotateLabel}
116
147
  style={{
117
148
  ...(rotatedToHorizontal ? rotatedStyle : defaultStyle),
@@ -124,7 +155,7 @@ const LabelComponent = (props) => {
124
155
  }}
125
156
  >
126
157
  {disabledLabel ? (
127
- <div style={styles.disabledLabel} dangerouslySetInnerHTML={{ __html: text || '' }} />
158
+ <LabelContent dangerouslySetInnerHTML={{ __html: text || '' }} />
128
159
  ) : (
129
160
  <EditableHtml
130
161
  markup={text || ''}
@@ -138,11 +169,12 @@ const LabelComponent = (props) => {
138
169
  disableScrollbar
139
170
  activePlugins={activePlugins}
140
171
  onDone={exitEditMode}
172
+ onKeyDown={onKeyDown}
141
173
  mathMlOptions={mathMlOptions}
142
174
  charactersLimit={charactersLimit}
143
175
  />
144
176
  )}
145
- </div>
177
+ </LabelWrapper>
146
178
  </Readable>
147
179
  );
148
180
  };
package/src/root.jsx CHANGED
@@ -9,6 +9,15 @@ import { ChildrenType, GraphPropsType } from './types';
9
9
  import Label from './label';
10
10
  import { extractTextFromHTML, isEmptyObject, isEmptyString } from './utils';
11
11
 
12
+ const centerPlaceholder = {
13
+ '& .ProseMirror p.is-editor-empty::before, & .ProseMirror div.is-editor-empty::before': {
14
+ left: 0,
15
+ right: 0,
16
+ width: '100%',
17
+ textAlign: 'center',
18
+ },
19
+ };
20
+
12
21
  const StyledRoot = styled('div')(({ theme }) => ({
13
22
  border: `solid 1px ${color.primaryLight()}`,
14
23
  color: color.defaults.TEXT,
@@ -26,10 +35,12 @@ const Wrapper = styled('div')({
26
35
  const DefineChartSvg = styled('svg')({
27
36
  paddingLeft: '50px',
28
37
  overflow: 'visible',
38
+ boxSizing: 'content-box',
29
39
  });
30
40
 
31
41
  const ChartSvg = styled('svg')({
32
42
  overflow: 'visible',
43
+ boxSizing: 'content-box',
33
44
  });
34
45
 
35
46
  const GraphBox = styled('g')({
@@ -48,6 +59,10 @@ const GraphTitle = styled('div')(({ theme }) => ({
48
59
  '&.rightMargin': {
49
60
  marginRight: '74px',
50
61
  },
62
+ '& p': {
63
+ margin: 0,
64
+ },
65
+ ...centerPlaceholder,
51
66
  }));
52
67
 
53
68
  const ChartTitle = styled('div')(({ theme }) => ({
@@ -61,6 +76,10 @@ const ChartTitle = styled('div')(({ theme }) => ({
61
76
  '&.rightMargin': {
62
77
  marginRight: '74px',
63
78
  },
79
+ '& p': {
80
+ margin: 0,
81
+ },
82
+ ...centerPlaceholder,
64
83
  }));
65
84
 
66
85
  const TopPixelGuides = styled('div')({
@@ -362,6 +381,7 @@ export class Root extends React.Component {
362
381
  graphWidth={finalWidth}
363
382
  onChange={(value) => this.onChangeLabel(value, 'top')}
364
383
  mathMlOptions={mathMlOptions}
384
+ preventNewLines={true}
365
385
  charactersLimit={labelsCharactersLimit}
366
386
  />
367
387
  )}
@@ -378,6 +398,7 @@ export class Root extends React.Component {
378
398
  isDefineChartLeftLabel={isChart && defineChart}
379
399
  onChange={(value) => this.onChangeLabel(value, 'left')}
380
400
  mathMlOptions={mathMlOptions}
401
+ preventNewLines={true}
381
402
  charactersLimit={labelsCharactersLimit}
382
403
  />
383
404
  )}
@@ -420,6 +441,7 @@ export class Root extends React.Component {
420
441
  graphWidth={finalWidth}
421
442
  onChange={(value) => this.onChangeLabel(value, 'right')}
422
443
  mathMlOptions={mathMlOptions}
444
+ preventNewLines={true}
423
445
  charactersLimit={labelsCharactersLimit}
424
446
  />
425
447
  )}
@@ -451,6 +473,7 @@ export class Root extends React.Component {
451
473
  isDefineChartBottomLabel={isChart && defineChart}
452
474
  onChange={(value) => this.onChangeLabel(value, 'bottom')}
453
475
  mathMlOptions={mathMlOptions}
476
+ preventNewLines={true}
454
477
  charactersLimit={labelsCharactersLimit}
455
478
  />
456
479
  )}