@pie-lib/charting 5.17.0-beta.0 → 5.17.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.
Files changed (74) hide show
  1. package/CHANGELOG.json +1 -581
  2. package/CHANGELOG.md +149 -43
  3. package/package.json +5 -5
  4. package/src/__tests__/__snapshots__/axes.test.jsx.snap +1 -0
  5. package/src/__tests__/__snapshots__/chart.test.jsx.snap +0 -18
  6. package/src/__tests__/__snapshots__/grid.test.jsx.snap +61 -17
  7. package/src/__tests__/axes.test.jsx +0 -5
  8. package/src/__tests__/chart.test.jsx +8 -0
  9. package/src/actions-button.jsx +109 -0
  10. package/src/axes.jsx +5 -31
  11. package/src/bars/common/bars.jsx +8 -10
  12. package/src/chart-setup.jsx +1 -1
  13. package/src/chart.jsx +31 -26
  14. package/src/common/drag-handle.jsx +3 -3
  15. package/src/common/styles.js +1 -1
  16. package/src/grid.jsx +38 -13
  17. package/src/index.js +2 -1
  18. package/src/key-legend.jsx +75 -0
  19. package/src/line/common/drag-handle.jsx +3 -9
  20. package/src/line/common/line.jsx +2 -6
  21. package/src/line/line-cross.js +29 -2
  22. package/src/line/line-dot.js +36 -19
  23. package/src/mark-label.jsx +7 -2
  24. package/src/plot/common/plot.jsx +8 -5
  25. package/src/tool-menu.jsx +1 -1
  26. package/lib/__tests__/axes.test.js +0 -181
  27. package/lib/__tests__/chart-setup.test.js +0 -58
  28. package/lib/__tests__/chart-type.test.js +0 -42
  29. package/lib/__tests__/chart.test.js +0 -108
  30. package/lib/__tests__/grid.test.js +0 -48
  31. package/lib/__tests__/mark-label.test.js +0 -57
  32. package/lib/__tests__/utils.js +0 -56
  33. package/lib/__tests__/utils.test.js +0 -197
  34. package/lib/axes.js +0 -643
  35. package/lib/bars/__tests__/bar.test.js +0 -62
  36. package/lib/bars/__tests__/histogram.test.js +0 -64
  37. package/lib/bars/__tests__/utils.js +0 -56
  38. package/lib/bars/bar.js +0 -86
  39. package/lib/bars/common/__tests__/bars.test.js +0 -100
  40. package/lib/bars/common/__tests__/utils.js +0 -56
  41. package/lib/bars/common/bars.js +0 -301
  42. package/lib/bars/histogram.js +0 -87
  43. package/lib/chart-setup.js +0 -458
  44. package/lib/chart-type.js +0 -71
  45. package/lib/chart-types.js +0 -31
  46. package/lib/chart.js +0 -438
  47. package/lib/common/__tests__/drag-handle.test.js +0 -134
  48. package/lib/common/__tests__/utils.js +0 -56
  49. package/lib/common/drag-handle.js +0 -175
  50. package/lib/common/drag-icon.js +0 -52
  51. package/lib/common/styles.js +0 -40
  52. package/lib/grid.js +0 -104
  53. package/lib/index.js +0 -40
  54. package/lib/line/__tests__/line-cross.test.js +0 -64
  55. package/lib/line/__tests__/line-dot.test.js +0 -64
  56. package/lib/line/__tests__/utils.js +0 -56
  57. package/lib/line/common/__tests__/drag-handle.test.js +0 -134
  58. package/lib/line/common/__tests__/line.test.js +0 -128
  59. package/lib/line/common/__tests__/utils.js +0 -56
  60. package/lib/line/common/drag-handle.js +0 -157
  61. package/lib/line/common/line.js +0 -261
  62. package/lib/line/line-cross.js +0 -168
  63. package/lib/line/line-dot.js +0 -131
  64. package/lib/mark-label.js +0 -255
  65. package/lib/plot/__tests__/dot.test.js +0 -64
  66. package/lib/plot/__tests__/line.test.js +0 -64
  67. package/lib/plot/__tests__/utils.js +0 -56
  68. package/lib/plot/common/__tests__/plot.test.js +0 -103
  69. package/lib/plot/common/__tests__/utils.js +0 -56
  70. package/lib/plot/common/plot.js +0 -280
  71. package/lib/plot/dot.js +0 -123
  72. package/lib/plot/line.js +0 -152
  73. package/lib/tool-menu.js +0 -142
  74. package/lib/utils.js +0 -244
