diff --git a/draftlogs/7563_fix.md b/draftlogs/7563_fix.md new file mode 100644 index 00000000000..f8530c94d56 --- /dev/null +++ b/draftlogs/7563_fix.md @@ -0,0 +1 @@ + - Fix issue causing empty ScatterGL plots when using text elements [#7563](https://github.com/plotly/plotly.js/pull/7563) diff --git a/package-lock.json b/package-lock.json index 518c310a649..7933efe5147 100644 --- a/package-lock.json +++ b/package-lock.json @@ -75,7 +75,6 @@ "deep-equal": "^2.2.3", "ecstatic": "^4.1.4", "esbuild": "^0.25.5", - "esbuild-plugin-browserify-adapter": "^0.1.4", "esbuild-plugin-environment": "^0.4.0", "esbuild-plugin-glsl": "^1.2.2", "esbuild-plugin-inline-css": "^0.0.1", @@ -4108,12 +4107,6 @@ "@esbuild/win32-x64": "0.25.5" } }, - "node_modules/esbuild-plugin-browserify-adapter": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/esbuild-plugin-browserify-adapter/-/esbuild-plugin-browserify-adapter-0.1.4.tgz", - "integrity": "sha512-CQikNT7vb0CDae/iB/ktjuB8MsPX/f7AfB8dPZ5d1ZYECdeaVQnPf2QYHGyCSo8qD9u1CaNUSF9p026UC+YUmg==", - "dev": true - }, "node_modules/esbuild-plugin-define": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/esbuild-plugin-define/-/esbuild-plugin-define-0.5.0.tgz", diff --git a/package.json b/package.json index d4f4d0768a4..f66a1af748e 100644 --- a/package.json +++ b/package.json @@ -133,7 +133,6 @@ "deep-equal": "^2.2.3", "ecstatic": "^4.1.4", "esbuild": "^0.25.5", - "esbuild-plugin-browserify-adapter": "^0.1.4", "esbuild-plugin-environment": "^0.4.0", "esbuild-plugin-glsl": "^1.2.2", "esbuild-plugin-inline-css": "^0.0.1", @@ -182,4 +181,4 @@ "acorn": "^8.1.1" } } -} +} \ No newline at end of file diff --git a/tasks/cibundle.mjs b/tasks/cibundle.mjs index f0d8761634c..159917031ae 100644 --- a/tasks/cibundle.mjs +++ b/tasks/cibundle.mjs @@ -19,7 +19,6 @@ var tasks = []; // Bundle plotly.js tasks.push(function(done) { _bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyBuild, { - noCompressAttributes: true, }, done) }); @@ -27,7 +26,6 @@ tasks.push(function(done) { tasks.push(function(done) { _bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyBuildMin, { minify: true, - noCompressAttributes: true, }, done) }); diff --git a/tasks/compress_attributes.js b/tasks/compress_attributes.js index aa1ae1df7d9..29b1ac8fa33 100644 --- a/tasks/compress_attributes.js +++ b/tasks/compress_attributes.js @@ -1,7 +1,7 @@ -var through = require('through2'); +const fs = require('fs'); /** - * Browserify transform that strips meta attributes out + * ESBuild plugin that strips out meta attributes * of the plotly.js bundles */ @@ -10,47 +10,46 @@ var OPTIONAL_COMMA = ',?'; // one line string with or without trailing comma function makeStringRegex(attr) { - return makeRegex( - WHITESPACE_BEFORE + attr + ': \'.*\'' + OPTIONAL_COMMA - ); + return makeRegex(WHITESPACE_BEFORE + attr + ": '.*'" + OPTIONAL_COMMA); } // joined array of strings with or without trailing comma function makeJoinedArrayRegex(attr) { - return makeRegex( - WHITESPACE_BEFORE + attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + OPTIONAL_COMMA - ); + return makeRegex(WHITESPACE_BEFORE + attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + OPTIONAL_COMMA); } // array with or without trailing comma function makeArrayRegex(attr) { - return makeRegex( - WHITESPACE_BEFORE + attr + ': \\[[\\s\\S]*?\\]' + OPTIONAL_COMMA - ); + return makeRegex(WHITESPACE_BEFORE + attr + ': \\[[\\s\\S]*?\\]' + OPTIONAL_COMMA); } function makeRegex(regexStr) { - return ( - new RegExp(regexStr, 'g') - ); + return new RegExp(regexStr, 'g'); } -module.exports = function() { - var allChunks = []; - return through(function(chunk, enc, next) { - allChunks.push(chunk); - next(); - }, function(done) { - var str = Buffer.concat(allChunks).toString('utf-8'); - this.push( - str - .replace(makeStringRegex('description'), '') - .replace(makeJoinedArrayRegex('description'), '') - .replace(makeArrayRegex('requiredOpts'), '') - .replace(makeArrayRegex('otherOpts'), '') - .replace(makeStringRegex('role'), '') - .replace(makeStringRegex('hrName'), '') - ); - done(); - }); +const allRegexes = [ + makeStringRegex('description'), + makeJoinedArrayRegex('description'), + makeArrayRegex('requiredOpts'), + makeArrayRegex('otherOpts'), + makeStringRegex('role'), + makeStringRegex('hrName') +]; + +const esbuildPluginStripMeta = { + name: 'strip-meta-attributes', + setup(build) { + const loader = 'js'; + build.onLoad({ filter: /\.js$/ }, async (file) => ({ + contents: await fs.promises.readFile(file.path, 'utf-8').then((c) => { + allRegexes.forEach((r) => { + c = c.replace(r, ''); + }); + return c; + }), + loader + })); + } }; + +module.exports = esbuildPluginStripMeta; diff --git a/tasks/util/bundle_wrapper.mjs b/tasks/util/bundle_wrapper.mjs index e324b0617bb..561588a58f5 100644 --- a/tasks/util/bundle_wrapper.mjs +++ b/tasks/util/bundle_wrapper.mjs @@ -5,9 +5,8 @@ import prependFile from 'prepend-file'; import { build } from 'esbuild'; import esbuildConfig from '../../esbuild-config.js'; -import browserifyAdapter from 'esbuild-plugin-browserify-adapter'; +import esbuildPluginStripMeta from '../../tasks/compress_attributes.js'; -import transform from '../../tasks/compress_attributes.js'; import common from './common.js'; var basePlugins = esbuildConfig.plugins; @@ -30,14 +29,14 @@ var basePlugins = esbuildConfig.plugins; export default async function _bundle(pathToIndex, pathToBundle, opts, cb) { opts = opts || {}; - var config = {...esbuildConfig}; + var config = { ...esbuildConfig }; config.entryPoints = [pathToIndex]; config.outfile = pathToBundle; config.minify = !!opts.minify; if(!opts.noCompressAttributes) { - config.plugins = basePlugins.concat([browserifyAdapter(transform)]); + config.plugins = basePlugins.concat([esbuildPluginStripMeta]); } if(opts.noPlugins) config.plugins = []; @@ -51,7 +50,7 @@ export default async function _bundle(pathToIndex, pathToBundle, opts, cb) { // Until https://github.com/evanw/esbuild/pull/513 is merged // Thanks to https://github.com/prantlf and https://github.com/birkskyum -function addWrapper(path){ +function addWrapper(path) { prependFile.sync( path, [ diff --git a/test/image/baselines/gl2d_scatter-colorscale-colorbar.png b/test/image/baselines/gl2d_scatter-colorscale-colorbar.png index 65c5f50dd9d..6c5f1854d57 100644 Binary files a/test/image/baselines/gl2d_scatter-colorscale-colorbar.png and b/test/image/baselines/gl2d_scatter-colorscale-colorbar.png differ diff --git a/test/image/mocks/gl2d_scatter-colorscale-colorbar.json b/test/image/mocks/gl2d_scatter-colorscale-colorbar.json index 6f6883846d8..dd90ff7ee30 100644 --- a/test/image/mocks/gl2d_scatter-colorscale-colorbar.json +++ b/test/image/mocks/gl2d_scatter-colorscale-colorbar.json @@ -36,8 +36,10 @@ "marker": { "size": 20 }, + "text": ["orange"], + "textposition": "top center", "type": "scattergl", - "mode": "markers" + "mode": "text+markers" } ], "layout": {