• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zooniverse / Panoptes-Front-End / 9976405917

17 Jul 2024 02:45PM UTC coverage: 56.865% (-0.08%) from 56.948%
9976405917

Pull #7123

github

web-flow
Merge 939d23516 into 2d0f81aa1
Pull Request #7123: refactor(subject previews): allow for single series JSON data subjects

7294 of 13080 branches covered (55.76%)

Branch coverage included in aggregate %.

0 of 16 new or added lines in 1 file covered. (0.0%)

5 existing lines in 2 files now uncovered.

8597 of 14865 relevant lines covered (57.83%)

103.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

14.0
/app/features/modelling/line-plot/index.js
1
import { Chart } from 'chart.js/auto';
21!
2

3
function getXYData(data) {
NEW
4
  return {
×
NEW
5
    data: data.x.map((x, index) => ({ x, y: data.y[index] })),
×
6
    pointStyle: 'circle',
7
    backgroundColor: '#ffffff',
8
    borderColor: '#000000'
9
  }
10
}
11

12
function getSeriesData(series, index) {
NEW
13
  const { seriesData, seriesOptions } = series;
×
NEW
14
  return {
×
15
    data: seriesData,
16
    label: seriesOptions.label || `Series ${index + 1}`,
×
17
    pointStyle: seriesOptions.glyph,
18
    backgroundColor: seriesOptions.color,
19
    borderColor: '#000000'
20
  };
21
}
22

23
function getDatasets(data) {
NEW
24
  if (data?.datasets) {
×
NEW
25
    return data.datasets;
×
26
  }
NEW
27
  if (data?.map) {
×
NEW
28
    return data.map(getSeriesData);
×
29
  }
NEW
30
  if (data?.x && data?.y) {
×
NEW
31
    return [getXYData(data)];
×
32
  }
NEW
33
  return [];
×
34
}
35

36
// Help at http://www.chartjs.org/docs/latest
37
class LinePlotModel {
1✔
38
  constructor(canvas, { frame, src }, { onLoad, modelDidError }) {
×
39
    this.ctx = canvas.getContext('2d');
×
40
    console.log('Line Plot', this.ctx, frame, src);
×
41
    this.frame = frame;
×
42
    fetch(`${src}?=`)
×
43
      .then(response => response.json())
×
44
      .then(data => {
NEW
45
        if(data.x && data.y) {
×
NEW
46
          return {
×
47
            data: {
48
              x: data.x,
49
              y: data.y
50
            },
51
            chartOptions: {
52
              xAxisLabel: 'Days',
53
              yAxisLabel: 'Brightness'
54
            }
55
          };
56
        }
NEW
57
        return data;
×
58
      })
NEW
59
      .then(({ data, chartOptions, ...rest }) => {
×
NEW
60
        const datasets = getDatasets(data);
×
UNCOV
61
        console.log({
×
62
          type: 'scatter',
63
          data: {
64
            datasets,
65
            ...rest
66
          }
67
        });
68
        this.lineChart = new Chart(
×
69
          this.ctx,
70
          {
71
            type: 'scatter',
72
            data: {
73
              datasets,
74
              ...rest
75
            },
76
            options: {
77
              plugins: {
78
                legend: {
79
                  labels: {
80
                    usePointStyle: true
81
                  }
82
                }
83
              },
84
              scales: {
85
                x: {
86
                  reverse: chartOptions?.invertAxes?.x || false,
×
87
                  title: {
88
                    display: true,
89
                    text: chartOptions?.xAxisLabel
×
90
                  }
91
                },
92
                y: {
93
                  reverse: chartOptions?.invertAxes?.y || false,
×
94
                  title: {
95
                    display: true,
96
                    text: chartOptions?.yAxisLabel
×
97
                  }
98
                }
99
              }
100
            }
101
          }
102
        );
103
        const { height, width } = canvas.getBoundingClientRect()
×
104
        onLoad({ height, width })
×
105
      })
106
      .catch((error) => {
107
        modelDidError({ modelErrorMessage: error.message })
×
108
        console.warn(error);
×
109
      });
110
  }
1✔
111
  update() {
112
    return null;
×
113
  }
44!
114
}
115

116
export default LinePlotModel;
23!
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc