<commit_before>import Chart from './chart'
import Query from '../data/query'
import { DashboardItemMetadata } from './item'
import * as charts from '../../charts'
import { extend } from '../../util'
import { PropertyList } from '../../core/property'

declare var $, d3, ts

export default class SinglegraphGrid extends Chart {
  static meta: DashboardItemMetadata = {
    icon: 'fa fa-image',
    category: 'chart',
    requires_data: true
  }

  format: string = ',.1s'
  transform: string = 'mean'
  columns: number = 4

  constructor(data?: any) {
    super(data)
    if (data) {
      this.format = data.format || this.format
      this.transform = data.transform || this.transform
      this.columns = data.columns || this.columns
    }
    if (!this.height)
      this.height = 1
  }

  toJSON() : any {
    return extend(super.toJSON(), {
      format: this.format,
      transform: this.transform,
      columns: this.columns
    })
  }

  data_handler(query: Query) : void {
    if (!query.data)
      return
    let span   = 12 / this.columns
    let format = d3.format(this.format)
    let flot   = <charts.FlotChartRenderer>charts.renderers.get('flot')
    let holder = $(`#${this.item_id} .ds-singlegraph-grid-holder`)
    let options = {
      colors: charts.get_palette(this.options.palette)
    }
    holder.empty()
    query.data.forEach((series, i) => {
      let value = series.summation[this.transform]
      holder.append(ts.templates.models.singlegraph_grid_item({
        item: this,
        index: i,
        colspan: span,
        value: format(value),
        label: series.target
      }))
      flot.sparkline(`#${this.item_id}-${i} .ds-graph-holder`, this, query, i, options)
    })
  }

  interactive_properties(): PropertyList {
    return super.interactive_properties().concat([
      'format', 'transform',
      {
        name: 'columns',
        edit_options: {
          type: 'select',
          source: [ 1, 2, 3, 4, 6, 12 ]
        }
      },

    ])
  }
}<commit_msg>Issue 548: Apply hide_zero_series to singlegraph grids<commit_after>import Chart from './chart'
import Query from '../data/query'
import { DashboardItemMetadata } from './item'
import * as charts from '../../charts'
import { extend } from '../../util'
import { PropertyList } from '../../core/property'

declare var $, d3, ts

export default class SinglegraphGrid extends Chart {
  static meta: DashboardItemMetadata = {
    icon: 'fa fa-image',
    category: 'chart',
    requires_data: true
  }

  format: string = ',.1s'
  transform: string = 'mean'
  columns: number = 4

  constructor(data?: any) {
    super(data)
    if (data) {
      this.format = data.format || this.format
      this.transform = data.transform || this.transform
      this.columns = data.columns || this.columns
    }
    if (!this.height)
      this.height = 1
  }

  toJSON() : any {
    return extend(super.toJSON(), {
      format: this.format,
      transform: this.transform,
      columns: this.columns
    })
  }

  data_handler(query: Query) : void {
    if (!query.data)
      return
    let span   = 12 / this.columns
    let format = d3.format(this.format)
    let flot   = <charts.FlotChartRenderer>charts.renderers.get('flot')
    let holder = $(`#${this.item_id} .ds-singlegraph-grid-holder`)
    let options = {
      colors: charts.get_palette(this.options.palette)
    }
    holder.empty()
    query.data.forEach((series, i) => {
      let value = series.summation[this.transform]
      if (!(series.summation.sum === 0 && this.hide_zero_series)) {
        holder.append(ts.templates.models.singlegraph_grid_item({
          item: this,
          index: i,
          colspan: span,
          value: format(value),
          label: series.target
        }))
        flot.sparkline(`#${this.item_id}-${i} .ds-graph-holder`, this, query, i, options)
      }
    })
  }

  interactive_properties(): PropertyList {
    return super.interactive_properties().concat([
      'format', 'transform',
      {
        name: 'columns',
        edit_options: {
          type: 'select',
          source: [ 1, 2, 3, 4, 6, 12 ]
        }
      },

    ])
  }
}
{'fraction_non_alphanumeric': 0.14468290330359296, 'fraction_numerical': 0.007716421509524958, 'mean_word_length': 2.4224422442244222, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7484346', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1287, 'n_words': 304}