Skip to content

Sort plot-schema and add test to track plot-schema changes #5776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ jobs:
echo https://$CIRCLE_BUILD_NUM-$PROJECT_NUM-gh.circle-artifacts.com/0/dist/plotly.js
echo https://$CIRCLE_BUILD_NUM-$PROJECT_NUM-gh.circle-artifacts.com/0/dist/plotly.min.js
echo https://$CIRCLE_BUILD_NUM-$PROJECT_NUM-gh.circle-artifacts.com/0/dist/plot-schema.json
- run:
name: Test plot-schema.json diff - If failed, after (npm start) you could run (npm run schema && git add test/plot-schema.json && git commit -m "update plot-schema diff")
command: diff --unified --color dist/plot-schema.json test/plot-schema.json
- run:
name: Test plotly.min.js import using requirejs
command: npm run test-requirejs
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
"custom-bundle": "node tasks/custom_bundle.js",
"bundle": "node tasks/bundle.js",
"extra-bundles": "node tasks/extra_bundles.js",
"schema": "node tasks/schema.js",
"stats": "node tasks/stats.js",
"find-strings": "node tasks/find_locale_strings.js",
"preprocess": "node tasks/preprocess.js",
"build": "node tasks/empty_dist.js && npm run preprocess && npm run find-strings && npm run bundle && npm run extra-bundles && npm run stats",
"build": "node tasks/empty_dist.js && npm run preprocess && npm run find-strings && npm run bundle && npm run extra-bundles && npm run schema dist && npm run stats",
"cibuild": "node tasks/empty_dist.js && npm run preprocess && node tasks/cibundle.js",
"watch": "node tasks/watch.js",
"lint": "eslint --version && eslint .",
Expand Down
5 changes: 1 addition & 4 deletions tasks/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ var prependFile = require('prepend-file');
var constants = require('./util/constants');
var common = require('./util/common');
var _bundle = require('./util/browserify_wrapper');
var makeSchema = require('./util/make_schema');
var wrapLocale = require('./util/wrap_locale');

var header = constants.licenseDist + '\n';
var pathToLib = constants.pathToLib;
var pathToDist = constants.pathToDist;
var pathToSchema = constants.pathToSchema;
var pathToPlotlyDist = constants.pathToPlotlyDist;
var pathToPlotlyIndex = constants.pathToPlotlyIndex;
var pathToPlotlyDistMin = constants.pathToPlotlyDistMin;
Expand Down Expand Up @@ -67,15 +65,14 @@ tasks.push(function(done) {
});
});

// Browserify plotly.js with meta and output plot-schema JSON
// Browserify plotly.js with meta
tasks.push(function(done) {
_bundle(pathToPlotlyIndex, pathToPlotlyDistWithMeta, {
standalone: 'Plotly',
noCompress: true
}, function() {
prependFile(pathToPlotlyDistWithMeta, header, common.throwOnError);

makeSchema(pathToPlotlyDistWithMeta, pathToSchema);
done();
});
});
Expand Down
29 changes: 29 additions & 0 deletions tasks/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var fs = require('fs');
var path = require('path');

var constants = require('./util/constants');
var plotlyNode = require('./util/plotly_node');
var sortObject = require('./util/sort_object');

function makeSchema(plotlyPath, schemaPath) {
var Plotly = plotlyNode(plotlyPath);

var plotSchema = sortObject(Plotly.PlotSchema.get());
var plotSchemaStr = JSON.stringify(plotSchema, null, 1);
fs.writeFileSync(schemaPath, plotSchemaStr);

console.log('ok ' + path.basename(schemaPath));
}

var isDist = process.argv[2] === 'dist';

var pathToSchema = isDist ?
constants.pathToSchemaDist :
constants.pathToSchemaDiff;

var pathToPlotly = isDist ?
constants.pathToPlotlyDistWithMeta :
constants.pathToPlotlyBuild;

// output plot-schema JSON
makeSchema(pathToPlotly, pathToSchema);
6 changes: 4 additions & 2 deletions tasks/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var pkg = require('../../package.json');
var pathToRoot = path.join(__dirname, '../../');
var pathToSrc = path.join(pathToRoot, 'src/');
var pathToLib = path.join(pathToRoot, 'lib/');
var pathToImageTest = path.join(pathToRoot, 'test/image');
var pathToTest = path.join(pathToRoot, 'test/');
var pathToImageTest = path.join(pathToTest, 'image/');
var pathToStrictD3Module = path.join(pathToRoot, 'test/strict-d3.js');
var pathToDist = path.join(pathToRoot, 'dist/');
var pathToBuild = path.join(pathToRoot, 'build/');
Expand Down Expand Up @@ -183,7 +184,8 @@ module.exports = {
pathToPlotlyDistMin: path.join(pathToDist, 'plotly.min.js'),
pathToPlotlyDistWithMeta: path.join(pathToDist, 'plotly-with-meta.js'),

pathToSchema: path.join(pathToDist, 'plot-schema.json'),
pathToSchemaDiff: path.join(pathToTest, 'plot-schema.json'),
pathToSchemaDist: path.join(pathToDist, 'plot-schema.json'),
pathToTranslationKeys: path.join(pathToDist, 'translation-keys.txt'),

partialBundleNames: partialBundleNames,
Expand Down
13 changes: 0 additions & 13 deletions tasks/util/make_schema.js

This file was deleted.

21 changes: 21 additions & 0 deletions tasks/util/sort_object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function caseInsensitive(a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
}

function sortObject(obj) {
var allKeys = Object.keys(obj);
allKeys.sort(caseInsensitive);

var newObj = {};
for(var i = 0; i < allKeys.length; i++) {
var key = allKeys[i];
var v = obj[key];
newObj[key] = (typeof v === 'object' && v !== null && !(v instanceof Array)) ?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we need to dig into arrays too, right? We've got stuff in the schema like:

      "items": [
       {
        "valType": "number",
        "min": 0,
        "max": 1,
        "editType": "calc"
       },
       {
        "valType": "number",
        "min": 0,
        "max": 1,
        "editType": "calc"
       }
      ],

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.
aea3022 also fixed cases where arrays e.g. enumerated valType turned into objects!
Before:

   "values": {
    "0": "forward",
    "1": "reverse"
   }

After

   "values": [
    "forward",
    "reverse"
   ]

sortObject(v) :
newObj[key] = v;
}

return newObj;
}

module.exports = sortObject;
1 change: 1 addition & 0 deletions tasks/util/watchified_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = function makeWatchifiedBundle(onFirstBundleCallback) {
var b = browserify(constants.pathToPlotlyIndex, {
debug: true,
standalone: 'Plotly',
ignoreTransform: './tasks/compress_attributes.js',
transform: [],
cache: {},
packageCache: {},
Expand Down
Loading