package/src/axes.jsx CHANGED
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { withStyles } from '@material-ui/core/styles';
4
4
  import { types } from '@pie-lib/plot';
5
- import { color } from '@pie-lib/render-ui';
5
+ import { color } from '../../render-ui/src/index';
6
6
  import { AlertDialog } from '@pie-lib/config-ui';
7
7
  import { AxisLeft, AxisBottom } from '@vx/axis';
8
8
  import { bandKey, getTickValues, getRotateAngle } from './utils';
@@ -45,14 +45,6 @@ export class TickComponent extends React.Component {
45
45
  onChangeCategory(index, { ...category, label: newLabel });
46
46
  };
47
47
 
48
- deleteCategory = (index) => {
49
- const { categories, onChange } = this.props;
50
-
51
- if (index >= 0 && categories[index]) {
52
- onChange([...categories.slice(0, index), ...categories.slice(index + 1)]);
53
- }
54
- };
55
-
56
48
  changeInteractive = (index, value) => {
57
49
  const { categories, onChangeCategory } = this.props;
58
50
  const category = categories[index];
@@ -144,7 +136,7 @@ export class TickComponent extends React.Component {
144
136
  const { changeEditable, changeInteractive } = chartingOptions || {};
145
137
  const index = parseInt(formattedValue.split('-')[0], 10);
146
138
  const category = categories[index];
147
- const { deletable, editable, interactive, label, correctness } = category || {};
139
+ const { editable, interactive, label, correctness } = category || {};
148
140
  const barX = xBand(bandKey({ label }, index));
149
141
  const longestCategory = (categories || []).reduce((a, b) => {
150
142
  const lengthA = a && a.label ? a.label.length : 0;
@@ -185,6 +177,7 @@ export class TickComponent extends React.Component {
185
177
  rotate={rotate}
186
178
  correctness={correctness}
187
179
  error={error && error[index]}
180
+ limitCharacters
188
181
  />
189
182
  </foreignObject>
190
183
 
@@ -194,24 +187,6 @@ export class TickComponent extends React.Component {
194
187
  </text>
195
188
  )}
196
189
 
197
- {deletable && !correctness && (
198
- <line x1={x} y1={0} x2={x} y2={y + 4 + top} className={classes.dottedLine} strokeDasharray="4 2" />
199
- )}
200
-
201
- {deletable && !correctness && (
202
- <svg
203
- xmlns="http://www.w3.org/2000/svg"
204
- x={x - 8}
205
- y={y + 60 + top}
206
- width={16}
207
- height={16}
208
- viewBox="0 0 512 512"
209
- onClick={() => this.deleteCategory(index)}
210
- >
211
- <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" />
212
- </svg>
213
- )}
214
-
215
190
  {defineChart && index === 0 && (
216
191
  <svg
217
192
  x={-55}
@@ -493,7 +468,7 @@ const ChartAxes = withStyles(
493
468
  strokeWidth: 2,
494
469
  },
495
470
  axisLine: {
496
- stroke: color.primaryDark(),
471
+ stroke: color.visualElementsColors.AXIS_LINE_COLOR,
497
472
  strokeWidth: 2,
498
473
  },
499
474
  tick: {
@@ -501,7 +476,6 @@ const ChartAxes = withStyles(
501
476
  stroke: color.primaryDark(),
502
477
  strokeWidth: 2,
503
478
  },
504
- fill: color.primaryDark(),
505
479
  fontFamily: theme.typography.body1.fontFamily,
506
480
  fontSize: theme.typography.fontSize,
507
481
  textAnchor: 'middle',
@@ -515,7 +489,7 @@ const ChartAxes = withStyles(
515
489
  fill: theme.palette.error.main,
516
490
  },
517
491
  customColor: {
518
- color: `${color.tertiary()} !important`
492
+ color: `${color.tertiary()} !important`,
519
493
  },
520
494
  }),
521
495
  { withTheme: true },
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { types } from '@pie-lib/plot';
4
4
  import { Group } from '@vx/group';
5
- import { color } from '@pie-lib/render-ui';
5
+ import { color } from '../../../render-ui/src/index';
6
6
  import { Bar as VxBar } from '@vx/shape';
7
7
  import { withStyles } from '@material-ui/core/styles/index';
8
8
  import debug from 'debug';
@@ -39,12 +39,12 @@ const hoverHistogramColors = [
39
39
  '#894A65',
40
40
  ];
41
41
 
42
- const calculateFillColor = (isHovered, barColor, index, hoverHistogramColors) => {
43
- if (isHovered && barColor) {
42
+ const calculateFillColor = (isHovered, barColor, index, hoverHistogramColors, allowRolloverEvent) => {
43
+ if (isHovered && barColor && allowRolloverEvent) {
44
44
  return hoverHistogramColors[index % hoverHistogramColors.length];
45
45
  }
46
- if (isHovered) {
47
- return color.primaryDark();
46
+ if (isHovered && allowRolloverEvent) {
47
+ return color.visualElementsColors.ROLLOVER_FILL_BAR_COLOR;
48
48
  }
49
49
  return barColor || null;
50
50
  };
@@ -148,7 +148,8 @@ export class RawBar extends React.Component {
148
148
  const { scale, range } = graphProps;
149
149
  const { dragValue, isHovered } = this.state;
150
150
 
151
- const fillColor = calculateFillColor(isHovered, barColor, index, hoverHistogramColors);
151
+ const allowRolloverEvent = interactive && !correctness;
152
+ const fillColor = calculateFillColor(isHovered, barColor, index, hoverHistogramColors, allowRolloverEvent);
152
153
  const v = Number.isFinite(dragValue) ? dragValue : value;
153
154
  const barWidth = xBand.bandwidth();
154
155
  const barHeight = scale.y(range.max - v);
@@ -195,10 +196,7 @@ export class RawBar extends React.Component {
195
196
 
196
197
  const Bar = withStyles(() => ({
197
198
  bar: {
198
- fill: color.primaryLight(),
199
- '&:hover': {
200
- fill: color.primaryDark(),
201
- },
199
+ fill: color.defaults.TERTIARY,
202
200
  },
203
201
  }))(RawBar);
204
202
 
@@ -1,6 +1,6 @@
1
1
  import React, { useState, useEffect } from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { color } from '@pie-lib/render-ui';
3
+ import { color } from '../../render-ui/src/index';
4
4
  import { withStyles } from '@material-ui/core/styles';
5
5
  import Typography from '@material-ui/core/Typography';
6
6
  import ChartType from './chart-type';
package/src/chart.jsx CHANGED
@@ -2,16 +2,16 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { withStyles } from '@material-ui/core/styles';
4
4
  import classNames from 'classnames';
5
- import { Root, createGraphProps } from '@pie-lib/plot';
5
+ import debug from 'debug';
6
6
  import cloneDeep from 'lodash/cloneDeep';
7
+
8
+ import { Root, createGraphProps } from '@pie-lib/plot';
9
+ import { AlertDialog } from '@pie-lib/config-ui';
7
10
  import ChartGrid from './grid';
8
11
  import ChartAxes from './axes';
9
- import debug from 'debug';
10
- import { color } from '@pie-lib/render-ui';
11
12
  import { dataToXBand, getDomainAndRangeByChartType, getGridLinesAndAxisByChartType, getTopPadding } from './utils';
12
- import ToolMenu from './tool-menu';
13
13
  import chartTypes from './chart-types';
14
- import { AlertDialog } from '@pie-lib/config-ui';
14
+ import ActionsButton from './actions-button';
15
15
  import Translator from '@pie-lib/translator';
16
16
 
17
17
  const { translator } = Translator;
@@ -25,6 +25,7 @@ export class Chart extends React.Component {
25
25
  dialog: {
26
26
  open: false,
27
27
  },
28
+ actionsAnchorEl: null,
28
29
  };
29
30
  this.maskUid = this.generateMaskId();
30
31
  }
@@ -174,6 +175,18 @@ export class Chart extends React.Component {
174
175
  }
175
176
  };
176
177
 
178
+ deleteCategory = (index) => {
179
+ const { data, onDataChange } = this.props;
180
+
181
+ if (typeof index !== 'number' || index < 0) {
182
+ return;
183
+ }
184
+
185
+ if (data && data.length > 0) {
186
+ onDataChange(data.filter((_, i) => i !== index));
187
+ }
188
+ };
189
+
177
190
  getFilteredCategories = () => {
178
191
  const { data, defineChart } = this.props;
179
192
 
@@ -252,15 +265,6 @@ export class Chart extends React.Component {
252
265
 
253
266
  return (
254
267
  <div className={classNames(classes.chart, classes.chartBox, className)}>
255
- <div className={classes.controls}>
256
- <ToolMenu
257
- className={classes.toolMenu}
258
- disabled={!addCategoryEnabled}
259
- addCategory={() => this.addCategory()}
260
- language={language}
261
- />
262
- </div>
263
-
264
268
  <Root
265
269
  title={title}
266
270
  onChangeTitle={onChangeTitle}
@@ -297,6 +301,18 @@ export class Chart extends React.Component {
297
301
  top={top}
298
302
  error={error}
299
303
  />
304
+ {addCategoryEnabled ? (
305
+ <foreignObject x={width - 8} y={height - 8} width={100} height={40}>
306
+ <div xmlns="http://www.w3.org/1999/xhtml" style={{ display: 'flex', justifyContent: 'center' }}>
307
+ <ActionsButton
308
+ categories={categories}
309
+ addCategory={this.addCategory}
310
+ deleteCategory={this.deleteCategory}
311
+ language={language}
312
+ />
313
+ </div>
314
+ </foreignObject>
315
+ ) : null}
300
316
  <mask id={`${this.maskUid}`}>
301
317
  <rect {...maskSize} fill="white" />
302
318
  </mask>
@@ -327,21 +343,10 @@ const styles = (theme) => ({
327
343
  graphBox: {
328
344
  transform: 'translate(60px, 35px)',
329
345
  },
330
- controls: {
331
- display: 'flex',
332
- justifyContent: 'space-between',
333
- padding: theme.spacing.unit,
334
- backgroundColor: color.primaryLight(),
335
- '& button': {
336
- fontSize: theme.typography.fontSize,
337
- },
338
- },
339
346
  svg: {
340
347
  overflow: 'visible',
341
348
  },
342
- toolMenu: {
343
- minHeight: '36px',
344
- },
349
+
345
350
  chartBox: {
346
351
  width: 'min-content',
347
352
  },
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
3
3
  import classNames from 'classnames';
4
4
  import { withStyles } from '@material-ui/core/styles';
5
5
  import { gridDraggable, utils, types } from '@pie-lib/plot';
6
- import { color } from '@pie-lib/render-ui';
6
+ import { color as enumColor } from '../../../render-ui/src/index';
7
7
  import { correct, incorrect, disabled } from './styles';
8
8
  import { getScale } from '../utils';
9
9
  import DragIcon from './drag-icon';
@@ -28,7 +28,7 @@ const RawDragHandle = ({
28
28
  return (
29
29
  <svg x={x} y={scale.y(y) - 10} width={width} overflow="visible" className={classes.svgOverflowVisible}>
30
30
  {isHovered && !correctness && interactive && (
31
- <DragIcon width={width} scaleValue={scaleValue} color={color} classes={classes} />
31
+ <DragIcon width={width} scaleValue={scaleValue} color={enumColor.defaults.BORDER_GRAY} classes={classes} />
32
32
  )}
33
33
  {interactive && !correctness && (
34
34
  <ellipse
@@ -107,7 +107,7 @@ export const DragHandle = withStyles(() => ({
107
107
  height: 30,
108
108
  '&:hover': {
109
109
  '& .handle': {
110
- fill: color.secondaryDark(),
110
+ fill: enumColor.secondaryDark(),
111
111
  height: '16px',
112
112
  },
113
113
  },
@@ -1,4 +1,4 @@
1
- import { color } from '@pie-lib/render-ui';
1
+ import { color } from '../../../render-ui/src/index';
2
2
 
3
3
  export const disabled = (key = 'fill') => ({
4
4
  [key]: `var(--graph-disabled, ${color.disabled()})`,
package/src/grid.jsx CHANGED
@@ -2,10 +2,10 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { withStyles } from '@material-ui/core/styles';
4
4
  import classNames from 'classnames';
5
+ import { GridRows, GridColumns } from '@vx/grid';
5
6
 
6
- import { Grid as VxGrid } from '@vx/grid';
7
7
  import { types } from '@pie-lib/plot';
8
- import { color } from '@pie-lib/render-ui';
8
+ import { color } from '../../render-ui/src/index';
9
9
 
10
10
  export class Grid extends React.Component {
11
11
  static propTypes = {
@@ -21,19 +21,44 @@ export class Grid extends React.Component {
21
21
 
22
22
  render() {
23
23
  const { classes, className, graphProps, xBand, rowTickValues, columnTickValues } = this.props;
24
- const { scale = {}, size = {} } = graphProps || {};
24
+ const { scale = {}, size = {}, range = {} } = graphProps || {};
25
+ const { step = 0, labelStep = 0 } = range;
26
+ const highlightNonLabel = step && labelStep && step < labelStep;
27
+ // if highlightNonLabel is true, we need to separate the unlabled lines in order to render them in a different color
28
+ const { unlabeledLines, labeledLines } = (rowTickValues || []).reduce(
29
+ (acc, value) => {
30
+ if (highlightNonLabel && value % labelStep !== 0) {
31
+ acc.unlabeledLines.push(value);
32
+ } else {
33
+ acc.labeledLines.push(value);
34
+ }
35
+ return acc;
36
+ },
37
+ { unlabeledLines: [], labeledLines: [] },
38
+ );
25
39
 
26
40
  return (
27
- <VxGrid
28
- xScale={xBand}
29
- yScale={scale.y}
30
- className={classNames(classes.grid, className)}
31
- width={size.width}
32
- height={size.height}
33
- xOffset={xBand.bandwidth() / 2}
34
- rowTickValues={rowTickValues}
35
- columnTickValues={columnTickValues}
36
- />
41
+ <g className={classNames(classes.grid, className)}>
42
+ <GridRows
43
+ scale={scale.y}
44
+ width={size.width}
45
+ tickValues={unlabeledLines}
46
+ lineStyle={{
47
+ stroke: color.fadedPrimary(),
48
+ strokeWidth: 1,
49
+ }}
50
+ />
51
+ <GridRows
52
+ scale={scale.y}
53
+ width={size.width}
54
+ tickValues={labeledLines}
55
+ lineStyle={{
56
+ stroke: color.visualElementsColors.GRIDLINES_COLOR,
57
+ strokeWidth: 1,
58
+ }}
59
+ />
60
+ <GridColumns scale={xBand} height={size.height} offset={xBand.bandwidth() / 2} tickValues={columnTickValues} />
61
+ </g>
37
62
  );
38
63
  }
39
64
  }
package/src/index.js CHANGED
@@ -2,5 +2,6 @@ import Chart from './chart';
2
2
  import chartTypes from './chart-types';
3
3
  import ConfigureChartPanel from './chart-setup';
4
4
  import ChartType from './chart-type';
5
+ import KeyLegend from './key-legend';
5
6
 
6
- export { Chart, chartTypes, ChartType, ConfigureChartPanel };
7
+ export { Chart, chartTypes, ChartType, ConfigureChartPanel, KeyLegend };
@@ -0,0 +1,75 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { withStyles } from '@material-ui/core/styles';
4
+ import Check from '@material-ui/icons/Check';
5
+ import Close from '@material-ui/icons/Close';
6
+ import { color } from '../../render-ui/src/index';
7
+ import Translator from '@pie-lib/translator';
8
+
9
+ const styles = (theme) => ({
10
+ container: {
11
+ backgroundColor: color.defaults.WHITE,
12
+ padding: theme.spacing.unit * 2,
13
+ width: '355px',
14
+ boxShadow: 'inset 0px 1px 5px 0px #9297A6',
15
+ display: 'flex',
16
+ flexDirection: 'column',
17
+ gap: '16px',
18
+ },
19
+ row: {
20
+ display: 'flex',
21
+ alignItems: 'center',
22
+ gap: '12px',
23
+ },
24
+ title: {
25
+ fontSize: theme.typography.h6.fontSize,
26
+ fontWeight: '700',
27
+ },
28
+ smallText: {
29
+ marginLeft: '2px',
30
+ },
31
+ correctIcon: {
32
+ backgroundColor: color.correct(),
33
+ borderRadius: theme.spacing.unit * 2,
34
+ color: color.defaults.WHITE,
35
+ },
36
+ incorrectIcon: {
37
+ backgroundColor: color.incorrectWithIcon(),
38
+ borderRadius: theme.spacing.unit * 2,
39
+ color: color.defaults.WHITE,
40
+ },
41
+
42
+ lastRow: {
43
+ marginLeft: '3px',
44
+ display: 'flex',
45
+ alignItems: 'center',
46
+ gap: '12px',
47
+ },
48
+ });
49
+
50
+ const { translator } = Translator;
51
+
52
+ const KeyLegend = ({ classes, language }) => (
53
+ <div className={classes.container}>
54
+ <div className={classes.title}>Key</div>
55
+ <div className={classes.row}>
56
+ <Close className={classes.incorrectIcon} />
57
+ <div className={classes.text}>{translator.t('charting.keyLegend.incorrectAnswer', { lng: language })}</div>
58
+ </div>
59
+ <div className={classes.row}>
60
+ <Check className={classes.correctIcon} />
61
+ <div className={classes.text}>{translator.t('charting.keyLegend.correctAnswer', { lng: language })}</div>
62
+ </div>
63
+ <div className={classes.lastRow}>
64
+ <Check className={classes.correctIcon} fontSize={'small'} />
65
+ <div className={classes.smallText}>{translator.t('charting.keyLegend.correctKeyAnswer', { lng: language })}</div>
66
+ </div>
67
+ </div>
68
+ );
69
+
70
+ KeyLegend.propTypes = {
71
+ classes: PropTypes.object.isRequired,
72
+ language: PropTypes.string,
73
+ };
74
+
75
+ export default withStyles(styles)(KeyLegend);
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import classNames from 'classnames';
3
3
  import { gridDraggable, utils, types } from '@pie-lib/plot';
4
4
  import { withStyles } from '@material-ui/core/styles/index';
5
- import { color } from '@pie-lib/render-ui';
5
+ import { color } from '../../../../render-ui/src/index';
6
6
  import PropTypes from 'prop-types';
7
7
  import { correct, incorrect, disabled } from '../../common/styles';
8
8
 
@@ -44,6 +44,7 @@ class RawDragHandle extends React.Component {
44
44
  classes={classes}
45
45
  className={classNames(className, !interactive && 'non-interactive')}
46
46
  correctness={correctness}
47
+ interactive={interactive}
47
48
  {...rest}
48
49
  />
49
50
  );
@@ -52,11 +53,7 @@ class RawDragHandle extends React.Component {
52
53
 
53
54
  export const DragHandle = withStyles(() => ({
54
55
  handle: {
55
- fill: color.defaults.SECONDARY,
56
56
  transition: 'fill 200ms linear, height 200ms linear',
57
- '&:hover': {
58
- fill: color.defaults.SECONDARY_DARK,
59
- },
60
57
  '&.correct': correct('fill'),
61
58
  '&.incorrect': incorrect('fill'),
62
59
  '&.non-interactive': disabled('fill'),
@@ -67,11 +64,8 @@ export const DragHandle = withStyles(() => ({
67
64
  stroke: 'transparent',
68
65
  },
69
66
  line: {
70
- stroke: color.defaults.SECONDARY,
67
+ stroke: color.defaults.TEXT,
71
68
  transition: 'fill 200ms linear, height 200ms linear',
72
- '&:hover': {
73
- stroke: color.defaults.SECONDARY_DARK,
74
- },
75
69
  '&.non-interactive': disabled('stroke'),
76
70
  '&.correct': correct('stroke'),
77
71
  '&.incorrect': incorrect('stroke'),
@@ -6,7 +6,7 @@ import { types } from '@pie-lib/plot';
6
6
  import DraggableHandle, { DragHandle } from './drag-handle';
7
7
  import { withStyles } from '@material-ui/core/styles/index';
8
8
  import isEqual from 'lodash/isEqual';
9
- import { color } from '@pie-lib/render-ui';
9
+ import { color } from '../../../../render-ui/src/index';
10
10
 
11
11
  const getData = (data, domain) => {
12
12
  const { max } = domain || {};
@@ -121,13 +121,9 @@ export class RawLine extends React.Component {
121
121
  const StyledLine = withStyles(() => ({
122
122
  line: {
123
123
  fill: 'transparent',
124
- stroke: color.primaryLight(),
124
+ stroke: color.defaults.TERTIARY,
125
125
  strokeWidth: 3,
126
126
  transition: 'stroke 200ms ease-in, stroke-width 200ms ease-in',
127
- '&:hover': {
128
- strokeWidth: 6,
129
- stroke: color.primaryDark(),
130
- },
131
127
  },
132
128
  }))(RawLine);
133
129
 
@@ -1,14 +1,21 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { types } from '@pie-lib/plot';
4
4
  import { LinePath } from '@vx/shape';
5
5
  import { Group } from '@vx/group';
6
6
  import classNames from 'classnames';
7
+ import { color } from '../../../render-ui/src/index';
7
8
  import { dataToXBand } from '../utils';
8
9
  import RawLine from './common/line';
9
10
 
10
11
  const DraggableComponent = (props) => {
11
12
  const { classes = {}, className, scale, x, y, r, correctness, ...rest } = props;
13
+ const [hover, setHover] = useState(false);
14
+
15
+ const squareSize = r * 4;
16
+ const squareHalf = squareSize / 2;
17
+ const cx = scale.x(x);
18
+ const cy = scale.y(y);
12
19
 
13
20
  return (
14
21
  <Group className={classNames(className, classes.line, correctness && correctness.value)}>
@@ -34,7 +41,27 @@ const DraggableComponent = (props) => {
34
41
  strokeWidth={5}
35
42
  style={{ pointerEvents: 'none' }}
36
43
  />
37
- <circle cx={scale.x(x)} cy={scale.y(y)} r={r * 2} className={classNames(classes.transparentHandle)} {...rest} />
44
+ {hover && (
45
+ <rect
46
+ x={cx - squareHalf}
47
+ y={cy - squareHalf}
48
+ width={squareSize}
49
+ height={squareSize}
50
+ stroke={color.defaults.BORDER_GRAY}
51
+ fill="none"
52
+ strokeWidth={2}
53
+ pointerEvents="none"
54
+ />
55
+ )}
56
+ <circle
57
+ cx={cx}
58
+ cy={cy}
59
+ r={r * 2}
60
+ className={classNames(classes.transparentHandle)}
61
+ onMouseEnter={() => setHover(true)}
62
+ onMouseLeave={() => setHover(false)}
63
+ {...rest}
64
+ />
38
65
  </Group>
39
66
  );
40
67
  };
@@ -1,29 +1,46 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { types } from '@pie-lib/plot';
4
+ import { color } from '../../../render-ui/src/index';
4
5
  import { dataToXBand } from '../utils';
5
6
  import RawLine from './common/line';
6
7
  import classNames from 'classnames';
7
8
 
8
- const DraggableComponent = ({ scale, x, y, className, classes, r, correctness, ...rest }) => (
9
- <g>
10
- <circle
11
- cx={scale.x(x)}
12
- cy={scale.y(y)}
13
- r={r * 3}
14
- className={classNames(classes.transparentHandle, className)}
15
- style={{ pointerEvents: 'none' }}
16
- {...rest}
17
- />
18
- <circle
19
- cx={scale.x(x)}
20
- cy={scale.y(y)}
21
- r={r}
22
- className={classNames(className, classes.handle, correctness && correctness.value)}
23
- {...rest}
24
- />
25
- </g>
26
- );
9
+ const DraggableComponent = ({ scale, x, y, className, classes, r, correctness, interactive, ...rest }) => {
10
+ const [isHovered, setIsHovered] = React.useState(false);
11
+ const allowRolloverEvent = !correctness && interactive;
12
+
13
+ return (
14
+ <g onMouseEnter={() => setIsHovered(true)} onMouseLeave={() => setIsHovered(false)}>
15
+ <circle
16
+ cx={scale.x(x)}
17
+ cy={scale.y(y)}
18
+ r={r * 3}
19
+ className={classNames(classes.transparentHandle, className)}
20
+ pointerEvents={correctness ? 'none' : ''}
21
+ {...rest}
22
+ />
23
+ <circle
24
+ cx={scale.x(x)}
25
+ cy={scale.y(y)}
26
+ r={r}
27
+ className={classNames(className, classes.handle, correctness && correctness.value)}
28
+ {...rest}
29
+ />
30
+ {isHovered && allowRolloverEvent && (
31
+ <rect
32
+ x={scale.x(x) - r * 2}
33
+ y={scale.y(y) - r * 2}
34
+ width={r * 4}
35
+ height={r * 4}
36
+ stroke={color.defaults.BORDER_GRAY}
37
+ strokeWidth="1"
38
+ fill="none"
39
+ />
40
+ )}
41
+ </g>
42
+ );
43
+ };
27
44
 
28
45
  DraggableComponent.propTypes = {
29
46
  scale: PropTypes.object,
@@ -5,7 +5,7 @@ import AutosizeInput from 'react-input-autosize';
5
5
  import PropTypes from 'prop-types';
6
6
  import { types } from '@pie-lib/plot';
7
7
  import { correct, incorrect, disabled } from './common/styles';
8
- import { color } from '@pie-lib/render-ui';
8
+ import { color } from '../../render-ui/src/index';
9
9
  import { renderMath } from '@pie-lib/math-rendering';
10
10
 
11
11
  const styles = (theme) => ({
@@ -14,7 +14,6 @@ const styles = (theme) => ({
14
14
  fontFamily: theme.typography.fontFamily,
15
15
  fontSize: theme.typography.fontSize,
16
16
  border: 'none',
17
- color: color.primaryDark(),
18
17
  '&.correct': correct('color'),
19
18
  '&.incorrect': incorrect('color'),
20
19
  '&.disabled': {
@@ -89,6 +88,7 @@ export const MarkLabel = (props) => {
89
88
  autoFocus,
90
89
  error,
91
90
  isHiddenLabel,
91
+ limitCharacters,
92
92
  } = props;
93
93
 
94
94
  const [label, setLabel] = useState(mark.label);
@@ -97,6 +97,10 @@ export const MarkLabel = (props) => {
97
97
  let root = useRef(null);
98
98
 
99
99
  const onChange = (e) => {
100
+ if (limitCharacters && e.target.value && e.target.value.length > 20) {
101
+ return;
102
+ }
103
+
100
104
  setLabel(e.target.value);
101
105
  };
102
106
 
@@ -205,6 +209,7 @@ MarkLabel.propTypes = {
205
209
  label: PropTypes.string,
206
210
  }),
207
211
  isHiddenLabel: PropTypes.bool,
212
+ limitCharacters: PropTypes.bool,
208
213
  };
209
214
 
210
215
  export default withStyles(styles)(MarkLabel);