{"action":"created","comment":{"url":"https://api.github.com/repos/ScottLogic/BitFlux/pulls/comments/52487684","id":52487684,"diff_hunk":"@@ -1,30 +1,154 @@\n import d3 from 'd3';\n import fc from 'd3fc';\n+import domain from '../util/domain/domain';\n \n export default function() {\n     var xScale = fc.scale.dateTime();\n     var xAxis = d3.svg.axis()\n-      .scale(xScale)\n-      .orient('bottom');\n+        .scale(xScale)\n+        .orient('bottom');\n \n-    function preventTicksMoreFrequentThanPeriod(period) {\n-        var scaleTickSeconds = (xScale.ticks()[1] - xScale.ticks()[0]) / 1000;\n-        if (scaleTickSeconds < period.seconds) {\n-            xAxis.ticks(period.d3TimeInterval.unit, period.d3TimeInterval.value);\n+    var containerWidth;\n+    var containerWidthChanged;\n+    var tickValues = [];\n+    var originalDomain;\n+    var tickSpacing;\n+\n+    function calculateNumberOfTicks() {\n+        return Math.max(Math.ceil(containerWidth / 150), 2);\n+    }\n+\n+    function calculateTickValues(model, numberOfTicks) {\n+        var lowerRoundedViewDomain = model.period.d3TimeInterval.unit.ceil(model.viewDomain[0]).getTime();\n+        var upperRoundedViewDomain = model.period.d3TimeInterval.unit.floor(model.viewDomain[1]).getTime();\n+        var viewDomainDifference = (upperRoundedViewDomain - lowerRoundedViewDomain);\n+        var zoomLevelChanged;\n+\n+        if (originalDomain) {\n+            zoomLevelChanged = (originalDomain[1].getTime() - originalDomain[0].getTime() !== model.viewDomain[1].getTime() - model.viewDomain[0].getTime());\n+            if (zoomLevelChanged || containerWidthChanged) {\n+                // If they have zoomed, recalculate the tick spacing\n+                tickSpacing = domain.roundTimestampUp((viewDomainDifference / numberOfTicks), model.period.seconds * 1000);\n+                containerWidthChanged = false;\n+            }\n+        }\n+\n+        if (!tickValues.length) {\n+            tickSpacing = domain.roundTimestampUp((viewDomainDifference / numberOfTicks), model.period.seconds * 1000);\n+        }\n+\n+        var lowerRounded = domain.roundTimestampDown(lowerRoundedViewDomain, tickSpacing);\n+        var viewDomainChanged = false;\n+\n+        if (originalDomain) {\n+            viewDomainChanged = (originalDomain[0].getTime() !== model.viewDomain[0].getTime()) ||\n+            (originalDomain[1].getTime() !== model.viewDomain[1].getTime());\n+        }\n+\n+        if (tickValues.length !== numberOfTicks || viewDomainChanged || zoomLevelChanged) {\n+            tickValues = [];\n+            for (var i = 0; i <= numberOfTicks; i++) {\n+                var tickDate = (model.period.d3TimeInterval.unit.ceil(lowerRounded + (tickSpacing * i)));\n+                tickValues.push(tickDate);\n+            }\n+        }\n+\n+        // Remove ticks lower than low view domain\n+        tickValues.forEach(function(tick) {\n+            if (tick < model.viewDomain[0]) {\n+                tickValues.splice(0, 1);\n+            }\n+        });\n+\n+        // Remove ticks higher than high view domain\n+        for (var j = 0; j < tickValues.length; j++) {\n+            if (tickValues[j] > model.viewDomain[1]) {\n+                tickValues.splice(j, tickValues.length - j);\n+            }\n+        }\n+\n+        xAxis.tickValues(tickValues);\n+\n+        if (viewDomainChanged || !originalDomain) {\n+            originalDomain = model.viewDomain;\n+        }\n+    }\n+\n+    function adaptAxisFormat(model, numberOfTicks) {\n+        var lowerRoundedViewDomain = model.period.d3TimeInterval.unit.ceil(model.viewDomain[0]).getTime();\n+        var upperRoundedViewDomain = model.period.d3TimeInterval.unit.floor(model.viewDomain[1]).getTime();\n+        var viewDomainDifference = (upperRoundedViewDomain - lowerRoundedViewDomain) / 1000;\n+\n+        var minimumPeriod = model.period.seconds;\n+        var formatting;\n+\n+        var yearInSeconds = 31557600;\n+        var monthInSeconds = 2592000;\n+        var dayInSeconds = 86400;\n+        var hourInSeconds = 3600;\n+\n+        var withinYear = viewDomainDifference < yearInSeconds;\n+        var withinMonth = viewDomainDifference < monthInSeconds;\n+        var withinDay = viewDomainDifference < dayInSeconds;\n+        var withinHour = viewDomainDifference < hourInSeconds;\n+\n+        var monthsDifference = Math.floor(viewDomainDifference / monthInSeconds);\n+        var daysDifference = Math.floor(viewDomainDifference / dayInSeconds);\n+        var hoursDifference = Math.floor(viewDomainDifference / hourInSeconds);\n+\n+        if (withinHour) {","path":"src/assets/js/chart/xAxis.js","position":105,"original_position":105,"commit_id":"ca27f9f30482e2d965c0a89dbcfb74caaf1e8379","original_commit_id":"ca27f9f30482e2d965c0a89dbcfb74caaf1e8379","user":{"login":"djmiley","id":13115186,"avatar_url":"https://avatars.githubusercontent.com/u/13115186?v=3","gravatar_id":"","url":"https://api.github.com/users/djmiley","html_url":"https://github.com/djmiley","followers_url":"https://api.github.com/users/djmiley/followers","following_url":"https://api.github.com/users/djmiley/following{/other_user}","gists_url":"https://api.github.com/users/djmiley/gists{/gist_id}","starred_url":"https://api.github.com/users/djmiley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djmiley/subscriptions","organizations_url":"https://api.github.com/users/djmiley/orgs","repos_url":"https://api.github.com/users/djmiley/repos","events_url":"https://api.github.com/users/djmiley/events{/privacy}","received_events_url":"https://api.github.com/users/djmiley/received_events","type":"User","site_admin":false},"body":"You could do a recursive check here possibly, rather than chaining if statements? Using [365, 12, 31, 24] etc.","created_at":"2016-02-10T16:57:44Z","updated_at":"2016-02-10T16:57:44Z","html_url":"https://github.com/ScottLogic/BitFlux/pull/599#discussion_r52487684","pull_request_url":"https://api.github.com/repos/ScottLogic/BitFlux/pulls/599","_links":{"self":{"href":"https://api.github.com/repos/ScottLogic/BitFlux/pulls/comments/52487684"},"html":{"href":"https://github.com/ScottLogic/BitFlux/pull/599#discussion_r52487684"},"pull_request":{"href":"https://api.github.com/repos/ScottLogic/BitFlux/pulls/599"}}},"pull_request":{"url":"https://api.github.com/repos/ScottLogic/BitFlux/pulls/599","id":57987411,"html_url":"https://github.com/ScottLogic/BitFlux/pull/599","diff_url":"https://github.com/ScottLogic/BitFlux/pull/599.diff","patch_url":"https://github.com/ScottLogic/BitFlux/pull/599.patch","issue_url":"https://api.github.com/repos/ScottLogic/BitFlux/issues/599","number":599,"state":"open","locked":false,"title":"Manual xAxis labels implemented","user":{"login":"rjmcneill","id":10117342,"avatar_url":"https://avatars.githubusercontent.com/u/10117342?v=3","gravatar_id":"","url":"https://api.github.com/users/rjmcneill","html_url":"https://github.com/rjmcneill","followers_url":"https://api.github.com/users/rjmcneill/followers","following_url":"https://api.github.com/users/rjmcneill/following{/other_user}","gists_url":"https://api.github.com/users/rjmcneill/gists{/gist_id}","starred_url":"https://api.github.com/users/rjmcneill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjmcneill/subscriptions","organizations_url":"https://api.github.com/users/rjmcneill/orgs","repos_url":"https://api.github.com/users/rjmcneill/repos","events_url":"https://api.github.com/users/rjmcneill/events{/privacy}","received_events_url":"https://api.github.com/users/rjmcneill/received_events","type":"User","site_admin":false},"body":"Relates to #503 ","created_at":"2016-02-02T13:38:26Z","updated_at":"2016-02-10T16:57:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6aa7635786f5385031c60908b3340defe767cf23","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ScottLogic/BitFlux/pulls/599/commits","review_comments_url":"https://api.github.com/repos/ScottLogic/BitFlux/pulls/599/comments","review_comment_url":"https://api.github.com/repos/ScottLogic/BitFlux/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ScottLogic/BitFlux/issues/599/comments","statuses_url":"https://api.github.com/repos/ScottLogic/BitFlux/statuses/ca27f9f30482e2d965c0a89dbcfb74caaf1e8379","head":{"label":"rjmcneill:bug/xAxis-labels-colliding","ref":"bug/xAxis-labels-colliding","sha":"ca27f9f30482e2d965c0a89dbcfb74caaf1e8379","user":{"login":"rjmcneill","id":10117342,"avatar_url":"https://avatars.githubusercontent.com/u/10117342?v=3","gravatar_id":"","url":"https://api.github.com/users/rjmcneill","html_url":"https://github.com/rjmcneill","followers_url":"https://api.github.com/users/rjmcneill/followers","following_url":"https://api.github.com/users/rjmcneill/following{/other_user}","gists_url":"https://api.github.com/users/rjmcneill/gists{/gist_id}","starred_url":"https://api.github.com/users/rjmcneill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjmcneill/subscriptions","organizations_url":"https://api.github.com/users/rjmcneill/orgs","repos_url":"https://api.github.com/users/rjmcneill/repos","events_url":"https://api.github.com/users/rjmcneill/events{/privacy}","received_events_url":"https://api.github.com/users/rjmcneill/received_events","type":"User","site_admin":false},"repo":{"id":44965754,"name":"d3fc-showcase","full_name":"rjmcneill/d3fc-showcase","owner":{"login":"rjmcneill","id":10117342,"avatar_url":"https://avatars.githubusercontent.com/u/10117342?v=3","gravatar_id":"","url":"https://api.github.com/users/rjmcneill","html_url":"https://github.com/rjmcneill","followers_url":"https://api.github.com/users/rjmcneill/followers","following_url":"https://api.github.com/users/rjmcneill/following{/other_user}","gists_url":"https://api.github.com/users/rjmcneill/gists{/gist_id}","starred_url":"https://api.github.com/users/rjmcneill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjmcneill/subscriptions","organizations_url":"https://api.github.com/users/rjmcneill/orgs","repos_url":"https://api.github.com/users/rjmcneill/repos","events_url":"https://api.github.com/users/rjmcneill/events{/privacy}","received_events_url":"https://api.github.com/users/rjmcneill/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rjmcneill/d3fc-showcase","description":"A cross-platform financial charting application to showcase the functionality of d3fc components.","fork":true,"url":"https://api.github.com/repos/rjmcneill/d3fc-showcase","forks_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/forks","keys_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/teams","hooks_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/hooks","issue_events_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/issues/events{/number}","events_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/events","assignees_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/assignees{/user}","branches_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/branches{/branch}","tags_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/tags","blobs_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/git/refs{/sha}","trees_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/statuses/{sha}","languages_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/languages","stargazers_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/stargazers","contributors_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/contributors","subscribers_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/subscribers","subscription_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/subscription","commits_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/commits{/sha}","git_commits_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/git/commits{/sha}","comments_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/comments{/number}","issue_comment_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/issues/comments{/number}","contents_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/contents/{+path}","compare_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/merges","archive_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/downloads","issues_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/issues{/number}","pulls_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/pulls{/number}","milestones_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/milestones{/number}","notifications_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/labels{/name}","releases_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/releases{/id}","deployments_url":"https://api.github.com/repos/rjmcneill/d3fc-showcase/deployments","created_at":"2015-10-26T12:03:38Z","updated_at":"2016-01-11T10:56:44Z","pushed_at":"2016-02-10T11:44:16Z","git_url":"git://github.com/rjmcneill/d3fc-showcase.git","ssh_url":"git@github.com:rjmcneill/d3fc-showcase.git","clone_url":"https://github.com/rjmcneill/d3fc-showcase.git","svn_url":"https://github.com/rjmcneill/d3fc-showcase","homepage":"http://scottlogic.github.io/d3fc-showcase/","size":1953,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"ScottLogic:develop","ref":"develop","sha":"4e7e8f84cf25154ee6188375404f298db9e45e25","user":{"login":"ScottLogic","id":2046037,"avatar_url":"https://avatars.githubusercontent.com/u/2046037?v=3","gravatar_id":"","url":"https://api.github.com/users/ScottLogic","html_url":"https://github.com/ScottLogic","followers_url":"https://api.github.com/users/ScottLogic/followers","following_url":"https://api.github.com/users/ScottLogic/following{/other_user}","gists_url":"https://api.github.com/users/ScottLogic/gists{/gist_id}","starred_url":"https://api.github.com/users/ScottLogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ScottLogic/subscriptions","organizations_url":"https://api.github.com/users/ScottLogic/orgs","repos_url":"https://api.github.com/users/ScottLogic/repos","events_url":"https://api.github.com/users/ScottLogic/events{/privacy}","received_events_url":"https://api.github.com/users/ScottLogic/received_events","type":"Organization","site_admin":false},"repo":{"id":39064095,"name":"BitFlux","full_name":"ScottLogic/BitFlux","owner":{"login":"ScottLogic","id":2046037,"avatar_url":"https://avatars.githubusercontent.com/u/2046037?v=3","gravatar_id":"","url":"https://api.github.com/users/ScottLogic","html_url":"https://github.com/ScottLogic","followers_url":"https://api.github.com/users/ScottLogic/followers","following_url":"https://api.github.com/users/ScottLogic/following{/other_user}","gists_url":"https://api.github.com/users/ScottLogic/gists{/gist_id}","starred_url":"https://api.github.com/users/ScottLogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ScottLogic/subscriptions","organizations_url":"https://api.github.com/users/ScottLogic/orgs","repos_url":"https://api.github.com/users/ScottLogic/repos","events_url":"https://api.github.com/users/ScottLogic/events{/privacy}","received_events_url":"https://api.github.com/users/ScottLogic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ScottLogic/BitFlux","description":"A cross-platform financial charting application to showcase the functionality of d3fc components.","fork":false,"url":"https://api.github.com/repos/ScottLogic/BitFlux","forks_url":"https://api.github.com/repos/ScottLogic/BitFlux/forks","keys_url":"https://api.github.com/repos/ScottLogic/BitFlux/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ScottLogic/BitFlux/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ScottLogic/BitFlux/teams","hooks_url":"https://api.github.com/repos/ScottLogic/BitFlux/hooks","issue_events_url":"https://api.github.com/repos/ScottLogic/BitFlux/issues/events{/number}","events_url":"https://api.github.com/repos/ScottLogic/BitFlux/events","assignees_url":"https://api.github.com/repos/ScottLogic/BitFlux/assignees{/user}","branches_url":"https://api.github.com/repos/ScottLogic/BitFlux/branches{/branch}","tags_url":"https://api.github.com/repos/ScottLogic/BitFlux/tags","blobs_url":"https://api.github.com/repos/ScottLogic/BitFlux/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ScottLogic/BitFlux/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ScottLogic/BitFlux/git/refs{/sha}","trees_url":"https://api.github.com/repos/ScottLogic/BitFlux/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ScottLogic/BitFlux/statuses/{sha}","languages_url":"https://api.github.com/repos/ScottLogic/BitFlux/languages","stargazers_url":"https://api.github.com/repos/ScottLogic/BitFlux/stargazers","contributors_url":"https://api.github.com/repos/ScottLogic/BitFlux/contributors","subscribers_url":"https://api.github.com/repos/ScottLogic/BitFlux/subscribers","subscription_url":"https://api.github.com/repos/ScottLogic/BitFlux/subscription","commits_url":"https://api.github.com/repos/ScottLogic/BitFlux/commits{/sha}","git_commits_url":"https://api.github.com/repos/ScottLogic/BitFlux/git/commits{/sha}","comments_url":"https://api.github.com/repos/ScottLogic/BitFlux/comments{/number}","issue_comment_url":"https://api.github.com/repos/ScottLogic/BitFlux/issues/comments{/number}","contents_url":"https://api.github.com/repos/ScottLogic/BitFlux/contents/{+path}","compare_url":"https://api.github.com/repos/ScottLogic/BitFlux/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ScottLogic/BitFlux/merges","archive_url":"https://api.github.com/repos/ScottLogic/BitFlux/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ScottLogic/BitFlux/downloads","issues_url":"https://api.github.com/repos/ScottLogic/BitFlux/issues{/number}","pulls_url":"https://api.github.com/repos/ScottLogic/BitFlux/pulls{/number}","milestones_url":"https://api.github.com/repos/ScottLogic/BitFlux/milestones{/number}","notifications_url":"https://api.github.com/repos/ScottLogic/BitFlux/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ScottLogic/BitFlux/labels{/name}","releases_url":"https://api.github.com/repos/ScottLogic/BitFlux/releases{/id}","deployments_url":"https://api.github.com/repos/ScottLogic/BitFlux/deployments","created_at":"2015-07-14T08:47:46Z","updated_at":"2016-02-01T13:03:28Z","pushed_at":"2016-02-10T16:55:17Z","git_url":"git://github.com/ScottLogic/BitFlux.git","ssh_url":"git@github.com:ScottLogic/BitFlux.git","clone_url":"https://github.com/ScottLogic/BitFlux.git","svn_url":"https://github.com/ScottLogic/BitFlux","homepage":"http://scottlogic.github.io/BitFlux/","size":2009,"stargazers_count":16,"watchers_count":16,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":11,"mirror_url":null,"open_issues_count":83,"forks":11,"open_issues":83,"watchers":16,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/ScottLogic/BitFlux/pulls/599"},"html":{"href":"https://github.com/ScottLogic/BitFlux/pull/599"},"issue":{"href":"https://api.github.com/repos/ScottLogic/BitFlux/issues/599"},"comments":{"href":"https://api.github.com/repos/ScottLogic/BitFlux/issues/599/comments"},"review_comments":{"href":"https://api.github.com/repos/ScottLogic/BitFlux/pulls/599/comments"},"review_comment":{"href":"https://api.github.com/repos/ScottLogic/BitFlux/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ScottLogic/BitFlux/pulls/599/commits"},"statuses":{"href":"https://api.github.com/repos/ScottLogic/BitFlux/statuses/ca27f9f30482e2d965c0a89dbcfb74caaf1e8379"}}}}