@sis-cc/dotstatsuite-components 8.11.0 → 8.13.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 (52) hide show
  1. package/lib/app.js +13 -5
  2. package/lib/rules/src/factories/stacked-dimension.js +17 -23
  3. package/lib/rules/src/factories/stacked-series.js +82 -158
  4. package/lib/rules/src/index.js +3 -6
  5. package/lib/rules/src/properties/index.js +2 -1
  6. package/lib/rules/src/properties/stacked.js +35 -11
  7. package/lib/rules/src/properties/utils.js +7 -1
  8. package/lib/rules-driver/src/app.js +116 -167
  9. package/lib/viewer/src/app/use-case-3.js +52 -0
  10. package/lib/viewer/src/app.js +9 -0
  11. package/lib/viewer/src/index.js +1 -1
  12. package/lib/viewer/src/legends/SeriesLegend.js +3 -1
  13. package/package.json +2 -2
  14. package/src/app.js +10 -5
  15. package/src/rules/src/factories/stacked-dimension.js +14 -10
  16. package/src/rules/src/factories/stacked-series.js +102 -94
  17. package/src/rules/src/index.js +1 -2
  18. package/src/rules/src/properties/index.js +3 -1
  19. package/src/rules/src/properties/stacked.js +23 -7
  20. package/src/rules/src/properties/utils.js +8 -3
  21. package/src/rules-driver/src/app.js +116 -132
  22. package/src/rules-driver/src/mocks/data1.json +332 -0
  23. package/src/rules-driver/src/mocks/data2.json +309 -0
  24. package/src/viewer/src/app/use-case-3.js +18 -0
  25. package/src/viewer/src/app.js +6 -0
  26. package/src/viewer/src/index.js +2 -2
  27. package/src/viewer/src/legends/SeriesLegend.js +4 -1
  28. package/lib/rules-driver/src/app/chart.js +0 -52
  29. package/lib/rules-driver/src/app/config-axis.js +0 -95
  30. package/lib/rules-driver/src/app/config-buttons.js +0 -47
  31. package/lib/rules-driver/src/app/config-input.js +0 -51
  32. package/lib/rules-driver/src/app/config-select.js +0 -57
  33. package/lib/rules-driver/src/app/config-t4size.js +0 -61
  34. package/lib/rules-driver/src/app/config1.js +0 -148
  35. package/lib/rules-driver/src/app/menu.js +0 -44
  36. package/lib/rules-driver/src/app/viewer1.js +0 -39
  37. package/lib/rules-driver/src/app/viewer2.js +0 -115
  38. package/src/rules-driver/src/app/chart.js +0 -18
  39. package/src/rules-driver/src/app/config-axis.js +0 -54
  40. package/src/rules-driver/src/app/config-buttons.js +0 -27
  41. package/src/rules-driver/src/app/config-input.js +0 -35
  42. package/src/rules-driver/src/app/config-select.js +0 -25
  43. package/src/rules-driver/src/app/config-t4size.js +0 -50
  44. package/src/rules-driver/src/app/config1.js +0 -120
  45. package/src/rules-driver/src/app/menu.js +0 -27
  46. package/src/rules-driver/src/app/viewer1.js +0 -18
  47. package/src/rules-driver/src/app/viewer2.js +0 -77
  48. package/src/rules-driver/src/mocks/ecb.json +0 -2069
  49. package/src/rules-driver/src/mocks/ins.json +0 -264
  50. package/src/rules-driver/src/mocks/oecd-time.json +0 -864
  51. package/src/rules-driver/src/mocks/oecd.json +0 -372
  52. package/src/rules-driver/src/mocks/tunisia.json +0 -333
@@ -1,139 +1,144 @@
1
- import { find, get, groupBy, has, head, isUndefined, join, keyBy, map, reduce, split, sortBy, sumBy, take } from 'lodash';
2
1
  import { isTimePeriodDimension } from '@sis-cc/dotstatsuite-sdmxjs';
3
2
  import { dimensionValueDisplay } from '../dimension-utils';
4
3
  import { getObservationFormater } from '../observation-formater';
4
+ import * as R from 'ramda';
5
5
 
