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

Pie chart #84

Closed
3 of 4 tasks
markov00 opened this issue Feb 28, 2019 · 15 comments · Fixed by #493
Closed
3 of 4 tasks

Pie chart #84

markov00 opened this issue Feb 28, 2019 · 15 comments · Fixed by #493
Assignees
Labels
enhancement New feature or request kibana cross issue Has a Kibana issue counterpart :new chart type New chart type related feature request released Issue released publicly

Comments

@markov00
Copy link
Member

markov00 commented Feb 28, 2019

Is your feature request related to a problem? Please describe.
It's required to draw piechart and donut chart, with one or multiple levels.

Describe the solution you'd like

  • Reuse as much as possible the code already implemented for XY axis
  • Use the same Chart structure but different specs for chart PieChartSeries

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Rendering a piechart is not so difficult, we can just use d3-arcs to compute the paths.

import { arc, pie } from 'd3-shape';

const pieSpec = {
  data: [[10],[20], [30]],
  accessor: 0,
}

const paths = pie().value((d: any) => {
  return d[pieSpec.accessor];
})(pieSpec.data);

// that is the space allowed to render the pie chart we should take in consideration the 
// how much space a direct labelling on the chart take
const { width, height } = chartDimensions; 
const outerRadius = width < height ? width / 2 : height / 2;
const innerRadius = pieSpec.donut ? outerRadius / 2 : 0;

const arcGenerator = arc();
const arcs = paths.map((path) => {
  const arc = arcGenerator({
    ...path,
    innerRadius: innerRadius,
    outerRadius: outerRadius,
  });
  return {
    arc: arc === null ? '' : arc,
    color: 'red',
    transform: {
      x: width / 2,
      y: height / 2,
    },
    geometryId: {
      specId: pieSpec.id,
      seriesKey: [],
    },
    seriesArcStyle: settings.theme.arcSeriesStyle.arc,
  };
});

The difficult part is the label positioning, place labels to avoid overlaps and overflows.
The pre-computing label dimensions will came in handy, but we need a good alghoritm to place them without overlapping them together.

We have to take in consideration also the style of the slices, specially when we will have many small slices.

Consider also label rotations as described here: https://www.amcharts.com/docs/v4/tutorials/labels-inside-pie-chart-slices/

Other interesting references:

Features:

Kibana Cross Issues

Checklist

  • this request is checked against already exist requests
  • every related Kibana issue is listed under Kibana Cross Issues list
  • kibana cross issue tag is associated to the issue if any kibana cross issue is present
@markov00 markov00 added enhancement New feature or request kibana cross issue Has a Kibana issue counterpart labels Feb 28, 2019
@markov00 markov00 mentioned this issue Feb 28, 2019
93 tasks
@markov00 markov00 added this to the 7.2 milestone Feb 28, 2019
@markov00 markov00 added the :new chart type New chart type related feature request label Feb 28, 2019
@markov00 markov00 changed the title [new-chart] Pie chart Pie chart Feb 28, 2019
@markov00 markov00 assigned monfera and unassigned monfera Jul 31, 2019
@monfera monfera self-assigned this Sep 9, 2019
@shahzad31
Copy link
Contributor

Is there any update on this?

@markov00
Copy link
Member Author

@monfera is currently working on this. Robert do you want to add some examples of the current status. I first need to merge a quite big refactoring of the library (it can be probably done in two weeks max) and than we can introduce the first version of the pie chart.

@monfera
Copy link
Contributor

monfera commented Sep 16, 2019

@shahzad31 we have most of the code; tests and improvements are being added as we speak
image

@shahzad31
Copy link
Contributor

Example looks great , thanks @monfera .. Are we close on this?

cc @justinkambic @andrewvc

@monfera
Copy link
Contributor

monfera commented Oct 1, 2019

@shahzad31 Thanks! The main elastic-charts branch is still undergoing major refactoring, the plan is for the integration to start next week and likely it'll take a couple of weeks of non-fulltime work (I'm off next week, then some Elastic{ON} days), so we're looking at late October, I'll reach out to you once it can be test driven, maybe a tad earlier

@justinkambic
Copy link

@monfera per your advice we're implementing a basic donut in D3, and then when y'all ship this we will migrate to it. Our chart is literally the simplest use case for a pie chart, so it should be a very easy transition.

@nickofthyme
Copy link
Collaborator

I saw this today and wanted to make a note of it for the future. I like the idea of the center value retaining the previously selected slice. That way you can easily drill into AND out.

0ac5d1e-graph

@monfera
Copy link
Contributor

monfera commented Oct 4, 2019

@nickofthyme good reference, I think it also came up on the 1st call where the issue of small slices on sunbursts came up, one reason for the color sharing between rings here 😄 There's a stale branch I'll try to brush up and merge for folks to experiment with

image

@markov00
Copy link
Member Author

🎉 This issue has been resolved in version 16.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Jan 21, 2020
@businessK8T
Copy link

hello @markov00 ... a year later ... how does one find out what version of kibana the fix is present in? the "resolved in version 16.2.0" doesn't jibe w/kibana's version number levels (6.8/7.1/etc) sorry to ask an old and annoying question...

@monfera
Copy link
Contributor

monfera commented Mar 9, 2021

Best place to look is package.json in Kibana, ie. here and this same file has the Kibana version on top (eg. the linked version in master shows the unreleased 8.0). So, best to go to the release tag in elastic/kibana you want, and see the package file. Btw. it's been in Kibana for a long while

@businessK8T
Copy link

fingers crossed "long time" covers how "old" my kibana is ... not by choice ... also, thanks a million for the answer!

@markov00
Copy link
Member Author

@businessK8T are you looking for a particular issue/bug in kibana for the piecharts? if so can you link it here?
This Piechart is currently used in Lens, and for 7.13 probably (if we have time) we will also release the migration of the existing Visualize Pie chart code with this implementation

@businessK8T
Copy link

businessK8T commented Mar 15, 2021

at least on the surface this / a very similar pie-chart-missing-labels github "thing" (elastic/kibana#16746) matches the "performance variance" we're seeing ATM. h i'm looking through all the different package.json files b/c apparently there's more than one ;)
.. planning on updating the application of which ELK is just a part of the whole this week so hopefully the "performance variance" will go away.

@markov00
Copy link
Member Author

@businessK8T this is the Kibana PR to follow for the Kibana migration to the new charting library: elastic/kibana#83929
If you are ok, we can also suggest a better representation for your data instead of a pie chart if you can describe your current use case, piechart are not always the best way to visualize data, in particular, if you are looking to compare slices side by side with precision, or if you have more then 3/5 very similar slices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request kibana cross issue Has a Kibana issue counterpart :new chart type New chart type related feature request released Issue released publicly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants