Skip to content

Commit 1fdd3da

Browse files
authored
Merge pull request #11 from zingchart/refactor-zingchart-dependency
Refactor zingchart dependency
2 parents dcb7189 + de02a21 commit 1fdd3da

19 files changed

+131
-1423
lines changed

.editorconfig

Lines changed: 0 additions & 5 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

README.md

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
1212

13-
![](https://d2ddoduugvun08.cloudfront.net/items/3D0r3t2z083W2K0m3t39/Screen%20Recording%202020-06-03%20at%2004.08%20PM.gif?X-CloudApp-Visitor-Id=3179966)
13+
![](https://d2ddoduugvun08.cloudfront.net/items/2u3R031j3O3M2A3c3V0w/Screen%20Recording%202020-06-04%20at%2002.24%20PM.gif?X-CloudApp-Visitor-Id=3179966)
14+
1415

1516
## Quickstart guide
1617

@@ -24,12 +25,24 @@ Install the `zingchart-vue` package via npm
2425

2526
`npm install zingchart-vue`
2627

28+
## 2. Include the `zinchart` package in your project
29+
30+
The `zingchart` package is a **DIRECT** dependency of `zingchart-vue` but you can also update this package outside of this component. Meaning the wrapper is no longer tied to a ZingChart library version, but just the component itself.
31+
32+
You can import the library like so:
33+
34+
```javascript
35+
// import the es6 version
36+
import 'zingchart/es6';
37+
```
2738

28-
## 2. Include the component in your project
39+
## 3. Include the component in your project
2940

30-
You can either include the `zingchart-vue` component to your project globally or locally per component. **DO NOT HAVE to import zingchart since it is a direct dependency of `zingchart-vue`**
41+
You can either include the `zingchart-vue` component to your project globally or locally per component. **Import the component AFTER ZingChart since it is a DIRECT dependency.**
3142

3243
```js
44+
// import the es6 version
45+
import 'zingchart/es6';
3346
// import the component AFTER ZingChart since it is a DIRECT dependency
3447
import zingchartVue from 'zingchart-vue';
3548
```
@@ -38,6 +51,24 @@ import zingchartVue from 'zingchart-vue';
3851

3952
In your main app file, add the following lines of code:
4053

54+
```js
55+
import Vue from 'vue';
56+
// import the es6 version
57+
import 'zingchart/es6';
58+
import zingchartVue from 'zingchart-vue';
59+
60+
// install globally to app
61+
Vue.component('zingchart', zingchartVue)
62+
```
63+
64+
This will register the zingchart component globally throughout your application. While the easiest installation option, this will load ZingChart immediately on your user's first load of the application - regardless if a chart is on the first page or not. We recommend this approach if ZingChart is used heavily across multiple pages.
65+
66+
67+
68+
### Globally and locally
69+
70+
You can also register the `zingChartVue` component globally and then import just `zingchart/es6` locally per each component that uses charts.
71+
4172
```js
4273
import Vue from 'vue';
4374
import zingchartVue from 'zingchart-vue';
@@ -46,14 +77,20 @@ import zingchartVue from 'zingchart-vue';
4677
Vue.component('zingchart', zingchartVue)
4778
```
4879

49-
This will register the zingchart component globally throughout your application. While the easiest installation option, this will load ZingChart immediately on your user's first load of the application - regardless if a chart is on the first page or not. We reccomend this approach if ZingChart is used heavily across multiple pages.
80+
Then inside the component you import the `zingchart/es6` library.
81+
82+
```js
83+
import 'zingchart/es6';
5084

85+
export default {...}
86+
```
5187

5288
### Locally per component
5389

5490
In each component where ZingChart is being used, include the following in your component's configuration:
5591

5692
```js
93+
import 'zingchart/es6';
5794
import zingchartVue from 'zingchart-vue';
5895

5996
{
@@ -74,10 +111,9 @@ ZingChart comes bundled with your common chart types such as line, column, pie,
74111
For example, adding a depth chart to your vue component will require an additional import. Note, you must import from the `modules-es6` directory in the zingchart package.
75112

76113
```js
114+
import 'zingchart/es6';
77115
// explicitly import the module
78116
import 'zingchart/modules-es6/zingchart-depth.min.js';
79-
...
80-
import zingchartVue from 'zingchart-vue';
81117
}
82118
```
83119

@@ -103,34 +139,33 @@ Here is a full .vue example for loading a map:
103139
</template>
104140
105141
<script>
142+
// import library
143+
import 'zingchart/es6';
144+
// import chart modules used on that page
106145
import 'zingchart/modules-es6/zingchart-maps.min.js';
107146
import 'zingchart/modules-es6/zingchart-maps-usa.min.js';
108147
109-
import zingchartVue from 'zingchart-vue';
110-
111148
export default {
112-
components: {
113-
zingchart: zingchartVue,
114-
},
149+
...
115150
}
116151
</script>
117152
```
118153

119154

120-
### `ZC` and `zingchart` Global Objects
155+
### `zingchart` Global Objects
121156

122-
If you need access to the `window.ZC` and `window.zingchart` objects we have
123-
exported those as well. Here is how to import them.
157+
If you need access to the `window.zingchart` objects for licensing or development flags.
124158

125159
```javascript
126-
import {default as zingchartVue, ZC, zingchart} from 'zingchart-vue';
160+
import zingchart from 'zingchart/es6';
161+
import zingchartVue from 'zingchart-vue';
127162

128163
// zingchart object for performance flags
129164
zingchart.DEV.KEEPSOURCE = 0; // prevents lib from storing the original data package
130165
zingchart.DEV.COPYDATA = 0; // prevents lib from creating a copy of the data package
131166

132167
// ZC object for license key
133-
ZC.LICENSEKEY = ['abcdefghijklmnopqrstuvwxy'];
168+
zingchart.LICENSE = ['abcdefghijklmnopqrstuvwxy'];
134169

135170
export default {
136171
components: {
@@ -139,6 +174,7 @@ export default {
139174
}
140175
```
141176

177+
142178
## Usage
143179

144180
The `zingchart-vue` component can be included into template as an element. Below is a simple example of a line chart:
@@ -197,13 +233,12 @@ The configuration object to pass to the chart. This can be a `graphset` object (
197233

198234
### `series` [array] (optional)
199235

200-
Accepts an array of series objects, and overrides a series if it was supplied into the config object. Varies by chart type used - Refer to the ZingChart documentation for more details.
236+
Accepts an array of series objects, and overrides a series if it was supplied into the config object. Varries by chart type used - Refer to the ZingChart documentation for more details.
201237

202238
### `id` [string] (optional)
203239

204240
The id for the DOM element for ZingChart to attach to. If no id is specified, the id will be autogenerated in the form of zingchart-auto-#
205241

206-
207242
### `output` [string] (optional)
208243

209244
The render type of the chart. **The default is `svg`** but you can also pass the string `canvas` to render the charts in canvas.

ZingChart.vue

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
</template>
44

55
<script>
6-
// Import the zingchart library to be used globally.
7-
import zingchart from 'zingchart/es6';
6+
// Import the zingchart library to be used globally (MUST BE DONE EXPLICITLY BEFORE THIS COMPONENT)
7+
// import zingchart from 'zingchart/es6';
8+
9+
// import constants that define methods, events and default rendering parameters
810
import constants from 'zingchart-constants';
911
const { DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_OUTPUT, EVENT_NAMES, METHOD_NAMES } = constants;
1012
13+
console.log(constants);
14+
1115
// One time setup globally to handle all zingchart-vue objects in the app space.
1216
if (!window.ZCVUE) {
1317
window.ZCVUE = {
@@ -136,10 +140,4 @@ export default {
136140
width: function() { this.resize() },
137141
}
138142
};
139-
140-
// assign window level constants to local vars for export
141-
let ZC = window.ZC;
142-
143-
// export ZingChart react class, ZC and zingchart window objects
144-
export {ZC, zingchart};
145143
</script>

dist/zingchartVue.common.js

Lines changed: 7 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/zingchartVue.common.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/zingchartVue.umd.js

Lines changed: 7 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/zingchartVue.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/zingchartVue.umd.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/zingchartVue.umd.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)