-
Notifications
You must be signed in to change notification settings - Fork 322
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
MapChart not displayed when build with Angular #1146
Comments
Thanks for the heads up. We're looking into it. Will keep you posted. |
Hi , i have the same issue On local server the worldMap is pretty good but after ng build --prod, we can see only the background of the globe, but the countries (polygons) don't appear ... Does anyone have the solution ? |
Hey guys, we've been working hard to debug this, but it's a very tough case. It turns out that it's not actually a bug in amCharts at all, instead it's a bug with Angular. To be specific, it's a bug with this package. To workaround this, you can add "scripts": {
"build": "ng build --prod --build-optimizer=false"
}, |
Thanks , i'll try tomorrow :-)
Envoyé depuis Yahoo Mail pour Android
Le mar., mai 28, 2019 à 19:27, Pauan<notifications@github.com> a écrit :
Hey guys, we've been working hard to debug this, but it's a very tough case.
It turns out that it's not actually a bug in amCharts at all, instead it's a bug with Angular. To be specific, it's a bug with this package.
To workaround this, you can add --build-optimizer=false to your package.json, like this:
"scripts": {
"build": "ng build --prod --build-optimizer=false"
},
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
It doesn't work :( |
@Nashoba38 Could you please share your code, so we can see what the problem is? |
@Nashoba38 I just tested your code, and indeed it is broken with Try deleting your If that doesn't work, then you'll need to send us your full code, so we can find the problem. |
It still doesn't work for me :/ . I put my code on gitHub if you want to check https://github.com/Nashoba38/herpingSite/tree/EssaiProd/AngularSnakes |
@Nashoba38 I just tested that repo, and it works fine when using |
Is there an corressponding Github issue at https://github.com/angular/angular-cli/issues ? |
I'll start by saying I really love amcharts v4. Gorgeous and easy to work with 👍 That being said...Turning off the build optimizer is not a valid solution for most production applications. I see that this has been closed as 'solved' but I'm not sure we've seen any proof this is actually a build optimizer issue. @Pauan have we actually seen that the build optimizer is mangling data or something? If not, it seems there is likely more digging to be done? (and if it has been seen, please update us so that someone can open the issue in the appropriate repo as @Knacktus pointed out) |
If it is a bug in Angular, did AMChart open an issue in Angular? If yes, can we track the issue? |
I am experiencing this same problem and like @benjamincharity said, turning off the build optimizer is not a valid solution for our project. Any news? Thx |
Hello, we cannot disable build-optimizer too. Please fix this bug, in another case, we will be forced to stop using your package and require money back. |
@piotrgolawski As we have explained, the bug is not in our code, the bug is with Angular. The bug in Angular affects many packages, not just amCharts. We cannot fix Angular bugs. So you will need to ask Angular to fix their bug. |
So please, if you have such knowledge, tell me where the bug is and what it
is about.
czw., 29 sie 2019, 18:23 użytkownik Pauan <notifications@github.com>
napisał:
… @piotrgolawski <https://github.com/piotrgolawski> As we have explained,
the bug is not in our code, the bug is with Angular. The bug in Angular
affects many packages, not just amCharts. We cannot fix Angular bugs. So
you will need to ask Angular to fix *their* bug.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1146?email_source=notifications&email_token=ADMDADYA4GOAW6RWSMUHKDTQG7ZYFA5CNFSM4HDQXIJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5PBVNY#issuecomment-526260919>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADMDAD4XCGN4H5LLAOWJ5BDQG7ZYFANCNFSM4HDQXIJA>
.
|
@piotrgolawski There isn't a bug report specifically for amCharts, because it's very difficult to reproduce (it happens because the There are several bugs already open for the build optimizer: And this is the Angular team's opinion on the build optimizer breaking code: angular/angular-cli#11439 (comment) There's a reason I'm curious: you claim that you cannot disable build-optimizer, what are the file sizes of your project with |
If it is not a bug in amCharts, so how your previous version is working well https://github.com/amcharts/amcharts3-angular2 ? It is about importing? We are using webpack. |
@piotrgolawski amCharts V3 doesn't use classes (it is vanilla JS), whereas V4 uses classes a lot (it uses TypeScript). The issue with the build optimizer is specifically with classes. In addition, V3 is not processed by Angular or Webpack, it is loaded with You haven't answered my question about file sizes, but assuming that there really is a huge difference, you can use the |
This is great information. Thank you for that. As far as build size, I can only speak for the place I am currently. But I’m on a team that manages our components and libraries, while the applications themselves are built by other teams. So it’s not a choice I can actually make. Thanks again for the great responses. |
Just noticed that this issue isn't happening with amcharts version 4.2.6 with the same version of builder optimiser. |
@aggiustino That's because in version 4.3.0 we started using d3-geo, which significantly improved the functionality of maps. |
Thank you @aggiustino, Unfortunately, I had to downgrade to @Pauan so amchart have issues for angular after upgrading to d3-geo, or any solution it may work |
@Pauan is there any plan for fixing this issue? |
@ha-akelius d3-geo is important for the functionality of the maps, so until Angular fixes their bugs, you will have to disable the build optimizer by using @aggiustino Angular has made it clear that they don't care if their build optimizer is buggy and breaks third-party libraries, so I doubt they will fix it anytime soon. |
yes, it doesn't work. |
I also struggled with this problem and found a solution (tested with Angular 8): Update your angular.json to use a modified config for webpack (replace builder and add customWebPackConfig to options): "builder": "@angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {
"path": "./custom-webpack.config.js",
"replaceDuplicatePlugins": true
}
} Create a custom-webpack.config.js. // ./custom-webpack.config.js
module.exports = (config, options) => {
config.optimization.minimizer.filter(({constructor: {name}}) => name === 'TerserPlugin')
.forEach(terser => {
Object.assign(terser.options.terserOptions, {
compress: {
global_defs: {ngDevMode: false, ngI18nClosureMode: false},
},
});
});
return config;
}; |
Mine is even not working on local server. Used the exact same code from this link, except that I placed the demo data to MongoDB, fetch them inside import {
Component,
NgZone,
OnInit,
AfterViewInit,
OnDestroy,
} from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators';
import * as socketio from 'socket.io-client';
import * as m4Core from '@amcharts/amcharts4/core';
import * as m4Maps from '@amcharts/amcharts4/maps';
import AnimatedTheme from '@amcharts/amcharts4/themes/animated';
import WORLD_MAP from '@amcharts/amcharts4-geodata/worldLow';
import { environment } from '../../environments/environment';
m4Core.useTheme(AnimatedTheme);
@Component({
selector: 'app-map',
templateUrl: './map.component.html',
styleUrls: ['./map.component.scss'],
})
export class MapComponent implements OnInit, AfterViewInit, OnDestroy {
private readonly URI = environment.api.uri + environment.api.endpoints.map;
private readonly socket = socketio(environment.socket);
private chart: m4Maps.MapChart;
constructor(
private readonly zone: NgZone,
private readonly http: HttpClient
) {}
private animateBullet(circle) {
const animation = circle.animate(
[
{ property: 'scale', from: 1, to: 5 },
{ property: 'opacity', from: 1, to: 0 },
],
1000,
m4Core.ease.circleOut
);
animation.events.on('animationended', (event) => {
this.animateBullet(event.target.object);
});
}
ngOnInit() {
// add data
const colorSet = new m4Core.ColorSet();
this.http
.get<{ statusCode: number; body: string }>(this.URI)
.pipe(
map((resp) => {
const { body } = resp;
const array = JSON.parse(body);
const data = array.map((each) => ({
title: each.name,
latitude: each.latitude,
longitude: each.longitude,
color: colorSet.next(),
}));
return data;
})
)
.subscribe((data) => {
this.chart.data = data;
});
// listen for changes
this.socket.on('map-replace', (change) => {
const temp = this.chart.data;
const index = temp.findIndex(
(each) =>
each.latitude === change.updatedDocument.latitude &&
each.longitude === change.updatedDocument.longitude
);
temp[index].title = change.updatedDocument.name;
this.chart.data = temp;
});
}
ngAfterViewInit() {
this.zone.runOutsideAngular(() => {
// Create map instance
const mapChart = m4Core.create('map', m4Maps.MapChart);
// Set map definition
mapChart.geodata = WORLD_MAP;
// Set projection
mapChart.projection = new m4Maps.projections.Miller();
// Create map polygon series
const pgSeries = mapChart.series.push(new m4Maps.MapPolygonSeries());
// Exclude Antartica
pgSeries.exclude = ['AQ'];
// Make map load polygon (like country names) data from GeoJSON
pgSeries.useGeodata = true;
// Configure series
const pgTemplate = pgSeries.mapPolygons.template;
pgTemplate.tooltipText = '{name}';
pgTemplate.polygon.fillOpacity = 0.6;
// Create hover state and set alternative fill color
const hs = pgTemplate.states.create('hover');
hs.properties.fill = mapChart.colors.getIndex(0);
// Add image series
const imgSeries = mapChart.series.push(new m4Maps.MapImageSeries());
imgSeries.mapImages.template.propertyFields.longitude = 'longitude';
imgSeries.mapImages.template.propertyFields.latitude = 'latitude';
imgSeries.mapImages.template.tooltipText = '{title}';
imgSeries.mapImages.template.propertyFields.url = 'url';
const circle1 = imgSeries.mapImages.template.createChild(m4Core.Circle);
circle1.radius = 3;
circle1.propertyFields.fill = 'color';
const circle2 = imgSeries.mapImages.template.createChild(m4Core.Circle);
circle2.radius = 3;
circle2.propertyFields.fill = 'color';
circle2.events.on('inited', (event) => {
this.animateBullet(event.target);
});
this.chart = mapChart;
});
}
ngOnDestroy() {
this.zone.runOutsideAngular(() => {
if (this.chart) {
this.chart.dispose();
}
});
}
} |
It worked for me, try doing the same for postinstall as well
|
Is this build-optimizer still an issue with the latest versions of angular? I was scratching my head when I saw the amcharts documentation for angular read: I don't have much experience with Angular 2+, but if the production file size has the chance of being significantly impacted by setting `--build-optimizer=false", this could be very important. What are the viable workarounds? |
I am running
with the same problems, no map displayed. Turning off build optimization increases my build size by 2mb, so very significant for me, about (75%). This seems like a really poor solution. I have a simple app here, but other applications that are much larger, if I turn off optimization there, the consequences would be unacceptable. Would love it if there was a specific issue filed in the optimizer github if there really is a problem there. Has anyone found a better solution? |
@wallace41290 Have you tried the lazy loading approach, and does that bypass the need to set "Lazy loading amCharts |
@mg1075 Just tried it, some problem, no chart on prod build |
ng build --prod --build-optimizer=false Worked for me as well. |
Maybe I am misunderstanding, but I can build it with build-optimizer set to false. But that is not an acceptable solution and I would be forced to use a different charting library. I work in very large enterprise applications, and the build size and performance cost is too great to just turn the build optimizer off. |
We recently faced this issue (still an issue). As the officially recommended solution is not an option, because our app size is already too large we solved it by lazy loading amcharts AND explicitly separating amchart scripts using webpack magic comments. Not exactly what we use but. it may give you an idea:
This will generate a separate chunk called For a detailed explanation read this article on Angular: Dynamically immporting large libraries |
It leads to amcharts not showing map (amcharts/amcharts4#1146)
ng build --prod --build-optimizer=false |
We had this issue, and it was driving us nuts. We worked around it by lazy loading the amchart stuff where maps were needed and then referencing like this to keep the TypeScript logic intact: private am4maps: typeof import("@amcharts/amcharts4/maps");
We then call the underlying loaded as per: private createChart(id: string, options: MapChartOptions) {
Not pretty, but better than disabling the optimizer. //A |
Worked for me!!! |
I have an issue when deploying an angular app using the latest amcharts version (4.3.5).
If I use
ng serve
to test my app it woks without any problems:If I build my app using
ng build --prod
and deploy it, e.g. with an nginx the MapCharts are not displayed:All other charts are working perfectly.
Using version 4.2.6 the MapCharts are working.
I uploaded my code to this repository.
The text was updated successfully, but these errors were encountered: