[
    {
        "type": "charts",
        "icon": "line-chart",
        "group": "booking",
        "title": "ADMIN_DASHBOARD.CHARTS.TITLES.BOOKINGS_BY_DAY",
        "code": "bookings_by_day",
        "panel": "google_chart_box",
        "config": {
            "source": "booking",
            "agg": {
                "filter": {
                    "range": {
                        "datetime": {
                            "gte": "$ctrlChart.chart.start_date",
                            "lte": "$ctrlChart.chart.end_date"
                        }
                    }
                },
                "aggs": {
                    "chart": {
                        "date_histogram": {
                            "field": "datetime",
                            "interval": "$ctrlChart.chart.interval",
                            "format": "$ctrlChart.chart.title_format"
                        }
                    }
                }
            },
            "form_schema": {
                "start_date":  {
                    "title": "Start Date",
                    "type": "relativedate",
                    "default": "now-7d"
                },
                "end_date":  {
                    "title": "End Date",
                    "type": "relativedate",
                    "default": "now"
                },
                "interval":  {
                    "title": "Interval",
                    "type": "select",
                    "titleMap": {
                        "month": "Month",
                        "week": "Week",
                        "day": "Day"
                    },
                    "default": "day"
                },
                "title_format":  {
                    "title": "Title Format",
                    "type": "string",
                    "default": "d MMM EEE Y"
                }
            },
            "series": ["Bookings"],
            "title": "Appointments by Day",
            "type": "AreaChart",
            "options": {
                "backgroundColor":{"strokeWidth": 1},
                "chartArea":{"width":"80%","height":"75%"},
                "colors": ["#3171B4"],
                "hAxis.baselineColor": "#FAFBFB",
                "hAxis": {
                    "gridlines": {"color": "#FAFBFB"},
                    "textStyle": {"fontSize": 8}
                }
            }
        }
    },
    {
        "type": "charts",
        "group": "booking",
        "title": "ADMIN_DASHBOARD.CHARTS.TITLES.BOOKINGS_BY_LOCATION",
        "code": "bookings_by_location",
        "panel": "google_chart_box",
        "config": {
            "source": "booking",
            "agg": {
                "filter": {
                    "range": {
                        "datetime": {
                            "gte": "$ctrlChart.chart.start_date",
                            "lte": "$ctrlChart.chart.end_date"
                        }
                    }
                },
                "aggs": {
                    "chart": {
                        "date_histogram": {
                            "field": "datetime",
                            "interval": "$ctrlChart.chart.interval",
                            "format": "$ctrlChart.chart.title_format"
                        }
                    }
                }
            },
            "series": ["Bookings"],
            "title": "Bookings by Location",
            "type": "BarChart",
            "options": {}
        }
    },
    {
        "type": "charts",
        "icon": "line-chart",
        "group": "booking",
        "title": "ADMIN_DASHBOARD.CHARTS.TITLES.BOOKINGS_BY_ACTIVITY_DATE",
        "code": "bookings_by_activity_date",
        "panel": "google_chart_box",
        "config": {
            "source": "booking",
            "agg": {
                "filter": {
                    "range": {
                        "datetime": {
                            "gte": "$ctrlChart.chart.start_date",
                            "lte": "$ctrlChart.chart.end_date"
                        }
                    }
                },
                "aggs": {
                    "chart": {
                        "date_histogram": {
                            "field": "datetime",
                            "interval": "$ctrlChart.chart.interval",
                            "format": "$ctrlChart.chart.title_format"
                        }
                    }
                }
            },
            "form_schema": {
                "start_date":  {
                    "title": "Start Date",
                    "type": "relativedate",
                    "default": "now-3M"
                },
                "end_date":  {
                    "title": "End Date",
                    "type": "relativedate",
                    "default": "now+3M"
                },
                "interval":  {
                    "title": "Interval",
                    "type": "select",
                    "titleMap": {
                        "month": "Month",
                        "week": "Week",
                        "day": "Day"
                    },
                    "default": "day"
                },
                "title_format":  {
                    "title": "Title Format",
                    "type": "string",
                    "default": "dd-MM-YYY"
                }
            },
            "series": ["Bookings"],
            "title": "Appointments by Day",
            "type": "Line",
            "options": {}
        }
    },
    {
        "type": "charts",
        "icon": "line-chart",
        "group": "booking",
        "title": "ADMIN_DASHBOARD.CHARTS.TITLES.BOOKINGS_BY_CREATED_DATE",
        "code": "bookings_by_created_date",
        "panel": "google_chart_box",
        "config": {
            "source": "booking",
            "agg": {
                "filter": {
                    "range": {
                        "created_at": {
                            "gte": "$ctrlChart.chart.start_date",
                            "lte": "$ctrlChart.chart.end_date"
                        }
                    }
                },
                "aggs": {
                    "chart": {
                        "date_histogram": {
                            "field": "created_at",
                            "interval": "$ctrlChart.chart.interval",
                            "format": "$ctrlChart.chart.title_format"
                        }
                    }
                }
            },
            "form_schema": {
                "start_date":  {
                    "title": "Start Date",
                    "type": "relativedate",
                    "default": "now-3M"
                },
                "end_date":  {
                    "title": "End Date",
                    "type": "relativedate",
                    "default": "now"
                },
                "interval":  {
                    "title": "Interval",
                    "type": "select",
                    "titleMap": {
                        "month": "Month",
                        "week": "Week",
                        "day": "Day"
                    },
                    "default": "day"
                },
                "title_format":  {
                    "title": "Title Format",
                    "type": "string",
                    "default": "dd-MM-YYY"
                }
            },
            "series": ["Bookings"],
            "title": "Appointments by Day",
            "type": "Line",
            "options": {}
        }
    },
     {
        "type": "charts",
        "icon": "bar-chart",
        "group": "booking",
        "title": "ADMIN_DASHBOARD.CHARTS.TITLES.BOOKINGS_BY_SERVICE",
        "code": "bookings_by_service_summary",
        "panel": "google_chart_box",
        "config": {
            "source": "booking",
            "agg": {
                "terms" : {
                    "field" : "service_global_id"
                }
            },
            "form_schema": {
                "start_date":  {
                    "title": "Start Date",
                    "type": "relativedate",
                    "default": "now-3M"
                },
                "end_date":  {
                    "title": "End Date",
                    "type": "relativedate",
                    "default": "now"
                },
                "interval":  {
                    "title": "Interval",
                    "type": "select",
                    "titleMap": {
                        "month": "Month",
                        "week": "Week",
                        "day": "Day"
                    },
                    "default": "day"
                },
                "title_format":  {
                    "title": "Title Format",
                    "type": "string",
                    "default": "dd-MM-YYY"
                }
            },

            "title": "Bookings by Service",
            "type": "BarChart",
            "options": {
                "animation": {"duration": 500, "startup": true},
                "colors": ["#19436D", "#3171B4", "#4998E0"],
                "legend": {"position": "none"}
            }
        }
    },

    {
        "type": "charts",
        "icon": "bar-chart",
        "group": "booking",
        "title": "ADMIN_DASHBOARD.CHARTS.TITLES.BOOKINGS_BY_CHANNEL",
        "code": "bookings_by_channel",
        "panel": "google_chart_box",
        "config": {
            "source": "booking",
            "agg": {
                "terms" : {
                    "field" : "channel.keyword"
                }
            },
            "title": "Bookings by channel",
            "type": "PieChart",
            "options": {
                "colors": ["#19436D", "#CB0037", "#4998E0"],
                "pieHole": 0.3,
                "sliceVisibilityThreshold": 0
            }
        }
    },
     {
        "type": "charts",
        "icon": "bar-chart",
        "group": "booking",
        "title": "ADMIN_DASHBOARD.CHARTS.TITLES.OUTCOMES",
        "code": "outcomes",
        "panel": "google_chart_box",
        "config": {
            "source": "booking",
            "agg": {
                "terms" : {
                    "field" : "outcomes"
                }
            },
            "form_schema": {
                "start_date":  {
                    "title": "Start Date",
                    "type": "relativedate",
                    "default": "now-3M"
                },
                "end_date":  {
                    "title": "End Date",
                    "type": "relativedate",
                    "default": "now"
                },
                "interval":  {
                    "title": "Interval",
                    "type": "select",
                    "titleMap": {
                        "month": "Month",
                        "week": "Week",
                        "day": "Day"
                    },
                    "default": "day"
                },
                "title_format":  {
                    "title": "Title Format",
                    "type": "string",
                    "default": "dd-MM-YYY"
                }
            },

            "title": "Outcomes",
            "type": "BarChart",
            "options": {
                "animation": {"duration": 500, "startup": true},
                "colors": ["#19436D", "#3171B4", "#4998E0"],
                "legend": {"position": "none"}
            }
        }
    },

     {
        "type": "charts",
        "icon": "bar-chart",
        "group": "booking",
        "title": "ADMIN_DASHBOARD.CHARTS.TITLES.BOOKINGS_STATUS",
        "code": "bookings_status",
        "panel": "google_chart_box",
        "config": {
            "source": "booking",
            "agg": {
                "terms" : {
                    "field" : "current_status.keyword"
                }
            },
            "form_schema": {
                "start_date":  {
                    "title": "Start Date",
                    "type": "relativedate",
                    "default": "now-3M"
                },
                "end_date":  {
                    "title": "End Date",
                    "type": "relativedate",
                    "default": "now"
                },
                "interval":  {
                    "title": "Interval",
                    "type": "select",
                    "titleMap": {
                        "month": "Month",
                        "week": "Week",
                        "day": "Day"
                    },
                    "default": "day"
                },
                "title_format":  {
                    "title": "Title Format",
                    "type": "string",
                    "default": "dd-MM-YYY"
                }
            },

            "title": "Bookings Status",
            "type": "BarChart",
            "options": {
                "animation": {"duration": 500, "startup": true},
                "colors": ["#19436D", "#3171B4", "#4998E0"],
                "legend": {"position": "none"}
            }
        }
    },


     {
        "type": "charts",
        "icon": "bar-chart",
        "group": "booking",
        "title": "ADMIN_DASHBOARD.CHARTS.TITLES.CANCELLATION_RATES",
        "code": "cancellation_rates",
        "panel": "google_chart_box",
        "config": {
            "source": "booking",
            "aggs": {
                "my_date_histo":{
                    "date_histogram":{
                        "field":"datetime",
                        "interval":"day",
                        "format": "dd-MM-YYY"
                    }
                }
            },
            "form_schema": {
                "start_date":  {
                    "title": "Start Date",
                    "type": "relativedate",
                    "default": "now-3M"
                },
                "end_date":  {
                    "title": "End Date",
                    "type": "relativedate",
                    "default": "now"
                },
                "interval":  {
                    "title": "Interval",
                    "type": "select",
                    "titleMap": {
                        "month": "Month",
                        "week": "Week",
                        "day": "Day"
                    },
                    "default": "day"
                },
                "title_format":  {
                    "title": "Title Format",
                    "type": "string",
                    "default": "dd-MM-YYY"
                }
            },

            "title": "Cancellation Rates",
            "type": "Line",
            "options": {
                "animation": {"duration": 500, "startup": true},
                "colors": ["#19436D", "#3171B4", "#4998E0"],
                "legend": {"position": "none"}
            }
        }
    },


     {
        "type": "charts",
        "icon": "bar-chart",
        "group": "booking",
        "title": "ADMIN_DASHBOARD.CHARTS.TITLES.CANCELLATION_RATES",
        "code": "cancellation_rates_pie",
        "panel": "google_chart_box",
        "config": {
            "source": "booking",
            "agg": {
                "terms" : {
                    "field" : "is_cancelled"
                }
            },
            "form_schema": {
                "start_date":  {
                    "title": "Start Date",
                    "type": "relativedate",
                    "default": "now-3M"
                },
                "end_date":  {
                    "title": "End Date",
                    "type": "relativedate",
                    "default": "now"
                },
                "interval":  {
                    "title": "Interval",
                    "type": "select",
                    "titleMap": {
                        "month": "Month",
                        "week": "Week",
                        "day": "Day"
                    },
                    "default": "day"
                },
                "title_format":  {
                    "title": "Title Format",
                    "type": "string",
                    "default": "dd-MM-YYY"
                }
            },

            "title": "Cancellation Rate",
            "type": "PieChart",
            "options": {
                "animation": {"duration": 500, "startup": true},
                "colors": ["#19436D", "#3171B4", "#4998E0"],
                "labels": ["ADMIN_DASHBOARD.CHARTS.CANCELLATION_RATES.LABELS.NOT_CANCELLED", "ADMIN_DASHBOARD.CHARTS.CANCELLATION_RATES.LABELS.CANCELLED"]
            }
        }
    },
    {
        "type": "charts",
        "icon": "bar-chart",
        "group": "booking",
        "title": "ADMIN_DASHBOARD.CHARTS.TITLES.BOOKINGS_BY_DAY_OF_WEEK",
        "code": "bookings_by_day_of_week",
        "panel": "google_chart_box",
        "config": {
            "source": "booking",
            "agg": {
                "terms" : {
                    "field" : "day_of_week"
                }
            },
            "labels": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
            "title": "Appointments by Day",
            "type": "PieChart",
            "options": {}
        }
    },
   {
        "type": "charts",
        "icon": "bar-chart",
        "group": "booking",
        "title": "ADMIN_DASHBOARD.CHARTS.TITLES.BOOKINGS_BY_PERSON",
        "code": "bookings_by_person",
        "panel": "google_chart_box",
        "config": {
            "source": "booking",
            "agg": {
                "filter": {
                    "range": {
                        "datetime": {
                            "gte": "$ctrlChart.chart.start_date",
                            "lte": "$ctrlChart.chart.end_date"
                        }
                    }
                },
                "aggs": {
                    "chart": {
                        "filters": {
                            "filters": "$ctrlChart.buildFilterHash('people', 'chart%(index)d', '{\"term\": {\"person_id\" : %(id)d}}')"
                        },
                        "aggs": {
                            "chart": {
                                "date_histogram": {
                                    "field": "datetime",
                                    "interval": "day",
                                    "format": "dd-MM-YYY"
                                }
                            }
                        }
                    }
                }
            },
            "form_schema": {
                "start_date":  {
                    "title": "Start Date",
                    "type": "relativedate",
                    "default": "now-3M"
                },
                "end_date":  {
                    "title": "End Date",
                    "type": "relativedate",
                    "default": "now"
                }
            },
            "series": "$ctrlChart.buildFilterArray('people', '%(name)s')",
            "query": {
                "term": {
                    "company_id": "$ctrlChart.company.id"
                }
            },
            "title": "Bookings by Staff Member",
            "type": "ColumnChart",
            "filters": ["service_id"],
            "options": {
                "hAxis": {
                    "minorGridlines": {
                        "count": 3
                    }
                },
                "legend": {
                    "position": "top",
                    "maxLines": 3
                },
                "bar": {
                    "groupWidth": "75%"
                }
            }
        }
    },
    {
        "type": "charts",
        "icon": "bar-chart",
        "group": "booking",
        "title": "ADMIN_DASHBOARD.CHARTS.TITLES.BOOKINGS_BY_SERVICE",
        "code": "bookings_by_service",
        "panel": "google_chart_box",
        "config": {
            "source": "booking",
            "agg": {
                "filter": {
                    "range": {
                        "datetime": {
                            "gte": "$ctrlChart.chart.start_date",
                            "lte": "$ctrlChart.chart.end_date"
                        }
                    }
                },
                "aggs": {
                    "chart": {
                        "filters" : {
                            "filters": "$ctrlChart.buildFilterHash('services', 'chart%(index)d', '{\"term\": {\"service_id\" : %(id)d}}')"
                        },
                        "aggs": {
                            "chart": {
                                "date_histogram": {
                                    "field": "datetime",
                                    "interval": "$ctrlChart.chart.interval",
                                    "format": "$ctrlChart.chart.title_format"
                                }
                            }
                        }
                    }
                }
            },
            "form_schema": {
                "start_date":  {
                    "title": "Start Date",
                    "type": "relativedate",
                    "default": "now-6M"
                },
                "end_date":  {
                    "title": "End Date",
                    "type": "relativedate",
                    "default": "now"
                },
                "interval":  {
                    "title": "Interval",
                    "type": "select",
                    "titleMap": {
                        "month": "Month",
                        "week": "Week",
                        "day": "Day"
                    },
                    "default": "day"
                },
                "title_format":  {
                    "title": "Title Format",
                    "type": "string",
                    "default": "dd-MM-YYY"
                }
            },
            "series": "$ctrlChart.buildFilterArray('services', '%(name)s (%(duration)d)')",
            "query": {
                "term": {
                    "company_id":"$ctrlChart.company.id"
                }
           },
            "title": "Bookings by Service",
            "type": "ColumnChart",
            "filters": ["person_id"],
            "options": {
                "hAxis": {
                    "minorGridlines": {
                        "count": 3
                    }
                },
                "legend": {
                    "position": "top",
                    "maxLines": 3
                },
                "bar": {
                    "groupWidth": "75%"
                }
            }
        }
    }
]
