From da75f6f5aca2bd226c8be108d77a9cca4c80df20 Mon Sep 17 00:00:00 2001 From: Matt Traynham Date: Tue, 27 Jan 2015 10:46:57 -0500 Subject: [PATCH 1/4] Cleanup the Gruntfile --- Gruntfile.js | 202 +++++++++++++++++++++++-------------------------- LICENSE_BANNER | 17 +++++ package.json | 24 +++--- src/banner.js | 18 ----- src/core.js | 4 +- 5 files changed, 126 insertions(+), 139 deletions(-) create mode 100644 LICENSE_BANNER diff --git a/Gruntfile.js b/Gruntfile.js index 2f356dba1..3de0101f4 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,21 +1,63 @@ module.exports = function (grunt) { 'use strict'; - var jsFiles = module.exports.jsFiles; + require('load-grunt-tasks')(grunt); + require('time-grunt')(grunt); - var output = { - js: '<%= pkg.name %>.js', - jsmin: '<%= pkg.name %>.min.js', - map: '<%= pkg.name %>.min.js.map' + var config = { + src: 'src', + spec: 'spec', + web: 'web', + pkg: require('./package.json'), + banner: grunt.file.read('./LICENSE_BANNER'), + jsFiles: [ + 'src/banner.js', // NOTE: keep this first + 'src/core.js', + 'src/errors.js', + 'src/utils.js', + 'src/logger.js', + 'src/events.js', + 'src/filters.js', + 'src/base-mixin.js', + 'src/margin-mixin.js', + 'src/color-mixin.js', + 'src/coordinate-grid-mixin.js', + 'src/stack-mixin.js', + 'src/cap-mixin.js', + 'src/bubble-mixin.js', + 'src/pie-chart.js', + 'src/bar-chart.js', + 'src/line-chart.js', + 'src/data-count.js', + 'src/data-table.js', + 'src/data-grid.js', + 'src/bubble-chart.js', + 'src/composite-chart.js', + 'src/series-chart.js', + 'src/geo-choropleth-chart.js', + 'src/bubble-overlay.js', + 'src/row-chart.js', + 'src/legend.js', + 'src/scatter-plot.js', + 'src/number-display.js', + 'src/heatmap.js', + 'src/d3.box.js', + 'src/box-plot.js', + 'src/footer.js' // NOTE: keep this last + ] }; grunt.initConfig({ - pkg: grunt.file.readJSON('package.json'), + conf: config, concat: { + options : { + process: true, + banner : '<%= conf.banner %>' + }, js: { - src: jsFiles, - dest: output.js + src: '<%= conf.jsFiles %>', + dest: '<%= conf.pkg.name %>.js' } }, uglify: { @@ -23,28 +65,23 @@ module.exports = function (grunt) { options: { mangle: true, compress: true, - sourceMap: output.map + sourceMap: true, + banner : '<%= conf.banner %>' }, - src: output.js, - dest: output.jsmin - } - }, - sed: { - version: { - pattern: '%VERSION%', - replacement: '<%= pkg.version %>', - path: [output.js, output.jsmin] + src: '<%= conf.pkg.name %>.js', + dest: '<%= conf.pkg.name %>.min.js' } }, jscs: { old: { - src: ['spec/**/*.js'], + src: ['<%= conf.spec %>/**/*.js'], options: { validateIndentation: 4 } }, source: { - src: ['src/**/*.js', '!src/{banner,footer}.js', 'Gruntfile.js', 'web/stock.js'], + src: ['<%= conf.src %>/**/*.js', '!<%= conf.src %>/{banner,footer}.js', 'Gruntfile.js', + '<%= conf.web %>/stock.js'], options: { config: '.jscsrc' } @@ -52,28 +89,32 @@ module.exports = function (grunt) { }, jshint: { source: { - src: ['src/**/*.js', 'Gruntfile.js', 'web/stock.js'], + src: ['<%= conf.src %>/**/*.js', 'Gruntfile.js', '<%= conf.web %>/stock.js'], options: { jshintrc: '.jshintrc', - ignores: ['src/banner.js', 'src/footer.js'] + ignores: ['<%= conf.src %>/banner.js', '<%= conf.src %>/footer.js'] } } }, watch: { scripts: { - files: ['src/**/*.js'], + files: ['<%= conf.src %>/**/*.js'], tasks: ['build', 'copy'] }, jasmineRunner: { - files: ['spec/**/*.js'], + files: ['<%= conf.spec %>/**/*.js'], tasks: ['jasmine:specs:build'] }, tests: { - files: ['src/**/*.js', 'spec/**/*.js'], + files: ['<%= conf.src %>/**/*.js', '<%= conf.spec %>/**/*.js'], tasks: ['test'] }, reload: { - files: ['dc.js', 'dc.css', 'web/js/dc.js', 'web/css/dc.css', 'dc.min.js'], + files: ['<%= conf.pkg.name %>.js', + '<%= conf.pkg.name %>css', + '<%= conf.web %>/js/<%= conf.pkg.name %>.js', + '<%= conf.web %>/css/<%= conf.pkg.name %>.css', + '<%= conf.pkg.name %>.min.js'], options: { livereload: true } @@ -92,17 +133,17 @@ module.exports = function (grunt) { options: { display: 'short', summary: true, - specs: 'spec/*-spec.js', - helpers: 'spec/helpers/*.js', + specs: '<%= conf.spec %>/*-spec.js', + helpers: '<%= conf.spec %>/helpers/*.js', version: '2.0.0', - outfile: 'spec/index.html', + outfile: '<%= conf.spec %>/index.html', keepRunner: true }, src: [ - 'web/js/d3.js', - 'web/js/crossfilter.js', - 'web/js/colorbrewer.js', - 'dc.js' + '<%= conf.web %>/js/d3.js', + '<%= conf.web %>/js/crossfilter.js', + '<%= conf.web %>/js/colorbrewer.js', + '<%= conf.pkg.name %>.js' ] }, coverage:{ @@ -129,10 +170,10 @@ module.exports = function (grunt) { options: { display: 'short', summary: true, - specs: 'spec/*-spec.js', - helpers: 'spec/helpers/*.js', + specs: '<%= conf.spec %>/*-spec.js', + helpers: '<%= conf.spec %>/helpers/*.js', version: '2.0.0', - outfile: 'spec/index-browserify.html', + outfile: '<%= conf.spec %>/index-browserify.html', keepRunner: true }, src: [ @@ -164,14 +205,14 @@ module.exports = function (grunt) { platform: 'WIN8' } ], - testname: 'dc.js' + testname: '<%= conf.pkg.name %>.js' } } }, emu: { api: { - src: output.js, - dest: 'web/docs/api-latest.md' + src: '<%= conf.pkg.name %>.js', + dest: '<%= conf.web %>/docs/api-latest.md' } }, toc: { @@ -183,19 +224,19 @@ module.exports = function (grunt) { markdown: { html: { src: '<%= emu.api.dest %>', - dest: 'web/docs/index.html' + dest: '<%= conf.web %>/docs/index.html' }, options: {markdownOptions: {highlight: 'manual'}} }, docco: { options: { - dst: 'web/docs', - basepath:'web' + dst: '<%= conf.web %>/docs', + basepath:'<%= conf.web %>' }, howto: { files: [ { - src: ['web/stock.js'] + src: ['<%= conf.web %>/stock.js'] } ] } @@ -203,18 +244,18 @@ module.exports = function (grunt) { copy: { 'dc-to-gh': { files: [ - {expand: true, flatten: true, src: 'dc.css', dest: 'web/css/'}, + {expand: true, flatten: true, src: '<%= conf.pkg.name %>.css', dest: '<%= conf.web %>/css/'}, { expand: true, flatten: true, src: [ - output.js, - output.js + '.map', + '<%= conf.pkg.name %>.min.js', + '<%= conf.pkg.name %>.min.js.map', 'node_modules/d3/d3.js', 'node_modules/crossfilter/crossfilter.js', 'test/env-data.js' ], - dest: 'web/js/' + dest: '<%= conf.web %>/js/' } ] } @@ -247,7 +288,7 @@ module.exports = function (grunt) { '

An attempt to present a simple example of each chart type.', '', 'Contributions welcome.

', - '

Source ', + '

Source ', 'here.

', body, '' @@ -256,14 +297,14 @@ module.exports = function (grunt) { absolute: true }, files: [ - {dest: 'web/examples/index.html', src: ['web/examples/*.html']} + {dest: '<%= conf.web %>/examples/index.html', src: ['<%= conf.web %>/examples/*.html']} ] } }, 'gh-pages': { options: { - base: 'web', + base: '<%= conf.web %>', message: 'Synced from from master branch.' }, src: ['**'] @@ -298,36 +339,17 @@ module.exports = function (grunt) { }, browserify: { dev: { - src: 'dc.js', + src: '<%= conf.pkg.name %>.js', dest: 'bundle.js', options: { browserifyOptions: { standalone: 'dc' } } - }, + } } }); - // These plugins provide necessary tasks. - grunt.loadNpmTasks('grunt-contrib-concat'); - grunt.loadNpmTasks('grunt-contrib-connect'); - grunt.loadNpmTasks('grunt-contrib-copy'); - grunt.loadNpmTasks('grunt-contrib-jasmine'); - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.loadNpmTasks('grunt-contrib-watch'); - grunt.loadNpmTasks('grunt-docco2'); - grunt.loadNpmTasks('grunt-gh-pages'); - grunt.loadNpmTasks('grunt-jscs'); - grunt.loadNpmTasks('grunt-saucelabs'); - grunt.loadNpmTasks('grunt-markdown'); - grunt.loadNpmTasks('grunt-sed'); - grunt.loadNpmTasks('grunt-shell'); - grunt.loadNpmTasks('grunt-debug-task'); - grunt.loadNpmTasks('grunt-fileindex'); - grunt.loadNpmTasks('grunt-browserify'); - // custom tasks grunt.registerMultiTask('emu', 'Documentation extraction by emu.', function () { var emu = require('emu'), @@ -376,7 +398,7 @@ module.exports = function (grunt) { }); // task aliases - grunt.registerTask('build', ['concat', 'uglify', 'sed']); + grunt.registerTask('build', ['concat', 'uglify']); grunt.registerTask('docs', ['build', 'copy', 'emu', 'toc', 'markdown', 'docco']); grunt.registerTask('web', ['docs', 'gh-pages']); grunt.registerTask('server', ['docs', 'fileindex', 'jasmine:specs:build', 'connect:server', 'watch:jasmine']); @@ -388,39 +410,3 @@ module.exports = function (grunt) { grunt.registerTask('lint', ['build', 'jshint', 'jscs']); grunt.registerTask('default', ['build']); }; - -module.exports.jsFiles = [ - 'src/banner.js', - 'src/core.js', - 'src/errors.js', - 'src/utils.js', - 'src/logger.js', - 'src/events.js', - 'src/filters.js', - 'src/base-mixin.js', - 'src/margin-mixin.js', - 'src/color-mixin.js', - 'src/coordinate-grid-mixin.js', - 'src/stack-mixin.js', - 'src/cap-mixin.js', - 'src/bubble-mixin.js', - 'src/pie-chart.js', - 'src/bar-chart.js', - 'src/line-chart.js', - 'src/data-count.js', - 'src/data-table.js', - 'src/data-grid.js', - 'src/bubble-chart.js', - 'src/composite-chart.js', - 'src/series-chart.js', - 'src/geo-choropleth-chart.js', - 'src/bubble-overlay.js', - 'src/row-chart.js', - 'src/legend.js', - 'src/scatter-plot.js', - 'src/number-display.js', - 'src/heatmap.js', - 'src/d3.box.js', - 'src/box-plot.js', - 'src/footer.js' // NOTE: keep this last -]; diff --git a/LICENSE_BANNER b/LICENSE_BANNER new file mode 100644 index 000000000..25aeadfa9 --- /dev/null +++ b/LICENSE_BANNER @@ -0,0 +1,17 @@ +/*! + * dc <%= conf.pkg.version %> + * http://dc-js.github.io/dc.js/ + * Copyright 2012 Nick Zhu and other contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ diff --git a/package.json b/package.json index f5f6eb5ab..b094aae78 100644 --- a/package.json +++ b/package.json @@ -30,29 +30,31 @@ }, "devDependencies": { "emu": "~0.0.2", - "grunt": "~0.4.1", - "grunt-browserify": "^3.2.1", - "grunt-cli": "~0.1.9", + "grunt": "~0.4.5", + "grunt-browserify": "~3.3.0", + "grunt-cli": "~0.1.13", "grunt-contrib-concat": "~0.5.0", "grunt-contrib-connect": "~0.9.0", "grunt-contrib-copy": "~0.7.0", - "grunt-contrib-jasmine": "~0.8.1", - "grunt-contrib-jshint": "~0.10.0", + "grunt-contrib-jasmine": "~0.8.2", + "grunt-contrib-jshint": "~0.11.0", "grunt-contrib-uglify": "~0.7.0", "grunt-contrib-watch": "~0.6.1", - "grunt-debug-task": "~0.1.4", + "grunt-debug-task": "~0.1.5", "grunt-docco2": "~0.2.0", "grunt-fileindex": "^0.1.0", "grunt-gh-pages": "~0.9.1", "grunt-jscs": "~1.2.0", "grunt-lib-phantomjs": "~0.6.0", - "grunt-markdown": "~0.6.1", - "grunt-saucelabs": "~8.4.1", + "grunt-markdown": "~0.7.0", + "grunt-saucelabs": "~8.5.0", "grunt-sed": "~0.1.1", "grunt-shell": "~1.1.1", - "grunt-template-jasmine-istanbul": "~0.3.1", - "marked": "~0.3.2", - "uglify-js": "2.4.x" + "grunt-template-jasmine-istanbul": "~0.3.2", + "load-grunt-tasks": "~3.0.0", + "marked": "~0.3.3", + "uglify-js": "2.4.x", + "time-grunt": "~1.0.0" }, "scripts": { "test": "grunt test" diff --git a/src/banner.js b/src/banner.js index 153885e9e..59be0972f 100644 --- a/src/banner.js +++ b/src/banner.js @@ -1,20 +1,2 @@ -/*! - * dc %VERSION% - * http://dc-js.github.io/dc.js/ - * Copyright 2012 Nick Zhu and other contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - (function() { function _dc(d3, crossfilter) { 'use strict'; diff --git a/src/core.js b/src/core.js index 1db554ccb..3f08b65e9 100644 --- a/src/core.js +++ b/src/core.js @@ -1,5 +1,5 @@ /** -#### Version %VERSION% +#### Version <%= conf.pkg.version %> The entire dc.js library is scoped under the **dc** name space. It does not introduce anything else into the global name space. #### Function Chaining @@ -20,7 +20,7 @@ that are chainable d3 objects.) /*jshint -W062*/ /*jshint -W079*/ var dc = { - version: '%VERSION%', + version: '<%= conf.pkg.version %>', constants: { CHART_CLASS: 'dc-chart', DEBUG_GROUP_CLASS: 'debug', From 8d3c088ddb92d068375a301ad54b736a97187d5f Mon Sep 17 00:00:00 2001 From: Matt Traynham Date: Tue, 27 Jan 2015 11:03:07 -0500 Subject: [PATCH 2/4] Forgot to remove the grunt-sed package --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index b094aae78..65c037441 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "grunt-lib-phantomjs": "~0.6.0", "grunt-markdown": "~0.7.0", "grunt-saucelabs": "~8.5.0", - "grunt-sed": "~0.1.1", "grunt-shell": "~1.1.1", "grunt-template-jasmine-istanbul": "~0.3.2", "load-grunt-tasks": "~3.0.0", From e2ff25ebf7dbfc682de502b690d224fe7aaa14b1 Mon Sep 17 00:00:00 2001 From: Matt Traynham Date: Tue, 27 Jan 2015 11:42:38 -0500 Subject: [PATCH 3/4] Removed difflib.js. Can pull from npm. Update Gruntfile to properly copy files to web. --- Gruntfile.js | 3 + package.json | 1 + regression/difflib.js | 411 ---------------------------- regression/stock-regression-test.js | 2 +- 4 files changed, 5 insertions(+), 412 deletions(-) delete mode 100644 regression/difflib.js diff --git a/Gruntfile.js b/Gruntfile.js index 3de0101f4..93ccb4c04 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -53,6 +53,7 @@ module.exports = function (grunt) { concat: { options : { process: true, + sourceMap: true, banner : '<%= conf.banner %>' }, js: { @@ -249,6 +250,8 @@ module.exports = function (grunt) { expand: true, flatten: true, src: [ + '<%= conf.pkg.name %>.js', + '<%= conf.pkg.name %>.js.map', '<%= conf.pkg.name %>.min.js', '<%= conf.pkg.name %>.min.js.map', 'node_modules/d3/d3.js', diff --git a/package.json b/package.json index 65c037441..769faed43 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "grunt-shell": "~1.1.1", "grunt-template-jasmine-istanbul": "~0.3.2", "load-grunt-tasks": "~3.0.0", + "jsdifflib": "~1.1.0", "marked": "~0.3.3", "uglify-js": "2.4.x", "time-grunt": "~1.0.0" diff --git a/regression/difflib.js b/regression/difflib.js deleted file mode 100644 index 5b8d769bd..000000000 --- a/regression/difflib.js +++ /dev/null @@ -1,411 +0,0 @@ -/*** -This is part of jsdifflib v1.0. - -Copyright (c) 2007, Snowtide Informatics Systems, Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of the Snowtide Informatics Systems nor the names of its - contributors may be used to endorse or promote products derived from this - software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT -SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -DAMAGE. -***/ -/* Author: Chas Emerick */ -__whitespace = {" ":true, "\t":true, "\n":true, "\f":true, "\r":true}; - -difflib = { - defaultJunkFunction: function (c) { - return __whitespace.hasOwnProperty(c); - }, - - stripLinebreaks: function (str) { return str.replace(/^[\n\r]*|[\n\r]*$/g, ""); }, - - stringAsLines: function (str) { - var lfpos = str.indexOf("\n"); - var crpos = str.indexOf("\r"); - var linebreak = ((lfpos > -1 && crpos > -1) || crpos < 0) ? "\n" : "\r"; - - var lines = str.split(linebreak); - for (var i = 0; i < lines.length; i++) { - lines[i] = difflib.stripLinebreaks(lines[i]); - } - - return lines; - }, - - // iteration-based reduce implementation - __reduce: function (func, list, initial) { - if (initial != null) { - var value = initial; - var idx = 0; - } else if (list) { - var value = list[0]; - var idx = 1; - } else { - return null; - } - - for (; idx < list.length; idx++) { - value = func(value, list[idx]); - } - - return value; - }, - - // comparison function for sorting lists of numeric tuples - __ntuplecomp: function (a, b) { - var mlen = Math.max(a.length, b.length); - for (var i = 0; i < mlen; i++) { - if (a[i] < b[i]) return -1; - if (a[i] > b[i]) return 1; - } - - return a.length == b.length ? 0 : (a.length < b.length ? -1 : 1); - }, - - __calculate_ratio: function (matches, length) { - return length ? 2.0 * matches / length : 1.0; - }, - - // returns a function that returns true if a key passed to the returned function - // is in the dict (js object) provided to this function; replaces being able to - // carry around dict.has_key in python... - __isindict: function (dict) { - return function (key) { return dict.hasOwnProperty(key); }; - }, - - // replacement for python's dict.get function -- need easy default values - __dictget: function (dict, key, defaultValue) { - return dict.hasOwnProperty(key) ? dict[key] : defaultValue; - }, - - SequenceMatcher: function (a, b, isjunk) { - this.set_seqs = function (a, b) { - this.set_seq1(a); - this.set_seq2(b); - } - - this.set_seq1 = function (a) { - if (a == this.a) return; - this.a = a; - this.matching_blocks = this.opcodes = null; - } - - this.set_seq2 = function (b) { - if (b == this.b) return; - this.b = b; - this.matching_blocks = this.opcodes = this.fullbcount = null; - this.__chain_b(); - } - - this.__chain_b = function () { - var b = this.b; - var n = b.length; - var b2j = this.b2j = {}; - var populardict = {}; - for (var i = 0; i < b.length; i++) { - var elt = b[i]; - if (b2j.hasOwnProperty(elt)) { - var indices = b2j[elt]; - if (n >= 200 && indices.length * 100 > n) { - populardict[elt] = 1; - delete b2j[elt]; - } else { - indices.push(i); - } - } else { - b2j[elt] = [i]; - } - } - - for (var elt in populardict) { - if (populardict.hasOwnProperty(elt)) { - delete b2j[elt]; - } - } - - var isjunk = this.isjunk; - var junkdict = {}; - if (isjunk) { - for (var elt in populardict) { - if (populardict.hasOwnProperty(elt) && isjunk(elt)) { - junkdict[elt] = 1; - delete populardict[elt]; - } - } - for (var elt in b2j) { - if (b2j.hasOwnProperty(elt) && isjunk(elt)) { - junkdict[elt] = 1; - delete b2j[elt]; - } - } - } - - this.isbjunk = difflib.__isindict(junkdict); - this.isbpopular = difflib.__isindict(populardict); - } - - this.find_longest_match = function (alo, ahi, blo, bhi) { - var a = this.a; - var b = this.b; - var b2j = this.b2j; - var isbjunk = this.isbjunk; - var besti = alo; - var bestj = blo; - var bestsize = 0; - var j = null; - - var j2len = {}; - var nothing = []; - for (var i = alo; i < ahi; i++) { - var newj2len = {}; - var jdict = difflib.__dictget(b2j, a[i], nothing); - for (var jkey in jdict) { - if (jdict.hasOwnProperty(jkey)) { - j = jdict[jkey]; - if (j < blo) continue; - if (j >= bhi) break; - newj2len[j] = k = difflib.__dictget(j2len, j - 1, 0) + 1; - if (k > bestsize) { - besti = i - k + 1; - bestj = j - k + 1; - bestsize = k; - } - } - } - j2len = newj2len; - } - - while (besti > alo && bestj > blo && !isbjunk(b[bestj - 1]) && a[besti - 1] == b[bestj - 1]) { - besti--; - bestj--; - bestsize++; - } - - while (besti + bestsize < ahi && bestj + bestsize < bhi && - !isbjunk(b[bestj + bestsize]) && - a[besti + bestsize] == b[bestj + bestsize]) { - bestsize++; - } - - while (besti > alo && bestj > blo && isbjunk(b[bestj - 1]) && a[besti - 1] == b[bestj - 1]) { - besti--; - bestj--; - bestsize++; - } - - while (besti + bestsize < ahi && bestj + bestsize < bhi && isbjunk(b[bestj + bestsize]) && - a[besti + bestsize] == b[bestj + bestsize]) { - bestsize++; - } - - return [besti, bestj, bestsize]; - } - - this.get_matching_blocks = function () { - if (this.matching_blocks != null) return this.matching_blocks; - var la = this.a.length; - var lb = this.b.length; - - var queue = [[0, la, 0, lb]]; - var matching_blocks = []; - var alo, ahi, blo, bhi, qi, i, j, k, x; - while (queue.length) { - qi = queue.pop(); - alo = qi[0]; - ahi = qi[1]; - blo = qi[2]; - bhi = qi[3]; - x = this.find_longest_match(alo, ahi, blo, bhi); - i = x[0]; - j = x[1]; - k = x[2]; - - if (k) { - matching_blocks.push(x); - if (alo < i && blo < j) - queue.push([alo, i, blo, j]); - if (i+k < ahi && j+k < bhi) - queue.push([i + k, ahi, j + k, bhi]); - } - } - - matching_blocks.sort(difflib.__ntuplecomp); - - var i1 = j1 = k1 = block = 0; - var non_adjacent = []; - for (var idx in matching_blocks) { - if (matching_blocks.hasOwnProperty(idx)) { - block = matching_blocks[idx]; - i2 = block[0]; - j2 = block[1]; - k2 = block[2]; - if (i1 + k1 == i2 && j1 + k1 == j2) { - k1 += k2; - } else { - if (k1) non_adjacent.push([i1, j1, k1]); - i1 = i2; - j1 = j2; - k1 = k2; - } - } - } - - if (k1) non_adjacent.push([i1, j1, k1]); - - non_adjacent.push([la, lb, 0]); - this.matching_blocks = non_adjacent; - return this.matching_blocks; - } - - this.get_opcodes = function () { - if (this.opcodes != null) return this.opcodes; - var i = 0; - var j = 0; - var answer = []; - this.opcodes = answer; - var block, ai, bj, size, tag; - var blocks = this.get_matching_blocks(); - for (var idx in blocks) { - if (blocks.hasOwnProperty(idx)) { - block = blocks[idx]; - ai = block[0]; - bj = block[1]; - size = block[2]; - tag = ''; - if (i < ai && j < bj) { - tag = 'replace'; - } else if (i < ai) { - tag = 'delete'; - } else if (j < bj) { - tag = 'insert'; - } - if (tag) answer.push([tag, i, ai, j, bj]); - i = ai + size; - j = bj + size; - - if (size) answer.push(['equal', ai, i, bj, j]); - } - } - - return answer; - } - - // this is a generator function in the python lib, which of course is not supported in javascript - // the reimplementation builds up the grouped opcodes into a list in their entirety and returns that. - this.get_grouped_opcodes = function (n) { - if (!n) n = 3; - var codes = this.get_opcodes(); - if (!codes) codes = [["equal", 0, 1, 0, 1]]; - var code, tag, i1, i2, j1, j2; - if (codes[0][0] == 'equal') { - code = codes[0]; - tag = code[0]; - i1 = code[1]; - i2 = code[2]; - j1 = code[3]; - j2 = code[4]; - codes[0] = [tag, Math.max(i1, i2 - n), i2, Math.max(j1, j2 - n), j2]; - } - if (codes[codes.length - 1][0] == 'equal') { - code = codes[codes.length - 1]; - tag = code[0]; - i1 = code[1]; - i2 = code[2]; - j1 = code[3]; - j2 = code[4]; - codes[codes.length - 1] = [tag, i1, Math.min(i2, i1 + n), j1, Math.min(j2, j1 + n)]; - } - - var nn = n + n; - var group = []; - var groups = []; - for (var idx in codes) { - if (codes.hasOwnProperty(idx)) { - code = codes[idx]; - tag = code[0]; - i1 = code[1]; - i2 = code[2]; - j1 = code[3]; - j2 = code[4]; - if (tag == 'equal' && i2 - i1 > nn) { - group.push([tag, i1, Math.min(i2, i1 + n), j1, Math.min(j2, j1 + n)]); - groups.push(group); - group = []; - i1 = Math.max(i1, i2-n); - j1 = Math.max(j1, j2-n); - } - - group.push([tag, i1, i2, j1, j2]); - } - } - - if (group && !(group.length == 1 && group[0][0] == 'equal')) groups.push(group) - - return groups; - } - - this.ratio = function () { - matches = difflib.__reduce( - function (sum, triple) { return sum + triple[triple.length - 1]; }, - this.get_matching_blocks(), 0); - return difflib.__calculate_ratio(matches, this.a.length + this.b.length); - } - - this.quick_ratio = function () { - var fullbcount, elt; - if (this.fullbcount == null) { - this.fullbcount = fullbcount = {}; - for (var i = 0; i < this.b.length; i++) { - elt = this.b[i]; - fullbcount[elt] = difflib.__dictget(fullbcount, elt, 0) + 1; - } - } - fullbcount = this.fullbcount; - - var avail = {}; - var availhas = difflib.__isindict(avail); - var matches = numb = 0; - for (var i = 0; i < this.a.length; i++) { - elt = this.a[i]; - if (availhas(elt)) { - numb = avail[elt]; - } else { - numb = difflib.__dictget(fullbcount, elt, 0); - } - avail[elt] = numb - 1; - if (numb > 0) matches++; - } - - return difflib.__calculate_ratio(matches, this.a.length + this.b.length); - } - - this.real_quick_ratio = function () { - var la = this.a.length; - var lb = this.b.length; - return _calculate_ratio(Math.min(la, lb), la + lb); - } - - this.isjunk = isjunk ? isjunk : difflib.defaultJunkFunction; - this.a = this.b = null; - this.set_seqs(a, b); - } -}; - diff --git a/regression/stock-regression-test.js b/regression/stock-regression-test.js index f58763dff..fd1e13bb0 100644 --- a/regression/stock-regression-test.js +++ b/regression/stock-regression-test.js @@ -1,6 +1,6 @@ var grunt = require("grunt"); var phantomjs = require('grunt-lib-phantomjs').init(grunt); -require("./difflib.js"); +var difflib = require("jsdifflib"); module.exports = { testStockExample: function (asyncDone, showDiff) { From a7193039ce6b0f77fb172dc0c1c9874188b81bf5 Mon Sep 17 00:00:00 2001 From: Skitch Date: Tue, 27 Jan 2015 22:48:14 -0500 Subject: [PATCH 4/4] Reverts part of the Gruntfile that exported the list of src files. --- Gruntfile.js | 72 +++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 93ccb4c04..8e8bc6f03 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -10,41 +10,7 @@ module.exports = function (grunt) { web: 'web', pkg: require('./package.json'), banner: grunt.file.read('./LICENSE_BANNER'), - jsFiles: [ - 'src/banner.js', // NOTE: keep this first - 'src/core.js', - 'src/errors.js', - 'src/utils.js', - 'src/logger.js', - 'src/events.js', - 'src/filters.js', - 'src/base-mixin.js', - 'src/margin-mixin.js', - 'src/color-mixin.js', - 'src/coordinate-grid-mixin.js', - 'src/stack-mixin.js', - 'src/cap-mixin.js', - 'src/bubble-mixin.js', - 'src/pie-chart.js', - 'src/bar-chart.js', - 'src/line-chart.js', - 'src/data-count.js', - 'src/data-table.js', - 'src/data-grid.js', - 'src/bubble-chart.js', - 'src/composite-chart.js', - 'src/series-chart.js', - 'src/geo-choropleth-chart.js', - 'src/bubble-overlay.js', - 'src/row-chart.js', - 'src/legend.js', - 'src/scatter-plot.js', - 'src/number-display.js', - 'src/heatmap.js', - 'src/d3.box.js', - 'src/box-plot.js', - 'src/footer.js' // NOTE: keep this last - ] + jsFiles: module.exports.jsFiles }; grunt.initConfig({ @@ -413,3 +379,39 @@ module.exports = function (grunt) { grunt.registerTask('lint', ['build', 'jshint', 'jscs']); grunt.registerTask('default', ['build']); }; + +module.exports.jsFiles = [ + 'src/banner.js', // NOTE: keep this first + 'src/core.js', + 'src/errors.js', + 'src/utils.js', + 'src/logger.js', + 'src/events.js', + 'src/filters.js', + 'src/base-mixin.js', + 'src/margin-mixin.js', + 'src/color-mixin.js', + 'src/coordinate-grid-mixin.js', + 'src/stack-mixin.js', + 'src/cap-mixin.js', + 'src/bubble-mixin.js', + 'src/pie-chart.js', + 'src/bar-chart.js', + 'src/line-chart.js', + 'src/data-count.js', + 'src/data-table.js', + 'src/data-grid.js', + 'src/bubble-chart.js', + 'src/composite-chart.js', + 'src/series-chart.js', + 'src/geo-choropleth-chart.js', + 'src/bubble-overlay.js', + 'src/row-chart.js', + 'src/legend.js', + 'src/scatter-plot.js', + 'src/number-display.js', + 'src/heatmap.js', + 'src/d3.box.js', + 'src/box-plot.js', + 'src/footer.js' // NOTE: keep this last +];