// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \example stackedbarchartdrilldown
    \title StackedBarChart Drilldown Example
    \ingroup qtcharts_examples

    \brief The example shows how to implement drilldown using a stacked barchart.

    In the drilldown example we create a stacked bar chart, which shows the harvest of various chili
    peppers during season. In season view the harvest is grouped by month. To drill down to weekly
    view, right-click the selected month. On weekly view, the harvest of the month clicked is shown
    by week.

    The season view looks like this:
    \image examples_stackedbarchartdrilldown1.png

    Clicking on a month shows that month's harvest:
    \image examples_stackedbarchartdrilldown2.png

    \include examples-run.qdocinc

    \section1 Implementing Drilldown

    First we define a drilldown series class, which adds categories to the stacked bar series and mapping for categories to other drilldown series.
    The purpose of the drilldown series is to contain knowledge of the drilldown structure. The mapDrilldownSeries function maps the category to a given series. We can request the mapping for a category with the drilldownSeries(int category) function.

    \snippet stackedbarchartdrilldown/drilldownseries.h 1

    Next we define our own drilldown chart, which implements the handler for the mouse click. All QBarSeries derived classes send out the clicked(QBarSet*, int) signal when a series is clicked with the mouse. The parameter QBarSet contains the pointer to the clicked bar set and parameter int contains the index of the clicked category.

    \snippet stackedbarchartdrilldown/drilldownchart.h 1

    Now we have our drilldown classes and we can start using them.
    First create the chart.

    \snippet stackedbarchartdrilldown/main.cpp 1

    We define the categories from which the drilldown series will be constructed.

    \snippet stackedbarchartdrilldown/main.cpp 2

    To create the drilldown structure, we first create our top level series, which we call seasonSeries. For each month in seasonSeries we create a drilldown series called weeklySeries which contains more detailed data for that month.
    In weeklySeries, we use the drilldown handler to bring us back to seasonSeries. To do so we add mapping to the series. The seasonSeries is mapped to weeklySeries for each month. Every weeklySeries is mapped back to the seasonSeries.
    To make mapping work, we connect the clicked signals from our series to the drilldownChart.

    \snippet stackedbarchartdrilldown/main.cpp 3

    When we have our drilldown structure ready, we can add the data to it. Here we generate a random crop for each plant in each week. The monthly crop is calculated from weekly crops and is set as value to the monthly series.

    \snippet stackedbarchartdrilldown/main.cpp 4

    Here we set the chart to show the top level series initially.

    \snippet stackedbarchartdrilldown/main.cpp 5
*/
