text:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.github.tipounet</groupId>
    <artifactId>bankHollidays</artifactId>
    <packaging>jar</packaging>
    <version>1.0.0-SNAPSHOT</version>
    <name>bankHollidays</name>
    <url>https://github.com/tipounet/bankHollidays</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <guava.version>21.0</guava.version>
        <assertj.version>3.6.2</assertj.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>${guava.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>${assertj.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <scm>
        <url>https://github.com/tipounet/bankHollidays</url>
        <connection>scm:git:git://github.com/tipounet/bankHollidays.git</connection>
        <developerConnection>scm:git:git@github.com:tipounet/bankHollidays.git</developerConnection>
    </scm>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>


text:
using UnityEditor;
using UnityEngine;

namespace NaughtyAttributes.Editor
{
    [PropertyValidator(typeof(MaxValueAttribute))]
    public class MaxValuePropertyValidator : PropertyValidator
    {
        public override void ValidateProperty(SerializedProperty property)
        {
            MaxValueAttribute maxValueAttribute = PropertyUtility.GetAttribute<MaxValueAttribute>(property);

            if (property.propertyType == SerializedPropertyType.Integer)
            {
                if (property.intValue > maxValueAttribute.MaxValue)
                {
                    property.intValue = (int)maxValueAttribute.MaxValue;
                }
            }
            else if (property.propertyType == SerializedPropertyType.Float)
            {
                if (property.floatValue > maxValueAttribute.MaxValue)
                {
                    property.floatValue = maxValueAttribute.MaxValue;
                }
            }
            else
            {
                string warning = maxValueAttribute.GetType().Name + " can be used only on int or float fields";
                EditorGUILayout.HelpBox(warning, MessageType.Warning);
                Debug.LogWarning(warning, PropertyUtility.GetTargetObject(property));
            }
        }
    }
}

redpajama_set_name: RedPajamaGithub


text:
package test
import "os"
func InsertUser(data *User) {
  // TypeName          = User
  // TableName         = user
  // TableColumns      = "id", "uuid", "name"
  // NonLabeledColumns = "uuid", "name"
  // LabeledColumns    = map[auto:[id]]
  // ToFieldName       = map[uuid:Uuid name:Name id:Id]
}


text:
This plugin will make the screenshots of your static html files using phantomjs.
(make sure you have phantomjs installed on your machine)

## Install

```
npm install --save-dev gulp-local-screenshots
```

## Example

```javascript
var gulp = require('gulp');
var localScreenshots = require('gulp-local-screenshots');

gulp.task('screens', function () {
  gulp.src('./public/*.html')
  .pipe(localScreenshots({
    width: ['1600', '1000', '480', '320']
   }))
  .pipe(gulp.dest('./public/'));
});
```

## Options

#### path

Type: `String`
Default: 'public/'

Path from which the static files are served (Trailing slash at the end is required.)

#### port

Type: `Number`
Default: '8080'

Port for the static web server

#### width

Type: `Array`
Default: ['1024']

Array of page widths to make screenshots (for the responsive website)

#### height

Type: `String`
Default: '10'

Height of the page, if the actual page heights is more than that it, iamge will have actual page height.
(specifing height is good for testing)

#### type

Type: `String`
Default: 'jpg'

Output image extension

#### folder

Type: `String`
Default: 'screens'

Folder where to put images

#### timeout

Type: `Number`
Default: '200'

Timeout between files, in most cases you dont need to change that

#### protocol

Type: `String`
Default: 'http'

Protocol that will be used in phantom.js

#### host

Type: `String`
Default: 'localhost'

Host that will be used in phantom.js

#### server

Type: `Boolean`
Default: 'true'

If plugin should start local web server (otherwise you should start your web server by yourself, or specify host option for some remote server)

#### zoom

Type: `Number`
Default: '1'

Zoom level to set the phantom.js browser viewport. Can be used to take 2x, 3x, etc. screen shots. Widths, heights and output file name remain as specified, but the resulting image will be * 'zoom' pixels. E.g. specify 320 width, zoom level 2: output file will be 320px of page content, but at twice the resolution (640px wide).

#### suffix

Type: `String`
Default: 'false'

A custom suffix for output file name, you can use -thumb, -shot, etc. And the output file will named source-file-name + custom-suffix. If no suffix set, will use default suffix.

## Demo

![Demo](demo.gif)

## License

MIT © [Daniel Husar](https://github.com/danielhusar)


text:
[![Build status](https://ci.appveyor.com/api/projects/status/sfvp7dw8u6aiodj1/branch/master?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-email/branch/master)

Sends log events by SMTP email.

**Package** - [Serilog.Sinks.Email](http://nuget.org/packages/serilog.sinks.email)
| **Platforms** - .NET 4.5

```csharp
var log = new LoggerConfiguration()
    .WriteTo.Email(
        fromEmail: "app@example.com",
        toEmail: "support@example.com",
        mailServer: "smtp.example.com")
    .CreateLogger();
```

An overload accepting `EmailConnectionInfo` can be used to specify advanced options.


text:
import React, { Component, cloneElement, isValidElement, createElement } from 'react';
import classNames from 'classnames';
import _, { isArray, isBoolean, isNil } from 'lodash';
import { Surface } from '../container/Surface';
import { Layer } from '../container/Layer';
import { Tooltip } from '../component/Tooltip';
import { Legend } from '../component/Legend';
import { Curve } from '../shape/Curve';
import { Cross } from '../shape/Cross';
import { Sector } from '../shape/Sector';
import { Dot } from '../shape/Dot';
import { isInRectangle, Rectangle } from '../shape/Rectangle';

import {
  findAllByType,
  findChildByType,
  getDisplayName,
  parseChildIndex,
  validateWidthHeight,
  isChildrenEqual,
  renderByOrder,
  getReactEventByType,
} from '../util/ReactUtils';

import { CartesianAxis } from '../cartesian/CartesianAxis';
import { Brush } from '../cartesian/Brush';
import { getOffset, calculateChartCoordinate } from '../util/DOMUtils';
import { getAnyElementOfObject, hasDuplicate, uniqueId, isNumber, findEntryInArray } from '../util/DataUtils';
import {
  calculateActiveTickIndex,
  getMainColorOfGraphicItem,
  getBarSizeList,
  getBarPosition,
  appendOffsetOfLegend,
  getLegendProps,
  combineEventHandlers,
  getTicksOfAxis,
  getCoordinatesOfGrid,
  getStackedDataOfItem,
  parseErrorBarsOfAxis,
  getBandSizeOfAxis,
  getStackGroupsByAxisId,
  isCategoricalAxis,
  getDomainOfItemsWithSameAxis,
  getDomainOfStackGroups,
  getDomainOfDataByKey,
  parseSpecifiedDomain,
  parseDomainOfCategoryAxis,
  getTooltipItem,
} from '../util/ChartUtils';
import { detectReferenceElementsDomain } from '../util/DetectReferenceElementsDomain';
import { inRangeOfSector, polarToCartesian } from '../util/PolarUtils';
import { shallowEqual } from '../util/ShallowEqual';
import { eventCenter, SYNC_EVENT } from '../util/Events';
import {
  LayoutType,
  StackOffsetType,
  CategoricalChartOptions,
  Margin,
  CartesianViewBox,
  ChartOffset,
  BaseAxisProps,
  Coordinate,
  ChartCoordinate,
  TickItem,
  filterProps,
  adaptEventHandlers,
  GeometrySector,
} from '../util/types';

const ORIENT_MAP = {
  xAxis: ['bottom', 'top'],
  yAxis: ['left', 'right'],
};

const originCoordinate: Coordinate = { x: 0, y: 0 };

// use legacy isFinite only if there is a problem (aka IE)
// eslint-disable-next-line no-restricted-globals
const isFinit = Number.isFinite ? Number.isFinite : isFinite;

const defer = // eslint-disable-next-line no-nested-ternary
  typeof requestAnimationFrame === 'function'
    ? requestAnimationFrame
    : typeof setImmediate === 'function'
    ? setImmediate
    : setTimeout;
const deferClear = // eslint-disable-next-line no-nested-ternary
  typeof cancelAnimationFrame === 'function'
    ? cancelAnimationFrame
    : typeof clearImmediate === 'function'
    ? clearImmediate
    : clearTimeout;

const calculateTooltipPos = (rangeObj: any, layout: LayoutType): any => {
  if (layout === 'horizontal') {
    return rangeObj.x;
  }
  if (layout === 'vertical') {
    return rangeObj.y;
  }
  if (layout === 'centric') {
    return rangeObj.angle;
  }

  return rangeObj.radius;
};

const getActiveCoordinate = (
  layout: LayoutType,
  tooltipTicks: TickItem[],
  activeIndex: any,
  rangeObj: any,
): ChartCoordinate => {
  const entry = tooltipTicks.find((tick: any) => tick && tick.index === activeIndex);

  if (entry) {
    if (layout === 'horizontal') {
      return { x: entry.coordinate, y: rangeObj.y };
    }
    if (layout === 'vertical') {
      return { x: rangeObj.x, y: entry.coordinate };
    }
    if (layout === 'centric') {
      const angle = entry.coordinate;
      const { radius } = rangeObj;

      return {
        ...rangeObj,
        ...polarToCartesian(rangeObj.cx, rangeObj.cy, radius, angle),
        angle,
        radius,
      };
    }

    const radius = entry.coordinate;
    const { angle } = rangeObj;

    return {
      ...rangeObj,
      ...polarToCartesian(rangeObj.cx, rangeObj.cy, radius, angle),
      angle,
      radius,
    };
  }

  return originCoordinate;
};

const getDisplayedData = (data: any[], { graphicalItems, dataStartIndex, dataEndIndex }: any, item?: any): any[] => {
  const itemsData = (graphicalItems || []).reduce((result: any, child: any) => {
    const itemData = child.props.data;

    if (itemData && itemData.length) {
      return [...result, ...itemData];
    }

    return result;
  }, []);
  if (itemsData && itemsData.length > 0) {
    return itemsData;
  }

  if (item && item.props && item.props.data && item.props.data.length > 0) {
    return item.props.data;
  }

  if (data && data.length && isNumber(dataStartIndex) && isNumber(dataEndIndex)) {
    return data.slice(dataStartIndex, dataEndIndex + 1);
  }

  return [];
};

/**
 * Get the content to be displayed in the tooltip
 * @param  {Object} state          Current state
 * @param  {Array}  chartData      The data defined in chart
 * @param  {Number} activeIndex    Active index of data
 * @param  {String} activeLabel    Active label of data
 * @return {Array}                 The content of tooltip
 */
const getTooltipContent = (
  state: CategoricalChartState,
  chartData: any[],
  activeIndex: number,
  activeLabel?: string,
): any[] => {
  const { graphicalItems, tooltipAxis } = state;
  const displayedData = getDisplayedData(chartData, state);

  if (activeIndex < 0 || !graphicalItems || !graphicalItems.length || activeIndex >= displayedData.length) {
    return null;
  }
  // get data by activeIndex when the axis don't allow duplicated category
  return graphicalItems.reduce((result: any, child: any) => {
    const { hide } = child.props;

    if (hide) {
      return result;
    }

    const { data } = child.props;
    let payload;

    if (tooltipAxis.dataKey && !tooltipAxis.allowDuplicatedCategory) {
      // graphic child has data props
      const entries = data === undefined ? displayedData : data;
      payload = findEntryInArray(entries, tooltipAxis.dataKey, activeLabel);
    } else {
      payload = (data && data[activeIndex]) || displayedData[activeIndex];
    }

    if (!payload) {
      return result;
    }

    return [...result, getTooltipItem(child, payload)];
  }, []);
};

/**
 * Returns tooltip data based on a mouse position (as a parameter or in state)
 * @param  {Object} state     current state
 * @param  {Array}  chartData the data defined in chart
 * @param  {String} layout     The layout type of chart
 * @param  {Object} rangeObj  { x, y } coordinates
 * @return {Object}           Tooltip data data
 */
const getTooltipData = (state: CategoricalChartState, chartData: any[], layout: LayoutType, rangeObj?: any) => {
  const rangeData = rangeObj || { x: state.chartX, y: state.chartY };

  const pos = calculateTooltipPos(rangeData, layout);
  const { orderedTooltipTicks: ticks, tooltipAxis: axis, tooltipTicks } = state;

  const activeIndex = calculateActiveTickIndex(pos, ticks, tooltipTicks, axis);

  if (activeIndex >= 0 && tooltipTicks) {
    const activeLabel = tooltipTicks[activeIndex] && tooltipTicks[activeIndex].value;
    const activePayload = getTooltipContent(state, chartData, activeIndex, activeLabel);
    const activeCoordinate = getActiveCoordinate(layout, ticks, activeIndex, rangeData);

    return {
      activeTooltipIndex: activeIndex,
      activeLabel,
      activePayload,
      activeCoordinate,
    };
  }

  return null;
};

/**
 * Get the configuration of axis by the options of axis instance
 * @param  {Object} props         Latest props
 * @param {Array}  axes           The instance of axes
 * @param  {Array} graphicalItems The instances of item
 * @param  {String} axisType      The type of axis, xAxis - x-axis, yAxis - y-axis
 * @param  {String} axisIdKey     The unique id of an axis
 * @param  {Object} stackGroups   The items grouped by axisId and stackId
 * @param {Number} dataStartIndex The start index of the data series when a brush is applied
 * @param {Number} dataEndIndex   The end index of the data series when a brush is applied
 * @return {Object}      Configuration
 */
const getAxisMapByAxes = (
  props: CategoricalChartProps,
  { axes, graphicalItems, axisType, axisIdKey, stackGroups, dataStartIndex, dataEndIndex }: any,
) => {
  const { layout, children, stackOffset } = props;
  const isCategorical = isCategoricalAxis(layout, axisType);

  // Eliminate duplicated axes
  const axisMap = axes.reduce((result: any, child: any) => {
    const { type, dataKey, allowDataOverflow, allowDuplicatedCategory, scale, ticks } = child.props;
    const axisId = child.props[axisIdKey];
    const displayedData = getDisplayedData(props.data, {
      graphicalItems: graphicalItems.filter((item: any) => item.props[axisIdKey] === axisId),
      dataStartIndex,
      dataEndIndex,
    });
    const len = displayedData.length;

    if (!result[axisId]) {
      let domain, duplicateDomain, categoricalDomain;

      if (dataKey) {
        // has dataKey in <Axis />
        domain = getDomainOfDataByKey(displayedData, dataKey, type);

        if (type === 'category' && isCategorical) {
          // the field type is category data and this axis is catrgorical axis
          const duplicate = hasDuplicate(domain);

          if (allowDuplicatedCategory && duplicate) {
            duplicateDomain = domain;
            // When category axis has duplicated text, serial numbers are used to generate scale
            domain = _.range(0, len);
          } else if (!allowDuplicatedCategory) {
            // remove duplicated category
            domain = parseDomainOfCategoryAxis(child.props.domain, domain, child).reduce(
              (finalDomain: any, entry: any) =>
                finalDomain.indexOf(entry) >= 0 ? finalDomain : [...finalDomain, entry],
              [],
            );
          }
        } else if (type === 'category') {
          // the field type is category data and this axis is numerical axis
          if (!allowDuplicatedCategory) {
            domain = parseDomainOfCategoryAxis(child.props.domain, domain, child).reduce(
              (finalDomain: any, entry: any) =>
                finalDomain.indexOf(entry) >= 0 || entry === '' || _.isNil(entry)
                  ? finalDomain
                  : [...finalDomain, entry],
              [],
            );
          } else {
            // eliminate undefined or null or empty string
            domain = domain.filter((entry: any) => entry !== '' && !_.isNil(entry));
          }
        } else if (type === 'number') {
          // the field type is numerical
          const errorBarsDomain = parseErrorBarsOfAxis(
            displayedData,
            graphicalItems.filter((item: any) => item.props[axisIdKey] === axisId && !item.props.hide),
            dataKey,
            axisType,
            layout,
          );

          if (errorBarsDomain) {
            domain = errorBarsDomain;
          }
        }

        if (isCategorical && (type === 'number' || scale !== 'auto')) {
          categoricalDomain = getDomainOfDataByKey(displayedData, dataKey, 'category');
        }
      } else if (isCategorical) {
        // the axis is a categorical axis
        domain = _.range(0, len);
      } else if (stackGroups && stackGroups[axisId] && stackGroups[axisId].hasStack && type === 'number') {
        // when stackOffset is 'expand', the domain may be calculated as [0, 1.000000000002]
        domain =
          stackOffset === 'expand'
            ? [0, 1]
            : getDomainOfStackGroups(stackGroups[axisId].stackGroups, dataStartIndex, dataEndIndex);
      } else {
        domain = getDomainOfItemsWithSameAxis(
          displayedData,
          graphicalItems.filter((item: any) => item.props[axisIdKey] === axisId && !item.props.hide),
          type,
          layout,
          true,
        );
      }

      if (type === 'number') {
        // To detect wether there is any reference lines whose props alwaysShow is true
        domain = detectReferenceElementsDomain(children, domain, axisId, axisType, ticks);

        if (child.props.domain) {
          domain = parseSpecifiedDomain(child.props.domain, domain, allowDataOverflow);
        }
      } else if (type === 'category' && child.props.domain) {
        const axisDomain = child.props.domain;
        const isDomainValidate = domain.every((entry: string | number) => axisDomain.indexOf(entry) >= 0);

        if (isDomainValidate) {
          domain = axisDomain;
        }
      }

      return {
        ...result,
        [axisId]: {
          ...child.props,
          axisType,
          domain,
          categoricalDomain,
          duplicateDomain,
          originalDomain: child.props.domain,
          isCategorical,
          layout,
        },
      };
    }

    return result;
  }, {});
  return axisMap;
};

/**
 * Get the configuration of axis by the options of item,
 * this kind of axis does not display in chart
 * @param  {Object} props         Latest props
 * @param  {Array} graphicalItems The instances of item
 * @param  {ReactElement} Axis    Axis Component
 * @param  {String} axisType      The type of axis, xAxis - x-axis, yAxis - y-axis
 * @param  {String} axisIdKey     The unique id of an axis
 * @param  {Object} stackGroups   The items grouped by axisId and stackId
 * @param {Number} dataStartIndex The start index of the data series when a brush is applied
 * @param {Number} dataEndIndex   The end index of the data series when a brush is applied
 * @return {Object}               Configuration
 */
const getAxisMapByItems = (
  props: CategoricalChartProps,
  { graphicalItems, Axis, axisType, axisIdKey, stackGroups, dataStartIndex, dataEndIndex }: any,
) => {
  const { layout, children } = props;
  const displayedData = getDisplayedData(props.data, {
    graphicalItems,
    dataStartIndex,
    dataEndIndex,
  });
  const len = displayedData.length;
  const isCategorical = isCategoricalAxis(layout, axisType);
  let index = -1;

  // The default type of x-axis is category axis,
  // The default contents of x-axis is the serial numbers of data
  // The default type of y-axis is number axis
  // The default contents of y-axis is the domain of data
  const axisMap = graphicalItems.reduce((result: any, child: any) => {
    const axisId = child.props[axisIdKey];

    if (!result[axisId]) {
      index++;
      let domain;

      if (isCategorical) {
        domain = _.range(0, len);
      } else if (stackGroups && stackGroups[axisId] && stackGroups[axisId].hasStack) {
        domain = getDomainOfStackGroups(stackGroups[axisId].stackGroups, dataStartIndex, dataEndIndex);
        domain = detectReferenceElementsDomain(children, domain, axisId, axisType);
      } else {
        domain = parseSpecifiedDomain(
          Axis.defaultProps.domain,
          getDomainOfItemsWithSameAxis(
            displayedData,
            graphicalItems.filter((item: any) => item.props[axisIdKey] === axisId && !item.props.hide),
            'number',
            layout,
          ),
          Axis.defaultProps.allowDataOverflow,
        );
        domain = detectReferenceElementsDomain(children, domain, axisId, axisType);
      }

      return {
        ...result,
        [axisId]: {
          axisType,
          ...Axis.defaultProps,
          hide: true,
          orientation: _.get(ORIENT_MAP, `${axisType}.${index % 2}`, null),
          domain,
          originalDomain: Axis.defaultProps.domain,
          isCategorical,
          layout,
          // specify scale when no Axis
          // scale: isCategorical ? 'band' : 'linear',
        },
      };
    }

    return result;
  }, {});

  return axisMap;
};

/**
 * Get the configuration of all x-axis or y-axis
 * @param  {Object} props          Latest props
 * @param  {String} axisType       The type of axis
 * @param  {Array}  graphicalItems The instances of item
 * @param  {Object} stackGroups    The items grouped by axisId and stackId
 * @param {Number} dataStartIndex  The start index of the data series when a brush is applied
 * @param {Number} dataEndIndex    The end index of the data series when a brush is applied
 * @return {Object}          Configuration
 */
const getAxisMap = (
  props: CategoricalChartProps,
  { axisType = 'xAxis', AxisComp, graphicalItems, stackGroups, dataStartIndex, dataEndIndex }: any,
) => {
  const { children } = props;
  const axisIdKey = `${axisType}Id`;
  // Get all the instance of Axis
  const axes = findAllByType(children, AxisComp);

  let axisMap = {};

  if (axes && axes.length) {
    axisMap = getAxisMapByAxes(props, {
      axes,
      graphicalItems,
      axisType,
      axisIdKey,
      stackGroups,
      dataStartIndex,
      dataEndIndex,
    });
  } else if (graphicalItems && graphicalItems.length) {
    axisMap = getAxisMapByItems(props, {
      Axis: AxisComp,
      graphicalItems,
      axisType,
      axisIdKey,
      stackGroups,
      dataStartIndex,
      dataEndIndex,
    });
  }

  return axisMap;
};

const tooltipTicksGenerator = (axisMap: any) => {
  const axis: BaseAxisProps = getAnyElementOfObject(axisMap);
  const tooltipTicks = getTicksOfAxis(axis, false, true);

  return {
    tooltipTicks,
    orderedTooltipTicks: _.sortBy(tooltipTicks, o => o.coordinate),
    tooltipAxis: axis,
    tooltipAxisBandSize: getBandSizeOfAxis(axis, tooltipTicks),
  };
};

/**
 * Returns default, reset state for the categorical chart.
 * @param {Object} props Props object to use when creating the default state
 * @return {Object} Whole new state
 */
const createDefaultState = (props: CategoricalChartProps): CategoricalChartState => {
  const { children, defaultShowTooltip } = props;
  const brushItem = findChildByType(children, Brush.displayName);
  const startIndex = (brushItem && brushItem.props && brushItem.props.startIndex) || 0;
  const endIndex =
    (brushItem && brushItem.props && brushItem.props.endIndex) || (props.data && props.data.length - 1) || 0;

  return {
    chartX: 0,
    chartY: 0,
    dataStartIndex: startIndex,
    dataEndIndex: endIndex,
    activeTooltipIndex: -1,
    isTooltipActive: !_.isNil(defaultShowTooltip) ? defaultShowTooltip : false,
  };
};

const hasGraphicalBarItem = (graphicalItems: any[]): any[] | boolean => {
  if (!graphicalItems || !graphicalItems.length) {
    return false;
  }

  return graphicalItems.some((item: any) => {
    const name = getDisplayName(item && item.type);

    return name && name.indexOf('Bar') >= 0;
  });
};

const getAxisNameByLayout = (layout: LayoutType) => {
  if (layout === 'horizontal') {
    return { numericAxisName: 'yAxis', cateAxisName: 'xAxis' };
  }
  if (layout === 'vertical') {
    return { numericAxisName: 'xAxis', cateAxisName: 'yAxis' };
  }
  if (layout === 'centric') {
    return { numericAxisName: 'radiusAxis', cateAxisName: 'angleAxis' };
  }

  return { numericAxisName: 'angleAxis', cateAxisName: 'radiusAxis' };
};

/**
 * Calculate the offset of main part in the svg element
 * @param  {Object} props          Latest props
 * graphicalItems The instances of item
 * xAxisMap       The configuration of x-axis
 * yAxisMap       The configuration of y-axis
 * @param  {Object} prevLegendBBox          the boundary box of legend
 * @return {Object} The offset of main part in the svg element
 */
const calculateOffset = (
  { props, graphicalItems, xAxisMap = {} as BaseAxisProps, yAxisMap = {} as BaseAxisProps }: any,
  prevLegendBBox?: any,
) => {
  const { width, height, children } = props;
  const margin = props.margin || {};
  const brushItem = findChildByType(children, Brush.displayName);
  const legendItem = findChildByType(children, Legend.displayName);

  const offsetH = Object.keys(yAxisMap).reduce(
    (result: any, id: any) => {
      const entry = yAxisMap[id];
      const { orientation } = entry;

      if (!entry.mirror && !entry.hide) {
        return { ...result, [orientation]: result[orientation] + entry.width };
      }

      return result;
    },
    { left: margin.left || 0, right: margin.right || 0 },
  );

  const offsetV = Object.keys(xAxisMap).reduce(
    (result, id) => {
      const entry = xAxisMap[id];
      const { orientation } = entry;

      if (!entry.mirror && !entry.hide) {
        return { ...result, [orientation]: _.get(result, `${orientation}`) + entry.height };
      }

      return result;
    },
    { top: margin.top || 0, bottom: margin.bottom || 0 },
  );

  let offset = { ...offsetV, ...offsetH };

  const brushBottom = offset.bottom;

  if (brushItem) {
    offset.bottom += brushItem.props.height || Brush.defaultProps.height;
  }

  if (legendItem && prevLegendBBox) {
    offset = appendOffsetOfLegend(offset, graphicalItems, props, prevLegendBBox);
  }

  return {
    brushBottom,
    ...offset,
    width: width - offset.left - offset.right,
    height: height - offset.top - offset.bottom,
  };
};

export interface CategoricalChartState {
  chartX?: number;

  chartY?: number;

  dataStartIndex?: number;

  dataEndIndex?: number;

  activeTooltipIndex?: number;

  isTooltipActive?: boolean;

  updateId?: number;

  xAxisMap?: {
    [k: string]: BaseAxisProps;
  };

  yAxisMap?: {
    [k: string]: BaseAxisProps;
  };

  orderedTooltipTicks?: any;

  tooltipAxis?: BaseAxisProps;

  tooltipTicks?: TickItem[];

  graphicalItems?: any;

  activeCoordinate?: ChartCoordinate;

  offset?: ChartOffset;

  angleAxisMap?: any;

  radiusAxisMap?: any;

  formattedGraphicalItems?: any;

  /** active tooltip payload */
  activePayload?: any[];

  tooltipAxisBandSize?: number;

  /** active item */
  activeItem?: any;

  /** Active label of data */
  activeLabel?: string;

  xValue?: number;

  yValue?: number;

  legendBBox?: any;

  prevData?: any[];
  prevWidth?: number;
  prevHeight?: number;
  prevLayout?: LayoutType;
  prevStackOffset?: StackOffsetType;
  prevMargin?: Margin;
  prevChildren?: any;
}

export type CategoricalChartFunc = (nextState: CategoricalChartState, event: any) => void;

export interface CategoricalChartProps {
  syncId?: number | string;
  syncMethod?: 'index' | 'value' | Function;
  compact?: boolean;
  width?: number;
  height?: number;
  data?: any[];
  layout?: LayoutType;
  stackOffset?: StackOffsetType;
  throttleDelay?: number;
  margin?: Margin;
  barCategoryGap?: number | string;
  barGap?: number | string;
  barSize?: number | string;
  maxBarSize?: number;
  style?: any;
  className?: string;
  children?: any;
  defaultShowTooltip?: boolean;
  onClick?: CategoricalChartFunc;
  onMouseLeave?: CategoricalChartFunc;
  onMouseEnter?: CategoricalChartFunc;
  onMouseMove?: CategoricalChartFunc;
  onMouseDown?: CategoricalChartFunc;
  onMouseUp?: CategoricalChartFunc;
  reverseStackOrder?: boolean;
  id?: string;

  startAngle?: number;
  endAngle?: number;
  cx?: number | string;
  cy?: number | string;
  innerRadius?: number | string;
  outerRadius?: number | string;
  title?: string;
  desc?: string;
}

export const generateCategoricalChart = ({
  chartName,
  GraphicalChild,
  defaultTooltipEventType = 'axis',
  validateTooltipEventTypes = ['axis'],
  axisComponents,
  legendContent,
  formatAxisMap,
  defaultProps,
}: CategoricalChartOptions) => {
  const getFormatItems = (props: CategoricalChartProps, currentState: any): any[] => {
    const { graphicalItems, stackGroups, offset, updateId, dataStartIndex, dataEndIndex } = currentState;
    const { barSize, layout, barGap, barCategoryGap, maxBarSize: globalMaxBarSize } = props;
    const { numericAxisName, cateAxisName } = getAxisNameByLayout(layout);
    const hasBar = hasGraphicalBarItem(graphicalItems);
    const sizeList = hasBar && getBarSizeList({ barSize, stackGroups });
    const formattedItems = [] as any[];

    graphicalItems.forEach((item: any, index: number) => {
      const displayedData = getDisplayedData(props.data, { dataStartIndex, dataEndIndex }, item);
      const { dataKey, maxBarSize: childMaxBarSize } = item.props;
      const numericAxisId = item.props[`${numericAxisName}Id`];
      const cateAxisId = item.props[`${cateAxisName}Id`];
      const axisObj = axisComponents.reduce((result: any, entry: any) => {
        const axisMap = currentState[`${entry.axisType}Map`];
        const id = item.props[`${entry.axisType}Id`];
        const axis = axisMap && axisMap[id];

        return {
          ...result,
          [entry.axisType]: axis,
          [`${entry.axisType}Ticks`]: getTicksOfAxis(axis),
        };
      }, {});
      const cateAxis = axisObj[cateAxisName];
      const cateTicks = axisObj[`${cateAxisName}Ticks`];
      const stackedData =
        stackGroups &&
        stackGroups[numericAxisId] &&
        stackGroups[numericAxisId].hasStack &&
        getStackedDataOfItem(item, stackGroups[numericAxisId].stackGroups);
      const itemIsBar = getDisplayName(item.type).indexOf('Bar') >= 0;
      const bandSize = getBandSizeOfAxis(cateAxis, cateTicks);
      let barPosition = [];

      if (itemIsBar) {
        // 如果是bar,计算bar的位置
        const maxBarSize = _.isNil(childMaxBarSize) ? globalMaxBarSize : childMaxBarSize;
        const barBandSize = getBandSizeOfAxis(cateAxis, cateTicks, true) ?? maxBarSize ?? 0;
        barPosition = getBarPosition({
          barGap,
          barCategoryGap,
          bandSize: barBandSize !== bandSize ? barBandSize : bandSize,
          sizeList: sizeList[cateAxisId],
          maxBarSize,
        });

        if (barBandSize !== bandSize) {
          barPosition = barPosition.map((pos: { item: any; position: { offset: number; size: number } }) => ({
            ...pos,
            position: { ...pos.position, offset: pos.position.offset - barBandSize / 2 },
          }));
        }
      }
      const composedFn = item && item.type && item.type.getComposedData;

      if (composedFn) {
        formattedItems.push({
          props: {
            ...composedFn({
              ...axisObj,
              displayedData,
              props,
              dataKey,
              item,
              bandSize,
              barPosition,
              offset,
              stackedData,
              layout,
              dataStartIndex,
              dataEndIndex,
            }),
            key: item.key || `item-${index}`,
            [numericAxisName]: axisObj[numericAxisName],
            [cateAxisName]: axisObj[cateAxisName],
            animationId: updateId,
          },
          childIndex: parseChildIndex(item, props.children),
          item,
        });
      }
    });

    return formattedItems;
  };

  /**
   * The AxisMaps are expensive to render on large data sets
   * so provide the ability to store them in state and only update them when necessary
   * they are dependent upon the start and end index of
   * the brush so it's important that this method is called _after_
   * the state is updated with any new start/end indices
   *
   * @param {Object} props          The props object to be used for updating the axismaps
   * dataStartIndex: The start index of the data series when a brush is applied
   * dataEndIndex: The end index of the data series when a brush is applied
   * updateId: The update id
   * @param {Object} prevState      Prev state
   * @return {Object} state New state to set
   */
  const updateStateOfAxisMapsOffsetAndStackGroups = (
    { props, dataStartIndex, dataEndIndex, updateId }: any,
    prevState?: CategoricalChartState,
  ): any => {
    if (!validateWidthHeight({ props })) {
      return null;
    }

    const { children, layout, stackOffset, data, reverseStackOrder } = props;
    const { numericAxisName, cateAxisName } = getAxisNameByLayout(layout);
    const graphicalItems = findAllByType(children, GraphicalChild);
    const stackGroups = getStackGroupsByAxisId(
      data,
      graphicalItems,
      `${numericAxisName}Id`,
      `${cateAxisName}Id`,
      stackOffset,
      reverseStackOrder,
    );
    const axisObj = axisComponents.reduce((result: any, entry: any) => {
      const name = `${entry.axisType}Map`;

      return {
        ...result,
        [name]: getAxisMap(props, {
          ...entry,
          graphicalItems,
          stackGroups: entry.axisType === numericAxisName && stackGroups,
          dataStartIndex,
          dataEndIndex,
        }),
      };
    }, {});

    const offset = calculateOffset({ ...axisObj, props, graphicalItems }, prevState?.legendBBox);

    Object.keys(axisObj).forEach(key => {
      axisObj[key] = formatAxisMap(props, axisObj[key], offset, key.replace('Map', ''), chartName);
    });
    const cateAxisMap = axisObj[`${cateAxisName}Map`];
    const ticksObj = tooltipTicksGenerator(cateAxisMap);

    const formattedGraphicalItems = getFormatItems(props, {
      ...axisObj,
      dataStartIndex,
      dataEndIndex,
      updateId,
      graphicalItems,
      stackGroups,
      offset,
    });

    return {
      formattedGraphicalItems,
      graphicalItems,
      offset,
      stackGroups,
      ...ticksObj,
      ...axisObj,
    };
  };

  return class CategoricalChartWrapper extends Component<CategoricalChartProps, CategoricalChartState> {
    static displayName = chartName;

    uniqueChartId: any;

    clipPathId: any;

    legendInstance: any;

    deferId: any;

    // todo join specific chart propTypes
    static defaultProps: CategoricalChartProps = {
      layout: 'horizontal',
      stackOffset: 'none',
      barCategoryGap: '10%',
      barGap: 4,
      margin: { top: 5, right: 5, bottom: 5, left: 5 } as Margin,
      reverseStackOrder: false,
      syncMethod: 'index',
      ...defaultProps,
    };

    container?: any;

    constructor(props: CategoricalChartProps) {
      super(props);

      this.uniqueChartId = _.isNil(props.id) ? uniqueId('recharts') : props.id;
      this.clipPathId = `${this.uniqueChartId}-clip`;

      if (props.throttleDelay) {
        this.triggeredAfterMouseMove = _.throttle(this.triggeredAfterMouseMove, props.throttleDelay);
      }

      this.state = {};
    }

    /* eslint-disable  react/no-did-mount-set-state */
    componentDidMount() {
      if (!_.isNil(this.props.syncId)) {
        this.addListener();
      }
    }

    static getDerivedStateFromProps = (
      nextProps: CategoricalChartProps,
      prevState: CategoricalChartState,
    ): CategoricalChartState => {
      const { data, children, width, height, layout, stackOffset, margin } = nextProps;

      if (_.isNil(prevState.updateId)) {
        const defaultState = createDefaultState(nextProps);

        return {
          ...defaultState,
          updateId: 0,
          ...updateStateOfAxisMapsOffsetAndStackGroups(
            {
              props: nextProps,
              ...defaultState,
              updateId: 0,
            },
            prevState,
          ),

          prevData: data,
          prevWidth: width,
          prevHeight: height,
          prevLayout: layout,
          prevStackOffset: stackOffset,
          prevMargin: margin,
          prevChildren: children,
        };
      }
      if (
        data !== prevState.prevData ||
        width !== prevState.prevWidth ||
        height !== prevState.prevHeight ||
        layout !== prevState.prevLayout ||
        stackOffset !== prevState.prevStackOffset ||
        !shallowEqual(margin, prevState.prevMargin)
      ) {
        const defaultState = createDefaultState(nextProps);

        // Fixes https://github.com/recharts/recharts/issues/2143
        const keepFromPrevState = {
          // (chartX, chartY) are (0,0) in default state, but we want to keep the last mouse position to avoid
          // any flickering
          chartX: prevState.chartX,
          chartY: prevState.chartY,

          // The tooltip should stay active when it was active in the previous render. If this is not
          // the case, the tooltip disappears and immediately re-appears, causing a flickering effect
          isTooltipActive: prevState.isTooltipActive,
        };

        const updatesToState = {
          // Update the current tooltip data (in case it changes without mouse interaction)
          ...getTooltipData(prevState, data, layout),
          updateId: prevState.updateId + 1,
        };

        const newState = {
          ...defaultState,
          ...keepFromPrevState,
          ...updatesToState,
        };

        return {
          ...newState,
          ...updateStateOfAxisMapsOffsetAndStackGroups(
            {
              props: nextProps,
              ...newState,
            },
            prevState,
          ),
          prevData: data,
          prevWidth: width,
          prevHeight: height,
          prevLayout: layout,
          prevStackOffset: stackOffset,
          prevMargin: margin,
          prevChildren: children,
        };
      }
      if (!isChildrenEqual(children, prevState.prevChildren)) {
        // update configuration in chilren
        const hasGlobalData = !_.isNil(data);
        const newUpdateId = hasGlobalData ? prevState.updateId : prevState.updateId + 1;

        return {
          updateId: newUpdateId,
          ...updateStateOfAxisMapsOffsetAndStackGroups(
            {
              props: nextProps,
              ...prevState,
              updateId: newUpdateId,
            },
            prevState,
          ),
          prevChildren: children,
        };
      }

      return null;
    };

    componentDidUpdate(prevProps: CategoricalChartProps) {
      // add syncId
      if (_.isNil(prevProps.syncId) && !_.isNil(this.props.syncId)) {
        this.addListener();
      }
      // remove syncId
      if (!_.isNil(prevProps.syncId) && _.isNil(this.props.syncId)) {
        this.removeListener();
      }
    }

    componentWillUnmount() {
      this.clearDeferId();
      if (!_.isNil(this.props.syncId)) {
        this.removeListener();
      }
      this.cancelThrottledTriggerAfterMouseMove();
    }

    cancelThrottledTriggerAfterMouseMove() {
      if (typeof (this.triggeredAfterMouseMove as any).cancel === 'function') {
        (this.triggeredAfterMouseMove as any).cancel();
      }
    }

    getTooltipEventType() {
      const tooltipItem = findChildByType(this.props.children, Tooltip.displayName);

      if (tooltipItem && isBoolean(tooltipItem.props.shared)) {
        const eventType = tooltipItem.props.shared ? 'axis' : 'item';

        return validateTooltipEventTypes.indexOf(eventType) >= 0 ? eventType : defaultTooltipEventType;
      }

      return defaultTooltipEventType;
    }

    /**
     * Get the information of mouse in chart, return null when the mouse is not in the chart
     * @param  {Object} event    The event object
     * @return {Object}          Mouse data
     */
    getMouseInfo(event: any) {
      if (!this.container) {
        return null;
      }

      const containerOffset = getOffset(this.container);
      const e = calculateChartCoordinate(event, containerOffset);
      const rangeObj = this.inRange(e.chartX, e.chartY);
      if (!rangeObj) {
        return null;
      }

      const { xAxisMap, yAxisMap } = this.state;
      const tooltipEventType = this.getTooltipEventType();

      if (tooltipEventType !== 'axis' && xAxisMap && yAxisMap) {
        const xScale = getAnyElementOfObject(xAxisMap).scale;
        const yScale = getAnyElementOfObject(yAxisMap).scale;
        const xValue = xScale && xScale.invert ? xScale.invert(e.chartX) : null;
        const yValue = yScale && yScale.invert ? yScale.invert(e.chartY) : null;

        return { ...e, xValue, yValue };
      }

      const toolTipData = getTooltipData(this.state, this.props.data, this.props.layout, rangeObj);

      if (toolTipData) {
        return {
          ...e,
          ...toolTipData,
        };
      }

      return null;
    }

    getCursorRectangle(): any {
      const { layout } = this.props;
      const { activeCoordinate, offset, tooltipAxisBandSize } = this.state;
      const halfSize = tooltipAxisBandSize / 2;

      return {
        stroke: 'none',
        fill: '#ccc',
        x: layout === 'horizontal' ? activeCoordinate.x - halfSize : offset.left + 0.5,
        y: layout === 'horizontal' ? offset.top + 0.5 : activeCoordinate.y - halfSize,
        width: layout === 'horizontal' ? tooltipAxisBandSize : offset.width - 1,
        height: layout === 'horizontal' ? offset.height - 1 : tooltipAxisBandSize,
      };
    }

    getCursorPoints(): any {
      const { layout } = this.props;
      const { activeCoordinate, offset } = this.state;
      let x1, y1, x2, y2;

      if (layout === 'horizontal') {
        x1 = activeCoordinate.x;
        x2 = x1;
        y1 = offset.top;
        y2 = offset.top + offset.height;
      } else if (layout === 'vertical') {
        y1 = activeCoordinate.y;
        y2 = y1;
        x1 = offset.left;
        x2 = offset.left + offset.width;
      } else if (!_.isNil(activeCoordinate.cx) || !_.isNil(activeCoordinate.cy)) {
        if (layout === 'centric') {
          const { cx, cy, innerRadius, outerRadius, angle } = activeCoordinate;
          const innerPoint = polarToCartesian(cx, cy, innerRadius, angle);
          const outerPoint = polarToCartesian(cx, cy, outerRadius, angle);
          x1 = innerPoint.x;
          y1 = innerPoint.y;
          x2 = outerPoint.x;
          y2 = outerPoint.y;
        } else {
          const { cx, cy, radius, startAngle, endAngle } = activeCoordinate;
          const startPoint = polarToCartesian(cx, cy, radius, startAngle);
          const endPoint = polarToCartesian(cx, cy, radius, endAngle);

          return {
            points: [startPoint, endPoint],
            cx,
            cy,
            radius,
            startAngle,
            endAngle,
          };
        }
      }

      return [
        { x: x1, y: y1 },
        { x: x2, y: y2 },
      ];
    }

    inRange(x: number, y: number): any {
      const { layout } = this.props;

      if (layout === 'horizontal' || layout === 'vertical') {
        const { offset } = this.state;
        const isInRange =
          x >= offset.left && x <= offset.left + offset.width && y >= offset.top && y <= offset.top + offset.height;

        return isInRange ? { x, y } : null;
      }

      const { angleAxisMap, radiusAxisMap } = this.state;

      if (angleAxisMap && radiusAxisMap) {
        const angleAxis = getAnyElementOfObject(angleAxisMap);

        return inRangeOfSector({ x, y }, angleAxis);
      }

      return null;
    }

    parseEventsOfWrapper() {
      const { children } = this.props;
      const tooltipEventType = this.getTooltipEventType();
      const tooltipItem = findChildByType(children, Tooltip.displayName);
      let tooltipEvents: any = {};

      if (tooltipItem && tooltipEventType === 'axis') {
        if (tooltipItem.props.trigger === 'click') {
          tooltipEvents = {
            onClick: this.handleClick,
          };
        } else {
          tooltipEvents = {
            onMouseEnter: this.handleMouseEnter,
            onMouseMove: this.handleMouseMove,
            onMouseLeave: this.handleMouseLeave,
            onTouchMove: this.handleTouchMove,
            onTouchStart: this.handleTouchStart,
            onTouchEnd: this.handleTouchEnd,
          };
        }
      }
      const outerEvents = adaptEventHandlers(this.props, this.handleOuterEvent);

      return {
        ...outerEvents,
        ...tooltipEvents,
      };
    }

    /* eslint-disable  no-underscore-dangle */
    addListener() {
      eventCenter.on(SYNC_EVENT, this.handleReceiveSyncEvent);

      if (eventCenter.setMaxListeners && eventCenter._maxListeners) {
        eventCenter.setMaxListeners(eventCenter._maxListeners + 1);
      }
    }

    removeListener() {
      eventCenter.removeListener(SYNC_EVENT, this.handleReceiveSyncEvent);

      if (eventCenter.setMaxListeners && eventCenter._maxListeners) {
        eventCenter.setMaxListeners(eventCenter._maxListeners - 1);
      }
    }

    clearDeferId = () => {
      if (!isNil(this.deferId) && deferClear) {
        deferClear(this.deferId);
      }
      this.deferId = null;
    };

    handleLegendBBoxUpdate = (box: any) => {
      if (box) {
        const { dataStartIndex, dataEndIndex, updateId } = this.state;

        this.setState({
          legendBBox: box,
          ...updateStateOfAxisMapsOffsetAndStackGroups(
            {
              props: this.props,
              dataStartIndex,
              dataEndIndex,
              updateId,
            },
            { ...this.state, legendBBox: box },
          ),
        });
      }
    };

    handleReceiveSyncEvent = (cId: number | string, chartId: string, data: CategoricalChartState) => {
      const { syncId } = this.props;

      if (syncId === cId && chartId !== this.uniqueChartId) {
        this.clearDeferId();
        this.deferId = defer && defer(this.applySyncEvent.bind(this, data));
      }
    };

    handleBrushChange = ({ startIndex, endIndex }: any) => {
      // Only trigger changes if the extents of the brush have actually changed
      if (startIndex !== this.state.dataStartIndex || endIndex !== this.state.dataEndIndex) {
        const { updateId } = this.state;

        this.setState(() => ({
          dataStartIndex: startIndex,
          dataEndIndex: endIndex,
          ...updateStateOfAxisMapsOffsetAndStackGroups(
            {
              props: this.props,
              dataStartIndex: startIndex,
              dataEndIndex: endIndex,
              updateId,
            },
            this.state,
          ),
        }));

        this.triggerSyncEvent({
          dataStartIndex: startIndex,
          dataEndIndex: endIndex,
        });
      }
    };

    /**
     * The handler of mouse entering chart
     * @param  {Object} e              Event object
     * @return {Null}                  null
     */
    handleMouseEnter = (e: any) => {
      const { onMouseEnter } = this.props;
      const mouse = this.getMouseInfo(e);

      if (mouse) {
        const nextState: CategoricalChartState = { ...mouse, isTooltipActive: true };
        this.setState(nextState);
        this.triggerSyncEvent(nextState);

        if (_.isFunction(onMouseEnter)) {
          onMouseEnter(nextState, e);
        }
      }
    };

    triggeredAfterMouseMove = (e: any): any => {
      const { onMouseMove } = this.props;
      const mouse = this.getMouseInfo(e);
      const nextState: CategoricalChartState = mouse ? { ...mouse, isTooltipActive: true } : { isTooltipActive: false };

      this.setState(nextState);
      this.triggerSyncEvent(nextState);

      if (_.isFunction(onMouseMove)) {
        onMouseMove(nextState, e);
      }
    };

    /**
     * The handler of mouse entering a scatter
     * @param {Object} el The active scatter
     * @return {Object} no return
     */
    handleItemMouseEnter = (el: any) => {
      this.setState(() => ({
        isTooltipActive: true,
        activeItem: el,
        activePayload: el.tooltipPayload,
        activeCoordinate: el.tooltipPosition || { x: el.cx, y: el.cy },
      }));
    };

    /**
     * The handler of mouse leaving a scatter
     * @return {Object} no return
     */
    handleItemMouseLeave = () => {
      this.setState(() => ({
        isTooltipActive: false,
      }));
    };

    /**
     * The handler of mouse moving in chart
     * @param  {Object} e        Event object
     * @return {Null} no return
     */
    handleMouseMove = (e: any) => {
      if (e && _.isFunction(e.persist)) {
        e.persist();
      }
      this.triggeredAfterMouseMove(e);
    };

    /**
     * The handler if mouse leaving chart
     * @param {Object} e Event object
     * @return {Null} no return
     */
    handleMouseLeave = (e: any) => {
      const { onMouseLeave } = this.props;
      const nextState: CategoricalChartState = { isTooltipActive: false };

      this.setState(nextState);
      this.triggerSyncEvent(nextState);

      if (_.isFunction(onMouseLeave)) {
        onMouseLeave(nextState, e);
      }

      this.cancelThrottledTriggerAfterMouseMove();
    };

    handleOuterEvent = (e: any) => {
      const eventName = getReactEventByType(e);

      const event = _.get(this.props, `${eventName}`);
      if (eventName && _.isFunction(event)) {
        let mouse;
        if (/.*touch.*/i.test(eventName)) {
          mouse = this.getMouseInfo(e.changedTouches[0]);
        } else {
          mouse = this.getMouseInfo(e);
        }

        const handler = event;

        handler(mouse, e);
      }
    };

    handleClick = (e: any) => {
      const { onClick } = this.props;
      const mouse = this.getMouseInfo(e);

      if (mouse) {
        const nextState: CategoricalChartState = { ...mouse, isTooltipActive: true };
        this.setState(nextState);
        this.triggerSyncEvent(nextState);

        if (_.isFunction(onClick)) {
          onClick(nextState, e);
        }
      }
    };

    handleMouseDown = (e: any) => {
      const { onMouseDown } = this.props;

      if (_.isFunction(onMouseDown)) {
        const nextState: CategoricalChartState = this.getMouseInfo(e);
        onMouseDown(nextState, e);
      }
    };

    handleMouseUp = (e: any) => {
      const { onMouseUp } = this.props;

      if (_.isFunction(onMouseUp)) {
        const nextState: CategoricalChartState = this.getMouseInfo(e);
        onMouseUp(nextState, e);
      }
    };

    handleTouchMove = (e: any) => {
      if (e.changedTouches != null && e.changedTouches.length > 0) {
        this.handleMouseMove(e.changedTouches[0]);
      }
    };

    handleTouchStart = (e: any) => {
      if (e.changedTouches != null && e.changedTouches.length > 0) {
        this.handleMouseDown(e.changedTouches[0]);
      }
    };

    handleTouchEnd = (e: any) => {
      if (e.changedTouches != null && e.changedTouches.length > 0) {
        this.handleMouseUp(e.changedTouches[0]);
      }
    };

    triggerSyncEvent(data: CategoricalChartState) {
      const { syncId } = this.props;

      if (!_.isNil(syncId)) {
        eventCenter.emit(SYNC_EVENT, syncId, this.uniqueChartId, data);
      }
    }

    applySyncEvent(data: CategoricalChartState) {
      const { layout, syncMethod } = this.props;
      const { updateId } = this.state;
      const { dataStartIndex, dataEndIndex } = data;

      if (!_.isNil(data.dataStartIndex) || !_.isNil(data.dataEndIndex)) {
        this.setState({
          dataStartIndex,
          dataEndIndex,
          ...updateStateOfAxisMapsOffsetAndStackGroups(
            {
              props: this.props,
              dataStartIndex,
              dataEndIndex,
              updateId,
            },
            this.state,
          ),
        });
      } else if (!_.isNil(data.activeTooltipIndex)) {
        const { chartX, chartY } = data;
        let { activeTooltipIndex } = data;
        const { offset, tooltipTicks } = this.state;
        if (!offset) {
          return;
        }
        if (typeof syncMethod === 'function') {
          // Call a callback function. If there is an application specific algorithm
          activeTooltipIndex = syncMethod(tooltipTicks, data);
        } else if (syncMethod === 'value') {
          // Set activeTooltipIndex to the index with the same value as data.activeLabel
          // For loop instead of findIndex because the latter is very slow in some browsers
          activeTooltipIndex = -1; // in case we cannot find the element
          for (let i = 0; i < tooltipTicks.length; i++) {
            if (tooltipTicks[i].value === data.activeLabel) {
              activeTooltipIndex = i;
              break;
            }
          }
        }
        const viewBox: CartesianViewBox = { ...offset, x: offset.left, y: offset.top };
        // When a categotical chart is combined with another chart, the value of chartX
        // and chartY may beyond the boundaries.
        const validateChartX = Math.min(chartX, viewBox.x + viewBox.width);
        const validateChartY = Math.min(chartY, viewBox.y + viewBox.height);
        const activeLabel = tooltipTicks[activeTooltipIndex] && tooltipTicks[activeTooltipIndex].value;
        const activePayload: any = getTooltipContent(this.state, this.props.data, activeTooltipIndex);
        const activeCoordinate = tooltipTicks[activeTooltipIndex]
          ? {
              x: layout === 'horizontal' ? tooltipTicks[activeTooltipIndex].coordinate : validateChartX,
              y: layout === 'horizontal' ? validateChartY : tooltipTicks[activeTooltipIndex].coordinate,
            }
          : originCoordinate;

        this.setState({
          ...data,
          activeLabel,
          activeCoordinate,
          activePayload,
          activeTooltipIndex,
        });
      } else {
        this.setState(data);
      }
    }

    verticalCoordinatesGenerator = ({ xAxis, width, height, offset }: ChartCoordinate) =>
      getCoordinatesOfGrid(
        CartesianAxis.getTicks({
          ...CartesianAxis.defaultProps,
          ...xAxis,
          ticks: getTicksOfAxis(xAxis, true),
          viewBox: { x: 0, y: 0, width, height },
        }),
        offset.left,
        offset.left + offset.width,
      );

    horizontalCoordinatesGenerator = ({ yAxis, width, height, offset }: ChartCoordinate) =>
      getCoordinatesOfGrid(
        CartesianAxis.getTicks({
          ...CartesianAxis.defaultProps,
          ...yAxis,
          ticks: getTicksOfAxis(yAxis, true),
          viewBox: { x: 0, y: 0, width, height },
        }),
        offset.top,
        offset.top + offset.height,
      );

    axesTicksGenerator = (axis?: any) => getTicksOfAxis(axis, true);

    filterFormatItem(item: any, displayName: any, childIndex: any) {
      const { formattedGraphicalItems } = this.state;

      for (let i = 0, len = formattedGraphicalItems.length; i < len; i++) {
        const entry = formattedGraphicalItems[i];

        if (
          entry.item === item ||
          entry.props.key === item.key ||
          (displayName === getDisplayName(entry.item.type) && childIndex === entry.childIndex)
        ) {
          return entry;
        }
      }

      return null;
    }

    renderCursor = (element: any) => {
      const { isTooltipActive, activeCoordinate, activePayload, offset, activeTooltipIndex } = this.state;
      const tooltipEventType = this.getTooltipEventType();

      if (
        !element ||
        !element.props.cursor ||
        !isTooltipActive ||
        !activeCoordinate ||
        (chartName !== 'ScatterChart' && tooltipEventType !== 'axis')
      ) {
        return null;
      }
      const { layout } = this.props;
      let restProps;
      let cursorComp: any = Curve;

      if (chartName === 'ScatterChart') {
        restProps = activeCoordinate;
        cursorComp = Cross;
      } else if (chartName === 'BarChart') {
        restProps = this.getCursorRectangle();
        cursorComp = Rectangle;
      } else if (layout === 'radial') {
        const { cx, cy, radius, startAngle, endAngle }: any = this.getCursorPoints();
        restProps = {
          cx,
          cy,
          startAngle,
          endAngle,
          innerRadius: radius,
          outerRadius: radius,
        };
        cursorComp = Sector;
      } else {
        restProps = { points: this.getCursorPoints() };
        cursorComp = Curve;
      }
      const key = element.key || '_recharts-cursor';
      const cursorProps = {
        stroke: '#ccc',
        pointerEvents: 'none',
        ...offset,
        ...restProps,
        ...filterProps(element.props.cursor),
        payload: activePayload,
        payloadIndex: activeTooltipIndex,
        key,
        className: 'recharts-tooltip-cursor',
      };

      return isValidElement(element.props.cursor)
        ? cloneElement(element.props.cursor, cursorProps)
        : createElement(cursorComp, cursorProps);
    };

    renderPolarAxis = (element: any, displayName: string, index: number) => {
      const axisType = _.get(element, 'type.axisType');
      const axisMap = _.get(this.state, `${axisType}Map`);
      const axisOption = axisMap[element.props[`${axisType}Id`]];

      return cloneElement(element, {
        ...axisOption,
        className: axisType,
        key: element.key || `${displayName}-${index}`,
        ticks: getTicksOfAxis(axisOption, true),
      });
    };

    renderXAxis = (element: any, displayName: string, index: number) => {
      const { xAxisMap } = this.state;
      const axisObj = xAxisMap[element.props.xAxisId];

      return this.renderAxis(axisObj, element, displayName, index);
    };

    renderYAxis = (element: any, displayName: string, index: number) => {
      const { yAxisMap } = this.state;
      const axisObj = yAxisMap[element.props.yAxisId];

      return this.renderAxis(axisObj, element, displayName, index);
    };

    /**
     * Draw axis
     * @param {Object} axisOptions The options of axis
     * @param {Object} element      The axis element
     * @param {String} displayName  The display name of axis
     * @param {Number} index        The index of element
     * @return {ReactElement}       The instance of x-axes
     */
    renderAxis(axisOptions: BaseAxisProps, element: any, displayName: string, index: number): React.ReactElement {
      const { width, height } = this.props;

      return (
        <CartesianAxis
          {...(axisOptions as any)}
          className={`recharts-${axisOptions.axisType} ${axisOptions.axisType}`}
          key={element.key || `${displayName}-${index}`}
          viewBox={{ x: 0, y: 0, width, height } as any}
          ticksGenerator={this.axesTicksGenerator}
        />
      );
    }

    /**
     * Draw grid
     * @param  {ReactElement} element the grid item
     * @return {ReactElement} The instance of grid
     */
    renderGrid = (element: React.ReactElement): React.ReactElement => {
      const { xAxisMap, yAxisMap, offset } = this.state;
      const { width, height } = this.props;
      const xAxis = getAnyElementOfObject(xAxisMap);
      const yAxisWithFiniteDomain = _.find(yAxisMap, axis => _.every(axis.domain, isFinit));
      const yAxis = yAxisWithFiniteDomain || getAnyElementOfObject(yAxisMap);
      const props = element.props || {};

      return cloneElement(element, {
        key: element.key || 'grid',
        x: isNumber(props.x) ? props.x : offset.left,
        y: isNumber(props.y) ? props.y : offset.top,
        width: isNumber(props.width) ? props.width : offset.width,
        height: isNumber(props.height) ? props.height : offset.height,
        xAxis,
        yAxis,
        offset,
        chartWidth: width,
        chartHeight: height,
        verticalCoordinatesGenerator: props.verticalCoordinatesGenerator || this.verticalCoordinatesGenerator,
        horizontalCoordinatesGenerator: props.horizontalCoordinatesGenerator || this.horizontalCoordinatesGenerator,
      });
    };

    renderPolarGrid = (element: React.ReactElement): React.ReactElement => {
      const { radialLines, polarAngles, polarRadius } = element.props;
      const { radiusAxisMap, angleAxisMap } = this.state;
      const radiusAxis = getAnyElementOfObject(radiusAxisMap);
      const angleAxis = getAnyElementOfObject(angleAxisMap);
      const { cx, cy, innerRadius, outerRadius } = angleAxis;

      return cloneElement(element, {
        polarAngles: isArray(polarAngles)
          ? polarAngles
          : getTicksOfAxis(angleAxis, true).map((entry: any) => entry.coordinate),
        polarRadius: isArray(polarRadius)
          ? polarRadius
          : getTicksOfAxis(radiusAxis, true).map((entry: any) => entry.coordinate),
        cx,
        cy,
        innerRadius,
        outerRadius,
        key: element.key || 'polar-grid',
        radialLines,
      });
    };

    /**
     * Draw legend
     * @return {ReactElement}            The instance of Legend
     */
    renderLegend = (): React.ReactElement => {
      const { formattedGraphicalItems } = this.state;
      const { children, width, height } = this.props;
      const margin = this.props.margin || {};
      const legendWidth: number = width - (margin.left || 0) - (margin.right || 0);
      const props = getLegendProps({
        children,
        formattedGraphicalItems,
        legendWidth,
        legendContent,
      });

      if (!props) {
        return null;
      }

      const { item, ...otherProps } = props;

      return cloneElement(item, {
        ...otherProps,
        chartWidth: width,
        chartHeight: height,
        margin,
        ref: (legend: any) => {
          this.legendInstance = legend;
        },
        onBBoxUpdate: this.handleLegendBBoxUpdate,
      });
    };

    /**
     * Draw Tooltip
     * @return {ReactElement}  The instance of Tooltip
     */
    renderTooltip = (): React.ReactElement => {
      const { children } = this.props;
      const tooltipItem = findChildByType(children, Tooltip.displayName);

      if (!tooltipItem) {
        return null;
      }

      const { isTooltipActive, activeCoordinate, activePayload, activeLabel, offset } = this.state;

      return cloneElement(tooltipItem, {
        viewBox: { ...offset, x: offset.left, y: offset.top },
        active: isTooltipActive,
        label: activeLabel,
        payload: isTooltipActive ? activePayload : [],
        coordinate: activeCoordinate,
      });
    };

    renderBrush = (element: React.ReactElement) => {
      const { margin, data } = this.props;
      const { offset, dataStartIndex, dataEndIndex, updateId } = this.state;

      // TODO: update brush when children update
      return cloneElement(element, {
        key: element.key || '_recharts-brush',
        onChange: combineEventHandlers(this.handleBrushChange, null, element.props.onChange),
        data,
        x: isNumber(element.props.x) ? element.props.x : offset.left,
        y: isNumber(element.props.y)
          ? element.props.y
          : offset.top + offset.height + offset.brushBottom - (margin.bottom || 0),
        width: isNumber(element.props.width) ? element.props.width : offset.width,
        startIndex: dataStartIndex,
        endIndex: dataEndIndex,
        updateId: `brush-${updateId}`,
      });
    };

    renderReferenceElement = (element: React.ReactElement, displayName: string, index: number): React.ReactElement => {
      if (!element) {
        return null;
      }
      const { clipPathId } = this;
      const { xAxisMap, yAxisMap, offset } = this.state;
      const { xAxisId, yAxisId } = element.props;

      return cloneElement(element, {
        key: element.key || `${displayName}-${index}`,
        xAxis: xAxisMap[xAxisId],
        yAxis: yAxisMap[yAxisId],
        viewBox: {
          x: offset.left,
          y: offset.top,
          width: offset.width,
          height: offset.height,
        },
        clipPathId,
      });
    };

    static renderActiveDot = (option: any, props: any): React.ReactElement => {
      let dot;

      if (isValidElement(option)) {
        dot = cloneElement(option, props);
      } else if (_.isFunction(option)) {
        dot = option(props);
      } else {
        dot = <Dot {...props} />;
      }

      return (
        <Layer className="recharts-active-dot" key={props.key}>
          {dot}
        </Layer>
      );
    };

    renderActivePoints = ({ item, activePoint, basePoint, childIndex, isRange }: any) => {
      const result = [];
      const { key } = item.props;
      const { activeDot, dataKey } = item.item.props;
      const dotProps = {
        index: childIndex,
        dataKey,
        cx: activePoint.x,
        cy: activePoint.y,
        r: 4,
        fill: getMainColorOfGraphicItem(item.item),
        strokeWidth: 2,
        stroke: '#fff',
        payload: activePoint.payload,
        value: activePoint.value,
        key: `${key}-activePoint-${childIndex}`,
        ...filterProps(activeDot),
        ...adaptEventHandlers(activeDot),
      };

      result.push(CategoricalChartWrapper.renderActiveDot(activeDot, dotProps));

      if (basePoint) {
        result.push(
          CategoricalChartWrapper.renderActiveDot(activeDot, {
            ...dotProps,
            cx: basePoint.x,
            cy: basePoint.y,
            key: `${key}-basePoint-${childIndex}`,
          }),
        );
      } else if (isRange) {
        result.push(null);
      }

      return result;
    };

    renderGraphicChild = (element: React.ReactElement, displayName: string, index: number): any[] => {
      const item = this.filterFormatItem(element, displayName, index);
      if (!item) {
        return null;
      }

      const tooltipEventType = this.getTooltipEventType();
      const { isTooltipActive, tooltipAxis, activeTooltipIndex, activeLabel } = this.state;
      const { children } = this.props;
      const tooltipItem = findChildByType(children, Tooltip.displayName);
      const { points, isRange, baseLine } = item.props;
      const { activeDot, hide } = item.item.props;
      const hasActive = !hide && isTooltipActive && tooltipItem && activeDot && activeTooltipIndex >= 0;
      let itemEvents = {};

      if (tooltipEventType !== 'axis' && tooltipItem && tooltipItem.props.trigger === 'click') {
        itemEvents = {
          onClick: combineEventHandlers(this.handleItemMouseEnter, null, element.props.onCLick),
        };
      } else if (tooltipEventType !== 'axis') {
        itemEvents = {
          onMouseLeave: combineEventHandlers(this.handleItemMouseLeave, null, element.props.onMouseLeave),
          onMouseEnter: combineEventHandlers(this.handleItemMouseEnter, null, element.props.onMouseEnter),
        };
      }

      const graphicalItem = cloneElement(element, { ...item.props, ...itemEvents });

      function findWithPayload(entry: any) {
        // TODO needs to verify dataKey is Function
        return typeof tooltipAxis.dataKey === 'function' ? tooltipAxis.dataKey(entry.payload) : null;
      }

      if (hasActive) {
        let activePoint, basePoint;

        if (tooltipAxis.dataKey && !tooltipAxis.allowDuplicatedCategory) {
          // number transform to string
          const specifiedKey =
            typeof tooltipAxis.dataKey === 'function'
              ? findWithPayload
              : 'payload.'.concat(tooltipAxis.dataKey.toString());
          activePoint = findEntryInArray(points, specifiedKey, activeLabel);
          basePoint = isRange && baseLine && findEntryInArray(baseLine, specifiedKey, activeLabel);
        } else {
          activePoint = points[activeTooltipIndex];
          basePoint = isRange && baseLine && baseLine[activeTooltipIndex];
        }

        if (!_.isNil(activePoint)) {
          return [
            graphicalItem,
            ...this.renderActivePoints({
              item,
              activePoint,
              basePoint,
              childIndex: activeTooltipIndex,
              isRange,
            }),
          ];
        }
      }

      if (isRange) {
        return [graphicalItem, null, null];
      }

      return [graphicalItem, null];
    };

    renderCustomized = (element: React.ReactElement, displayName: string, index: number): React.ReactElement =>
      cloneElement(element, {
        key: `recharts-customized-${index}`,
        ...this.props,
        ...this.state,
      });

    renderClipPath() {
      const { clipPathId } = this;
      const {
        offset: { left, top, height, width },
      } = this.state;

      return (
        <defs>
          <clipPath id={clipPathId}>
            <rect x={left} y={top} height={height} width={width} />
          </clipPath>
        </defs>
      );
    }

    public getXScales() {
      const { xAxisMap } = this.state;

      return xAxisMap
        ? Object.entries(xAxisMap).reduce(
            (res: Record<string, Function>, [axisId, axisProps]: [string, BaseAxisProps]) => {
              return { ...res, [axisId]: (axisProps as BaseAxisProps).scale };
            },
            {},
          )
        : null;
    }

    public getYScales() {
      const { yAxisMap } = this.state;

      return yAxisMap
        ? Object.entries(yAxisMap).reduce(
            (res: Record<string, Function>, [axisId, axisProps]: [string, BaseAxisProps]) => {
              return { ...res, [axisId]: (axisProps as BaseAxisProps).scale };
            },
            {},
          )
        : null;
    }

    public getXScaleByAxisId(axisId: string) {
      return this.state.xAxisMap?.[axisId]?.scale;
    }

    public getYScaleByAxisId(axisId: string) {
      return this.state.yAxisMap?.[axisId]?.scale;
    }

    public getItemByXY(chartXY: { x: number; y: number }) {
      const { formattedGraphicalItems } = this.state;

      if (formattedGraphicalItems && formattedGraphicalItems.length) {
        for (let i = 0, len = formattedGraphicalItems.length; i < len; i++) {
          const graphicalItem = formattedGraphicalItems[i];
          const { props, item } = graphicalItem;
          const itemDisplayName = getDisplayName(item.type);

          if (itemDisplayName === 'Bar') {
            const activeBarItem = (props.data || []).find(
              (entry: { x: number; y: number; width: number; height: number }) => {
                return isInRectangle(chartXY, entry);
              },
            );

            if (activeBarItem) {
              return { graphicalItem, payload: activeBarItem };
            }
          } else if (itemDisplayName === 'RadialBar') {
            const activeBarItem = (props.data || []).find((entry: GeometrySector) => {
              return inRangeOfSector(chartXY, entry);
            });

            if (activeBarItem) {
              return { graphicalItem, payload: activeBarItem };
            }
          }
        }
      }

      return null;
    }

    render() {
      if (!validateWidthHeight(this)) {
        return null;
      }

      const { children, className, width, height, style, compact, title, desc, ...others } = this.props;
      const attrs = filterProps(others);
      const map = {
        CartesianGrid: { handler: this.renderGrid, once: true },
        ReferenceArea: { handler: this.renderReferenceElement },
        ReferenceLine: { handler: this.renderReferenceElement },
        ReferenceDot: { handler: this.renderReferenceElement },
        XAxis: { handler: this.renderXAxis },
        YAxis: { handler: this.renderYAxis },
        Brush: { handler: this.renderBrush, once: true },
        Bar: { handler: this.renderGraphicChild },
        Line: { handler: this.renderGraphicChild },
        Area: { handler: this.renderGraphicChild },
        Radar: { handler: this.renderGraphicChild },
        RadialBar: { handler: this.renderGraphicChild },
        Scatter: { handler: this.renderGraphicChild },
        Pie: { handler: this.renderGraphicChild },
        Funnel: { handler: this.renderGraphicChild },
        Tooltip: { handler: this.renderCursor, once: true },
        PolarGrid: { handler: this.renderPolarGrid, once: true },
        PolarAngleAxis: { handler: this.renderPolarAxis },
        PolarRadiusAxis: { handler: this.renderPolarAxis },
        Customized: { handler: this.renderCustomized },
      } as any;

      // The "compact" mode is mainly used as the panorama within Brush
      if (compact) {
        return (
          <Surface {...attrs} width={width} height={height} title={title} desc={desc}>
            {this.renderClipPath()}
            {renderByOrder(children, map)}
          </Surface>
        );
      }

      const events = this.parseEventsOfWrapper();
      return (
        <div
          className={classNames('recharts-wrapper', className)}
          style={{ position: 'relative', cursor: 'default', width, height, ...style }}
          {...events}
          ref={node => {
            this.container = node;
          }}
        >
          <Surface {...attrs} width={width} height={height} title={title} desc={desc}>
            {this.renderClipPath()}
            {renderByOrder(children, map)}
          </Surface>
          {this.renderLegend()}
          {this.renderTooltip()}
        </div>
      );
    }
  };
};


text: A messaging hub that can be accessed from the web or any mobile phone.


text:
@(elements : helper.FieldElements)

@import views.tags.forms.FormHelper.addClassValue

@input = @{
  if(elements.hasErrors) {
    addClassValue(elements.input.toString(), "form-control is-invalid")
  } else {
    addClassValue(elements.input.toString(), "form-control")
  }
}

@elements.label

  @Html(input)
  @elements.errors.mkString(", ")
  @elements.infos.mkString(", ")


text:
package org.micropython.jnupy;

public class JavaObject {
    private Object obj;

    public JavaObject(Object obj) {
        this.obj = obj;
    }

    public Object getObject() {
        return this.obj;
    }

    // TODO: implement __getitem__, etc thing.
    //       but never impl with __call__?
}


text:
__revision__ = "test/scons-time/time/no-args.py rel_2.5.1:3735:9dc6cee5c168 2016/11/03 14:02:02 bdbaddog"

"""
Verify the error when the time subcommand is passed no arguments.
"""

import TestSCons_time

test = TestSCons_time.TestSCons_time()

expect = """\
scons-time: mem: No arguments specified.
            No *.log files found in "%s".
            Type "scons-time help mem" for help.
""" % test.workpath()

test.run(arguments = 'mem', status = 1, stderr = expect)

test.pass_test()

# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:


text:
import bisect
import logging

import numpy as np
from scipy.misc import toimage

from .media import apply_colormap
from utils import cached_property, ProgressProxy

log = logging.getLogger(__name__)

class Composition(object):
    def __init__(self, sound,
                 scale_resolution=1/36, omega0=70):
        self.sound = sound
        self.scale_resolution = scale_resolution
        self.omega0 = omega0

        # samplerate = sound.samples / sound.duration
        self.samplerate = sound.samplerate

        self.block_size = 2 ** 17
        self.decimate = 2 ** int(np.log2(self.samplerate) - 8)

        self._wbox = None

    def __enter__(self):
        from .wavelet.intel_backend import WaveletBox

        self._wbox = WaveletBox(
            self.block_size,
            samplerate=self.samplerate,
            scale_resolution=self.scale_resolution,
            omega0=self.omega0
        )

        return self

    def __exit__(self, exc_type, exc_value, tb):
        # FIXME cache wbox or free resources
        self._wbox = None

    def get_complex_image(self, progressbar=None):
        if not self._wbox:
            raise RuntimeError('You need to use {} in a with block'.
                               format(self.__class__.__name__))

        if not progressbar:
            progressbar = ProgressProxy

        return self._wbox.sound_apply_cwt(
            self.sound, progressbar, decimate=self.decimate
        )

    def get_spectrogram(self, progressbar=None):
        complex_image = self.get_complex_image(progressbar)

        return Spectrogram(
            abs_image=np.abs(complex_image),
            sound=self.sound,
            frequencies=self._wbox.frequencies
        )

class Spectrogram(object):
    def __init__(self, abs_image, sound, frequencies):
        self.abs_image = abs_image
        self.image = toimage(apply_colormap(self.abs_image))
        self.width, self.height = self.image.size
        self.sound = sound
        self.frequencies = frequencies
        self.reversed_frequencies = list(reversed(frequencies))

    def x2time(self, x):
        """
        Assume self.width and self.sound.size equal
        """
        return self.sound.x2time(x * self.sound.size / self.width)

    def time2x(self, time):
        """
        Assume self.width and self.sound.size equal
        """
        return int(self.sound.time2x(time) * self.width / self.sound.size)

    def y2freq(self, y):
        return np.interp(
            [y],
            np.linspace(0, self.height - 1, len(self.frequencies)),
            self.frequencies
        )[0]

    def freq2y(self, f):
        return self.height - bisect.bisect(self.reversed_frequencies, f)

    def get_sound_fragment(self, x1x2, y1y2):
        time_band = tuple(map(self.x2time, x1x2))
        frequency_band = tuple(map(self.y2freq, y1y2))

        return self.sound.get_fragment(time_band, frequency_band)


text:
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class p_kategori extends Model
{
    protected $fillable = ['nama_kategori'];
    protected $table = 'p_kategori';
    protected $primaryKey = 'p_kategori_id';
}


text:
/*
 * This is a basic func test for a Common application.
 */
YUI.add('common-testlazyloadrpcclient-tests', function (Y) {

    var suite = new Y.Test.Suite("Common: LazyLoadRPCClient");

    suite.add(new Y.Test.Case({

        "test LazyLoadRPCClient": function() {
            var that = this;
            Y.one('#lazyloadrpcButton').simulate('click');
            that.wait(function(){
                Y.Assert.areEqual('Lazy load succeeded:', Y.one('#LazyLoadRPCtitle').get('innerHTML'));
                Y.Assert.areEqual('foo-value set by binder', Y.one('#LazyLoadRPCfoo').get('innerHTML'));
                Y.Assert.areEqual('bar-value set by controller', Y.one('#LazyLoadRPCbar').get('innerHTML'));
                Y.Assert.areEqual('From controller: foo-value set by binder', Y.one('#LazyLoadRPCbaz').get('innerHTML'));
                Y.Assert.areEqual('Data has changed: 2 times', Y.one('#LazyLoadRPCcount').get('innerHTML'));
            }, 2000);
        }

    }));
    Y.Test.Runner.add(suite);

}, '0.0.1', { requires: [
    'node', 'node-event-simulate', 'test', 'console'
]});


text:
import logging.config
import os

import logging_tree

from structlog import configure, dev, get_logger, processors, stdlib

class StructlogHandler(logging.Handler):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._log = get_logger()

    def emit(self, record):
        kw = {k: getattr(record, k) for k in {'exc_info', 'exc_text', 'args'}
              if getattr(record, k)}
        try:
            message = record.msg % record.args
        except TypeError:
            message = record.msg
        if len(message) > 100:
            message = message[:100] + ' [TRUNCATED]'
        kw['full_message'] = message
        self._log.log(record.levelno, record.msg,
                      logger_name=record.name, **kw)

def fix_logger_name(logger, method_name, event_dict):
    """
    Captured stdlib logging messages have logger=feedhq.logging and
    logger_name=original_logger_name. Overwrite logger with correct name.
    """
    if 'logger_name' in event_dict:
        event_dict['logger'] = event_dict.pop('logger_name')
    return event_dict

OBFUSCATE_HEADERS = {'Authorization', 'Cookie'}

def get_headers(request, obfuscate=OBFUSCATE_HEADERS):
    headers = {k for k in request.META if k.startswith('HTTP_')}
    pretty_headers = {}
    for header in headers:
        key = "-".join([
            w.capitalize() for w in header[len('HTTP_'):].split('_')
        ])
        pretty_headers[key] = request.META[header]
    for key in set(pretty_headers.keys()).intersection(obfuscate):
        if pretty_headers[key]:
            pretty_headers[key] = '**********'
        else:
            pretty_headers.pop(key)
    for key in ['Content-Type', 'Content-Length']:
        meta_key = key.upper().replace('-', '_')
        if meta_key in request.META:
            pretty_headers[key] = request.META[meta_key]
    return pretty_headers

def format_request(logger, method_name, event_dict):
    """Add request attrs when available:
        - URL
        - headers
        - querystring
        - User info
        - JSON/POST data
    """
    if 'request' in event_dict:
        req = event_dict['request']
        # Can't rely on instance checks because django's http request must
        # not be imported too soon.
        if 'rest_framework.request.Request' in str(type(req)):
            event_dict['request'] = {
                'method': req.method,
                'headers': get_headers(req),
                'path': req.path,
                'querystring': req.query_params,
                'user_id': req.user.pk,
            }
        elif 'django.http.request.HttpRequest' in str(type(req)):
            event_dict['request'] = {
                'method': req.method,
                'headers': get_headers(req),
                'path': req.path,
                'querystring': dict(req.GET),
                'user_id': req.user.pk,
            }
    return event_dict

def ensure_event(_, __, event_dict):
    event_dict.setdefault('event', '(no message)')
    return event_dict

def logstash_processor(_, __, event_dict):
    """
    Adds @version field for Logstash.
    Puts event in a 'message' field.
    Serializes timestamps in ISO format.
    """
    if 'message' in event_dict and 'full_message' not in event_dict:
        event_dict['full_message'] = event_dict['message']
    event_dict['message'] = event_dict.pop('event', '')
    for key, value in event_dict.items():
        if hasattr(value, 'isoformat') and callable(value.isoformat):
            event_dict[key] = value.isoformat() + 'Z'
    event_dict['@version'] = 1
    event_dict['_type'] = event_dict['type'] = 'feedhq'
    return event_dict

def add_syslog_program(syslog):
    pid = os.getpid()

    def renderer(_, __, message):
        if syslog:
            return 'feedhq[{}]: {}'.format(pid, message)
        return message
    return renderer

def root(lvl):
    return {'handlers': ['root'],
            'level': lvl,
            'propagate': False}

def configure_logging(debug=False, syslog=False, silenced_loggers=None,
                      level_overrides=None):
    if silenced_loggers is None:
        silenced_loggers = []
    if level_overrides is None:
        level_overrides = {}
    level = 'DEBUG' if debug else 'INFO'
    renderers = [
        dev.ConsoleRenderer(),
    ] if debug else [
        logstash_processor,
        processors.JSONRenderer(separators=(',', ':')),
        add_syslog_program(syslog),
    ]
    structlog_processors = [
        stdlib.filter_by_level,
        stdlib.add_logger_name,
        stdlib.add_log_level,
        fix_logger_name,
        format_request,
        ensure_event,
        stdlib.PositionalArgumentsFormatter(),
        processors.TimeStamper(fmt="ISO", key='@timestamp'),
        processors.StackInfoRenderer(),
        processors.format_exc_info,
    ] + renderers

    configure(
        processors=structlog_processors,
        context_class=dict,
        logger_factory=stdlib.LoggerFactory(),
        wrapper_class=stdlib.BoundLogger,
        cache_logger_on_first_use=True,
    )

    structlog = {'handlers': ['raw'],
                 'level': level,
                 'propagate': False}
    null = {'handlers': ['null'],
            'propagate': False}
    loggers = {l: root(level_overrides.get(l, level))
               for l, _, _ in logging_tree.tree()[2]}
    loggers['feedhq'] = structlog

    for nulled_logger in silenced_loggers:
        loggers[nulled_logger] = null

    raw = {
        'level': level,
        'class': 'logging.handlers.SysLogHandler',
        'address': '/dev/log',
        'facility': 'local0',
    } if syslog else {
        'level': level,
        'class': 'logging.StreamHandler',
    }

    return {
        'version': 1,
        'level': level,
        'handlers': {
            'root': {
                'level': level,
                '()': StructlogHandler,
            },
            'raw': raw,
            'null': {
                'class': 'logging.NullHandler',
            },
        },
        'loggers': loggers,
        'root': root(level),
    }


text:
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace UMA
{
    [System.Serializable]
    public class AssetItem
#if UNITY_EDITOR
        : System.IEquatable<AssetItem>, System.IComparable<AssetItem>
#endif
    {
        #region Fields
        private System.Type _TheType;
        public string _BaseTypeName;
        public string _Name;
        public Object _SerializedItem;
        public string _Path;
		public string _Guid;
        public bool IsResource;
        public bool IsAssetBundle;
        #endregion
        #region Properties
        public System.Type _Type
        {
            get
            {
                if (_TheType != null) return _TheType;

                _TheType = UMAAssetIndexer.TypeFromString[_BaseTypeName];
                return _TheType;
            }
        }

        public AssetItem CreateSerializedItem(bool ForceItemSave)
        {
            if (ForceItemSave)
            {
                // If this flag is set, then we must serialize the item also (this is used when building the executable).
                return new AssetItem(this._Type, this._Name, this._Path, this.Item);
            }
            else
            {
                return new AssetItem(this._Type, this._Name, this._Path, null);
            }
        }

        public Object Item
        {
            get
            {
#if UNITY_EDITOR
                if (_SerializedItem != null) return _SerializedItem;
				CachSerializedItem();
                return _SerializedItem;
#else
                return _SerializedItem;
#endif
            }
        }

        public string _AssetBaseName
        {
            get
            {
                return System.IO.Path.GetFileNameWithoutExtension(_Path);
            }
        }

		public void CachSerializedItem()
		{
			#if UNITY_EDITOR
			if (_SerializedItem != null) return;
			_SerializedItem = AssetDatabase.LoadAssetAtPath(_Path, _Type);
			if (_SerializedItem == null)
			{
				// uhoh. It's gone.
				if (!string.IsNullOrEmpty(_Guid))
				{
					// at least we have a guid. Let's try to find it from that...
					_Path = AssetDatabase.GUIDToAssetPath(_Guid);
					if (!string.IsNullOrEmpty(_Path))
					{
						_SerializedItem = AssetDatabase.LoadAssetAtPath(_Path,_Type);
					}
				}
				// No guid, or couldn't even find by GUID.
				// Let's search for it?
				if (_SerializedItem == null)
				{
					string s = _Type.Name;
					string[] guids = AssetDatabase.FindAssets(_Name+ " t:" + s);
					if (guids.Length > 0)
					{
						_Guid = guids[0];
						_Path = AssetDatabase.GUIDToAssetPath(_Guid);
						_SerializedItem = AssetDatabase.LoadAssetAtPath(_Path, _Type);
					}
				}
			}
			#endif
		}

        public string EvilName
        {
            get
            {
                Object o = Item;

                if (!o)
                {
                    return "<Not Found!>";
                }
                if (o is SlotDataAsset)
                {
                    SlotDataAsset sd = o as SlotDataAsset;
                    return sd.slotName;
                }
                if (o is OverlayDataAsset)
                {
                    OverlayDataAsset od = o as OverlayDataAsset;
                    return od.overlayName;
                }
                if (o is RaceData)
                {
                    return (o as RaceData).raceName;
                }

                return o.name;
            }
        }
        #endregion
        #region Methods (edit time)
#if UNITY_EDITOR

        public void ReleaseItem()
        {
            _SerializedItem = null;
        }

        public string ToString(string SortOrder)
        {
            if (SortOrder == "AssetName")
                return _AssetBaseName;
            if (SortOrder == "FilePath")
                return _Path;
            return _Name;
        }

        public bool Equals(AssetItem other)
        {
            if (other == null)
                return false;

            if (UMAAssetIndexer.SortOrder == "AssetName")
            {
                if (this._AssetBaseName == other._AssetBaseName)
                    return true;
                else
                    return false;
            }

            if (UMAAssetIndexer.SortOrder == "FilePath")
            {
                if (this._Path == other._Path)
                    return true;
                else
                    return false;

            }

            if (this._Name == other._Name)
                return true;

            return false;
        }

        public int CompareTo(AssetItem other)
        {
            // A null value means that this object is greater.
            if (other == null)
                return 1;

            if (UMAAssetIndexer.SortOrder == "AssetName")
            {
                return (this._AssetBaseName.CompareTo(other._AssetBaseName));
            }

            if (UMAAssetIndexer.SortOrder == "FilePath")
            {
                return this._Path.CompareTo(other._Path);
            }

            return this._Name.CompareTo(other._Name);
        }

#endif
        #endregion
        #region Constructors
        public AssetItem(System.Type Type, string Name, string Path, Object Item)
        {
            if (Type == null) return;
            _TheType = Type;
            _BaseTypeName = Type.Name;
            _Name = Name;
            _SerializedItem = Item;
            _Path = Path;
			#if UNITY_EDITOR
			_Guid = AssetDatabase.AssetPathToGUID(_Path);
			#endif
        }
        public AssetItem(System.Type Type, Object Item)
        {
            if (Type == null) return;
#if UNITY_EDITOR
            _Path = AssetDatabase.GetAssetPath(Item.GetInstanceID());
			_Guid = AssetDatabase.AssetPathToGUID(_Path);
#endif
            _TheType = Type;
            _BaseTypeName = Type.Name;
            _SerializedItem = Item;
            _Name = EvilName;
        }
        #endregion
    }
}


text:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PlanterApp.Domain;

namespace UnitTests
{
    [TestClass]
    public class TrayTests
    {
        [TestMethod]
        public void TestAddPlant()
        {
            var tray = new Tray();
            var plant = new Plant(1);

            tray.AddPlant(plant);

            foreach (var p in tray.Plants)
            {
                Assert.AreSame(plant, p);
            }
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void TestDoubleAddPlant()
        {
            var tray = new Tray();
            var plant = new Plant(1);

            tray.AddPlant(plant);
            tray.AddPlant(plant);
        }

        [TestMethod]
        public void TestRemovePlant()
        {
            var tray = new Tray();
            var plant = new Plant(1);

            Assert.IsFalse(tray.RemovePlant(plant));

            tray.AddPlant(plant);
            Assert.IsTrue(tray.RemovePlant(plant));

            Assert.IsFalse(tray.RemovePlant(plant));
        }

        [TestMethod]
        public void TestShuffle()
        {
            var tray = new Tray();
            tray.AddPlant(new Plant(1));
            tray.AddPlant(new Plant(2));
            tray.AddPlant(new Plant(3));
            tray.AddPlant(new Plant(4));
            tray.AddPlant(new Plant(5));
            tray.Shuffle();
        }
    }
}


text:
package com.amazonaws.services.quicksight.model.transform;

import java.math.*;

import javax.annotation.Generated;

import com.amazonaws.services.quicksight.model.*;
import com.amazonaws.transform.SimpleTypeJsonUnmarshallers.*;
import com.amazonaws.transform.*;

import com.fasterxml.jackson.core.JsonToken;
import static com.fasterxml.jackson.core.JsonToken.*;

/**
 * DescribeDataSourcePermissionsResult JSON Unmarshaller
 */
@Generated("com.amazonaws:aws-java-sdk-code-generator")
public class DescribeDataSourcePermissionsResultJsonUnmarshaller implements Unmarshaller<DescribeDataSourcePermissionsResult, JsonUnmarshallerContext> {

    public DescribeDataSourcePermissionsResult unmarshall(JsonUnmarshallerContext context) throws Exception {
        DescribeDataSourcePermissionsResult describeDataSourcePermissionsResult = new DescribeDataSourcePermissionsResult();

        describeDataSourcePermissionsResult.setStatus(context.getHttpResponse().getStatusCode());

        int originalDepth = context.getCurrentDepth();
        String currentParentElement = context.getCurrentParentElement();
        int targetDepth = originalDepth + 1;

        JsonToken token = context.getCurrentToken();
        if (token == null)
            token = context.nextToken();
        if (token == VALUE_NULL) {
            return describeDataSourcePermissionsResult;
        }

        while (true) {
            if (token == null)
                break;

            if (token == FIELD_NAME || token == START_OBJECT) {
                if (context.testExpression("DataSourceArn", targetDepth)) {
                    context.nextToken();
                    describeDataSourcePermissionsResult.setDataSourceArn(context.getUnmarshaller(String.class).unmarshall(context));
                }
                if (context.testExpression("DataSourceId", targetDepth)) {
                    context.nextToken();
                    describeDataSourcePermissionsResult.setDataSourceId(context.getUnmarshaller(String.class).unmarshall(context));
                }
                if (context.testExpression("Permissions", targetDepth)) {
                    context.nextToken();
                    describeDataSourcePermissionsResult.setPermissions(new ListUnmarshaller<ResourcePermission>(ResourcePermissionJsonUnmarshaller
                            .getInstance())

                    .unmarshall(context));
                }
                if (context.testExpression("RequestId", targetDepth)) {
                    context.nextToken();
                    describeDataSourcePermissionsResult.setRequestId(context.getUnmarshaller(String.class).unmarshall(context));
                }
            } else if (token == END_ARRAY || token == END_OBJECT) {
                if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) {
                    if (context.getCurrentDepth() <= originalDepth)
                        break;
                }
            }
            token = context.nextToken();
        }

        return describeDataSourcePermissionsResult;
    }

    private static DescribeDataSourcePermissionsResultJsonUnmarshaller instance;

    public static DescribeDataSourcePermissionsResultJsonUnmarshaller getInstance() {
        if (instance == null)
            instance = new DescribeDataSourcePermissionsResultJsonUnmarshaller();
        return instance;
    }
}


text:
RSpec.describe FipExtractor::Request do
  subject { described_class.new }

  describe '#call' do
    let(:response_class) { double(:response_class) }
    let(:request) { double(:request) }

    before do
      expect(subject).to receive_messages(response_class: response_class, request: request)
      expect(response_class).to receive(:new).with(request).and_return(response)
    end

    context 'successfully response' do
      let(:response) { double(:response, error?: false) }
      it do
        expect(subject.call).to eq(response)
      end
    end

    context 'unsuccessfully response' do
      let(:response) { double(:response, error?: true) }
      it do
        expect { subject.call }.to(
          raise_error(FipExtractor::ResourceNotFoundError)
        )
      end
    end
  end

  describe '#request' do
    let(:request_instance) { double(:request_instance, post: true) }
    let(:resource) { 'resource' }
    let(:headers) { 'headers' }
    let(:route) { 'route' }

    it do
      allow(subject).to receive(:route).and_return(route)
      allow(subject).to receive(:resource).and_return(resource)
      allow(subject).to receive(:headers).and_return(headers)
      expect(Faraday).to(
        receive(:new)
        .with(url: resource, headers: headers)
        .and_return(request_instance)
      )
      subject.request
    end
  end

  describe '#params' do
    it { expect(subject.params).to eq({}) }
  end

  describe '#resource' do
    it do
      expect(subject).to receive(:route).and_return('resource_route')
      expect(subject.resource).to eq('https://veiculos.fipe.org.br/api/veiculos/resource_route')
    end
  end

  describe '#route' do
    it { expect{ subject.route }.to raise_error(FipExtractor::RouteNotFoundError) }
  end

  describe '#base_url' do
    it do
      expect(subject.base_url).to eq("https://veiculos.fipe.org.br/api/veiculos")
    end
  end

  describe '#response_class' do
    it do
      stub_const('FipExtractor::RequestResponse', Class.new)
      expect(subject).to receive(:class).and_return(FipExtractor::Request)
      expect(subject.response_class).to eq(FipExtractor::RequestResponse)
    end
  end
end