6
6
  const flatDatapoints = (observations, dimensions, dimensionsWithValuesIndexedById, serieDimensionId, display, formaterAttrs) => {
7
- return map(
8
- observations,
7
+
8
+ const datapoints = R.mapObjIndexed(
9
9
  (observationValue, observationKey) => {
10
10
  let x = null;
11
- const y = Number(head(observationValue));
11
+ const y = Number(R.head(observationValue));
12
12
  const formater = getObservationFormater(observationValue, formaterAttrs);
13
- const splittedKey = split(observationKey, ':');
13
+ const splittedKey = R.split(':', observationKey);
14
14
  let layerKey = [];
15
- const layerDimensions = reduce(
16
- splittedKey,
15
+ const layerDimensions = R.addIndex(R.reduce)(
17
16
  (memo, dimensionValueIndex, dimensionIndex) => {
18
- const dimension = get(dimensions, `[${dimensionIndex}]`);
19
- if (has(dimensionsWithValuesIndexedById, dimension.id)) {
20
- const dimensionValue = {
21
- ...get(dimension, `values[${dimensionValueIndex}]`, {}),
22
- index: dimensionValueIndex,
23
- label: dimensionValueDisplay(display)(get(dimension, `values[${dimensionValueIndex}]`, {}))
24
- }
25
- if (dimension.id === serieDimensionId) {
26
- x = dimensionValue;
27
- }
28
- else {
29
- memo.push(dimensionValue);
30
- layerKey.push(dimensionValueIndex);
31
- }
17
+ const dimension = R.nth(dimensionIndex, dimensions);
18
+ const _dimensionValue = R.pathOr({}, ['values', Number(dimensionValueIndex)], dimension);
19
+ const label = dimensionValueDisplay(display)(_dimensionValue);
20
+ const dimensionValue = {
21
+ ..._dimensionValue,
22
+ index: Number(dimensionValueIndex),
23
+ label
24
+ };
25
+ if (dimension.id === serieDimensionId) {
26
+ x = dimensionValue;
27
+ }
28
+ else if (R.has(dimension.id, dimensionsWithValuesIndexedById)) {
29
+ memo.push(dimensionValue);
30
+ layerKey.push(dimensionValueIndex);
32
31
  }
33
32
  return memo;
34
33
  },
35
- []
34
+ [],
35
+ splittedKey
36
36
  );
37
- return ({ formater, x, y, layerDimensions, layerKey: join(layerKey, ':') });
38
- }
37
+ return ({ formater, x, y, layerDimensions, layerKey: R.join(':', layerKey) });
38
+ },
39
+ observations
39
40
  );
41
+
42
+ return R.values(datapoints);
40
43
  };
41
44
 
42
45
  const serie = (observations, dimensions, dimensionsWithValuesIndexedById, serieDimensionId, display, formaterAttrs) => {
43
- const serieDimension = find(dimensionsWithValuesIndexedById, d => d.id === serieDimensionId);
44
- if (isUndefined(serieDimension)) {
45
- return [];
46
+ const serieDimension = R.find(R.propEq('id', serieDimensionId), dimensions);
47
+ if (R.isNil(serieDimension)) {
48
+ return { datapoints: [], layerSeries: [] };
46
49
  }
47
50
  const _flatDatapoints = flatDatapoints(observations, dimensions, dimensionsWithValuesIndexedById, serieDimensionId, display, formaterAttrs);
48
- const layeredDatapoints = groupBy(
49
- _flatDatapoints,
50
- dp => dp.layerKey
51
+
52
+ const layeredDatapoints = R.groupBy(
53
+ R.prop('layerKey'),
54
+ _flatDatapoints
51
55
  ); // { [layeredKey]: [dps] }
52
- const layerFullSeries = map(
53
- layeredDatapoints,
54
- (datapoints, layerKey) => ({ layerDimensions: get(head(datapoints), 'layerDimensions'), layerKey })
56
+
57
+ const layerFullSeries = R.map(
58
+ datapoints => ({
59
+ layerDimensions: R.prop('layerDimensions', R.head(datapoints)),
60
+ layerKey: R.prop('layerKey', R.head(datapoints))
61
+ }),
62
+ R.values(layeredDatapoints)
55
63
  ); // [{ layerDimensions, layerKey }]
56
- const layerSeries = take(sortBy(layerFullSeries, layer => layer.layerKey), 5);
57
- const layeredDatapointsKeyedByX = reduce(
58
- layeredDatapoints,
59
- (memo, layerDps, key) => {
60
- const dps = keyBy(layerDps, dp => get(dp, 'x.id', ''));
61
- return ({
62
- ...memo,
63
- [`${key}`]: dps
64
- });
65
- },
66
- {}
64
+ const layerSeries = R.take(5, R.sortBy(R.prop('layerKey'), layerFullSeries));
65
+ const layeredDatapointsKeyedByX = R.mapObjIndexed(
66
+ R.indexBy(R.path(['x', 'id'])),
67
+ layeredDatapoints
67
68
  ); // { [layeredKey]: { [x.id]: dp } }
68
- const datapoints = map(
69
- serieDimension.values,
69
+ const datapoints = R.addIndex(R.map)(
70
70
  (serieValue, index) => {
71
71
  const serieValueId = serieValue.id;
72
72
  const x = dimensionValueDisplay(display)(serieValue);
73
- const y = map(
73
+ const y = R.map(
74
+ ({ layerKey }) => R.pathOr(null, [layerKey, serieValueId, 'y'], layeredDatapointsKeyedByX),
74
75
  layerSeries,
75
- ({ layerKey }) => get(layeredDatapointsKeyedByX, `${layerKey}.${serieValueId}.y`, null)
76
76
  );
77
- const formaters = map(
77
+ const formaters = R.map(
78
+ ({ layerKey }) => R.pathOr(null, [layerKey, serieValueId, 'formater'], layeredDatapointsKeyedByX),
78
79
  layerSeries,
79
- ({ layerKey }) => get(layeredDatapointsKeyedByX, `${layerKey}.${serieValueId}.formater`, null)
80
80
  );
81
81
  return ({ category: x, formaters, index, x, y, key: serieValueId });
82
- }
82
+ },
83
+ serieDimension.values,
84
+ );
85
+ const _datapoints = R.when(
86
+ R.pipe(R.length, R.equals(1)),
87
+ R.pipe(
88
+ R.set(R.lensPath([0, 'category']), ''),
89
+ R.set(R.lensPath([0, 'x']), ''),
90
+ ),
91
+ datapoints
83
92
  );
84
93
  return ({
85
- datapoints,
86
- layerSeries: map(
87
- layerSeries,
94
+ datapoints: _datapoints,
95
+ layerSeries: R.map(
88
96
  layer => ({
89
- id: join(map(layer.layerDimensions, l => l.id), ' - '),
90
- label: join(map(layer.layerDimensions, l => l.label), ' - '),
91
- })
97
+ id: R.pipe(R.prop('layerDimensions'), R.pluck('id'), R.join(' - '))(layer),
98
+ label: R.pipe(R.prop('layerDimensions'), R.pluck('label'), R.join(' - '))(layer),
99
+ }),
100
+ layerSeries
92
101
  )
93
102
  });
94
103
  };
95
104
 
96
- const percentSerie = (serie) => {
97
- return [{
98
- layerSeries: serie.layerSeries,
99
- datapoints: map(
100
- serie.datapoints,
101
- dp => {
102
- const total = sumBy(dp.y, val => Math.abs(val));
103
- if (!total) {
104
- return dp;
105
- }
106
- return ({
107
- ...dp,
108
- y: map(dp.y, value => (Math.abs(value) / total) * 100),
109
- formaters: null,
110
- });
105
+ const percentSerie = R.pipe(
106
+ R.over(
107
+ R.lensProp('datapoints'),
108
+ R.map(dp => {
109
+ const total = R.pipe(R.map(v => Math.abs(v)), R.sum)(dp.y);
110
+ if (!total) {
111
+ return dp;
111
112
  }
112
- )
113
- }];
114
- };
113
+ return ({
114
+ ...dp,
115
+ y: R.map(v => (Math.abs(v) / total) * 100, dp.y),
116
+ formaters: null,
117
+ });
118
+ })
119
+ ),
120
+ R.of
121
+ );
115
122
 
116
- const serieSortedByTotal = (serie) => {
117
- return [{
118
- layerSeries: serie.layerSeries,
119
- datapoints: sortBy(
120
- serie.datapoints,
121
- dp => sumBy(dp.y, val => val > 0 ? (-1 * val) : 0)
122
- )
123
- }];
124
- };
123
+ const serieSortedByTotal = R.pipe(
124
+ R.over(
125
+ R.lensProp('datapoints'),
126
+ R.sortBy(R.pipe(R.prop('y'), R.map(v => v > 0 ? R.negate(v) : 0), R.sum))
127
+ ),
128
+ R.of
129
+ );
125
130
 
126
- const serieSortedByDataOrder = (serie) => [{ //to robustize with date generation, as in timeline series
127
- layerSeries: serie.layerSeries,
128
- datapoints: sortBy(
129
- serie.datapoints,
130
- dp => dp.index
131
- )
132
- }];
131
+ const serieSortedByDataOrder = R.pipe(
132
+ R.over(
133
+ R.lensProp('datapoints'),
134
+ R.sortBy(R.prop('index'))
135
+ ),
136
+ R.of
137
+ );
133
138
 
134
139
  export default ({ observations, dimensions }, dimensionsWithValuesIndexedById, singularity, display, formaterAttrs) => {
135
- const mode = get(singularity, 'mode', 'values');
136
- const serieDimensionId = get(singularity, 'id', null);
140
+ const mode = R.propOr('values', 'mode', singularity);
141
+ const serieDimensionId = R.propOr(null, 'id', singularity);
137
142
  const _serie = serie(observations, dimensions, dimensionsWithValuesIndexedById, serieDimensionId, display, formaterAttrs);
138
143
  if (mode === 'percent') {
139
144
  return percentSerie(_serie);
@@ -141,5 +146,8 @@ export default ({ observations, dimensions }, dimensionsWithValuesIndexedById, s
141
146
  else if (isTimePeriodDimension({ id: serieDimensionId })) {
142
147
  return serieSortedByDataOrder(_serie);
143
148
  }
144
- return serieSortedByTotal(_serie);
149
+ //console.log('raw serie', _serie);
150
+ const res = serieSortedByTotal(_serie);
151
+ //console.log('serie', res);
152
+ return res;
145
153
  };
@@ -129,8 +129,7 @@ const _symbolDimension = (data, ids) => {
129
129
  export const symbolDimension = memoizee(_symbolDimension);
130
130
 
131
131
  const _stackedDimension = (data, singularity) => {
132
- const { values } = splitDimensions(data);
133
- return __stackedDimension(values, singularity);
132
+ return __stackedDimension(splitDimensions(data), singularity);
134
133
  }
135
134
  export const stackedDimension = memoizee(_stackedDimension);
136
135
 
@@ -40,6 +40,7 @@ import {
40
40
  } from './symbol';
41
41
  import {
42
42
  isStacked,
43
+ isStackedDimActive,
43
44
  onChangeStackedDimension,
44
45
  onChangeStackedMode,
45
46
  stackedModeOptions,
@@ -205,6 +206,7 @@ export const initialState = {
205
206
  };
206
207
 
207
208
  export const stateFromNewProps = (props, state) => {
209
+ if (R.isNil(props.data)) return state; // don't reset state
208
210
  const focusState = sampleFocusStateFromNewProps(props, state);
209
211
  const scatterState = scatterStateFromNewProps(props, state);
210
212
  const symbolState = symbolStateFromNewProps(props, state);
@@ -403,7 +405,7 @@ export const toProperties = (props, state, onChange) => ({
403
405
  },
404
406
  stackedDimension: {
405
407
  id: 'stackedDimension',
406
- isActive: isStacked(props.type),
408
+ isActive: isStackedDimActive(props),
407
409
  options: chartDimensionOptions(props, isStacked),
408
410
  onChange: R.pipe(
409
411
  optionParser,
@@ -6,6 +6,7 @@ import {
6
6
  getPropertyDimension,
7
7
  toState
8
8
  } from './utils';
9
+ import { splitDimensions } from '../';
9
10
  import { focusStateFromNewProps } from './focus';
10
11
 
11
12
  const getStackedDimension = getPropertyDimension('stackedDimension');
@@ -38,6 +39,15 @@ export const onChangeStackedDimension = ({ data }, state) => (value) => {
38
39
 
39
40
  export const stackedModeOptions = [{ value: VALUES }, { value: PERCENT }];
40
41
 
42
+ export const isStackedDimActive = ({ data, type }) => {
43
+ const { values } = splitDimensions(data);
44
+ if (R.length(values) < 2) {
45
+ console.log('niet');
46
+ return false;
47
+ }
48
+ return isStacked(type);
49
+ };
50
+
41
51
  export const onChangeStackedMode = (value) => R.has(value, stackedModes)
42
52
  ? ({ stackedMode: value })
43
53
  : ({});
@@ -54,15 +64,21 @@ export const stackedStateFromNewProps = (props, state) => {
54
64
 
55
65
  let dimension = getStackedDimension(data, state);
56
66
  if (R.isNil(dimension)) {
57
- const { area, time, other } = getGroupedDimensions(data);
58
- if (!R.isNil(area) && !R.isEmpty(area)) {
59
- dimension = R.head(area);
60
- }
61
- else if (!R.isNil(time) && !R.isEmpty(time)) {
62
- dimension = R.head(time)
67
+ const { value, values } = splitDimensions(data);
68
+ if (R.length(values) === 1) {
69
+ dimension = R.head(value);
63
70
  }
64
71
  else {
65
- dimension = R.head(other);
72
+ const { area, time, other } = getGroupedDimensions(data);
73
+ if (!R.isNil(area) && !R.isEmpty(area)) {
74
+ dimension = R.head(area);
75
+ }
76
+ else if (!R.isNil(time) && !R.isEmpty(time)) {
77
+ dimension = R.head(time)
78
+ }
79
+ else {
80
+ dimension = R.head(other);
81
+ }
66
82
  }
67
83
  }
68
84
  const _mode = R.prop('stackedMode', state);
@@ -1,10 +1,12 @@
1
1
  import {
2
- groupBy,
2
+ equals,
3
3
  find,
4
+ groupBy,
4
5
  has,
5
6
  head,
6
7
  is,
7
8
  isNil,
9
+ length,
8
10
  map,
9
11
  not,
10
12
  omit,
@@ -15,7 +17,7 @@ import {
15
17
  } from 'ramda';
16
18
  import { isRefAreaDimension, isTimePeriodDimension } from '@sis-cc/dotstatsuite-sdmxjs';
17
19
  import { extractSdmxArtefacts, parseDisplay, splitDimensions } from '../';
18
- import { CHORO, H_SYMBOL, SCATTER, TYPES, V_SYMBOL } from '../constants';
20
+ import { CHORO, H_SYMBOL, SCATTER, STACKED, TYPES, V_SYMBOL } from '../constants';
19
21
  import { dimensionValueDisplay } from '../dimension-utils';
20
22
 
21
23
  export const isNumber = (input) => {
@@ -44,7 +46,7 @@ export const toState = (artefact) => prop('id', artefact);
44
46
 
45
47
  export const getPropertyDimension = (property) => (data, state) => {
46
48
  const statePropertyDimensionId = prop(property, state);
47
- const dimensions = getDimensionsWithValues(data);
49
+ const { dimensions } = extractSdmxArtefacts(data);
48
50
  return find(
49
51
  propEq('id', statePropertyDimensionId),
50
52
  dimensions
@@ -99,6 +101,9 @@ export const chartDimensionOptions = ({ data, type, display }, typeValidator) =>
99
101
  return [];
100
102
  }
101
103
  const dimensions = prop('values', splitDimensions(data));
104
+ if (equals(type, STACKED) && length(dimensions) === 1) {
105
+ return [];
106
+ }
102
107
  return map(
103
108
  artefactToOption(display),
104
109
  dimensions
@@ -1,139 +1,123 @@
1
- import React, { Component } from 'react';
2
- import { render } from 'react-dom';
3
- import { Button } from '@blueprintjs/core';
4
- import '@blueprintjs/core/dist/blueprint.css';
5
- import { find, prop, propEq } from 'ramda';
1
+ import React, { useState } from 'react';
2
+ import * as R from 'ramda';
3
+ import { ChartsConfig } from '@sis-cc/dotstatsuite-visions';
6
4
  import RulesDriver from './';
7
- import oecdData from './mocks/oecd.json';
8
- import oecdTimeData from './mocks/oecd-time.json';
9
- import Menu from './app/menu';
10
- import Viewer1 from './app/viewer1';
11
- import Viewer2 from './app/viewer2';
5
+ import data1 from './mocks/data1.json';
6
+ import data2 from './mocks/data2.json';
7
+ import { Viewer } from '../../';
12
8
 
13
- export default class App extends Component {
14
- constructor(props) {
15
- super(props);
16
-
17
- this.availableDatas = { oecdData, oecdTimeData };
18
-
19
- this.sources = [
20
- { label: 'oecd', value: 'oecdData', dataflowCode: 'KEI' },
21
- { label: 'oecd quarter', value: 'oecdTimeData', dataflowCode: 'KEI' }
22
- ];
23
-
24
- this.chartTypes = [
25
- { label: 'Bar', value: 'BarChart' },
26
- { label: 'Row', value: 'RowChart' },
27
- { label: 'Scatter', value: 'ScatterChart' },
28
- { label: 'Timeline', value: 'TimelineChart' },
29
- { label: 'H Symbol', value: 'HorizontalSymbolChart' },
30
- { label: 'V Symbol', value: 'VerticalSymbolChart' },
31
- { label: 'Stacked Bar', value: 'StackedBarChart' },
32
- { label: 'Non Chart Type', value: 'NonChartType' }
33
- ];
34
-
35
- this.viewerOptions = [
36
- { label: 'Old Classic OCC View', value: 'Viewer1' },
37
- { label: 'Alternative Split', value: 'Viewer2' },
38
- ];
39
-
40
- this.viewers = {
41
- Viewer1,
42
- Viewer2,
43
- };
44
-
45
- this.state = {
46
- data: oecdData,
47
- display: 'label',
48
- source: 'oecdData',
49
- type: 'BarChart',
50
- viewer: 'Viewer1',
51
- };
52
-
53
- this.onChangeData = this.onChangeData.bind(this);
54
- this.onChangeType = this.onChangeType.bind(this);
55
- this.onChangeViewer = this.onChangeViewer.bind(this);
56
- this.onChangeDisplay = this.onChangeDisplay.bind(this);
57
- };
58
-
59
- onChangeData(source) {
60
- this.setState({ data: this.availableDatas[source], source });
61
- };
62
-
63
- onChangeType(type) {
64
- this.setState({ type });
9
+ const labels = {
10
+ focus: 'Chart Focus',
11
+ highlight: 'Highlights',
12
+ baseline: 'Baseline',
13
+ select: 'Select',
14
+ size: 'Chart Size',
15
+ width: 'Width',
16
+ height: 'Height',
17
+ series: 'Chart Series',
18
+ scatterDimension: 'Scatter Dimension',
19
+ scatterX: 'Scatter X',
20
+ scatterY: 'Scatter Y',
21
+ symbolDimension: 'Symbol Dimension',
22
+ stackedDimension: 'Stacked Dimension',
23
+ stackedMode: 'Stacked Mode',
24
+ stackedModeOptions: {
25
+ values: 'Values',
26
+ percent: 'Percent',
27
+ },
28
+ axisX: 'Chart X Axis',
29
+ axisY: 'Chart Y Axis',
30
+ max: 'Max',
31
+ min: 'Min',
32
+ pivot: 'Pivot',
33
+ step: 'Step',
34
+ frequency: 'Frequency',
35
+ freqStep: 'Frequency Step',
36
+ logo: 'Remove logo',
37
+ copyright: 'Remove copyright',
38
+ title: 'Title',
39
+ subtitle: 'Subtitle',
40
+ source: 'Source',
41
+ information: 'Information',
42
+ reset: 'reset label',
43
+ uniqFocusOption: 'serie',
44
+ display: 'Display',
45
+ displayOptions: {
46
+ name: 'Name',
47
+ code: 'Code',
48
+ both: 'Both'
65
49
  }
50
+ };
66
51
 
67
- onChangeViewer(viewer) {
68
- this.setState({ viewer });
69
- }
52
+ const renameKey = R.curry((oldKey, newKey, obj) =>
53
+ R.assoc(newKey, R.prop(oldKey, obj), R.dissoc(oldKey, obj)),
54
+ );
70
55
 
71
- onChangeDisplay(display) {
72
- this.setState({ display });
73
- }
56
+ const renameProperties = (keys = []) =>
57
+ R.map(
58
+ R.ifElse(
59
+ R.pipe(R.prop('id'), R.flip(R.includes)(keys)),
60
+ renameKey('onChange', 'onSubmit'),
61
+ R.identity,
62
+ ),
63
+ );
64
+
65
+ const propertiesKeys = [
66
+ 'width',
67
+ 'height',
68
+ 'freqStep',
69
+ 'maxX',
70
+ 'minX',
71
+ 'pivotX',
72
+ 'stepX',
73
+ 'maxY',
74
+ 'minY',
75
+ 'pivotY',
76
+ 'stepY',
77
+ 'title',
78
+ 'subtitle',
79
+ 'source',
80
+ ];
74
81
 
75
- render() {
76
- const { data, source, type, viewer, display } = this.state;
77
- const displayOptions = [
78
- { label: 'label', value: 'label' },
79
- { label: 'code', value: 'code' },
80
- { label: 'both', value: 'both' }
81
- ];
82
- const displayProperties = {
83
- display: {
84
- isActive: true,
85
- label: 'Display as',
86
- onChange: this.onChangeDisplay,
87
- options: displayOptions,
88
- value: display,
89
- }
90
- };
91
- const dataflowCode = prop('dataflowCode', find(propEq('value', this.state.source), this.sources));
92
- const Viewer = this.viewers[viewer];
93
- return (
94
- <div>
95
- <nav className="pt-navbar pt-dark">
96
- <Menu
97
- align="left"
98
- items={this.viewerOptions}
99
- onChange={this.onChangeViewer}
100
- selected={viewer}
101
- />
102
- <span className="pt-navbar-divider"></span>
103
- <Menu
104
- align="right"
105
- items={this.chartTypes}
106
- onChange={this.onChangeType}
107
- selected={type}
108
- />
109
- <span className="pt-navbar-divider"></span>
110
- <Menu
111
- align="right"
112
- iconName="import"
113
- items={this.sources}
114
- onChange={this.onChangeData}
115
- selected={source}
116
- />
117
- </nav>
118
- <RulesDriver
119
- data={data}
120
- dataflowCode={dataflowCode}
121
- display={display}
122
- options={{ base: { height: 500 } }}
123
- type={type}
124
- render={
125
- ({ chartData, chartOptions, onChange, properties }) => (
126
- <Viewer
127
- chartData={chartData}
128
- chartOptions={chartOptions}
129
- onChange={onChange}
130
- properties={{ ...properties, ...displayProperties }}
131
- type={type}
132
- />
133
- )
82
+ const App = () => {
83
+ const [toggle, setToggle] = useState(true);
84
+ const dataflow = { id: "DF_KEI_21760", name: "Harmonised Unemployment Rate" };
85
+ const display = 'label';
86
+ const type = 'BarChart';
87
+ const props = { dataflow, display, type }
88
+
89
+ return (
90
+ <div>
91
+ <button onClick={() => setToggle(prev => !prev)} style={{ marginBottom: '10px' }}>Toggle Selection</button>
92
+ <RulesDriver
93
+ data={toggle ? data1 : data2}
94
+ {...props}
95
+ display={display}
96
+ type={type}
97
+ render={
98
+ ({ properties, ...parsedProps }) => {
99
+ return (
100
+ <div>
101
+ <ChartsConfig
102
+ properties={R.pipe(
103
+ renameProperties(propertiesKeys),
104
+ )(properties)}
105
+ labels={labels}
106
+ />
107
+ <Viewer
108
+ {...parsedProps}
109
+ chartData={R.pick(['series', 'frequency'])(parsedProps.chartData)}
110
+ properties={R.tap(console.log)(R.over(R.lensProp('baseline'), R.omit(['onChange']), properties))}
111
+ type='BarChart'
112
+ locale='en'
113
+ />
114
+ </div>
115
+ );
134
116
  }
135
- />
136
- </div>
137
- );
138
- };
139
- };
117
+ }
118
+ />
119
+ </div>
120
+ )
121
+ }
122
+
123
+ export default App;