From bb7b41960e53318772a413f10b35daf35d476257 Mon Sep 17 00:00:00 2001 From: deepak Date: Sun, 18 Feb 2018 22:43:37 +0530 Subject: [PATCH 01/42] pie-charts all test cases passing with d3v4 --- Gruntfile.js | 7 +- package-lock.json | 377 +++++++++++++++++++++++++++++++---- package.json | 2 +- spec/pie-chart-spec.js | 48 ++--- src/d3-compat/d3-compat00.js | 4 + src/d3-compat/d3-compat01.js | 42 ++++ src/d3-compat/d3-compat02.js | 41 ++++ 7 files changed, 451 insertions(+), 70 deletions(-) create mode 100644 src/d3-compat/d3-compat00.js create mode 100644 src/d3-compat/d3-compat01.js create mode 100644 src/d3-compat/d3-compat02.js diff --git a/Gruntfile.js b/Gruntfile.js index f6908373a..b0c0f6878 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -145,7 +145,7 @@ module.exports = function (grunt) { options: { display: 'short', summary: true, - specs: '<%= conf.spec %>/*-spec.js', + specs: '<%= conf.spec %>/pie-chart-spec.js', helpers: [ '<%= conf.web %>/js/jasmine-jsreporter.js', '<%= conf.spec %>/helpers/*.js' @@ -159,6 +159,9 @@ module.exports = function (grunt) { }, src: [ '<%= conf.web %>/js/d3.js', + '<%= conf.src %>/d3-compat/d3-compat00.js', + '<%= conf.src %>/d3-compat/d3-compat01.js', + '<%= conf.src %>/d3-compat/d3-compat02.js', '<%= conf.web %>/js/crossfilter.js', '<%= conf.web %>/js/colorbrewer.js', '<%= conf.pkg.name %>.js' @@ -289,7 +292,7 @@ module.exports = function (grunt) { '<%= conf.pkg.name %>.js.map', '<%= conf.pkg.name %>.min.js', '<%= conf.pkg.name %>.min.js.map', - 'node_modules/d3/d3.js', + 'node_modules/d3/build/d3.js', 'node_modules/crossfilter2/crossfilter.js', 'node_modules/queue-async/build/queue.js', 'node_modules/grunt-saucelabs/examples/jasmine/lib/jasmine-jsreporter/jasmine-jsreporter.js', diff --git a/package-lock.json b/package-lock.json index 115407d24..2994dd1e7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -106,7 +106,8 @@ "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true }, "ansi-styles": { "version": "2.2.1", @@ -139,12 +140,14 @@ "aproba": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", - "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==" + "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", + "dev": true }, "are-we-there-yet": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.4.tgz", "integrity": "sha1-u13KOCu5TwXhUZQ3PRb9O6HKEQ0=", + "dev": true, "requires": { "delegates": "1.0.0", "readable-stream": "2.2.11" @@ -825,6 +828,7 @@ "resolved": "https://registry.npmjs.org/center-align/-/center-align-0.1.3.tgz", "integrity": "sha1-qg0yYptu6XIgBBHL1EYckHvCt60=", "dev": true, + "optional": true, "requires": { "align-text": "0.1.4", "lazy-cache": "1.0.4" @@ -927,6 +931,7 @@ "resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz", "integrity": "sha1-S0dXYP+AJkx2LDoXGQMukcf+oNE=", "dev": true, + "optional": true, "requires": { "center-align": "0.1.3", "right-align": "0.1.3", @@ -936,7 +941,8 @@ "code-point-at": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" + "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", + "dev": true }, "coffee-script": { "version": "1.10.0", @@ -1074,7 +1080,6 @@ "version": "2.8.1", "resolved": "https://registry.npmjs.org/commander/-/commander-2.8.1.tgz", "integrity": "sha1-Br42f+v9oMMwqh4qBy09yXYkJdQ=", - "dev": true, "requires": { "graceful-readlink": "1.0.1" } @@ -1166,7 +1171,8 @@ "console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", - "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=" + "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", + "dev": true }, "constants-browserify": { "version": "1.0.0", @@ -1195,7 +1201,8 @@ "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", + "dev": true }, "create-ecdh": { "version": "4.0.0", @@ -1306,9 +1313,259 @@ "dev": true }, "d3": { - "version": "3.5.17", - "resolved": "https://registry.npmjs.org/d3/-/d3-3.5.17.tgz", - "integrity": "sha1-vEZ0gAQ3iyGjYMn8fPUjF5B2L7g=" + "version": "4.13.0", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3/-/d3-4.13.0.tgz", + "integrity": "sha512-l8c4+0SldjVKLaE2WG++EQlqD7mh/dmQjvi2L2lKPadAVC+TbJC4ci7Uk9bRi+To0+ansgsS0iWfPjD7DBy+FQ==", + "requires": { + "d3-array": "1.2.1", + "d3-axis": "1.0.8", + "d3-brush": "1.0.4", + "d3-chord": "1.0.4", + "d3-collection": "1.0.4", + "d3-color": "1.0.3", + "d3-dispatch": "1.0.3", + "d3-drag": "1.2.1", + "d3-dsv": "1.0.8", + "d3-ease": "1.0.3", + "d3-force": "1.1.0", + "d3-format": "1.2.2", + "d3-geo": "1.9.1", + "d3-hierarchy": "1.1.5", + "d3-interpolate": "1.1.6", + "d3-path": "1.0.5", + "d3-polygon": "1.0.3", + "d3-quadtree": "1.0.3", + "d3-queue": "3.0.7", + "d3-random": "1.1.0", + "d3-request": "1.0.6", + "d3-scale": "1.0.7", + "d3-selection": "1.3.0", + "d3-shape": "1.2.0", + "d3-time": "1.0.8", + "d3-time-format": "2.1.1", + "d3-timer": "1.0.7", + "d3-transition": "1.1.1", + "d3-voronoi": "1.1.2", + "d3-zoom": "1.7.1" + } + }, + "d3-array": { + "version": "1.2.1", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-array/-/d3-array-1.2.1.tgz", + "integrity": "sha512-CyINJQ0SOUHojDdFDH4JEM0552vCR1utGyLHegJHyYH0JyCpSeTPxi4OBqHMA2jJZq4NH782LtaJWBImqI/HBw==" + }, + "d3-axis": { + "version": "1.0.8", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-axis/-/d3-axis-1.0.8.tgz", + "integrity": "sha1-MacFoLU15ldZ3hQXOjGTMTfxjvo=" + }, + "d3-brush": { + "version": "1.0.4", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-brush/-/d3-brush-1.0.4.tgz", + "integrity": "sha1-AMLyOAGfJPbAoZSibUGhUw/+e8Q=", + "requires": { + "d3-dispatch": "1.0.3", + "d3-drag": "1.2.1", + "d3-interpolate": "1.1.6", + "d3-selection": "1.3.0", + "d3-transition": "1.1.1" + } + }, + "d3-chord": { + "version": "1.0.4", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-chord/-/d3-chord-1.0.4.tgz", + "integrity": "sha1-fexPC6iG9xP+ERxF92NBT290yiw=", + "requires": { + "d3-array": "1.2.1", + "d3-path": "1.0.5" + } + }, + "d3-collection": { + "version": "1.0.4", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-collection/-/d3-collection-1.0.4.tgz", + "integrity": "sha1-NC39EoN8kJdPM/HMCnha6lcNzcI=" + }, + "d3-color": { + "version": "1.0.3", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-color/-/d3-color-1.0.3.tgz", + "integrity": "sha1-vHZD/KjlOoNH4vva/6I2eWtYUJs=" + }, + "d3-dispatch": { + "version": "1.0.3", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-dispatch/-/d3-dispatch-1.0.3.tgz", + "integrity": "sha1-RuFJHqqbWMNY/OW+TovtYm54cfg=" + }, + "d3-drag": { + "version": "1.2.1", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-drag/-/d3-drag-1.2.1.tgz", + "integrity": "sha512-Cg8/K2rTtzxzrb0fmnYOUeZHvwa4PHzwXOLZZPwtEs2SKLLKLXeYwZKBB+DlOxUvFmarOnmt//cU4+3US2lyyQ==", + "requires": { + "d3-dispatch": "1.0.3", + "d3-selection": "1.3.0" + } + }, + "d3-dsv": { + "version": "1.0.8", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-dsv/-/d3-dsv-1.0.8.tgz", + "integrity": "sha512-IVCJpQ+YGe3qu6odkPQI0KPqfxkhbP/oM1XhhE/DFiYmcXKfCRub4KXyiuehV1d4drjWVXHUWx4gHqhdZb6n/A==", + "requires": { + "commander": "2.8.1", + "iconv-lite": "0.4.18", + "rw": "1.3.3" + } + }, + "d3-ease": { + "version": "1.0.3", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-ease/-/d3-ease-1.0.3.tgz", + "integrity": "sha1-aL+8NJM4o4DETYrMT7wzBKotjA4=" + }, + "d3-force": { + "version": "1.1.0", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-force/-/d3-force-1.1.0.tgz", + "integrity": "sha512-2HVQz3/VCQs0QeRNZTYb7GxoUCeb6bOzMp/cGcLa87awY9ZsPvXOGeZm0iaGBjXic6I1ysKwMn+g+5jSAdzwcg==", + "requires": { + "d3-collection": "1.0.4", + "d3-dispatch": "1.0.3", + "d3-quadtree": "1.0.3", + "d3-timer": "1.0.7" + } + }, + "d3-format": { + "version": "1.2.2", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-format/-/d3-format-1.2.2.tgz", + "integrity": "sha512-zH9CfF/3C8zUI47nsiKfD0+AGDEuM8LwBIP7pBVpyR4l/sKkZqITmMtxRp04rwBrlshIZ17XeFAaovN3++wzkw==" + }, + "d3-geo": { + "version": "1.9.1", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-geo/-/d3-geo-1.9.1.tgz", + "integrity": "sha512-l9wL/cEQkyZQYXw3xbmLsH3eQ5ij+icNfo4r0GrLa5rOCZR/e/3am45IQ0FvQ5uMsv+77zBRunLc9ufTWSQYFA==", + "requires": { + "d3-array": "1.2.1" + } + }, + "d3-hierarchy": { + "version": "1.1.5", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-hierarchy/-/d3-hierarchy-1.1.5.tgz", + "integrity": "sha1-ochFxC+Eoga88cAcAQmOpN2qeiY=" + }, + "d3-interpolate": { + "version": "1.1.6", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-interpolate/-/d3-interpolate-1.1.6.tgz", + "integrity": "sha512-mOnv5a+pZzkNIHtw/V6I+w9Lqm9L5bG3OTXPM5A+QO0yyVMQ4W1uZhR+VOJmazaOZXri2ppbiZ5BUNWT0pFM9A==", + "requires": { + "d3-color": "1.0.3" + } + }, + "d3-path": { + "version": "1.0.5", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-path/-/d3-path-1.0.5.tgz", + "integrity": "sha1-JB6xhJvZ6egCHA0KeZ+KDo5EF2Q=" + }, + "d3-polygon": { + "version": "1.0.3", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-polygon/-/d3-polygon-1.0.3.tgz", + "integrity": "sha1-FoiOkCZGCTPysXllKtN4Ik04LGI=" + }, + "d3-quadtree": { + "version": "1.0.3", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-quadtree/-/d3-quadtree-1.0.3.tgz", + "integrity": "sha1-rHmH4+I/6AWpkPKOG1DTj8uCJDg=" + }, + "d3-queue": { + "version": "3.0.7", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-queue/-/d3-queue-3.0.7.tgz", + "integrity": "sha1-yTouVLQXwJWRKdfXP2z31Ckudhg=" + }, + "d3-random": { + "version": "1.1.0", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-random/-/d3-random-1.1.0.tgz", + "integrity": "sha1-ZkLlBsb6OmSFldKyRpeIqNElKdM=" + }, + "d3-request": { + "version": "1.0.6", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-request/-/d3-request-1.0.6.tgz", + "integrity": "sha512-FJj8ySY6GYuAJHZMaCQ83xEYE4KbkPkmxZ3Hu6zA1xxG2GD+z6P+Lyp+zjdsHf0xEbp2xcluDI50rCS855EQ6w==", + "requires": { + "d3-collection": "1.0.4", + "d3-dispatch": "1.0.3", + "d3-dsv": "1.0.8", + "xmlhttprequest": "1.8.0" + } + }, + "d3-scale": { + "version": "1.0.7", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-scale/-/d3-scale-1.0.7.tgz", + "integrity": "sha512-KvU92czp2/qse5tUfGms6Kjig0AhHOwkzXG0+PqIJB3ke0WUv088AHMZI0OssO9NCkXt4RP8yju9rpH8aGB7Lw==", + "requires": { + "d3-array": "1.2.1", + "d3-collection": "1.0.4", + "d3-color": "1.0.3", + "d3-format": "1.2.2", + "d3-interpolate": "1.1.6", + "d3-time": "1.0.8", + "d3-time-format": "2.1.1" + } + }, + "d3-selection": { + "version": "1.3.0", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-selection/-/d3-selection-1.3.0.tgz", + "integrity": "sha512-qgpUOg9tl5CirdqESUAu0t9MU/t3O9klYfGfyKsXEmhyxyzLpzpeh08gaxBUTQw1uXIOkr/30Ut2YRjSSxlmHA==" + }, + "d3-shape": { + "version": "1.2.0", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-shape/-/d3-shape-1.2.0.tgz", + "integrity": "sha1-RdAVOPBkuv0F6j1tLLdI/YxB93c=", + "requires": { + "d3-path": "1.0.5" + } + }, + "d3-time": { + "version": "1.0.8", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-time/-/d3-time-1.0.8.tgz", + "integrity": "sha512-YRZkNhphZh3KcnBfitvF3c6E0JOFGikHZ4YqD+Lzv83ZHn1/u6yGenRU1m+KAk9J1GnZMnKcrtfvSktlA1DXNQ==" + }, + "d3-time-format": { + "version": "2.1.1", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-time-format/-/d3-time-format-2.1.1.tgz", + "integrity": "sha512-8kAkymq2WMfzW7e+s/IUNAtN/y3gZXGRrdGfo6R8NKPAA85UBTxZg5E61bR6nLwjPjj4d3zywSQe1CkYLPFyrw==", + "requires": { + "d3-time": "1.0.8" + } + }, + "d3-timer": { + "version": "1.0.7", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-timer/-/d3-timer-1.0.7.tgz", + "integrity": "sha512-vMZXR88XujmG/L5oB96NNKH5lCWwiLM/S2HyyAQLcjWJCloK5shxta4CwOFYLZoY3AWX73v8Lgv4cCAdWtRmOA==" + }, + "d3-transition": { + "version": "1.1.1", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-transition/-/d3-transition-1.1.1.tgz", + "integrity": "sha512-xeg8oggyQ+y5eb4J13iDgKIjUcEfIOZs2BqV/eEmXm2twx80wTzJ4tB4vaZ5BKfz7XsI/DFmQL5me6O27/5ykQ==", + "requires": { + "d3-color": "1.0.3", + "d3-dispatch": "1.0.3", + "d3-ease": "1.0.3", + "d3-interpolate": "1.1.6", + "d3-selection": "1.3.0", + "d3-timer": "1.0.7" + } + }, + "d3-voronoi": { + "version": "1.1.2", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-voronoi/-/d3-voronoi-1.1.2.tgz", + "integrity": "sha1-Fodmfo8TotFYyAwUgMWinLDYlzw=" + }, + "d3-zoom": { + "version": "1.7.1", + "resolved": "https://repos.kreatio.com/repository/npm-all/d3-zoom/-/d3-zoom-1.7.1.tgz", + "integrity": "sha512-sZHQ55DGq5BZBFGnRshUT8tm2sfhPHFnOlmPbbwTkAoPeVdRTkB4Xsf9GCY0TSHrTD8PeJPZGmP/TpGicwJDJQ==", + "requires": { + "d3-dispatch": "1.0.3", + "d3-drag": "1.2.1", + "d3-interpolate": "1.1.6", + "d3-selection": "1.3.0", + "d3-transition": "1.1.1" + } }, "dashdash": { "version": "1.14.1", @@ -1406,7 +1663,8 @@ "delegates": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", - "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=" + "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", + "dev": true }, "depd": { "version": "1.1.0", @@ -3009,6 +3267,7 @@ "version": "2.7.4", "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", + "dev": true, "requires": { "aproba": "1.2.0", "console-control-strings": "1.1.0", @@ -3154,8 +3413,7 @@ "graceful-readlink": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz", - "integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=", - "dev": true + "integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=" }, "grunt": { "version": "1.0.1", @@ -3353,34 +3611,37 @@ } }, "grunt-contrib-uglify": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/grunt-contrib-uglify/-/grunt-contrib-uglify-2.0.0.tgz", - "integrity": "sha1-jJlw1pCTbN5tJaoRk1Sb2SkBaTA=", + "version": "3.2.1", + "resolved": "https://repos.kreatio.com/repository/npm-all/grunt-contrib-uglify/-/grunt-contrib-uglify-3.2.1.tgz", + "integrity": "sha512-xBPwg8wuA/m+HiSh2uMADuadKEnFQt9N5OhEy35vIl945yG6095oY1H1Og3ucg0wBSOieIBn3raqStvIcwKqHg==", "dev": true, "requires": { "chalk": "1.1.3", - "lodash.assign": "4.2.0", "maxmin": "1.1.0", - "uglify-js": "2.7.5", + "uglify-js": "3.2.2", "uri-path": "1.0.0" }, "dependencies": { - "async": { - "version": "0.2.10", - "resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz", - "integrity": "sha1-trvgsGdLnXGXCMo43owjfLUmw9E=", + "commander": { + "version": "2.12.2", + "resolved": "https://repos.kreatio.com/repository/npm-all/commander/-/commander-2.12.2.tgz", + "integrity": "sha512-BFnaq5ZOGcDN7FlrtBT4xxkgIToalIIxwjxLWVJ8bGTpe1LroqMiqQXdA7ygc7CRvaYS+9zfPGFnJqFSayx+AA==", + "dev": true + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://repos.kreatio.com/repository/npm-all/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", "dev": true }, "uglify-js": { - "version": "2.7.5", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.7.5.tgz", - "integrity": "sha1-RhLAx7qu4rp8SH3kkErhIgefLKg=", + "version": "3.2.2", + "resolved": "https://repos.kreatio.com/repository/npm-all/uglify-js/-/uglify-js-3.2.2.tgz", + "integrity": "sha512-++1NO/zZIEdWf6cDIGceSJQPX31SqIpbVAHwFG5+240MtZqPG/NIPoinj8zlXQtAfMBqEt1Jyv2FiLP3n9gVhQ==", "dev": true, "requires": { - "async": "0.2.10", - "source-map": "0.5.6", - "uglify-to-browserify": "1.0.2", - "yargs": "3.10.0" + "commander": "2.12.2", + "source-map": "0.6.1" } } } @@ -3788,7 +4049,8 @@ "has-unicode": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", - "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=" + "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", + "dev": true }, "hash-base": { "version": "2.0.2", @@ -3966,8 +4228,7 @@ "iconv-lite": { "version": "0.4.18", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.18.tgz", - "integrity": "sha512-sr1ZQph3UwHTR0XftSbK85OvBbxe/abLGzEnPENCQwmHf7sck8Oyu4ob3LgBxWWxRoM+QszeUyl7jbqapu2TqA==", - "dev": true + "integrity": "sha512-sr1ZQph3UwHTR0XftSbK85OvBbxe/abLGzEnPENCQwmHf7sck8Oyu4ob3LgBxWWxRoM+QszeUyl7jbqapu2TqA==" }, "ieee754": { "version": "1.1.8", @@ -4015,7 +4276,8 @@ "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true }, "ink-docstrap": { "version": "1.3.0", @@ -4128,6 +4390,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "dev": true, "requires": { "number-is-nan": "1.0.1" } @@ -4201,7 +4464,8 @@ "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", + "dev": true }, "isexe": { "version": "2.0.0", @@ -4791,7 +5055,8 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz", "integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4=", - "dev": true + "dev": true, + "optional": true }, "lcid": { "version": "1.0.0", @@ -5400,7 +5665,8 @@ "number-is-nan": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", + "dev": true }, "oauth-sign": { "version": "0.8.2", @@ -5411,7 +5677,8 @@ "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "dev": true }, "object-get": { "version": "2.1.0", @@ -5891,7 +6158,8 @@ "process-nextick-args": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", - "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=" + "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=", + "dev": true }, "progress": { "version": "1.1.8", @@ -6150,6 +6418,7 @@ "version": "2.2.11", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.2.11.tgz", "integrity": "sha512-h+8+r3MKEhkiVrwdKL8aWs1oc1VvBu33ueshOvS26RsZQ3Amhx/oO3TKe4lApSV9ueY6as8EAh7mtuFjdlhg9Q==", + "dev": true, "requires": { "core-util-is": "1.0.2", "inherits": "2.0.3", @@ -6164,6 +6433,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.2.tgz", "integrity": "sha1-sp4fThEl+pehA4K4pTNze3SR4Xk=", + "dev": true, "requires": { "safe-buffer": "5.0.1" } @@ -6428,6 +6698,7 @@ "resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz", "integrity": "sha1-YTObci/mo1FWiSENJOFMlhSGE+8=", "dev": true, + "optional": true, "requires": { "align-text": "0.1.4" } @@ -6448,10 +6719,16 @@ "inherits": "2.0.3" } }, + "rw": { + "version": "1.3.3", + "resolved": "https://repos.kreatio.com/repository/npm-all/rw/-/rw-1.3.3.tgz", + "integrity": "sha1-P4Yt+pGrdmsUiF700BEkv9oHT7Q=" + }, "safe-buffer": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.0.1.tgz", - "integrity": "sha1-0mPKVGls2KMGtcplUekt5XkY++c=" + "integrity": "sha1-0mPKVGls2KMGtcplUekt5XkY++c=", + "dev": true }, "sanitize-html": { "version": "1.14.1", @@ -6709,7 +6986,8 @@ "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", - "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", + "dev": true }, "sntp": { "version": "1.0.9", @@ -6895,6 +7173,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "dev": true, "requires": { "code-point-at": "1.1.0", "is-fullwidth-code-point": "1.0.0", @@ -6917,6 +7196,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, "requires": { "ansi-regex": "2.1.1" } @@ -7241,7 +7521,8 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz", "integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=", - "dev": true + "dev": true, + "optional": true }, "umd": { "version": "3.0.1", @@ -7391,7 +7672,8 @@ "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", + "dev": true }, "utile": { "version": "0.2.1", @@ -7557,6 +7839,7 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.2.tgz", "integrity": "sha512-ijDLlyQ7s6x1JgCLur53osjm/UXUYD9+0PbYKrBsYisYXzCxN+HC3mYDNy/dWdmf3AwqwU3CXwDCvsNgGK1S0w==", + "dev": true, "requires": { "string-width": "1.0.2" } @@ -7565,7 +7848,8 @@ "version": "0.1.0", "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz", "integrity": "sha1-VDjNLqk7IC76Ohn+iIeu58lPnJ0=", - "dev": true + "dev": true, + "optional": true }, "winston": { "version": "0.8.3", @@ -7649,6 +7933,11 @@ "integrity": "sha1-+mv3YqYKQT+z3Y9LA8WyaSONMI8=", "dev": true }, + "xmlhttprequest": { + "version": "1.8.0", + "resolved": "https://repos.kreatio.com/repository/npm-all/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz", + "integrity": "sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw=" + }, "xtend": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", @@ -7672,6 +7961,7 @@ "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz", "integrity": "sha1-9+572FfdfB0tOMDnTvvWgdFDH9E=", "dev": true, + "optional": true, "requires": { "camelcase": "1.2.1", "cliui": "2.1.0", @@ -7683,7 +7973,8 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz", "integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=", - "dev": true + "dev": true, + "optional": true } } }, diff --git a/package.json b/package.json index 3c365c519..0abf9e156 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ }, "dependencies": { "crossfilter2": "~1.4", - "d3": "^3" + "d3": "^4" }, "devDependencies": { "file-saver": "^1.3.0", diff --git a/spec/pie-chart-spec.js b/spec/pie-chart-spec.js index fc405c3e8..22c0bfc20 100644 --- a/spec/pie-chart-spec.js +++ b/spec/pie-chart-spec.js @@ -157,10 +157,10 @@ describe('dc.pieChart', function () { }); }); it('slice path fill should be set correctly', function () { - expect(d3.select(chart.selectAll('g.pie-slice path')[0][0]).attr('fill')).toMatch(/#3182bd/i); - expect(d3.select(chart.selectAll('g.pie-slice path')[0][1]).attr('fill')).toMatch(/#6baed6/i); - expect(d3.select(chart.selectAll('g.pie-slice path')[0][2]).attr('fill')).toMatch(/#9ecae1/i); - expect(d3.select(chart.selectAll('g.pie-slice path')[0][3]).attr('fill')).toMatch(/#c6dbef/i); + expect(d3.select(chart.selectAll('g.pie-slice path').nodes()[0]).attr('fill')).toMatch(/#3182bd/i); + expect(d3.select(chart.selectAll('g.pie-slice path').nodes()[1]).attr('fill')).toMatch(/#6baed6/i); + expect(d3.select(chart.selectAll('g.pie-slice path').nodes()[2]).attr('fill')).toMatch(/#9ecae1/i); + expect(d3.select(chart.selectAll('g.pie-slice path').nodes()[3]).attr('fill')).toMatch(/#c6dbef/i); }); it('slice label should be created', function () { expect(chart.selectAll('svg text.pie-slice').data().length).toEqual(5); @@ -227,7 +227,7 @@ describe('dc.pieChart', function () { return chart; }); it('multiple invocation of render should update chart', function () { - expect(d3.selectAll('#pie-chart-age svg')[0].length).toEqual(1); + expect(d3.selectAll('#pie-chart-age svg').nodes().length).toEqual(1); }); }); describe('filter', function () { @@ -236,8 +236,8 @@ describe('dc.pieChart', function () { chart.render(); }); it('label should be hidden if filtered out', function () { - expect(chart.selectAll('svg g text.pie-slice')[0][0].textContent).toEqual('22'); - expect(chart.selectAll('svg g text.pie-slice')[0][1].textContent).toEqual(''); + expect(chart.selectAll('svg g text.pie-slice').nodes()[0].textContent).toEqual('22'); + expect(chart.selectAll('svg g text.pie-slice').nodes()[1].textContent).toEqual(''); }); afterEach(function () { regionDimension.filterAll(); @@ -253,7 +253,7 @@ describe('dc.pieChart', function () { expect(chart.select('g').classed('empty-chart')).toBeTruthy(); }); it('should have one slice', function () { - expect(chart.selectAll('svg g text.pie-slice').length).toBe(1); + expect(chart.selectAll('svg g text.pie-slice').nodes().length).toBe(1); }); afterEach(function () { statusDimension.filterAll(); @@ -456,14 +456,14 @@ describe('dc.pieChart', function () { }); it('label should not be generated if the slice is too small', function () { // slice '66' - expect(d3.select(chart.selectAll('text.pie-slice')[0][4]).text()).toEqual(''); + expect(d3.select(chart.selectAll('text.pie-slice').nodes()[4]).text()).toEqual(''); }); describe('selected', function () { beforeEach(function () { chart.filter('66').redraw(); }); it('a small slice should be labelled if it is selected', function () { - expect(d3.select(chart.selectAll('text.pie-slice')[0][4]).text()).toEqual('66'); + expect(d3.select(chart.selectAll('text.pie-slice').nodes()[4]).text()).toEqual('66'); }); afterEach(function () { chart.filter(null); @@ -486,17 +486,17 @@ describe('dc.pieChart', function () { chart.render(); }); it('should render correct number of text', function () { - expect(chart.selectAll('text.pie-slice')[0].length).toEqual(5); + expect(chart.selectAll('text.pie-slice').nodes().length).toEqual(5); }); it('custom function should be used to dynamically generate label', function () { - expect(d3.select(chart.selectAll('text.pie-slice')[0][0]).text()).toEqual('custom'); + expect(d3.select(chart.selectAll('text.pie-slice').nodes()[0]).text()).toEqual('custom'); }); it('label should not be generated if the slice is too small', function () { // slice '66' - expect(d3.select(chart.selectAll('text.pie-slice')[0][4]).text()).toEqual(''); + expect(d3.select(chart.selectAll('text.pie-slice').nodes()[4]).text()).toEqual(''); }); it('should render correct number of title', function () { - expect(chart.selectAll('g.pie-slice title')[0].length).toEqual(5); + expect(chart.selectAll('g.pie-slice title').nodes().length).toEqual(5); }); it('custom function should be used to dynamically generate title', function () { chart.selectAll('g.pie-slice title').each(function (p) { @@ -525,10 +525,10 @@ describe('dc.pieChart', function () { .render(); }); it('produce expected number of slices', function () { - expect(chart.selectAll('text.pie-slice')[0].length).toEqual(3); + expect(chart.selectAll('text.pie-slice').nodes().length).toEqual(3); }); it('others slice should use custom name', function () { - expect(d3.select(chart.selectAll('text.pie-slice')[0][2]).text()).toEqual('small'); + expect(d3.select(chart.selectAll('text.pie-slice').nodes()[2]).text()).toEqual('small'); }); it('remaining slices should be in descending value order', function () { expect(chart.selectAll('text.pie-slice').data().map(dc.pluck('value'))) @@ -539,14 +539,14 @@ describe('dc.pieChart', function () { beforeEach(function () { event = document.createEvent('MouseEvents'); event.initEvent('click', true, true); - chart.selectAll('.pie-slice path')[0][2].dispatchEvent(event); + chart.selectAll('.pie-slice path').nodes()[2].dispatchEvent(event); }); it('should filter three smallest', function () { expect(chart.filters()).toEqual(['33', '55', '66','small']); }); describe('clicking again', function () { beforeEach(function () { - chart.selectAll('.pie-slice path')[0][2].dispatchEvent(event); + chart.selectAll('.pie-slice path').nodes()[2].dispatchEvent(event); }); it('should reset filter', function () { expect(chart.filters()).toEqual([]); @@ -577,7 +577,7 @@ describe('dc.pieChart', function () { chart.cap(1).render(); }); it('correct values, others row', function () { - expect(chart.selectAll('title')[0].map(function (t) {return d3.select(t).text();})) + expect(chart.selectAll('title').nodes().map(function (t) {return d3.select(t).text();})) .toEqual(['F: 220', 'small: 198']); }); }); @@ -632,10 +632,10 @@ describe('dc.pieChart', function () { return chart; }); it('default function should be used to dynamically generate label', function () { - expect(d3.select(chart.selectAll('text.pie-slice')[0][0]).text()).toEqual('F'); + expect(d3.select(chart.selectAll('text.pie-slice').nodes()[0]).text()).toEqual('F'); }); it('default function should be used to dynamically generate title', function () { - expect(d3.select(chart.selectAll('g.pie-slice title')[0][0]).text()).toEqual('F: 5'); + expect(d3.select(chart.selectAll('g.pie-slice title').nodes()[0]).text()).toEqual('F: 5'); }); describe('with n/a filter', function () { beforeEach(function () { @@ -647,17 +647,17 @@ describe('dc.pieChart', function () { expect(chart.select('g').classed('empty-chart')).toBeTruthy(); }); it('should have one slice', function () { - expect(chart.selectAll('svg g text.pie-slice').length).toBe(1); + expect(chart.selectAll('svg g text.pie-slice').nodes().length).toBe(1); }); it('should have slice labeled empty', function () { - expect(d3.select(chart.selectAll('text.pie-slice')[0][0]).text()).toEqual('empty'); + expect(d3.select(chart.selectAll('text.pie-slice').nodes()[0]).text()).toEqual('empty'); }); describe('with emptyTitle', function () { beforeEach(function () { chart.emptyTitle('nothing').render(); }); it('should respect the emptyTitle', function () { - expect(d3.select(chart.selectAll('text.pie-slice')[0][0]).text()).toEqual('nothing'); + expect(d3.select(chart.selectAll('text.pie-slice').nodes()[0]).text()).toEqual('nothing'); }); afterEach(function () { chart.emptyTitle('empty'); diff --git a/src/d3-compat/d3-compat00.js b/src/d3-compat/d3-compat00.js new file mode 100644 index 000000000..635f1f431 --- /dev/null +++ b/src/d3-compat/d3-compat00.js @@ -0,0 +1,4 @@ + +var d3v4 = d3; + +d3 = {}; diff --git a/src/d3-compat/d3-compat01.js b/src/d3-compat/d3-compat01.js new file mode 100644 index 000000000..92d703138 --- /dev/null +++ b/src/d3-compat/d3-compat01.js @@ -0,0 +1,42 @@ +d3.behavior = {}; +d3.geo = {}; +d3.layout = {}; +d3.scale = {}; +d3.svg = {}; +d3.time = {}; + +d3.ascending = d3v4.ascending; // d3-array; import ascending from 'd3-array/src/ascending' +d3.behavior.zoom = d3v4.zoom; // d3-zoom; import zoom from 'd3-zoom/src/zoom' +d3.descending = d3v4.descending; // d3-array; import descending from 'd3-array/src/descending' +d3.dispatch = d3v4.dispatch; // d3-dispatch; import dispatch from 'd3-dispatch/src/dispatch' +d3.event = d3v4.event; // d3-selection; import event from 'd3-selection/src/selection/on' +d3.extent = d3v4.extent; // d3-array; import extent from 'd3-array/src/extent' +d3.format = d3v4.format; // d3-format; import {format, utcFormat} from 'd3-format/src/defaultLocale' +d3.geo.path = d3v4.geoPath; // d3-geo; import path from 'd3-geo/src/path/index' +d3.interpolate = d3v4.interpolate; // d3-interpolate; import interpolate from 'd3-interpolate/src/value' +d3.interpolateHcl = d3v4.interpolateHcl; // d3-interpolate; import interpolateHcl from 'd3-interpolate/src/hcl' +d3.interpolateNumber = d3v4.interpolateNumber; // d3-interpolate; import interpolateNumber from 'd3-interpolate/src/number' +d3.layout.pie = d3v4.pie; // d3-shape; import pie from 'd3-shape/src/pie' +d3.layout.stack = d3v4.stack; // d3-shape; import stack from 'd3-shape/src/stack' +d3.max = d3v4.max; // d3-array; import max from 'd3-array/src/max' +d3.min = d3v4.min; // d3-array; import min from 'd3-array/src/min' +d3.mouse = d3v4.mouse; // d3-selection; import mouse from 'd3-selection/src/mouse' +d3.nest = d3v4.nest; // d3-collection; import nest from 'd3-collection/src/nest' +d3.quantile = d3v4.quantile; // d3-array; import quantile from 'd3-array/src/quantile' +d3.range = d3v4.range; // d3-array; import range from 'd3-array/src/range' +d3.scale.category20c = d3v4.schemeCategory20c; // d3-scale; import category20c from 'd3-scale/src/category20c' +d3.scale.linear = d3v4.scaleLinear; // d3-scale; import scaleLinear from 'd3-scale/src/linear' +d3.scale.ordinal = d3v4.scaleOrdinal; // d3-scale; import scaleOrdinal from 'd3-scale/src/ordinal' +d3.scale.quantize = d3v4.scaleQuantize; // d3-scale; import scaleQuantize from 'd3-scale/src/quantize' +d3.select = d3v4.select; // d3-selection; import select from 'd3-selection/src/select' +d3.set = d3v4.set; // d3-collection; import set from 'd3-collection/src/set' +d3.sum = d3v4.sum; // d3-array; import sum from 'd3-array/src/sum' +d3.svg.arc = d3v4.arc; // d3-shape; import arc from 'd3-shape/src/arc' +d3.svg.area = d3v4.area; // d3-shape; import line from 'd3-shape/src/area' +d3.svg.axis = d3v4.axisTop; // d3-axis; import {axisBottom, axisLeft} from 'd3-axis/src/axis' +d3.svg.brush = d3v4.brush; // d3-brush; import {brushX, brushY, default as brush} from 'd3-brush/src/brush' +d3.svg.line = d3v4.line; // d3-shape; import line from 'd3-shape/src/line' +d3.svg.symbol = d3v4.symbol; // d3-shape; import symbol from 'd3-shape/src/symbol' +d3.time.format = d3v4.timeFormat; // d3-time-format; import {timeFormat, utcFormat} from 'd3-time-format/src/defaultLocale' +d3.timer = d3v4.timer; // d3-timer; import {timer} from 'd3-timer/src/timer' + diff --git a/src/d3-compat/d3-compat02.js b/src/d3-compat/d3-compat02.js new file mode 100644 index 000000000..4625b875c --- /dev/null +++ b/src/d3-compat/d3-compat02.js @@ -0,0 +1,41 @@ +d3.selectAll = d3v4.selectAll; + +d3.time.format.iso = d3v4.isoFormat; + +d3.time.format.iso.parse = d3v4.isoParse; + +d3.time.day = d3v4.timeDay; + +d3.time.day.utc = d3v4.utcDay; + +d3.scale.category20c = function () { + return d3v4.scaleOrdinal(d3v4.schemeCategory20c); +}; + +d3.functor = function (v) { + return typeof v === "function" ? v : function () { + return v; + }; +}; + +d3._dispatch_tmp_fn_gen = function (_dispatch, event) { + return function () { + _dispatch.apply(event, this, arguments); + }; +}; + +d3.dispatch = function () { + var _out = {}; + var _dispatch = d3v4.dispatch.apply(this, arguments); + + for (var i = 0; i < arguments.length; i++) { + var event = arguments[i]; + _out[event] = this._dispatch_tmp_fn_gen(_dispatch, event); + } + + _out.on = function (event, callback) { + _dispatch.on(event, callback); + }; + + return _out; +}; From 09698c5c40b70c6d659fa76b8edba01feb02b4f0 Mon Sep 17 00:00:00 2001 From: deepak Date: Tue, 20 Feb 2018 10:36:31 +0530 Subject: [PATCH 02/42] Better alignment to build infrastructure --- Gruntfile.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index b0c0f6878..c524a6bfb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -29,6 +29,14 @@ module.exports = function (grunt) { banner: '<%= conf.banner %>' } }, + d3compat: { + src: '<%= conf.src %>/d3-compat/*.js', + dest: 'd3-compat.js', + options: { + process: true, + sourceMap: true + } + }, welcome: { src: ['docs/welcome.base.md', 'web/img/class-hierarchy.svg'], dest: 'welcome.md', @@ -159,9 +167,7 @@ module.exports = function (grunt) { }, src: [ '<%= conf.web %>/js/d3.js', - '<%= conf.src %>/d3-compat/d3-compat00.js', - '<%= conf.src %>/d3-compat/d3-compat01.js', - '<%= conf.src %>/d3-compat/d3-compat02.js', + '<%= conf.web %>/js/d3-compat.js', '<%= conf.web %>/js/crossfilter.js', '<%= conf.web %>/js/colorbrewer.js', '<%= conf.pkg.name %>.js' @@ -292,6 +298,8 @@ module.exports = function (grunt) { '<%= conf.pkg.name %>.js.map', '<%= conf.pkg.name %>.min.js', '<%= conf.pkg.name %>.min.js.map', + 'd3-compat.js', + 'd3-compat.js.map', 'node_modules/d3/build/d3.js', 'node_modules/crossfilter2/crossfilter.js', 'node_modules/queue-async/build/queue.js', From 771a7143f59a5e9df2f6d6529ab41068d4dc3d29 Mon Sep 17 00:00:00 2001 From: deepak Date: Tue, 20 Feb 2018 15:35:01 +0530 Subject: [PATCH 03/42] .selectAll('anything')[0] -> .selectAll('anything').nodes() --- spec/bar-chart-spec.js | 14 ++++----- spec/box-plot-spec.js | 2 +- spec/bubble-chart-spec.js | 18 ++++++------ spec/bubble-overlay-spec.js | 40 +++++++++++++------------- spec/composite-chart-spec.js | 12 ++++---- spec/coordinate-grid-chart-spec.js | 8 +++--- spec/data-addition-spec.js | 6 ++-- spec/data-grid-spec.js | 24 ++++++++-------- spec/data-table-spec.js | 40 +++++++++++++------------- spec/geo-choropleth-chart-spec.js | 46 +++++++++++++++--------------- spec/heatmap-spec.js | 4 +-- spec/legend-spec.js | 10 +++---- spec/line-chart-spec.js | 10 +++---- spec/row-chart-spec.js | 12 ++++---- spec/scatter-plot-spec.js | 4 +-- spec/select-menu-spec.js | 14 ++++----- 16 files changed, 132 insertions(+), 132 deletions(-) diff --git a/spec/bar-chart-spec.js b/spec/bar-chart-spec.js index 9fd1923e9..22d60b4a5 100644 --- a/spec/bar-chart-spec.js +++ b/spec/bar-chart-spec.js @@ -147,7 +147,7 @@ describe('dc.barChart', function () { }); }); function nthYAxisText (n) { - return d3.select(chart.selectAll('g.y text')[0][n]); + return d3.select(chart.selectAll('g.y text').nodes()[n]); } it('should generate bars with positions corresponding to their data', function () { expect(nthStack(0).nthBar(0).attr('x')).toBeWithinDelta(58, 1); @@ -552,7 +552,7 @@ describe('dc.barChart', function () { }); it('should generate y axis domain dynamically', function () { - var nthText = function (n) { return d3.select(chart.selectAll('g.axis.y .tick text')[0][n]); }; + var nthText = function (n) { return d3.select(chart.selectAll('g.axis.y .tick text').nodes()[n]); }; expect(nthText(0).text()).toBe('-20'); expect(nthText(1).text()).toBe('0'); @@ -576,7 +576,7 @@ describe('dc.barChart', function () { }); it('should generate y axis domain dynamically', function () { - var nthText = function (n) { return d3.select(chart.selectAll('g.axis.y .tick text')[0][n]); }; + var nthText = function (n) { return d3.select(chart.selectAll('g.axis.y .tick text').nodes()[n]); }; expect(nthText(0).text()).toBe('-30'); expect(nthText(1).text()).toBe('-20'); @@ -634,7 +634,7 @@ describe('dc.barChart', function () { } function xAxisText () { - return chart.selectAll('g.x text')[0].map(function (x) { return d3.select(x).text(); }); + return chart.selectAll('g.x text').nodes().map(function (x) { return d3.select(x).text(); }); } }); @@ -1191,7 +1191,7 @@ describe('dc.barChart', function () { }); function xAxisText () { - return chart.selectAll('g.x text')[0].map(function (x) { return d3.select(x).text(); }); + return chart.selectAll('g.x text').nodes().map(function (x) { return d3.select(x).text(); }); } }); @@ -1255,12 +1255,12 @@ describe('dc.barChart', function () { }); function xAxisText () { - return chart.selectAll('g.x text')[0].map(function (x) { return d3.select(x).text(); }); + return chart.selectAll('g.x text').nodes().map(function (x) { return d3.select(x).text(); }); } }); function nthStack (n) { - var stack = d3.select(chart.selectAll('.stack')[0][n]); + var stack = d3.select(chart.selectAll('.stack').nodes()[n]); stack.nthBar = function (n) { return d3.select(this.selectAll('rect.bar')[0][n]); diff --git a/spec/box-plot-spec.js b/spec/box-plot-spec.js index b553dad32..6a10a8e4e 100644 --- a/spec/box-plot-spec.js +++ b/spec/box-plot-spec.js @@ -196,7 +196,7 @@ describe('dc.boxPlot', function () { }); function box (n) { - var nthBox = d3.select(chart.selectAll('g.box')[0][n]); + var nthBox = d3.select(chart.selectAll('g.box').nodes()[n]); nthBox.boxText = function (n) { return d3.select(this.selectAll('text.box')[0][n]); }; diff --git a/spec/bubble-chart-spec.js b/spec/bubble-chart-spec.js index 26a83103b..3ae5eaebe 100644 --- a/spec/bubble-chart-spec.js +++ b/spec/bubble-chart-spec.js @@ -98,7 +98,7 @@ describe('dc.bubbleChart', function () { }); it('generates right number of bubbles', function () { - expect(chart.selectAll('circle.bubble')[0].length).toBe(2); + expect(chart.selectAll('circle.bubble').nodes().length).toBe(2); }); it('calculates right cx for each bubble', function () { @@ -142,7 +142,7 @@ describe('dc.bubbleChart', function () { }); it('generates right number of labels', function () { - expect(chart.selectAll('g.node text')[0].length).toBe(2); + expect(chart.selectAll('g.node text').nodes().length).toBe(2); }); it('creates correct label for each bubble', function () { @@ -157,7 +157,7 @@ describe('dc.bubbleChart', function () { }); it('generates right number of titles', function () { - expect(chart.selectAll('g.node title')[0].length).toBe(2); + expect(chart.selectAll('g.node title').nodes().length).toBe(2); }); it('creates correct title for each bubble', function () { @@ -189,11 +189,11 @@ describe('dc.bubbleChart', function () { }); it('generates right number of labels', function () { - expect(chart.selectAll('g.node text')[0].length).toBe(0); + expect(chart.selectAll('g.node text').nodes().length).toBe(0); }); it('generates right number of titles', function () { - expect(chart.selectAll('g.node title')[0].length).toBe(0); + expect(chart.selectAll('g.node title').nodes().length).toBe(0); }); }); @@ -375,7 +375,7 @@ describe('dc.bubbleChart', function () { }); it('generates right number of bubbles', function () { - expect(chart.selectAll('circle.bubble')[0].length).toBe(10); + expect(chart.selectAll('circle.bubble').nodes().length).toBe(10); }); it('auto calculates x range based on width', function () { @@ -659,14 +659,14 @@ describe('dc.bubbleChart', function () { } function testBubbleRadiiCol3 (chart) { - var bubbles = chart.selectAll('circle.bubble')[0]; + var bubbles = chart.selectAll('circle.bubble').nodes(); var expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34.5, 16.1, 0, 0, 16.1, 59.1, 34.5, 16.1, 96, 0, 22.2, 0, 0, 0, 0]; bubbles.forEach(function (b, i) { expect(+d3.select(b).attr('r')).toBeWithinDelta(expected[i], 0.1); }); } function testBubbleTitlesCol3 (chart) { - var titles = chart.selectAll('g.node title')[0]; + var titles = chart.selectAll('g.node title').nodes(); var expected = [ {'total': 0,'setosa': 0,'versicolor': 0,'virginica': 0},{'total': 0,'setosa': 0,'versicolor': 0,'virginica': 0}, {'total': 0,'setosa': 0,'versicolor': 0,'virginica': 0},{'total': 0,'setosa': 0,'versicolor': 0,'virginica': 0}, @@ -687,7 +687,7 @@ describe('dc.bubbleChart', function () { }); } function testBubbleLabelsCol3 (chart) { - var labels = chart.selectAll('g.node text')[0]; + var labels = chart.selectAll('g.node text').nodes(); var expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 1, 0, 0, 1, 8, 4, 1, 14, 0, 2, 0, 0, 0, 0]; labels.forEach(function (l, i) { expect(+d3.select(l).text()).toBe(expected[i]); diff --git a/spec/bubble-overlay-spec.js b/spec/bubble-overlay-spec.js index 0621fa5f1..cecb13b03 100644 --- a/spec/bubble-overlay-spec.js +++ b/spec/bubble-overlay-spec.js @@ -45,60 +45,60 @@ describe('dc.bubbleOverlay', function () { }); it('should generate the correct number of overlay groups', function () { - expect(chart.selectAll('g.node')[0].length).toEqual(6); + expect(chart.selectAll('g.node').nodes().length).toEqual(6); }); it('should generate a correct class name for the overlay groups', function () { - expect(d3.select(chart.selectAll('g.node')[0][0]).attr('class')).toEqual('node california'); - expect(d3.select(chart.selectAll('g.node')[0][3]).attr('class')).toEqual('node ontario'); + expect(d3.select(chart.selectAll('g.node').nodes()[0]).attr('class')).toEqual('node california'); + expect(d3.select(chart.selectAll('g.node').nodes()[3]).attr('class')).toEqual('node ontario'); }); it('should generate the correct number of overlay bubbles', function () { - expect(chart.selectAll('circle.bubble')[0].length).toEqual(6); + expect(chart.selectAll('circle.bubble').nodes().length).toEqual(6); }); it('should generate a correct translate for overlay groups', function () { - expect(d3.select(chart.selectAll('g.node')[0][0]).attr('transform')).toMatchTranslate(100, 120); - expect(d3.select(chart.selectAll('g.node')[0][3]).attr('transform')).toMatchTranslate(180, 90); + expect(d3.select(chart.selectAll('g.node').nodes()[0]).attr('transform')).toMatchTranslate(100, 120); + expect(d3.select(chart.selectAll('g.node').nodes()[3]).attr('transform')).toMatchTranslate(180, 90); }); it('should generate correct radii for circles', function () { - expect(d3.select(chart.selectAll('circle.bubble')[0][0]).attr('r')).toEqual('87'); - expect(d3.select(chart.selectAll('circle.bubble')[0][3]).attr('r')).toEqual('48.5'); + expect(d3.select(chart.selectAll('circle.bubble').nodes()[0]).attr('r')).toEqual('87'); + expect(d3.select(chart.selectAll('circle.bubble').nodes()[3]).attr('r')).toEqual('48.5'); }); it('should generate correct labels', function () { - expect(d3.select(chart.selectAll('g.node text')[0][0]).text()).toEqual('California'); - expect(d3.select(chart.selectAll('g.node text')[0][3]).text()).toEqual('Ontario'); + expect(d3.select(chart.selectAll('g.node text').nodes()[0]).text()).toEqual('California'); + expect(d3.select(chart.selectAll('g.node text').nodes()[3]).text()).toEqual('Ontario'); }); it('should generate the label only once', function () { chart.redraw(); - expect(chart.selectAll('g.node text')[0].length).toEqual(6); + expect(chart.selectAll('g.node text').nodes().length).toEqual(6); }); it('generate the correct titles', function () { - expect(d3.select(chart.selectAll('g.node title')[0][0]).text()).toEqual('Title: California'); - expect(d3.select(chart.selectAll('g.node title')[0][3]).text()).toEqual('Title: Ontario'); + expect(d3.select(chart.selectAll('g.node title').nodes()[0]).text()).toEqual('Title: California'); + expect(d3.select(chart.selectAll('g.node title').nodes()[3]).text()).toEqual('Title: Ontario'); }); it('should only generate titles once', function () { chart.redraw(); - expect(chart.selectAll('g.node title')[0].length).toEqual(6); + expect(chart.selectAll('g.node title').nodes().length).toEqual(6); }); it('should fill circles with the specified colors', function () { - expect(d3.select(chart.selectAll('circle.bubble')[0][0]).attr('fill')).toEqual('blue'); - expect(d3.select(chart.selectAll('circle.bubble')[0][3]).attr('fill')).toEqual('blue'); + expect(d3.select(chart.selectAll('circle.bubble').nodes()[0]).attr('fill')).toEqual('blue'); + expect(d3.select(chart.selectAll('circle.bubble').nodes()[3]).attr('fill')).toEqual('blue'); }); it('should highlight the filtered bubbles', function () { chart.filter('Colorado'); chart.filter('California'); chart.redraw(); - expect(d3.select(chart.selectAll('g.node')[0][0]).attr('class')).toEqual('node california selected'); - expect(d3.select(chart.selectAll('g.node')[0][1]).attr('class')).toEqual('node colorado selected'); - expect(d3.select(chart.selectAll('g.node')[0][3]).attr('class')).toEqual('node ontario deselected'); + expect(d3.select(chart.selectAll('g.node').nodes()[0]).attr('class')).toEqual('node california selected'); + expect(d3.select(chart.selectAll('g.node').nodes()[1]).attr('class')).toEqual('node colorado selected'); + expect(d3.select(chart.selectAll('g.node').nodes()[3]).attr('class')).toEqual('node ontario deselected'); }); }); @@ -118,7 +118,7 @@ describe('dc.bubbleOverlay', function () { regionDim = data.dimension(function (d) { return d.region; }); }); function expectRadii (expected) { - var circles = chart.selectAll('circle.bubble')[0]; + var circles = chart.selectAll('circle.bubble').nodes(); console.log(circles.map(function (c) { return +d3.select(c).attr('r'); })); circles.forEach(function (c, i) { expect(+d3.select(c).attr('r')).toBeWithinDelta(expected[i], 0.1); diff --git a/spec/composite-chart-spec.js b/spec/composite-chart-spec.js index a3b7fb488..66c19de8e 100644 --- a/spec/composite-chart-spec.js +++ b/spec/composite-chart-spec.js @@ -156,8 +156,8 @@ describe('dc.compositeChart', function () { }); it('should index each subchart g by css class', function () { - expect(d3.select(chart.selectAll('g.sub')[0][0]).attr('class')).toBe('sub _0'); - expect(d3.select(chart.selectAll('g.sub')[0][1]).attr('class')).toBe('sub _1'); + expect(d3.select(chart.selectAll('g.sub').nodes()[0]).attr('class')).toBe('sub _0'); + expect(d3.select(chart.selectAll('g.sub').nodes()[1]).attr('class')).toBe('sub _1'); }); it('should generate sub line chart paths', function () { @@ -311,7 +311,7 @@ describe('dc.compositeChart', function () { it('should generate legend labels with their associated group text', function () { function legendText (n) { - return d3.select(chart.selectAll('g.dc-legend g.dc-legend-item text')[0][n]).text(); + return d3.select(chart.selectAll('g.dc-legend g.dc-legend-item text').nodes()[n]).text(); } expect(legendText(0)).toBe('Date Value Group Bar'); expect(legendText(1)).toBe('Date ID Group'); @@ -332,11 +332,11 @@ describe('dc.compositeChart', function () { }); it('should hide hidable child stacks', function () { - var dateValueGroupLine2 = d3.select(chart.selectAll('g.dc-legend g.dc-legend-item')[0][3]); + var dateValueGroupLine2 = d3.select(chart.selectAll('g.dc-legend g.dc-legend-item').nodes()[3]); dateValueGroupLine2.on('click')(dateValueGroupLine2.datum()); expect(dateValueGroupLine2.text()).toBe('Date Value Group Line 2'); - expect(d3.select(chart.selectAll('g.dc-legend g.dc-legend-item')[0][3]).classed('fadeout')).toBeTruthy(); + expect(d3.select(chart.selectAll('g.dc-legend g.dc-legend-item').nodes()[3]).classed('fadeout')).toBeTruthy(); expect(chart.selectAll('path.line').size()).toEqual(3); }); }); @@ -384,7 +384,7 @@ describe('dc.compositeChart', function () { }); it('should trigger the sub-chart renderlet', function () { - expect(d3.select(chart.selectAll('rect')[0][0]).attr('width')).toBe('10'); + expect(d3.select(chart.selectAll('rect').nodes()[0]).attr('width')).toBe('10'); }); }); diff --git a/spec/coordinate-grid-chart-spec.js b/spec/coordinate-grid-chart-spec.js index 41160e53b..dd1ff0813 100644 --- a/spec/coordinate-grid-chart-spec.js +++ b/spec/coordinate-grid-chart-spec.js @@ -315,7 +315,7 @@ describe('dc.coordinateGridChart', function () { describe('horizontal grid lines', function () { it('should draw lines associated with the data shown on the right y-axis', function () { - var nthGridLine = function (n) { return d3.select(chart.selectAll('.grid-line.horizontal line')[0][n]); }; + var nthGridLine = function (n) { return d3.select(chart.selectAll('.grid-line.horizontal line').nodes()[n]); }; expect(chart.selectAll('.grid-line.horizontal line').size()).toBe(7); expect(nthGridLine(0).attr('y2')).toBe('130'); @@ -338,7 +338,7 @@ describe('dc.coordinateGridChart', function () { }); it('should draws lines associated with the data using the custom ticks', function () { - var nthGridLine = function (n) { return d3.select(chart.selectAll('.grid-line.horizontal line')[0][n]); }; + var nthGridLine = function (n) { return d3.select(chart.selectAll('.grid-line.horizontal line').nodes()[n]); }; expect(chart.selectAll('.grid-line.horizontal line').size()).toBe(3); expect(nthGridLine(0).attr('y2')).toBe('130'); @@ -351,7 +351,7 @@ describe('dc.coordinateGridChart', function () { describe('vertical grid lines', function () { it('should draw lines associated with the data shown on the x-axis', function () { - var nthGridLine = function (n) { return d3.select(chart.selectAll('.grid-line.vertical line')[0][n]); }; + var nthGridLine = function (n) { return d3.select(chart.selectAll('.grid-line.vertical line').nodes()[n]); }; expect(chart.selectAll('.grid-line.vertical line').size()).toBe(13); expect(nthGridLine(0).attr('x2')).toBe('0'); @@ -374,7 +374,7 @@ describe('dc.coordinateGridChart', function () { }); it('should draw lines associated with the data using the custom ticks', function () { - var nthGridLine = function (n) { return d3.select(chart.selectAll('.grid-line.vertical line')[0][n]); }; + var nthGridLine = function (n) { return d3.select(chart.selectAll('.grid-line.vertical line').nodes()[n]); }; expect(chart.selectAll('.grid-line.vertical line').size()).toBe(3); expect(nthGridLine(0).attr('x2')).toBeWithinDelta(6, 1); diff --git a/spec/data-addition-spec.js b/spec/data-addition-spec.js index 1b6e618e7..67f0fa540 100644 --- a/spec/data-addition-spec.js +++ b/spec/data-addition-spec.js @@ -48,14 +48,14 @@ describe('Dynamic data addition in crossfilter', function () { expect(chart.selectAll('svg g g.pie-slice path').data().length).toEqual(7); }); it('default function should be used to dynamically generate label', function () { - expect(d3.select(chart.selectAll('text.pie-slice')[0][0]).text()).toEqual('11'); + expect(d3.select(chart.selectAll('text.pie-slice').nodes()[0]).text()).toEqual('11'); }); it('pie chart slices should be in numerical order', function () { expect(chart.selectAll('text.pie-slice').data().map(function (slice) { return slice.data.key; })) .toEqual(['11','22','33','44','55','66','76']); }); it('default function should be used to dynamically generate title', function () { - expect(d3.select(chart.selectAll('g.pie-slice title')[0][0]).text()).toEqual('11: 1'); + expect(d3.select(chart.selectAll('g.pie-slice title').nodes()[0]).text()).toEqual('11: 1'); }); afterEach(function () { valueDimension.filterAll(); @@ -89,7 +89,7 @@ describe('Dynamic data addition in crossfilter', function () { chart.render(); }); it('number of dots should equal the size of the group', function () { - expect(chart.selectAll('circle.dot')[0].length).toEqual(timeGroup.size()); + expect(chart.selectAll('circle.dot').nodes().length).toEqual(timeGroup.size()); }); it('number of line segments should equal the size of the group', function () { var path = chart.selectAll('path.line').attr('d'); diff --git a/spec/data-grid-spec.js b/spec/data-grid-spec.js index 759fa73cd..20b9b4971 100644 --- a/spec/data-grid-spec.js +++ b/spec/data-grid-spec.js @@ -49,17 +49,17 @@ describe('dc.dataGrid', function () { expect(chart.order()).toBe(d3.descending); }); it('sets the group label', function () { - expect(chart.selectAll('.dc-grid-group h1.dc-grid-label')[0][0].innerHTML).toEqual('Data Grid'); + expect(chart.selectAll('.dc-grid-group h1.dc-grid-label').nodes()[0].innerHTML).toEqual('Data Grid'); }); it('creates id div', function () { - expect(chart.selectAll('.dc-grid-item div#id_9')[0].length).toEqual(1); - expect(chart.selectAll('.dc-grid-item div#id_8')[0].length).toEqual(1); - expect(chart.selectAll('.dc-grid-item div#id_3')[0].length).toEqual(1); + expect(chart.selectAll('.dc-grid-item div#id_9').nodes().length).toEqual(1); + expect(chart.selectAll('.dc-grid-item div#id_8').nodes().length).toEqual(1); + expect(chart.selectAll('.dc-grid-item div#id_3').nodes().length).toEqual(1); }); it('creates div content', function () { - expect(chart.selectAll('.dc-grid-item div')[0][0].innerHTML).toEqual('Mississippi:44'); - expect(chart.selectAll('.dc-grid-item div')[0][1].innerHTML).toEqual('Mississippi:33'); - expect(chart.selectAll('.dc-grid-item div')[0][2].innerHTML).toEqual('Delaware:33'); + expect(chart.selectAll('.dc-grid-item div').nodes()[0].innerHTML).toEqual('Mississippi:44'); + expect(chart.selectAll('.dc-grid-item div').nodes()[1].innerHTML).toEqual('Mississippi:33'); + expect(chart.selectAll('.dc-grid-item div').nodes()[2].innerHTML).toEqual('Delaware:33'); }); }); @@ -70,14 +70,14 @@ describe('dc.dataGrid', function () { }); it('slice beginning', function () { - expect(chart.selectAll('.dc-grid-item')[0].length).toEqual(2); + expect(chart.selectAll('.dc-grid-item').nodes().length).toEqual(2); }); it('slice beginning and end', function () { chart.endSlice(2); chart.redraw(); - expect(chart.selectAll('.dc-grid-item')[0].length).toEqual(1); + expect(chart.selectAll('.dc-grid-item').nodes().length).toEqual(1); }); }); @@ -87,11 +87,11 @@ describe('dc.dataGrid', function () { chart.redraw(); }); it('renders only filtered data set', function () { - expect(chart.selectAll('.dc-grid-item div')[0].length).toEqual(2); + expect(chart.selectAll('.dc-grid-item div').nodes().length).toEqual(2); }); it('renders the correctly filtered records', function () { - expect(chart.selectAll('.dc-grid-item div')[0][0].innerHTML).toEqual('Ontario:22'); - expect(chart.selectAll('.dc-grid-item div')[0][1].innerHTML).toEqual('Ontario:55'); + expect(chart.selectAll('.dc-grid-item div').nodes()[0].innerHTML).toEqual('Ontario:22'); + expect(chart.selectAll('.dc-grid-item div').nodes()[1].innerHTML).toEqual('Ontario:55'); }); }); diff --git a/spec/data-table-spec.js b/spec/data-table-spec.js index 9b7eb5232..36918c350 100644 --- a/spec/data-table-spec.js +++ b/spec/data-table-spec.js @@ -62,20 +62,20 @@ describe('dc.dataTable', function () { expect(chart.group()).toEqual(valueGroup); }); it('group tr should not be undefined', function () { - expect(typeof(chart.selectAll('tr.dc-table-group')[0][0])).not.toBe('undefined'); + expect(typeof(chart.selectAll('tr.dc-table-group').nodes()[0])).not.toBe('undefined'); }); it('sets column span set on group tr', function () { - expect(chart.selectAll('tr.dc-table-group td')[0][0].getAttribute('colspan')).toEqual('2'); + expect(chart.selectAll('tr.dc-table-group td').nodes()[0].getAttribute('colspan')).toEqual('2'); }); it('creates id column', function () { - expect(chart.selectAll('td._0')[0][0].innerHTML).toEqual('9'); - expect(chart.selectAll('td._0')[0][1].innerHTML).toEqual('8'); - expect(chart.selectAll('td._0')[0][2].innerHTML).toEqual('3'); + expect(chart.selectAll('td._0').nodes()[0].innerHTML).toEqual('9'); + expect(chart.selectAll('td._0').nodes()[1].innerHTML).toEqual('8'); + expect(chart.selectAll('td._0').nodes()[2].innerHTML).toEqual('3'); }); it('creates status column', function () { - expect(chart.selectAll('td._1')[0][0].innerHTML).toEqual('T'); - expect(chart.selectAll('td._1')[0][1].innerHTML).toEqual('F'); - expect(chart.selectAll('td._1')[0][2].innerHTML).toEqual('T'); + expect(chart.selectAll('td._1').nodes()[0].innerHTML).toEqual('T'); + expect(chart.selectAll('td._1').nodes()[1].innerHTML).toEqual('F'); + expect(chart.selectAll('td._1').nodes()[2].innerHTML).toEqual('T'); }); }); @@ -86,14 +86,14 @@ describe('dc.dataTable', function () { }); it('slice beginning', function () { - expect(chart.selectAll('tr.dc-table-row')[0].length).toEqual(2); + expect(chart.selectAll('tr.dc-table-row').nodes().length).toEqual(2); }); it('slice beginning and end', function () { chart.endSlice(2); chart.redraw(); - expect(chart.selectAll('tr.dc-table-row')[0].length).toEqual(1); + expect(chart.selectAll('tr.dc-table-row').nodes().length).toEqual(1); }); }); @@ -103,11 +103,11 @@ describe('dc.dataTable', function () { chart.redraw(); }); it('renders only filtered data set', function () { - expect(chart.selectAll('td._0')[0].length).toEqual(2); + expect(chart.selectAll('td._0').nodes().length).toEqual(2); }); it('renders the correctly filtered records', function () { - expect(chart.selectAll('td._0')[0][0].innerHTML).toEqual('7'); - expect(chart.selectAll('td._0')[0][1].innerHTML).toEqual('5'); + expect(chart.selectAll('td._0').nodes()[0].innerHTML).toEqual('7'); + expect(chart.selectAll('td._0').nodes()[1].innerHTML).toEqual('5'); }); }); @@ -117,7 +117,7 @@ describe('dc.dataTable', function () { chart.redraw(); }); it('uses dimension.bottom() instead of top()', function () { - expect(chart.selectAll('td._0')[0][0].innerHTML).toEqual('1'); + expect(chart.selectAll('td._0').nodes()[0].innerHTML).toEqual('1'); }); }); }); @@ -149,13 +149,13 @@ describe('dc.dataTable', function () { chart.render(); }); it('should render value and capitalized header', function () { - var cols = chart.selectAll('td.dc-table-column')[0].map(function (d) {return d.textContent;}); + var cols = chart.selectAll('td.dc-table-column').nodes().map(function (d) {return d.textContent;}); var expected = ['Mississippi', 'Mississippi', 'Delaware']; expect(cols.length).toEqual(expected.length); expected.forEach(function (d) { expect(cols).toContain(d); }); - var colheader = chart.selectAll('th.dc-table-head')[0].map(function (d) {return d.textContent;}); + var colheader = chart.selectAll('th.dc-table-head').nodes().map(function (d) {return d.textContent;}); expect(colheader.length).toEqual(1); expect(colheader[0]).toEqual('State'); @@ -167,13 +167,13 @@ describe('dc.dataTable', function () { chart.render(); }); it('should render function result and no header', function () { - var cols = chart.selectAll('td.dc-table-column')[0].map(function (d) {return d.textContent;}); + var cols = chart.selectAll('td.dc-table-column').nodes().map(function (d) {return d.textContent;}); var expected = ['9test', '8test', '3test']; expect(cols.length).toEqual(expected.length); expected.forEach(function (d) { expect(cols).toContain(d); }); - var colheader = chart.selectAll('th.dc-table-head')[0].map(function (d) {return d.textContent;}); + var colheader = chart.selectAll('th.dc-table-head').nodes().map(function (d) {return d.textContent;}); expect(colheader.length).toEqual(0); }); }); @@ -198,7 +198,7 @@ describe('dc.dataTable', function () { }); it('should render correct values in rows', function () { - var cols = chart.selectAll('td.dc-table-column')[0].map(function (d) {return d.textContent;}); + var cols = chart.selectAll('td.dc-table-column').nodes().map(function (d) {return d.textContent;}); var expected = ['test9', 'test8', 'test3']; expect(cols.length).toEqual(expected.length); expected.forEach(function (d, i) { @@ -239,7 +239,7 @@ describe('dc.dataTable', function () { chart.render(); }); it('group tr should be undefined', function () { - expect(typeof(chart.selectAll('tr.dc-table-group')[0][0])).toBe('undefined'); + expect(typeof(chart.selectAll('tr.dc-table-group').nodes()[0])).toBe('undefined'); }); }); diff --git a/spec/geo-choropleth-chart-spec.js b/spec/geo-choropleth-chart-spec.js index 4d23a04d6..309fc0a48 100644 --- a/spec/geo-choropleth-chart-spec.js +++ b/spec/geo-choropleth-chart-spec.js @@ -89,64 +89,64 @@ describe('dc.geoChoropleth', function () { expect(chart.selectAll('g.layer0').length).not.toEqual(0); }); it('correct number of states should be generated', function () { - expect(chart.selectAll('g.layer0 g.state')[0].length).toEqual(52); + expect(chart.selectAll('g.layer0 g.state').nodes().length).toEqual(52); }); it('correct css class should be set [Alaska]', function () { - expect(chart.selectAll('g.layer0 g.state')[0][1].getAttribute('class')).toEqual('state alaska'); + expect(chart.selectAll('g.layer0 g.state').nodes()[1].getAttribute('class')).toEqual('state alaska'); }); it('correct title should be set [Alaska]', function () { - expect(chart.selectAll('g.layer0 g.state title')[0][1].textContent).toEqual('Alaska : 0'); + expect(chart.selectAll('g.layer0 g.state title').nodes()[1].textContent).toEqual('Alaska : 0'); }); it('correct color filling should be set [Alaska]', function () { - expect(chart.selectAll('g.layer0 g.state path')[0][1].getAttribute('fill')).toMatch(/#ccc/i); + expect(chart.selectAll('g.layer0 g.state path').nodes()[1].getAttribute('fill')).toMatch(/#ccc/i); }); it('correct state boundary should be rendered [Alaska]', function () { - expect(chart.selectAll('g.layer0 g.state path')[0][1].getAttribute('d').length).not.toEqual(0); + expect(chart.selectAll('g.layer0 g.state path').nodes()[1].getAttribute('d').length).not.toEqual(0); }); it('correct css class should be set [California]', function () { - expect(chart.selectAll('g.layer0 g.state')[0][4].getAttribute('class')).toEqual('state california'); + expect(chart.selectAll('g.layer0 g.state').nodes()[4].getAttribute('class')).toEqual('state california'); }); it('correct css class should be set [District of Columbia]', function () { - expect(chart.selectAll('g.layer0 g.state')[0][8].getAttribute('class')).toEqual('state district_of_columbia'); + expect(chart.selectAll('g.layer0 g.state').nodes()[8].getAttribute('class')).toEqual('state district_of_columbia'); }); it('correct title should be set [California]', function () { - expect(chart.selectAll('g.layer0 g.state title')[0][4].textContent).toEqual('California : 154'); + expect(chart.selectAll('g.layer0 g.state title').nodes()[4].textContent).toEqual('California : 154'); }); it('correct color should be set [California]', function () { - expect(chart.selectAll('g.layer0 g.state path')[0][4].getAttribute('fill')).toMatch(/#0089ff/i); + expect(chart.selectAll('g.layer0 g.state path').nodes()[4].getAttribute('fill')).toMatch(/#0089ff/i); }); it('correct state boundary should be rendered [California]', function () { - expect(chart.selectAll('g.layer0 g.state path')[0][4].getAttribute('d').length).not.toEqual(0); + expect(chart.selectAll('g.layer0 g.state path').nodes()[4].getAttribute('d').length).not.toEqual(0); }); it('correct css class should be set [Colorado]', function () { - expect(chart.selectAll('g.layer0 g.state')[0][5].getAttribute('class')).toEqual('state colorado'); + expect(chart.selectAll('g.layer0 g.state').nodes()[5].getAttribute('class')).toEqual('state colorado'); }); it('correct title should be set [Colorado]', function () { - expect(chart.selectAll('g.layer0 g.state title')[0][5].textContent).toEqual('Colorado : 22'); + expect(chart.selectAll('g.layer0 g.state title').nodes()[5].textContent).toEqual('Colorado : 22'); }); it('correct color should be set [Colorado]', function () { - expect(chart.selectAll('g.layer0 g.state path')[0][5].getAttribute('fill')).toMatch(/#e2f2ff/i); + expect(chart.selectAll('g.layer0 g.state path').nodes()[5].getAttribute('fill')).toMatch(/#e2f2ff/i); }); it('correct state boundary should be rendered [Colorado]', function () { - expect(chart.selectAll('g.layer0 g.state path')[0][5].getAttribute('d').length).not.toEqual(0); + expect(chart.selectAll('g.layer0 g.state path').nodes()[5].getAttribute('d').length).not.toEqual(0); }); it('geo layer1 g is created', function () { expect(chart.selectAll('g.layer1').length).not.toEqual(0); }); it('correct number of counties should be generated', function () { - expect(chart.selectAll('g.layer1 g.county')[0].length).toEqual(5); + expect(chart.selectAll('g.layer1 g.county').nodes().length).toEqual(5); }); it('correct css class should be set [county]', function () { - expect(chart.selectAll('g.layer1 g.county')[0][1].getAttribute('class')).toEqual('county'); + expect(chart.selectAll('g.layer1 g.county').nodes()[1].getAttribute('class')).toEqual('county'); }); it('correct title should be set [county]', function () { - expect(chart.selectAll('g.layer1 g.county title')[0][1].textContent).toEqual(''); + expect(chart.selectAll('g.layer1 g.county title').nodes()[1].textContent).toEqual(''); }); it('correct color filling should be set [county]', function () { - expect(chart.selectAll('g.layer1 g.county path')[0][1].getAttribute('fill')).toEqual('white'); + expect(chart.selectAll('g.layer1 g.county path').nodes()[1].getAttribute('fill')).toEqual('white'); }); it('correct state boundary should be rendered [county]', function () { - expect(chart.selectAll('g.layer1 g.county path')[0][1].getAttribute('d').length).not.toEqual(0); + expect(chart.selectAll('g.layer1 g.county path').nodes()[1].getAttribute('d').length).not.toEqual(0); }); }); @@ -160,12 +160,12 @@ describe('dc.geoChoropleth', function () { }); it('sets deselected classes for some states', function () { - expect(chart.selectAll('g.layer0 g.state')[0][0].getAttribute('class')).toEqual('state alabama deselected'); - expect(chart.selectAll('g.layer0 g.state')[0][1].getAttribute('class')).toEqual('state alaska deselected'); + expect(chart.selectAll('g.layer0 g.state').nodes()[0].getAttribute('class')).toEqual('state alabama deselected'); + expect(chart.selectAll('g.layer0 g.state').nodes()[1].getAttribute('class')).toEqual('state alaska deselected'); }); it('sets selected classes for selected states', function () { - expect(chart.selectAll('g.layer0 g.state')[0][4].getAttribute('class')).toEqual('state california selected'); - expect(chart.selectAll('g.layer0 g.state')[0][5].getAttribute('class')).toEqual('state colorado selected'); + expect(chart.selectAll('g.layer0 g.state').nodes()[4].getAttribute('class')).toEqual('state california selected'); + expect(chart.selectAll('g.layer0 g.state').nodes()[5].getAttribute('class')).toEqual('state colorado selected'); }); }); diff --git a/spec/heatmap-spec.js b/spec/heatmap-spec.js index aa4a626b9..ae5ecf453 100644 --- a/spec/heatmap-spec.js +++ b/spec/heatmap-spec.js @@ -565,7 +565,7 @@ describe('dc.heatmap', function () { } function testRectFillsBubble12 (chart) { - var rects = chart.selectAll('rect')[0]; + var rects = chart.selectAll('rect').nodes(); expect(d3.select(rects[0]).attr('fill')).toMatch(/#f8f8f8/i); expect(d3.select(rects[3]).attr('fill')).toMatch(/#377eb8/i); expect(d3.select(rects[4]).attr('fill')).toMatch(/#377eb8/i); @@ -576,7 +576,7 @@ describe('dc.heatmap', function () { expect(d3.select(rects[12]).attr('fill')).toMatch(/#f8f8f8/i); } function testRectTitlesBubble12 (chart) { - var titles = chart.selectAll('g.box-group title')[0]; + var titles = chart.selectAll('g.box-group title').nodes(); expect(JSON.parse(d3.select(titles[0]).text()).total).toBe(0); expect(JSON.parse(d3.select(titles[2]).text()).total).toBe(0); expect(JSON.parse(d3.select(titles[3]).text()).total).toBe(2); diff --git a/spec/legend-spec.js b/spec/legend-spec.js index 200b65f1d..74dd01436 100644 --- a/spec/legend-spec.js +++ b/spec/legend-spec.js @@ -260,7 +260,7 @@ describe('dc.legend', function () { it('disable hover highlighting for that legend item', function () { legendItem(0).on('mouseover')(legendItem(0).datum()); - expect(d3.select(chart.selectAll('path.line')[0][1]).classed('fadeout')).toBeFalsy(); + expect(d3.select(chart.selectAll('path.line').nodes()[1]).classed('fadeout')).toBeFalsy(); }); describe('clicking on a faded out legend item', function () { @@ -280,16 +280,16 @@ describe('dc.legend', function () { }); function legendItem (n) { - return d3.select(chart.selectAll('g.dc-legend g.dc-legend-item')[0][n]); + return d3.select(chart.selectAll('g.dc-legend g.dc-legend-item').nodes()[n]); } function legendLabel (n) { - return d3.select(chart.selectAll('g.dc-legend g.dc-legend-item text')[0][n]); + return d3.select(chart.selectAll('g.dc-legend g.dc-legend-item text').nodes()[n]); } function legendIcon (n) { - return d3.select(chart.selectAll('g.dc-legend g.dc-legend-item rect')[0][n]); + return d3.select(chart.selectAll('g.dc-legend g.dc-legend-item rect').nodes()[n]); } function legendLine (n) { - return d3.select(chart.selectAll('g.dc-legend g.dc-legend-item line')[0][n]); + return d3.select(chart.selectAll('g.dc-legend g.dc-legend-item line').nodes()[n]); } }); diff --git a/spec/line-chart-spec.js b/spec/line-chart-spec.js index c7f7875a0..dc7dd39b9 100644 --- a/spec/line-chart-spec.js +++ b/spec/line-chart-spec.js @@ -558,7 +558,7 @@ describe('dc.lineChart', function () { }); it('should generate y axis domain dynamically', function () { - var nthText = function (n) { return d3.select(chart.selectAll('g.axis.y .tick text')[0][n]); }; + var nthText = function (n) { return d3.select(chart.selectAll('g.axis.y .tick text').nodes()[n]); }; expect(nthText(0).text()).toBe('-20'); expect(nthText(1).text()).toBe('0'); @@ -592,7 +592,7 @@ describe('dc.lineChart', function () { }); it('should generate y axis domain dynamically', function () { - var nthText = function (n) { return d3.select(chart.selectAll('g.axis.y .tick text')[0][n]); }; + var nthText = function (n) { return d3.select(chart.selectAll('g.axis.y .tick text').nodes()[n]); }; expect(nthText(0).text()).toBe('-30'); expect(nthText(1).text()).toBe('-20'); @@ -642,11 +642,11 @@ describe('dc.lineChart', function () { }); function nthLine (n) { - return d3.select(chart.selectAll('path.line')[0][n]); + return d3.select(chart.selectAll('path.line').nodes()[n]); } function nthArea (n) { - return d3.select(chart.selectAll('path.area')[0][n]); + return d3.select(chart.selectAll('path.area').nodes()[n]); } }); @@ -750,7 +750,7 @@ describe('dc.lineChart', function () { function lineLabelPositions () { var LABEL_PADDING = 3; - chart.selectAll('.stack')[0].forEach(function (stack, i) { + chart.selectAll('.stack').nodes().forEach(function (stack, i) { d3.select(stack).selectAll('text.lineLabel')[0].forEach(function (lineLabel, j) { expect(+d3.select(lineLabel).attr('x')).toBeCloseTo(chart.x()(chart.data()[i].values[j].x)); expect(+d3.select(lineLabel).attr('y') + LABEL_PADDING).toBeCloseTo(chart.y()(chart.data()[i].values[j].y + diff --git a/spec/row-chart-spec.js b/spec/row-chart-spec.js index c42a83ece..548ee18f6 100644 --- a/spec/row-chart-spec.js +++ b/spec/row-chart-spec.js @@ -117,11 +117,11 @@ describe('dc.rowChart', function () { }); it('should fill each row rect with pre-defined colors', function () { - expect(d3.select(chart.selectAll('g.row rect')[0][0]).attr('fill')).toMatch(/#3182bd/i); - expect(d3.select(chart.selectAll('g.row rect')[0][1]).attr('fill')).toMatch(/#6baed6/i); - expect(d3.select(chart.selectAll('g.row rect')[0][2]).attr('fill')).toMatch(/#9ecae1/i); - expect(d3.select(chart.selectAll('g.row rect')[0][3]).attr('fill')).toMatch(/#c6dbef/i); - expect(d3.select(chart.selectAll('g.row rect')[0][4]).attr('fill')).toMatch(/#e6550d/i); + expect(d3.select(chart.selectAll('g.row rect').nodes()[0]).attr('fill')).toMatch(/#3182bd/i); + expect(d3.select(chart.selectAll('g.row rect').nodes()[1]).attr('fill')).toMatch(/#6baed6/i); + expect(d3.select(chart.selectAll('g.row rect').nodes()[2]).attr('fill')).toMatch(/#9ecae1/i); + expect(d3.select(chart.selectAll('g.row rect').nodes()[3]).attr('fill')).toMatch(/#c6dbef/i); + expect(d3.select(chart.selectAll('g.row rect').nodes()[4]).attr('fill')).toMatch(/#e6550d/i); }); it('should create a row label from the data for each row', function () { @@ -381,7 +381,7 @@ describe('dc.rowChart', function () { }); it('should generate x axis domain dynamically', function () { - var nthText = function (n) { return d3.select(chart.selectAll('g.axis .tick text')[0][n]); }; + var nthText = function (n) { return d3.select(chart.selectAll('g.axis .tick text').nodes()[n]); }; for (var i = 0; i < xAxisTicks.length; i++) { expect(nthText(i).text()).toBe(xAxisTicks[i]); diff --git a/spec/scatter-plot-spec.js b/spec/scatter-plot-spec.js index 1f5eb4863..dc1620755 100644 --- a/spec/scatter-plot-spec.js +++ b/spec/scatter-plot-spec.js @@ -127,7 +127,7 @@ describe('dc.scatterPlot', function () { }); function nthSymbol (i) { - return d3.select(chart.selectAll('path.symbol')[0][i]); + return d3.select(chart.selectAll('path.symbol').nodes()[i]); } describe('filtering the chart', function () { @@ -430,7 +430,7 @@ describe('dc.scatterPlot', function () { }); function nthChart (n) { - var subChart = d3.select(compositeChart.selectAll('g.sub')[0][n]); + var subChart = d3.select(compositeChart.selectAll('g.sub').nodes()[n]); subChart.expectPlotSymbolsToHaveClass = function (className) { subChart.selectAll('path.symbol').each(function () { diff --git a/spec/select-menu-spec.js b/spec/select-menu-spec.js index 51a688b00..0a8cc04b8 100644 --- a/spec/select-menu-spec.js +++ b/spec/select-menu-spec.js @@ -53,16 +53,16 @@ describe('dc.selectMenu', function () { expect(chart.selectAll('select').attr('size')).toEqual('10'); }); it('creates prompt option with empty value', function () { - var option = chart.selectAll('option')[0][0]; + var option = chart.selectAll('option').nodes()[0]; expect(option).not.toBeNull(); expect(option.value).toEqual(''); }); it('creates prompt option with default prompt text', function () { - var option = chart.selectAll('option')[0][0]; + var option = chart.selectAll('option').nodes()[0]; expect(option.text).toEqual('Select all'); }); it('creates correct number of options', function () { - expect(chart.selectAll('option.dc-select-option')[0].length).toEqual(stateGroup.all().length); + expect(chart.selectAll('option.dc-select-option').nodes().length).toEqual(stateGroup.all().length); }); }); @@ -121,7 +121,7 @@ describe('dc.selectMenu', function () { it('selects option corresponding to active filter', function () { chart.onChange(stateGroup.all()[0].key); chart.redraw(); - expect(chart.selectAll('select')[0][0].value).toEqual('California'); + expect(chart.selectAll('select').nodes()[0].value).toEqual('California'); }); }); @@ -176,13 +176,13 @@ describe('dc.selectMenu', function () { it('only displays options whose value > 0 by default', function () { regionDimension.filter('South'); chart.redraw(); - expect(chart.selectAll('option.dc-select-option')[0].length).toEqual(1); + expect(chart.selectAll('option.dc-select-option').nodes().length).toEqual(1); expect(getOption(chart, 0).text).toEqual('California: 2'); }); it('can be overridden', function () { regionDimension.filter('South'); chart.filterDisplayed(function (d) { return true; }).redraw(); - expect(chart.selectAll('option.dc-select-option')[0].length).toEqual(stateGroup.all().length); + expect(chart.selectAll('option.dc-select-option').nodes().length).toEqual(stateGroup.all().length); expect(getOption(chart, stateGroup.all().length - 1).text).toEqual('Ontario: 0'); }); it('retains order with filtered options', function () { @@ -197,6 +197,6 @@ describe('dc.selectMenu', function () { }); function getOption (chart, i) { - return chart.selectAll('option.dc-select-option')[0][i]; + return chart.selectAll('option.dc-select-option').nodes()[i]; } }); From 3cc0ee2d47c7e8c4b8712d0859bc6dc4e091f44f Mon Sep 17 00:00:00 2001 From: deepak Date: Tue, 20 Feb 2018 19:38:31 +0530 Subject: [PATCH 04/42] interpolate and tension semantics have changed. --- src/line-chart.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/line-chart.js b/src/line-chart.js index b8f0b9410..c5a691cc3 100644 --- a/src/line-chart.js +++ b/src/line-chart.js @@ -39,7 +39,7 @@ dc.lineChart = function (parent, chartGroup) { var _dataPointRadius = null; var _dataPointFillOpacity = DEFAULT_DOT_OPACITY; var _dataPointStrokeOpacity = DEFAULT_DOT_OPACITY; - var _interpolate = 'linear'; + var _interpolate = d3.curveLinear; var _tension = 0.7; var _defined; var _dashStyle; @@ -187,6 +187,12 @@ dc.lineChart = function (parent, chartGroup) { return _chart.getColor.call(d, d.values, i); } + // Behavior of interpolator has changed in D3v4 + var _interpolateWithTension = function () { + return typeof _interpolate.tension === "function" ? + _interpolate.tension(_tension) : _interpolate; + }; + function drawLine (layersEnter, layers) { var line = d3.svg.line() .x(function (d) { @@ -195,8 +201,7 @@ dc.lineChart = function (parent, chartGroup) { .y(function (d) { return _chart.y()(d.y + d.y0); }) - .interpolate(_interpolate) - .tension(_tension); + .curve(_interpolateWithTension()); if (_defined) { line.defined(_defined); } @@ -228,8 +233,7 @@ dc.lineChart = function (parent, chartGroup) { .y0(function (d) { return _chart.y()(d.y0); }) - .interpolate(_interpolate) - .tension(_tension); + .curve(_interpolateWithTension()); if (_defined) { area.defined(_defined); } From 9253b902221ce9ff6894901b33b1b8991a5f6840 Mon Sep 17 00:00:00 2001 From: deepak Date: Tue, 20 Feb 2018 19:43:06 +0530 Subject: [PATCH 05/42] Updated for semantics of D3v4 .enter() Fixed test cases --- spec/select-menu-spec.js | 6 +++--- src/select-menu.js | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/spec/select-menu-spec.js b/spec/select-menu-spec.js index 0a8cc04b8..a4a83022d 100644 --- a/spec/select-menu-spec.js +++ b/spec/select-menu-spec.js @@ -36,7 +36,7 @@ describe('dc.selectMenu', function () { expect(chart.promptText()).toBe('Select all'); }); it('creates select tag', function () { - expect(chart.selectAll('select').length).toEqual(1); + expect(chart.selectAll('select').nodes().length).toEqual(1); }); it('select tag is not a multiple select by default', function () { expect(chart.selectAll('select').attr('multiple')).toBeNull(); @@ -149,7 +149,7 @@ describe('dc.selectMenu', function () { expect(regionGroup.all()[0].value).toEqual(1); }); it('selects all options corresponding to active filters on redraw', function () { - var selectedOptions = chart.selectAll('select').selectAll('option')[0].filter(function (d) { + var selectedOptions = chart.selectAll('select').selectAll('option').nodes().filter(function (d) { // IE returns an extra option with value '', not sure what it means return d.value && d.selected; }); @@ -159,7 +159,7 @@ describe('dc.selectMenu', function () { it('does not deselect previously filtered options when new option is added', function () { chart.onChange([stateGroup.all()[0].key, stateGroup.all()[1].key, stateGroup.all()[5].key]); - var selectedOptions = chart.selectAll('select').selectAll('option')[0].filter(function (d) { + var selectedOptions = chart.selectAll('select').selectAll('option').nodes().filter(function (d) { // IE returns an extra option with value '', not sure what it means return d.value && d.selected; }); diff --git a/src/select-menu.js b/src/select-menu.js index 7efd752a3..a43a4c4da 100644 --- a/src/select-menu.js +++ b/src/select-menu.js @@ -85,12 +85,13 @@ dc.selectMenu = function (parent, chartGroup) { var options = _select.selectAll('option.' + OPTION_CSS_CLASS) .data(_chart.data(), function (d) { return _chart.keyAccessor()(d); }); - options.enter() + options = options.enter() .append('option') .classed(OPTION_CSS_CLASS, true) - .attr('value', function (d) { return _chart.keyAccessor()(d); }); + .attr('value', function (d) { return _chart.keyAccessor()(d); }) + .merge(options) + .text(_chart.title()); - options.text(_chart.title()); options.exit().remove(); _select.selectAll('option.' + OPTION_CSS_CLASS).sort(_order); From 159e76850e9b0264f1c8e958a1a48889cf663452 Mon Sep 17 00:00:00 2001 From: deepak Date: Tue, 20 Feb 2018 19:47:01 +0530 Subject: [PATCH 06/42] Discovered that more D3 functions that are used. --- src/d3-compat/d3-compat02.js | 51 +++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/d3-compat/d3-compat02.js b/src/d3-compat/d3-compat02.js index 4625b875c..381afdc3b 100644 --- a/src/d3-compat/d3-compat02.js +++ b/src/d3-compat/d3-compat02.js @@ -1,23 +1,68 @@ -d3.selectAll = d3v4.selectAll; +// Simple function change package/name d3.time.format.iso = d3v4.isoFormat; +d3.time.format.utc = d3v4.utcFormat; d3.time.format.iso.parse = d3v4.isoParse; +d3.time.second = d3v4.timeSecond; +d3.time.minute = d3v4.timeMinute; +d3.time.hour = d3v4.timeHour; d3.time.day = d3v4.timeDay; +d3.time.week = d3v4.timeWeek; +d3.time.month = d3v4.timeMonth; +d3.time.year = d3v4.timeYear; + +d3.time.seconds = d3v4.timeSeconds; +d3.time.minutes = d3v4.timeMinutes; +d3.time.hours = d3v4.timeHours; +d3.time.days = d3v4.timeDays; +d3.time.weeks = d3v4.timeWeeks; +d3.time.months = d3v4.timeMonths; +d3.time.years = d3v4.timeYears; + d3.time.day.utc = d3v4.utcDay; +d3.time.days.utc = d3v4.utcDays; + +d3.time.scale = {}; +d3.time.scale.utc = d3v4.scaleUtc; + +d3.timer.flush = d3v4.timerFlush; + +d3.axisBottom = d3v4.axisBottom; +d3.axisLeft = d3v4.axisLeft; +d3.axisRight = d3v4.axisRight; + +d3.layout.stack = d3v4.stack; +d3.curveLinear = d3v4.curveLinear; + +// Selection behavior have changed significantly, need manual changes for +// each invocation of .enter() +d3.selectAll = d3v4.selectAll; + + + +// Semantic change +d3.scale.category10 = function () { + return d3v4.scaleOrdinal(d3v4.schemeCategory10); +}; d3.scale.category20c = function () { return d3v4.scaleOrdinal(d3v4.schemeCategory20c); }; + +// Missing in D3v4, code picked up from D3v3 d3.functor = function (v) { return typeof v === "function" ? v : function () { return v; }; }; + +// Behavior of d3.dispatch has changed, ultimately changes will +// be applied to code directly - thankfully used in code only once d3._dispatch_tmp_fn_gen = function (_dispatch, event) { return function () { _dispatch.apply(event, this, arguments); @@ -39,3 +84,7 @@ d3.dispatch = function () { return _out; }; + + +// Brushes - used only once, significant changes +// From e86896f2c655dee61f0694b2eb4be0e38b1cd06c Mon Sep 17 00:00:00 2001 From: deepak Date: Tue, 20 Feb 2018 23:51:16 +0530 Subject: [PATCH 07/42] Updated for semantics of D3v4 .enter() --- src/select-menu.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/select-menu.js b/src/select-menu.js index a43a4c4da..393c8528a 100644 --- a/src/select-menu.js +++ b/src/select-menu.js @@ -85,7 +85,7 @@ dc.selectMenu = function (parent, chartGroup) { var options = _select.selectAll('option.' + OPTION_CSS_CLASS) .data(_chart.data(), function (d) { return _chart.keyAccessor()(d); }); - options = options.enter() + options.enter() .append('option') .classed(OPTION_CSS_CLASS, true) .attr('value', function (d) { return _chart.keyAccessor()(d); }) @@ -96,7 +96,9 @@ dc.selectMenu = function (parent, chartGroup) { _select.selectAll('option.' + OPTION_CSS_CLASS).sort(_order); _select.on('change', onChange); - return options; + + // indicate that no one should use return value + return null; } function onChange (d, i) { From d3feee0ed7e98cd9f44b2e6034fb5b854fd3c1ed Mon Sep 17 00:00:00 2001 From: deepak Date: Wed, 21 Feb 2018 11:48:24 +0530 Subject: [PATCH 08/42] Updated for semantics of D3v4 .enter() and fixed test cases. --- Gruntfile.js | 33 ++++++++++++++++++++++++++++++++- spec/data-table-spec.js | 12 ++++++------ src/d3-compat/d3-compat02.js | 2 ++ src/data-table.js | 16 +++++++++------- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index c524a6bfb..ba9ae6c0c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -153,7 +153,38 @@ module.exports = function (grunt) { options: { display: 'short', summary: true, - specs: '<%= conf.spec %>/pie-chart-spec.js', + specs: [ + // '<%= conf.spec %>/bar-chart-spec.js', + // '<%= conf.spec %>/base-mixin-spec.js', + // '<%= conf.spec %>/biggish-data-spec.js', + // '<%= conf.spec %>/box-plot-spec.js', + // '<%= conf.spec %>/bubble-chart-spec.js', + // '<%= conf.spec %>/bubble-overlay-spec.js', + '<%= conf.spec %>/cap-mixin-spec.js', + // '<%= conf.spec %>/color-spec.js', // Need proper color matcher + // '<%= conf.spec %>/composite-chart-spec.js', + // '<%= conf.spec %>/coordinate-grid-chart-spec.js', + '<%= conf.spec %>/core-spec.js', + // '<%= conf.spec %>/data-addition-spec.js', + '<%= conf.spec %>/data-count-spec.js', + '<%= conf.spec %>/data-grid-spec.js', + '<%= conf.spec %>/data-table-spec.js', + '<%= conf.spec %>/event-spec.js', + '<%= conf.spec %>/filter-dates-spec.js', + '<%= conf.spec %>/filters-spec.js', + '<%= conf.spec %>/geo-choropleth-chart-spec.js', + // '<%= conf.spec %>/heatmap-spec.js', + // '<%= conf.spec %>/legend-spec.js', + // '<%= conf.spec %>/line-chart-spec.js', + '<%= conf.spec %>/logger-spec.js', + // '<%= conf.spec %>/number-display-spec.js', + '<%= conf.spec %>/pie-chart-spec.js', + // '<%= conf.spec %>/row-chart-spec.js', + // '<%= conf.spec %>/scatter-plot-spec.js', + '<%= conf.spec %>/select-menu-spec.js', + // '<%= conf.spec %>/series-chart-spec.js', + '<%= conf.spec %>/utils-spec.js' + ], helpers: [ '<%= conf.web %>/js/jasmine-jsreporter.js', '<%= conf.spec %>/helpers/*.js' diff --git a/spec/data-table-spec.js b/spec/data-table-spec.js index 36918c350..400663202 100644 --- a/spec/data-table-spec.js +++ b/spec/data-table-spec.js @@ -189,10 +189,10 @@ describe('dc.dataTable', function () { }); it('should produce correct table header with single column', function () { var thead = chart.selectAll('thead'); - expect(thead.length).toBe(1); + expect(thead.nodes().length).toBe(1); var tr = thead.selectAll('tr'); - expect(tr.length).toBe(1); - var colheader = tr.selectAll('th.dc-table-head')[0].map(function (d) {return d.textContent;}); + expect(tr.nodes().length).toBe(1); + var colheader = tr.selectAll('th.dc-table-head').nodes().map(function (d) {return d.textContent;}); expect(colheader.length).toEqual(1); expect(colheader[0]).toEqual('Test ID'); }); @@ -224,10 +224,10 @@ describe('dc.dataTable', function () { }); it('should produce correct table header with single column', function () { var thead = chart.selectAll('thead'); - expect(thead.length).toBe(1); + expect(thead.nodes().length).toBe(1); var tr = thead.selectAll('tr'); - expect(tr.length).toBe(1); - var colheader = tr.selectAll('th.dc-table-head')[0].map(function (d) {return d.textContent;}); + expect(tr.nodes().length).toBe(1); + var colheader = tr.selectAll('th.dc-table-head').nodes().map(function (d) {return d.textContent;}); expect(colheader.length).toEqual(1); expect(colheader[0]).toEqual('Test ID'); }); diff --git a/src/d3-compat/d3-compat02.js b/src/d3-compat/d3-compat02.js index 381afdc3b..d5fcb6206 100644 --- a/src/d3-compat/d3-compat02.js +++ b/src/d3-compat/d3-compat02.js @@ -37,6 +37,8 @@ d3.axisRight = d3v4.axisRight; d3.layout.stack = d3v4.stack; d3.curveLinear = d3v4.curveLinear; +d3.geo.mercator = d3v4.geoMercator; + // Selection behavior have changed significantly, need manual changes for // each invocation of .enter() d3.selectAll = d3v4.selectAll; diff --git a/src/data-table.js b/src/data-table.js index 108761705..ca418c0f0 100644 --- a/src/data-table.js +++ b/src/data-table.js @@ -110,25 +110,27 @@ dc.dataTable = function (parent, chartGroup) { if (!bAllFunctions) { // ensure one thead var thead = _chart.selectAll('thead').data([0]); - thead.enter().append('thead'); thead.exit().remove(); + thead = thead.enter() + .append('thead') + .merge(thead); // with one tr var headrow = thead.selectAll('tr').data([0]); - headrow.enter().append('tr'); headrow.exit().remove(); + headrow = headrow.enter() + .append('tr') + .merge(headrow); // with a th for each column var headcols = headrow.selectAll('th') .data(_columns); - headcols.enter().append('th'); headcols.exit().remove(); - - headcols - .attr('class', HEAD_CSS_CLASS) + headcols.enter().append('th') + .merge(headcols) + .attr('class', HEAD_CSS_CLASS) .html(function (d) { return (_chart._doColumnHeaderFormat(d)); - }); } From 2d624bb31d6a254f891646e122b9e4ae5172c2ff Mon Sep 17 00:00:00 2001 From: deepak Date: Wed, 21 Feb 2018 19:06:47 +0530 Subject: [PATCH 09/42] All test cases for number display and row chart passing --- Gruntfile.js | 4 ++-- spec/row-chart-spec.js | 4 ++-- src/d3-compat/d3-compat02.js | 4 ++++ src/number-display.js | 12 ++++++++---- src/row-chart.js | 7 +++++-- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index ba9ae6c0c..5d42cc9d5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -177,9 +177,9 @@ module.exports = function (grunt) { // '<%= conf.spec %>/legend-spec.js', // '<%= conf.spec %>/line-chart-spec.js', '<%= conf.spec %>/logger-spec.js', - // '<%= conf.spec %>/number-display-spec.js', + '<%= conf.spec %>/number-display-spec.js', '<%= conf.spec %>/pie-chart-spec.js', - // '<%= conf.spec %>/row-chart-spec.js', + '<%= conf.spec %>/row-chart-spec.js', // '<%= conf.spec %>/scatter-plot-spec.js', '<%= conf.spec %>/select-menu-spec.js', // '<%= conf.spec %>/series-chart-spec.js', diff --git a/spec/row-chart-spec.js b/spec/row-chart-spec.js index 548ee18f6..c2c36e35d 100644 --- a/spec/row-chart-spec.js +++ b/spec/row-chart-spec.js @@ -141,8 +141,8 @@ describe('dc.rowChart', function () { function itShouldVerticallyCenterLabelWithinRow (i) { it('should place label ' + i + ' within row ' + i, function () { - var rowpos = rows[0][i].getBoundingClientRect(), - textpos = labels[0][i].getBoundingClientRect(); + var rowpos = rows.nodes()[i].getBoundingClientRect(), + textpos = labels.nodes()[i].getBoundingClientRect(); expect((textpos.top + textpos.bottom) / 2) .toBeWithinDelta((rowpos.top + rowpos.bottom) / 2, 2); }); diff --git a/src/d3-compat/d3-compat02.js b/src/d3-compat/d3-compat02.js index d5fcb6206..4c007b9e8 100644 --- a/src/d3-compat/d3-compat02.js +++ b/src/d3-compat/d3-compat02.js @@ -28,6 +28,10 @@ d3.time.days.utc = d3v4.utcDays; d3.time.scale = {}; d3.time.scale.utc = d3v4.scaleUtc; +d3.easeQuadIn = d3v4.easeQuadIn; + +d3.scale.log = d3v4.scaleLog; + d3.timer.flush = d3v4.timerFlush; d3.axisBottom = d3v4.axisBottom; diff --git a/src/number-display.js b/src/number-display.js index a19e891cb..4b79d73f7 100644 --- a/src/number-display.js +++ b/src/number-display.js @@ -102,19 +102,23 @@ dc.numberDisplay = function (parent, chartGroup) { if (span.empty()) { span = span.data([0]) .enter() - .append('span') - .attr('class', SPAN_CLASS); + .append('span') + .attr('class', SPAN_CLASS) + .merge(span); } span.transition() .duration(_chart.transitionDuration()) .delay(_chart.transitionDelay()) - .ease('quad-out-in') + .ease(d3.easeQuadIn) .tween('text', function () { // [XA] don't try and interpolate from Infinity, else this breaks. var interpStart = isFinite(_lastValue) ? _lastValue : 0; var interp = d3.interpolateNumber(interpStart || 0, newValue); _lastValue = newValue; + + // need to save it in D3v4 + var node = this; return function (t) { var html = null, num = _chart.formatNumber()(interp(t)); if (newValue === 0 && (_html.none !== '')) { @@ -124,7 +128,7 @@ dc.numberDisplay = function (parent, chartGroup) { } else if (_html.some !== '') { html = _html.some; } - this.innerHTML = html ? html.replace('%number', num) : num; + node.innerHTML = html ? html.replace('%number', num) : num; }; }); }; diff --git a/src/row-chart.js b/src/row-chart.js index a89cc19fd..95c4a76ec 100644 --- a/src/row-chart.js +++ b/src/row-chart.js @@ -44,7 +44,7 @@ dc.rowChart = function (parent, chartGroup) { var _elasticX; - var _xAxis = d3.svg.axis().orient('bottom'); + var _xAxis = d3.axisBottom(); var _rowData; @@ -140,8 +140,9 @@ dc.rowChart = function (parent, chartGroup) { var rows = _g.selectAll('g.' + _rowCssClass) .data(_rowData); - createElements(rows); removeElements(rows); + rows = createElements(rows) + .merge(rows); updateElements(rows); } @@ -155,6 +156,8 @@ dc.rowChart = function (parent, chartGroup) { rowEnter.append('rect').attr('width', 0); createLabels(rowEnter); + + return rowEnter; } function removeElements (rows) { From 5561b742e35c85a6252f45beedc3597c0156b928 Mon Sep 17 00:00:00 2001 From: deepak Date: Wed, 21 Feb 2018 20:05:59 +0530 Subject: [PATCH 10/42] Tests passing --- spec/base-mixin-spec.js | 2 +- spec/bubble-overlay-spec.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/base-mixin-spec.js b/spec/base-mixin-spec.js index baa4bc5a3..e626ac23d 100644 --- a/spec/base-mixin-spec.js +++ b/spec/base-mixin-spec.js @@ -358,7 +358,7 @@ describe('dc.baseMixin', function () { beforeEach(function () { dimdiv = appendChartID('dimensionTest'); chart.anchor('#dimensionTest'); - bodyWidth = d3.select('body')[0][0].getBoundingClientRect().width; + bodyWidth = d3.select('body').nodes()[0].getBoundingClientRect().width; }); describe('when set to a falsy on a sized div', function () { diff --git a/spec/bubble-overlay-spec.js b/spec/bubble-overlay-spec.js index cecb13b03..b2df8218d 100644 --- a/spec/bubble-overlay-spec.js +++ b/spec/bubble-overlay-spec.js @@ -12,7 +12,8 @@ describe('dc.bubbleOverlay', function () { var parent = appendChartID(id); var width = 600, height = 400; var svg = parent.append('svg') - .attr({width: width, height: height}); + .attr('width', width) + .attr('height', height); chart = dc.bubbleOverlay('#' + id) .svg(svg) From 7d8e1964054a40cfcfbabe77b0927b768759a55d Mon Sep 17 00:00:00 2001 From: deepak Date: Fri, 23 Feb 2018 19:41:58 +0530 Subject: [PATCH 11/42] Axis, Scales - temp --- spec/coordinate-grid-chart-spec.js | 10 ++++++---- src/coordinate-grid-mixin.js | 29 +++++++++++++++++++---------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/spec/coordinate-grid-chart-spec.js b/spec/coordinate-grid-chart-spec.js index dd1ff0813..64bf78035 100644 --- a/spec/coordinate-grid-chart-spec.js +++ b/spec/coordinate-grid-chart-spec.js @@ -406,9 +406,10 @@ describe('dc.coordinateGridChart', function () { expect(chart.selectAll('.axis.y').size()).toBe(1); }); - it('should orient the y-axis text to the left by default', function () { + // No longer valid in D3v4 + /*it('should orient the y-axis text to the left by default', function () { expect(chart.yAxis().orient()).toBe('left'); - }); + });*/ it('should place the y axis to the left', function () { expect(chart.select('g.y').attr('transform')).toMatchTranslate(0, 20); @@ -453,9 +454,10 @@ describe('dc.coordinateGridChart', function () { expect(chart.selectAll('.axis.y').size()).toBe(1); }); - it('should orient the y-axis text to the right', function () { + // Not applicable in D3v4 + /*it('should orient the y-axis text to the right', function () { expect(chart.yAxis().orient()).toBe('right'); - }); + });*/ it('should position the axis to the right of the chart', function () { expect(chart.select('.axis.y').attr('transform')).toMatchTranslate(490, 20); diff --git a/src/coordinate-grid-mixin.js b/src/coordinate-grid-mixin.js index 2e91f0cbb..73746d8a4 100644 --- a/src/coordinate-grid-mixin.js +++ b/src/coordinate-grid-mixin.js @@ -28,7 +28,7 @@ dc.coordinateGridMixin = function (_chart) { var _x; var _xOriginalDomain; - var _xAxis = d3.svg.axis().orient('bottom'); + var _xAxis = d3.axisBottom(); var _xUnits = dc.units.integers; var _xAxisPadding = 0; var _xAxisPaddingUnit = 'day'; @@ -38,7 +38,7 @@ dc.coordinateGridMixin = function (_chart) { var _lastXDomain; var _y; - var _yAxis = d3.svg.axis().orient('left'); + var _yAxis; var _yAxisPadding = 0; var _yElasticity = false; var _yAxisLabel; @@ -459,6 +459,9 @@ dc.coordinateGridMixin = function (_chart) { _x.domain([_chart.xAxisMin(), _chart.xAxisMax()]); } } else { // _chart.isOrdinal() + // D3v4 - find better place to put it + // It is special subclass that support rangeBands + _x = d3.scaleBand(); if (_chart.elasticX() || _x.domain().length === 0) { _x.domain(_chart._ordinalXDomain()); } @@ -473,8 +476,9 @@ dc.coordinateGridMixin = function (_chart) { // please can't we always use rangeBands for bar charts? if (_chart.isOrdinal()) { - _x.rangeBands([0, _chart.xAxisLength()], _rangeBandPadding, - _chart._useOuterPadding() ? _outerRangeBandPadding : 0); + _x.range([0, _chart.xAxisLength()]) + .paddingInner(_rangeBandPadding) + .paddingOuter(_chart._useOuterPadding() ? _outerRangeBandPadding : 0); } else { _x.range([0, _chart.xAxisLength()]); } @@ -545,7 +549,8 @@ dc.coordinateGridMixin = function (_chart) { .attr('opacity', 1); // update - dc.transition(lines, _chart.transitionDuration(), _chart.transitionDelay()) + var linesGEnterUpdate = linesGEnter.merge(lines); + dc.transition(linesGEnterUpdate, _chart.transitionDuration(), _chart.transitionDelay()) .attr('x1', function (d) { return _x(d); }) @@ -592,6 +597,13 @@ dc.coordinateGridMixin = function (_chart) { }; _chart._prepareYAxis = function (g) { + // D3v4 - consider dropping _useRightYAxis + if (_useRightYAxis) { + _yAxis = d3.axisRight(); + } else { + _yAxis = d3.axisLeft(); + } + if (_y === undefined || _chart.elasticY()) { if (_y === undefined) { _y = d3.scale.linear(); @@ -604,10 +616,6 @@ dc.coordinateGridMixin = function (_chart) { _y.range([_chart.yAxisHeight(), 0]); _yAxis = _yAxis.scale(_y); - if (_useRightYAxis) { - _yAxis.orient('right'); - } - _chart._renderHorizontalGridLinesForAxis(g, _y, _yAxis); }; @@ -682,7 +690,8 @@ dc.coordinateGridMixin = function (_chart) { .attr('opacity', 1); // update - dc.transition(lines, _chart.transitionDuration(), _chart.transitionDelay()) + var linesGEnterUpdate = linesGEnter.merge(lines); + dc.transition(linesGEnterUpdate, _chart.transitionDuration(), _chart.transitionDelay()) .attr('x1', 1) .attr('y1', function (d) { return scale(d); From 0d3c23833ec57e03ea2961a9870196acc7bcca79 Mon Sep 17 00:00:00 2001 From: deepak Date: Sun, 25 Feb 2018 21:38:44 +0530 Subject: [PATCH 12/42] Added d3-compat to examples --- web/crime/index.html | 2 +- web/ep/index.html | 2 +- web/examples/align-axes.html | 2 +- web/examples/area.html | 2 +- web/examples/bar-extra-line.html | 2 +- web/examples/bar-single-select.html | 2 +- web/examples/bar.html | 2 +- web/examples/box-plot-time.html | 2 +- web/examples/box-plot.html | 2 +- web/examples/complex-reduce.html | 2 +- web/examples/composite.html | 2 +- web/examples/download-table.html | 2 +- web/examples/filter-stacks.html | 2 +- web/examples/filtering-removing.html | 2 +- web/examples/filtering.html | 13 +------------ web/examples/heat.html | 2 +- web/examples/heatmap-filtering.html | 2 +- web/examples/line.html | 2 +- web/examples/multi-focus.html | 2 +- web/examples/multi-scatter.html | 2 +- web/examples/number.html | 2 +- web/examples/ordinal-bar.html | 2 +- web/examples/ordinal-line.html | 2 +- web/examples/pie-external-labels.html | 2 +- web/examples/pie.html | 2 +- web/examples/range-series.html | 2 +- web/examples/right-axis.html | 2 +- web/examples/row.html | 2 +- web/examples/scatter-brushing.html | 2 +- web/examples/scatter-series.html | 2 +- web/examples/scatter.html | 2 +- web/examples/select.html | 2 +- web/examples/series.html | 2 +- web/examples/sparkline.html | 2 +- web/examples/splom.html | 2 +- web/examples/stacked-bar.html | 2 +- web/examples/switching-time-intervals.html | 2 +- web/examples/table-on-aggregated-data.html | 2 +- web/examples/table-pagination.html | 2 +- web/examples/time-intervals.html | 2 +- web/resizing/resizing-bar.html | 2 +- web/resizing/resizing-heatmap.html | 2 +- web/resizing/resizing-pie.html | 2 +- web/resizing/resizing-right-axis.html | 2 +- web/resizing/resizing-row.html | 2 +- web/resizing/resizing-series.html | 2 +- web/transitions/area-progression.html | 2 +- web/transitions/area-transitions.html | 2 +- web/transitions/bar-progression.html | 2 +- web/transitions/bar-transitions.html | 2 +- web/transitions/number-transitions.html | 2 +- web/transitions/ordinal-bar-transitions.html | 2 +- web/transitions/ordinal-line-transitions.html | 2 +- web/transitions/ordinal-row-transitions.html | 2 +- web/transitions/pie-external-label-transitions.html | 2 +- web/transitions/pie-transitions.html | 2 +- web/transitions/stacked-bar-transitions.html | 2 +- web/vc/index.html | 2 +- web/zoom/restrict-panning.html | 2 +- 59 files changed, 59 insertions(+), 70 deletions(-) diff --git a/web/crime/index.html b/web/crime/index.html index 6af9a7f3c..f848f4605 100644 --- a/web/crime/index.html +++ b/web/crime/index.html @@ -322,7 +322,7 @@

Major Canadian City Crime Stats 1998-2011

src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"> - + + diff --git a/web/examples/align-axes.html b/web/examples/align-axes.html index 1662d683e..8b00153be 100644 --- a/web/examples/align-axes.html +++ b/web/examples/align-axes.html @@ -63,7 +63,7 @@ - +
diff --git a/web/examples/area.html b/web/examples/area.html index d00d63269..1f9124e23 100644 --- a/web/examples/area.html +++ b/web/examples/area.html @@ -12,7 +12,7 @@
- + + +
- + + + + - + + diff --git a/web/examples/filter-stacks.html b/web/examples/filter-stacks.html index 225b133a8..cc8b6ee3a 100644 --- a/web/examples/filter-stacks.html +++ b/web/examples/filter-stacks.html @@ -29,7 +29,7 @@
- + + + + +
- + +
- + +
- +
- +
- +
- + + +
- + +
- +
- + + diff --git a/web/examples/series.html b/web/examples/series.html index bd9dd097d..e77ece3a8 100644 --- a/web/examples/series.html +++ b/web/examples/series.html @@ -15,7 +15,7 @@ - + + - +
diff --git a/web/examples/stacked-bar.html b/web/examples/stacked-bar.html index 7c6633e3c..85a92306a 100644 --- a/web/examples/stacked-bar.html +++ b/web/examples/stacked-bar.html @@ -17,7 +17,7 @@
- + + + + + diff --git a/web/resizing/resizing-bar.html b/web/resizing/resizing-bar.html index 80f7208bd..67c5f5146 100644 --- a/web/resizing/resizing-bar.html +++ b/web/resizing/resizing-bar.html @@ -10,7 +10,7 @@
- + diff --git a/web/resizing/resizing-heatmap.html b/web/resizing/resizing-heatmap.html index 2d6137311..f354791f4 100644 --- a/web/resizing/resizing-heatmap.html +++ b/web/resizing/resizing-heatmap.html @@ -12,7 +12,7 @@

Michelson–Morley experiment

- + + diff --git a/web/resizing/resizing-right-axis.html b/web/resizing/resizing-right-axis.html index 2ccc3bcc8..e74a17cc2 100644 --- a/web/resizing/resizing-right-axis.html +++ b/web/resizing/resizing-right-axis.html @@ -14,7 +14,7 @@
- + diff --git a/web/resizing/resizing-row.html b/web/resizing/resizing-row.html index 8787cec9b..745bcc2f8 100644 --- a/web/resizing/resizing-row.html +++ b/web/resizing/resizing-row.html @@ -10,7 +10,7 @@
- + diff --git a/web/resizing/resizing-series.html b/web/resizing/resizing-series.html index 816ba8715..5b3df5ecb 100644 --- a/web/resizing/resizing-series.html +++ b/web/resizing/resizing-series.html @@ -13,7 +13,7 @@ - + diff --git a/web/transitions/area-progression.html b/web/transitions/area-progression.html index 72ca110a9..5f8ba5d51 100644 --- a/web/transitions/area-progression.html +++ b/web/transitions/area-progression.html @@ -15,7 +15,7 @@ - + diff --git a/web/transitions/area-transitions.html b/web/transitions/area-transitions.html index db811f950..101f68e0d 100644 --- a/web/transitions/area-transitions.html +++ b/web/transitions/area-transitions.html @@ -17,7 +17,7 @@ - + diff --git a/web/transitions/bar-progression.html b/web/transitions/bar-progression.html index b7ad72901..c232a6763 100644 --- a/web/transitions/bar-progression.html +++ b/web/transitions/bar-progression.html @@ -15,7 +15,7 @@ - + diff --git a/web/transitions/bar-transitions.html b/web/transitions/bar-transitions.html index 8839a22c2..eedf62a27 100644 --- a/web/transitions/bar-transitions.html +++ b/web/transitions/bar-transitions.html @@ -16,7 +16,7 @@ - + diff --git a/web/transitions/number-transitions.html b/web/transitions/number-transitions.html index edf03f677..fe132e0cb 100644 --- a/web/transitions/number-transitions.html +++ b/web/transitions/number-transitions.html @@ -10,7 +10,7 @@
- + diff --git a/web/transitions/ordinal-bar-transitions.html b/web/transitions/ordinal-bar-transitions.html index b2ac602f1..5c6f29c93 100644 --- a/web/transitions/ordinal-bar-transitions.html +++ b/web/transitions/ordinal-bar-transitions.html @@ -19,7 +19,7 @@ - + diff --git a/web/transitions/ordinal-line-transitions.html b/web/transitions/ordinal-line-transitions.html index 871803041..cc53454d5 100644 --- a/web/transitions/ordinal-line-transitions.html +++ b/web/transitions/ordinal-line-transitions.html @@ -19,7 +19,7 @@ - + diff --git a/web/transitions/ordinal-row-transitions.html b/web/transitions/ordinal-row-transitions.html index 85514e6cd..4c4bd592c 100644 --- a/web/transitions/ordinal-row-transitions.html +++ b/web/transitions/ordinal-row-transitions.html @@ -19,7 +19,7 @@ - + diff --git a/web/transitions/pie-external-label-transitions.html b/web/transitions/pie-external-label-transitions.html index 8c772a7c8..4d2a58be3 100644 --- a/web/transitions/pie-external-label-transitions.html +++ b/web/transitions/pie-external-label-transitions.html @@ -17,7 +17,7 @@ - + diff --git a/web/transitions/pie-transitions.html b/web/transitions/pie-transitions.html index 33191b01a..c1898b5be 100644 --- a/web/transitions/pie-transitions.html +++ b/web/transitions/pie-transitions.html @@ -17,7 +17,7 @@ - + diff --git a/web/transitions/stacked-bar-transitions.html b/web/transitions/stacked-bar-transitions.html index 5952c2619..3761273c7 100644 --- a/web/transitions/stacked-bar-transitions.html +++ b/web/transitions/stacked-bar-transitions.html @@ -17,7 +17,7 @@ - + diff --git a/web/vc/index.html b/web/vc/index.html index 6570e89dc..7e7fbe73e 100644 --- a/web/vc/index.html +++ b/web/vc/index.html @@ -66,7 +66,7 @@

US Venture Capital Landscape 2011

src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"> - +
- + + diff --git a/web/examples/align-axes.html b/web/examples/align-axes.html index 8b00153be..5c1610bbf 100644 --- a/web/examples/align-axes.html +++ b/web/examples/align-axes.html @@ -84,7 +84,7 @@ var posiness = ['heading', 'above', 'upward', 'even', 'downward', 'below']; var N = 20; - var gen = d3.random.normal(); + var gen = d3.randomNormal(); function distribute(vals, min, max) { var ext = d3.extent(vals); return vals.map(function(x) { @@ -111,7 +111,7 @@ } var line = d3.svg.line() - .interpolate('linear'); + .curve(d3.curveLinear); function draw_horizontals(chart, hz) { chart.g().select('g.chart-body') diff --git a/web/examples/bar-extra-line.html b/web/examples/bar-extra-line.html index 02321306a..3994e84b9 100644 --- a/web/examples/bar-extra-line.html +++ b/web/examples/bar-extra-line.html @@ -52,25 +52,28 @@ var line = d3.svg.line() .x(function(d) { return d.x; }) .y(function(d) { return d.y; }) - .interpolate('linear'); + .curve(d3.curveLinear); var chartBody = chart.select('g.chart-body'); var path = chartBody.selectAll('path.extra').data([extra_data]); - path.enter().append('path').attr({ - class: 'extra', - stroke: 'red', - id: 'extra-line' - }); + path = path + .enter() + .append('path') + .attr('class', 'extra') + .attr('stroke', 'red') + .attr('id', 'extra-line') + .merge(path); path.attr('d', line); + // and perhaps you'd like to label it? var text = chartBody.selectAll('text.extra-label').data([0]); - text.enter().append('text') + text.enter() + .append('text') .attr('text-anchor', 'middle') - .append('textPath').attr({ - class: 'extra-label', - 'xlink:href': '#extra-line', - startOffset: '50%' - }) - .text('this is a label for the line'); + .append('textPath') + .attr('class', 'extra-label') + .attr('xlink:href', '#extra-line') + .attr('startOffset', '50%') + .text('this is a label for the line'); }); chart.render(); }); diff --git a/web/examples/bar-single-select.html b/web/examples/bar-single-select.html index c533b102f..b375e02b8 100644 --- a/web/examples/bar-single-select.html +++ b/web/examples/bar-single-select.html @@ -14,7 +14,7 @@
- +
diff --git a/web/examples/box-plot-time.html b/web/examples/box-plot-time.html index a4c45e2af..35c95d7ff 100644 --- a/web/examples/box-plot-time.html +++ b/web/examples/box-plot-time.html @@ -54,7 +54,7 @@ .margins({top: 10, right: 50, bottom: 30, left: 50}) .dimension(monthDimension) .group(closeGroup) - .x(d3.time.scale()) + .x(d3.scaleTime()) .round(d3.time.month.round) .xUnits(d3.time.months) .elasticY(true); diff --git a/web/examples/complex-reduce.html b/web/examples/complex-reduce.html index 8682cc568..f3bf1f58f 100644 --- a/web/examples/complex-reduce.html +++ b/web/examples/complex-reduce.html @@ -36,13 +36,13 @@

Run

Experiment

diff --git a/web/examples/download-table.html b/web/examples/download-table.html index 45a9dd6d2..c7fdd779e 100644 --- a/web/examples/download-table.html +++ b/web/examples/download-table.html @@ -143,7 +143,7 @@ return row; }); } - var blob = new Blob([d3.csv.format(data)], {type: "text/csv;charset=utf-8"}); + var blob = new Blob([d3.csvFormat(data)], {type: "text/csv;charset=utf-8"}); saveAs(blob, 'data.csv'); }); diff --git a/web/examples/heatmap-filtering.html b/web/examples/heatmap-filtering.html index e6ced0aae..6d092758a 100644 --- a/web/examples/heatmap-filtering.html +++ b/web/examples/heatmap-filtering.html @@ -27,10 +27,12 @@

Nasdaq 100 Percentage Gain by Month of Year

d3.csv("../ndx.csv", function(error, data) { - var dateFormat = d3.time.format("%m/%d/%Y"); + var dateFormatSpecifier = "%m/%d/%Y"; + var dateFormat = d3.time.format(dateFormatSpecifier); + var dateFormatParser = d3.timeParse(dateFormatSpecifier); data.forEach(function (d) { - d.dd = dateFormat.parse(d.date); + d.dd = dateFormatParser(d.date); d.month = d3.time.month(d.dd).getMonth(); // pre-calculate month for better performance d.year = d3.time.year(d.dd).getFullYear(); d.close = +d.close; // coerce to number diff --git a/web/examples/line.html b/web/examples/line.html index b52eba9d9..705fda842 100644 --- a/web/examples/line.html +++ b/web/examples/line.html @@ -32,7 +32,7 @@ .width(768) .height(480) .x(d3.scale.linear().domain([0,20])) - .interpolate('step-before') + .interpolate(d3.curveStepBefore) .renderArea(true) .brushOn(false) .renderDataPoints(true) diff --git a/web/examples/range-series.html b/web/examples/range-series.html index e227762a0..29d9cc542 100644 --- a/web/examples/range-series.html +++ b/web/examples/range-series.html @@ -35,7 +35,7 @@ focusChart .width(768) .height(480) - .chart(function(c) { return dc.lineChart(c).interpolate('cardinal').evadeDomainFilter(true); }) + .chart(function(c) { return dc.lineChart(c).interpolate(d3.curveCardinal).evadeDomainFilter(true); }) .x(d3.scale.linear().domain([0,20])) .brushOn(false) .yAxisLabel("Measured Speed km/s") @@ -74,7 +74,7 @@ .width(768) .height(100) .chart(function(c,_,_,i) { - var chart = dc.lineChart(c).interpolate('cardinal'); + var chart = dc.lineChart(c).interpolate(d3.curveCardinal); if(i===0) chart.on('filtered', function (chart) { if (!chart.filter()) { diff --git a/web/examples/right-axis.html b/web/examples/right-axis.html index 4fe590319..df2480ad5 100644 --- a/web/examples/right-axis.html +++ b/web/examples/right-axis.html @@ -22,11 +22,13 @@ var moveChart = dc.compositeChart("#monthly-move-chart"); d3.csv("monthly-move.csv", function (error, data) { - var dateFormat = d3.time.format("%m/%d/%Y"); + var dateFormatSpecifier = "%m/%d/%Y"; + var dateFormat = d3.time.format(dateFormatSpecifier); + var dateFormatParser = d3.timeParse(dateFormatSpecifier); var numberFormat = d3.format(".2f"); data.forEach(function (e) { - e.dd = dateFormat.parse(e.date); + e.dd = dateFormatParser(e.date); e.month = d3.time.month(e.dd); // pre-calculate month for better performance }); @@ -63,7 +65,7 @@ .dimension(moveMonths) .mouseZoomable(true) .shareTitle(false) - .x(d3.time.scale().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)])) + .x(d3.scaleTime().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)])) .round(d3.time.month.round) .xUnits(d3.time.months) .elasticY(true) diff --git a/web/examples/scatter-brushing.html b/web/examples/scatter-brushing.html index 30fa7410d..041f8eb4d 100644 --- a/web/examples/scatter-brushing.html +++ b/web/examples/scatter-brushing.html @@ -32,7 +32,7 @@ "8,6,14\n"+ "1,4,9\n"+ "8,8,12\n"; -var data = d3.csv.parse(data); +var data = d3.csvParse(data); data.forEach(function (x) { x.x = +x.x; diff --git a/web/examples/scatter-series.html b/web/examples/scatter-series.html index 40437aff7..c5b107e07 100644 --- a/web/examples/scatter-series.html +++ b/web/examples/scatter-series.html @@ -26,7 +26,7 @@ runDimension = ndx.dimension(function(d) {return [+d.Expt, +d.Run]; }); runGroup = runDimension.group().reduceSum(function(d) { return +d.Speed; }); - var symbolScale = d3.scale.ordinal().range(d3.svg.symbolTypes); + var symbolScale = d3.scale.ordinal().range(d3.symbols); var symbolAccessor = function(d) { return symbolScale(d.key[0]); }; var subChart = function(c) { return dc.scatterPlot(c) diff --git a/web/examples/switching-time-intervals.html b/web/examples/switching-time-intervals.html index c14773f07..402fddd04 100644 --- a/web/examples/switching-time-intervals.html +++ b/web/examples/switching-time-intervals.html @@ -85,7 +85,7 @@ dateDim.dispose(); group.dispose(); } - var interval = intervals[d3.select('#interval')[0][0].value]; + var interval = intervals[d3.select('#interval').nodes()[0].value]; dateDim = ndx.dimension(function(d) {return interval(d[date_col]);}); chart.xUnits(interval.range); group = dateDim @@ -127,7 +127,7 @@ chart .width(768) .height(480) - .x(d3.time.scale()) + .x(d3.scaleTime()) .xUnits(d3.time.weeks) .margins({left: 50, top: 0, right: 0, bottom: 20}) .elasticY(true) diff --git a/web/examples/time-intervals.html b/web/examples/time-intervals.html index c0467f4f6..718eeecd7 100644 --- a/web/examples/time-intervals.html +++ b/web/examples/time-intervals.html @@ -52,15 +52,18 @@ } }; } - var timeFormat = d3.time.format('%x'); + + var dateFormatSpecifier = '%x'; + var timeFormat = d3.time.format(dateFormatSpecifier); + var dateFormatParser = d3.timeParse(dateFormatSpecifier); var monthChart = dc.barChart("#month"); var costChart = dc.barChart("#cost"); // data from http://stackoverflow.com/questions/22603788/crossfilter-how-to-extract-time-information-from-start-date-and-end-date-column d3.csv("intervals.csv", function(error, projects) { projects.forEach(function(x) { - x['Start Date'] = timeFormat.parse(x['Start Date']); - x['End Date'] = timeFormat.parse(x['End Date']); + x['Start Date'] = dateFormatParser(x['Start Date']); + x['End Date'] = dateFormatParser(x['End Date']); // the library uses object identity so we have to cache the interval arrays x.interval = [x['Start Date'].getTime(), x['End Date'].getTime()]; x.Cost = +x.Cost; @@ -91,7 +94,7 @@ monthChart .width(400) .height(300) - .x(d3.time.scale()) + .x(d3.scaleTime()) .y(d3.scale.linear().domain([0,25])) .xUnits(d3.time.months) .gap(5) From 2d082ee44a7f173401532c197bc7ab87216dfbf7 Mon Sep 17 00:00:00 2001 From: deepak Date: Wed, 28 Feb 2018 22:03:41 +0530 Subject: [PATCH 15/42] Zoom and focus working --- D3v4 Upgrade Notes.md | 20 ++++++++------------ src/coordinate-grid-mixin.js | 23 +++++++++++++++++------ src/d3-compat/d3-compat02.js | 3 +++ src/geo-choropleth-chart.js | 3 ++- src/line-chart.js | 2 +- web/examples/series.html | 2 +- web/vc/index.html | 5 +++-- 7 files changed, 35 insertions(+), 23 deletions(-) diff --git a/D3v4 Upgrade Notes.md b/D3v4 Upgrade Notes.md index 50c1f45ae..a31916730 100644 --- a/D3v4 Upgrade Notes.md +++ b/D3v4 Upgrade Notes.md @@ -1,28 +1,24 @@ To look soon: -- Need proper color matcher for Jasmine -- Need proper URL matcher for Jasmine -- setters for `xAxis` and `yAxis` update docs for D3v4. -- Either of `yAxis` or `_useRightYAxis` should go. Better to drop `_useRightYAxis`. - Current workaround not great. +- Need proper color matcher for Jasmine (Low) +- Need proper URL matcher for Jasmine (Low) +- setters for `xAxis` and `yAxis` update docs for D3v4. +- Update docs for `yAxis` or `_useRightYAxis`. These are now related. +- `.tension` can now be dropped, it can be handled by `.interpolate` itself - In brushing events - if change filter is applied on brush end no event - delay is needed. -- MouseZoom needs careful reimplementation. .focus not working as it uses zoom. + delay is needed - change back to 'brush' to keep consistent with current + behavior. - Lines chart - Area is not working - the function d3.area seems to return different value from D3v3 - manual debugging needed - +- geoChoroplethChart Non working examples: - http://localhost:8888/web/examples/area.html (lines ok, area missing) - http://localhost:8888/web/examples/box-plot-time.html - http://localhost:8888/web/examples/line.html (lines ok, area missing) -- http://localhost:8888/web/examples/multi-focus.html -- http://localhost:8888/web/examples/range-series.html (brush/zoom not working) - http://localhost:8888/web/examples/scatter-brushing.html (brush not working) -- http://localhost:8888/web/examples/series.html - http://localhost:8888/web/examples/splom.html (brush not working) - http://localhost:8888/web/examples/time-intervals.html (bar width, some warnings, brushing not working) -- http://localhost:8888/web/examples/time-intervals.html (bar width incorrect) diff --git a/src/coordinate-grid-mixin.js b/src/coordinate-grid-mixin.js index 85b2be026..1c3dc0d86 100644 --- a/src/coordinate-grid-mixin.js +++ b/src/coordinate-grid-mixin.js @@ -27,6 +27,7 @@ dc.coordinateGridMixin = function (_chart) { var _chartBodyG; var _x; + var _origX; // Will hold orginial scale in case of zoom var _xOriginalDomain; var _xAxis = d3.axisBottom(); var _xUnits = dc.units.integers; @@ -58,7 +59,7 @@ dc.coordinateGridMixin = function (_chart) { var _zoomScale = [1, Infinity]; var _zoomOutRestrict = true; - var _zoom = d3.behavior.zoom().on('zoom', zoomHandler); + var _zoom = d3.behavior.zoom().on('zoom', onZoom); var _nullZoom = d3.behavior.zoom().on('zoom', null); var _hasBeenMouseZoomable = false; @@ -1214,6 +1215,9 @@ dc.coordinateGridMixin = function (_chart) { } function configureMouseZoom () { + // Save a copy of original x scale + _origX = _x.copy(); + if (_mouseZoomable) { _chart._enableMouseZoom(); } else if (_hasBeenMouseZoomable) { @@ -1224,12 +1228,12 @@ dc.coordinateGridMixin = function (_chart) { _chart._enableMouseZoom = function () { _hasBeenMouseZoomable = true; // Needs reimplementation for D3v4 -/* - _zoom.x(_chart.x()) + + _zoom .scaleExtent(_zoomScale) - .size([_chart.width(), _chart.height()]) + .extent([[0 ,0], [_chart.width(), _chart.height()]]) .duration(_chart.transitionDuration()); -*/ + _chart.root().call(_zoom); }; @@ -1273,6 +1277,14 @@ dc.coordinateGridMixin = function (_chart) { _refocused = !rangesEqual(domain, _xOriginalDomain); } + function onZoom () { + if (!d3v4.event.sourceEvent && d3v4.event.sourceEvent.type !== "zoom") return; + + _chart.x(d3v4.event.transform.rescaleX(_origX)); + + zoomHandler(); + } + function intersectExtents (ext1, ext2) { if (ext1[0] > ext2[1] || ext1[1] < ext2[0]) { console.warn('could not intersect extents'); @@ -1316,7 +1328,6 @@ dc.coordinateGridMixin = function (_chart) { _chart.x().domain(_xOriginalDomain); } - _zoom.x(_chart.x()); zoomHandler(); }; diff --git a/src/d3-compat/d3-compat02.js b/src/d3-compat/d3-compat02.js index 3febe04b1..9c4673141 100644 --- a/src/d3-compat/d3-compat02.js +++ b/src/d3-compat/d3-compat02.js @@ -7,6 +7,7 @@ d3.time.format.iso.parse = d3v4.isoParse; d3.timeParse = d3v4.timeParse; d3.scaleTime = d3v4.scaleTime; +d3.scaleQuantize = d3v4.scaleQuantize; d3.time.second = d3v4.timeSecond; d3.time.minute = d3v4.timeMinute; @@ -51,6 +52,8 @@ d3.symbolTypes = d3v4.symbolTypes; d3.symbols = d3v4.symbols; d3.geo.mercator = d3v4.geoMercator; +d3.geoPath = d3v4.geoPath; +d3.geoAlbersUsa = d3.geoAlbersUsa; d3.csv = d3v4.csv; d3.json = d3v4.json; diff --git a/src/geo-choropleth-chart.js b/src/geo-choropleth-chart.js index 9f61beaaa..bd3d4c891 100644 --- a/src/geo-choropleth-chart.js +++ b/src/geo-choropleth-chart.js @@ -28,7 +28,7 @@ dc.geoChoroplethChart = function (parent, chartGroup) { return d || 0; }); - var _geoPath = d3.geo.path(); + var _geoPath = d3.geoPath(); var _projectionFlag; var _geoJsons = []; @@ -105,6 +105,7 @@ dc.geoChoroplethChart = function (parent, chartGroup) { } return baseClasses; }); + return regionG; } diff --git a/src/line-chart.js b/src/line-chart.js index 68e885f3e..f0de9ee68 100644 --- a/src/line-chart.js +++ b/src/line-chart.js @@ -40,7 +40,7 @@ dc.lineChart = function (parent, chartGroup) { var _dataPointFillOpacity = DEFAULT_DOT_OPACITY; var _dataPointStrokeOpacity = DEFAULT_DOT_OPACITY; var _interpolate = d3.curveLinear; - var _tension = 0.7; + var _tension = 0; var _defined; var _dashStyle; var _xyTipsOn = true; diff --git a/web/examples/series.html b/web/examples/series.html index e77ece3a8..71b9de2e2 100644 --- a/web/examples/series.html +++ b/web/examples/series.html @@ -32,7 +32,7 @@ chart .width(768) .height(480) - .chart(function(c) { return dc.lineChart(c).interpolate('cardinal'); }) + .chart(function(c) { return dc.lineChart(c).interpolate(d3.curveCardinal); }) .x(d3.scale.linear().domain([0,20])) .brushOn(false) .yAxisLabel("Measured Speed km/s") diff --git a/web/vc/index.html b/web/vc/index.html index 7e7fbe73e..afafe9972 100644 --- a/web/vc/index.html +++ b/web/vc/index.html @@ -131,14 +131,15 @@

US Venture Capital Landscape 2011

.height(500) .dimension(states) .group(stateRaisedSum) - .colors(d3.scale.quantize().range(["#E2F2FF", "#C4E4FF", "#9ED2FF", "#81C5FF", "#6BBAFF", "#51AEFF", "#36A2FF", "#1E96FF", "#0089FF", "#0061B5"])) + .colors(d3.scaleQuantize().range(["#E2F2FF", "#C4E4FF", "#9ED2FF", "#81C5FF", "#6BBAFF", "#51AEFF", "#36A2FF", "#1E96FF", "#0089FF", "#0061B5"])) .colorDomain([0, 200]) .colorCalculator(function (d) { return d ? usChart.colors()(d) : '#ccc'; }) .overlayGeoJson(statesJson.features, "state", function (d) { return d.properties.name; }) + .projection(d3.geoAlbersUsa) .valueAccessor(function(kv) { - console.log(kv); + // console.log(kv); return kv.value; }) .title(function (d) { From d5b4b26ff36a8d9660b407954174a2f5fbe0ef58 Mon Sep 17 00:00:00 2001 From: deepak Date: Wed, 28 Feb 2018 22:29:35 +0530 Subject: [PATCH 16/42] Home page charts works (issue with brushes) --- src/bar-chart.js | 2 +- web/docs/stock.html | 10 ++++++---- web/index.html | 2 +- web/stock.js | 10 ++++++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/bar-chart.js b/src/bar-chart.js index 0a3569fee..110a01a24 100644 --- a/src/bar-chart.js +++ b/src/bar-chart.js @@ -311,7 +311,7 @@ dc.barChart = function (parent, chartGroup) { selection[0] = _chart.round(selection[0]); selection[1] = _chart.round(selection[1]); - _chart.brushSelection(selection); + // _chart.updateBrushSelection(selection); } return selection; }; diff --git a/web/docs/stock.html b/web/docs/stock.html index b539042a5..a1d5c19a0 100644 --- a/web/docs/stock.html +++ b/web/docs/stock.html @@ -231,11 +231,13 @@

Load your data

-
    var dateFormat = d3.time.format('%m/%d/%Y');
+            
    var dateFormatSpecifier = '%m/%d/%Y';
+    var dateFormat = d3.time.format(dateFormatSpecifier);
+    var dateFormatParser = d3.timeParse(dateFormatSpecifier);
     var numberFormat = d3.format('.2f');
 
     data.forEach(function (d) {
-        d.dd = dateFormat.parse(d.date);
+        d.dd = dateFormatParser(d.date);
         d.month = d3.time.month(d.dd); // pre-calculate month for better performance
         d.close = +d.close; // coerce to number
         d.open = +d.open;
@@ -1433,7 +1435,7 @@ 

Stacked Area Chart

        .rangeChart(volumeChart)
-        .x(d3.time.scale().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)]))
+        .x(d3.scaleTime().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)]))
         .round(d3.time.month.round)
         .xUnits(d3.time.months)
         .elasticY(true)
@@ -1561,7 +1563,7 @@ 

Range Chart

.group(volumeByMonthGroup) .centerBar(true) .gap(1) - .x(d3.time.scale().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)])) + .x(d3.scaleTime().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)])) .round(d3.time.month.round) .alwaysUseRounding(true) .xUnits(d3.time.months);
diff --git a/web/index.html b/web/index.html index 6b196f865..ee783bb56 100644 --- a/web/index.html +++ b/web/index.html @@ -169,7 +169,7 @@

Nasdaq 100 Index 1985/11/01-2012/06/29

- + diff --git a/web/stock.js b/web/stock.js index 1eaf655f5..fe0308118 100644 --- a/web/stock.js +++ b/web/stock.js @@ -61,11 +61,13 @@ var nasdaqTable = dc.dataTable('.dc-data-table'); //``` d3.csv('ndx.csv', function (data) { // Since its a csv file we need to format the data a bit. - var dateFormat = d3.time.format('%m/%d/%Y'); + var dateFormatSpecifier = '%m/%d/%Y'; + var dateFormat = d3.time.format(dateFormatSpecifier); + var dateFormatParser = d3.timeParse(dateFormatSpecifier); var numberFormat = d3.format('.2f'); data.forEach(function (d) { - d.dd = dateFormat.parse(d.date); + d.dd = dateFormatParser(d.date); d.month = d3.time.month(d.dd); // pre-calculate month for better performance d.close = +d.close; // coerce to number d.open = +d.open; @@ -417,7 +419,7 @@ d3.csv('ndx.csv', function (data) { .mouseZoomable(true) // Specify a "range chart" to link its brush extent with the zoom of the current "focus chart". .rangeChart(volumeChart) - .x(d3.time.scale().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)])) + .x(d3.scaleTime().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)])) .round(d3.time.month.round) .xUnits(d3.time.months) .elasticY(true) @@ -459,7 +461,7 @@ d3.csv('ndx.csv', function (data) { .group(volumeByMonthGroup) .centerBar(true) .gap(1) - .x(d3.time.scale().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)])) + .x(d3.scaleTime().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)])) .round(d3.time.month.round) .alwaysUseRounding(true) .xUnits(d3.time.months); From 5c3c4123d839f0859a7af01eb26086d548840c42 Mon Sep 17 00:00:00 2001 From: deepak Date: Thu, 1 Mar 2018 18:26:28 +0530 Subject: [PATCH 17/42] Fixing some of the specs --- spec/bar-chart-spec.js | 14 +++---- spec/heatmap-spec.js | 88 ++++++++++++++++++++-------------------- spec/helpers/fixtures.js | 2 +- 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/spec/bar-chart-spec.js b/spec/bar-chart-spec.js index 22d60b4a5..c1410adc3 100644 --- a/spec/bar-chart-spec.js +++ b/spec/bar-chart-spec.js @@ -404,7 +404,7 @@ describe('dc.barChart', function () { it('should have titles rendered for extra stacks', function () { nthStack(1).forEachBar(function (bar, datum) { - expect(bar.selectAll('title')[0].length).toBe(1); + expect(bar.selectAll('title').nodes().length).toBe(1); expect(bar.select('title').text()).toBe('stack 1: ' + datum.data.value); }); }); @@ -423,7 +423,7 @@ describe('dc.barChart', function () { it('should not create extra title elements', function () { nthStack(1).forEachBar(function (bar, datum) { - expect(bar.selectAll('title')[0].length).toBe(1); + expect(bar.selectAll('title').nodes().length).toBe(1); }); }); }); @@ -805,7 +805,7 @@ describe('dc.barChart', function () { it('should base the y-axis height on the maximum value in the data', function () { var yAxisMax = 3.0; var ticks = chart.selectAll('g.y g.tick'); - var tickValues = ticks[0].map(function (tick) { return +d3.select(tick).text(); }); + var tickValues = ticks.nodes().map(function (tick) { return +d3.select(tick).text(); }); var maxTickValue = Math.max.apply(this, tickValues); expect(maxTickValue).toBe(yAxisMax); }); @@ -819,7 +819,7 @@ describe('dc.barChart', function () { it('should rescale the y-axis after applying a filter', function () { var yAxisMax = 1.0; var ticks = chart.selectAll('g.y g.tick'); - var tickValues = ticks[0].map(function (tick) { return +d3.select(tick).text(); }); + var tickValues = ticks.nodes().map(function (tick) { return +d3.select(tick).text(); }); var maxTickValue = Math.max.apply(this, tickValues); expect(maxTickValue).toBe(yAxisMax); }); @@ -965,7 +965,7 @@ describe('dc.barChart', function () { chart = dc.barChart('#' + id); chart.width(500) .transitionDuration(0) - .x(d3.time.scale()) + .x(d3.scaleTime()) .elasticY(true).elasticX(true) .dimension(dimension) .group(group); @@ -1263,11 +1263,11 @@ describe('dc.barChart', function () { var stack = d3.select(chart.selectAll('.stack').nodes()[n]); stack.nthBar = function (n) { - return d3.select(this.selectAll('rect.bar')[0][n]); + return d3.select(this.selectAll('rect.bar').nodes()[n]); }; stack.nthLabel = function (n) { - return d3.select(this.selectAll('text.barLabel')[0][n]); + return d3.select(this.selectAll('text.barLabel').nodes()[n]); }; stack.forEachBar = function (assertions) { diff --git a/spec/heatmap-spec.js b/spec/heatmap-spec.js index ae5ecf453..86f287f2e 100644 --- a/spec/heatmap-spec.js +++ b/spec/heatmap-spec.js @@ -46,26 +46,26 @@ describe('dc.heatmap', function () { it('should position the heatboxes in a matrix', function () { var heatBoxes = chart.selectAll('rect.heat-box'); - expect(+heatBoxes[0][0].getAttribute('x')).toEqual(0); - expect(+heatBoxes[0][0].getAttribute('y')).toEqual(100); + expect(+heatBoxes.nodes()[0].getAttribute('x')).toEqual(0); + expect(+heatBoxes.nodes()[0].getAttribute('y')).toEqual(100); - expect(+heatBoxes[0][1].getAttribute('x')).toEqual(0); - expect(+heatBoxes[0][1].getAttribute('y')).toEqual(0); + expect(+heatBoxes.nodes()[1].getAttribute('x')).toEqual(0); + expect(+heatBoxes.nodes()[1].getAttribute('y')).toEqual(0); - expect(+heatBoxes[0][2].getAttribute('x')).toEqual(100); - expect(+heatBoxes[0][2].getAttribute('y')).toEqual(100); + expect(+heatBoxes.nodes()[2].getAttribute('x')).toEqual(100); + expect(+heatBoxes.nodes()[2].getAttribute('y')).toEqual(100); - expect(+heatBoxes[0][3].getAttribute('x')).toEqual(100); - expect(+heatBoxes[0][3].getAttribute('y')).toEqual(0); + expect(+heatBoxes.nodes()[3].getAttribute('x')).toEqual(100); + expect(+heatBoxes.nodes()[3].getAttribute('y')).toEqual(0); }); it('should color heatboxes using the provided color option', function () { var heatBoxes = chart.selectAll('rect.heat-box'); - expect(heatBoxes[0][0].getAttribute('fill')).toMatch(/#000001/i); - expect(heatBoxes[0][1].getAttribute('fill')).toMatch(/#000002/i); - expect(heatBoxes[0][2].getAttribute('fill')).toMatch(/#000003/i); - expect(heatBoxes[0][3].getAttribute('fill')).toMatch(/#000004/i); + expect(heatBoxes.nodes()[0].getAttribute('fill')).toMatch(/#000001/i); + expect(heatBoxes.nodes()[1].getAttribute('fill')).toMatch(/#000002/i); + expect(heatBoxes.nodes()[2].getAttribute('fill')).toMatch(/#000003/i); + expect(heatBoxes.nodes()[3].getAttribute('fill')).toMatch(/#000004/i); }); it('should size heatboxes based on the size of the matrix', function () { @@ -77,30 +77,30 @@ describe('dc.heatmap', function () { it('should position the y-axis labels with their associated rows', function () { var yaxisTexts = chart.selectAll('.rows.axis text'); - expect(+yaxisTexts[0][0].getAttribute('y')).toEqual(150); - expect(+yaxisTexts[0][0].getAttribute('x')).toEqual(0); - expect(+yaxisTexts[0][1].getAttribute('y')).toEqual(50); - expect(+yaxisTexts[0][1].getAttribute('x')).toEqual(0); + expect(+yaxisTexts.nodes()[0].getAttribute('y')).toEqual(150); + expect(+yaxisTexts.nodes()[0].getAttribute('x')).toEqual(0); + expect(+yaxisTexts.nodes()[1].getAttribute('y')).toEqual(50); + expect(+yaxisTexts.nodes()[1].getAttribute('x')).toEqual(0); }); it('should have labels on the y-axis corresponding to the row values', function () { var yaxisTexts = chart.selectAll('.rows.axis text'); - expect(yaxisTexts[0][0].textContent).toEqual('1'); - expect(yaxisTexts[0][1].textContent).toEqual('2'); + expect(yaxisTexts.nodes()[0].textContent).toEqual('1'); + expect(yaxisTexts.nodes()[1].textContent).toEqual('2'); }); it('should position the x-axis labels with their associated columns', function () { var xaxisTexts = chart.selectAll('.cols.axis text'); - expect(+xaxisTexts[0][0].getAttribute('y')).toEqual(200); - expect(+xaxisTexts[0][0].getAttribute('x')).toEqual(50); - expect(+xaxisTexts[0][1].getAttribute('y')).toEqual(200); - expect(+xaxisTexts[0][1].getAttribute('x')).toEqual(150); + expect(+xaxisTexts.nodes()[0].getAttribute('y')).toEqual(200); + expect(+xaxisTexts.nodes()[0].getAttribute('x')).toEqual(50); + expect(+xaxisTexts.nodes()[1].getAttribute('y')).toEqual(200); + expect(+xaxisTexts.nodes()[1].getAttribute('x')).toEqual(150); }); it('should have labels on the x-axis corresponding to the row values', function () { var xaxisTexts = chart.selectAll('.cols.axis text'); - expect(xaxisTexts[0][0].textContent).toEqual('1'); - expect(xaxisTexts[0][1].textContent).toEqual('2'); + expect(xaxisTexts.nodes()[0].textContent).toEqual('1'); + expect(xaxisTexts.nodes()[1].textContent).toEqual('2'); }); describe('with custom labels', function () { @@ -111,13 +111,13 @@ describe('dc.heatmap', function () { }); it('should display the custom labels on the x axis', function () { var xaxisTexts = chart.selectAll('.cols.axis text'); - expect(xaxisTexts[0][0].textContent).toEqual('col 1'); - expect(xaxisTexts[0][1].textContent).toEqual('col 2'); + expect(xaxisTexts.nodes()[0].textContent).toEqual('col 1'); + expect(xaxisTexts.nodes()[1].textContent).toEqual('col 2'); }); it('should display the custom labels on the y axis', function () { var yaxisTexts = chart.selectAll('.rows.axis text'); - expect(yaxisTexts[0][0].textContent).toEqual('row 1'); - expect(yaxisTexts[0][1].textContent).toEqual('row 2'); + expect(yaxisTexts.nodes()[0].textContent).toEqual('row 1'); + expect(yaxisTexts.nodes()[1].textContent).toEqual('row 2'); }); }); @@ -164,32 +164,32 @@ describe('dc.heatmap', function () { it('should only have 1 row on the y axis', function () { var yaxisTexts = chart.selectAll('.rows.axis text'); - expect(yaxisTexts[0].length).toEqual(1); - expect(yaxisTexts[0][0].textContent).toEqual('1'); + expect(yaxisTexts.nodes().length).toEqual(1); + expect(yaxisTexts.nodes()[0].textContent).toEqual('1'); }); it('should only have 1 col on the x axis', function () { var xaxisTexts = chart.selectAll('.cols.axis text'); - expect(xaxisTexts[0].length).toEqual(1); - expect(xaxisTexts[0][0].textContent).toEqual('1'); + expect(xaxisTexts.nodes().length).toEqual(1); + expect(xaxisTexts.nodes()[0].textContent).toEqual('1'); }); it('should reset the rows to using the chart data on the y axis', function () { chart.rows(null); chart.redraw(); var yaxisTexts = chart.selectAll('.rows.axis text'); - expect(yaxisTexts[0].length).toEqual(2); - expect(yaxisTexts[0][0].textContent).toEqual('1'); - expect(yaxisTexts[0][1].textContent).toEqual('2'); + expect(yaxisTexts.nodes().length).toEqual(2); + expect(yaxisTexts.nodes()[0].textContent).toEqual('1'); + expect(yaxisTexts.nodes()[1].textContent).toEqual('2'); }); it('should reset the cols to using the chart data on the y axis', function () { chart.cols(null); chart.redraw(); var xaxisTexts = chart.selectAll('.cols.axis text'); - expect(xaxisTexts[0].length).toEqual(2); - expect(xaxisTexts[0][0].textContent).toEqual('1'); - expect(xaxisTexts[0][1].textContent).toEqual('2'); + expect(xaxisTexts.nodes().length).toEqual(2); + expect(xaxisTexts.nodes()[0].textContent).toEqual('1'); + expect(xaxisTexts.nodes()[1].textContent).toEqual('2'); }); }); @@ -202,14 +202,14 @@ describe('dc.heatmap', function () { it('should have descending rows', function () { var yaxisTexts = chart.selectAll('.rows.axis text'); - expect(yaxisTexts[0][0].textContent).toEqual('2'); - expect(yaxisTexts[0][1].textContent).toEqual('1'); + expect(yaxisTexts.nodes()[0].textContent).toEqual('2'); + expect(yaxisTexts.nodes()[1].textContent).toEqual('1'); }); it('should have descending cols', function () { var yaxisTexts = chart.selectAll('.rows.axis text'); - expect(yaxisTexts[0][0].textContent).toEqual('2'); - expect(yaxisTexts[0][1].textContent).toEqual('1'); + expect(yaxisTexts.nodes()[0].textContent).toEqual('2'); + expect(yaxisTexts.nodes()[1].textContent).toEqual('1'); }); }); @@ -371,8 +371,8 @@ describe('dc.heatmap', function () { }); describe('with one cell on that axis already filtered', function () { it('should filter all cells on that axis (and the original cell should remain filtered)', function () { - var boxes = chart.selectAll('.box-group'); - var box = d3.select(boxes[0][Math.floor(Math.random() * boxes.length)]); + var boxNodes = chart.selectAll('.box-group').nodes(); + var box = d3.select(boxNodes[Math.floor(Math.random() * boxNodes.length)]); box.select('rect').on('click')(box.datum()); diff --git a/spec/helpers/fixtures.js b/spec/helpers/fixtures.js index 7f895fac3..20a012388 100644 --- a/spec/helpers/fixtures.js +++ b/spec/helpers/fixtures.js @@ -79,7 +79,7 @@ function loadColorFixture2 () { } function loadIrisFixture () { - return d3.csv.parse( + return d3.csvParse( "sepal_length,sepal_width,petal_length,petal_width,species\n" + "5.1,3.5,1.4,0.2,setosa\n" + "4.9,3,1.4,0.2,setosa\n" + From 205facc3fe518ceebcdfa6a44c11343054656bc7 Mon Sep 17 00:00:00 2001 From: deepak Date: Thu, 1 Mar 2018 23:45:55 +0530 Subject: [PATCH 18/42] X Axis brushing --- D3v4 Upgrade Notes.md | 9 ++++- Gruntfile.js | 34 ++++++++++-------- src/bar-chart.js | 15 +++----- src/box-plot.js | 5 ++- src/bubble-chart.js | 6 ++-- src/bubble-mixin.js | 2 +- src/bubble-overlay.js | 4 +-- src/composite-chart.js | 20 ++++++++--- src/coordinate-grid-mixin.js | 59 +++++++++++++------------------- src/scatter-plot.js | 22 +++++++----- web/examples/time-intervals.html | 4 +-- 11 files changed, 94 insertions(+), 86 deletions(-) diff --git a/D3v4 Upgrade Notes.md b/D3v4 Upgrade Notes.md index a31916730..3c3c51c44 100644 --- a/D3v4 Upgrade Notes.md +++ b/D3v4 Upgrade Notes.md @@ -20,5 +20,12 @@ Non working examples: - http://localhost:8888/web/examples/scatter-brushing.html (brush not working) - http://localhost:8888/web/examples/splom.html (brush not working) - http://localhost:8888/web/examples/time-intervals.html - (bar width, some warnings, brushing not working) + (bar width, brushing not working) +- http://localhost:8888/web/examples/switching-time-intervals.html (warnings) + + +._brushing +.extendBrush +.redrawBrush +.fadeDeselectedArea diff --git a/Gruntfile.js b/Gruntfile.js index 4de71cb11..109458197 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -154,18 +154,21 @@ module.exports = function (grunt) { display: 'short', summary: true, specs: [ - /*// '<%= conf.spec %>/bar-chart-spec.js', - // '<%= conf.spec %>/base-mixin-spec.js', - // '<%= conf.spec %>/biggish-data-spec.js', - // '<%= conf.spec %>/box-plot-spec.js', - // '<%= conf.spec %>/bubble-chart-spec.js', + '<%= conf.spec %>/*-spec.js' + +/* + '<%= conf.spec %>/bar-chart-spec.js', + '<%= conf.spec %>/base-mixin-spec.js', + '<%= conf.spec %>/biggish-data-spec.js', + '<%= conf.spec %>/box-plot-spec.js', + '<%= conf.spec %>/bubble-chart-spec.js', '<%= conf.spec %>/bubble-overlay-spec.js', '<%= conf.spec %>/cap-mixin-spec.js', - // '<%= conf.spec %>/color-spec.js', // Need proper color matcher - // '<%= conf.spec %>/composite-chart-spec.js',*/ + '<%= conf.spec %>/color-spec.js', // Need proper color matcher + '<%= conf.spec %>/composite-chart-spec.js', '<%= conf.spec %>/coordinate-grid-chart-spec.js', - /*'<%= conf.spec %>/core-spec.js', - // '<%= conf.spec %>/data-addition-spec.js', + '<%= conf.spec %>/core-spec.js', + '<%= conf.spec %>/data-addition-spec.js', '<%= conf.spec %>/data-count-spec.js', '<%= conf.spec %>/data-grid-spec.js', '<%= conf.spec %>/data-table-spec.js', @@ -173,17 +176,18 @@ module.exports = function (grunt) { '<%= conf.spec %>/filter-dates-spec.js', '<%= conf.spec %>/filters-spec.js', '<%= conf.spec %>/geo-choropleth-chart-spec.js', - // '<%= conf.spec %>/heatmap-spec.js', - // '<%= conf.spec %>/legend-spec.js',*/ - '<%= conf.spec %>/line-chart-spec.js'/*, + '<%= conf.spec %>/heatmap-spec.js', + '<%= conf.spec %>/legend-spec.js', + '<%= conf.spec %>/line-chart-spec.js', '<%= conf.spec %>/logger-spec.js', '<%= conf.spec %>/number-display-spec.js', '<%= conf.spec %>/pie-chart-spec.js', '<%= conf.spec %>/row-chart-spec.js', - // '<%= conf.spec %>/scatter-plot-spec.js', + '<%= conf.spec %>/scatter-plot-spec.js', '<%= conf.spec %>/select-menu-spec.js', - // '<%= conf.spec %>/series-chart-spec.js', - '<%= conf.spec %>/utils-spec.js'*/ + '<%= conf.spec %>/series-chart-spec.js', + '<%= conf.spec %>/utils-spec.js' +*/ ], helpers: [ '<%= conf.web %>/js/jasmine-jsreporter.js', diff --git a/src/bar-chart.js b/src/bar-chart.js index 110a01a24..ea91f83aa 100644 --- a/src/bar-chart.js +++ b/src/bar-chart.js @@ -201,9 +201,8 @@ dc.barChart = function (parent, chartGroup) { } } - _chart.fadeDeselectedArea = function () { + _chart.fadeDeselectedArea = function (selection) { var bars = _chart.chartBodyG().selectAll('rect.bar'); - var selection = _chart.getBrushSelection(); if (_chart.isOrdinal()) { if (_chart.hasFilter()) { @@ -304,14 +303,10 @@ dc.barChart = function (parent, chartGroup) { return _chart; }; - _chart.extendBrush = function () { - var selection = _chart.getBrushSelection(); - - if (_chart.round() && (!_centerBar || _alwaysUseRounding)) { - selection[0] = _chart.round(selection[0]); - selection[1] = _chart.round(selection[1]); - - // _chart.updateBrushSelection(selection); + _chart.extendBrush = function (selection) { + if (selection && _chart.round() && (!_centerBar || _alwaysUseRounding)) { + selection[0] = _chart.round()(selection[0]); + selection[1] = _chart.round()(selection[1]); } return selection; }; diff --git a/src/box-plot.js b/src/box-plot.js index 703ac87d5..bf9789b6d 100644 --- a/src/box-plot.js +++ b/src/box-plot.js @@ -150,7 +150,7 @@ dc.boxPlot = function (parent, chartGroup) { updateBoxes(boxesG); removeBoxes(boxesG); - _chart.fadeDeselectedArea(); + _chart.fadeDeselectedArea(_chart.filter()); }; function renderBoxes (boxesG) { @@ -181,7 +181,7 @@ dc.boxPlot = function (parent, chartGroup) { boxesG.exit().remove().call(_box); } - _chart.fadeDeselectedArea = function () { + _chart.fadeDeselectedArea = function (selection) { if (_chart.hasFilter()) { if (_chart.isOrdinal()) { _chart.g().selectAll('g.box').each(function (d) { @@ -192,7 +192,6 @@ dc.boxPlot = function (parent, chartGroup) { } }); } else { - var selection = _chart.getBrushSelection();; var start = selection[0]; var end = selection[1]; var keyAccessor = _chart.keyAccessor(); diff --git a/src/bubble-chart.js b/src/bubble-chart.js index 9969301a6..e739ca7fe 100644 --- a/src/bubble-chart.js +++ b/src/bubble-chart.js @@ -54,7 +54,7 @@ dc.bubbleChart = function (parent, chartGroup) { removeNodes(bubbleG); - _chart.fadeDeselectedArea(); + _chart.fadeDeselectedArea(_chart.filter()); }; function renderNodes (bubbleG) { @@ -128,9 +128,9 @@ dc.bubbleChart = function (parent, chartGroup) { // override default x axis brush from parent chart }; - _chart.redrawBrush = function () { + _chart.redrawBrush = function (g, selection, doTransition) { // override default x axis brush from parent chart - _chart.fadeDeselectedArea(); + _chart.fadeDeselectedArea(selection); }; return _chart.anchor(parent, chartGroup); diff --git a/src/bubble-mixin.js b/src/bubble-mixin.js index 527049cae..b3b185fd7 100644 --- a/src/bubble-mixin.js +++ b/src/bubble-mixin.js @@ -255,7 +255,7 @@ dc.bubbleMixin = function (_chart) { return _chart; }; - _chart.fadeDeselectedArea = function () { + _chart.fadeDeselectedArea = function (selection) { if (_chart.hasFilter()) { _chart.selectAll('g.' + _chart.BUBBLE_NODE_CLASS).each(function (d) { if (_chart.isSelectedNode(d)) { diff --git a/src/bubble-overlay.js b/src/bubble-overlay.js index ed5efc7a7..05e34c283 100644 --- a/src/bubble-overlay.js +++ b/src/bubble-overlay.js @@ -81,7 +81,7 @@ dc.bubbleOverlay = function (parent, chartGroup) { initializeBubbles(); - _chart.fadeDeselectedArea(); + _chart.fadeDeselectedArea(_chart.filter()); return _chart; }; @@ -149,7 +149,7 @@ dc.bubbleOverlay = function (parent, chartGroup) { _chart._doRedraw = function () { updateBubbles(); - _chart.fadeDeselectedArea(); + _chart.fadeDeselectedArea(_chart.filter()); return _chart; }; diff --git a/src/composite-chart.js b/src/composite-chart.js index c0522b3ad..9fa643279 100644 --- a/src/composite-chart.js +++ b/src/composite-chart.js @@ -69,11 +69,21 @@ dc.compositeChart = function (parent, chartGroup) { }); _chart._brushing = function () { - var extent = _chart.extendBrush(); - var brushIsEmpty = _chart.brushIsEmpty(extent); + var event = d3v4.event; + // Avoids infinite recursion + // To ensure that when it is called because of brush.move there is no d3v4.event.sourceEvent + d3v4.event = null; + if (!event.sourceEvent) return; + var selection = event.selection; + if (selection) { + selection = selection.map(_chart.x().invert); + } + selection = _chart.extendBrush(selection); + + var brushIsEmpty = _chart.brushIsEmpty(selection); for (var i = 0; i < _children.length; ++i) { - _children[i].replaceFilter(brushIsEmpty ? null : extent); + _children[i].replaceFilter(brushIsEmpty ? null : selection); } }; @@ -263,11 +273,11 @@ dc.compositeChart = function (parent, chartGroup) { return _chart; }; - _chart.fadeDeselectedArea = function () { + _chart.fadeDeselectedArea = function (selection) { for (var i = 0; i < _children.length; ++i) { var child = _children[i]; child.brush(_chart.brush()); - child.fadeDeselectedArea(); + child.fadeDeselectedArea(selection); } }; diff --git a/src/coordinate-grid-mixin.js b/src/coordinate-grid-mixin.js index 1c3dc0d86..7314569ee 100644 --- a/src/coordinate-grid-mixin.js +++ b/src/coordinate-grid-mixin.js @@ -981,17 +981,6 @@ dc.coordinateGridMixin = function (_chart) { return _chart.effectiveWidth(); } - _chart.getBrushSelection = function () { - if (!_gBrush) return null; - - var selection = d3.brushSelection(_gBrush.node()); - - // Empty selection - if (!selection) return null; - - return selection.map(_x.invert); - }; - _chart.updateBrushSelection = function (selection) { if (_brush && _gBrush) { @@ -1021,17 +1010,12 @@ dc.coordinateGridMixin = function (_chart) { // Set boundaries of the brush _brush.extent([0,0], [brushWidth(), brushHeight()]); - _brush.on('end', function() { - var evt = d3v4.event; - if (!evt.sourceEvent) return; - - _chart._brushing(); - }); + _brush.on('start brush end', _chart._brushing); // _chart.setBrushY(gBrush, false); // _chart.setHandlePaths(gBrush); if (_chart.hasFilter()) { - _chart.redrawBrush(g, false); + _chart.redrawBrush(g, _chart.filter(), false); } } }; @@ -1049,14 +1033,10 @@ dc.coordinateGridMixin = function (_chart) { .attr('d', _chart.resizeHandlePath); }; - _chart.extendBrush = function () { - var selection = _chart.getBrushSelection(); - - if (_chart.round()) { - selection[0] = _chart.round(selection[0]); - selection[1] = _chart.round(selection[1]); - - // _chart.updateBrushSelection(selection); + _chart.extendBrush = function (selection) { + if (selection && _chart.round()) { + selection[0] = _chart.round()(selection[0]); + selection[1] = _chart.round()(selection[1]); } return selection; }; @@ -1066,12 +1046,18 @@ dc.coordinateGridMixin = function (_chart) { }; _chart._brushing = function () { - var evt = d3v4.event; - if (!d3v4.event.sourceEvent) return; - - var selection = _chart.extendBrush(); + var event = d3v4.event; + // Avoids infinite recursion + // To ensure that when it is called because of brush.move there is no d3v4.event.sourceEvent + d3v4.event = null; + if (!event.sourceEvent) return; + var selection = event.selection; + if (selection) { + selection = selection.map(_chart.x().invert); + } + selection = _chart.extendBrush(selection); - _chart.redrawBrush(_g, false); + _chart.redrawBrush(_g, selection, false); if (_chart.brushIsEmpty(selection)) { dc.events.trigger(function () { @@ -1088,8 +1074,9 @@ dc.coordinateGridMixin = function (_chart) { } }; - _chart.redrawBrush = function (g, doTransition) { + _chart.redrawBrush = function (g, selection, doTransition) { // fix for D3v4 + _chart.updateBrushSelection(selection); /* if (_brushOn) { if (_chart.filter() && _chart.brush().empty()) { @@ -1103,10 +1090,10 @@ dc.coordinateGridMixin = function (_chart) { .extent(_chart.brush().extent())); } */ - _chart.fadeDeselectedArea(); + _chart.fadeDeselectedArea(selection); }; - _chart.fadeDeselectedArea = function () { + _chart.fadeDeselectedArea = function (selection) { // do nothing, sub-chart should override this function }; @@ -1208,9 +1195,9 @@ dc.coordinateGridMixin = function (_chart) { if (render) { _chart.renderBrush(_chart.g(), false); } else { - _chart.redrawBrush(_chart.g(), _resizing); + _chart.redrawBrush(_chart.g(), _chart.filter(), _resizing); } - _chart.fadeDeselectedArea(); + _chart.fadeDeselectedArea(_chart.filter()); _resizing = false; } diff --git a/src/scatter-plot.js b/src/scatter-plot.js index 2b3ce6c2a..6c5df0ed6 100644 --- a/src/scatter-plot.js +++ b/src/scatter-plot.js @@ -389,13 +389,10 @@ dc.scatterPlot = function (parent, chartGroup) { // no handle paths for poly-brushes }; - _chart.extendBrush = function () { - var selection = _chart.getBrushSelection(); + _chart.extendBrush = function (selection) { if (_chart.round()) { selection[0] = selection[0].map(_chart.round()); selection[1] = selection[1].map(_chart.round()); - - // _chart.brushSelection(selection); } return selection; }; @@ -405,18 +402,27 @@ dc.scatterPlot = function (parent, chartGroup) { }; _chart._brushing = function () { - var extent = _chart.extendBrush(); + var event = d3v4.event; + // Avoids infinite recursion + // To ensure that when it is called because of brush.move there is no d3v4.event.sourceEvent + d3v4.event = null; + if (!event.sourceEvent) return; + var selection = event.selection; + if (selection) { + selection = selection.map(_chart.x().invert); + } + selection = _chart.extendBrush(selection); - _chart.redrawBrush(_chart.g()); + _chart.redrawBrush(_chart.g(), selection); - if (_chart.brushIsEmpty(extent)) { + if (_chart.brushIsEmpty(selection)) { dc.events.trigger(function () { _chart.filter(null); _chart.redrawGroup(); }); } else { - var ranged2DFilter = dc.filters.RangedTwoDimensionalFilter(extent); + var ranged2DFilter = dc.filters.RangedTwoDimensionalFilter(selection); dc.events.trigger(function () { _chart.filter(null); _chart.filter(ranged2DFilter); diff --git a/web/examples/time-intervals.html b/web/examples/time-intervals.html index 718eeecd7..350bcd981 100644 --- a/web/examples/time-intervals.html +++ b/web/examples/time-intervals.html @@ -16,12 +16,12 @@ any items whose intervals overlap with it.

From 4a5e35c940c8bf82e93558c148987e05578a6a52 Mon Sep 17 00:00:00 2001 From: deepak Date: Fri, 2 Mar 2018 16:49:05 +0530 Subject: [PATCH 19/42] Brushing for Scatter Plot --- src/coordinate-grid-mixin.js | 26 +++++++++++++++++++++-- src/d3-compat/d3-compat02.js | 4 +++- src/scatter-plot.js | 41 ++++++++++++++++++++++++++++++++---- 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/coordinate-grid-mixin.js b/src/coordinate-grid-mixin.js index 7314569ee..4989dc308 100644 --- a/src/coordinate-grid-mixin.js +++ b/src/coordinate-grid-mixin.js @@ -999,7 +999,8 @@ dc.coordinateGridMixin = function (_chart) { // _brush.on('brush', _chart._brushing); // _brush.on('brushstart', _chart._disableMouseZoom); // _brush.on('brushend', configureMouseZoom); - //_brush.on('end', _chart._brush_tmp_end); + + _brush.on('start brush end', _chart._brushing); // To retrieve selection we need _gBrush _gBrush = g.append('g') @@ -1010,7 +1011,6 @@ dc.coordinateGridMixin = function (_chart) { // Set boundaries of the brush _brush.extent([0,0], [brushWidth(), brushHeight()]); - _brush.on('start brush end', _chart._brushing); // _chart.setBrushY(gBrush, false); // _chart.setHandlePaths(gBrush); @@ -1376,6 +1376,28 @@ dc.coordinateGridMixin = function (_chart) { return _chart; }; + /** + * Get or set the brush. Brush must be an instance of d3 brushes + * https://github.com/d3/d3-brush/blob/master/README.md + * @method brush + * @memberof dc.coordinateGridMixin + * @instance + * @param {d3.brush} [brush] + * @returns {d3.brush|dc.coordinateGridMixin} + */ + _chart.brush = function (_) { + if (!arguments.length) { + return _brush; + } + _brush = _; + return _chart; + }; + + // Get the SVG rendered brush + _chart.gBrush = function() { + return _gBrush; + }; + function hasRangeSelected (range) { return range instanceof Array && range.length > 1; } diff --git a/src/d3-compat/d3-compat02.js b/src/d3-compat/d3-compat02.js index 9c4673141..48d7d2bd2 100644 --- a/src/d3-compat/d3-compat02.js +++ b/src/d3-compat/d3-compat02.js @@ -53,12 +53,14 @@ d3.symbols = d3v4.symbols; d3.geo.mercator = d3v4.geoMercator; d3.geoPath = d3v4.geoPath; -d3.geoAlbersUsa = d3.geoAlbersUsa; +d3.geoAlbersUsa = d3v4.geoAlbersUsa; + d3.csv = d3v4.csv; d3.json = d3v4.json; d3.csvFormat = d3v4.csvFormat; d3.csvParse = d3v4.csvParse; +d3.brush = d3v4.brush; d3.brushX = d3v4.brushX; d3.brushSelection = d3v4.brushSelection; diff --git a/src/scatter-plot.js b/src/scatter-plot.js index 6c5df0ed6..0f8a09a66 100644 --- a/src/scatter-plot.js +++ b/src/scatter-plot.js @@ -55,6 +55,9 @@ dc.scatterPlot = function (parent, chartGroup) { var _emptyColor = null; var _filtered = []; + // Use a 2 dimensional brush + _chart.brush(d3.brush()); + function elementSize (d, i) { if (!_existenceAccessor(d)) { return Math.pow(_emptySize, 2); @@ -385,6 +388,27 @@ dc.scatterPlot = function (parent, chartGroup) { _symbol.size(oldSize); } + _chart.updateBrushSelection = function (selection) { + var _brush = _chart.brush(); + var _gBrush = _chart.gBrush(); + + if (_brush && _gBrush) { + + if (selection) { + selection = selection.map(function (point) { + return point.map(function (coord, i) { + var scale = i === 0 ? _chart.x() : _chart.y(); + return scale(coord); + }); + }) + } + + _brush.move(_gBrush, selection); + + // Redraw handles + } + }; + _chart.setHandlePaths = function () { // no handle paths for poly-brushes }; @@ -397,8 +421,8 @@ dc.scatterPlot = function (parent, chartGroup) { return selection; }; - _chart.brushIsEmpty = function (extent) { - return _chart.brush().empty() || !extent || extent[0][0] >= extent[1][0] || extent[0][1] >= extent[1][1]; + _chart.brushIsEmpty = function (selection) { + return !selection || selection[0][0] === selection[1][0] || selection[0][1] === selection[1][1]; }; _chart._brushing = function () { @@ -408,14 +432,23 @@ dc.scatterPlot = function (parent, chartGroup) { d3v4.event = null; if (!event.sourceEvent) return; var selection = event.selection; + + // Testing with pixels is more reliable + var brushIsEmpty = _chart.brushIsEmpty(selection); + if (selection) { - selection = selection.map(_chart.x().invert); + selection = selection.map(function (point) { + return point.map(function (coord, i) { + var scale = i === 0 ? _chart.x() : _chart.y(); + return scale.invert(coord); + }); + }) } selection = _chart.extendBrush(selection); _chart.redrawBrush(_chart.g(), selection); - if (_chart.brushIsEmpty(selection)) { + if (brushIsEmpty) { dc.events.trigger(function () { _chart.filter(null); _chart.redrawGroup(); From 69561b0502610c5656433428602bd1b01c67b100 Mon Sep 17 00:00:00 2001 From: deepak Date: Fri, 2 Mar 2018 20:10:13 +0530 Subject: [PATCH 20/42] Brush extents and background color --- src/coordinate-grid-mixin.js | 20 +++++++------------- style/dc.scss | 5 +---- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/coordinate-grid-mixin.js b/src/coordinate-grid-mixin.js index 4989dc308..88c82f20d 100644 --- a/src/coordinate-grid-mixin.js +++ b/src/coordinate-grid-mixin.js @@ -1002,16 +1002,15 @@ dc.coordinateGridMixin = function (_chart) { _brush.on('start brush end', _chart._brushing); + // Set boundaries of the brush, must set it before applying to _gBrush + _brush.extent([[0,0], [brushWidth(), brushHeight()]]); + // To retrieve selection we need _gBrush _gBrush = g.append('g') .attr('class', 'brush') .attr('transform', 'translate(' + _chart.margins().left + ',' + _chart.margins().top + ')') .call(_brush); - // Set boundaries of the brush - _brush.extent([0,0], [brushWidth(), brushHeight()]); - - // _chart.setBrushY(gBrush, false); // _chart.setHandlePaths(gBrush); if (_chart.hasFilter()) { @@ -1020,18 +1019,11 @@ dc.coordinateGridMixin = function (_chart) { } }; +/* _chart.setHandlePaths = function (gBrush) { gBrush.selectAll('.resize').append('path').attr('d', _chart.resizeHandlePath); }; - - - // D3v4 rework needed - _chart.setBrushY = function (gBrush) { - gBrush.selectAll('rect') - .attr('height', brushHeight()); - gBrush.selectAll('.resize path') - .attr('d', _chart.resizeHandlePath); - }; +*/ _chart.extendBrush = function (selection) { if (selection && _chart.round()) { @@ -1097,6 +1089,7 @@ dc.coordinateGridMixin = function (_chart) { // do nothing, sub-chart should override this function }; +/* // borrowed from Crossfilter example _chart.resizeHandlePath = function (d) { var e = +(d === 'e'), x = e ? 1 : -1, y = brushHeight() / 3; @@ -1110,6 +1103,7 @@ dc.coordinateGridMixin = function (_chart) { 'M' + (4.5 * x) + ',' + (y + 8) + 'V' + (2 * y - 8); }; +*/ function getClipPathId () { return _chart.anchorName().replace(/[ .#=\[\]"]/g, '-') + '-clip'; diff --git a/style/dc.scss b/style/dc.scss index 8844ac771..b17b570dc 100644 --- a/style/dc.scss +++ b/style/dc.scss @@ -96,10 +96,7 @@ div.dc-chart { } .brush { rect { - &.background { - z-index: -999; - } - &.extent { + &.selection { fill: $color_steel_blue; fill-opacity: .125; } From 923fa0b33ca6428718fc79988210a84f0a5b84f0 Mon Sep 17 00:00:00 2001 From: deepak Date: Fri, 2 Mar 2018 20:10:33 +0530 Subject: [PATCH 21/42] Brush extent specs --- spec/bar-chart-spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/bar-chart-spec.js b/spec/bar-chart-spec.js index c1410adc3..6b11a120c 100644 --- a/spec/bar-chart-spec.js +++ b/spec/bar-chart-spec.js @@ -728,19 +728,19 @@ describe('dc.barChart', function () { }); it('should stretch the background', function () { - expect(+chart.select('g.brush rect.background').attr('width')).toBe(1020); + expect(+chart.select('g.brush rect.overlay').attr('width')).toBe(1020); }); it('should set the background height to the chart height', function () { - expect(+chart.select('g.brush rect.background').attr('height')).toBe(160); + expect(+chart.select('g.brush rect.overlay').attr('height')).toBe(160); }); it('should set extent height to the chart height', function () { - expect(+chart.select('g.brush rect.extent').attr('height')).toBe(160); + expect(+chart.select('g.brush rect.selection').attr('height')).toBe(160); }); it('should set extent width based on filter set', function () { - expect(chart.select('g.brush rect.extent').attr('width')).toBeWithinDelta(81, 1); + expect(chart.select('g.brush rect.selection').attr('width')).toBeWithinDelta(81, 1); }); it('should push unselected bars to the background', function () { From 51ba3f80442f47f764b5d65d9babe65f63c259b6 Mon Sep 17 00:00:00 2001 From: deepak Date: Sat, 3 Mar 2018 07:47:36 +0530 Subject: [PATCH 22/42] Brushing works :) --- D3v4 Upgrade Notes.md | 16 +------ src/coordinate-grid-mixin.js | 88 +++++++++++++++--------------------- src/scatter-plot.js | 6 +++ style/dc.scss | 3 +- 4 files changed, 47 insertions(+), 66 deletions(-) diff --git a/D3v4 Upgrade Notes.md b/D3v4 Upgrade Notes.md index 3c3c51c44..8ea4e5c4c 100644 --- a/D3v4 Upgrade Notes.md +++ b/D3v4 Upgrade Notes.md @@ -5,9 +5,6 @@ To look soon: - setters for `xAxis` and `yAxis` update docs for D3v4. - Update docs for `yAxis` or `_useRightYAxis`. These are now related. - `.tension` can now be dropped, it can be handled by `.interpolate` itself -- In brushing events - if change filter is applied on brush end no event - delay is needed - change back to 'brush' to keep consistent with current - behavior. - Lines chart - Area is not working - the function d3.area seems to return different value from D3v3 - manual debugging needed - geoChoroplethChart @@ -17,15 +14,6 @@ Non working examples: - http://localhost:8888/web/examples/area.html (lines ok, area missing) - http://localhost:8888/web/examples/box-plot-time.html - http://localhost:8888/web/examples/line.html (lines ok, area missing) -- http://localhost:8888/web/examples/scatter-brushing.html (brush not working) -- http://localhost:8888/web/examples/splom.html (brush not working) -- http://localhost:8888/web/examples/time-intervals.html - (bar width, brushing not working) +- http://localhost:8888/web/examples/time-intervals.html (bar width) - http://localhost:8888/web/examples/switching-time-intervals.html (warnings) - - - -._brushing -.extendBrush -.redrawBrush -.fadeDeselectedArea +- http://localhost:8888/web/examples/filter-stacks.html (fading is peculiar) \ No newline at end of file diff --git a/src/coordinate-grid-mixin.js b/src/coordinate-grid-mixin.js index 88c82f20d..bcf07cfe8 100644 --- a/src/coordinate-grid-mixin.js +++ b/src/coordinate-grid-mixin.js @@ -47,6 +47,7 @@ dc.coordinateGridMixin = function (_chart) { var _brush = d3.brushX(); var _gBrush; + var _brushHandles; var _brushOn = true; var _round; @@ -963,6 +964,15 @@ dc.coordinateGridMixin = function (_chart) { return _chart; }); + /** + * Get or set the brush. Brush must be an instance of d3 brushes + * https://github.com/d3/d3-brush/blob/master/README.md + * @method brush + * @memberof dc.coordinateGridMixin + * @instance + * @param {d3.brush} [brush] + * @returns {d3.brush|dc.coordinateGridMixin} + */ _chart.brush = function (_) { if (!arguments.length) { return _brush; @@ -971,13 +981,11 @@ dc.coordinateGridMixin = function (_chart) { return _chart; }; - // D3v4 rework needed - function brushHeight () { + function brushHeight() { return _chart.effectiveHeight(); } - // D3v4 rework needed - function brushWidth () { + function brushWidth() { return _chart.effectiveWidth(); } @@ -989,21 +997,15 @@ dc.coordinateGridMixin = function (_chart) { } _brush.move(_gBrush, selection); - - // Redraw handles } }; _chart.renderBrush = function (g) { if (_brushOn) { - // _brush.on('brush', _chart._brushing); - // _brush.on('brushstart', _chart._disableMouseZoom); - // _brush.on('brushend', configureMouseZoom); - _brush.on('start brush end', _chart._brushing); // Set boundaries of the brush, must set it before applying to _gBrush - _brush.extent([[0,0], [brushWidth(), brushHeight()]]); + _brush.extent([[0, 0], [brushWidth(), brushHeight()]]); // To retrieve selection we need _gBrush _gBrush = g.append('g') @@ -1011,19 +1013,22 @@ dc.coordinateGridMixin = function (_chart) { .attr('transform', 'translate(' + _chart.margins().left + ',' + _chart.margins().top + ')') .call(_brush); - // _chart.setHandlePaths(gBrush); + _chart.setHandlePaths(_gBrush); - if (_chart.hasFilter()) { - _chart.redrawBrush(g, _chart.filter(), false); - } + _chart.redrawBrush(g, _chart.filter(), false); } }; -/* _chart.setHandlePaths = function (gBrush) { - gBrush.selectAll('.resize').append('path').attr('d', _chart.resizeHandlePath); + _brushHandles = gBrush.selectAll('.handle--custom').data([{type: "w"}, {type: "e"}]); + + _brushHandles = _brushHandles + .enter() + .append('path') + .attr("class", "handle--custom") + .attr('d', _chart.resizeHandlePath) + .merge(_brushHandles); }; -*/ _chart.extendBrush = function (selection) { if (selection && _chart.round()) { @@ -1067,21 +1072,20 @@ dc.coordinateGridMixin = function (_chart) { }; _chart.redrawBrush = function (g, selection, doTransition) { - // fix for D3v4 _chart.updateBrushSelection(selection); -/* + if (_brushOn) { - if (_chart.filter() && _chart.brush().empty()) { - _chart.brush().extent(_chart.filter()); + if (!selection) { + _brushHandles + .attr("display", "none"); + } else { + _brushHandles + .attr("display", null) + .attr("transform", function (d, i) { + return "translate(" + _x(selection[i]) + ", 0)"; + }); } - - var gBrush = dc.optionalTransition(doTransition, _chart.transitionDuration(), _chart.transitionDelay())(g.select('g.brush')); - _chart.setBrushY(gBrush); - gBrush.call(_chart.brush() - .x(_chart.x()) - .extent(_chart.brush().extent())); } -*/ _chart.fadeDeselectedArea(selection); }; @@ -1089,9 +1093,9 @@ dc.coordinateGridMixin = function (_chart) { // do nothing, sub-chart should override this function }; -/* // borrowed from Crossfilter example _chart.resizeHandlePath = function (d) { + d = d.type; var e = +(d === 'e'), x = e ? 1 : -1, y = brushHeight() / 3; return 'M' + (0.5 * x) + ',' + y + 'A6,6 0 0 ' + e + ' ' + (6.5 * x) + ',' + (y + 6) + @@ -1103,7 +1107,6 @@ dc.coordinateGridMixin = function (_chart) { 'M' + (4.5 * x) + ',' + (y + 8) + 'V' + (2 * y - 8); }; -*/ function getClipPathId () { return _chart.anchorName().replace(/[ .#=\[\]"]/g, '-') + '-clip'; @@ -1212,7 +1215,7 @@ dc.coordinateGridMixin = function (_chart) { _zoom .scaleExtent(_zoomScale) - .extent([[0 ,0], [_chart.width(), _chart.height()]]) + .extent([[0, 0], [_chart.width(), _chart.height()]]) .duration(_chart.transitionDuration()); _chart.root().call(_zoom); @@ -1335,7 +1338,7 @@ dc.coordinateGridMixin = function (_chart) { return _chart; }; - function rangesEqual (range1, range2) { + function rangesEqual(range1, range2) { if (!range1 && !range2) { return true; } else if (!range1 || !range2) { @@ -1370,25 +1373,8 @@ dc.coordinateGridMixin = function (_chart) { return _chart; }; - /** - * Get or set the brush. Brush must be an instance of d3 brushes - * https://github.com/d3/d3-brush/blob/master/README.md - * @method brush - * @memberof dc.coordinateGridMixin - * @instance - * @param {d3.brush} [brush] - * @returns {d3.brush|dc.coordinateGridMixin} - */ - _chart.brush = function (_) { - if (!arguments.length) { - return _brush; - } - _brush = _; - return _chart; - }; - // Get the SVG rendered brush - _chart.gBrush = function() { + _chart.gBrush = function () { return _gBrush; }; diff --git a/src/scatter-plot.js b/src/scatter-plot.js index 0f8a09a66..9da4cb66e 100644 --- a/src/scatter-plot.js +++ b/src/scatter-plot.js @@ -465,6 +465,12 @@ dc.scatterPlot = function (parent, chartGroup) { } }; + _chart.redrawBrush = function (g, selection, doTransition) { + // override default x axis brush from parent chart + _chart.updateBrushSelection(selection); + _chart.fadeDeselectedArea(selection); + }; + _chart.setBrushY = function (gBrush) { gBrush.call(_chart.brush().y(_chart.y())); }; diff --git a/style/dc.scss b/style/dc.scss index b17b570dc..ca3506413 100644 --- a/style/dc.scss +++ b/style/dc.scss @@ -101,9 +101,10 @@ div.dc-chart { fill-opacity: .125; } } - .resize path { + .handle--custom { fill: $color_gallery; stroke: $color_storm_dust; + cursor: ew-resize; } } path { From 6dbceed00da70924bc1a2d05dbf7447790133cca Mon Sep 17 00:00:00 2001 From: deepak Date: Sat, 3 Mar 2018 07:56:30 +0530 Subject: [PATCH 23/42] Current status --- D3v4 Upgrade Notes.md | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/D3v4 Upgrade Notes.md b/D3v4 Upgrade Notes.md index 8ea4e5c4c..1f8d32a89 100644 --- a/D3v4 Upgrade Notes.md +++ b/D3v4 Upgrade Notes.md @@ -1,19 +1,32 @@ -To look soon: - -- Need proper color matcher for Jasmine (Low) -- Need proper URL matcher for Jasmine (Low) -- setters for `xAxis` and `yAxis` update docs for D3v4. -- Update docs for `yAxis` or `_useRightYAxis`. These are now related. -- `.tension` can now be dropped, it can be handled by `.interpolate` itself -- Lines chart - Area is not working - the function d3.area seems to return different - value from D3v3 - manual debugging needed -- geoChoroplethChart - -Non working examples: +##Non working examples - http://localhost:8888/web/examples/area.html (lines ok, area missing) - http://localhost:8888/web/examples/box-plot-time.html - http://localhost:8888/web/examples/line.html (lines ok, area missing) - http://localhost:8888/web/examples/time-intervals.html (bar width) -- http://localhost:8888/web/examples/switching-time-intervals.html (warnings) -- http://localhost:8888/web/examples/filter-stacks.html (fading is peculiar) \ No newline at end of file +- http://localhost:8888/web/examples/switching-time-intervals.html + (warnings) +- http://localhost:8888/web/examples/filter-stacks.html + (fading is peculiar) + + +##Issues to be fixed + +- Lines chart - Area is not working +- geoChoroplethChart +- Bar width +- Peculiar fading in filter-stacks.html +- Need proper color matcher for Jasmine (Low) +- Need proper URL matcher for Jasmine (Low) +- Update/fix test cases + + +##Before release + +- Update documentation + + - setters for `xAxis` and `yAxis` update docs for D3v4. + - Update docs for `yAxis` or `_useRightYAxis`. These are now related. + - `.tension` can now be dropped, it can be handled by `.interpolate` itself + +- Prepare upgrade guide From 9c4abdf57f6b78bb383c1d257ec9b60becdb8324 Mon Sep 17 00:00:00 2001 From: deepak Date: Sat, 3 Mar 2018 17:12:30 +0530 Subject: [PATCH 24/42] Bar width corrected --- D3v4 Upgrade Notes.md | 5 ----- src/coordinate-grid-mixin.js | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/D3v4 Upgrade Notes.md b/D3v4 Upgrade Notes.md index 1f8d32a89..5e4206a40 100644 --- a/D3v4 Upgrade Notes.md +++ b/D3v4 Upgrade Notes.md @@ -1,11 +1,7 @@ ##Non working examples - http://localhost:8888/web/examples/area.html (lines ok, area missing) -- http://localhost:8888/web/examples/box-plot-time.html - http://localhost:8888/web/examples/line.html (lines ok, area missing) -- http://localhost:8888/web/examples/time-intervals.html (bar width) -- http://localhost:8888/web/examples/switching-time-intervals.html - (warnings) - http://localhost:8888/web/examples/filter-stacks.html (fading is peculiar) @@ -14,7 +10,6 @@ - Lines chart - Area is not working - geoChoroplethChart -- Bar width - Peculiar fading in filter-stacks.html - Need proper color matcher for Jasmine (Low) - Need proper URL matcher for Jasmine (Low) diff --git a/src/coordinate-grid-mixin.js b/src/coordinate-grid-mixin.js index bcf07cfe8..f02fc22d2 100644 --- a/src/coordinate-grid-mixin.js +++ b/src/coordinate-grid-mixin.js @@ -399,7 +399,7 @@ dc.coordinateGridMixin = function (_chart) { */ _chart.xUnitCount = function () { if (_unitCount === undefined) { - var units = _chart.xUnits()(_chart.x().domain()[0], _chart.x().domain()[1], _chart.x().domain()); + var units = _chart.xUnits()(_chart.x().domain()[0], _chart.x().domain()[1]); if (units instanceof Array) { _unitCount = units.length; From 04ed7c9171a1fba65f2e966982ed1587bba2d5c5 Mon Sep 17 00:00:00 2001 From: deepak Date: Sat, 3 Mar 2018 20:20:11 +0530 Subject: [PATCH 25/42] Area is working --- D3v4 Upgrade Notes.md | 3 --- src/line-chart.js | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/D3v4 Upgrade Notes.md b/D3v4 Upgrade Notes.md index 5e4206a40..dd6e6109f 100644 --- a/D3v4 Upgrade Notes.md +++ b/D3v4 Upgrade Notes.md @@ -1,14 +1,11 @@ ##Non working examples -- http://localhost:8888/web/examples/area.html (lines ok, area missing) -- http://localhost:8888/web/examples/line.html (lines ok, area missing) - http://localhost:8888/web/examples/filter-stacks.html (fading is peculiar) ##Issues to be fixed -- Lines chart - Area is not working - geoChoroplethChart - Peculiar fading in filter-stacks.html - Need proper color matcher for Jasmine (Low) diff --git a/src/line-chart.js b/src/line-chart.js index f0de9ee68..aafa945de 100644 --- a/src/line-chart.js +++ b/src/line-chart.js @@ -229,7 +229,7 @@ dc.lineChart = function (parent, chartGroup) { .x(function (d) { return _chart.x()(d.x); }) - .y(function (d) { + .y1(function (d) { return _chart.y()(d.y + d.y0); }) .y0(function (d) { From e08d8ff0e85b982a67ee3b9a41dcb731250ff7d3 Mon Sep 17 00:00:00 2001 From: deepak Date: Sat, 3 Mar 2018 21:15:24 +0530 Subject: [PATCH 26/42] geoChoroplethChart --- D3v4 Upgrade Notes.md | 5 ++--- src/geo-choropleth-chart.js | 1 - web/vc/index.html | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/D3v4 Upgrade Notes.md b/D3v4 Upgrade Notes.md index dd6e6109f..6138ca3a9 100644 --- a/D3v4 Upgrade Notes.md +++ b/D3v4 Upgrade Notes.md @@ -6,11 +6,10 @@ ##Issues to be fixed -- geoChoroplethChart -- Peculiar fading in filter-stacks.html +- Peculiar fading in filter-stacks.html (Low) - Need proper color matcher for Jasmine (Low) - Need proper URL matcher for Jasmine (Low) -- Update/fix test cases +- Update/fix test cases (High) ##Before release diff --git a/src/geo-choropleth-chart.js b/src/geo-choropleth-chart.js index bd3d4c891..7a6c5c418 100644 --- a/src/geo-choropleth-chart.js +++ b/src/geo-choropleth-chart.js @@ -105,7 +105,6 @@ dc.geoChoroplethChart = function (parent, chartGroup) { } return baseClasses; }); - return regionG; } diff --git a/web/vc/index.html b/web/vc/index.html index afafe9972..dc205e00f 100644 --- a/web/vc/index.html +++ b/web/vc/index.html @@ -137,9 +137,9 @@

US Venture Capital Landscape 2011

.overlayGeoJson(statesJson.features, "state", function (d) { return d.properties.name; }) - .projection(d3.geoAlbersUsa) + .projection(d3.geoAlbersUsa()) .valueAccessor(function(kv) { - // console.log(kv); + console.log(kv); return kv.value; }) .title(function (d) { From 9390423bac9318bf359c3f943fb290c4705bc98e Mon Sep 17 00:00:00 2001 From: deepak Date: Sat, 3 Mar 2018 21:19:46 +0530 Subject: [PATCH 27/42] Functional completeness --- D3v4 Upgrade Notes.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/D3v4 Upgrade Notes.md b/D3v4 Upgrade Notes.md index 6138ca3a9..80ac44336 100644 --- a/D3v4 Upgrade Notes.md +++ b/D3v4 Upgrade Notes.md @@ -6,14 +6,21 @@ ##Issues to be fixed -- Peculiar fading in filter-stacks.html (Low) +- Peculiar fading in filter-stacks.html (Medium) - Need proper color matcher for Jasmine (Low) - Need proper URL matcher for Jasmine (Low) - Update/fix test cases (High) +- Remove D3v3 compat (High) + + - Apply renames + - Apply d3.dispatch changes + - Move remaining compat functions inside dc namespace ##Before release +- All High priority issues +- Possibly Medium priority issues - Update documentation - setters for `xAxis` and `yAxis` update docs for D3v4. From 10aebbbdc6af5707856fd778881e107f14df28a5 Mon Sep 17 00:00:00 2001 From: deepak Date: Sun, 4 Mar 2018 18:35:26 +0530 Subject: [PATCH 28/42] dispatch directly implemented, compatibility code discarded. base-mixin test cases passing --- spec/base-mixin-spec.js | 188 +++++++++++++++++++++-------------- spec/helpers/spec-helper.js | 3 - src/base-mixin.js | 18 ++-- src/d3-compat/d3-compat02.js | 31 +----- 4 files changed, 126 insertions(+), 114 deletions(-) diff --git a/spec/base-mixin-spec.js b/spec/base-mixin-spec.js index e626ac23d..2f2db406f 100644 --- a/spec/base-mixin-spec.js +++ b/spec/base-mixin-spec.js @@ -28,116 +28,159 @@ describe('dc.baseMixin', function () { }); describe('renderlets', function () { - var firstRenderlet, secondRenderlet, thirdRenderlet, - pretransition; - beforeEach(function () { - var expectedCallbackSignature = function (callbackChart) { + it('should not execute a renderlet until after the render transitions', function (done) { + var firstRenderlet = jasmine.createSpy().and.callFake(function (callbackChart) { expect(callbackChart).toBe(chart); - }; - firstRenderlet = jasmine.createSpy().and.callFake(expectedCallbackSignature); - secondRenderlet = jasmine.createSpy().and.callFake(expectedCallbackSignature); - thirdRenderlet = jasmine.createSpy().and.callFake(expectedCallbackSignature); - pretransition = jasmine.createSpy().and.callFake(expectedCallbackSignature); - chart.renderlet(firstRenderlet); // still testing renderlet event-namespace generation here - chart.renderlet(secondRenderlet); - chart.on('renderlet.third', thirdRenderlet); - chart.on('pretransition.pret', pretransition); - }); - - it('should not execute a renderlet until after the render transitions', function () { + done(); + }); + chart.renderlet(firstRenderlet); chart.render(); expect(firstRenderlet).not.toHaveBeenCalled(); flushAllD3Transitions(); - expect(firstRenderlet).toHaveBeenCalled(); + // Test will wait until firstRenderlet has been called }); - it('should not execute a renderlet until after the redraw transitions', function () { + it('should not execute a renderlet until after the redraw transitions', function (done) { + var firstRenderlet = jasmine.createSpy().and.callFake(function (callbackChart) { + expect(callbackChart).toBe(chart); + done(); + }); + chart.renderlet(firstRenderlet); chart.redraw(); expect(firstRenderlet).not.toHaveBeenCalled(); flushAllD3Transitions(); - expect(firstRenderlet).toHaveBeenCalled(); + // Test will wait until firstRenderlet has been called }); it('should execute pretransition event before the render transitions', function () { + var pretransition = jasmine.createSpy(); + chart.on('pretransition.pret', pretransition); chart.render(); - expect(pretransition).toHaveBeenCalled(); + expect(pretransition).toHaveBeenCalledWith(chart); flushAllD3Transitions(); }); it('should execute pretransition event before the redraw transitions', function () { + var pretransition = jasmine.createSpy(); + chart.on('pretransition.pret', pretransition); chart.redraw(); - expect(pretransition).toHaveBeenCalled(); + expect(pretransition).toHaveBeenCalledWith(chart); flushAllD3Transitions(); }); - it('should execute each renderlet after a render', function () { + it('should execute each renderlet after a render', function (done) { + var count = 0; + var renderlet = jasmine.createSpy().and.callFake(function (callbackChart) { + expect(callbackChart).toBe(chart); + count++; + if(count === 2){ + done(); + } + }); + var firstRenderlet = renderlet, + secondRenderlet = firstRenderlet; + chart.renderlet(firstRenderlet); + chart.renderlet(firstRenderlet); chart.render(); flushAllD3Transitions(); - expect(firstRenderlet).toHaveBeenCalled(); - expect(secondRenderlet).toHaveBeenCalled(); + // Test will wait till firstRenderlet and secondRenderlet both have been called }); - it('should execute each renderlet after a redraw', function () { + it('should execute each renderlet after a redraw', function (done) { + var count = 0; + var renderlet = jasmine.createSpy().and.callFake(function (callbackChart) { + expect(callbackChart).toBe(chart); + count++; + if(count === 2){ + done(); + } + }); + var firstRenderlet = renderlet, + secondRenderlet = firstRenderlet; + chart.renderlet(firstRenderlet); + chart.renderlet(firstRenderlet); chart.redraw(); flushAllD3Transitions(); - expect(firstRenderlet).toHaveBeenCalled(); - expect(secondRenderlet).toHaveBeenCalled(); + // Test will wait till firstRenderlet and secondRenderlet both have been called }); - it('should execute a named renderlet after a render', function () { + it('should execute a named renderlet after a render', function (done) { + var thirdRenderlet = jasmine.createSpy().and.callFake(function (callbackChart) { + expect(callbackChart).toBe(chart); + done(); + }); + chart.on('renderlet.third', thirdRenderlet); chart.render(); + expect(thirdRenderlet).not.toHaveBeenCalled(); flushAllD3Transitions(); - expect(thirdRenderlet).toHaveBeenCalled(); + // Test will wait until thirdRenderlet has been called }); - it('should execute a named renderlet after a redraw', function () { + it('should execute a named renderlet after a redraw', function (done) { + var thirdRenderlet = jasmine.createSpy().and.callFake(function (callbackChart) { + expect(callbackChart).toBe(chart); + done(); + }); + chart.on('renderlet.third', thirdRenderlet); chart.redraw(); flushAllD3Transitions(); - expect(thirdRenderlet).toHaveBeenCalled(); + // Test will wait until thirdRenderlet has been called }); - it('should remove a named renderlet expect no call after a redraw', function () { + it('should remove a named renderlet expect no call after a redraw', function (done) { + var secondRenderlet = jasmine.createSpy().and.callFake(function (callbackChart) { + expect(thirdRenderlet).not.toHaveBeenCalled(); + done(); + }); + var thirdRenderlet = jasmine.createSpy(); + chart.on('renderlet.third' , secondRenderlet); + chart.renderlet(secondRenderlet); chart.on('renderlet.third'); chart.redraw(); flushAllD3Transitions(); - expect(secondRenderlet).toHaveBeenCalled(); - expect(thirdRenderlet).not.toHaveBeenCalled(); + // Test will wait until secondRenderlet has been called }); - it('should remove a named renderlet and expect no call after a redraw', function () { + it('should remove a named renderlet and expect no call after a render', function (done) { + var secondRenderlet = jasmine.createSpy().and.callFake(function (callbackChart) { + expect(thirdRenderlet).not.toHaveBeenCalled(); + done(); + }); + var thirdRenderlet = jasmine.createSpy(); + chart.on('renderlet.third' , secondRenderlet); + chart.renderlet(secondRenderlet); chart.on('renderlet.third'); chart.render(); flushAllD3Transitions(); - expect(secondRenderlet).toHaveBeenCalled(); - expect(thirdRenderlet).not.toHaveBeenCalled(); + // Test will wait until secondRenderlet has been called }); }); describe('event listeners', function () { describe('on render', function () { - var preRenderSpy, postRenderSpy; - beforeEach(function () { - var expectedCallbackSignature = function (callbackChart) { - expect(callbackChart).toBe(chart); - }; - - preRenderSpy = jasmine.createSpy().and.callFake(expectedCallbackSignature); - postRenderSpy = jasmine.createSpy().and.callFake(expectedCallbackSignature); - - chart.on('preRender', preRenderSpy); - chart.on('postRender', postRenderSpy); - }); - it('should execute the preRender callback', function () { + var preRenderSpy = jasmine.createSpy(); + chart.on('preRender', preRenderSpy); chart.render(); flushAllD3Transitions(); - expect(preRenderSpy).toHaveBeenCalled(); + expect(preRenderSpy).toHaveBeenCalledWith(chart); }); - it('should execute the postRender callback', function () { + it('should execute the postRender callback', function (done) { + var preRenderSpy = jasmine.createSpy(); + var postRender = function (callbackChart) { + // By now preRender must have been called + expect(preRenderSpy).toHaveBeenCalledWith(chart); + + expect(callbackChart).toBe(chart); + done(); + }; + + chart.on('preRender', preRenderSpy); + chart.on('postRender', postRender); chart.render(); flushAllD3Transitions(); - expect(postRenderSpy).toHaveBeenCalled(); + // Test case will wait until postRender has been called }); }); @@ -199,30 +242,30 @@ describe('dc.baseMixin', function () { }); describe('on redraw', function () { - var preRedrawSpy, postRedrawSpy; - beforeEach(function () { - var expectedCallbackSignature = function (callbackChart) { - expect(callbackChart).toBe(chart); - }; - - preRedrawSpy = jasmine.createSpy().and.callFake(expectedCallbackSignature); - postRedrawSpy = jasmine.createSpy().and.callFake(expectedCallbackSignature); - - chart.on('preRedraw', preRedrawSpy); - chart.on('postRedraw', postRedrawSpy); - }); - it('should execute the preRedraw callback before transitions', function () { + var preRedrawSpy = jasmine.createSpy(); + chart.on('preRedraw', preRedrawSpy); chart.redraw(); - expect(preRedrawSpy).toHaveBeenCalled(); + expect(preRedrawSpy).toHaveBeenCalledWith(chart); flushAllD3Transitions(); }); - it('should execute the postRedraw callback after transitions', function () { + it('should execute the postRedraw callback after transitions', function (done) { + var preRedrawSpy = jasmine.createSpy(); + var postRedraw = function (callbackChart) { + // By now preRedraw must have been called + expect(preRedrawSpy).toHaveBeenCalledWith(chart); + + expect(callbackChart).toBe(chart); + done(); + }; + var postRedrawSpy = jasmine.createSpy().and.callFake(postRedraw); + chart.on('preRedraw', preRedrawSpy); + chart.on('postRedraw', postRedraw); chart.redraw(); expect(postRedrawSpy).not.toHaveBeenCalled(); flushAllD3Transitions(); - expect(postRedrawSpy).toHaveBeenCalled(); + // The test case will wait till postRedraw has been called }); }); }); @@ -364,10 +407,9 @@ describe('dc.baseMixin', function () { describe('when set to a falsy on a sized div', function () { var h0, w0; beforeEach(function () { - dimdiv.style({ - height: '220px', - width: '230px' - }); + dimdiv + .style('height', '220px') + .style('width', '230px'); chart.width(null).height(null).render(); w0 = chart.width(); h0 = chart.height(); diff --git a/spec/helpers/spec-helper.js b/spec/helpers/spec-helper.js index 0e96ceef6..f0b75b6d3 100644 --- a/spec/helpers/spec-helper.js +++ b/spec/helpers/spec-helper.js @@ -45,9 +45,6 @@ function cleanDateRange (range) { // http://stackoverflow.com/questions/20068497/d3-transition-in-unit-testing function flushAllD3Transitions () { - var now = Date.now; - Date.now = function () { return Infinity; }; d3.timer.flush(); - Date.now = now; } /* jshint +W098 */ diff --git a/src/base-mixin.js b/src/base-mixin.js index 79f1e00ab..0f9d8adb9 100644 --- a/src/base-mixin.js +++ b/src/base-mixin.js @@ -688,7 +688,7 @@ dc.baseMixin = function (_chart) { */ _chart.render = function () { _height = _width = undefined; // force recalculate - _listeners.preRender(_chart); + _listeners.call('preRender', _chart, _chart); if (_mandatoryAttributes) { _mandatoryAttributes.forEach(checkForMandatoryAttributes); @@ -706,19 +706,19 @@ dc.baseMixin = function (_chart) { }; _chart._activateRenderlets = function (event) { - _listeners.pretransition(_chart); + _listeners.call('pretransition', _chart, _chart); if (_chart.transitionDuration() > 0 && _svg) { _svg.transition().duration(_chart.transitionDuration()).delay(_chart.transitionDelay()) .on('end', function () { - _listeners.renderlet(_chart); + _listeners.call('renderlet', _chart, _chart); if (event) { - _listeners[event](_chart); + _listeners.call(event, _chart, _chart); } }); } else { - _listeners.renderlet(_chart); + _listeners.call('renderlet', _chart, _chart); if (event) { - _listeners[event](_chart); + _listeners.call(event, _chart, _chart); } } }; @@ -738,7 +738,7 @@ dc.baseMixin = function (_chart) { */ _chart.redraw = function () { sizeSvg(); - _listeners.preRedraw(_chart); + _listeners.call('preRedraw', _chart, _chart); var result = _chart._doRedraw(); @@ -821,12 +821,12 @@ dc.baseMixin = function (_chart) { _chart._invokeFilteredListener = function (f) { if (f !== undefined) { - _listeners.filtered(_chart, f); + _listeners.call('filtered', _chart, _chart, f); } }; _chart._invokeZoomedListener = function () { - _listeners.zoomed(_chart); + _listeners.call('zoomed', _chart, _chart); }; var _hasFilterHandler = function (filters, filter) { diff --git a/src/d3-compat/d3-compat02.js b/src/d3-compat/d3-compat02.js index 48d7d2bd2..b752b929c 100644 --- a/src/d3-compat/d3-compat02.js +++ b/src/d3-compat/d3-compat02.js @@ -32,6 +32,8 @@ d3.time.days.utc = d3v4.utcDays; d3.time.scale = {}; d3.time.scale.utc = d3v4.scaleUtc; +d3.timeout = d3v4.timeout; + d3.easeQuadIn = d3v4.easeQuadIn; d3.scale.log = d3v4.scaleLog; @@ -92,35 +94,6 @@ d3.functor = function (v) { }; -// Behavior of d3.dispatch has changed, ultimately changes will -// be applied to code directly - thankfully used in code only once -d3._dispatch_tmp_fn_gen = function (_dispatch, event) { - return function () { - _dispatch.apply(event, this, arguments); - }; -}; - -d3.dispatch = function () { - var _out = {}; - var _dispatch = d3v4.dispatch.apply(this, arguments); - - for (var i = 0; i < arguments.length; i++) { - var event = arguments[i]; - _out[event] = this._dispatch_tmp_fn_gen(_dispatch, event); - } - - _out.on = function (event, callback) { - _dispatch.on(event, callback); - }; - - return _out; -}; - - -// Brushes - used only once, significant changes -// - - // Significant changes in d3.layout.stack - copying from D3v3 for now d3.permute = d3v4.permute; From 5b7cdcac8eb79ea685adad331c338b1e3b1d3835 Mon Sep 17 00:00:00 2001 From: deepak Date: Sun, 4 Mar 2018 20:17:40 +0530 Subject: [PATCH 29/42] All specs passing --- Gruntfile.js | 63 ++++++++++++++---------------- spec/bar-chart-spec.js | 23 +++++++---- spec/biggish-data-spec.js | 4 +- spec/box-plot-spec.js | 6 +-- spec/bubble-chart-spec.js | 4 +- spec/color-spec.js | 16 ++++---- spec/composite-chart-spec.js | 55 ++++++++++++++------------ spec/coordinate-grid-chart-spec.js | 43 +++++++++++++------- spec/helpers/custom_matchers.js | 32 ++++++++++++++- spec/helpers/spec-helper.js | 28 +++++++++++++ spec/legend-spec.js | 6 +-- spec/line-chart-spec.js | 39 +++++++++--------- spec/scatter-plot-spec.js | 17 +++++--- spec/series-chart-spec.js | 24 ++++++------ src/box-plot.js | 4 +- src/bubble-chart.js | 4 +- src/coordinate-grid-mixin.js | 40 +++++++++++++------ src/d3-compat/d3-compat02.js | 4 ++ 18 files changed, 260 insertions(+), 152 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 109458197..fdc77120a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -155,39 +155,36 @@ module.exports = function (grunt) { summary: true, specs: [ '<%= conf.spec %>/*-spec.js' - -/* - '<%= conf.spec %>/bar-chart-spec.js', - '<%= conf.spec %>/base-mixin-spec.js', - '<%= conf.spec %>/biggish-data-spec.js', - '<%= conf.spec %>/box-plot-spec.js', - '<%= conf.spec %>/bubble-chart-spec.js', - '<%= conf.spec %>/bubble-overlay-spec.js', - '<%= conf.spec %>/cap-mixin-spec.js', - '<%= conf.spec %>/color-spec.js', // Need proper color matcher - '<%= conf.spec %>/composite-chart-spec.js', - '<%= conf.spec %>/coordinate-grid-chart-spec.js', - '<%= conf.spec %>/core-spec.js', - '<%= conf.spec %>/data-addition-spec.js', - '<%= conf.spec %>/data-count-spec.js', - '<%= conf.spec %>/data-grid-spec.js', - '<%= conf.spec %>/data-table-spec.js', - '<%= conf.spec %>/event-spec.js', - '<%= conf.spec %>/filter-dates-spec.js', - '<%= conf.spec %>/filters-spec.js', - '<%= conf.spec %>/geo-choropleth-chart-spec.js', - '<%= conf.spec %>/heatmap-spec.js', - '<%= conf.spec %>/legend-spec.js', - '<%= conf.spec %>/line-chart-spec.js', - '<%= conf.spec %>/logger-spec.js', - '<%= conf.spec %>/number-display-spec.js', - '<%= conf.spec %>/pie-chart-spec.js', - '<%= conf.spec %>/row-chart-spec.js', - '<%= conf.spec %>/scatter-plot-spec.js', - '<%= conf.spec %>/select-menu-spec.js', - '<%= conf.spec %>/series-chart-spec.js', - '<%= conf.spec %>/utils-spec.js' -*/ + // '<%= conf.spec %>/bar-chart-spec.js', + // '<%= conf.spec %>/base-mixin-spec.js', + // '<%= conf.spec %>/biggish-data-spec.js', + // '<%= conf.spec %>/box-plot-spec.js', + // '<%= conf.spec %>/bubble-chart-spec.js', + // '<%= conf.spec %>/bubble-overlay-spec.js', + // '<%= conf.spec %>/cap-mixin-spec.js', + // '<%= conf.spec %>/color-spec.js', + // '<%= conf.spec %>/composite-chart-spec.js', + // '<%= conf.spec %>/coordinate-grid-chart-spec.js', + // '<%= conf.spec %>/core-spec.js', + // '<%= conf.spec %>/data-addition-spec.js', + // '<%= conf.spec %>/data-count-spec.js', + // '<%= conf.spec %>/data-grid-spec.js', + // '<%= conf.spec %>/data-table-spec.js', + // '<%= conf.spec %>/event-spec.js', + // '<%= conf.spec %>/filter-dates-spec.js', + // '<%= conf.spec %>/filters-spec.js', + // '<%= conf.spec %>/geo-choropleth-chart-spec.js', + // '<%= conf.spec %>/heatmap-spec.js', + // '<%= conf.spec %>/legend-spec.js', + // '<%= conf.spec %>/line-chart-spec.js', + // '<%= conf.spec %>/logger-spec.js', + // '<%= conf.spec %>/number-display-spec.js', + // '<%= conf.spec %>/pie-chart-spec.js', + // '<%= conf.spec %>/row-chart-spec.js', + // '<%= conf.spec %>/scatter-plot-spec.js', + // '<%= conf.spec %>/select-menu-spec.js', + // '<%= conf.spec %>/series-chart-spec.js', + // '<%= conf.spec %>/utils-spec.js' ], helpers: [ '<%= conf.web %>/js/jasmine-jsreporter.js', diff --git a/spec/bar-chart-spec.js b/spec/bar-chart-spec.js index 6b11a120c..11730b7b7 100644 --- a/spec/bar-chart-spec.js +++ b/spec/bar-chart-spec.js @@ -716,13 +716,14 @@ describe('dc.barChart', function () { }); it('should create a fancy brush resize handle', function () { - chart.select('g.brush').selectAll('.resize path').each(function (d, i) { + var selectAll = chart.select('g.brush').selectAll('path.handle--custom'); + selectAll.each(function (d, i) { if (i === 0) { expect(d3.select(this).attr('d')) - .toMatchPath('M0.5,53 A6,6 0 0 1 6.5,59 V100 A6,6 0 0 1 0.5,106 ZM2.5,61 V98 M4.5,61 V98'); + .toMatchPath('M-0.5,53 A6,6 0 0 0 -6.5,59 V100 A6,6 0 0 0 -0.5,106 ZM-2.5,61 V98 M-4.5,61 V98'); } else { expect(d3.select(this).attr('d')) - .toMatchPath('M-0.5,53 A6,6 0 0 0 -6.5,59 V100 A6,6 0 0 0 -0.5,106 ZM-2.5,61 V98 M-4.5,61 V98'); + .toMatchPath('M0.5,53 A6,6 0 0 1 6.5,59 V100 A6,6 0 0 1 0.5,106 ZM2.5,61 V98 M4.5,61 V98'); } }); }); @@ -1107,8 +1108,11 @@ describe('dc.barChart', function () { chart.alwaysUseRounding(false); consoleWarnSpy = spyOn(console, 'warn'); chart.render(); - chart.brush().extent([makeDate(2012, 6, 1), makeDate(2012, 7, 15)]); - chart.brush().event(chart.root()); + + // Setup a dummy event - just enough for the handler to get fooled + setupEventForBrushing(chart, [makeDate(2012, 6, 1), makeDate(2012, 7, 15)]); + // Directly call the handler + chart._brushing(); }); it('should log a warning indicating that brush rounding was disabled', function () { @@ -1126,13 +1130,16 @@ describe('dc.barChart', function () { beforeEach(function () { chart.alwaysUseRounding(true); chart.render(); - chart.brush().extent([makeDate(2012, 6, 1), makeDate(2012, 7, 15)]); - chart.brush().event(chart.root()); + // Setup a dummy event - just enough for the handler to get fooled + setupEventForBrushing(chart, [makeDate(2012, 6, 1), makeDate(2012, 7, 15)]); + // Directly call the handler + chart._brushing(); }); it('should round the brush', function () { jasmine.clock().tick(100); - expect(chart.brush().extent()).toEqual([makeDate(2012, 6, 1), makeDate(2012, 7, 1)]); + var filter = cleanDateRange(chart.filter()); + expect(filter).toEqual([makeDate(2012, 6, 1), makeDate(2012, 7, 1)]); }); }); }); diff --git a/spec/biggish-data-spec.js b/spec/biggish-data-spec.js index 27d0653ed..ea13f4a57 100644 --- a/spec/biggish-data-spec.js +++ b/spec/biggish-data-spec.js @@ -89,7 +89,7 @@ describe('dc.barChart.biggish', function () { .margins({top: 30, right: 50, bottom: 25, left: 40}) .renderArea(true) .height(200) - .x(d3.time.scale().domain(extentDay)) + .x(d3.scaleTime().domain(extentDay)) .renderHorizontalGridLines(true) .rangeChart(chartRange) .transitionDuration(1000) @@ -116,7 +116,7 @@ describe('dc.barChart.biggish', function () { .xUnits(d3.time.hours) .round(d3.time.hour.round) .alwaysUseRounding(true) - .x(d3.time.scale().domain(extentDay)) + .x(d3.scaleTime().domain(extentDay)) // hide the range chart's y axis // note: breaks function chaining by returning the yAxis diff --git a/spec/box-plot-spec.js b/spec/box-plot-spec.js index 6a10a8e4e..5be74d60c 100644 --- a/spec/box-plot-spec.js +++ b/spec/box-plot-spec.js @@ -198,13 +198,13 @@ describe('dc.boxPlot', function () { function box (n) { var nthBox = d3.select(chart.selectAll('g.box').nodes()[n]); nthBox.boxText = function (n) { - return d3.select(this.selectAll('text.box')[0][n]); + return d3.select(this.selectAll('text.box').nodes()[n]); }; nthBox.whiskerLine = function (n) { - return d3.select(this.selectAll('line.whisker')[0][n]); + return d3.select(this.selectAll('line.whisker').nodes()[n]); }; nthBox.whiskerText = function (n) { - return d3.select(this.selectAll('text.whisker')[0][n]); + return d3.select(this.selectAll('text.whisker').nodes()[n]); }; return nthBox; } diff --git a/spec/bubble-chart-spec.js b/spec/bubble-chart-spec.js index 3ae5eaebe..b0b462f93 100644 --- a/spec/bubble-chart-spec.js +++ b/spec/bubble-chart-spec.js @@ -695,7 +695,7 @@ describe('dc.bubbleChart', function () { } describe('column filtering with straight crossfilter', function () { beforeEach(function () { - var axisLabel = d3.select(heatMap.selectAll('.cols.axis text')[0][3]); + var axisLabel = d3.select(heatMap.selectAll('.cols.axis text').nodes()[3]); axisLabel.on('click')(axisLabel.datum()); d3.timer.flush(); }); @@ -713,7 +713,7 @@ describe('dc.bubbleChart', function () { beforeEach(function () { chart.group(clone_group(sepalGroup)); chart.render(); - var axisLabel = d3.select(heatMap.selectAll('.cols.axis text')[0][3]); + var axisLabel = d3.select(heatMap.selectAll('.cols.axis text').nodes()[3]); axisLabel.on('click')(axisLabel.datum()); d3.timer.flush(); }); diff --git a/spec/color-spec.js b/spec/color-spec.js index d30382092..3b98d2c06 100644 --- a/spec/color-spec.js +++ b/spec/color-spec.js @@ -17,24 +17,24 @@ describe('dc.colorMixin', function () { }); it('default', function () { - expect(colorTest(chart, domain)).toEqual(['#3182bd','#6baed6','#9ecae1','#c6dbef','#e6550d']); + expect(colorTest(chart, domain)).toMatchColors(['#3182bd','#6baed6','#9ecae1','#c6dbef','#e6550d']); }); it('custom', function () { chart.colors(d3.scale.category10()); - expect(colorTest(chart, domain)).toEqual(['#1f77b4','#ff7f0e','#2ca02c','#d62728','#9467bd']); + expect(colorTest(chart, domain)).toMatchColors(['#1f77b4','#ff7f0e','#2ca02c','#d62728','#9467bd']); }); it('ordinal', function () { chart.ordinalColors(['red','green','blue']); - expect(colorTest(chart, domain)).toEqual(['red','green','blue','red','green']); + expect(colorTest(chart, domain)).toMatchColors(['red','green','blue','red','green']); }); it('linear', function () { // GIGO: mapping ordinal domain to linear scale is nonsensical // actually it gets scaled to NaN and then d3 corrects it chart.linearColors(['#ff0000','#00ff00']); - expect(colorTest(chart, domain)).toEqual(['#000000', '#000000', '#000000', '#000000', '#000000']); + expect(colorTest(chart, domain)).toMatchColors(['#000000', '#000000', '#000000', '#000000', '#000000']); }); }); describe('with numeric domain' , function () { @@ -48,22 +48,22 @@ describe('dc.colorMixin', function () { }); it('default', function () { - expect(colorTest(chart, domain, test)).toEqual(['#9ecae1','#3182bd','#c6dbef','#6baed6','#e6550d','#3182bd']); + expect(colorTest(chart, domain, test)).toMatchColors(['#9ecae1','#3182bd','#c6dbef','#6baed6','#e6550d','#3182bd']); }); it('custom', function () { chart.colors(d3.scale.category10()); - expect(colorTest(chart, domain, test)).toEqual(['#2ca02c', '#1f77b4', '#d62728', '#ff7f0e', '#9467bd', '#1f77b4']); + expect(colorTest(chart, domain, test)).toMatchColors(['#2ca02c', '#1f77b4', '#d62728', '#ff7f0e', '#9467bd', '#1f77b4']); }); it('ordinal', function () { chart.ordinalColors(['red','green','blue']); - expect(colorTest(chart, domain, test)).toEqual(['blue', 'red', 'red', 'green', 'green', 'red']); + expect(colorTest(chart, domain, test)).toMatchColors(['blue', 'red', 'red', 'green', 'green', 'red']); }); it('linear', function () { chart.linearColors(['#4575b4','#ffffbf']); - expect(colorTest(chart, domain, test)).toEqual(['#4773b3', '#4575b4', '#4dc6c1', '#ffffbf', '#ffffc0', '#4575b4']); + expect(colorTest(chart, domain, test)).toMatchColors(['#4773b3', '#4575b4', '#4dc6c1', '#ffffbf', '#ffffc0', '#4575b4']); }); }); describe('calculateColorDomain' , function () { diff --git a/spec/composite-chart-spec.js b/spec/composite-chart-spec.js index 66c19de8e..025f35b8b 100644 --- a/spec/composite-chart-spec.js +++ b/spec/composite-chart-spec.js @@ -236,32 +236,28 @@ describe('dc.compositeChart', function () { }); it('should have a resize handle', function () { - expect(chart.selectAll('g.brush .resize path').size()).not.toBe(0); - chart.selectAll('g.brush .resize path').each(function (d, i) { + expect(chart.selectAll('g.brush path.handle--custom').size()).not.toBe(0); + chart.selectAll('g.brush path.handle--custom').each(function (d, i) { if (i === 0) { - expect(d3.select(this).attr('d')) - .toMatchPath('M0.5,36.666666666666664A6,6 0 0 1 6.5,42.666666666666664V67.33333333333333A6,' + - '6 0 0 1 0.5,73.33333333333333ZM2.5,44.666666666666664V65.33333333333333M4.5,' + - '44.666666666666664V65.33333333333333'); - } else { expect(d3.select(this).attr('d')) .toMatchPath('M-0.5,36.666666666666664A6,6 0 0 0 -6.5,42.666666666666664V67.33333333333333A6,' + - '6 0 0 0 -0.5,73.33333333333333ZM-2.5,44.666666666666664V65.33333333333333M-4.5,' + - '44.666666666666664V65.33333333333333'); + '6 0 0 0 -0.5,73.33333333333333ZM-2.5,44.666666666666664V65.33333333333333M-4.5,' + + '44.666666666666664V65.33333333333333'); + } else { + expect(d3.select(this).attr('d')) + .toMatchPath('M0.5,36.666666666666664A6,6 0 0 1 6.5,42.666666666666664V67.33333333333333A6,' + + '6 0 0 1 0.5,73.33333333333333ZM2.5,44.666666666666664V65.33333333333333M4.5,' + + '44.666666666666664V65.33333333333333'); } }); }); it('should stretch the background', function () { - expect(chart.select('g.brush rect.background').attr('width')).toBe('420'); + expect(chart.select('g.brush rect.overlay').attr('width')).toBe('420'); }); it('should set the height of background to height of chart', function () { - expect(chart.select('g.brush rect.background').attr('height')).toBe('110'); - }); - - it('should set the extent height to chart height', function () { - expect(chart.select('g.brush rect.extent').attr('height')).toBe('110'); + expect(chart.select('g.brush rect.overlay').attr('height')).toBe('110'); }); describe('when filtering the chart', function () { @@ -269,8 +265,12 @@ describe('dc.compositeChart', function () { chart.filter([makeDate(2012, 5, 1), makeDate(2012, 5, 30)]).redraw(); }); + it('should set the extent height to chart height', function () { + expect(chart.select('g.brush rect.selection').attr('height')).toBe('110'); + }); + it('should set extent width to chart width based on filter set', function () { - expect(chart.select('g.brush rect.extent').attr('width')).toBe('140'); + expect(chart.select('g.brush rect.selection').attr('width')).toBe('140'); }); it('should fade filtered bars into the background', function () { @@ -547,10 +547,11 @@ describe('dc.compositeChart', function () { describe('when composing charts with just a right axis', function () { beforeEach(function () { - chart.yAxis().ticks(7); chart.compose([ dc.lineChart(chart).group(dateGroup).useRightYAxis(true) - ]).renderHorizontalGridLines(true).render(); + ]).renderHorizontalGridLines(true); + chart.rightYAxis().ticks(7); + chart.render(); }); it('should only render a right y axis', function () { @@ -697,8 +698,10 @@ describe('dc.compositeChart', function () { beforeEach(function () { otherDimension = data.dimension(function (d) { return [+d.value, +d.nvalue]; }); - chart.brush().extent([22, 35]); - chart.brush().on('brush')(); + // Setup a dummy event - just enough for the handler to get fooled + setupEventForBrushing(chart, [22, 35]); + // Directly call the handler + chart._brushing(); chart.redraw(); }); @@ -708,8 +711,10 @@ describe('dc.compositeChart', function () { describe('brush decreases in size', function () { beforeEach(function () { - chart.brush().extent([22, 33]); - chart.brush().on('brush')(); + // Setup a dummy event - just enough for the handler to get fooled + setupEventForBrushing(chart, [22, 33]); + // Directly call the handler + chart._brushing(); chart.redraw(); }); @@ -721,8 +726,10 @@ describe('dc.compositeChart', function () { describe('brush disappears', function () { beforeEach(function () { - chart.brush().extent([22, 22]); - chart.brush().on('brush')(); + // Setup a dummy event - just enough for the handler to get fooled + setupEventForBrushing(chart, [22, 22]); + // Directly call the handler + chart._brushing(); chart.redraw(); }); diff --git a/spec/coordinate-grid-chart-spec.js b/spec/coordinate-grid-chart-spec.js index eeb0f0657..ef53200b3 100644 --- a/spec/coordinate-grid-chart-spec.js +++ b/spec/coordinate-grid-chart-spec.js @@ -307,6 +307,10 @@ describe('dc.coordinateGridChart', function () { describe('y-axes', function () { describe('grid lines', function () { beforeEach(function () { + // The calculations have changed internally for tick count from D3v3 to D3v4 + // By default it guesses 10 ticks and computes from there. In v3 it ends up with 7 in v4 + // it is 16. For 9 as well as 11 both the versions agree. + chart.yAxis().ticks(9); chart .renderHorizontalGridLines(true) .renderVerticalGridLines(true) @@ -314,7 +318,7 @@ describe('dc.coordinateGridChart', function () { }); describe('horizontal grid lines', function () { - it('should draw lines associated with the data shown on the right y-axis', function () { + it('should draw lines associated with the data shown on the y-axis', function () { var nthGridLine = function (n) { return d3.select(chart.selectAll('.grid-line.horizontal line').nodes()[n]); }; expect(chart.selectAll('.grid-line.horizontal line').size()).toBe(7); @@ -640,8 +644,12 @@ describe('dc.coordinateGridChart', function () { chart.filter(filter); }); - it('should update the brush extent', function () { - expect(chart.getBrushSelection()).toEqual(filter); + it('should update the brush selection', function () { + // expect(chart.getBrushSelection()).toEqual(filter); + var brushSelectionRect = chart.select('g.brush rect.selection'); + expect(brushSelectionRect.attr('x')).toBeCloseTo(chart.x()(filter[0]), 1); + expect(+brushSelectionRect.attr('x') + +brushSelectionRect.attr('width')) + .toBeCloseTo(chart.x()(filter[1]), 1); }); }); @@ -653,8 +661,9 @@ describe('dc.coordinateGridChart', function () { chart.filter(null); }); - it('should clear the brush extent', function () { - expect(chart.brushIsEmpty(chart.getBrushSelection())); + it('should clear the brush selection', function () { + var brushSelectionRect = chart.select('g.brush rect.selection'); + expect(+brushSelectionRect.attr('width')).toEqual(0); }); }); @@ -792,19 +801,20 @@ describe('dc.coordinateGridChart', function () { describe('brushing', function () { beforeEach(function () { chart.brushOn(true); + chart.render(); }); // D3v4 needs reimplementation, APIs have changed describe('with equal dates', function () { beforeEach(function () { - spyOn(chart, 'filter'); - chart.brush().clear(); - chart.render(); - chart.brush().event(chart.root()); + // Setup a dummy event - just enough for the handler to get fooled + setupEventForBrushing(chart, [22, 22]); + // Directly call the handler + chart._brushing(); }); it('should clear the chart filter', function () { - expect(chart.filter()).toEqual(undefined); + expect(chart.filter()).toBeFalsy(); }); }); }); @@ -822,17 +832,20 @@ describe('dc.coordinateGridChart', function () { it('should zoom the focus chart when range chart is brushed', function () { spyOn(chart, 'focus').and.callThrough(); - rangeChart.brush().extent(selectedRange); - rangeChart.brush().event(rangeChart.g()); + // Setup a dummy event - just enough for the handler to get fooled + setupEventForBrushing(rangeChart, selectedRange); + // Directly call the handler + rangeChart._brushing(); jasmine.clock().tick(100); - // expect(chart.focus).toHaveBeenCalledWith(selectedRange); var focus = cleanDateRange(chart.focus.calls.argsFor(0)[0]); expect(focus).toEqual(selectedRange); }); it('should zoom the focus chart back out when range chart is un-brushed', function () { - rangeChart.brush().extent(selectedRange); - rangeChart.brush().event(rangeChart.g()); + // Setup a dummy event - just enough for the handler to get fooled + setupEventForBrushing(rangeChart, selectedRange); + // Directly call the handler + rangeChart._brushing(); jasmine.clock().tick(100); expect(chart.x().domain()).toEqual(selectedRange); diff --git a/spec/helpers/custom_matchers.js b/spec/helpers/custom_matchers.js index 557d45710..3fb5607c5 100644 --- a/spec/helpers/custom_matchers.js +++ b/spec/helpers/custom_matchers.js @@ -188,8 +188,20 @@ beforeEach(function () { toMatchUrl: function () { return { compare: function (actual, url) { - var regexp = new RegExp('url\\("?' + url + '"?\\)'); - expect(actual).toMatch(regexp); + /* + URL can be like: + url(http://localhost:8888/spec/?random=true#composite-chart-clip) + http://localhost:8888/spec/?random=true#composite-chart-clip + http://localhost:8888/spec/##composite-chart-clip + */ + var cleanURL = function(u) { + var matches = u.match(/url\((.*)\)/); + if (matches) { + u = matches[1]; + } + return u.replace(/\#+/, '#'); + }; + expect(cleanURL(actual)).toEqual(cleanURL(url)); return {pass: true}; } }; @@ -208,6 +220,22 @@ beforeEach(function () { return { compare: compareIntList }; + }, + toMatchColors: function () { + return { + compare: function (actual, expected) { + // Colors can be rgb(0, 0, 0), #000000 or black + var normalizeColor = function(c){ + // will convert to rgb(0, 0, 0) + return d3.color(c).toString(); + }; + actual = actual.map(normalizeColor); + expected = expected.map(normalizeColor); + + expect(actual).toEqual(expected); + return {pass: true}; + } + }; } }); }); diff --git a/spec/helpers/spec-helper.js b/spec/helpers/spec-helper.js index f0b75b6d3..120d95590 100644 --- a/spec/helpers/spec-helper.js +++ b/spec/helpers/spec-helper.js @@ -47,4 +47,32 @@ function cleanDateRange (range) { function flushAllD3Transitions () { d3.timer.flush(); } + +// Setup a dummy event - just enough for the handler to get fooled +var setupEventForBrushing = function (chart, domainSelection) { + // D3v4 needs scaled coordinates for the event + var scaledSelection = domainSelection.map(function (coord) { + return chart.x()(coord); + }); + d3v4.event = { + sourceEvent: true, + selection: scaledSelection + }; +}; + +// Setup a dummy event - just enough for the handler to get fooled +var setupEventFor2DBrushing = function (chart, domainSelection) { + // D3v4 needs scaled coordinates for the event + var scaledSelection = domainSelection.map(function (point) { + return point.map(function (coord, i) { + var scale = i === 0 ? chart.x() : chart.y(); + return scale(coord); + }); + }); + d3v4.event = { + sourceEvent: true, + selection: scaledSelection + }; +}; + /* jshint +W098 */ diff --git a/spec/legend-spec.js b/spec/legend-spec.js index 74dd01436..8548c5ae5 100644 --- a/spec/legend-spec.js +++ b/spec/legend-spec.js @@ -69,7 +69,7 @@ describe('dc.legend', function () { }); it('not allow hiding stacks be default', function () { - legendItem(0).on('click').call(legendItem(0)[0][0], legendItem(0).datum()); + legendItem(0).on('click').call(legendItem(0).nodes()[0], legendItem(0).datum()); expect(chart.selectAll('path.line').size()).toBe(3); }); @@ -247,7 +247,7 @@ describe('dc.legend', function () { describe('clicking on a legend item', function () { beforeEach(function () { - legendItem(0).on('click').call(legendItem(0)[0][0], legendItem(0).datum()); + legendItem(0).on('click').call(legendItem(0).nodes()[0], legendItem(0).datum()); }); it('should fade out the legend item', function () { @@ -265,7 +265,7 @@ describe('dc.legend', function () { describe('clicking on a faded out legend item', function () { beforeEach(function () { - legendItem(0).on('click').call(legendItem(0)[0][0], legendItem(0).datum()); + legendItem(0).on('click').call(legendItem(0).nodes()[0], legendItem(0).datum()); }); it('should unfade the legend item', function () { diff --git a/spec/line-chart-spec.js b/spec/line-chart-spec.js index dc7dd39b9..44e6cc8b5 100644 --- a/spec/line-chart-spec.js +++ b/spec/line-chart-spec.js @@ -252,7 +252,7 @@ describe('dc.lineChart', function () { var x; beforeEach(function () { var dot = chart.select('circle.dot'); - dot.on('mousemove').call(dot[0][0]); + dot.on('mousemove').call(dot.nodes()[0]); x = dot.attr('cx'); }); @@ -268,7 +268,7 @@ describe('dc.lineChart', function () { var x; beforeEach(function () { var dot = chart.select('circle.dot'); - dot.on('mousemove').call(dot[0][0]); + dot.on('mousemove').call(dot.nodes()[0]); x = dot.attr('cx'); }); @@ -284,7 +284,7 @@ describe('dc.lineChart', function () { beforeEach(function () { chart.useRightYAxis(true).render(); var dot = chart.select('circle.dot'); - dot.on('mousemove').call(dot[0][0]); + dot.on('mousemove').call(dot.nodes()[0]); x = dot.attr('cx'); }); @@ -429,9 +429,9 @@ describe('dc.lineChart', function () { it('should draw tooltip dots on top of paths and areas', function () { var list = chart.selectAll('circle.dot, path.line, path.area'); - var indexOfLastLine = list[0].indexOf(list.filter('path.line')[0][2]); - var indexOfLastArea = list[0].indexOf(list.filter('path.area')[0][2]); - var indexOfDot = list[0].indexOf(list.filter('circle.dot')[0][0]); + var indexOfLastLine = list.nodes().indexOf(list.filter('path.line').nodes()[2]); + var indexOfLastArea = list.nodes().indexOf(list.filter('path.area').nodes()[2]); + var indexOfDot = list.nodes().indexOf(list.filter('circle.dot').nodes()[0]); expect(indexOfDot).toBeGreaterThan(indexOfLastArea); expect(indexOfDot).toBeGreaterThan(indexOfLastLine); @@ -440,11 +440,11 @@ describe('dc.lineChart', function () { it('should draw tooltip ref lines on top of paths', function () { var list = chart.selectAll('path.yRef, path.xRef, path.line, path.area'); - var indexOfLastLine = list[0].indexOf(list.filter('path.line')[0][2]); - var indexOfLastArea = list[0].indexOf(list.filter('path.area')[0][2]); + var indexOfLastLine = list.nodes().indexOf(list.filter('path.line').nodes()[2]); + var indexOfLastArea = list.nodes().indexOf(list.filter('path.area').nodes()[2]); - var indexOfFirstYRef = list[0].indexOf(list.filter('path.yRef')[0][0]); - var indexOfFirstXRef = list[0].indexOf(list.filter('path.xRef')[0][0]); + var indexOfFirstYRef = list.nodes().indexOf(list.filter('path.yRef').nodes()[0]); + var indexOfFirstXRef = list.nodes().indexOf(list.filter('path.xRef').nodes()[0]); expect(indexOfLastLine).toBeLessThan(indexOfFirstXRef); expect(indexOfLastLine).toBeLessThan(indexOfFirstYRef); @@ -673,31 +673,32 @@ describe('dc.lineChart', function () { }); it('should create a fancy brush resize handle', function () { - chart.select('g.brush').selectAll('.resize path').each(function (d, i) { + var selectAll = chart.select('g.brush').selectAll('path.handle--custom'); + selectAll.each(function (d, i) { if (i === 0) { expect(d3.select(this).attr('d')) - .toMatchPath('M0.5,53 A6,6 0 0 1 6.5,59 V100 A6,6 0 0 1 0.5,106 ZM2.5,61 V98 M4.5,61 V98'); + .toMatchPath('M-0.5,53 A6,6 0 0 0 -6.5,59 V100 A6,6 0 0 0 -0.5,106 ZM-2.5,61 V98 M-4.5,61 V98'); } else { expect(d3.select(this).attr('d')) - .toMatchPath('M-0.5,53 A6,6 0 0 0 -6.5,59 V100 A6,6 0 0 0 -0.5,106 ZM-2.5,61 V98 M-4.5,61 V98'); + .toMatchPath('M0.5,53 A6,6 0 0 1 6.5,59 V100 A6,6 0 0 1 0.5,106 ZM2.5,61 V98 M4.5,61 V98'); } }); }); it('should stretch the background', function () { - expect(chart.select('g.brush rect.background').attr('width')).toBe('1020'); + expect(chart.select('g.brush rect.overlay').attr('width')).toBe('1020'); }); it('should set the background height to the chart height', function () { - expect(chart.select('g.brush rect.background').attr('height')).toBe('160'); + expect(chart.select('g.brush rect.overlay').attr('height')).toBe('160'); }); it('should set extent height to the chart height', function () { - expect(chart.select('g.brush rect.extent').attr('height')).toBe('160'); + expect(chart.select('g.brush rect.selection').attr('height')).toBe('160'); }); it('should set extent width based on filter set', function () { - expect(chart.select('g.brush rect.extent').attr('width')).toBeWithinDelta(88, 1); + expect(chart.select('g.brush rect.selection').attr('width')).toBeWithinDelta(88, 1); }); it('should not have an area path', function () { @@ -740,7 +741,7 @@ describe('dc.lineChart', function () { .render(); }); it('updates dot colors', function () { - expect(chart.select('circle.dot')[0][0].attributes.fill.value).toMatch(/#ff0000/i); + expect(chart.select('circle.dot').nodes()[0].attributes.fill.value).toMatch(/#ff0000/i); }); }); @@ -751,7 +752,7 @@ describe('dc.lineChart', function () { function lineLabelPositions () { var LABEL_PADDING = 3; chart.selectAll('.stack').nodes().forEach(function (stack, i) { - d3.select(stack).selectAll('text.lineLabel')[0].forEach(function (lineLabel, j) { + d3.select(stack).selectAll('text.lineLabel').nodes().forEach(function (lineLabel, j) { expect(+d3.select(lineLabel).attr('x')).toBeCloseTo(chart.x()(chart.data()[i].values[j].x)); expect(+d3.select(lineLabel).attr('y') + LABEL_PADDING).toBeCloseTo(chart.y()(chart.data()[i].values[j].y + chart.data()[i].values[j].y0)); diff --git a/spec/scatter-plot-spec.js b/spec/scatter-plot-spec.js index dc1620755..7bd29fbd1 100644 --- a/spec/scatter-plot-spec.js +++ b/spec/scatter-plot-spec.js @@ -229,8 +229,11 @@ describe('dc.scatterPlot', function () { beforeEach(function () { otherDimension = data.dimension(function (d) { return [+d.value, +d.nvalue]; }); - chart.brush().extent([[22, -3], [44, 2]]); - chart.brush().on('brush')(); + // Setup a dummy event - just enough for the handler to get fooled + setupEventFor2DBrushing(chart, [[22, -3], [44, 2]]); + // Directly call the handler + chart._brushing(); + chart.redraw(); }); @@ -239,9 +242,11 @@ describe('dc.scatterPlot', function () { expect(otherDimension.top(Infinity).length).toBe(3); }); +/* D3v4 - no easy replacement, dropping this case it('should set the height of the brush to the height implied by the extent', function () { expect(chart.select('g.brush rect.extent').attr('height')).toBe('46'); }); +*/ it('should not add handles to the brush', function () { expect(chart.select('.resize path').empty()).toBeTruthy(); @@ -307,8 +312,10 @@ describe('dc.scatterPlot', function () { }); it('should restore sizes, colors, and opacity when the brush is empty', function () { - chart.brush().extent([[22, 2], [22, -3]]); - chart.brush().on('brush')(); + // Setup a dummy event - just enough for the handler to get fooled + setupEventFor2DBrushing(chart, [[22, 2], [22, -3]]); + // Directly call the handler + chart._brushing(); jasmine.clock().tick(100); selectedPoints = symbolsOfRadius(chart.symbolSize()); @@ -357,7 +364,7 @@ describe('dc.scatterPlot', function () { function symbolsMatching (pred) { function getData (symbols) { - return symbols[0].map(function (symbol) { + return symbols.nodes().map(function (symbol) { return d3.select(symbol).datum(); }); } diff --git a/spec/series-chart-spec.js b/spec/series-chart-spec.js index 00320fc29..33a2abcaa 100644 --- a/spec/series-chart-spec.js +++ b/spec/series-chart-spec.js @@ -45,22 +45,22 @@ describe('dc.seriesChart', function () { it('should position generated lineCharts using the data', function () { var lines = chart.selectAll('path.line'); - expect(d3.select(lines[0][0]).attr('d')).toMatchPath('M0,128L130,85'); - expect(d3.select(lines[0][1]).attr('d')).toMatchPath('M0,43L130,0'); + expect(d3.select(lines.nodes()[0]).attr('d')).toMatchPath('M0,128L130,85'); + expect(d3.select(lines.nodes()[1]).attr('d')).toMatchPath('M0,43L130,0'); }); it('should color lines using the colors in the data', function () { var lines = chart.selectAll('path.line'); - expect(d3.select(lines[0][0]).attr('stroke')).toMatch(/#000001/i); - expect(d3.select(lines[0][1]).attr('stroke')).toMatch(/#000002/i); + expect(d3.select(lines.nodes()[0]).attr('stroke')).toMatch(/#000001/i); + expect(d3.select(lines.nodes()[1]).attr('stroke')).toMatch(/#000002/i); }); describe('with brush off', function () { it('should create line chart dots', function () { chart.brushOn(false).render(); var dots = chart.selectAll('circle.dot'); - expect(dots[0].length).toEqual(4); + expect(dots.nodes().length).toEqual(4); chart.brushOn(true); }); }); @@ -76,8 +76,8 @@ describe('dc.seriesChart', function () { it('should order lineCharts in the order specified', function () { var lines = chart.selectAll('path.line'); - expect(d3.select(lines[0][1]).attr('d')).toMatchPath('M0,128L130,85'); - expect(d3.select(lines[0][0]).attr('d')).toMatchPath('M0,43L130,0'); + expect(d3.select(lines.nodes()[1]).attr('d')).toMatchPath('M0,128L130,85'); + expect(d3.select(lines.nodes()[0]).attr('d')).toMatchPath('M0,43L130,0'); }); }); @@ -90,11 +90,11 @@ describe('dc.seriesChart', function () { var lines = chart.selectAll('path.line'); var areas = chart.selectAll('path.area'); - expect(d3.select(lines[0][0]).attr('stroke-dasharray')).toEqualIntList('3,1,1'); - expect(d3.select(lines[0][1]).attr('stroke-dasharray')).toEqualIntList('3,1,1'); + expect(d3.select(lines.nodes()[0]).attr('stroke-dasharray')).toEqualIntList('3,1,1'); + expect(d3.select(lines.nodes()[1]).attr('stroke-dasharray')).toEqualIntList('3,1,1'); - expect(d3.select(areas[0][0]).attr('fill')).toMatch(/#000001/i); - expect(d3.select(areas[0][1]).attr('fill')).toMatch(/#000002/i); + expect(d3.select(areas.nodes()[0]).attr('fill')).toMatch(/#000001/i); + expect(d3.select(areas.nodes()[1]).attr('fill')).toMatch(/#000002/i); }); }); @@ -127,7 +127,7 @@ describe('dc.seriesChart', function () { it('is redrawn with dots', function () { var dots = chart.selectAll('circle.dot'); - expect(dots[0].length).toEqual(6); + expect(dots.nodes().length).toEqual(6); }); }); }); diff --git a/src/box-plot.js b/src/box-plot.js index bf9789b6d..5df71bc2c 100644 --- a/src/box-plot.js +++ b/src/box-plot.js @@ -146,8 +146,8 @@ dc.boxPlot = function (parent, chartGroup) { var boxesG = _chart.chartBodyG().selectAll('g.box').data(_chart.data(), _chart.keyAccessor()); - boxesG = renderBoxes(boxesG); - updateBoxes(boxesG); + var boxesGEnterUpdate = renderBoxes(boxesG); + updateBoxes(boxesGEnterUpdate); removeBoxes(boxesG); _chart.fadeDeselectedArea(_chart.filter()); diff --git a/src/bubble-chart.js b/src/bubble-chart.js index e739ca7fe..5ad4d9688 100644 --- a/src/bubble-chart.js +++ b/src/bubble-chart.js @@ -110,7 +110,7 @@ dc.bubbleChart = function (parent, chartGroup) { function bubbleX (d) { var x = _chart.x()(_chart.keyAccessor()(d)); - if (isNaN(x)) { + if (isNaN(x) || !isFinite(x)) { x = 0; } return x; @@ -118,7 +118,7 @@ dc.bubbleChart = function (parent, chartGroup) { function bubbleY (d) { var y = _chart.y()(_chart.valueAccessor()(d)); - if (isNaN(y)) { + if (isNaN(y) || !isFinite(y)) { y = 0; } return y; diff --git a/src/coordinate-grid-mixin.js b/src/coordinate-grid-mixin.js index f02fc22d2..2e5f4bc1d 100644 --- a/src/coordinate-grid-mixin.js +++ b/src/coordinate-grid-mixin.js @@ -399,7 +399,13 @@ dc.coordinateGridMixin = function (_chart) { */ _chart.xUnitCount = function () { if (_unitCount === undefined) { - var units = _chart.xUnits()(_chart.x().domain()[0], _chart.x().domain()[1]); + var units; + if(_chart.xUnits() === dc.units.ordinal) { + // In this case it number of items in domain + units = _chart.x().domain(); + } else { + units = _chart.xUnits()(_chart.x().domain()[0], _chart.x().domain()[1]); + } if (units instanceof Array) { _unitCount = units.length; @@ -426,13 +432,6 @@ dc.coordinateGridMixin = function (_chart) { return _useRightYAxis; } _useRightYAxis = useRightYAxis; - - if (_useRightYAxis) { - _yAxis = d3.axisRight(); - } else { - _yAxis = d3.axisLeft(); - } - return _chart; }; @@ -469,9 +468,14 @@ dc.coordinateGridMixin = function (_chart) { _x.domain([_chart.xAxisMin(), _chart.xAxisMax()]); } } else { // _chart.isOrdinal() - // D3v4 - find better place to put it - // It is special subclass that support rangeBands - _x = d3.scaleBand(); + // D3v4 - Ordinal charts would need scaleBand + // bandwidth is a method in scaleBand + // (https://github.com/d3/d3-scale/blob/master/README.md#scaleBand) + if (!_x.bandwidth) { + // copy the original domain to the new scale + _x = d3.scaleBand().domain(_x.domain()); + } + if (_chart.elasticX() || _x.domain().length === 0) { _x.domain(_chart._ordinalXDomain()); } @@ -617,6 +621,17 @@ dc.coordinateGridMixin = function (_chart) { } _y.range([_chart.yAxisHeight(), 0]); + + // Ideally we should update the API so that if someone uses Right Y Axis + // they would need to pass _yAxis as well + if (!_yAxis) { + if (_useRightYAxis) { + _yAxis = d3.axisRight(); + } else { + _yAxis = d3.axisLeft(); + } + } + _yAxis = _yAxis.scale(_y); _chart._renderHorizontalGridLinesForAxis(g, _y, _yAxis); @@ -666,7 +681,8 @@ dc.coordinateGridMixin = function (_chart) { var gridLineG = g.select('g.' + HORIZONTAL_CLASS); if (_renderHorizontalGridLine) { - var ticks = axis.tickValues() ? axis.tickValues() : scale.ticks(axis.ticks()[0]); + // Last part copied from https://github.com/d3/d3-axis/blob/master/src/axis.js#L48 + var ticks = axis.tickValues() ? axis.tickValues() : scale.ticks.apply(scale, axis.tickArguments()); if (gridLineG.empty()) { gridLineG = g.insert('g', ':first-child') diff --git a/src/d3-compat/d3-compat02.js b/src/d3-compat/d3-compat02.js index b752b929c..4063a607d 100644 --- a/src/d3-compat/d3-compat02.js +++ b/src/d3-compat/d3-compat02.js @@ -28,6 +28,8 @@ d3.time.years = d3v4.timeYears; d3.time.day.utc = d3v4.utcDay; d3.time.days.utc = d3v4.utcDays; +d3.time.month.utc = d3v4.utcMonth; + d3.time.scale = {}; d3.time.scale.utc = d3v4.scaleUtc; @@ -57,6 +59,8 @@ d3.geo.mercator = d3v4.geoMercator; d3.geoPath = d3v4.geoPath; d3.geoAlbersUsa = d3v4.geoAlbersUsa; +d3.color = d3v4.color; + d3.csv = d3v4.csv; d3.json = d3v4.json; From 8056643bf01de304101ad9518db53dea2db0d520 Mon Sep 17 00:00:00 2001 From: deepak Date: Tue, 6 Mar 2018 23:39:30 +0530 Subject: [PATCH 30/42] All specs passing --- D3v4 Upgrade Notes.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/D3v4 Upgrade Notes.md b/D3v4 Upgrade Notes.md index 80ac44336..04c0336f0 100644 --- a/D3v4 Upgrade Notes.md +++ b/D3v4 Upgrade Notes.md @@ -7,9 +7,6 @@ ##Issues to be fixed - Peculiar fading in filter-stacks.html (Medium) -- Need proper color matcher for Jasmine (Low) -- Need proper URL matcher for Jasmine (Low) -- Update/fix test cases (High) - Remove D3v3 compat (High) - Apply renames From a832f1cfdd773647ed72b7ea7d5e31076858322b Mon Sep 17 00:00:00 2001 From: deepak Date: Fri, 9 Mar 2018 14:53:17 +0530 Subject: [PATCH 31/42] Merged D3v3-compat --- Gruntfile.js | 46 +-------- spec/bar-chart-spec.js | 56 +++++------ spec/base-mixin-spec.js | 2 +- spec/biggish-data-spec.js | 16 ++- spec/box-plot-spec.js | 2 +- spec/bubble-chart-spec.js | 28 +++--- spec/bubble-overlay-spec.js | 2 +- spec/color-spec.js | 4 +- spec/composite-chart-spec.js | 16 +-- spec/coordinate-grid-chart-spec.js | 16 +-- spec/data-addition-spec.js | 4 +- spec/data-count-spec.js | 2 +- spec/data-grid-spec.js | 2 +- spec/data-table-spec.js | 2 +- spec/geo-choropleth-chart-spec.js | 4 +- spec/heatmap-spec.js | 10 +- spec/helpers/fixtures.js | 2 +- spec/helpers/spec-helper.js | 6 +- spec/legend-spec.js | 6 +- spec/line-chart-spec.js | 14 +-- spec/number-display-spec.js | 24 ++--- spec/pie-chart-spec.js | 6 +- spec/row-chart-spec.js | 6 +- spec/scatter-plot-spec.js | 8 +- spec/series-chart-spec.js | 2 +- spec/utils-spec.js | 2 +- src/box-plot.js | 2 +- src/bubble-mixin.js | 6 +- src/color-mixin.js | 14 +-- src/composite-chart.js | 10 +- src/coordinate-grid-mixin.js | 28 +++--- src/core.js | 6 +- src/d3-compat/d3-compat00.js | 4 - src/d3-compat/d3-compat01.js | 42 -------- src/d3.box.js | 6 +- .../d3-compat02.js => d3v3-compat.js} | 97 +------------------ src/geo-choropleth-chart.js | 6 +- src/line-chart.js | 24 ++--- src/pie-chart.js | 8 +- src/row-chart.js | 2 +- src/scatter-plot.js | 24 ++--- src/select-menu.js | 4 +- src/stack-mixin.js | 10 +- src/utils.js | 13 ++- 44 files changed, 207 insertions(+), 387 deletions(-) delete mode 100644 src/d3-compat/d3-compat00.js delete mode 100644 src/d3-compat/d3-compat01.js rename src/{d3-compat/d3-compat02.js => d3v3-compat.js} (58%) diff --git a/Gruntfile.js b/Gruntfile.js index fdc77120a..ae6056ddf 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -29,14 +29,6 @@ module.exports = function (grunt) { banner: '<%= conf.banner %>' } }, - d3compat: { - src: '<%= conf.src %>/d3-compat/*.js', - dest: 'd3-compat.js', - options: { - process: true, - sourceMap: true - } - }, welcome: { src: ['docs/welcome.base.md', 'web/img/class-hierarchy.svg'], dest: 'welcome.md', @@ -153,39 +145,7 @@ module.exports = function (grunt) { options: { display: 'short', summary: true, - specs: [ - '<%= conf.spec %>/*-spec.js' - // '<%= conf.spec %>/bar-chart-spec.js', - // '<%= conf.spec %>/base-mixin-spec.js', - // '<%= conf.spec %>/biggish-data-spec.js', - // '<%= conf.spec %>/box-plot-spec.js', - // '<%= conf.spec %>/bubble-chart-spec.js', - // '<%= conf.spec %>/bubble-overlay-spec.js', - // '<%= conf.spec %>/cap-mixin-spec.js', - // '<%= conf.spec %>/color-spec.js', - // '<%= conf.spec %>/composite-chart-spec.js', - // '<%= conf.spec %>/coordinate-grid-chart-spec.js', - // '<%= conf.spec %>/core-spec.js', - // '<%= conf.spec %>/data-addition-spec.js', - // '<%= conf.spec %>/data-count-spec.js', - // '<%= conf.spec %>/data-grid-spec.js', - // '<%= conf.spec %>/data-table-spec.js', - // '<%= conf.spec %>/event-spec.js', - // '<%= conf.spec %>/filter-dates-spec.js', - // '<%= conf.spec %>/filters-spec.js', - // '<%= conf.spec %>/geo-choropleth-chart-spec.js', - // '<%= conf.spec %>/heatmap-spec.js', - // '<%= conf.spec %>/legend-spec.js', - // '<%= conf.spec %>/line-chart-spec.js', - // '<%= conf.spec %>/logger-spec.js', - // '<%= conf.spec %>/number-display-spec.js', - // '<%= conf.spec %>/pie-chart-spec.js', - // '<%= conf.spec %>/row-chart-spec.js', - // '<%= conf.spec %>/scatter-plot-spec.js', - // '<%= conf.spec %>/select-menu-spec.js', - // '<%= conf.spec %>/series-chart-spec.js', - // '<%= conf.spec %>/utils-spec.js' - ], + specs: '<%= conf.spec %>/*-spec.js', helpers: [ '<%= conf.web %>/js/jasmine-jsreporter.js', '<%= conf.spec %>/helpers/*.js' @@ -199,7 +159,6 @@ module.exports = function (grunt) { }, src: [ '<%= conf.web %>/js/d3.js', - '<%= conf.web %>/js/d3-compat.js', '<%= conf.web %>/js/crossfilter.js', '<%= conf.web %>/js/colorbrewer.js', '<%= conf.pkg.name %>.js' @@ -330,8 +289,6 @@ module.exports = function (grunt) { '<%= conf.pkg.name %>.js.map', '<%= conf.pkg.name %>.min.js', '<%= conf.pkg.name %>.min.js.map', - 'd3-compat.js', - 'd3-compat.js.map', 'node_modules/d3/build/d3.js', 'node_modules/crossfilter2/crossfilter.js', 'node_modules/queue-async/build/queue.js', @@ -495,6 +452,7 @@ module.exports = function (grunt) { module.exports.jsFiles = [ 'src/banner.js', // NOTE: keep this first + 'src/d3v3-compat.js', 'src/core.js', 'src/errors.js', 'src/utils.js', diff --git a/spec/bar-chart-spec.js b/spec/bar-chart-spec.js index 11730b7b7..bb31c9c38 100644 --- a/spec/bar-chart-spec.js +++ b/spec/bar-chart-spec.js @@ -5,7 +5,7 @@ describe('dc.barChart', function () { beforeEach(function () { data = crossfilter(loadDateFixture()); - dimension = data.dimension(function (d) { return d3.time.day.utc(d.dd); }); + dimension = data.dimension(function (d) { return d3.utcDay(d.dd); }); group = dimension.group(); id = 'bar-chart'; @@ -14,7 +14,7 @@ describe('dc.barChart', function () { chart = dc.barChart('#' + id); chart.dimension(dimension).group(group) .width(1100).height(200) - .x(d3.time.scale.utc().domain([makeDate(2012, 0, 1), makeDate(2012, 11, 31)])) + .x(d3.scaleUtc().domain([makeDate(2012, 0, 1), makeDate(2012, 11, 31)])) .transitionDuration(0) .controlsUseVisibility(true); }); @@ -125,13 +125,13 @@ describe('dc.barChart', function () { var domain = [makeDate(2012, 4, 20), makeDate(2012, 7, 15)]; - chart.x(d3.time.scale.utc().domain(domain)) + chart.x(d3.scaleUtc().domain(domain)) .group(dimension.group().reduceSum(function (d) { return +d.nvalue; })) .elasticY(true) .centerBar(false) - .xUnits(d3.time.days.utc) + .xUnits(d3.utcDays) .yAxis().ticks(5); chart.render(); @@ -184,7 +184,7 @@ describe('dc.barChart', function () { chart.dimension(stateDimension) .group(stateGroup) .xUnits(dc.units.ordinal) - .x(d3.scale.ordinal().domain(ordinalDomainValues)) + .x(d3.scaleOrdinal().domain(ordinalDomainValues)) .barPadding(0) .outerPadding(0.1) .render(); @@ -240,7 +240,7 @@ describe('dc.barChart', function () { describe('with an unspecified domain', function () { beforeEach(function () { - chart.x(d3.scale.ordinal()).render(); + chart.x(d3.scaleOrdinal()).render(); }); it('should use alphabetical ordering', function () { @@ -305,7 +305,7 @@ describe('dc.barChart', function () { chart.dimension(linearDimension) .group(linearGroup) .xUnits(dc.units.integers) - .x(d3.scale.linear().domain([20, 70])) + .x(d3.scaleLinear().domain([20, 70])) .render(); }); @@ -350,7 +350,7 @@ describe('dc.barChart', function () { chart .brushOn(false) - .x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])) + .x(d3.scaleUtc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])) .group(idGroup, 'stack 0') .title('stack 0', function (d) { return 'stack 0: ' + d.value; }) .stack(sumGroup, 'stack 1') @@ -500,12 +500,12 @@ describe('dc.barChart', function () { var mixedGroup = dimension.group().reduceSum(function (d) { return d.nvalue; }); chart.group(mixedGroup).stack(mixedGroup).stack(mixedGroup); - chart.x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])); + chart.x(d3.scaleUtc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])); chart.margins({top: 30, right: 50, bottom: 30, left: 30}) .yAxisPadding(5) .elasticY(true) - .xUnits(d3.time.days.utc) + .xUnits(d3.utcDays) .yAxis().ticks(5); chart.rescale(); // BUG: barWidth cannot change after initial rendering @@ -565,11 +565,11 @@ describe('dc.barChart', function () { var negativeGroup = dimension.group().reduceSum(function (d) { return -Math.abs(d.nvalue); }); chart.group(negativeGroup).stack(negativeGroup).stack(negativeGroup); - chart.x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])); + chart.x(d3.scaleUtc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])); chart.margins({top: 30, right: 50, bottom: 30, left: 30}) .elasticY(true) - .xUnits(d3.time.days.utc) + .xUnits(d3.utcDays) .yAxis().ticks(3); chart.render(); @@ -592,7 +592,7 @@ describe('dc.barChart', function () { describe('when focused', function () { beforeEach(function () { - chart.elasticY(true).gap(1).xUnits(d3.time.days.utc); + chart.elasticY(true).gap(1).xUnits(d3.utcDays); chart.focus([makeDate(2012, 5, 11), makeDate(2012, 6, 9)]); }); @@ -686,7 +686,7 @@ describe('dc.barChart', function () { d3.select('#' + id).append('span').attr('class', 'filter').style('visibility', 'hidden'); d3.select('#' + id).append('a').attr('class', 'reset').style('visibility', 'hidden'); chart.filter([makeDate(2012, 5, 1), makeDate(2012, 5, 30)]).redraw(); - dc.dateFormat = d3.time.format.utc('%m/%d/%Y'); + dc.dateFormat = d3.utcFormat('%m/%d/%Y'); chart.redraw(); }); @@ -772,7 +772,7 @@ describe('dc.barChart', function () { describe('a chart with a large domain', function () { beforeEach(function () { - chart.x(d3.time.scale.utc().domain([makeDate(2000, 0, 1), makeDate(2012, 11, 31)])); + chart.x(d3.scaleUtc().domain([makeDate(2000, 0, 1), makeDate(2012, 11, 31)])); }); describe('when filters are applied', function () { @@ -799,7 +799,7 @@ describe('dc.barChart', function () { beforeEach(function () { var numericalDimension = data.dimension(function (d) { return +d.value; }); chart.dimension(numericalDimension).group(numericalDimension.group()); - chart.x(d3.scale.linear().domain([10, 80])).elasticY(true); + chart.x(d3.scaleLinear().domain([10, 80])).elasticY(true); chart.render(); }); @@ -839,7 +839,7 @@ describe('dc.barChart', function () { chart = dc.barChart('#' + id); chart.xUnits(dc.units.ordinal) - .x(d3.scale.ordinal()) + .x(d3.scaleOrdinal()) .transitionDuration(0) .dimension(dimension) .group(group, 'Population'); @@ -891,7 +891,7 @@ describe('dc.barChart', function () { .outerPadding(0) .dimension(dimension) .group(group) - .x(d3.scale.ordinal()) + .x(d3.scaleOrdinal()) .xUnits(dc.units.ordinal); chart.render(); }); @@ -921,7 +921,7 @@ describe('dc.barChart', function () { chart = dc.barChart('#' + id); chart.width(500).transitionDuration(0) - .x(d3.scale.linear().domain([0,7])) + .x(d3.scaleLinear().domain([0,7])) .elasticY(true) .dimension(dimension) .group(group); @@ -981,8 +981,8 @@ describe('dc.barChart', function () { it('should render the right xAxisMax/Min when 10 day padding', function () { chart.xAxisPadding(10) .render(); - var expectedStartDate = d3.time.day.offset(date, -10); - var expectedEndDate = d3.time.day.offset(date, 10); + var expectedStartDate = d3.timeDay.offset(date, -10); + var expectedEndDate = d3.timeDay.offset(date, 10); expect(chart.xAxisMin()).toEqual(expectedStartDate); expect(chart.xAxisMax()).toEqual(expectedEndDate); }); @@ -990,8 +990,8 @@ describe('dc.barChart', function () { chart.xAxisPaddingUnit('month') .xAxisPadding(2) .render(); - var expectedStartDate = d3.time.month.offset(date, -2); - var expectedEndDate = d3.time.month.offset(date, 2); + var expectedStartDate = d3.timeMonth.offset(date, -2); + var expectedEndDate = d3.timeMonth.offset(date, 2); expect(chart.xAxisMin()).toEqual(expectedStartDate); expect(chart.xAxisMax()).toEqual(expectedEndDate); }); @@ -1015,7 +1015,7 @@ describe('dc.barChart', function () { chart = dc.barChart('#' + id); chart.width(500).transitionDuration(0) - .x(d3.scale.linear()) + .x(d3.scaleLinear()) .elasticY(true).elasticX(true) .dimension(dimension) .group(group); @@ -1063,7 +1063,7 @@ describe('dc.barChart', function () { chart = dc.barChart('#' + id); chart.width(500).transitionDuration(0) - .x(d3.scale.ordinal()) + .x(d3.scaleOrdinal()) .xUnits(dc.units.ordinal) .elasticY(true).elasticX(true) .dimension(dimension) @@ -1097,7 +1097,7 @@ describe('dc.barChart', function () { beforeEach(function () { chart .brushOn(true) - .round(d3.time.month.utc.round) + .round(d3.utcMonth.round) .centerBar(true); }); @@ -1165,7 +1165,7 @@ describe('dc.barChart', function () { chart = dc.barChart('#' + id); chart.width(500).transitionDuration(0) - .x(d3.scale.ordinal()) + .x(d3.scaleOrdinal()) .xUnits(dc.units.ordinal) .elasticY(true).elasticX(true) .dimension(dimension) @@ -1226,7 +1226,7 @@ describe('dc.barChart', function () { chart = dc.barChart('#' + id); chart.width(500).transitionDuration(0) - .x(d3.scale.ordinal()) + .x(d3.scaleOrdinal()) .xUnits(dc.units.ordinal) .elasticY(true).elasticX(true) .dimension(dimension) diff --git a/spec/base-mixin-spec.js b/spec/base-mixin-spec.js index 2f2db406f..3875a4795 100644 --- a/spec/base-mixin-spec.js +++ b/spec/base-mixin-spec.js @@ -5,7 +5,7 @@ describe('dc.baseMixin', function () { beforeEach(function () { var data = crossfilter(loadDateFixture()); dimension = data.dimension(function (d) { - return d3.time.day.utc(d.dd); + return d3.utcDay(d.dd); }); group = dimension.group().reduceSum(function (d) { return d.value; diff --git a/spec/biggish-data-spec.js b/spec/biggish-data-spec.js index ea13f4a57..5476778f8 100644 --- a/spec/biggish-data-spec.js +++ b/spec/biggish-data-spec.js @@ -14,8 +14,6 @@ describe('dc.barChart.biggish', function () { var chartAttemptSeries = dc.lineChart('#stack-chart'); var chartRange = dc.barChart('#range-chart'); - var dateFormat = d3.time.format.iso; - var xfilter; var data = biggishData(); @@ -24,11 +22,11 @@ describe('dc.barChart.biggish', function () { // coerce k(ind) into a number row.k = +row.k; // convert event time into d3 date format - row.dd = dateFormat.parse(row.t); + row.dd = d3.isoParse(row.t); // pre-calculate the day of the time - row.day = d3.time.day(row.dd); + row.day = d3.timeDay(row.dd); // precalculate the hour of the time - row.hour = d3.time.hour(row.dd); + row.hour = d3.timeHour(row.dd); // coerce n(umber of attempts) into a number row.n = +row.n; }); @@ -83,7 +81,7 @@ describe('dc.barChart.biggish', function () { // calculate day extent (two element array of first and last items in the range) - of the hour data var extentDay = d3.extent(data, function (row) { return row.day; }); // select the following day for the end of the extent - extentDay[1] = d3.time.day.offset(extentDay[1], 1); + extentDay[1] = d3.timeDay.offset(extentDay[1], 1); chartAttemptSeries .margins({top: 30, right: 50, bottom: 25, left: 40}) @@ -103,7 +101,7 @@ describe('dc.barChart.biggish', function () { .valueAccessor(function (d) { return d.value.bfa; }) .stack(groupHourSeries, 'Horizontal Movement', function (d) { return d.value.hma; }) .stack(groupHourSeries, 'User Account Hacking', function (d) { return d.value.uha; }) - .xUnits(d3.time.hours); + .xUnits(d3.timeHours); chartAttemptSeries.legend(dc.legend().horizontal(true).x(50).y(0).itemWidth(150).gap(5)); @@ -113,8 +111,8 @@ describe('dc.barChart.biggish', function () { .group(groupHourSum) .centerBar(true) .gap(1) - .xUnits(d3.time.hours) - .round(d3.time.hour.round) + .xUnits(d3.timeHours) + .round(d3.timeHour.round) .alwaysUseRounding(true) .x(d3.scaleTime().domain(extentDay)) diff --git a/spec/box-plot-spec.js b/spec/box-plot-spec.js index 5be74d60c..5bd3cf2b4 100644 --- a/spec/box-plot-spec.js +++ b/spec/box-plot-spec.js @@ -26,7 +26,7 @@ describe('dc.boxPlot', function () { .boxPadding(0) .transitionDuration(0) .transitionDelay(0) - .y(d3.scale.linear().domain([0, 144])) + .y(d3.scaleLinear().domain([0, 144])) .ordinalColors(['#01','#02']); }); diff --git a/spec/bubble-chart-spec.js b/spec/bubble-chart-spec.js index b0b462f93..5c9a9ec6b 100644 --- a/spec/bubble-chart-spec.js +++ b/spec/bubble-chart-spec.js @@ -56,9 +56,9 @@ describe('dc.bubbleChart', function () { .radiusValueAccessor(function (p) { return p.value.count; }) - .x(d3.scale.linear().domain([0, 300])) - .y(d3.scale.linear().domain([0, 10])) - .r(d3.scale.linear().domain([0, 30])) + .x(d3.scaleLinear().domain([0, 300])) + .y(d3.scaleLinear().domain([0, 10])) + .r(d3.scaleLinear().domain([0, 30])) .maxBubbleRelativeSize(0.3) .transitionDuration(0) .renderLabel(true) @@ -415,8 +415,8 @@ describe('dc.bubbleChart', function () { .valueAccessor(function (kv) { return 0; }) - .x(d3.scale.log().domain([1, 300])) - .y(d3.scale.log().domain([1, 10])) + .x(d3.scaleLog().domain([1, 300])) + .y(d3.scaleLog().domain([1, 10])) .elasticX(false) .elasticY(false); chart.render(); @@ -431,13 +431,13 @@ describe('dc.bubbleChart', function () { describe('with a date-based scale', function () { beforeEach(function () { - dimension = data.dimension(function (d) { return d3.time.day.utc(d.dd); }); + dimension = data.dimension(function (d) { return d3.utcDay(d.dd); }); group = dimension.group(); chart .dimension(dimension) .group(group) - .x(d3.time.scale.utc().domain([makeDate(2012, 0, 1), makeDate(2012, 11, 31)])) + .x(d3.scaleUtc().domain([makeDate(2012, 0, 1), makeDate(2012, 11, 31)])) .elasticX(true) .elasticY(true) .keyAccessor(function (kv) { @@ -449,7 +449,7 @@ describe('dc.bubbleChart', function () { .radiusValueAccessor(function (kv) { return kv.value; }) - .colors(d3.scale.ordinal().range(['#a60000', '#ff0000', '#ff4040', '#ff7373', '#67e667', '#39e639', '#00cc00'])) + .colors(d3.scaleOrdinal().range(['#a60000', '#ff0000', '#ff4040', '#ff7373', '#67e667', '#39e639', '#00cc00'])) .colorAccessor(function (kv) { return kv.key; }) @@ -587,15 +587,15 @@ describe('dc.bubbleChart', function () { .transitionDuration(0) .width(400) .height(400) - .x(d3.scale.linear()).xAxisPadding(0.5) - .y(d3.scale.linear()).yAxisPadding(0.5) + .x(d3.scaleLinear()).xAxisPadding(0.5) + .y(d3.scaleLinear()).yAxisPadding(0.5) .elasticX(true) .elasticY(true) .keyAccessor(key_part(0)) .valueAccessor(key_part(1)) .radiusValueAccessor(function (kv) { return kv.value.total; }) .elasticRadius(true) - .colors(d3.scale.ordinal() + .colors(d3.scaleOrdinal() .domain(species.concat('none')) .range(['#e41a1c','#377eb8','#4daf4a', '#f8f8f8'])) .colorAccessor(function (d) { @@ -616,7 +616,7 @@ describe('dc.bubbleChart', function () { .xBorderRadius(15).yBorderRadius(15) .keyAccessor(key_part(0)) .valueAccessor(key_part(1)) - .colors(d3.scale.ordinal() + .colors(d3.scaleOrdinal() .domain(species.concat('none')) .range(['#e41a1c','#377eb8','#4daf4a', '#f8f8f8'])) .colorAccessor(function (d) { @@ -697,7 +697,7 @@ describe('dc.bubbleChart', function () { beforeEach(function () { var axisLabel = d3.select(heatMap.selectAll('.cols.axis text').nodes()[3]); axisLabel.on('click')(axisLabel.datum()); - d3.timer.flush(); + d3.timerFlush(); }); it('updates bubble radii correctly', function () { testBubbleRadiiCol3(chart); @@ -715,7 +715,7 @@ describe('dc.bubbleChart', function () { chart.render(); var axisLabel = d3.select(heatMap.selectAll('.cols.axis text').nodes()[3]); axisLabel.on('click')(axisLabel.datum()); - d3.timer.flush(); + d3.timerFlush(); }); it('updates bubble radii correctly', function () { testBubbleRadiiCol3(chart); diff --git a/spec/bubble-overlay-spec.js b/spec/bubble-overlay-spec.js index b2df8218d..80d9b6285 100644 --- a/spec/bubble-overlay-spec.js +++ b/spec/bubble-overlay-spec.js @@ -23,7 +23,7 @@ describe('dc.bubbleOverlay', function () { .height(height) .transitionDuration(0) .title(function (d) {return 'Title: ' + d.key;}) - .r(d3.scale.linear().domain([0, 100])) + .r(d3.scaleLinear().domain([0, 100])) .maxBubbleRelativeSize(0.1) .ordinalColors(['blue']) .point('California', 100, 120) diff --git a/spec/color-spec.js b/spec/color-spec.js index 3b98d2c06..161514c2b 100644 --- a/spec/color-spec.js +++ b/spec/color-spec.js @@ -21,7 +21,7 @@ describe('dc.colorMixin', function () { }); it('custom', function () { - chart.colors(d3.scale.category10()); + chart.colors(d3.scaleOrdinal(d3.schemeCategory10)); expect(colorTest(chart, domain)).toMatchColors(['#1f77b4','#ff7f0e','#2ca02c','#d62728','#9467bd']); }); @@ -52,7 +52,7 @@ describe('dc.colorMixin', function () { }); it('custom', function () { - chart.colors(d3.scale.category10()); + chart.colors(d3.scaleOrdinal(d3.schemeCategory10)); expect(colorTest(chart, domain, test)).toMatchColors(['#2ca02c', '#1f77b4', '#d62728', '#ff7f0e', '#9467bd', '#1f77b4']); }); diff --git a/spec/composite-chart-spec.js b/spec/composite-chart-spec.js index 025f35b8b..fd482514b 100644 --- a/spec/composite-chart-spec.js +++ b/spec/composite-chart-spec.js @@ -5,7 +5,7 @@ describe('dc.compositeChart', function () { beforeEach(function () { data = crossfilter(loadDateFixture()); - dateDimension = data.dimension(function (d) { return d3.time.day.utc(d.dd); }); + dateDimension = data.dimension(function (d) { return d3.utcDay(d.dd); }); dateValueSumGroup = dateDimension.group().reduceSum(function (d) { return d.value; }); dateValueNegativeSumGroup = dateDimension.group().reduceSum(function (d) { return -d.value; }); dateIdSumGroup = dateDimension.group().reduceSum(function (d) { return d.id; }); @@ -21,9 +21,9 @@ describe('dc.compositeChart', function () { .group(dateIdSumGroup) .width(500) .height(150) - .x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])) + .x(d3.scaleUtc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])) .transitionDuration(0) - .xUnits(d3.time.days.utc) + .xUnits(d3.utcDays) .shareColors(true) .compose([ dc.barChart(chart) @@ -78,7 +78,7 @@ describe('dc.compositeChart', function () { }); it('should set the x units', function () { - expect(chart.xUnits()).toBe(d3.time.days.utc); + expect(chart.xUnits()).toBe(d3.utcDays); }); it('should create the x axis', function () { @@ -98,7 +98,7 @@ describe('dc.compositeChart', function () { }); it('can change round', function () { - chart.round(d3.time.day.utc.round); + chart.round(d3.utcDay.round); expect(chart.round()).not.toBeNull(); }); @@ -344,7 +344,7 @@ describe('dc.compositeChart', function () { describe('no elastic', function () { beforeEach(function () { - chart.y(d3.scale.linear().domain([-200, 200])); + chart.y(d3.scaleLinear().domain([-200, 200])); chart.render(); }); @@ -412,7 +412,7 @@ describe('dc.compositeChart', function () { .brushOn(false) .dimension(dimension) .shareTitle(false) - .x(d3.scale.ordinal()) + .x(d3.scaleOrdinal()) .xUnits(dc.units.ordinal) .compose([ dc.lineChart(chart) @@ -684,7 +684,7 @@ describe('dc.compositeChart', function () { chart .dimension(scatterDimension) .group(scatterGroup) - .x(d3.scale.linear().domain([0,70])) + .x(d3.scaleLinear().domain([0,70])) .brushOn(true) .compose([ dc.scatterPlot(chart), diff --git a/spec/coordinate-grid-chart-spec.js b/spec/coordinate-grid-chart-spec.js index ef53200b3..8fac3aedf 100644 --- a/spec/coordinate-grid-chart-spec.js +++ b/spec/coordinate-grid-chart-spec.js @@ -5,7 +5,7 @@ describe('dc.coordinateGridChart', function () { beforeEach(function () { data = crossfilter(loadDateFixture()); - dimension = data.dimension(function (d) { return d3.time.day.utc(d.dd); }); + dimension = data.dimension(function (d) { return d3.utcDay(d.dd); }); group = dimension.group(); id = 'coordinate-grid-chart'; @@ -20,7 +20,7 @@ describe('dc.coordinateGridChart', function () { .transitionDelay(0) .brushOn(false) .margins({top: 20, bottom: 0, right: 10, left: 0}) - .x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])); + .x(d3.scaleUtc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])); }); describe('rendering', function () { @@ -108,7 +108,7 @@ describe('dc.coordinateGridChart', function () { }); it('should be able to change round', function () { - chart.round(d3.time.day.utc.round); + chart.round(d3.utcDay.round); expect(chart.round()).not.toBeNull(); }); @@ -205,7 +205,7 @@ describe('dc.coordinateGridChart', function () { .transitionDelay(0) .brushOn(false) .margins({top: 20, bottom: 0, right: 10, left: 0}) - .x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])); + .x(d3.scaleUtc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])); chart.render(); }); it('should generate a valid clippath id', function () { @@ -226,7 +226,7 @@ describe('dc.coordinateGridChart', function () { .transitionDelay(0) .brushOn(false) .margins({top: 20, bottom: 0, right: 10, left: 0}) - .x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])); + .x(d3.scaleUtc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])); chart.render(); }); it('should generate a valid clippath id', function () { @@ -390,7 +390,7 @@ describe('dc.coordinateGridChart', function () { describe('with an ordinal x axis', function () { beforeEach(function () { - chart.x(d3.scale.ordinal()) + chart.x(d3.scaleOrdinal()) .xUnits(dc.units.ordinal) .render(); }); @@ -593,7 +593,7 @@ describe('dc.coordinateGridChart', function () { describe('setting x', function () { var newDomain = [1,10]; beforeEach(function () { - chart.x(d3.scale.linear().domain(newDomain)); + chart.x(d3.scaleLinear().domain(newDomain)); }); it('should reset the original x domain', function () { @@ -940,7 +940,7 @@ describe('dc.coordinateGridChart', function () { return dc.lineChart('#' + rangeId) .dimension(dimension) .group(dimension.group().reduceSum(function (d) { return d.id; })) - .x(d3.time.scale.utc().domain([makeDate(2012, 5, 20), makeDate(2012, 6, 15)])); + .x(d3.scaleUtc().domain([makeDate(2012, 5, 20), makeDate(2012, 6, 15)])); } function doubleClick (chart) { diff --git a/spec/data-addition-spec.js b/spec/data-addition-spec.js index 67f0fa540..ed84d206c 100644 --- a/spec/data-addition-spec.js +++ b/spec/data-addition-spec.js @@ -69,9 +69,9 @@ describe('Dynamic data addition in crossfilter', function () { var chart = dc.lineChart('#' + id); chart.dimension(timeDimension).group(timeGroup) .width(width).height(height) - .x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])) + .x(d3.scaleUtc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])) .transitionDuration(0) - .xUnits(d3.time.days.utc) + .xUnits(d3.utcDays) .brushOn(false) .renderArea(true) .renderTitle(true); diff --git a/spec/data-count-spec.js b/spec/data-count-spec.js index bff0d789d..8603bf5bf 100644 --- a/spec/data-count-spec.js +++ b/spec/data-count-spec.js @@ -16,7 +16,7 @@ describe('dc.dataCount', function () { .dimension(data) .group(groupAll); chart.render(); - d3.timer.flush(); + d3.timerFlush(); return chart; } describe('creation', function () { diff --git a/spec/data-grid-spec.js b/spec/data-grid-spec.js index 20b9b4971..a12fb3b53 100644 --- a/spec/data-grid-spec.js +++ b/spec/data-grid-spec.js @@ -9,7 +9,7 @@ describe('dc.dataGrid', function () { dateFixture = loadDateFixture(); data = crossfilter(dateFixture); dimension = data.dimension(function (d) { - return d3.time.day.utc(d.dd); + return d3.utcDay(d.dd); }); countryDimension = data.dimension(function (d) { return d.countrycode; diff --git a/spec/data-table-spec.js b/spec/data-table-spec.js index 400663202..9634c1424 100644 --- a/spec/data-table-spec.js +++ b/spec/data-table-spec.js @@ -10,7 +10,7 @@ describe('dc.dataTable', function () { dateFixture = loadDateFixture(); data = crossfilter(dateFixture); dimension = data.dimension(function (d) { - return d3.time.day.utc(d.dd); + return d3.utcDay(d.dd); }); countryDimension = data.dimension(function (d) { return d.countrycode; diff --git a/spec/geo-choropleth-chart-spec.js b/spec/geo-choropleth-chart-spec.js index 309fc0a48..7dc3f53db 100644 --- a/spec/geo-choropleth-chart-spec.js +++ b/spec/geo-choropleth-chart-spec.js @@ -52,7 +52,7 @@ describe('dc.geoChoropleth', function () { var chart = dc.geoChoroplethChart('#' + id); chart.dimension(districtDimension) .group(districtValueEnrollGroup) - .projection(d3.geo.mercator() + .projection(d3.geoMercator() .scale(26778) .translate([8227, 3207])) .width(990) @@ -79,7 +79,7 @@ describe('dc.geoChoropleth', function () { it('should return not null', function () { expect(chart).not.toBeNull(); }); - it('should have a d3.geo.path', function () { + it('should have a d3.geoPath', function () { expect(chart.geoPath()).not.toBeNull(); }); it('svg is created', function () { diff --git a/spec/heatmap-spec.js b/spec/heatmap-spec.js index 86f287f2e..d409f6576 100644 --- a/spec/heatmap-spec.js +++ b/spec/heatmap-spec.js @@ -495,16 +495,16 @@ describe('dc.heatmap', function () { .width(400) .height(400) .transitionDuration(0) - .x(d3.scale.linear()).xAxisPadding(0.5) - .y(d3.scale.linear()).yAxisPadding(0.5) + .x(d3.scaleLinear()).xAxisPadding(0.5) + .y(d3.scaleLinear()).yAxisPadding(0.5) .elasticX(true) .elasticY(true) .label(d3.functor('')) .keyAccessor(key_part(0)) .valueAccessor(key_part(1)) - .r(d3.scale.linear().domain([0,20]).range([4,25])) + .r(d3.scaleLinear().domain([0,20]).range([4,25])) .radiusValueAccessor(function (kv) { return kv.value.total; }) - .colors(d3.scale.ordinal() + .colors(d3.scaleOrdinal() .domain(species.concat('none')) .range(['#e41a1c','#377eb8','#4daf4a', '#f8f8f8'])) .colorAccessor(function (d) { @@ -518,7 +518,7 @@ describe('dc.heatmap', function () { .xBorderRadius(15).yBorderRadius(15) .keyAccessor(key_part(0)) .valueAccessor(key_part(1)) - .colors(d3.scale.ordinal() + .colors(d3.scaleOrdinal() .domain(species.concat('none')) .range(['#e41a1c','#377eb8','#4daf4a', '#f8f8f8'])) .colorAccessor(function (d) { diff --git a/spec/helpers/fixtures.js b/spec/helpers/fixtures.js index 20a012388..c537864d8 100644 --- a/spec/helpers/fixtures.js +++ b/spec/helpers/fixtures.js @@ -1,7 +1,7 @@ /* jscs:disable validateQuoteMarks, maximumLineLength */ /* jshint -W109, -W101, -W098 */ function dateCleaner (e) { - e.dd = d3.time.format.iso.parse(e.date); + e.dd = d3.isoParse(e.date); } function loadDateFixture () { diff --git a/spec/helpers/spec-helper.js b/spec/helpers/spec-helper.js index 120d95590..84b6ed348 100644 --- a/spec/helpers/spec-helper.js +++ b/spec/helpers/spec-helper.js @@ -45,7 +45,7 @@ function cleanDateRange (range) { // http://stackoverflow.com/questions/20068497/d3-transition-in-unit-testing function flushAllD3Transitions () { - d3.timer.flush(); + d3.timerFlush(); } // Setup a dummy event - just enough for the handler to get fooled @@ -54,7 +54,7 @@ var setupEventForBrushing = function (chart, domainSelection) { var scaledSelection = domainSelection.map(function (coord) { return chart.x()(coord); }); - d3v4.event = { + d3.event = { sourceEvent: true, selection: scaledSelection }; @@ -69,7 +69,7 @@ var setupEventFor2DBrushing = function (chart, domainSelection) { return scale(coord); }); }); - d3v4.event = { + d3.event = { sourceEvent: true, selection: scaledSelection }; diff --git a/spec/legend-spec.js b/spec/legend-spec.js index 8548c5ae5..941fcc1d8 100644 --- a/spec/legend-spec.js +++ b/spec/legend-spec.js @@ -4,7 +4,7 @@ describe('dc.legend', function () { beforeEach(function () { var data = crossfilter(loadDateFixture()); - dateDimension = data.dimension(function (d) { return d3.time.day.utc(d.dd); }); + dateDimension = data.dimension(function (d) { return d3.utcDay(d.dd); }); dateValueSumGroup = dateDimension.group().reduceSum(function (d) { return d.value; }); dateIdSumGroup = dateDimension.group().reduceSum(function (d) { return d.id; }); @@ -17,7 +17,7 @@ describe('dc.legend', function () { .group(dateIdSumGroup, 'Id Sum') .stack(dateValueSumGroup, 'Value Sum') .stack(dateValueSumGroup, 'Fixed', function () {}) - .x(d3.time.scale.utc().domain([new Date(2012, 4, 20), new Date(2012, 7, 15)])) + .x(d3.scaleUtc().domain([new Date(2012, 4, 20), new Date(2012, 7, 15)])) .legend(dc.legend().x(400).y(10).itemHeight(13).gap(5)); }); @@ -228,7 +228,7 @@ describe('dc.legend', function () { .dashStyle([2,1]); chart - .x(d3.scale.linear().domain([0,20])) + .x(d3.scaleLinear().domain([0,20])) .legend(dc.legend().x(400).y(10).itemHeight(13).gap(5)) .compose([subChart1, subChart2]) .render(); diff --git a/spec/line-chart-spec.js b/spec/line-chart-spec.js index 44e6cc8b5..5a9c73a02 100644 --- a/spec/line-chart-spec.js +++ b/spec/line-chart-spec.js @@ -5,7 +5,7 @@ describe('dc.lineChart', function () { beforeEach(function () { data = crossfilter(loadDateFixture()); - dimension = data.dimension(function (d) { return d3.time.day.utc(d.dd); }); + dimension = data.dimension(function (d) { return d3.utcDay(d.dd); }); group = dimension.group(); id = 'line-chart'; @@ -14,7 +14,7 @@ describe('dc.lineChart', function () { chart = dc.lineChart('#' + id); chart.dimension(dimension).group(group) .width(1100).height(200) - .x(d3.time.scale.utc().domain([makeDate(2012, 1, 1), makeDate(2012, 11, 31)])) + .x(d3.scaleUtc().domain([makeDate(2012, 1, 1), makeDate(2012, 11, 31)])) .transitionDuration(0); }); @@ -337,7 +337,7 @@ describe('dc.lineChart', function () { chart.dimension(stateDimension) .group(stateGroup) .xUnits(dc.units.ordinal) - .x(d3.scale.ordinal().domain(['California', 'Colorado', 'Delaware', 'Mississippi', 'Oklahoma', 'Ontario'])) + .x(d3.scaleOrdinal().domain(['California', 'Colorado', 'Delaware', 'Mississippi', 'Oklahoma', 'Ontario'])) .render(); }); @@ -358,7 +358,7 @@ describe('dc.lineChart', function () { chart.dimension(dimension) .brushOn(false) - .x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])) + .x(d3.scaleUtc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])) .group(idGroup, 'stack 0') .title('stack 0', function (d) { return 'stack 0: ' + d.value; }) .stack(valueGroup, 'stack 1') @@ -529,7 +529,7 @@ describe('dc.lineChart', function () { var mixedGroup = dimension.group().reduceSum(function (d) { return d.nvalue; }); chart.group(mixedGroup).stack(mixedGroup).stack(mixedGroup); - chart.x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])); + chart.x(d3.scaleUtc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])); chart.margins({top: 30, right: 50, bottom: 30, left: 30}) .renderArea(true) @@ -581,11 +581,11 @@ describe('dc.lineChart', function () { var negativeGroup = dimension.group().reduceSum(function (d) { return -Math.abs(d.nvalue); }); chart.group(negativeGroup).stack(negativeGroup).stack(negativeGroup); - chart.x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])); + chart.x(d3.scaleUtc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])); chart.margins({top: 30, right: 50, bottom: 30, left: 30}) .elasticY(true) - .xUnits(d3.time.days.utc) + .xUnits(d3.utcDays) .yAxis().ticks(3); chart.render(); diff --git a/spec/number-display-spec.js b/spec/number-display-spec.js index c6d1619c7..6615e71fc 100644 --- a/spec/number-display-spec.js +++ b/spec/number-display-spec.js @@ -35,7 +35,7 @@ describe('dc.numberDisplay', function () { .formatNumber(d3.format('.3s')) .valueAccessor(average); chart.render(); - d3.timer.flush(); + d3.timerFlush(); return chart; } @@ -62,7 +62,7 @@ describe('dc.numberDisplay', function () { beforeEach(function () { countryDimension.filterAll(); chart.redraw(); - d3.timer.flush(); + d3.timerFlush(); }); it('should update value', function () { expect(chart.select('span.number-display').text()).toEqual('41.8'); @@ -72,7 +72,7 @@ describe('dc.numberDisplay', function () { beforeEach(function () { chart.html({one: '%number number',none: 'no number',some: '%number numbers'}); chart.redraw(); - d3.timer.flush(); + d3.timerFlush(); }); it('should use some for some', function () { expect(chart.select('span.number-display').text()).toEqual('38.5 numbers'); @@ -83,7 +83,7 @@ describe('dc.numberDisplay', function () { chart.html({one: '%number number',none: 'no number',some: '%number numbers'}); chart.valueAccessor(function (d) {return 1;}); chart.redraw(); - d3.timer.flush(); + d3.timerFlush(); }); it('should use one for one', function () { expect(chart.select('span.number-display').text()).toEqual('1.00 number'); @@ -94,7 +94,7 @@ describe('dc.numberDisplay', function () { chart.html({one: '%number number',none: 'no number',some: '%number numbers'}); chart.valueAccessor(function (d) {return 0;}); chart.redraw(); - d3.timer.flush(); + d3.timerFlush(); }); it('should use zero for zero', function () { expect(chart.select('span.number-display').text()).toEqual('no number'); @@ -104,7 +104,7 @@ describe('dc.numberDisplay', function () { beforeEach(function () { chart.html({one: '%number number'}); chart.redraw(); - d3.timer.flush(); + d3.timerFlush(); }); it('should use one for showing some', function () { expect(chart.select('span.number-display').text()).toEqual('38.5 number'); @@ -114,7 +114,7 @@ describe('dc.numberDisplay', function () { beforeEach(function () { chart.html({some: '%number numbers'}); chart.redraw(); - d3.timer.flush(); + d3.timerFlush(); }); it('should use some for showing one', function () { expect(chart.select('span.number-display').text()).toEqual('38.5 numbers'); @@ -124,7 +124,7 @@ describe('dc.numberDisplay', function () { beforeEach(function () { chart.html({}); chart.redraw(); - d3.timer.flush(); + d3.timerFlush(); }); it('should just show the number in case of some and one', function () { expect(chart.select('span.number-display').text()).toEqual('38.5'); @@ -177,7 +177,7 @@ describe('dc.numberDisplay', function () { .group(group) .valueAccessor(function (kv) { return kv.value; }) .render(); - d3.timer.flush(); + d3.timerFlush(); }); it('should show the largest value', function () { @@ -188,7 +188,7 @@ describe('dc.numberDisplay', function () { beforeEach(function () { chart.ordering(function (kv) { return -kv.value; }) .render(); - d3.timer.flush(); + d3.timerFlush(); }); it('should show the smallest value', function () { expect(chart.select('span.number-display').text()).toEqual('77.0'); @@ -206,7 +206,7 @@ describe('dc.numberDisplay', function () { .group({value: function () { return Infinity; }}) .formatNumber(function (d) { return d; }) .render(); - d3.timer.flush(); + d3.timerFlush(); }); it('should display as Infinity', function () { expect(chart.root().text()).toEqual('Infinity'); @@ -215,7 +215,7 @@ describe('dc.numberDisplay', function () { beforeEach(function () { chart.group({value: function () { return 17; }}) .render(); - d3.timer.flush(); + d3.timerFlush(); }); it('should display finite', function () { expect(chart.root().text()).toEqual('17'); diff --git a/spec/pie-chart-spec.js b/spec/pie-chart-spec.js index 22c0bfc20..18c4bfebe 100644 --- a/spec/pie-chart-spec.js +++ b/spec/pie-chart-spec.js @@ -27,7 +27,7 @@ describe('dc.pieChart', function () { }); countryGroup = countryDimension.group(); dateDimension = data.dimension(function (d) { - return d3.time.day.utc(d.dd); + return d3.utcDay(d.dd); }); statusGroup = statusDimension.group(); statusMultiGroup = statusGroup.reduce( @@ -699,7 +699,7 @@ describe('dc.pieChart', function () { it('should place labels outside of pie offset by given radius', function () { var label = d3.select('#pie-chart-external-labeling svg g text.pie-slice'); - var centroid = d3.svg.arc() + var centroid = d3.arc() .outerRadius(chart.radius() + 10) .innerRadius(chart.radius() + 10) .centroid(label.datum()); @@ -720,7 +720,7 @@ describe('dc.pieChart', function () { d3.selectAll('#pie-chart-external-labeling svg g text.pie-slice').each(function () { var label = d3.select(this); - var centroid = d3.svg.arc() + var centroid = d3.arc() .outerRadius(chart.radius()) .innerRadius(chart.innerRadius()) .centroid(label.datum()); diff --git a/spec/row-chart-spec.js b/spec/row-chart-spec.js index c2c36e35d..d7da3613f 100644 --- a/spec/row-chart-spec.js +++ b/spec/row-chart-spec.js @@ -52,7 +52,7 @@ describe('dc.rowChart', function () { beforeEach(function () { chart.group(positiveGroupHolder.group); chart.elasticX(false); - chart.x(d3.scale.log()); + chart.x(d3.scaleLog()); chart.render(); }); @@ -65,7 +65,7 @@ describe('dc.rowChart', function () { beforeEach(function () { chart.group(positiveGroupHolder.group); chart.elasticX(false); - chart.x(d3.scale.log()); + chart.x(d3.scaleLog()); chart.fixedBarHeight(10); chart.render(); }); @@ -78,7 +78,7 @@ describe('dc.rowChart', function () { describe('with renderTitleLabel', function () { beforeEach(function () { chart.group(positiveGroupHolder.group); - chart.x(d3.scale.linear()); + chart.x(d3.scaleLinear()); chart.title(function () { return 'test title'; }); diff --git a/spec/scatter-plot-spec.js b/spec/scatter-plot-spec.js index 7bd29fbd1..8b8809fdd 100644 --- a/spec/scatter-plot-spec.js +++ b/spec/scatter-plot-spec.js @@ -15,7 +15,7 @@ describe('dc.scatterPlot', function () { chart.dimension(dimension) .group(group) .width(500).height(180) - .x(d3.scale.linear().domain([0, 70])) + .x(d3.scaleLinear().domain([0, 70])) .symbolSize(10) .nonemptyOpacity(0.9) .excludedSize(2) @@ -81,7 +81,7 @@ describe('dc.scatterPlot', function () { // native size is 3 square pixels, so to get size N, multiply by sqrt(N)/3 var m = size.call(this, d, i); m = Math.sqrt(m) / 3; - var path = d3.svg.line() + var path = d3.line() .x(function (d) { return d[0] * m; }) @@ -346,7 +346,7 @@ describe('dc.scatterPlot', function () { return function () { var symbol = d3.select(this); var size = Math.pow(r, 2); - var path = d3.svg.symbol().size(size)(); + var path = d3.symbol().size(size)(); var result = comparePaths(symbol.attr('d'), path); return result.pass; }; @@ -387,7 +387,7 @@ describe('dc.scatterPlot', function () { compositeChart = dc.compositeChart('#' + id); compositeChart .dimension(dimension) - .x(d3.time.scale.utc().domain([makeDate(2012, 0, 1), makeDate(2012, 11, 31)])) + .x(d3.scaleUtc().domain([makeDate(2012, 0, 1), makeDate(2012, 11, 31)])) .transitionDuration(0) .legend(dc.legend()) .compose([ diff --git a/spec/series-chart-spec.js b/spec/series-chart-spec.js index 33a2abcaa..3133808c4 100644 --- a/spec/series-chart-spec.js +++ b/spec/series-chart-spec.js @@ -22,7 +22,7 @@ describe('dc.seriesChart', function () { chart .width(210) .height(210) - .x(d3.scale.linear().domain([1,2])) + .x(d3.scaleLinear().domain([1,2])) .dimension(dimensionColorData) .group(groupColorData) .ordinalColors(['#000001', '#000002']) diff --git a/spec/utils-spec.js b/spec/utils-spec.js index da1bd8db2..b32e29c96 100644 --- a/spec/utils-spec.js +++ b/spec/utils-spec.js @@ -20,7 +20,7 @@ describe('dc utils', function () { var printer; beforeEach(function () { printer = dc.printers.filter; - dc.dateFormat = d3.time.format.utc('%m/%d/%Y'); + dc.dateFormat = d3.utcFormat('%m/%d/%Y'); }); it('print simple string', function () { expect(printer('a')).toEqual('a'); diff --git a/src/box-plot.js b/src/box-plot.js index 5df71bc2c..7871a3065 100644 --- a/src/box-plot.js +++ b/src/box-plot.js @@ -79,7 +79,7 @@ dc.boxPlot = function (parent, chartGroup) { * @method boxPadding * @memberof dc.boxPlot * @instance - * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Ordinal-Scales.md#ordinal_rangeBands d3.scale.ordinal.rangeBands} + * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Ordinal-Scales.md#ordinal_rangeBands d3.scaleOrdinal.rangeBands} * @param {Number} [padding=0.8] * @returns {Number|dc.boxPlot} */ diff --git a/src/bubble-mixin.js b/src/bubble-mixin.js index b3b185fd7..5034103e2 100644 --- a/src/bubble-mixin.js +++ b/src/bubble-mixin.js @@ -31,7 +31,7 @@ dc.bubbleMixin = function (_chart) { return data; }); - var _r = d3.scale.linear().domain([0, 100]); + var _r = d3.scaleLinear().domain([0, 100]); var _rValueAccessor = function (d) { return d.r; @@ -39,13 +39,13 @@ dc.bubbleMixin = function (_chart) { /** * Get or set the bubble radius scale. By default the bubble chart uses - * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Quantitative-Scales.md#linear d3.scale.linear().domain([0, 100])} + * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Quantitative-Scales.md#linear d3.scaleLinear().domain([0, 100])} * as its radius scale. * @method r * @memberof dc.bubbleMixin * @instance * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Scales.md d3.scale} - * @param {d3.scale} [bubbleRadiusScale=d3.scale.linear().domain([0, 100])] + * @param {d3.scale} [bubbleRadiusScale=d3.scaleLinear().domain([0, 100])] * @returns {d3.scale|dc.bubbleMixin} */ _chart.r = function (bubbleRadiusScale) { diff --git a/src/color-mixin.js b/src/color-mixin.js index 2774cf76f..6b303f9a0 100644 --- a/src/color-mixin.js +++ b/src/color-mixin.js @@ -8,7 +8,7 @@ * @returns {dc.colorMixin} */ dc.colorMixin = function (_chart) { - var _colors = d3.scale.category20c(); + var _colors = d3.scaleOrdinal(d3.schemeCategory20c); var _defaultAccessor = true; var _colorAccessor = function (d) { return _chart.keyAccessor()(d); }; @@ -24,12 +24,12 @@ dc.colorMixin = function (_chart) { * // alternate categorical scale * chart.colors(d3.scale.category20b()); * // ordinal scale - * chart.colors(d3.scale.ordinal().range(['red','green','blue'])); + * chart.colors(d3.scaleOrdinal().range(['red','green','blue'])); * // convenience method, the same as above * chart.ordinalColors(['red','green','blue']); * // set a linear scale * chart.linearColors(["#4575b4", "#ffffbf", "#a50026"]); - * @param {d3.scale} [colorScale=d3.scale.category20c()] + * @param {d3.scale} [colorScale=d3.scaleOrdinal(d3.schemeCategory20c)] * @returns {d3.scale|dc.colorMixin} */ _chart.colors = function (colorScale) { @@ -37,7 +37,7 @@ dc.colorMixin = function (_chart) { return _colors; } if (colorScale instanceof Array) { - _colors = d3.scale.quantize().range(colorScale); // deprecated legacy support, note: this fails for ordinal domains + _colors = d3.scaleQuantize().range(colorScale); // deprecated legacy support, note: this fails for ordinal domains } else { _colors = d3.functor(colorScale); } @@ -46,7 +46,7 @@ dc.colorMixin = function (_chart) { /** * Convenience method to set the color scale to - * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Ordinal-Scales.md#ordinal d3.scale.ordinal} with + * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Ordinal-Scales.md#ordinal d3.scaleOrdinal} with * range `r`. * @method ordinalColors * @memberof dc.colorMixin @@ -55,7 +55,7 @@ dc.colorMixin = function (_chart) { * @returns {dc.colorMixin} */ _chart.ordinalColors = function (r) { - return _chart.colors(d3.scale.ordinal().range(r)); + return _chart.colors(d3.scaleOrdinal().range(r)); }; /** @@ -67,7 +67,7 @@ dc.colorMixin = function (_chart) { * @returns {dc.colorMixin} */ _chart.linearColors = function (r) { - return _chart.colors(d3.scale.linear() + return _chart.colors(d3.scaleLinear() .range(r) .interpolate(d3.interpolateHcl)); }; diff --git a/src/composite-chart.js b/src/composite-chart.js index 9fa643279..64488fc9a 100644 --- a/src/composite-chart.js +++ b/src/composite-chart.js @@ -69,10 +69,10 @@ dc.compositeChart = function (parent, chartGroup) { }); _chart._brushing = function () { - var event = d3v4.event; + var event = d3.event; // Avoids infinite recursion - // To ensure that when it is called because of brush.move there is no d3v4.event.sourceEvent - d3v4.event = null; + // To ensure that when it is called because of brush.move there is no d3.event.sourceEvent + d3.event = null; if (!event.sourceEvent) return; var selection = event.selection; if (selection) { @@ -163,7 +163,7 @@ dc.compositeChart = function (parent, chartGroup) { var needDomain = _chart.rightY() === undefined || _chart.elasticY(), needRange = needDomain || _chart.resizing(); if (_chart.rightY() === undefined) { - _chart.rightY(d3.scale.linear()); + _chart.rightY(d3.scaleLinear()); } if (needDomain) { _chart.rightY().domain([ranges.ryAxisMin, ranges.ryAxisMax]); @@ -183,7 +183,7 @@ dc.compositeChart = function (parent, chartGroup) { var needDomain = _chart.y() === undefined || _chart.elasticY(), needRange = needDomain || _chart.resizing(); if (_chart.y() === undefined) { - _chart.y(d3.scale.linear()); + _chart.y(d3.scaleLinear()); } if (needDomain) { _chart.y().domain([ranges.lyAxisMin, ranges.lyAxisMax]); diff --git a/src/coordinate-grid-mixin.js b/src/coordinate-grid-mixin.js index 2e5f4bc1d..3a457ba95 100644 --- a/src/coordinate-grid-mixin.js +++ b/src/coordinate-grid-mixin.js @@ -20,7 +20,7 @@ dc.coordinateGridMixin = function (_chart) { _chart = dc.colorMixin(dc.marginMixin(dc.baseMixin(_chart))); - _chart.colors(d3.scale.category10()); + _chart.colors(d3.scaleOrdinal(d3.schemeCategory10)); _chart._mandatoryAttributes().push('x'); var _parent; var _g; @@ -60,8 +60,8 @@ dc.coordinateGridMixin = function (_chart) { var _zoomScale = [1, Infinity]; var _zoomOutRestrict = true; - var _zoom = d3.behavior.zoom().on('zoom', onZoom); - var _nullZoom = d3.behavior.zoom().on('zoom', null); + var _zoom = d3.zoom().on('zoom', onZoom); + var _nullZoom = d3.zoom().on('zoom', null); var _hasBeenMouseZoomable = false; var _rangeChart; @@ -236,7 +236,7 @@ dc.coordinateGridMixin = function (_chart) { * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Scales.md d3.scale} * @example * // set x to a linear scale - * chart.x(d3.scale.linear().domain([-2500, 2500])) + * chart.x(d3.scaleLinear().domain([-2500, 2500])) * // set x to a time scale to generate histogram * chart.x(d3.time.scale().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)])) * @param {d3.scale} [xScale] @@ -261,8 +261,8 @@ dc.coordinateGridMixin = function (_chart) { * the number of data projections on x axis such as the number of bars for a bar chart or the * number of dots for a line chart. This function is expected to return a Javascript array of all * data points on x axis, or the number of points on the axis. [d3 time range functions - * d3.time.days, d3.time.months, and - * d3.time.years](https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Intervals.md#aliases) are all valid xUnits + * d3.timeDays, d3.time.months, and + * d3.timeYears](https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Intervals.md#aliases) are all valid xUnits * function. dc.js also provides a few units function, see the {@link dc.units Units Namespace} for * a list of built-in units functions. * @method xUnits @@ -271,7 +271,7 @@ dc.coordinateGridMixin = function (_chart) { * @todo Add docs for utilities * @example * // set x units to count days - * chart.xUnits(d3.time.days); + * chart.xUnits(d3.timeDays); * // set x units to count months * chart.xUnits(d3.time.months); * @@ -613,7 +613,7 @@ dc.coordinateGridMixin = function (_chart) { _chart._prepareYAxis = function (g) { if (_y === undefined || _chart.elasticY()) { if (_y === undefined) { - _y = d3.scale.linear(); + _y = d3.scaleLinear(); } var min = _chart.yAxisMin() || 0, max = _chart.yAxisMax() || 0; @@ -940,7 +940,7 @@ dc.coordinateGridMixin = function (_chart) { * @example * // set x unit round to by month, this will make sure range selection brush will * // select whole months - * chart.round(d3.time.month.round); + * chart.round(d3.timeMonth.round); * @param {Function} [round] * @returns {Function|dc.coordinateGridMixin} */ @@ -1059,10 +1059,10 @@ dc.coordinateGridMixin = function (_chart) { }; _chart._brushing = function () { - var event = d3v4.event; + var event = d3.event; // Avoids infinite recursion - // To ensure that when it is called because of brush.move there is no d3v4.event.sourceEvent - d3v4.event = null; + // To ensure that when it is called because of brush.move there is no d3.event.sourceEvent + d3.event = null; if (!event.sourceEvent) return; var selection = event.selection; if (selection) { @@ -1278,9 +1278,9 @@ dc.coordinateGridMixin = function (_chart) { } function onZoom () { - if (!d3v4.event.sourceEvent && d3v4.event.sourceEvent.type !== "zoom") return; + if (!d3.event.sourceEvent && d3.event.sourceEvent.type !== "zoom") return; - _chart.x(d3v4.event.transform.rescaleX(_origX)); + _chart.x(d3.event.transform.rescaleX(_origX)); zoomHandler(); } diff --git a/src/core.js b/src/core.js index 388da1a95..e321d97d7 100644 --- a/src/core.js +++ b/src/core.js @@ -355,17 +355,17 @@ dc.units.integers = function (start, end) { /** * This argument can be passed to the {@link dc.coordinateGridMixin#xUnits .xUnits} function of the to * specify ordinal units for the x axis. Usually this parameter is used in combination with passing - * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Ordinal-Scales.md d3.scale.ordinal} to + * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Ordinal-Scales.md d3.scaleOrdinal} to * {@link dc.coordinateGridMixin#x .x}. * It just returns the domain passed to it, which for ordinal charts is an array of all values. * @method ordinal * @memberof dc.units - * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Ordinal-Scales.md d3.scale.ordinal} + * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Ordinal-Scales.md d3.scaleOrdinal} * @see {@link dc.coordinateGridMixin#xUnits coordinateGridMixin.xUnits} * @see {@link dc.coordinateGridMixin#x coordinateGridMixin.x} * @example * chart.xUnits(dc.units.ordinal) - * .x(d3.scale.ordinal()) + * .x(d3.scaleOrdinal()) * @param {*} start * @param {*} end * @param {Array} domain diff --git a/src/d3-compat/d3-compat00.js b/src/d3-compat/d3-compat00.js deleted file mode 100644 index 635f1f431..000000000 --- a/src/d3-compat/d3-compat00.js +++ /dev/null @@ -1,4 +0,0 @@ - -var d3v4 = d3; - -d3 = {}; diff --git a/src/d3-compat/d3-compat01.js b/src/d3-compat/d3-compat01.js deleted file mode 100644 index 92d703138..000000000 --- a/src/d3-compat/d3-compat01.js +++ /dev/null @@ -1,42 +0,0 @@ -d3.behavior = {}; -d3.geo = {}; -d3.layout = {}; -d3.scale = {}; -d3.svg = {}; -d3.time = {}; - -d3.ascending = d3v4.ascending; // d3-array; import ascending from 'd3-array/src/ascending' -d3.behavior.zoom = d3v4.zoom; // d3-zoom; import zoom from 'd3-zoom/src/zoom' -d3.descending = d3v4.descending; // d3-array; import descending from 'd3-array/src/descending' -d3.dispatch = d3v4.dispatch; // d3-dispatch; import dispatch from 'd3-dispatch/src/dispatch' -d3.event = d3v4.event; // d3-selection; import event from 'd3-selection/src/selection/on' -d3.extent = d3v4.extent; // d3-array; import extent from 'd3-array/src/extent' -d3.format = d3v4.format; // d3-format; import {format, utcFormat} from 'd3-format/src/defaultLocale' -d3.geo.path = d3v4.geoPath; // d3-geo; import path from 'd3-geo/src/path/index' -d3.interpolate = d3v4.interpolate; // d3-interpolate; import interpolate from 'd3-interpolate/src/value' -d3.interpolateHcl = d3v4.interpolateHcl; // d3-interpolate; import interpolateHcl from 'd3-interpolate/src/hcl' -d3.interpolateNumber = d3v4.interpolateNumber; // d3-interpolate; import interpolateNumber from 'd3-interpolate/src/number' -d3.layout.pie = d3v4.pie; // d3-shape; import pie from 'd3-shape/src/pie' -d3.layout.stack = d3v4.stack; // d3-shape; import stack from 'd3-shape/src/stack' -d3.max = d3v4.max; // d3-array; import max from 'd3-array/src/max' -d3.min = d3v4.min; // d3-array; import min from 'd3-array/src/min' -d3.mouse = d3v4.mouse; // d3-selection; import mouse from 'd3-selection/src/mouse' -d3.nest = d3v4.nest; // d3-collection; import nest from 'd3-collection/src/nest' -d3.quantile = d3v4.quantile; // d3-array; import quantile from 'd3-array/src/quantile' -d3.range = d3v4.range; // d3-array; import range from 'd3-array/src/range' -d3.scale.category20c = d3v4.schemeCategory20c; // d3-scale; import category20c from 'd3-scale/src/category20c' -d3.scale.linear = d3v4.scaleLinear; // d3-scale; import scaleLinear from 'd3-scale/src/linear' -d3.scale.ordinal = d3v4.scaleOrdinal; // d3-scale; import scaleOrdinal from 'd3-scale/src/ordinal' -d3.scale.quantize = d3v4.scaleQuantize; // d3-scale; import scaleQuantize from 'd3-scale/src/quantize' -d3.select = d3v4.select; // d3-selection; import select from 'd3-selection/src/select' -d3.set = d3v4.set; // d3-collection; import set from 'd3-collection/src/set' -d3.sum = d3v4.sum; // d3-array; import sum from 'd3-array/src/sum' -d3.svg.arc = d3v4.arc; // d3-shape; import arc from 'd3-shape/src/arc' -d3.svg.area = d3v4.area; // d3-shape; import line from 'd3-shape/src/area' -d3.svg.axis = d3v4.axisTop; // d3-axis; import {axisBottom, axisLeft} from 'd3-axis/src/axis' -d3.svg.brush = d3v4.brush; // d3-brush; import {brushX, brushY, default as brush} from 'd3-brush/src/brush' -d3.svg.line = d3v4.line; // d3-shape; import line from 'd3-shape/src/line' -d3.svg.symbol = d3v4.symbol; // d3-shape; import symbol from 'd3-shape/src/symbol' -d3.time.format = d3v4.timeFormat; // d3-time-format; import {timeFormat, utcFormat} from 'd3-time-format/src/defaultLocale' -d3.timer = d3v4.timer; // d3-timer; import {timer} from 'd3-timer/src/timer' - diff --git a/src/d3.box.js b/src/d3.box.js index 5aaa9df7f..147bb0da1 100644 --- a/src/d3.box.js +++ b/src/d3.box.js @@ -35,12 +35,12 @@ d3.range(0, whiskerIndices[0]).concat(d3.range(whiskerIndices[1] + 1, n)) : d3.range(n); // Compute the new x-scale. - var x1 = d3.scale.linear() + var x1 = d3.scaleLinear() .domain(domain && domain.call(this, d, i) || [min, max]) .range([height, 0]); // Retrieve the old x-scale, if this is an update. - var x0 = this.__chart__ || d3.scale.linear() + var x0 = this.__chart__ || d3.scaleLinear() .domain([0, Infinity]) .range(x1.range()); @@ -261,7 +261,7 @@ .style('opacity', 1e-6) .remove(); }); - d3.timer.flush(); + d3.timerFlush(); } box.width = function (x) { diff --git a/src/d3-compat/d3-compat02.js b/src/d3v3-compat.js similarity index 58% rename from src/d3-compat/d3-compat02.js rename to src/d3v3-compat.js index 4063a607d..da75659d2 100644 --- a/src/d3-compat/d3-compat02.js +++ b/src/d3v3-compat.js @@ -1,95 +1,3 @@ - -// Simple function change package/name -d3.time.format.iso = d3v4.isoFormat; -d3.time.format.utc = d3v4.utcFormat; - -d3.time.format.iso.parse = d3v4.isoParse; -d3.timeParse = d3v4.timeParse; - -d3.scaleTime = d3v4.scaleTime; -d3.scaleQuantize = d3v4.scaleQuantize; - -d3.time.second = d3v4.timeSecond; -d3.time.minute = d3v4.timeMinute; -d3.time.hour = d3v4.timeHour; -d3.time.day = d3v4.timeDay; -d3.time.week = d3v4.timeWeek; -d3.time.month = d3v4.timeMonth; -d3.time.year = d3v4.timeYear; - -d3.time.seconds = d3v4.timeSeconds; -d3.time.minutes = d3v4.timeMinutes; -d3.time.hours = d3v4.timeHours; -d3.time.days = d3v4.timeDays; -d3.time.weeks = d3v4.timeWeeks; -d3.time.months = d3v4.timeMonths; -d3.time.years = d3v4.timeYears; - - -d3.time.day.utc = d3v4.utcDay; -d3.time.days.utc = d3v4.utcDays; -d3.time.month.utc = d3v4.utcMonth; - - -d3.time.scale = {}; -d3.time.scale.utc = d3v4.scaleUtc; - -d3.timeout = d3v4.timeout; - -d3.easeQuadIn = d3v4.easeQuadIn; - -d3.scale.log = d3v4.scaleLog; -d3.scaleBand = d3v4.scaleBand; - -d3.timer.flush = d3v4.timerFlush; - -d3.axisBottom = d3v4.axisBottom; -d3.axisLeft = d3v4.axisLeft; -d3.axisRight = d3v4.axisRight; - -d3.layout.stack = d3v4.stack; -d3.curveLinear = d3v4.curveLinear; -d3.curveStepBefore = d3v4.curveStepBefore; -d3.curveCardinal = d3v4.curveCardinal; - -d3.symbolTypes = d3v4.symbolTypes; -d3.symbols = d3v4.symbols; - -d3.geo.mercator = d3v4.geoMercator; -d3.geoPath = d3v4.geoPath; -d3.geoAlbersUsa = d3v4.geoAlbersUsa; - -d3.color = d3v4.color; - - -d3.csv = d3v4.csv; -d3.json = d3v4.json; -d3.csvFormat = d3v4.csvFormat; -d3.csvParse = d3v4.csvParse; -d3.brush = d3v4.brush; -d3.brushX = d3v4.brushX; -d3.brushSelection = d3v4.brushSelection; - -d3.bisector = d3v4.bisector; -d3.median = d3v4.median; - -d3.randomNormal = d3v4.randomNormal; - -// Selection behavior have changed significantly, need manual changes for -// each invocation of .enter() -d3.selectAll = d3v4.selectAll; - - -// Semantic change -d3.scale.category10 = function () { - return d3v4.scaleOrdinal(d3v4.schemeCategory10); -}; - -d3.scale.category20c = function () { - return d3v4.scaleOrdinal(d3v4.schemeCategory20c); -}; - - // Missing in D3v4, code picked up from D3v3 d3.functor = function (v) { return typeof v === "function" ? v : function () { @@ -97,11 +5,8 @@ d3.functor = function (v) { }; }; - // Significant changes in d3.layout.stack - copying from D3v3 for now -d3.permute = d3v4.permute; - -d3.layout.stack = function () { +d3.stackD3v3 = function () { function d3_layout_stackOrderDefault(data) { return d3.range(data.length); } diff --git a/src/geo-choropleth-chart.js b/src/geo-choropleth-chart.js index 7a6c5c418..722de1465 100644 --- a/src/geo-choropleth-chart.js +++ b/src/geo-choropleth-chart.js @@ -241,14 +241,14 @@ dc.geoChoroplethChart = function (parent, chartGroup) { }; /** - * Returns the {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Geo-Paths.md#path d3.geo.path} object used to + * Returns the {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Geo-Paths.md#path d3.geoPath} object used to * render the projection and features. Can be useful for figuring out the bounding box of the * feature set and thus a way to calculate scale and translation for the projection. * @method geoPath * @memberof dc.geoChoroplethChart * @instance - * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Geo-Paths.md#path d3.geo.path} - * @returns {d3.geo.path} + * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Geo-Paths.md#path d3.geoPath} + * @returns {d3.geoPath} */ _chart.geoPath = function () { return _geoPath; diff --git a/src/line-chart.js b/src/line-chart.js index aafa945de..b0924f905 100644 --- a/src/line-chart.js +++ b/src/line-chart.js @@ -82,14 +82,14 @@ dc.lineChart = function (parent, chartGroup) { /** * Gets or sets the interpolator to use for lines drawn, by string name, allowing e.g. step * functions, splines, and cubic interpolation. This is passed to - * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#line_interpolate d3.svg.line.interpolate} and - * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#area_interpolate d3.svg.area.interpolate}, + * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#line_interpolate d3.line.interpolate} and + * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#area_interpolate d3.area.interpolate}, * where you can find a complete list of valid arguments. * @method interpolate * @memberof dc.lineChart * @instance - * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#line_interpolate d3.svg.line.interpolate} - * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#area_interpolate d3.svg.area.interpolate} + * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#line_interpolate d3.line.interpolate} + * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#area_interpolate d3.area.interpolate} * @param {String} [interpolate='linear'] * @returns {String|dc.lineChart} */ @@ -104,13 +104,13 @@ dc.lineChart = function (parent, chartGroup) { /** * Gets or sets the tension to use for lines drawn, in the range 0 to 1. * This parameter further customizes the interpolation behavior. It is passed to - * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#line_tension d3.svg.line.tension} and - * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#area_tension d3.svg.area.tension}. + * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#line_tension d3.line.tension} and + * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#area_tension d3.area.tension}. * @method tension * @memberof dc.lineChart * @instance - * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#line_interpolate d3.svg.line.interpolate} - * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#area_interpolate d3.svg.area.interpolate} + * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#line_interpolate d3.line.interpolate} + * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#area_interpolate d3.area.interpolate} * @param {Number} [tension=0.7] * @returns {Number|dc.lineChart} */ @@ -126,7 +126,7 @@ dc.lineChart = function (parent, chartGroup) { * Gets or sets a function that will determine discontinuities in the line which should be * skipped: the path will be broken into separate subpaths if some points are undefined. * This function is passed to - * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#line_defined d3.svg.line.defined} + * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#line_defined d3.line.defined} * * Note: crossfilter will sometimes coerce nulls to 0, so you may need to carefully write * custom reduce functions to get this to work, depending on your data. See @@ -135,7 +135,7 @@ dc.lineChart = function (parent, chartGroup) { * @method defined * @memberof dc.lineChart * @instance - * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#line_defined d3.svg.line.defined} + * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#line_defined d3.line.defined} * @param {Function} [defined] * @returns {Function|dc.lineChart} */ @@ -196,7 +196,7 @@ dc.lineChart = function (parent, chartGroup) { }; function drawLine (layersEnter, layers) { - var line = d3.svg.line() + var line = d3.line() .x(function (d) { return _chart.x()(d.x); }) @@ -225,7 +225,7 @@ dc.lineChart = function (parent, chartGroup) { function drawArea (layersEnter, layers) { if (_renderArea) { - var area = d3.svg.area() + var area = d3.area() .x(function (d) { return _chart.x()(d.x); }) diff --git a/src/pie-chart.js b/src/pie-chart.js index b79ebfa34..c01ab28b2 100644 --- a/src/pie-chart.js +++ b/src/pie-chart.js @@ -255,7 +255,7 @@ dc.pieChart = function (parent, chartGroup) { }) .merge(polyline); - var arc2 = d3.svg.arc() + var arc2 = d3.arc() .outerRadius(_radius - _externalRadiusPadding + _externalLabelRadius) .innerRadius(_radius - _externalRadiusPadding); var transition = dc.transition(polyline, _chart.transitionDuration(), _chart.transitionDelay()); @@ -430,7 +430,7 @@ dc.pieChart = function (parent, chartGroup) { }; function buildArcs () { - return d3.svg.arc() + return d3.arc() .outerRadius(_radius - _externalRadiusPadding) .innerRadius(_innerRadius); } @@ -462,7 +462,7 @@ dc.pieChart = function (parent, chartGroup) { }; function pieLayout () { - return d3.layout.pie().sort(null).value(_chart.cappedValueAccessor); + return d3.pie().sort(null).value(_chart.cappedValueAccessor); } function sliceTooSmall (d) { @@ -570,7 +570,7 @@ dc.pieChart = function (parent, chartGroup) { function labelPosition (d, arc) { var centroid; if (_externalLabelRadius) { - centroid = d3.svg.arc() + centroid = d3.arc() .outerRadius(_radius - _externalRadiusPadding + _externalLabelRadius) .innerRadius(_radius - _externalRadiusPadding + _externalLabelRadius) .centroid(d); diff --git a/src/row-chart.js b/src/row-chart.js index 95c4a76ec..974b85f2a 100644 --- a/src/row-chart.js +++ b/src/row-chart.js @@ -59,7 +59,7 @@ dc.rowChart = function (parent, chartGroup) { if (extent[1] < 0) { extent[1] = 0; } - _x = d3.scale.linear().domain(extent) + _x = d3.scaleLinear().domain(extent) .range([0, _chart.effectiveWidth()]); } _xAxis.scale(_x); diff --git a/src/scatter-plot.js b/src/scatter-plot.js index 9da4cb66e..068d29ba1 100644 --- a/src/scatter-plot.js +++ b/src/scatter-plot.js @@ -23,7 +23,7 @@ */ dc.scatterPlot = function (parent, chartGroup) { var _chart = dc.coordinateGridMixin({}); - var _symbol = d3.svg.symbol(); + var _symbol = d3.symbol(); var _existenceAccessor = function (d) { return d.value; }; @@ -162,7 +162,7 @@ dc.scatterPlot = function (parent, chartGroup) { * @method symbol * @memberof dc.scatterPlot * @instance - * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_type d3.svg.symbol.type} + * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_type d3.symbol.type} * @example * // Circle type * chart.symbol('circle'); @@ -181,16 +181,16 @@ dc.scatterPlot = function (parent, chartGroup) { /** * Get or set the symbol generator. By default `dc.scatterPlot` will use - * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol d3.svg.symbol()} + * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol d3.symbol()} * to generate symbols. `dc.scatterPlot` will set the * {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_size size accessor} * on the symbol generator. * @method customSymbol * @memberof dc.scatterPlot * @instance - * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol d3.svg.symbol} + * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol d3.symbol} * @see {@link https://stackoverflow.com/questions/25332120/create-additional-d3-js-symbols Create additional D3.js symbols} - * @param {String|Function} [customSymbol=d3.svg.symbol()] + * @param {String|Function} [customSymbol=d3.symbol()] * @returns {String|Function|dc.scatterPlot} */ _chart.customSymbol = function (customSymbol) { @@ -207,7 +207,7 @@ dc.scatterPlot = function (parent, chartGroup) { * @method symbolSize * @memberof dc.scatterPlot * @instance - * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_size d3.svg.symbol.size} + * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_size d3.symbol.size} * @param {Number} [symbolSize=3] * @returns {Number|dc.scatterPlot} */ @@ -224,7 +224,7 @@ dc.scatterPlot = function (parent, chartGroup) { * @method highlightedSize * @memberof dc.scatterPlot * @instance - * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_size d3.svg.symbol.size} + * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_size d3.symbol.size} * @param {Number} [highlightedSize=5] * @returns {Number|dc.scatterPlot} */ @@ -242,7 +242,7 @@ dc.scatterPlot = function (parent, chartGroup) { * @method excludedSize * @memberof dc.scatterPlot * @instance - * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_size d3.svg.symbol.size} + * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_size d3.symbol.size} * @param {Number} [excludedSize=null] * @returns {Number|dc.scatterPlot} */ @@ -292,7 +292,7 @@ dc.scatterPlot = function (parent, chartGroup) { * @method emptySize * @memberof dc.scatterPlot * @instance - * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_size d3.svg.symbol.size} + * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_size d3.symbol.size} * @param {Number} [emptySize=0] * @returns {Number|dc.scatterPlot} */ @@ -426,10 +426,10 @@ dc.scatterPlot = function (parent, chartGroup) { }; _chart._brushing = function () { - var event = d3v4.event; + var event = d3.event; // Avoids infinite recursion - // To ensure that when it is called because of brush.move there is no d3v4.event.sourceEvent - d3v4.event = null; + // To ensure that when it is called because of brush.move there is no d3.event.sourceEvent + d3.event = null; if (!event.sourceEvent) return; var selection = event.selection; diff --git a/src/select-menu.js b/src/select-menu.js index 3b032a07e..e0727177f 100644 --- a/src/select-menu.js +++ b/src/select-menu.js @@ -104,7 +104,7 @@ dc.selectMenu = function (parent, chartGroup) { function onChange (d, i) { var values; - var target = d3v4.event.target; + var target = d3.event.target; if (target.selectedOptions) { var selectedOptions = Array.prototype.slice.call(target.selectedOptions); values = selectedOptions.map(function (d) { @@ -112,7 +112,7 @@ dc.selectMenu = function (parent, chartGroup) { }); } else { // IE and other browsers do not support selectedOptions // adapted from this polyfill: https://gist.github.com/brettz9/4212217 - var options = [].slice.call(d3v4.event.target.options); + var options = [].slice.call(d3.event.target.options); values = options.filter(function (option) { return option.selected; }).map(function (option) { diff --git a/src/stack-mixin.js b/src/stack-mixin.js index 17d4cf0ab..70efea70d 100644 --- a/src/stack-mixin.js +++ b/src/stack-mixin.js @@ -1,5 +1,5 @@ /** - * Stack Mixin is an mixin that provides cross-chart support of stackability using d3.layout.stack. + * Stack Mixin is an mixin that provides cross-chart support of stackability using d3.stackD3v3. * @name stackMixin * @memberof dc * @mixin @@ -25,7 +25,7 @@ dc.stackMixin = function (_chart) { return layer.values; } - var _stackLayout = d3.layout.stack() + var _stackLayout = d3.stackD3v3() .values(prepareValues); var _stack = []; @@ -249,8 +249,8 @@ dc.stackMixin = function (_chart) { * @method stackLayout * @memberof dc.stackMixin * @instance - * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Stack-Layout.md d3.layout.stack} - * @param {Function} [stack=d3.layout.stack] + * @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Stack-Layout.md d3.stackD3v3} + * @param {Function} [stack=d3.stackD3v3] * @returns {Function|dc.stackMixin} */ _chart.stackLayout = function (stack) { @@ -258,7 +258,7 @@ dc.stackMixin = function (_chart) { return _stackLayout; } _stackLayout = stack; - if (_stackLayout.values() === d3.layout.stack().values()) { + if (_stackLayout.values() === d3.stackD3v3().values()) { _stackLayout.values(prepareValues); } return _chart; diff --git a/src/utils.js b/src/utils.js index 56928b9f4..e95cd3d6f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -3,9 +3,9 @@ * @name dateFormat * @memberof dc * @type {Function} - * @default d3.time.format('%m/%d/%Y') + * @default d3.timeFormat('%m/%d/%Y') */ -dc.dateFormat = d3.time.format('%m/%d/%Y'); +dc.dateFormat = d3.timeFormat('%m/%d/%Y'); /** * @namespace printers @@ -120,6 +120,11 @@ dc.utils.printSingleValue = function (filter) { }; dc.utils.printSingleValue.fformat = d3.format('.2f'); +// convert 'day' to 'timeDay' and similar +dc.utils.toTimeFunc = function (t) { + return 'time' + t.charAt(0).toUpperCase() + t.slice(1); +}; + /** * Arbitrary add one value to another. * @method add @@ -147,7 +152,7 @@ dc.utils.add = function (l, r, t) { return new Date(l.getTime() + r); } t = t || 'day'; - return d3.time[t].offset(l, r); + return d3[dc.utils.toTimeFunc(t)].offset(l, r); } else if (typeof r === 'string') { var percentage = (+r / 100); return l > 0 ? l * (1 + percentage) : l * (1 - percentage); @@ -183,7 +188,7 @@ dc.utils.subtract = function (l, r, t) { return new Date(l.getTime() - r); } t = t || 'day'; - return d3.time[t].offset(l, -r); + return d3[dc.utils.toTimeFunc(t)].offset(l, -r); } else if (typeof r === 'string') { var percentage = (+r / 100); return l < 0 ? l * (1 + percentage) : l * (1 - percentage); From 1fa542f475d18dd54a46aada73b5dc2f18295cc9 Mon Sep 17 00:00:00 2001 From: deepak Date: Fri, 9 Mar 2018 23:26:43 +0530 Subject: [PATCH 32/42] Minor cleanup --- spec/coordinate-grid-chart-spec.js | 1 - src/coordinate-grid-mixin.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/coordinate-grid-chart-spec.js b/spec/coordinate-grid-chart-spec.js index 8fac3aedf..58c5d5bfa 100644 --- a/spec/coordinate-grid-chart-spec.js +++ b/spec/coordinate-grid-chart-spec.js @@ -804,7 +804,6 @@ describe('dc.coordinateGridChart', function () { chart.render(); }); - // D3v4 needs reimplementation, APIs have changed describe('with equal dates', function () { beforeEach(function () { // Setup a dummy event - just enough for the handler to get fooled diff --git a/src/coordinate-grid-mixin.js b/src/coordinate-grid-mixin.js index 3a457ba95..d4434a76f 100644 --- a/src/coordinate-grid-mixin.js +++ b/src/coordinate-grid-mixin.js @@ -472,6 +472,7 @@ dc.coordinateGridMixin = function (_chart) { // bandwidth is a method in scaleBand // (https://github.com/d3/d3-scale/blob/master/README.md#scaleBand) if (!_x.bandwidth) { + // If _x is not a scaleBand create a new scale and // copy the original domain to the new scale _x = d3.scaleBand().domain(_x.domain()); } @@ -1227,7 +1228,6 @@ dc.coordinateGridMixin = function (_chart) { _chart._enableMouseZoom = function () { _hasBeenMouseZoomable = true; - // Needs reimplementation for D3v4 _zoom .scaleExtent(_zoomScale) From 07bbcd4e7c653ce4b123489b2f85f41674e02e2b Mon Sep 17 00:00:00 2001 From: deepak Date: Sun, 11 Mar 2018 09:14:33 +0530 Subject: [PATCH 33/42] Merge d3 compat --- D3v4 Upgrade Notes.md | 13 +++++----- web/crime/index.html | 8 +++---- web/docs/stock.html | 24 +++++++++---------- web/ep/index.html | 14 +++++------ web/ep/list.js | 4 ++-- web/examples/adjustable-threshold.html | 4 ++-- web/examples/align-axes.html | 10 ++++---- web/examples/area.html | 4 ++-- web/examples/bar-extra-line.html | 6 ++--- web/examples/bar-single-select.html | 4 ++-- web/examples/bar.html | 4 ++-- web/examples/box-plot-time.html | 10 ++++---- web/examples/box-plot.html | 2 +- web/examples/complex-reduce.html | 6 ++--- web/examples/composite.html | 4 ++-- web/examples/download-table.html | 4 ++-- web/examples/filter-stacks.html | 6 ++--- web/examples/filtering-removing.html | 4 ++-- web/examples/filtering.html | 4 ++-- web/examples/heat.html | 2 +- web/examples/heatmap-filtering.html | 14 +++++------ web/examples/line.html | 4 ++-- web/examples/multi-focus.html | 4 ++-- web/examples/multi-scatter.html | 4 ++-- web/examples/number.html | 2 +- web/examples/ordinal-bar.html | 4 ++-- web/examples/ordinal-line.html | 4 ++-- web/examples/pie-external-labels.html | 2 +- web/examples/pie.html | 2 +- web/examples/range-series.html | 6 ++--- web/examples/right-axis.html | 10 ++++---- web/examples/row.html | 4 ++-- web/examples/scatter-brushing.html | 6 ++--- web/examples/scatter-series.html | 6 ++--- web/examples/scatter.html | 4 ++-- web/examples/select.html | 2 +- web/examples/series.html | 4 ++-- web/examples/sparkline.html | 6 ++--- web/examples/splom.html | 6 ++--- web/examples/stacked-bar.html | 4 ++-- web/examples/switching-time-intervals.html | 14 +++++------ web/examples/table-on-aggregated-data.html | 2 +- web/examples/table-pagination.html | 2 +- web/examples/time-intervals.html | 14 +++++------ web/index.html | 2 +- web/resizing/dc-resizing.js | 4 +++- web/resizing/resizing-bar.html | 4 ++-- web/resizing/resizing-heatmap.html | 18 +++++++------- web/resizing/resizing-pie.html | 2 +- web/resizing/resizing-right-axis.html | 16 ++++++------- web/resizing/resizing-row.html | 4 ++-- web/resizing/resizing-series.html | 6 ++--- web/stock.js | 24 +++++++++---------- web/transitions/area-progression.html | 4 ++-- web/transitions/area-transitions.html | 4 ++-- web/transitions/bar-progression.html | 4 ++-- web/transitions/bar-transitions.html | 4 ++-- web/transitions/number-transitions.html | 2 +- web/transitions/ordinal-bar-transitions.html | 4 ++-- web/transitions/ordinal-line-transitions.html | 4 ++-- web/transitions/ordinal-row-transitions.html | 2 +- .../pie-external-label-transitions.html | 2 +- web/transitions/pie-transitions.html | 2 +- web/transitions/stacked-bar-transitions.html | 4 ++-- web/transitions/transition-test.js | 2 +- web/vc/index.html | 14 +++++------ web/zoom/restrict-panning.html | 10 ++++---- 67 files changed, 206 insertions(+), 203 deletions(-) diff --git a/D3v4 Upgrade Notes.md b/D3v4 Upgrade Notes.md index 04c0336f0..ebf050c1e 100644 --- a/D3v4 Upgrade Notes.md +++ b/D3v4 Upgrade Notes.md @@ -2,16 +2,17 @@ - http://localhost:8888/web/examples/filter-stacks.html (fading is peculiar) - +- http://localhost:8888/web/zoom/restrict-panning.html + Inconsistent with previous version +- http://localhost:8888/web/ + Range brushing inconsistent with previous version + If the range chart is brushed first it works correctly + If the Focus chart is zoomed first, brushing range chart fails. + ##Issues to be fixed - Peculiar fading in filter-stacks.html (Medium) -- Remove D3v3 compat (High) - - - Apply renames - - Apply d3.dispatch changes - - Move remaining compat functions inside dc namespace ##Before release diff --git a/web/crime/index.html b/web/crime/index.html index f848f4605..77a3127b6 100644 --- a/web/crime/index.html +++ b/web/crime/index.html @@ -322,7 +322,7 @@

Major Canadian City Crime Stats 1998-2011

src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"> - + + @@ -26,12 +26,12 @@ function adjust (data) { //calculate age - var dateFormat = d3.time.format("%Y-%m-%d"); + var dateParse = d3.timeParse("%Y-%m-%d"); var now = Date.now(); var birthdate=null; data.forEach(function (e) { - birthdate = dateFormat.parse(e.birthdate); + birthdate = dateParse(e.birthdate); e.age= ~~((now - birthdate) / (31557600000));// 24 * 3600 * 365.25 * 1000 }); } @@ -54,12 +54,12 @@ }); var ageGroup = age.group().reduceSum(function(d) { return 1; }); - //.x(d3.scale.ordinal()) + //.x(d3.scaleOrdinal()) chart_age .width(444) .height(200) .margins({top: 0, right: 0, bottom: 95, left: 30}) - .x(d3.scale.linear().domain([20,100])) + .x(d3.scaleLinear().domain([20,100])) .brushOn(true) .renderArea(true) .elasticY(true) @@ -112,7 +112,7 @@ .width(200) .height(200) .dimension(group) - .colors(d3.scale.category10()) + .colors(d3.scaleOrdinal(d3.schemeCategory10)) .group(groupGroup) .on('renderlet', function (chart) { }); @@ -123,7 +123,7 @@ .outerPadding(0) .gap(1) .margins({top: 0, right: 0, bottom: 95, left: 30}) - .x(d3.scale.ordinal()) + .x(d3.scaleOrdinal()) .xUnits(dc.units.ordinal) .brushOn(false) .elasticY(true) diff --git a/web/ep/list.js b/web/ep/list.js index 1c172741e..299cf435f 100644 --- a/web/ep/list.js +++ b/web/ep/list.js @@ -35,7 +35,7 @@ function list (selector,path,data) { .width(200) .height(200) .dimension(group) - .colors(d3.scale.category10()) + .colors(d3.scaleOrdinal(d3.schemeCategory10)) .group(groupGroup) .on('renderlet', function (chart) { }); @@ -46,7 +46,7 @@ function list (selector,path,data) { .outerPadding(0) .gap(1) .margins({top: 0, right: 0, bottom: 95, left: 30}) - .x(d3.scale.ordinal()) + .x(d3.scaleOrdinal()) .xUnits(dc.units.ordinal) .brushOn(false) .elasticY(true) diff --git a/web/examples/adjustable-threshold.html b/web/examples/adjustable-threshold.html index bf2cb1b63..94b1fdb5b 100644 --- a/web/examples/adjustable-threshold.html +++ b/web/examples/adjustable-threshold.html @@ -4,7 +4,7 @@ dc.js - Adjustable Threshold Example - + @@ -55,7 +55,7 @@ .dimension(bookDimension) .group(bookscoresGroup) .elasticY(true) - .x(d3.scale.ordinal()) + .x(d3.scaleOrdinal()) .xUnits(dc.units.ordinal) .colors(["orange"]) .yAxis().ticks(5); diff --git a/web/examples/align-axes.html b/web/examples/align-axes.html index 5c1610bbf..de20659f8 100644 --- a/web/examples/align-axes.html +++ b/web/examples/align-axes.html @@ -63,7 +63,7 @@ - +
@@ -110,7 +110,7 @@ return ldist.map(function(v, i) { return {key: i, lvalue: v, rvalue: rdist[i]}; }); } - var line = d3.svg.line() + var line = d3.line() .curve(d3.curveLinear); function draw_horizontals(chart, hz) { @@ -157,7 +157,7 @@ .width(200) .height(200) .margins({left: 25, top: 20, right: 30, bottom: 20}) - .x(d3.scale.linear()) + .x(d3.scaleLinear()) .brushOn(false) .alignYAxes(true) .elasticX(true) @@ -166,7 +166,7 @@ dc.lineChart(chart) .dimension(dim) .group(lgroup) - .x(d3.scale.linear()) + .x(d3.scaleLinear()) .elasticX(true) .elasticY(true) .yAxisPadding(1) @@ -180,7 +180,7 @@ dc.lineChart(chart) .dimension(dim) .group(rgroup) - .x(d3.scale.linear()) + .x(d3.scaleLinear()) .ordinalColors(["darkorange"]) .elasticX(true) .elasticY(true) diff --git a/web/examples/area.html b/web/examples/area.html index 1f9124e23..de4b02216 100644 --- a/web/examples/area.html +++ b/web/examples/area.html @@ -12,7 +12,7 @@
- + + +
- + + + + - + + @@ -91,7 +91,7 @@ spendHistChart .dimension(spendDim) .group(spendHist) - .x(d3.scale.linear().domain([0,10])) + .x(d3.scaleLinear().domain([0,10])) .elasticY(true) .controlsUseVisibility(true); diff --git a/web/examples/filter-stacks.html b/web/examples/filter-stacks.html index cc8b6ee3a..33d8913b3 100644 --- a/web/examples/filter-stacks.html +++ b/web/examples/filter-stacks.html @@ -29,7 +29,7 @@
- + + + + +
- + +
- + +
- +
- +
- +
- + + +
- + +
- +
- + + diff --git a/web/examples/series.html b/web/examples/series.html index 71b9de2e2..4b1001d10 100644 --- a/web/examples/series.html +++ b/web/examples/series.html @@ -15,7 +15,7 @@ - + + - +
@@ -157,8 +157,8 @@ .valueAccessor(key_part(1)) .colorAccessor(key_part(2)) .colorDomain(['setosa', 'versicolor', 'virginica']) - .x(d3.scale.linear()).xAxisPadding("0.001%") - .y(d3.scale.linear()).yAxisPadding("0.001%") + .x(d3.scaleLinear()).xAxisPadding("0.001%") + .y(d3.scaleLinear()).yAxisPadding("0.001%") .brushOn(true) .elasticX(true) .elasticY(true) diff --git a/web/examples/stacked-bar.html b/web/examples/stacked-bar.html index 85a92306a..6767fd7f3 100644 --- a/web/examples/stacked-bar.html +++ b/web/examples/stacked-bar.html @@ -17,7 +17,7 @@
- + + + + + @@ -34,7 +34,7 @@ function intervalTreeGroup(tree, firstDate, lastDate) { return { all: function() { - var begin = d3.time.month(firstDate), end = d3.time.month(lastDate); + var begin = d3.timeMonth(firstDate), end = d3.timeMonth(lastDate); var i = new Date(begin); var ret = [], count; do { @@ -54,7 +54,7 @@ } var dateFormatSpecifier = '%x'; - var timeFormat = d3.time.format(dateFormatSpecifier); + var timeFormat = d3.timeFormat(dateFormatSpecifier); var dateFormatParser = d3.timeParse(dateFormatSpecifier); var monthChart = dc.barChart("#month"); var costChart = dc.barChart("#cost"); @@ -95,8 +95,8 @@ .width(400) .height(300) .x(d3.scaleTime()) - .y(d3.scale.linear().domain([0,25])) - .xUnits(d3.time.months) + .y(d3.scaleLinear().domain([0,25])) + .xUnits(d3.timeMonths) .gap(5) .elasticX(true) .brushOn(true) @@ -123,8 +123,8 @@ costChart .width(400) .height(300) - .x(d3.scale.linear().domain([0,24])) - .y(d3.scale.linear().domain([0,25])) + .x(d3.scaleLinear().domain([0,24])) + .y(d3.scaleLinear().domain([0,25])) .brushOn(true) .yAxisLabel("Number of Projects") .xAxisLabel("Cost") diff --git a/web/index.html b/web/index.html index ee783bb56..6b196f865 100644 --- a/web/index.html +++ b/web/index.html @@ -169,7 +169,7 @@

Nasdaq 100 Index 1985/11/01-2012/06/29

- + diff --git a/web/resizing/dc-resizing.js b/web/resizing/dc-resizing.js index 39318db12..46be4e733 100644 --- a/web/resizing/dc-resizing.js +++ b/web/resizing/dc-resizing.js @@ -28,7 +28,9 @@ function apply_resizing(chart, adjustX, adjustY, onresize) { .width(window.innerWidth-adjustX) .height(window.innerHeight-adjustY); window.onresize = function() { - onresize(chart); + if(onresize) { + onresize(chart); + } chart .width(window.innerWidth-20) .height(window.innerHeight-20) diff --git a/web/resizing/resizing-bar.html b/web/resizing/resizing-bar.html index 67c5f5146..d4f243a98 100644 --- a/web/resizing/resizing-bar.html +++ b/web/resizing/resizing-bar.html @@ -10,7 +10,7 @@
- + @@ -28,7 +28,7 @@ speedSumGroup = runDimension.group().reduceSum(function(d) {return d.Speed * d.Run / 1000;}); chart - .x(d3.scale.linear().domain([6,20])) + .x(d3.scaleLinear().domain([6,20])) .brushOn(true) .xAxisLabel("This is the X Axis!!") .yAxisLabel("This is the Y Axis!") diff --git a/web/resizing/resizing-heatmap.html b/web/resizing/resizing-heatmap.html index f354791f4..b2fa9be65 100644 --- a/web/resizing/resizing-heatmap.html +++ b/web/resizing/resizing-heatmap.html @@ -12,7 +12,7 @@

Michelson–Morley experiment

- + + diff --git a/web/resizing/resizing-right-axis.html b/web/resizing/resizing-right-axis.html index e74a17cc2..48965469e 100644 --- a/web/resizing/resizing-right-axis.html +++ b/web/resizing/resizing-right-axis.html @@ -14,7 +14,7 @@
- + @@ -22,12 +22,12 @@ var moveChart = dc.compositeChart("#monthly-move-chart"); d3.csv("../examples/monthly-move.csv", function (error, data) { - var dateFormat = d3.time.format("%m/%d/%Y"); + var dateParse = d3.timeParse("%m/%d/%Y"); var numberFormat = d3.format(".2f"); data.forEach(function (e) { - e.dd = dateFormat.parse(e.date); - e.month = d3.time.month(e.dd); // pre-calculate month for better performance + e.dd = dateParse(e.date); + e.month = d3.timeMonth(e.dd); // pre-calculate month for better performance }); var ndx = crossfilter(data); @@ -64,9 +64,9 @@ .margins({top: 30, right: 50, bottom: 25, left: 60}) .dimension(moveMonths) .mouseZoomable(true) - .x(d3.time.scale().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)])) - .round(d3.time.month.round) - .xUnits(d3.time.months) + .x(d3.scaleTime().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)])) + .round(d3.timeMonth.round) + .xUnits(d3.timeMonths) .elasticY(true) .renderHorizontalGridLines(true) .legend(dc.legend().x(90).y(10).itemHeight(13).gap(5)) @@ -85,7 +85,7 @@ .title(function (d) { var value = d.data.value.avg ? d.data.value.avg : d.data.value; if (isNaN(value)) value = 0; - return dateFormat(d.data.key) + "\n" + numberFormat(value); + return dateParse(d.data.key) + "\n" + numberFormat(value); }) .ordinalColors(["orange"]) .useRightYAxis(true) diff --git a/web/resizing/resizing-row.html b/web/resizing/resizing-row.html index 745bcc2f8..1b1df370c 100644 --- a/web/resizing/resizing-row.html +++ b/web/resizing/resizing-row.html @@ -10,7 +10,7 @@
- + @@ -30,7 +30,7 @@ chart .width(window.innerWidth-20) .height(window.innerHeight-20) - .x(d3.scale.linear().domain([6,20])) + .x(d3.scaleLinear().domain([6,20])) .elasticX(true) .dimension(runDimension) .group(speedSumGroup) diff --git a/web/resizing/resizing-series.html b/web/resizing/resizing-series.html index 5b3df5ecb..13531b6ee 100644 --- a/web/resizing/resizing-series.html +++ b/web/resizing/resizing-series.html @@ -13,7 +13,7 @@ - + @@ -32,8 +32,8 @@ chart .width(window.innerWidth-adjustX) .height(window.innerHeight-adjustY) - .chart(function(c) { return dc.lineChart(c).interpolate('cardinal'); }) - .x(d3.scale.linear().domain([0,20])) + .chart(function(c) { return dc.lineChart(c).interpolate(d3.curveCardinal); }) + .x(d3.scaleLinear().domain([0,20])) .brushOn(false) .yAxisLabel("Measured Speed km/s") .xAxisLabel("Run") diff --git a/web/stock.js b/web/stock.js index fe0308118..322e24a34 100644 --- a/web/stock.js +++ b/web/stock.js @@ -62,13 +62,13 @@ var nasdaqTable = dc.dataTable('.dc-data-table'); d3.csv('ndx.csv', function (data) { // Since its a csv file we need to format the data a bit. var dateFormatSpecifier = '%m/%d/%Y'; - var dateFormat = d3.time.format(dateFormatSpecifier); + var dateFormat = d3.timeFormat(dateFormatSpecifier); var dateFormatParser = d3.timeParse(dateFormatSpecifier); var numberFormat = d3.format('.2f'); data.forEach(function (d) { d.dd = dateFormatParser(d.date); - d.month = d3.time.month(d.dd); // pre-calculate month for better performance + d.month = d3.timeMonth(d.dd); // pre-calculate month for better performance d.close = +d.close; // coerce to number d.open = +d.open; }); @@ -81,7 +81,7 @@ d3.csv('ndx.csv', function (data) { // Dimension by year var yearlyDimension = ndx.dimension(function (d) { - return d3.time.year(d.dd).getFullYear(); + return d3.timeYear(d.dd).getFullYear(); }); // Maintain running tallies by year as filters are applied or removed var yearlyPerformanceGroup = yearlyDimension.group().reduce( @@ -245,9 +245,9 @@ d3.csv('ndx.csv', function (data) { return p.value.fluctuationPercentage; }) .maxBubbleRelativeSize(0.3) - .x(d3.scale.linear().domain([-2500, 2500])) - .y(d3.scale.linear().domain([-100, 100])) - .r(d3.scale.linear().domain([0, 4000])) + .x(d3.scaleLinear().domain([-2500, 2500])) + .y(d3.scaleLinear().domain([-100, 100])) + .r(d3.scaleLinear().domain([0, 4000])) //##### Elastic Scaling //`.elasticY` and `.elasticX` determine whether the chart should rescale each axis to fit the data. @@ -390,7 +390,7 @@ d3.csv('ndx.csv', function (data) { // (_optional_) set filter brush rounding .round(dc.round.floor) .alwaysUseRounding(true) - .x(d3.scale.linear().domain([-25, 25])) + .x(d3.scaleLinear().domain([-25, 25])) .renderHorizontalGridLines(true) // Customize the filter displayed in the control span .filterPrinter(function (filters) { @@ -420,8 +420,8 @@ d3.csv('ndx.csv', function (data) { // Specify a "range chart" to link its brush extent with the zoom of the current "focus chart". .rangeChart(volumeChart) .x(d3.scaleTime().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)])) - .round(d3.time.month.round) - .xUnits(d3.time.months) + .round(d3.timeMonth.round) + .xUnits(d3.timeMonths) .elasticY(true) .renderHorizontalGridLines(true) //##### Legend @@ -462,9 +462,9 @@ d3.csv('ndx.csv', function (data) { .centerBar(true) .gap(1) .x(d3.scaleTime().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)])) - .round(d3.time.month.round) + .round(d3.timeMonth.round) .alwaysUseRounding(true) - .xUnits(d3.time.months); + .xUnits(d3.timeMonths); //#### Data Count @@ -637,7 +637,7 @@ d3.csv('ndx.csv', function (data) { // Closure used to retrieve radius value from multi-value group .radiusValueAccessor(function(p) {return p.value.fluctuationPercentage;}) // set radius scale - .r(d3.scale.linear().domain([0, 3])) + .r(d3.scaleLinear().domain([0, 3])) // (_optional_) whether chart should render labels, `default = true` .renderLabel(true) // (_optional_) closure to generate label per bubble, `default = group.key` diff --git a/web/transitions/area-progression.html b/web/transitions/area-progression.html index 5f8ba5d51..8e2508f28 100644 --- a/web/transitions/area-progression.html +++ b/web/transitions/area-progression.html @@ -15,7 +15,7 @@ - + @@ -42,7 +42,7 @@ .transitionDuration(transitionTest.duration) .width(768) .height(480) - .x(d3.scale.linear()) + .x(d3.scaleLinear()) .elasticX(true) .elasticY(true) .margins({left: 50, top: 10, right: 10, bottom: 20}) diff --git a/web/transitions/area-transitions.html b/web/transitions/area-transitions.html index 101f68e0d..ef521786c 100644 --- a/web/transitions/area-transitions.html +++ b/web/transitions/area-transitions.html @@ -17,7 +17,7 @@ - + @@ -54,7 +54,7 @@ .transitionDuration(transitionTest.duration) .width(768) .height(480) - .x(d3.scale.linear().domain([1,20])) + .x(d3.scaleLinear().domain([1,20])) .margins({left: 50, top: 10, right: 10, bottom: 20}) .renderArea(doArea) .brushOn(false) diff --git a/web/transitions/bar-progression.html b/web/transitions/bar-progression.html index c232a6763..c63f88eb9 100644 --- a/web/transitions/bar-progression.html +++ b/web/transitions/bar-progression.html @@ -15,7 +15,7 @@ - + @@ -40,7 +40,7 @@ .transitionDuration(transitionTest.duration) .width(768) .height(480) - .x(d3.scale.linear()) + .x(d3.scaleLinear()) .elasticX(true) .elasticY(true) .margins({left: 50, top: 10, right: 10, bottom: 20}) diff --git a/web/transitions/bar-transitions.html b/web/transitions/bar-transitions.html index eedf62a27..65aebbe84 100644 --- a/web/transitions/bar-transitions.html +++ b/web/transitions/bar-transitions.html @@ -16,7 +16,7 @@ - + @@ -37,7 +37,7 @@ .transitionDuration(transitionTest.duration) .width(768) .height(480) - .x(d3.scale.linear().domain([0,20])) + .x(d3.scaleLinear().domain([0,20])) .brushOn(false) .yAxisLabel("This is the Y Axis!") .dimension(runDimension) diff --git a/web/transitions/number-transitions.html b/web/transitions/number-transitions.html index fe132e0cb..edf03f677 100644 --- a/web/transitions/number-transitions.html +++ b/web/transitions/number-transitions.html @@ -10,7 +10,7 @@
- + diff --git a/web/transitions/ordinal-bar-transitions.html b/web/transitions/ordinal-bar-transitions.html index 5c6f29c93..556a10e3c 100644 --- a/web/transitions/ordinal-bar-transitions.html +++ b/web/transitions/ordinal-bar-transitions.html @@ -19,7 +19,7 @@ - + @@ -31,7 +31,7 @@ return chart .width(768) .height(380) - .x(d3.scale.ordinal()) + .x(d3.scaleOrdinal()) .xUnits(dc.units.ordinal) .elasticX(true) .elasticY(true) diff --git a/web/transitions/ordinal-line-transitions.html b/web/transitions/ordinal-line-transitions.html index cc53454d5..9edb68cbb 100644 --- a/web/transitions/ordinal-line-transitions.html +++ b/web/transitions/ordinal-line-transitions.html @@ -19,7 +19,7 @@ - + @@ -31,7 +31,7 @@ return chart .width(768) .height(380) - .x(d3.scale.ordinal()) + .x(d3.scaleOrdinal()) .xUnits(dc.units.ordinal) .elasticX(true) .elasticY(true) diff --git a/web/transitions/ordinal-row-transitions.html b/web/transitions/ordinal-row-transitions.html index 4c4bd592c..85514e6cd 100644 --- a/web/transitions/ordinal-row-transitions.html +++ b/web/transitions/ordinal-row-transitions.html @@ -19,7 +19,7 @@ - + diff --git a/web/transitions/pie-external-label-transitions.html b/web/transitions/pie-external-label-transitions.html index 4d2a58be3..8c772a7c8 100644 --- a/web/transitions/pie-external-label-transitions.html +++ b/web/transitions/pie-external-label-transitions.html @@ -17,7 +17,7 @@ - + diff --git a/web/transitions/pie-transitions.html b/web/transitions/pie-transitions.html index c1898b5be..33191b01a 100644 --- a/web/transitions/pie-transitions.html +++ b/web/transitions/pie-transitions.html @@ -17,7 +17,7 @@ - + diff --git a/web/transitions/stacked-bar-transitions.html b/web/transitions/stacked-bar-transitions.html index 3761273c7..687b6601d 100644 --- a/web/transitions/stacked-bar-transitions.html +++ b/web/transitions/stacked-bar-transitions.html @@ -17,7 +17,7 @@ - + @@ -52,7 +52,7 @@ .transitionDuration(transitionTest.duration) .width(768) .height(480) - .x(d3.scale.linear().domain([1,21])) + .x(d3.scaleLinear().domain([1,21])) .margins({left: 50, top: 10, right: 10, bottom: 20}) .brushOn(false) .clipPadding(10) diff --git a/web/transitions/transition-test.js b/web/transitions/transition-test.js index dfd492089..b2dc322ac 100644 --- a/web/transitions/transition-test.js +++ b/web/transitions/transition-test.js @@ -44,7 +44,7 @@ var transitionTest = (function() { _magnitude = 1, // maximum change in y per observation _reverse = false; // whether to regress instead of progress var _data = []; - var rand = d3.random.normal(); + var rand = d3.randomNormal(); function startval() { // .fill() (when can we drop ie?) var a = new Array(N); for(var i = 0; iUS Venture Capital Landscape 2011 src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"> - +
- +