{"action":"created","comment":{"url":"https://api.github.com/repos/n3-charts/line-chart/pulls/comments/40764473","id":40764473,"diff_hunk":"@@ -9,64 +20,117 @@ module n3Charts.Utils {\n     public type: string[] = ['line'];\n     public id: string;\n     public color: string;\n-    public visible = true;\n+    public visible: boolean = true;\n+\n+    static TYPE = {\n+        DOT: 'dot',\n+        LINE: 'line',\n+        AREA: 'area',\n+        COLUMN: 'column'\n+    };\n \n     constructor(js: any = {}) {\n-      this.parse(js);\n+      var options = this.sanitizeOptions(js);\n+\n+      this.id = options.id || Options.uuid();\n+      this.axis = this.sanitizeAxis(options.axis);\n+      this.dataset = options.dataset;\n+      this.key = options.key;\n+      this.color = options.color;\n+      this.visible = options.visible;\n+      this.label = options.label || options.id;\n+\n+      if (options.type.length > 0) {\n+        this.type = this.sanitizeType(options.type);\n+      }\n     }\n \n-    parse(jsSeries: any) {\n-      this.id = jsSeries.id || Options.uuid();\n-      this.axis = jsSeries.axis;\n-      this.dataset = jsSeries.dataset;\n-      this.key = jsSeries.key;\n-      this.type = this.parseType(jsSeries.type);\n-      this.id = jsSeries.id;\n-      this.color = jsSeries.color;\n-      this.visible = !(jsSeries.visible === false);\n-      this.label = jsSeries.label || jsSeries.id;\n+    /**\n+     * Make sure that the options have proper types,\n+     * and convert raw js to typed variables\n+     */\n+    sanitizeOptions(js: any) {\n+      var options = <ISeriesOptions>{};\n+\n+      // Extend the default options\n+      angular.extend(options, this, js);\n+\n+      options.id = Options.getString(options.id);\n+      options.type = Options.getArray(options.type);\n+      options.dataset = Options.getString(options.dataset);\n+      options.key = Options.getString(options.key);\n+      options.color = Options.getString(options.color);\n+      options.label = Options.getString(options.label);\n+      options.visible = Options.getBoolean(options.visible);\n+\n+      return options;\n     }\n \n+    /**\n+     * Return the toggeled visibility without modifying\n+     * the visibility property itself\n+     */\n     getToggledVisibility() {\n       return !this.visible;\n     }\n \n-    parseType(js:any): string[] {\n-      if (!js) {\n-        return ['line'];\n-      }\n+    /**\n+     * Return an array of valid types\n+     */\n+    sanitizeType(types: string[]) {\n+      return types.filter((type) => {\n+        return SeriesOptions.isValidType(type);\n+      });\n+    }\n \n-      if (typeof js === 'string') {\n-        return [js];\n+    /**\n+     * Return a valid axis key\n+     */\n+    sanitizeAxis(axis: string) {\n+      if (['y'].indexOf(axis) === -1) {\n+        throw TypeError(axis + ' is not a valid series option for axis.');\n       }\n \n-      return js;\n+      return axis;\n     }\n \n+    /**\n+     * Returns true if the series has a type column.\n+     * Series of type column need special treatment,\n+     * because x values are usually offset\n+     */\n     isAColumn() {\n-      return this.type.indexOf(Options.SERIES_TYPES.COLUMN) > -1;\n+      return this.hasType(SeriesOptions.TYPE.COLUMN);\n     }\n \n     getMainType() {\n-      if (this.type.length === 1) {\n-        return this.type[0];\n-      }\n-\n-      var types = Options.SERIES_TYPES;\n+      // @Sebastien: do we really need a main type?\n+      // I saw we are just using it for defining classes,\n+      // but this could be perfectly done for every type\n+      d3.values(SeriesOptions.TYPE).forEach((type) => {\n+        if (this.hasType(type)) {\n+          return type;\n+        }\n+      });\n \n-      if (this.type.indexOf(types.AREA) !== -1) {\n-        return types.AREA;\n-      }\n-\n-      if (this.type.indexOf(types.LINE) !== -1) {\n-        return types.LINE;\n-      }\n+      // We should always find the type with the lines\n+      // above and never reach this return statement\n+      return this.type[0];\n+    }\n \n-      if (this.type.indexOf(types.DOT) !== -1) {\n-        return types.DOT;\n-      }\n+    /**\n+     * Returns true if the series has a type *type*,\n+     * where type should be a value of SeriesOptions.TYPE","path":"src/utils/SeriesOptions.ts","position":159,"original_position":159,"commit_id":"6c231910c532ea2793e0dcfa0a5e7b0fb3285556","original_commit_id":"6c231910c532ea2793e0dcfa0a5e7b0fb3285556","user":{"login":"chaosmail","id":2969388,"avatar_url":"https://avatars.githubusercontent.com/u/2969388?v=3","gravatar_id":"","url":"https://api.github.com/users/chaosmail","html_url":"https://github.com/chaosmail","followers_url":"https://api.github.com/users/chaosmail/followers","following_url":"https://api.github.com/users/chaosmail/following{/other_user}","gists_url":"https://api.github.com/users/chaosmail/gists{/gist_id}","starred_url":"https://api.github.com/users/chaosmail/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chaosmail/subscriptions","organizations_url":"https://api.github.com/users/chaosmail/orgs","repos_url":"https://api.github.com/users/chaosmail/repos","events_url":"https://api.github.com/users/chaosmail/events{/privacy}","received_events_url":"https://api.github.com/users/chaosmail/received_events","type":"User","site_admin":false},"body":"it's an ENUM, so you can theoretically also plug values inside. If the values don't match the function will return false anyway. Not sure if this is really necessary here","created_at":"2015-09-30T07:16:00Z","updated_at":"2015-09-30T07:16:00Z","html_url":"https://github.com/n3-charts/line-chart/pull/339#discussion_r40764473","pull_request_url":"https://api.github.com/repos/n3-charts/line-chart/pulls/339","_links":{"self":{"href":"https://api.github.com/repos/n3-charts/line-chart/pulls/comments/40764473"},"html":{"href":"https://github.com/n3-charts/line-chart/pull/339#discussion_r40764473"},"pull_request":{"href":"https://api.github.com/repos/n3-charts/line-chart/pulls/339"}}},"pull_request":{"url":"https://api.github.com/repos/n3-charts/line-chart/pulls/339","id":46080758,"html_url":"https://github.com/n3-charts/line-chart/pull/339","diff_url":"https://github.com/n3-charts/line-chart/pull/339.diff","patch_url":"https://github.com/n3-charts/line-chart/pull/339.patch","issue_url":"https://api.github.com/repos/n3-charts/line-chart/issues/339","number":339,"state":"open","locked":false,"title":"Options Refactoring","user":{"login":"chaosmail","id":2969388,"avatar_url":"https://avatars.githubusercontent.com/u/2969388?v=3","gravatar_id":"","url":"https://api.github.com/users/chaosmail","html_url":"https://github.com/chaosmail","followers_url":"https://api.github.com/users/chaosmail/followers","following_url":"https://api.github.com/users/chaosmail/following{/other_user}","gists_url":"https://api.github.com/users/chaosmail/gists{/gist_id}","starred_url":"https://api.github.com/users/chaosmail/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chaosmail/subscriptions","organizations_url":"https://api.github.com/users/chaosmail/orgs","repos_url":"https://api.github.com/users/chaosmail/repos","events_url":"https://api.github.com/users/chaosmail/events{/privacy}","received_events_url":"https://api.github.com/users/chaosmail/received_events","type":"User","site_admin":false},"body":"Hi Sébastien,\r\n\r\nI am still very active in finding a perfect structure for the Options, so I conitnued refactoring everything. This time I want your opinion before I write all the tests.\r\n\r\nBest,\r\nChristoph","created_at":"2015-09-26T12:04:13Z","updated_at":"2015-09-30T07:16:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b1be70cfcf5eb012ee7fdf51e11533104214ae24","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/n3-charts/line-chart/pulls/339/commits","review_comments_url":"https://api.github.com/repos/n3-charts/line-chart/pulls/339/comments","review_comment_url":"https://api.github.com/repos/n3-charts/line-chart/pulls/comments{/number}","comments_url":"https://api.github.com/repos/n3-charts/line-chart/issues/339/comments","statuses_url":"https://api.github.com/repos/n3-charts/line-chart/statuses/6c231910c532ea2793e0dcfa0a5e7b0fb3285556","head":{"label":"n3-charts:feat/e2e-playground","ref":"feat/e2e-playground","sha":"6c231910c532ea2793e0dcfa0a5e7b0fb3285556","user":{"login":"n3-charts","id":4318902,"avatar_url":"https://avatars.githubusercontent.com/u/4318902?v=3","gravatar_id":"","url":"https://api.github.com/users/n3-charts","html_url":"https://github.com/n3-charts","followers_url":"https://api.github.com/users/n3-charts/followers","following_url":"https://api.github.com/users/n3-charts/following{/other_user}","gists_url":"https://api.github.com/users/n3-charts/gists{/gist_id}","starred_url":"https://api.github.com/users/n3-charts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/n3-charts/subscriptions","organizations_url":"https://api.github.com/users/n3-charts/orgs","repos_url":"https://api.github.com/users/n3-charts/repos","events_url":"https://api.github.com/users/n3-charts/events{/privacy}","received_events_url":"https://api.github.com/users/n3-charts/received_events","type":"Organization","site_admin":false},"repo":{"id":9873034,"name":"line-chart","full_name":"n3-charts/line-chart","owner":{"login":"n3-charts","id":4318902,"avatar_url":"https://avatars.githubusercontent.com/u/4318902?v=3","gravatar_id":"","url":"https://api.github.com/users/n3-charts","html_url":"https://github.com/n3-charts","followers_url":"https://api.github.com/users/n3-charts/followers","following_url":"https://api.github.com/users/n3-charts/following{/other_user}","gists_url":"https://api.github.com/users/n3-charts/gists{/gist_id}","starred_url":"https://api.github.com/users/n3-charts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/n3-charts/subscriptions","organizations_url":"https://api.github.com/users/n3-charts/orgs","repos_url":"https://api.github.com/users/n3-charts/repos","events_url":"https://api.github.com/users/n3-charts/events{/privacy}","received_events_url":"https://api.github.com/users/n3-charts/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/n3-charts/line-chart","description":"Awesome charts for AngularJS.","fork":false,"url":"https://api.github.com/repos/n3-charts/line-chart","forks_url":"https://api.github.com/repos/n3-charts/line-chart/forks","keys_url":"https://api.github.com/repos/n3-charts/line-chart/keys{/key_id}","collaborators_url":"https://api.github.com/repos/n3-charts/line-chart/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/n3-charts/line-chart/teams","hooks_url":"https://api.github.com/repos/n3-charts/line-chart/hooks","issue_events_url":"https://api.github.com/repos/n3-charts/line-chart/issues/events{/number}","events_url":"https://api.github.com/repos/n3-charts/line-chart/events","assignees_url":"https://api.github.com/repos/n3-charts/line-chart/assignees{/user}","branches_url":"https://api.github.com/repos/n3-charts/line-chart/branches{/branch}","tags_url":"https://api.github.com/repos/n3-charts/line-chart/tags","blobs_url":"https://api.github.com/repos/n3-charts/line-chart/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/n3-charts/line-chart/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/n3-charts/line-chart/git/refs{/sha}","trees_url":"https://api.github.com/repos/n3-charts/line-chart/git/trees{/sha}","statuses_url":"https://api.github.com/repos/n3-charts/line-chart/statuses/{sha}","languages_url":"https://api.github.com/repos/n3-charts/line-chart/languages","stargazers_url":"https://api.github.com/repos/n3-charts/line-chart/stargazers","contributors_url":"https://api.github.com/repos/n3-charts/line-chart/contributors","subscribers_url":"https://api.github.com/repos/n3-charts/line-chart/subscribers","subscription_url":"https://api.github.com/repos/n3-charts/line-chart/subscription","commits_url":"https://api.github.com/repos/n3-charts/line-chart/commits{/sha}","git_commits_url":"https://api.github.com/repos/n3-charts/line-chart/git/commits{/sha}","comments_url":"https://api.github.com/repos/n3-charts/line-chart/comments{/number}","issue_comment_url":"https://api.github.com/repos/n3-charts/line-chart/issues/comments{/number}","contents_url":"https://api.github.com/repos/n3-charts/line-chart/contents/{+path}","compare_url":"https://api.github.com/repos/n3-charts/line-chart/compare/{base}...{head}","merges_url":"https://api.github.com/repos/n3-charts/line-chart/merges","archive_url":"https://api.github.com/repos/n3-charts/line-chart/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/n3-charts/line-chart/downloads","issues_url":"https://api.github.com/repos/n3-charts/line-chart/issues{/number}","pulls_url":"https://api.github.com/repos/n3-charts/line-chart/pulls{/number}","milestones_url":"https://api.github.com/repos/n3-charts/line-chart/milestones{/number}","notifications_url":"https://api.github.com/repos/n3-charts/line-chart/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/n3-charts/line-chart/labels{/name}","releases_url":"https://api.github.com/repos/n3-charts/line-chart/releases{/id}","created_at":"2013-05-05T19:01:04Z","updated_at":"2015-09-29T20:16:18Z","pushed_at":"2015-09-29T20:17:19Z","git_url":"git://github.com/n3-charts/line-chart.git","ssh_url":"git@github.com:n3-charts/line-chart.git","clone_url":"https://github.com/n3-charts/line-chart.git","svn_url":"https://github.com/n3-charts/line-chart","homepage":"http://n3-charts.github.io/line-chart/","size":15952,"stargazers_count":1004,"watchers_count":1004,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":148,"mirror_url":null,"open_issues_count":35,"forks":148,"open_issues":35,"watchers":1004,"default_branch":"master"}},"base":{"label":"n3-charts:dev","ref":"dev","sha":"af8bd64d4bcff30a598db6574b0221d4d968d08e","user":{"login":"n3-charts","id":4318902,"avatar_url":"https://avatars.githubusercontent.com/u/4318902?v=3","gravatar_id":"","url":"https://api.github.com/users/n3-charts","html_url":"https://github.com/n3-charts","followers_url":"https://api.github.com/users/n3-charts/followers","following_url":"https://api.github.com/users/n3-charts/following{/other_user}","gists_url":"https://api.github.com/users/n3-charts/gists{/gist_id}","starred_url":"https://api.github.com/users/n3-charts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/n3-charts/subscriptions","organizations_url":"https://api.github.com/users/n3-charts/orgs","repos_url":"https://api.github.com/users/n3-charts/repos","events_url":"https://api.github.com/users/n3-charts/events{/privacy}","received_events_url":"https://api.github.com/users/n3-charts/received_events","type":"Organization","site_admin":false},"repo":{"id":9873034,"name":"line-chart","full_name":"n3-charts/line-chart","owner":{"login":"n3-charts","id":4318902,"avatar_url":"https://avatars.githubusercontent.com/u/4318902?v=3","gravatar_id":"","url":"https://api.github.com/users/n3-charts","html_url":"https://github.com/n3-charts","followers_url":"https://api.github.com/users/n3-charts/followers","following_url":"https://api.github.com/users/n3-charts/following{/other_user}","gists_url":"https://api.github.com/users/n3-charts/gists{/gist_id}","starred_url":"https://api.github.com/users/n3-charts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/n3-charts/subscriptions","organizations_url":"https://api.github.com/users/n3-charts/orgs","repos_url":"https://api.github.com/users/n3-charts/repos","events_url":"https://api.github.com/users/n3-charts/events{/privacy}","received_events_url":"https://api.github.com/users/n3-charts/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/n3-charts/line-chart","description":"Awesome charts for AngularJS.","fork":false,"url":"https://api.github.com/repos/n3-charts/line-chart","forks_url":"https://api.github.com/repos/n3-charts/line-chart/forks","keys_url":"https://api.github.com/repos/n3-charts/line-chart/keys{/key_id}","collaborators_url":"https://api.github.com/repos/n3-charts/line-chart/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/n3-charts/line-chart/teams","hooks_url":"https://api.github.com/repos/n3-charts/line-chart/hooks","issue_events_url":"https://api.github.com/repos/n3-charts/line-chart/issues/events{/number}","events_url":"https://api.github.com/repos/n3-charts/line-chart/events","assignees_url":"https://api.github.com/repos/n3-charts/line-chart/assignees{/user}","branches_url":"https://api.github.com/repos/n3-charts/line-chart/branches{/branch}","tags_url":"https://api.github.com/repos/n3-charts/line-chart/tags","blobs_url":"https://api.github.com/repos/n3-charts/line-chart/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/n3-charts/line-chart/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/n3-charts/line-chart/git/refs{/sha}","trees_url":"https://api.github.com/repos/n3-charts/line-chart/git/trees{/sha}","statuses_url":"https://api.github.com/repos/n3-charts/line-chart/statuses/{sha}","languages_url":"https://api.github.com/repos/n3-charts/line-chart/languages","stargazers_url":"https://api.github.com/repos/n3-charts/line-chart/stargazers","contributors_url":"https://api.github.com/repos/n3-charts/line-chart/contributors","subscribers_url":"https://api.github.com/repos/n3-charts/line-chart/subscribers","subscription_url":"https://api.github.com/repos/n3-charts/line-chart/subscription","commits_url":"https://api.github.com/repos/n3-charts/line-chart/commits{/sha}","git_commits_url":"https://api.github.com/repos/n3-charts/line-chart/git/commits{/sha}","comments_url":"https://api.github.com/repos/n3-charts/line-chart/comments{/number}","issue_comment_url":"https://api.github.com/repos/n3-charts/line-chart/issues/comments{/number}","contents_url":"https://api.github.com/repos/n3-charts/line-chart/contents/{+path}","compare_url":"https://api.github.com/repos/n3-charts/line-chart/compare/{base}...{head}","merges_url":"https://api.github.com/repos/n3-charts/line-chart/merges","archive_url":"https://api.github.com/repos/n3-charts/line-chart/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/n3-charts/line-chart/downloads","issues_url":"https://api.github.com/repos/n3-charts/line-chart/issues{/number}","pulls_url":"https://api.github.com/repos/n3-charts/line-chart/pulls{/number}","milestones_url":"https://api.github.com/repos/n3-charts/line-chart/milestones{/number}","notifications_url":"https://api.github.com/repos/n3-charts/line-chart/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/n3-charts/line-chart/labels{/name}","releases_url":"https://api.github.com/repos/n3-charts/line-chart/releases{/id}","created_at":"2013-05-05T19:01:04Z","updated_at":"2015-09-29T20:16:18Z","pushed_at":"2015-09-29T20:17:19Z","git_url":"git://github.com/n3-charts/line-chart.git","ssh_url":"git@github.com:n3-charts/line-chart.git","clone_url":"https://github.com/n3-charts/line-chart.git","svn_url":"https://github.com/n3-charts/line-chart","homepage":"http://n3-charts.github.io/line-chart/","size":15952,"stargazers_count":1004,"watchers_count":1004,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":148,"mirror_url":null,"open_issues_count":35,"forks":148,"open_issues":35,"watchers":1004,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/n3-charts/line-chart/pulls/339"},"html":{"href":"https://github.com/n3-charts/line-chart/pull/339"},"issue":{"href":"https://api.github.com/repos/n3-charts/line-chart/issues/339"},"comments":{"href":"https://api.github.com/repos/n3-charts/line-chart/issues/339/comments"},"review_comments":{"href":"https://api.github.com/repos/n3-charts/line-chart/pulls/339/comments"},"review_comment":{"href":"https://api.github.com/repos/n3-charts/line-chart/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/n3-charts/line-chart/pulls/339/commits"},"statuses":{"href":"https://api.github.com/repos/n3-charts/line-chart/statuses/6c231910c532ea2793e0dcfa0a5e7b0fb3285556"}}}}