Skip to content
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

Info about MapChart constructor is missing in docs #128

Closed
KacperMadej opened this issue Mar 27, 2018 · 11 comments
Closed

Info about MapChart constructor is missing in docs #128

KacperMadej opened this issue Mar 27, 2018 · 11 comments

Comments

@KacperMadej
Copy link

https://github.com/highcharts/node-export-server/blame/master/README.md#L75

@KacperMadej
Copy link
Author

KacperMadej commented Apr 5, 2018

@cvasseng Looks like MapChart is not working - however, mapChart seems to work fine. I tried via console.

Additionally, adding map JS (like https://code.highcharts.com/mapdata/countries/gb/gb-all.js) in cdnAdditional breaks the server when trying to create a chart - maybe file loading order is wrong? so it's just not a good place to add a map file.

Thu Apr 05 2018 13:14:02 GMT+0200 (Central European Summer Time) [error] phantom worker 1 unexpected data - TypeError: Object is not a constructor (near '...77],[4078,7445]]}}]}/*...')

It works fine when the map file is added like:

const cdnMaps = [
    "maps/{{version}}/modules/map.js",
    "mapdata/countries/gb/gb-all.js"
];

@TorsteinHonsi
Copy link
Contributor

TorsteinHonsi commented Apr 6, 2018

MapChart is not defined, it's either chart = new Highcharts.Map(..) or chart = Highcharts.mapChart(..). When we added the lower-case-first factory functions, the name Highcharts.map was already taken, hence the inconsistency.

https://github.com/highcharts/highcharts/blob/8c1c146ab5bf0dd5bd798d997fc46b7fe75884e2/js/parts-map/Map.js#L396

@cvasseng
Copy link
Contributor

cvasseng commented Apr 6, 2018

I've updated the readme to say Map now.

About the map collection - I think we need to add prompting or something on which to include. I'm thinking maybe asking the user to supply an (optional) location for a JSON file with an array of collections to include if building with maps support. There's too many of them to prompt for each, and it needs to be compatible with automated deployments too (e.g. needs to be possible to set it via. env variables or something similar). It could also be possible to set up a highcharts object in people's package.json with an array of additional things to include, but that would only make sense for people using it as a module.

@cvasseng
Copy link
Contributor

cvasseng commented Apr 6, 2018

BTW - as a workaround for the mapcollection, you should be able to put the collection URL's in the cdnScriptsOptional map - just include a fully qualified URL.

@KacperMadej
Copy link
Author

@cvasseng
The server throws error when trying to create a chart after more than a one map is loaded. I tried loading them through cdnScriptsOptional using full URL, in cdnMaps using short and full. Files are loaded, but during worker's work the error is:

phantom worker 1 unexpected data - SyntaxError: Expected an identifier but found 'Highcharts' instead

  phantomjs://code/worker.js:629 in loop
{"filename":"1.png"}

The file name is from command used:
highcharts-export-server --infile options.json --outfile 1.png --constr mapChart

@jerang
Copy link

jerang commented Apr 9, 2018

@cvasseng please reopen this, still an issue for us. Could you please take a look?

@cvasseng cvasseng reopened this Apr 10, 2018
@KacperMadej
Copy link
Author

@jerang @cvasseng
The problem is caused by maps - the .js files are looking like Highcharts.maps["map_name"] = { ... } and there's no ; at the end, so if next map is loaded, then page breaks. As far as I could test this could be resolved by adding ; between each loaded script. It won't harm other files and will make maps work.

Required change in build.js before running npm link:

        funs.push(function (next) {
            // If we've allready fetched the required script, just return it.
            if (cachedScripts[fullURL]) {
              console.log(('   using cached fetch for ' + fullURL).gray);
              scriptBody += cachedScripts[fullURL] + ';';
              return next();
            }

            console.log('  ', (fullURL).gray);

            request(fullURL, function (error, response, body) {

                if (error) {
                  if (optionals[scriptOriginal]) {
                    console.log(`  ${script} is not available for v${version}`.gray)
                    return next();
                  }

                  return next(error, fullURL);
                }

                if (body.trim().indexOf('<!DOCTYPE') === 0) {
                  if (optionals[scriptOriginal]) {
                    console.log(`   ${script.substr(script.lastIndexOf('/') + 1)} is not available for v${version}, skipped..`.yellow);
                    return next();
                  }

                  return next(404, script);
                }

                cachedScripts[fullURL] = body;
                scriptBody += body + ';';
                next();
            });
        });

so lines change are:
scriptBody += cachedScripts[fullURL] + ';';
and
scriptBody += body + ';';

After those changes adding maps to cdnMaps works.

const cdnMaps = [
    "maps/{{version}}/modules/map.js",
    "https://code.highcharts.com/mapdata/countries/us/us-all.js",
    "https://code.highcharts.com/mapdata/countries/gb/gb-all.js",
    "https://code.highcharts.com/mapdata/custom/world.js",
    "https://code.highcharts.com/mapdata/custom/africa.js"
];

@jerang
Copy link

jerang commented Apr 24, 2018

@KacperMadej that did the trick! Thanks!!
cc @cvasseng

@cvasseng
Copy link
Contributor

cvasseng commented Aug 2, 2018

The fix for this is now live on NPM (2.0.15).

@cvasseng cvasseng closed this as completed Aug 2, 2018
@andreyfomin
Copy link

Please give example how to generate map chart png file.

@KacperMadej
Copy link
Author

The ; was added to all maps in .js format in https://github.com/highcharts/map-collection/pull/11 and was published in the current Map Collection (v1.1.4), so the workaround in 2d07efc is no longer needed.

An additional ; doesn't break anything as far as I know. To allow backwards compatibility with older Map Collections no action is required here.

I am just adding the info here in case someone has a different usage or finds a problem with doubled ;.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants