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

Highcharts/13 syncronized pies #13

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
74 changes: 41 additions & 33 deletions highcharts-api/highcharts/13-synchronized-pies/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,45 @@ const commonData = [{
{
name: 'trollfaces',
y: 15
},
];
}];

Highcharts.wrap(Highcharts.Tooltip.prototype, 'hide', function(p, delay) {
if (this === this.chart.tooltip) {
p.call(this, delay);
p.call(this.chart.customTooltip, delay);
}
})

const c = Highcharts.chart('container', {
chart: {
type: 'pie',
title: {
text: ''
}
},
plotOptions: {
pie: {
events: {
mouseOver: function() {
console.log('AWDAWD');
}
},
events: {
load() {
Copy link

Choose a reason for hiding this comment

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

Nice idea to create a custom tooltip in events.load() 👍

Small cosmetic fix, you can add spacing of the if condition.

        if (p.name === pointName) {
          p.setState('hover');
          chart.customTooltip.refresh(p);
        } else {
          p.setState('inactive');
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will fix! Forgot to run it thru jsfiddle this morning! time to get a proper linter set up ;)

const chart = this;
chart.customTooltip = new Highcharts.Tooltip(chart, Highcharts.merge(chart.options.tooltip));
chart.manualHover = (series, pointName) => {
series.points.forEach(p => {
if(p.name === pointName){
p.setState('hover');
chart.customTooltip.refresh(p);
}else{
p.setState('inactive');
}
});
};
}
}
},

series: [{
center: ['25%'],
data: commonData,
showInLegend: true,
point: {
events: {
legendItemClick: function(e) {
legendItemClick(e){
this.series.chart.series[1].data.forEach(d => {
if (d.name === this.name) {
d.update({
Expand All @@ -44,36 +56,32 @@ const c = Highcharts.chart('container', {
}
});
},
mouseOver: function(e) {
this.series.chart.series[1].data.forEach(d => {
d.name === this.name ? d.setState('hover') : d.setState('inactive');
});
},
mouseOver(e){
this.series.chart.manualHover(this.series.chart.series[1],this.name);
}
}
}
},
{
center: ['75%'],
data: commonData
data: commonData,
point: {
events: {
mouseOver(e) {
this.series.chart.manualHover(this.series.chart.series[0],this.name);
}
}
}

}
]
});

c.legend.allItems.forEach(l => { //trying to make legend behave uniformily

c.legend.allItems.forEach(l => {
l.legendItem.element.addEventListener('mouseover', () => {
c.series.forEach(ser => {
ser.points.forEach(d => {
d.name === l.name ? d.setState('hover') : d.setState('inactive');
})
});
})

c.series[1].points.forEach(d => d.name === l.name ? d.setState('hover') : d.setState('inactive'));
});
l.legendItem.element.addEventListener('mouseout', () => {
c.series.forEach(ser => {
ser.points.forEach(d => {
d.setState('normal');
})
});
c.series[1].points.forEach(d => d.setState('normal'));
});
});
});