                 $(".chart,.zoom_slider,.legend", @$result.parent()).show()
                 $(".time_table", @$result.parent()).hide()
                 if val == "bar"
-                    if $(".legend .line", @$result).length > 1
-                        $(".legend li:last:not(.disabled) .action", @$result).click()
-                        if (_.all _.map $(".legend .line", @$result), (item) -> $(item).is(".disabled"))
-                            $(".legend li:first .action", @$result).click()
+                    @setBarMode()
+                    # if $(".legend .line", @$result).length > 1
+                    #     $(".legend li:last:not(.disabled) .action", @$result).click()
+                    #     if (_.all _.map $(".legend .line", @$result), (item) -> $(item).is(".disabled"))
+                    #         $(".legend li:first .action", @$result).click()
                 else if val == "table"
-                    $(".chart,.zoom_slider,.legend", @$result).hide()
-                    $(".time_table", @$result.parent()).show()
-                    nRows = series.length or 2
-                    h = (nRows * 2) + 4
-                    h = Math.min h, 40
-                    $(".time_table:visible", @$result).height "#{h}.1em"
-                    @time_grid?.resizeCanvas()
-                    $(".exportTimeStatsSection", @$result).show()
-
-                    setExportUrl = () ->
-                        selVal = $(".timeKindOfData option:selected", @$result).val()
-                        selType = $(".timeKindOfFormat option:selected", @$result).val()
-                        dataDelimiter = if selType is "TSV" then "%09" else ";"
-
-                        header = [ util.getLocaleString("stats_hit") ]
-
-                        for cell in series[0].data
-                            header.push moment(cell.x * 1000).format("YYYY")
-
-                        output = [header]
-
-                        for row in series
-                            cells = [ if row.name is "&Sigma;" then "Σ" else row.name ]
-                            for cell in row.data
-                                if selVal is "relative"
-                                    cells.push cell.y
-                                else
-                                    i = _.indexOf (_.pluck row.abs_data, "x"), cell.x, true
-                                    cells.push row.abs_data[i].y
-                            output.push cells
-
-                        csv = new CSV(output, {
-                            header : header
-                            delimiter : dataDelimiter
-                            # line : escape(String.fromCharCode(0x0D) + String.fromCharCode(0x0A))
-                        })
-                        csvstr = csv.encode()
-                        blob = new Blob([csvstr], { type: "text/#{selType}"})
-                        csvUrl = URL.createObjectURL(blob)
-                        $(".exportTimeStatsSection .btn.export", @$result).attr({
-                            download : "export.#{selType}"
-                            href : csvUrl
-                        })
-
-                    setExportUrl()
+                    @setTableMode(series)
+                    @renderTable(series)
 
                     # $(".timeExportButton", @$result).unbind "click"
                     # $(".timeExportButton", @$result).click =>

        return
    setLineMode : () ->

    setTableMode : () ->

    makeRequest : (cqp, subcqps, corpora, labelMapping, showTotal) ->
        c.log "makeRequest", cqp, subcqps, corpora, labelMapping, showTotal

                    graph.render()
                    $(".exportTimeStatsSection", @$result).hide()

            

            # $(".smoothing_label .ui-button-text", @$result.parent()).localeKey("smoothing")
            # $(".form_switch .ui-button:first .ui-button-text", @$result).localeKey("line")
            # $(".form_switch .ui-button:eq(1) .ui-button-text", @$result).localeKey("bar")
