mirror of
https://github.com/nasa/openmct.git
synced 2025-06-01 07:00:49 +00:00
[Plot] Try multiple chart options
Choose among multiple chart options, WTD-1070.
This commit is contained in:
parent
eba980c720
commit
3db8c1a32d
@ -87,7 +87,7 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ...and add points to it...
|
// ...and add points to it...
|
||||||
for (i = 2; i < buf.length - 1; i = i + 2) {
|
for (i = 2; i < points * 2; i = i + 2) {
|
||||||
c2d.lineTo(x(buf[i]), y(buf[i + 1]));
|
c2d.lineTo(x(buf[i]), y(buf[i + 1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
* Module defining MCTChart. Created by vwoeltje on 11/12/14.
|
* Module defining MCTChart. Created by vwoeltje on 11/12/14.
|
||||||
*/
|
*/
|
||||||
define(
|
define(
|
||||||
["./GLChart"],
|
["./GLChart", "./Canvas2DChart"],
|
||||||
function (GLChart) {
|
function (GLChart, Canvas2DChart) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var TEMPLATE = "<canvas style='position: absolute; background: none; width: 100%; height: 100%;'></canvas>";
|
var TEMPLATE = "<canvas style='position: absolute; background: none; width: 100%; height: 100%;'></canvas>";
|
||||||
@ -43,22 +43,38 @@ define(
|
|||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function MCTChart($interval, $log) {
|
function MCTChart($interval, $log) {
|
||||||
|
// Get an underlying chart implementation
|
||||||
|
function getChart(Charts, canvas) {
|
||||||
|
// Try the first available option...
|
||||||
|
var Chart = Charts[0];
|
||||||
|
|
||||||
|
// This function recursively try-catches all options;
|
||||||
|
// if these all fail, issue a warning.
|
||||||
|
if (!Chart) {
|
||||||
|
$log.warn("Cannot initialize mct-chart.");
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try first option; if it fails, try remaining options
|
||||||
|
try {
|
||||||
|
return new Chart(canvas);
|
||||||
|
} catch (e) {
|
||||||
|
$log.warn([
|
||||||
|
"Could not instantiate chart",
|
||||||
|
Chart.name,
|
||||||
|
";",
|
||||||
|
e.message
|
||||||
|
].join(" "));
|
||||||
|
|
||||||
|
return getChart(Charts.slice(1), canvas);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function linkChart(scope, element) {
|
function linkChart(scope, element) {
|
||||||
var canvas = element.find("canvas")[0],
|
var canvas = element.find("canvas")[0],
|
||||||
activeInterval,
|
activeInterval,
|
||||||
chart;
|
chart;
|
||||||
|
|
||||||
// Try to initialize GLChart, which allows drawing using WebGL.
|
|
||||||
// This may fail, particularly where browsers do not support
|
|
||||||
// WebGL, so catch that here.
|
|
||||||
try {
|
|
||||||
chart = new GLChart(canvas);
|
|
||||||
} catch (e) {
|
|
||||||
$log.warn("Cannot initialize mct-chart; " + e.message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle drawing, based on contents of the "draw" object
|
// Handle drawing, based on contents of the "draw" object
|
||||||
// in scope
|
// in scope
|
||||||
function doDraw(draw) {
|
function doDraw(draw) {
|
||||||
@ -118,6 +134,15 @@ define(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to initialize a chart.
|
||||||
|
chart = getChart([GLChart, Canvas2DChart], canvas);
|
||||||
|
|
||||||
|
// If that failed, there's nothing more we can do here.
|
||||||
|
// (A warning will already have been issued)
|
||||||
|
if (!chart) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check for resize, on a timer
|
// Check for resize, on a timer
|
||||||
activeInterval = $interval(drawIfResized, 1000);
|
activeInterval = $interval(drawIfResized, 1000);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user