// See http://dygraphs.com/data.html
428983
func (p *Plot) data() (dataPoints, []string, error) {
	var (
		series []*timeSeries
		count  int
	)

	for _, as := range p.series {
		for _, s := range as.series {
			if s != nil {
				series = append(series, s)
				count += s.len
			}
		}
	}

	var (
		size   = 1 + len(series)
		nan    = math.NaN()
		labels = make([]string, size)
		data   = make(dataPoints, 0, count)
	)

	labels[0] = "Seconds"

	sort.Slice(series, func(i, j int) bool {
		return series[i].attack+series[i].label <
			series[j].attack+series[j].label
	})

	for i, s := range series {
		points, err := lttb.Downsample(s.len, p.threshold, s.iter())
		if err != nil {
			return nil, nil, err
		}

		for _, p := range points {
			pt := make([]float64, size)
			for j := range pt {
				pt[j] = nan
			}
			pt[0], pt[i+1] = p.X, p.Y
			data = append(data, pt)
		}

		labels[i+1] = s.attack + ": " + s.label
	}

	sort.Sort(data)

	return data, labels, nil
}
556685
func (s *memoryStore) Graph(ctx context.Context, id string) (storage.Graph, error) {
	s.rwmu.RLock()
	defer s.rwmu.RUnlock()
	if g, ok := s.graphs[id]; ok {
		return g, nil
	}
	return nil, fmt.Errorf("memory.Graph(%q): graph does not exist", id)
}
636739
func (f Float64Data) Pearson(d Float64Data) (float64, error) {
	return Pearson(f, d)
}
238299
func (gt GraphType) String() string {
	if gt == DIGRAPH {
		return "digraph"
	} else if gt == GRAPH {
		return "graph"
	} else if gt == SUBGRAPH {
		return "subgraph"
	}
	return "(invalid)"
}
31626
func (charts *ChartData) Chart(chartID, zoomString string) ([]byte, error) {
	zoom := ParseZoom(zoomString)
	cache, found, cacheID := charts.getCache(chartID, zoom)
	if found && cache.cacheID == cacheID {
		return cache.data, nil
	}
	maker, hasMaker := chartMakers[chartID]
	if !hasMaker {
		return nil, UnknownChartErr
	}
	// Do the locking here, rather than in encodeXY, so that the helper functions
	// (accumulate, btw) are run under lock.
	charts.mtx.RLock()
	data, err := maker(charts, zoom)
	charts.mtx.RUnlock()
	if err != nil {
		return nil, err
	}
	charts.cacheChart(chartID, zoom, data)
	return data, nil
}
1023877
func (g *Graph) Dot(opts *DotOpts) []byte {
	return newMarshalGraph("", g).Dot(opts)
}
1353095
func TicketPoolData(interval dbtypes.TimeBasedGrouping, height int64) (timeGraph *dbtypes.PoolTicketsData,
	priceGraph *dbtypes.PoolTicketsData, donutChart *dbtypes.PoolTicketsData, actualHeight int64, intervalFound, isStale bool) {
	ticketPoolGraphsCache.RLock()
	defer ticketPoolGraphsCache.RUnlock()

	var tFound, pFound, dFound bool
	timeGraph, tFound = ticketPoolGraphsCache.TimeGraphCache[interval]
	priceGraph, pFound = ticketPoolGraphsCache.PriceGraphCache[interval]
	donutChart, dFound = ticketPoolGraphsCache.DonutGraphCache[interval]
	intervalFound = tFound && pFound && dFound

	actualHeight = ticketPoolGraphsCache.Height[interval]
	isStale = ticketPoolGraphsCache.Height[interval] != height

	return
}
161962
func (c *ScatterChart) AddData(name string, data []EPoint, plotstyle PlotStyle, style Style) {

	// Update styles if non given
	if plotstyle.undefined() {
		plotstyle = PlotStylePoints
	}
	if style.empty() {
		style = AutoStyle(len(c.Data), false)
	}
	// Fix missing values in style
	if (plotstyle & PlotStyleLines) != 0 {
		if style.LineWidth <= 0 {
			style.LineWidth = 1
		}
		if style.LineColor == nil {
			style.LineColor = style.SymbolColor
		}
	}
	if (plotstyle&PlotStylePoints) != 0 && style.Symbol == 0 {
		style.Symbol = '#'
	}

	// Init axis
	if len(c.Data) == 0 {
		c.XRange.init()
		c.YRange.init()
	}

	// Add data
	scd := ScatterChartData{Name: name, PlotStyle: plotstyle, Style: style, Samples: data, Func: nil}
	c.Data = append(c.Data, scd)

	// Autoscale
	for _, d := range data {
		xl, yl, xh, yh := d.BoundingBox()
		c.XRange.autoscale(xl)
		c.XRange.autoscale(xh)
		c.YRange.autoscale(yl)
		c.YRange.autoscale(yh)
	}

	// Add key/legend entry
	if name != "" {
		ke := KeyEntry{Style: style, PlotStyle: plotstyle, Text: name}
		c.Key.Entries = append(c.Key.Entries, ke)
	}
}
547213
func (t *ActivatedTask) WalkGraph(req *dm.WalkGraphReq) (*dm.GraphData, error) {
	newReq := *req
	newReq.Auth = t.Auth
	return t.s.WalkGraph(t.c, &newReq)
}
474169
func (pgb *ChainDB) getChartData(data map[string]*dbtypes.ChartsData,
	chartT string) *dbtypes.ChartsData {
	cData := data[chartT]
	if cData == nil {
		cData = new(dbtypes.ChartsData)
	}
	return cData
}
816264
func (sc *StripChart) AddData(name string, data []float64, style Style) {
	n := len(sc.ScatterChart.Data) + 1
	pd := make([]EPoint, len(data))
	nan := math.NaN()
	for i, d := range data {
		pd[i].X = d
		pd[i].Y = float64(n)
		pd[i].DeltaX, pd[i].DeltaY = nan, nan
	}
	if style.empty() {
		style = AutoStyle(len(sc.Data), false)
	}
	style.LineStyle = 0
	sc.ScatterChart.AddData(name, pd, PlotStylePoints, style)
}
915198
func (m schemaMap) Data(
	s *terraform.InstanceState,
	d *terraform.InstanceDiff) (*ResourceData, error) {
	return &ResourceData{
		schema:       m,
		state:        s,
		diff:         d,
		panicOnError: m.panicOnError(),
	}, nil
}
1172513
func JSON2Dot(r io.Reader) ([]byte, error) {
	g, err := decodeGraph(r)
	if err != nil {
		return nil, err
	}

	return g.Dot(nil), nil
}
1171083
func (pd *pingData) data() (float64, float64) {
	if pd.updated {
		pd.Lock()

		// Calculate the mean
		var accumulator float64
		for _, d := range pd.pings {
			accumulator += float64(d)
		}
		pd.lastMean = accumulator / float64(len(pd.pings))

		// Subtract the mean and square the result; calculcate the mean
		accumulator = 0.0 // Reusing accumulator.
		for _, d := range pd.pings {
			diff := pd.lastMean - float64(d)
			accumulator += math.Pow(diff, 2.0)
		}
		squareDiffMean := accumulator / float64(len(pd.pings))

		// Sqrt the square diffs mean and we have our stddev
		pd.lastStddev = math.Sqrt(squareDiffMean)

		pd.updated = false

		pd.Unlock()
	}

	return pd.lastMean, pd.lastStddev
}
542575
func (t *PairTree) Data() []Pair {
	arr := make([]Pair, t.Len())
	var i int
	i = 0
	t.Do(func(v Pair) bool {
		arr[i] = v
		i++
		return true
	})
	return arr
}
1327867
func (col Color) Xyy() (x, y, Y float64) {
	return XyzToXyy(col.Xyz())
}
928340
func (e GaugeDelta) Stats() []string {
	return []string{fmt.Sprintf("%s:%+d|g", e.Name, e.Value)}
}