33
33
#include " qwt_plot_renderer.h"
34
34
#include " qwt_series_data.h"
35
35
#include " qwt_date_scale_draw.h"
36
- #include " PlotJuggler/random_color.h"
37
36
#include " point_series_xy.h"
38
37
#include " suggest_dialog.h"
39
38
#include " transforms/custom_function.h"
40
39
#include " transforms/custom_timeseries.h"
41
40
41
+ int PlotWidget::global_color_index = 0 ;
42
+
43
+ QColor PlotWidget::getColorHint (PlotData* data)
44
+ {
45
+ QSettings settings;
46
+ bool remember_color = settings.value (" Preferences::remember_color" , true ).toBool ();
47
+ if ( data && remember_color && data->getColorHint () != Qt::black )
48
+ {
49
+ return data->getColorHint ();
50
+ }
51
+ QColor color;
52
+ bool use_plot_color_index = settings.value (" Preferences::use_plot_color_index" , false ).toBool ();
53
+ int index = _curve_list.size ();
54
+
55
+ if ( !use_plot_color_index )
56
+ {
57
+ index = (PlotWidget::global_color_index++);
58
+ }
59
+
60
+ // https://matplotlib.org/3.1.1/users/dflt_style_changes.html
61
+ switch ( index %8 )
62
+ {
63
+ case 0 : color = QColor (" #1f77b4" ); break ;
64
+ case 1 : color = QColor (" #d62728" ); break ;
65
+ case 2 : color = QColor (" #1ac938" ); break ;
66
+ case 3 : color = QColor (" #ff7f0e" ); break ;
67
+
68
+ case 4 : color = QColor (" #f14cc1" ); break ;
69
+ case 5 : color = QColor (" #9467bd" ); break ;
70
+ case 6 : color = QColor (" #17becf" ); break ;
71
+ case 7 : color = QColor (" #bcbd22" ); break ;
72
+ }
73
+ if ( data ){
74
+ data->setColorHint (color);
75
+ }
76
+
77
+ return color;
78
+ }
79
+
42
80
class TimeScaleDraw : public QwtScaleDraw
43
81
{
44
82
virtual QwtText label (double v) const
@@ -82,6 +120,7 @@ PlotWidget::PlotWidget(PlotDataMapRef &datamap, QWidget *parent):
82
120
_xy_mode(false ),
83
121
_transform_select_dialog(nullptr ),
84
122
_use_date_time_scale(false ),
123
+ _color_index(0 ),
85
124
_zoom_enabled(true ),
86
125
_keep_aspect_ratio(true )
87
126
{
@@ -369,12 +408,8 @@ bool PlotWidget::addCurve(const std::string &name)
369
408
370
409
curve->setStyle ( _curve_style );
371
410
372
- QColor color = data.getColorHint ();
373
- if ( color == Qt::black)
374
- {
375
- color = randomColorHint ();
376
- data.setColorHint (color);
377
- }
411
+ QColor color = getColorHint (&data);
412
+
378
413
curve->setPen ( color, (_curve_style == QwtPlotCurve::Dots) ? 4 : 1.0 );
379
414
curve->setRenderHint ( QwtPlotItem::RenderAntialiased, true );
380
415
@@ -443,7 +478,6 @@ bool PlotWidget::addCurveXY(std::string name_x, std::string name_y,
443
478
return false ;
444
479
}
445
480
446
- PlotData& data = it->second ;
447
481
const auto qname = QString::fromStdString ( name );
448
482
449
483
auto curve = new QwtPlotCurve ( qname );
@@ -463,7 +497,7 @@ bool PlotWidget::addCurveXY(std::string name_x, std::string name_y,
463
497
464
498
curve->setStyle ( _curve_style );
465
499
466
- QColor color = randomColorHint ( );
500
+ QColor color = getColorHint ( nullptr );
467
501
468
502
curve->setPen ( color, (_curve_style == QwtPlotCurve::Dots) ? 4 : 1.0 );
469
503
curve->setRenderHint ( QwtPlotItem::RenderAntialiased, true );
0 commit comments