Skip to content

[IMPROVEMENT] Drawing lines #25

@WoodySlum

Description

@WoodySlum

Hi !

I'm currently working on a line chart. I successfully display points (with squares), but I didn't found a way to display lines (maybe by using lot of 1px squares).

Would it be possible to add drawable lines ?

Here is my (current) code for drawing my temperature chart :

                var temperatureObjects = JSON.parse(subReq.responseText);
                var maxVal = 0;
                var minVal = 100;
                temperatureObjects.forEach(function(notification) {
                    if (notification.tmp > maxVal) maxVal = notification.tmp;
                    if (notification.tmp < minVal) minVal = notification.tmp;
                });


                var pointList = [];
                var difference = maxVal - minVal;
                var screenHeight = 144;
                var screenWidth = 168;
                var screenHeightAdjust = 20;
                var screeWidthAdjust = 20;
                var totalElts = temperatureObjects.length;
                var startX = parseInt(screeWidthAdjust / 2);
                // if (screeWidthAdjust > 0) startX = parseInt((screenWidth - screeWidthAdjust) / 2);
                var step = parseInt((screenWidth - screeWidthAdjust) / totalElts);
                temperatureObjects.forEach(function(notification) {
                  var stdVal = notification.tmp - minVal;
                  var x = startX;
                  var y = screenHeight-parseInt((stdVal*screenHeight)/difference) + screenHeightAdjust;
                  // console.log(notification.tmp + ' -> ' +y);
                  startX += step;
                  pointList.push({x: x, y: y});
                });

                var chart = new UI.Window();
                pointList.forEach(function(point) {
                  var element = new UI.Rect({ position: new Vector2(0, 0), size: new Vector2(5, 5) });
                  element.backgroundColor('white');
                  element.borderColor('white');
                  chart.add(element);
                  element.animate('position', new Vector2(point.x, point.y), 1000);
                });
                //var rect = new UI.Rect({ position: new Vector2(2, ), size: new Vector2(5, 5) });
                //chart.add(rect);
                chart.show();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions