@pie-lib/charting 4.5.11-next.266 → 4.5.11-next.408

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/axes.jsx CHANGED
@@ -6,6 +6,7 @@ import { color } from '@pie-lib/render-ui';
6
6
  import { AxisLeft, AxisBottom } from '@vx/axis';
7
7
  import { bandKey, getTickValues, getRotateAngle } from './utils';
8
8
  import MarkLabel from './mark-label';
9
+ import Checkbox from '@material-ui/core/Checkbox';
9
10
 
10
11
  export class TickComponent extends React.Component {
11
12
  changeCategory = (index, newLabel) => {
@@ -23,6 +24,20 @@ export class TickComponent extends React.Component {
23
24
  }
24
25
  };
25
26
 
27
+ changeInteractive = (index, value) => {
28
+ const { categories, onChangeCategory } = this.props;
29
+ const category = categories[index];
30
+
31
+ onChangeCategory(index, { ...category, interactive: !category.interactive });
32
+ };
33
+
34
+ changeEditable = (index, value) => {
35
+ const { categories, onChangeCategory } = this.props;
36
+ const category = categories[index];
37
+
38
+ onChangeCategory(index, { ...category, editable: !category.editable || false });
39
+ };
40
+
26
41
  render() {
27
42
  const {
28
43
  classes,
@@ -33,6 +48,7 @@ export class TickComponent extends React.Component {
33
48
  rotate,
34
49
  top,
35
50
  graphProps,
51
+ defineChart,
36
52
  x,
37
53
  y,
38
54
  formattedValue
@@ -61,7 +77,7 @@ export class TickComponent extends React.Component {
61
77
  x={bandWidth ? barX : x - barWidth / 2}
62
78
  y={6}
63
79
  width={barWidth}
64
- height={24}
80
+ height={4}
65
81
  style={{ pointerEvents: 'none', overflow: 'visible' }}
66
82
  >
67
83
  {index === 0 && (
@@ -81,7 +97,7 @@ export class TickComponent extends React.Component {
81
97
  )}
82
98
  <MarkLabel
83
99
  inputRef={r => (this.input = r)}
84
- disabled={!(editable && interactive)}
100
+ disabled={!editable}
85
101
  mark={category}
86
102
  graphProps={graphProps}
87
103
  onChange={newLabel => this.changeCategory(index, newLabel)}
@@ -113,6 +129,84 @@ export class TickComponent extends React.Component {
113
129
  <path d="M128 405.429C128 428.846 147.198 448 170.667 448h170.667C364.802 448 384 428.846 384 405.429V160H128v245.429zM416 96h-80l-26.785-32H202.786L176 96H96v32h320V96z" />
114
130
  </svg>
115
131
  )}
132
+ {defineChart && index === 0 && (
133
+ <text
134
+ x={x - 80}
135
+ y={y + 40 + top}
136
+ width={barWidth}
137
+ height={4}
138
+ style={{
139
+ position: 'absolute',
140
+ pointerEvents: 'none',
141
+ wordBreak: 'break-word',
142
+ overflow: 'visible',
143
+ maxWidth: barWidth,
144
+ display: 'inline-block'
145
+ }}
146
+ >
147
+ <tspan x="0" dy=".6em">
148
+ {' '}
149
+ Student can{' '}
150
+ </tspan>
151
+ <tspan x="0" dy="1.2em">
152
+ {' '}
153
+ set value
154
+ </tspan>
155
+ </text>
156
+ )}
157
+ {defineChart && index === 0 && (
158
+ <text
159
+ x={x - 80}
160
+ y={y + 80 + top}
161
+ width={barWidth}
162
+ height={4}
163
+ style={{
164
+ position: 'absolute',
165
+ pointerEvents: 'none',
166
+ wordBreak: 'break-word',
167
+ overflow: 'visible',
168
+ maxWidth: barWidth,
169
+ display: 'inline-block'
170
+ }}
171
+ >
172
+ <tspan x="0" dy=".6em">
173
+ {' '}
174
+ Student can{' '}
175
+ </tspan>
176
+ <tspan x="0" dy="1.2em">
177
+ {' '}
178
+ edit name
179
+ </tspan>
180
+ </text>
181
+ )}
182
+ {defineChart && (
183
+ <foreignObject
184
+ x={x - 24}
185
+ y={y + 20 + top}
186
+ width={barWidth}
187
+ height={4}
188
+ style={{ pointerEvents: 'visible', overflow: 'visible' }}
189
+ >
190
+ <Checkbox
191
+ checked={interactive}
192
+ onChange={e => this.changeInteractive(index, e.target.checked)}
193
+ />
194
+ </foreignObject>
195
+ )}
196
+ {defineChart && (
197
+ <foreignObject
198
+ x={x - 24}
199
+ y={y + 70 + top}
200
+ width={barWidth}
201
+ height={4}
202
+ style={{ pointerEvents: 'visible', overflow: 'visible' }}
203
+ >
204
+ <Checkbox
205
+ checked={editable}
206
+ onChange={e => this.changeEditable(index, e.target.checked)}
207
+ />
208
+ </foreignObject>
209
+ )}
116
210
  </g>
117
211
  );
118
212
  }
@@ -168,6 +262,7 @@ export class RawChartAxes extends React.Component {
168
262
  onChangeCategory,
169
263
  categories = [],
170
264
  top,
265
+ defineChart,
171
266
  theme
172
267
  } = this.props;
173
268
 
@@ -177,6 +272,7 @@ export class RawChartAxes extends React.Component {
177
272
 
178
273
  const bottomScale =
179
274
  xBand && typeof xBand.rangeRound === 'function' && xBand.rangeRound([0, size.width]);
275
+
180
276
  const bandWidth = xBand && typeof xBand.bandwidth === 'function' && xBand.bandwidth();
181
277
  // for chartType "line", bandWidth will be 0, so we have to calculate it
182
278
  const barWidth = bandWidth || (scale.x && scale.x(domain.max) / categories.length);
@@ -199,6 +295,7 @@ export class RawChartAxes extends React.Component {
199
295
  barWidth,
200
296
  rotate,
201
297
  top,
298
+ defineChart,
202
299
  onChangeCategory,
203
300
  onChange,
204
301
  graphProps,
package/src/chart.jsx CHANGED
@@ -47,7 +47,6 @@ export class Chart extends React.Component {
47
47
  title: PropTypes.string,
48
48
  onDataChange: PropTypes.func,
49
49
  addCategoryEnabled: PropTypes.bool,
50
- editCategoryEnabled: PropTypes.bool,
51
50
  categoryDefaultLabel: PropTypes.string,
52
51
  theme: PropTypes.object
53
52
  };
@@ -127,13 +126,12 @@ export class Chart extends React.Component {
127
126
  };
128
127
 
129
128
  getFilteredCategories = () => {
130
- const { data, editCategoryEnabled, addCategoryEnabled } = this.props;
129
+ const { data, defineChart } = this.props;
131
130
 
132
131
  return data
133
132
  ? data.map(d => ({
134
133
  ...d,
135
- editable: !d.initial || (d.initial && editCategoryEnabled),
136
- deletable: !d.initial || (d.initial && addCategoryEnabled)
134
+ deletable: defineChart || d.deletable
137
135
  }))
138
136
  : [];
139
137
  };
@@ -150,6 +148,8 @@ export class Chart extends React.Component {
150
148
  theme
151
149
  } = this.props;
152
150
  let { chartType } = this.props;
151
+
152
+ const defineChart = this.props.defineChart || false;
153
153
  const { width, height } = size || {};
154
154
 
155
155
  const { ChartComponent } = this.getChart();
@@ -176,9 +176,10 @@ export class Chart extends React.Component {
176
176
  () => this.rootNode
177
177
  )
178
178
  };
179
+
179
180
  log('[render] common:', common);
180
181
 
181
- const maskSize = { x: -10, y: -10, width: width + 20, height: height + 20 };
182
+ const maskSize = { x: -10, y: -10, width: width + 20, height: height + 80 };
182
183
  const { scale } = common.graphProps;
183
184
  const xBand = dataToXBand(scale.x, categories, width, chartType);
184
185
 
@@ -189,12 +190,13 @@ export class Chart extends React.Component {
189
190
  const bandWidth = xBand.bandwidth();
190
191
  // for chartType "line", bandWidth will be 0, so we have to calculate it
191
192
  const barWidth = bandWidth || scale.x(correctValues.domain.max) / categories.length;
193
+ const increaseHeight = defineChart ? 80 : 0;
192
194
 
193
195
  // if there are many categories, we have to rotate their names in order to fit
194
196
  // and we have to add extra value on top of some items
195
197
  const top = getTopPadding(barWidth);
196
198
  const rootCommon = cloneDeep(common);
197
- rootCommon.graphProps.size.height += top;
199
+ rootCommon.graphProps.size.height += top + increaseHeight;
198
200
 
199
201
  return (
200
202
  <div className={classNames(classes.class, className)}>
@@ -214,6 +216,7 @@ export class Chart extends React.Component {
214
216
  />
215
217
  <ChartAxes
216
218
  {...common}
219
+ defineChart={defineChart}
217
220
  categories={categories}
218
221
  xBand={xBand}
219
222
  leftAxis={leftAxis}