Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/v2.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
adarshlilha committed Dec 2, 2019
2 parents 675d359 + 58ec694 commit 0b6712a
Show file tree
Hide file tree
Showing 47 changed files with 727 additions and 282 deletions.
19 changes: 19 additions & 0 deletions checklist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Checklist to release a new build to NPM:
* Clone the repository if needed
* Checkout develop branch and make sure develop branch is up-to-date with remote
* If git flow is not initialized yet, Run: git flow init
* Create a new release branch, Run: git flow release start <new_version_with_v_character>
* Delete all existing npm dependencies, Run: rm -rf node_modules package-lock.json
* Install dependencies again, Run: npm install
* Update package version with new release version in package.json
* Update LICENSE file if needed
* Update README.md file if needed
* Now, create a release-ready build, Run: npm run build
* Test the dist/* files if needed
* Now commit all the changes with this message: "Make a build and bump version"
* Then finish the release, Run: git flow release finish [-s] <new_version_with_v_character> and enter release notes
* Push all changes and tags to remote, Run: git push origin master && git push origin develop && git push origin --tags
* Edit the title of the released tag in Github
* When everything is fine, it's ready to release
* Checkout master branch
* Now if everything is fine, release it to npm, Run: npm publish
2 changes: 1 addition & 1 deletion dist/datamodel.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/datamodel.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<body>
<!-- <script src="./samples/sample-with-split.js"></script> -->
<script src="./samples/example3.js"></script>
<script src="./samples/example2.js"></script>
</body>

</html>
68 changes: 58 additions & 10 deletions example/samples/example2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,59 @@
const DataModel = window.DataModel.default;
// const DataModel = window.DataModel.default;
const columnMajor = (store) => {
let i = 0;
return (...fields) => {
fields.forEach((val, fieldIndex) => {
if (!(store[fieldIndex] instanceof Array)) {
store[fieldIndex] = Array.from({ length: i });
}
store[fieldIndex].push(val);
});
i++;
};
};


function FlatJSON222 (arr, schema) {
if (!Array.isArray(schema)) {
throw new Error('Schema missing or is in an unsupported format');
}

const header = {};
let i = 0;
let insertionIndex;
const columns = [];
const push = columnMajor(columns);
const schemaFieldsName = schema.map(unitSchema => unitSchema.name);

arr.forEach((item) => {
const fields = [];
schemaFieldsName.forEach((unitSchema) => {
if (unitSchema in header) {
insertionIndex = header[unitSchema];
} else {
header[unitSchema] = i++;
insertionIndex = i - 1;
}
fields[insertionIndex] = item[unitSchema];
});
push(...fields);
});

return [Object.keys(header), columns];
}

class JSONConverter2 extends DataModel.DataConverter{
constructor(){
super("json2")
}

convert(data , schema , options){
console.log("this is json2")
return FlatJSON222(data,schema,options);
}
}

DataModel.Converters.register(new JSONConverter2());

const schema = [
{
Expand Down Expand Up @@ -50,13 +105,6 @@ const data = [
}
];

const dm = new DataModel(data, schema);
const dataGenerated = dm.getData({
order: 'column',
formatter: {
birthday: val => new Date(val),
name: val => `Name: ${val}`
}
});
const dm = new DataModel(data, schema,{ dataFormat:"json2" });

console.log(dataGenerated);
console.log(dm.getData());
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "datamodel",
"description": "Relational algebra compliant in-memory tabular data store",
"homepage": "https://github.com/chartshq/datamodel",
"version": "2.2.3",
"version": "2.3.0",
"license": "MIT",
"main": "dist/datamodel.js",
"keywords": [
Expand Down
72 changes: 72 additions & 0 deletions src/converter/dataConverterStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import DataConverter from './model/dataConverter';
import { DSVStringConverter, DSVArrayConverter, JSONConverter, AutoDataConverter } from './defaultConverters';

class DataConverterStore {
constructor() {
this.store = new Map();
this.converters(this._getDefaultConverters());
}

_getDefaultConverters() {
return [
new DSVStringConverter(),
new DSVArrayConverter(),
new JSONConverter(),
new AutoDataConverter()
];
}

/**
* Sets the given converters in the store and returns the store
* @param {Array<DataConverter>} converters : contains array of converter instance
* @return { Map<String,DataConverter> }
*/
converters(converters = []) {
converters.forEach(converter => this.store.set(converter.type, converter));
return this.store;
}

/**
* Registers a Converter of type DataConverter
* @param {DataConverter} converter : converter Instance
* @returns self
*/
register(converter) {
if (converter instanceof DataConverter) {
this.store.set(converter.type, converter);
return this;
}
return null;
}

/**
* Rempves a converter from store
* @param {DataConverter} converter : converter Instance
* @returns self
*/

unregister(converter) {
this.store.delete(converter.type);
return this;
}

get(name) {
if (this.store.has(name)) {
return this.store.get(name);
}
return null;
}

}

const converterStore = (function () {
let store = null;

function getStore () {
store = new DataConverterStore();
return store;
}
return store || getStore();
}());

export default converterStore;
31 changes: 31 additions & 0 deletions src/converter/dataConverterStore.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* global describe, it */
/* eslint-disable no-unused-expressions */

