@cdc/editor 1.4.2 → 1.4.4

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.
@@ -1,5 +1,5 @@
1
1
  STATE,Rate,Location,URL
2
- Alabama,30,Vehicle,https://www.cdc.gov/
2
+ Alabama,130,Vehicle,https://www.cdc.gov/
3
3
  Alaska,40,Work,https://www.cdc.gov/
4
4
  American Samoa,55,Home,https://www.cdc.gov/
5
5
  Arizona,57,School,https://www.cdc.gov/
@@ -56,4 +56,4 @@ Virgin Islands,55,School,https://www.cdc.gov/
56
56
  Virginia,57,School,https://www.cdc.gov/
57
57
  Washington,62,Work,https://www.cdc.gov/
58
58
  West Virginia,25,Vehicle,https://www.cdc.gov/
59
- Wyoming,43,Vehicle,https://www.cdc.gov/
59
+ Wyoming,43,Vehicle,https://www.cdc.gov/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdc/editor",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "main": "dist/cdceditor",
5
5
  "bugs": {
6
6
  "url": "https://github.com/CDCgov/cdc-open-viz/issues"
@@ -16,16 +16,18 @@
16
16
  "build": "npx webpack --mode production --env packageName=CdcEditor --env folderName=editor -c ../../webpack.config.js",
17
17
  "prepublishOnly": "lerna run --scope @cdc/editor build"
18
18
  },
19
- "devDependencies": {
19
+ "dependencies": {
20
20
  "@babel/runtime": "^7.12.5",
21
- "@cdc/chart": "^1.3.2",
22
- "@cdc/core": "^1.1.2",
23
- "@cdc/dashboard": "^1.1.2",
24
- "@cdc/data-bite": "^1.1.2",
25
- "@cdc/map": "^2.6.2",
21
+ "@cdc/chart": "^1.3.4",
22
+ "@cdc/core": "^1.1.4",
23
+ "@cdc/dashboard": "^1.1.4",
24
+ "@cdc/data-bite": "^1.1.4",
25
+ "@cdc/map": "^2.6.4",
26
+ "@cdc/markup-include": "^1.0.2",
27
+ "@cdc/waffle-chart": "^1.0.2",
26
28
  "axios": "^0.21.1",
27
29
  "d3": "^7.0.0",
28
- "html-react-parser": "^0.14.0",
30
+ "html-react-parser": "1.4.9",
29
31
  "react-dropzone": "^11.2.4",
30
32
  "react-table": "^7.6.2",
31
33
  "use-debounce": "^5.2.0",
@@ -35,5 +37,8 @@
35
37
  "react": ">=16.8",
36
38
  "react-dom": ">=16"
37
39
  },
38
- "gitHead": "8790a2336ff2453d0d6f09ecec56b5e4beaa7377"
40
+ "resolutions": {
41
+ "@types/react": "17.x"
42
+ },
43
+ "gitHead": "ff89a7aea74c533413c62ef8859cc011e6b3cbfa"
39
44
  }
package/src/CdcEditor.js CHANGED
@@ -6,7 +6,11 @@ import ResizeObserver from 'resize-observer-polyfill'
6
6
 
7
7
  import getViewport from '@cdc/core/helpers/getViewport';
8
8
 
9
+ import { GlobalContextProvider } from '@cdc/core/components/GlobalContext'
9
10
  import GlobalState from './context';
11
+
12
+ import OverlayFrame from '@cdc/core/components/ui/OverlayFrame'
13
+
10
14
  import DataImport from './components/DataImport';
11
15
  import ChooseTab from './components/ChooseTab';
12
16
  import ConfigureTab from './components/ConfigureTab';
@@ -15,7 +19,7 @@ import Tabs from './components/Tabs';
15
19
 
16
20
  import './scss/main.scss';
17
21
 
18
- export default function CdcEditor({ config: configObj = {newViz: true}, hostname }) {
22
+ export default function CdcEditor({ config: configObj = {newViz: true}, hostname, containerEl, sharepath }) {
19
23
  const [config, setConfig] = useState(configObj)
20
24
  const [tempConfig, setTempConfig] = useState(null)
21
25
  const [errors, setErrors] = useState([])
@@ -50,7 +54,7 @@ export default function CdcEditor({ config: configObj = {newViz: true}, hostname
50
54
  if(null !== tempConfig) {
51
55
  const parsedData = JSON.stringify(tempConfig)
52
56
  // Emit the data in a regular JS event so it can be consumed by anything.
53
- const event = new CustomEvent('updateVizConfig', { detail: parsedData})
57
+ const event = new CustomEvent('updateVizConfig', { detail: parsedData, bubbles: true })
54
58
  window.dispatchEvent(event)
55
59
  }
56
60
  }, [tempConfig])
@@ -93,24 +97,28 @@ export default function CdcEditor({ config: configObj = {newViz: true}, hostname
93
97
  globalActive,
94
98
  setGlobalActive,
95
99
  tempConfig,
96
- setTempConfig
100
+ setTempConfig,
101
+ sharepath
97
102
  }
98
103
 
99
104
  return (
100
- <GlobalState.Provider value={state}>
101
- <div className={`cdc-open-viz-module cdc-editor ${currentViewport}`} ref={outerContainerRef}>
102
- <Tabs className="top-level" startingTab={globalActive}>
103
- <TabPane title="1. Import Data" className="data-designer">
104
- <DataImport />
105
- </TabPane>
106
- <TabPane title="2. Choose Visualization Type" className="choose-type" disableRule={!config.data && !config.formattedData}>
107
- <ChooseTab />
108
- </TabPane>
109
- <TabPane title="3. Configure" className="configure" disableRule={null === config.data || !config.type}>
110
- <ConfigureTab />
111
- </TabPane>
112
- </Tabs>
113
- </div>
114
- </GlobalState.Provider>
105
+ <GlobalContextProvider>
106
+ <GlobalState.Provider value={state}>
107
+ <div className={`cdc-open-viz-module cdc-editor ${currentViewport}`} ref={outerContainerRef} >
108
+ <Tabs className="top-level" startingTab={globalActive}>
109
+ <TabPane title="1. Import Data" className="data-designer">
110
+ <DataImport />
111
+ </TabPane>
112
+ <TabPane title="2. Choose Visualization Type" className="choose-type" disableRule={!config.data && !config.formattedData}>
113
+ <ChooseTab />
114
+ </TabPane>
115
+ <TabPane title="3. Configure" className="configure" disableRule={null === config.data || !config.type}>
116
+ <ConfigureTab containerEl={containerEl }/>
117
+ </TabPane>
118
+ </Tabs>
119
+ </div>
120
+ </GlobalState.Provider>
121
+ <OverlayFrame/>
122
+ </GlobalContextProvider>
115
123
  );
116
124
  }
@@ -1,94 +1,243 @@
1
- import React, { useContext, useEffect } from 'react';
2
- import '../scss/choose-vis-tab.scss';
1
+ import React, { useContext, useEffect } from 'react'
2
+ import '../scss/choose-vis-tab.scss'
3
3
 
4
- import GlobalState from '../context';
4
+ import GlobalState from '../context'
5
+ import Tooltip from '@cdc/core/components/ui/Tooltip'
5
6
 
6
- import DashboardIcon from '../assets/icons/dashboard.svg';
7
- import BarIcon from '@cdc/core/assets/chart-bar-solid.svg';
8
- import LineIcon from '@cdc/core/assets/chart-line-solid.svg';
9
- import PieIcon from '@cdc/core/assets/chart-pie-solid.svg';
10
- import GlobeIcon from '@cdc/core/assets/world-graphic.svg';
11
- import UsaIcon from '@cdc/core/assets/usa-graphic.svg';
12
- import DataBiteIcon from '@cdc/core/assets/data-bite-graphic.svg';
7
+ import DashboardIcon from '../assets/icons/dashboard.svg'
8
+ import BarIcon from '@cdc/core/assets/chart-bar-solid.svg'
9
+ import LineIcon from '@cdc/core/assets/chart-line-solid.svg'
10
+ import PieIcon from '@cdc/core/assets/chart-pie-solid.svg'
11
+ import GlobeIcon from '@cdc/core/assets/world-graphic.svg'
12
+ import UsaIcon from '@cdc/core/assets/usa-graphic.svg'
13
+ import UsaRegionIcon from '@cdc/core/assets/usa-region-graphic.svg'
14
+ import DataBiteIcon from '@cdc/core/assets/data-bite-graphic.svg'
15
+ import WaffleChartIcon from '@cdc/core/assets/icon-grid.svg'
16
+ import MarkupIncludeIcon from '@cdc/core/assets/icon-code.svg'
17
+ import AlabamaGraphic from '@cdc/core/assets/alabama-graphic.svg'
18
+ import PairedBarIcon from '@cdc/core/assets/paired-bar.svg'
19
+ import HorizontalStackIcon from '@cdc/core/assets/horizontal-stacked-bar.svg'
13
20
 
14
21
  export default function ChooseTab() {
15
- const {config, setConfig, setGlobalActive, tempConfig, setTempConfig} = useContext(GlobalState);
22
+ const { config, setConfig, setGlobalActive, tempConfig, setTempConfig } = useContext(GlobalState)
16
23
 
17
- useEffect(() => {
18
- if(tempConfig !== null) {
19
- setConfig(tempConfig)
20
- setTempConfig(null)
21
- }
22
- })
24
+ useEffect(() => {
25
+ if (tempConfig !== null) {
26
+ setConfig(tempConfig)
27
+ setTempConfig(null)
28
+ }
29
+ })
23
30
 
24
- /**
25
- * IconButton component
26
- */
27
- const IconButton = ({icon, label, type, subType}) => {
28
- let isSubType = false
31
+ /**
32
+ * IconButton component
33
+ */
34
+ const IconButton = ({ icon, label, type, subType, barType, orientation, stacked = false }) => {
35
+ let isSubType = false
36
+ let isHorizontalStackedChart = false
37
+ let classNames;
29
38
 
30
- if(type === 'map' && config.general) {
31
- let geoType = config.general.geoType
32
- isSubType = (subType === geoType)
33
- }
39
+ if (type === 'map' && config.general) {
40
+ let geoType = config.general.geoType
41
+ isSubType = (subType === geoType)
42
+ }
34
43
 
35
- if(type === 'chart') {
36
- isSubType = (subType === config.visualizationType)
37
- }
44
+ if (type === 'chart') {
45
+ isSubType = (subType === config.visualizationType)
46
+ isHorizontalStackedChart = (orientation === config.orientation && stacked === true)
47
+ }
48
+
49
+ if (type === 'dashboard' || type === 'data-bite' || type === 'waffle-chart' || type === 'markup-include') isSubType = true
50
+
51
+ // TODO: sorry, we should refactor this at some point.
52
+ // trying to get this out for 4.22.5 - this is so stacked horizontal and bar charts aren't highlighted at the same time.
53
+ // this functionality appears to be working but is admittedly confusing.
54
+ if(type === 'chart' && stacked) {
55
+ classNames = (config.type === type && isSubType && config.visualizationSubType === 'stacked') ? 'active' : ''
56
+ } else if (type === 'chart' && !stacked && config.visualizationSubType !== 'stacked') {
57
+ classNames = (config.type === type && isSubType ) ? 'active' : ''
58
+ }
38
59
 
39
- if(type === 'dashboard' || type === 'data-bite') isSubType = true;
40
-
41
- let classNames = (config.type === type && isSubType) ? 'active' : ''
42
-
43
- let setTypes = () => {
44
- // Only take the data/data source properties from existing config. Covers case of selecting a new visualization.
45
- let newConfig = {
46
- data: [...config.data],
47
- dataFileName: config.dataFileName,
48
- dataFileSourceType: config.dataFileSourceType,
49
- dataDescription: config.dataDescription,
50
- newViz: true,
51
- type
52
- }
53
-
54
- if(config.formattedData) {
55
- newConfig.formattedData = config.formattedData
56
- }
57
-
58
- if(type === 'map') {
59
- newConfig.general = {
60
- ...newConfig.general,
61
- geoType: subType
62
- }
63
- } else {
64
- newConfig.visualizationType = subType
65
- }
66
-
67
- setConfig(newConfig)
68
- setGlobalActive(2)
60
+ if(type !== 'chart') {
61
+ classNames = (config.type === type && isSubType && !isHorizontalStackedChart) ? 'active' : ''
62
+ }
63
+
64
+
65
+ let setTypes = () => {
66
+ // Only take the data/data source properties from existing config. Covers case of selecting a new visualization.
67
+ let newConfig = {
68
+ data: [ ...config.data ],
69
+ dataFileName: config.dataFileName,
70
+ dataFileSourceType: config.dataFileSourceType,
71
+ dataDescription: config.dataDescription,
72
+ dataUrl: config.dataUrl,
73
+ newViz: true,
74
+ type,
75
+ orientation: orientation ? orientation : null,
76
+ visualizationSubType: label === 'Horizontal Bar (Stacked)' ? 'stacked' : null
77
+ }
78
+
79
+ if (config.formattedData) {
80
+ newConfig.formattedData = config.formattedData
81
+ }
82
+
83
+ if (type === 'map') {
84
+ newConfig.general = {
85
+ ...newConfig.general,
86
+ geoType: subType
69
87
  }
88
+ } else {
89
+ newConfig.visualizationType = subType
90
+ }
70
91
 
71
- return (<button className={classNames} onClick={() => setTypes()} aria-label={label}>{icon}<span className="mt-1">{label}</span></button>)
92
+ setConfig(newConfig)
93
+ setGlobalActive(2)
72
94
  }
73
95
 
74
- return (
75
- <div className="choose-vis">
76
- <div className="heading-2">General</div>
77
- <ul className="grid">
78
- <li><IconButton label="Dashboard" type="dashboard" icon={ <DashboardIcon /> } /></li>
79
- <li><IconButton label="Data Bite" type="data-bite" icon={ <DataBiteIcon /> } /></li>
80
- </ul>
81
- <div className="heading-2">Charts</div>
82
- <ul className="grid">
83
- <li><IconButton label="Bar" type="chart" subType="Bar" icon={ <BarIcon /> } /></li>
84
- <li><IconButton label="Line" type="chart" subType="Line" icon={ <LineIcon /> } /></li>
85
- <li><IconButton label="Pie" type="chart" subType="Pie" icon={ <PieIcon /> } /></li>
86
- </ul>
87
- <div className="heading-2">Maps</div>
88
- <ul className="grid">
89
- <li><IconButton label="United States" type="map" subType="us" icon={ <UsaIcon /> } /></li>
90
- <li><IconButton label="World" type="map" subType="world" icon={ <GlobeIcon /> } /></li>
91
- </ul>
96
+ return (<button className={classNames} onClick={() => setTypes()} aria-label={label}>{icon}<span
97
+ className="mt-1">{label}</span></button>)
98
+ }
99
+
100
+ return (
101
+ <div className="choose-vis">
102
+ <a href="https://www.cdc.gov/wcms/4.0/cdc-wp/data-presentation/index.html" target="_blank"
103
+ rel="noopener noreferrer" className="guidance-link" style={{marginTop: 0, marginBottom: "2rem"}}>
104
+ <div>
105
+ <p>For more information on the types of data visualizations in the WCMS, including examples and best practices, <u>see the WCMS Features Gallery</u>.</p>
92
106
  </div>
93
- )
107
+ </a>
108
+
109
+ <div className="heading-2">General</div>
110
+ <ul className="grid cove-temp"> {/*TODO: Remove cove class during refactor to Wizard*/}
111
+ <li>
112
+ <Tooltip position="right">
113
+ <Tooltip.Target>
114
+ <IconButton label="Dashboard" type="dashboard" icon={<DashboardIcon/>}/>
115
+ </Tooltip.Target>
116
+ <Tooltip.Content>
117
+ Present multiple data visualizations with shared filter controls.
118
+ </Tooltip.Content>
119
+ </Tooltip>
120
+ </li>
121
+ <li>
122
+ <Tooltip>
123
+ <Tooltip.Target>
124
+ <IconButton label="Data Bite" type="data-bite" icon={<DataBiteIcon/>}/>
125
+ </Tooltip.Target>
126
+ <Tooltip.Content>
127
+ Highlight a single aggregated value (e.g., sum or median).
128
+ </Tooltip.Content>
129
+ </Tooltip>
130
+ </li>
131
+ <li>
132
+ <Tooltip>
133
+ <Tooltip.Target>
134
+ <IconButton label="Waffle Chart" type="waffle-chart" icon={<WaffleChartIcon/>}/>
135
+ </Tooltip.Target>
136
+ <Tooltip.Content>
137
+ Highlight a piece of data in relationship to a data set.
138
+ </Tooltip.Content>
139
+ </Tooltip>
140
+ </li>
141
+ </ul>
142
+
143
+ <div className="heading-2">Charts</div>
144
+ <ul className="grid cove-temp">
145
+ <li>
146
+ <Tooltip position="right">
147
+ <Tooltip.Target>
148
+ <IconButton label="Bar" type="chart" subType="Bar" orientation="vertical" icon={<BarIcon/>}/>
149
+ </Tooltip.Target>
150
+ <Tooltip.Content>
151
+ Use bars to show comparisons between data categories.
152
+ </Tooltip.Content>
153
+ </Tooltip>
154
+ </li>
155
+ <li>
156
+ <Tooltip>
157
+ <Tooltip.Target>
158
+ <IconButton label="Line" type="chart" subType="Line" orientation="vertical" icon={<LineIcon/>}/>
159
+ </Tooltip.Target>
160
+ <Tooltip.Content>
161
+ Present one or more data trends over time.
162
+ </Tooltip.Content>
163
+ </Tooltip>
164
+ </li>
165
+ <li>
166
+ <Tooltip>
167
+ <Tooltip.Target>
168
+ <IconButton label="Pie" type="chart" subType="Pie" orientation="vertical" icon={<PieIcon/>}/>
169
+ </Tooltip.Target>
170
+ <Tooltip.Content>
171
+ Present the numerical proportions of a data series.
172
+ </Tooltip.Content>
173
+ </Tooltip>
174
+ </li>
175
+ <li>
176
+ <Tooltip>
177
+ <Tooltip.Target>
178
+ <IconButton label="Paired Bar" type="chart" subType="Paired Bar" orientation="horizontal" icon={<PairedBarIcon/>}/>
179
+ </Tooltip.Target>
180
+ <Tooltip.Content>
181
+ Use paired bars to show comparisons between two different data categories.
182
+ </Tooltip.Content>
183
+ </Tooltip>
184
+ </li>
185
+ <li>
186
+ <Tooltip>
187
+ <Tooltip.Target>
188
+ <IconButton label="Horizontal Bar (Stacked)" type="chart" subType="Bar" orientation="horizontal" stacked={true}
189
+ icon={<HorizontalStackIcon/>}/>
190
+ </Tooltip.Target>
191
+ <Tooltip.Content>
192
+ Use bars to show comparisons between data categories.
193
+ </Tooltip.Content>
194
+ </Tooltip>
195
+ </li>
196
+ </ul>
197
+
198
+ <div className="heading-2">Maps</div>
199
+ <ul className="grid cove-temp">
200
+ <li>
201
+ <Tooltip position="right">
202
+ <Tooltip.Target>
203
+ <IconButton label="United States (State- or County-Level)" type="map" subType="us" icon={<UsaIcon/>}/>
204
+ </Tooltip.Target>
205
+ <Tooltip.Content>
206
+ Present a U.S. choropleth map at state or county level.
207
+ </Tooltip.Content>
208
+ </Tooltip>
209
+ </li>
210
+ <li>
211
+ <Tooltip position="right">
212
+ <Tooltip.Target>
213
+ <IconButton label="United States (HHS Regions)" type="map" subType="us-region" icon={<UsaRegionIcon/>}/>
214
+ </Tooltip.Target>
215
+ <Tooltip.Content>
216
+ Present a U.S. choropleth map at state or county level.
217
+ </Tooltip.Content>
218
+ </Tooltip>
219
+ </li>
220
+ <li>
221
+ <Tooltip>
222
+ <Tooltip.Target>
223
+ <IconButton label="World" type="map" subType="world" icon={<GlobeIcon/>}/>
224
+ </Tooltip.Target>
225
+ <Tooltip.Content>
226
+ Present a choropleth map of the world.
227
+ </Tooltip.Content>
228
+ </Tooltip>
229
+ </li>
230
+ <li>
231
+ <Tooltip>
232
+ <Tooltip.Target>
233
+ <IconButton label="U.S. State" type="map" subType="single-state" icon={<AlabamaGraphic/>}/>
234
+ </Tooltip.Target>
235
+ <Tooltip.Content>
236
+ Present a choropleth map of an individual U.S. state.
237
+ </Tooltip.Content>
238
+ </Tooltip>
239
+ </li>
240
+ </ul>
241
+ </div>
242
+ )
94
243
  }
@@ -4,13 +4,15 @@ import CdcDashboard from '@cdc/dashboard'; // TODO: Lazy load this
4
4
  import CdcMap from '@cdc/map'; // TODO: Lazy load this
5
5
  import CdcChart from '@cdc/chart'; // TODO: Lazy load this
6
6
  import CdcDataBite from '@cdc/data-bite';
7
+ import CdcWaffleChart from '@cdc/waffle-chart'
8
+ import CdcMarkupInclude from '@cdc/markup-include'
7
9
 
8
10
  import '../scss/configure-tab.scss';
9
11
 
10
12
  import ErrorBoundary from '@cdc/core/components/ErrorBoundary';
11
13
  import GlobalState from '../context';
12
14
 
13
- export default function ConfigureTab() {
15
+ export default function ConfigureTab({containerEl}) {
14
16
  const { config, setTempConfig, hostname } = useContext(GlobalState);
15
17
 
16
18
  let { type } = config
@@ -19,7 +21,7 @@ export default function ConfigureTab() {
19
21
  case 'map':
20
22
  return (
21
23
  <ErrorBoundary component="CdcMap">
22
- <CdcMap isEditor={true} config={config} hostname={hostname} setConfig={setTempConfig} />
24
+ <CdcMap isEditor={true} config={config} hostname={hostname} setConfig={setTempConfig} containerEl={containerEl} />
23
25
  </ErrorBoundary>
24
26
  )
25
27
  case 'chart':
@@ -40,7 +42,19 @@ export default function ConfigureTab() {
40
42
  <CdcDataBite isEditor={true} config={config} setConfig={setTempConfig} />
41
43
  </ErrorBoundary>
42
44
  )
45
+ case 'waffle-chart':
46
+ return (
47
+ <ErrorBoundary component="CdcDashboard">
48
+ <CdcWaffleChart isEditor={true} config={config} setConfig={setTempConfig} />
49
+ </ErrorBoundary>
50
+ )
51
+ case 'markup-include':
52
+ return (
53
+ <ErrorBoundary component="CdcDashboard">
54
+ <CdcMarkupInclude isEditor={true} config={config} setConfig={setTempConfig} />
55
+ </ErrorBoundary>
56
+ )
43
57
  default:
44
58
  return <p>No visualization type selected.</p>
45
59
  }
46
- }
60
+ }