Skip to content

Commit c624d3d

Browse files
authored
Merge pull request #7563 from plotly/fix-missing-json-font-attrs
Fix issue causing empty ScatterGL plots when using text elements
2 parents e2abf6e + 33c46a4 commit c624d3d

File tree

8 files changed

+40
-49
lines changed

8 files changed

+40
-49
lines changed

draftlogs/7563_fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix issue causing empty ScatterGL plots when using text elements [#7563](https://github.com/plotly/plotly.js/pull/7563)

package-lock.json

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@
133133
"deep-equal": "^2.2.3",
134134
"ecstatic": "^4.1.4",
135135
"esbuild": "^0.25.5",
136-
"esbuild-plugin-browserify-adapter": "^0.1.4",
137136
"esbuild-plugin-environment": "^0.4.0",
138137
"esbuild-plugin-glsl": "^1.2.2",
139138
"esbuild-plugin-inline-css": "^0.0.1",
@@ -182,4 +181,4 @@
182181
"acorn": "^8.1.1"
183182
}
184183
}
185-
}
184+
}

tasks/cibundle.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ var tasks = [];
1919
// Bundle plotly.js
2020
tasks.push(function(done) {
2121
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyBuild, {
22-
noCompressAttributes: true,
2322
}, done)
2423
});
2524

2625
// Bundle plotly.min.js
2726
tasks.push(function(done) {
2827
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyBuildMin, {
2928
minify: true,
30-
noCompressAttributes: true,
3129
}, done)
3230
});
3331

tasks/compress_attributes.js

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var through = require('through2');
1+
const fs = require('fs');
22

33
/**
4-
* Browserify transform that strips meta attributes out
4+
* ESBuild plugin that strips out meta attributes
55
* of the plotly.js bundles
66
*/
77

@@ -10,47 +10,46 @@ var OPTIONAL_COMMA = ',?';
1010

1111
// one line string with or without trailing comma
1212
function makeStringRegex(attr) {
13-
return makeRegex(
14-
WHITESPACE_BEFORE + attr + ': \'.*\'' + OPTIONAL_COMMA
15-
);
13+
return makeRegex(WHITESPACE_BEFORE + attr + ": '.*'" + OPTIONAL_COMMA);
1614
}
1715

1816
// joined array of strings with or without trailing comma
1917
function makeJoinedArrayRegex(attr) {
20-
return makeRegex(
21-
WHITESPACE_BEFORE + attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + OPTIONAL_COMMA
22-
);
18+
return makeRegex(WHITESPACE_BEFORE + attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + OPTIONAL_COMMA);
2319
}
2420

2521
// array with or without trailing comma
2622
function makeArrayRegex(attr) {
27-
return makeRegex(
28-
WHITESPACE_BEFORE + attr + ': \\[[\\s\\S]*?\\]' + OPTIONAL_COMMA
29-
);
23+
return makeRegex(WHITESPACE_BEFORE + attr + ': \\[[\\s\\S]*?\\]' + OPTIONAL_COMMA);
3024
}
3125

3226
function makeRegex(regexStr) {
33-
return (
34-
new RegExp(regexStr, 'g')
35-
);
27+
return new RegExp(regexStr, 'g');
3628
}
3729

38-
module.exports = function() {
39-
var allChunks = [];
40-
return through(function(chunk, enc, next) {
41-
allChunks.push(chunk);
42-
next();
43-
}, function(done) {
44-
var str = Buffer.concat(allChunks).toString('utf-8');
45-
this.push(
46-
str
47-
.replace(makeStringRegex('description'), '')
48-
.replace(makeJoinedArrayRegex('description'), '')
49-
.replace(makeArrayRegex('requiredOpts'), '')
50-
.replace(makeArrayRegex('otherOpts'), '')
51-
.replace(makeStringRegex('role'), '')
52-
.replace(makeStringRegex('hrName'), '')
53-
);
54-
done();
55-
});
30+
const allRegexes = [
31+
makeStringRegex('description'),
32+
makeJoinedArrayRegex('description'),
33+
makeArrayRegex('requiredOpts'),
34+
makeArrayRegex('otherOpts'),
35+
makeStringRegex('role'),
36+
makeStringRegex('hrName')
37+
];
38+
39+
const esbuildPluginStripMeta = {
40+
name: 'strip-meta-attributes',
41+
setup(build) {
42+
const loader = 'js';
43+
build.onLoad({ filter: /\.js$/ }, async (file) => ({
44+
contents: await fs.promises.readFile(file.path, 'utf-8').then((c) => {
45+
allRegexes.forEach((r) => {
46+
c = c.replace(r, '');
47+
});
48+
return c;
49+
}),
50+
loader
51+
}));
52+
}
5653
};
54+
55+
module.exports = esbuildPluginStripMeta;

tasks/util/bundle_wrapper.mjs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import prependFile from 'prepend-file';
55
import { build } from 'esbuild';
66

77
import esbuildConfig from '../../esbuild-config.js';
8-
import browserifyAdapter from 'esbuild-plugin-browserify-adapter';
8+
import esbuildPluginStripMeta from '../../tasks/compress_attributes.js';
99

10-
import transform from '../../tasks/compress_attributes.js';
1110
import common from './common.js';
1211

1312
var basePlugins = esbuildConfig.plugins;
@@ -30,14 +29,14 @@ var basePlugins = esbuildConfig.plugins;
3029
export default async function _bundle(pathToIndex, pathToBundle, opts, cb) {
3130
opts = opts || {};
3231

33-
var config = {...esbuildConfig};
32+
var config = { ...esbuildConfig };
3433

3534
config.entryPoints = [pathToIndex];
3635
config.outfile = pathToBundle;
3736
config.minify = !!opts.minify;
3837

3938
if(!opts.noCompressAttributes) {
40-
config.plugins = basePlugins.concat([browserifyAdapter(transform)]);
39+
config.plugins = basePlugins.concat([esbuildPluginStripMeta]);
4140
}
4241

4342
if(opts.noPlugins) config.plugins = [];
@@ -51,7 +50,7 @@ export default async function _bundle(pathToIndex, pathToBundle, opts, cb) {
5150

5251
// Until https://github.com/evanw/esbuild/pull/513 is merged
5352
// Thanks to https://github.com/prantlf and https://github.com/birkskyum
54-
function addWrapper(path){
53+
function addWrapper(path) {
5554
prependFile.sync(
5655
path,
5756
[
560 Bytes
Loading

test/image/mocks/gl2d_scatter-colorscale-colorbar.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
"marker": {
3737
"size": 20
3838
},
39+
"text": ["orange"],
40+
"textposition": "top center",
3941
"type": "scattergl",
40-
"mode": "markers"
42+
"mode": "text+markers"
4143
}
4244
],
4345
"layout": {

0 commit comments

Comments
 (0)