import { expect } from 'chai';
import converterStore from './dataConverterStore';
import DataConverter from '../converter/model/dataConverter';

describe('#DataConverterStore', () => {
it('should register and unregister converter', () => {
class JSONConverter2 extends DataConverter {
constructor() {
super('json2');
}

convert() {
return '';
}
}

const converter = new JSONConverter2();
converterStore.register(converter);
expect(converterStore.get('json2')).to.not.null;

converterStore.unregister(converter);
expect(converterStore.get('json2')).to.null;
});

it('should not register invalid Coverter', () => {
expect(converterStore.register(() => {})).to.null;
});
});
13 changes: 13 additions & 0 deletions src/converter/defaultConverters/autoConverter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import DataConverter from '../model/dataConverter';
import AUTO from '../utils/auto-resolver';
import DataFormat from '../../enums/data-format';

export default class AutoDataConverter extends DataConverter {
constructor() {
super(DataFormat.AUTO);
}

convert(data, schema, options) {
return AUTO(data, schema, options);
}
}
13 changes: 13 additions & 0 deletions src/converter/defaultConverters/dsvArrayConverter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import DataConverter from '../model/dataConverter';
import DSVArr from '../utils/dsv-arr';
import DataFormat from '../../enums/data-format';

export default class DSVArrayConverter extends DataConverter {
constructor() {
super(DataFormat.DSV_ARR);
}

convert(data, schema, options) {
return DSVArr(data, schema, options);
}
}
13 changes: 13 additions & 0 deletions src/converter/defaultConverters/dsvStringConverter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import DataConverter from '../model/dataConverter';
import DSVStr from '../utils/dsv-str';
import DataFormat from '../../enums/data-format';

export default class DSVStringConverter extends DataConverter {
constructor() {
super(DataFormat.DSV_STR);
}

convert(data, schema, options) {
return DSVStr(data, schema, options);
}
}
4 changes: 4 additions & 0 deletions src/converter/defaultConverters/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { default as DSVStringConverter } from './dsvStringConverter';
export { default as JSONConverter } from './jsonConverter';
export { default as DSVArrayConverter } from './dsvArrayConverter';
export { default as AutoDataConverter } from './autoConverter';
13 changes: 13 additions & 0 deletions src/converter/defaultConverters/jsonConverter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import DataConverter from '../model/dataConverter';
import FlatJSON from '../utils/flat-json';
import DataFormat from '../../enums/data-format';

export default class JSONConverter extends DataConverter {
constructor() {
super(DataFormat.FLAT_JSON);
}

convert(data, schema, options) {
return FlatJSON(data, schema, options);
}
}
56 changes: 56 additions & 0 deletions src/converter/defaultConverters/jsonConverter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* global describe, it ,beforeEach */
/* eslint-disable no-unused-expressions */

import { expect } from 'chai';
import JSONConverter from './jsonConverter';

describe('JSON Converter', () => {
let data;
let converter = new JSONConverter();
beforeEach(() => {
data = [
{
a: 1,
b: 2,
c: 3
},
{
a: 4,
b: 5,
c: 6
},
{
a: 7,
b: 8,
c: 9
}
];
});

describe('#JSON', () => {
it('should convert to JSON data', () => {
const schema = [
{
name: 'a',
type: 'measure',
subtype: 'continuous'
},
{
name: 'b',
type: 'measure',
subtype: 'continuous'
},
{
name: 'c',
type: 'measure',
subtype: 'continuous'
}
];

const parsedData = converter.convert(data, schema);
const expected = [['a', 'b', 'c'], [[1, 4, 7], [2, 5, 8], [3, 6, 9]]];

expect(parsedData).to.deep.equal(expected);
});
});
});
8 changes: 4 additions & 4 deletions src/converter/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as DSVArr } from './dsv-arr';
export { default as DSVStr } from './dsv-str';
export { default as FlatJSON } from './flat-json';
export { default as Auto } from './auto-resolver';
import converterStore from './dataConverterStore';
import DataConverter from './model/dataConverter';

export { DataConverter, converterStore };
17 changes: 17 additions & 0 deletions src/converter/model/dataConverter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Interface for all data converters
*/
export default class DataConverter {
constructor(type) {
this._type = type;
}

get type() {
return this._type;
}

convert() {
throw new Error('Convert method not implemented.');
}

}
11 changes: 11 additions & 0 deletions src/converter/model/dataConverter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* global describe, it */
/* eslint-disable no-unused-expressions */

import { expect } from 'chai';
import DataConverter from './dataConverter';

describe('#DataConverterModel', () => {
it('should throw error', () => {
expect(new DataConverter().convert).to.throw(Error, 'Convert method not implemented');
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import FlatJSON from './flat-json';
import DSVArr from './dsv-arr';
import DSVStr from './dsv-str';
import { detectDataFormat } from '../utils';
import { detectDataFormat } from '../../utils';

/**
* Parses the input data and detect the format automatically.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { columnMajor } from '../utils';
import { columnMajor } from '../../utils';

/**
* Parses and converts data formatted in DSV array to a manageable internal format.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { columnMajor } from '../utils';
import { columnMajor } from '../../utils';

/**
* Parses and converts data formatted in JSON to a manageable internal format.
Expand Down
File renamed without changes.
Loading

0 comments on commit 0b6712a

Please sign in to comment.