Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

very wide horizontal svg render is missing the time axis with a variable set width #41

Open
jeffwillette opened this issue May 22, 2017 · 3 comments

Comments

@jeffwillette
Copy link
Contributor

sorry for the confusing title, but I have a strange situation where I am setting the width by the number of data points I have...

graph.Width = (len(data.Time) / 30) * 4

I have 30 reading from an accelerometer every second so I am making each second of data 4 pixels wide (I believe)

Here is the code that I am using:

func main() {
	fileName := os.Args[1]
	readFile := fmt.Sprintf("./%s", fileName)
	outFile := fmt.Sprintf("./%s.svg", strings.Split(fileName, ".")[0])
	fmt.Println(readFile, outFile)
	data, err := readAccelerometerFile(readFile)
	var x []float64
	for i := range data.Time {
		//fmt.Println(data.Time[i], data.Time[i].Unix())
		x = append(x, float64(data.Time[i].UnixNano()))
	}
	fmt.Println(len(data.X), len(data.Time))

	graph := chart.Chart{
		XAxis: chart.XAxis{
			Style: chart.Style{
				Show: true,
			},
			ValueFormatter: func(v interface{}) string {
				typed := v.(float64)
				typedDate := util.Time.FromFloat64(typed)
				return fmt.Sprintf("%d:%d:%d", typedDate.Hour(), typedDate.Minute(), typedDate.Second())
			},
		},
		YAxis: chart.YAxis{
			Style: chart.Style{
				Show: true,
			},
			GridMajorStyle: chart.Style{
				Show:        true,
				StrokeColor: chart.ColorAlternateLightGray,
				StrokeWidth: 1.0,
			},
			GridLines: []chart.GridLine{
				chart.GridLine{Value: -6.0},
				chart.GridLine{Value: -4.0},
				chart.GridLine{Value: -2.0},
				chart.GridLine{Value: 2.0},
				chart.GridLine{Value: 4.0},
				chart.GridLine{Value: 6.0},
			},
		},
		Series: []chart.Series{
			chart.ContinuousSeries{ // x axis acceleration
				XValues: x,
				YValues: data.Z,
			},
			chart.ContinuousSeries{ // x axis acceleration
				XValues: x,
				YValues: data.X,
			},
			chart.ContinuousSeries{ // x axis acceleration
				XValues: x,
				YValues: data.Y,
			},
		},
	}

	graph.Width = (len(data.Time) / 30) * 4
	buffer := bytes.NewBuffer([]byte{})
	err = graph.Render(chart.SVG, buffer)
	if err != nil {
		fmt.Println(err)
	}

	err = ioutil.WriteFile(outFile, buffer.Bytes(), 0644)
	if err != nil {
		fmt.Println(err)
	}
}

If youll notice, I have printed the length to verify that the length of the Y-axis data is the same as the X(time) axis data. it prints 482980 482980 so they are the same.

If I use a pixel width per second of 4 (like in the example above) everything comes out ok, like this example file: (sorry, GH will not accept the file, and it is about 15mb)

http://s000.tinyupload.com/index.php?file_id=25360982963139220109

but if I change the number to 8 or 16 which is where I want it, the time axis stops at a certain point.

http://s000.tinyupload.com/index.php?file_id=02149796522295593801

@jeffwillette
Copy link
Contributor Author

this is width set to 4 pixels per second

screen shot 2017-05-23 at 11 00 15 am

this is set to 8 pixels per second

screen shot 2017-05-23 at 11 00 47 am

the end of the 8 pixels per second chart still has the correct end time

screen shot 2017-05-23 at 11 01 00 am

@jeffwillette
Copy link
Contributor Author

The fix doesn't fix the underlying issue, but it would have been much easier for me to find the cause if the proper variable was used from defaults.go

@wcharczuk
Copy link
Owner

ack, good catch

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants