qwt_plot_abstract_barchart.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
11 #include "qwt_scale_map.h"
12 #include "qwt_math.h"
13 
14 static inline double qwtTransformWidth(
15  const QwtScaleMap &map, double value, double width )
16 {
17  const double w2 = 0.5 * width;
18 
19  const double v1 = map.transform( value - w2 );
20  const double v2 = map.transform( value + w2 );
21 
22  return qAbs( v2 - v1 );
23 }
24 
26 {
27 public:
30  layoutHint( 0.5 ),
31  spacing( 10 ),
32  margin( 5 ),
33  baseline( 0.0 )
34  {
35  }
36 
38  double layoutHint;
39  int spacing;
40  int margin;
41  double baseline;
42 };
43 
49  QwtPlotSeriesItem( title )
50 {
51  d_data = new PrivateData;
52 
56  setZ( 19.0 );
57 }
58 
61 {
62  delete d_data;
63 }
64 
74 {
75  if ( policy != d_data->layoutPolicy )
76  {
77  d_data->layoutPolicy = policy;
78  itemChanged();
79  }
80 }
81 
90 {
91  return d_data->layoutPolicy;
92 }
93 
103 {
104  hint = qwtMaxF( 0.0, hint );
105  if ( hint != d_data->layoutHint )
106  {
107  d_data->layoutHint = hint;
108  itemChanged();
109  }
110 }
111 
120 {
121  return d_data->layoutHint;
122 }
123 
133 {
134  spacing = qMax( spacing, 0 );
135  if ( spacing != d_data->spacing )
136  {
138  itemChanged();
139  }
140 }
141 
147 {
148  return d_data->spacing;
149 }
161 {
162  margin = qMax( margin, 0 );
163  if ( margin != d_data->margin )
164  {
165  d_data->margin = margin;
166  itemChanged();
167  }
168 }
169 
177 {
178  return d_data->margin;
179 }
180 
196 {
197  if ( value != d_data->baseline )
198  {
199  d_data->baseline = value;
200  itemChanged();
201  }
202 }
203 
209 {
210  return d_data->baseline;
211 }
212 
226  double canvasSize, double boundingSize, double value ) const
227 {
228  double width;
229 
230  switch( d_data->layoutPolicy )
231  {
232  case ScaleSamplesToAxes:
233  {
234  width = qwtTransformWidth( map, value, d_data->layoutHint );
235  break;
236  }
237  case ScaleSampleToCanvas:
238  {
239  width = canvasSize * d_data->layoutHint;
240  break;
241  }
242  case FixedSampleSize:
243  {
244  width = d_data->layoutHint;
245  break;
246  }
247  case AutoAdjustSamples:
248  default:
249  {
250  const size_t numSamples = dataSize();
251 
252  double w = 1.0;
253  if ( numSamples > 1 )
254  {
255  w = qAbs( boundingSize / ( numSamples - 1 ) );
256  }
257 
258  width = qwtTransformWidth( map, value, w );
259  width -= d_data->spacing;
260  width = qwtMaxF( width, d_data->layoutHint );
261  }
262  }
263 
264  return width;
265 }
266 
290  const QwtScaleMap &yMap, const QRectF &canvasRect,
291  double &left, double &top, double &right, double &bottom ) const
292 {
293  double hint = -1.0;
294 
295  switch( layoutPolicy() )
296  {
297  case ScaleSampleToCanvas:
298  {
299  if ( orientation() == Qt::Vertical )
300  hint = 0.5 * canvasRect.width() * d_data->layoutHint;
301  else
302  hint = 0.5 * canvasRect.height() * d_data->layoutHint;
303 
304  break;
305  }
306  case FixedSampleSize:
307  {
308  hint = 0.5 * d_data->layoutHint;
309  break;
310  }
311  case AutoAdjustSamples:
312  case ScaleSamplesToAxes:
313  default:
314  {
315  const size_t numSamples = dataSize();
316  if ( numSamples <= 0 )
317  break;
318 
319  // doesn't work for nonlinear scales
320 
321  const QRectF br = dataRect();
322  double spacing = 0.0;
323  double sampleWidthS = 1.0;
324 
325  if ( layoutPolicy() == ScaleSamplesToAxes )
326  {
327  sampleWidthS = qwtMaxF( d_data->layoutHint, 0.0 );
328  }
329  else
330  {
331  spacing = d_data->spacing;
332 
333  if ( numSamples > 1 )
334  {
335  sampleWidthS = qAbs( br.width() / ( numSamples - 1 ) );
336  }
337  }
338 
339  double ds, w;
340  if ( orientation() == Qt::Vertical )
341  {
342  ds = qAbs( xMap.sDist() );
343  w = canvasRect.width();
344  }
345  else
346  {
347  ds = qAbs( yMap.sDist() );
348  w = canvasRect.height();
349  }
350 
351  const double sampleWidthP = ( w - spacing * ( numSamples - 1 ) )
352  * sampleWidthS / ( ds + sampleWidthS );
353 
354  hint = 0.5 * sampleWidthP;
355  hint += qMax( d_data->margin, 0 );
356  }
357  }
358 
359  if ( orientation() == Qt::Vertical )
360  {
361  left = right = hint;
362  top = bottom = -1.0; // no hint
363  }
364  else
365  {
366  left = right = -1.0; // no hint
367  top = bottom = hint;
368  }
369 }
Qt::Orientation orientation() const
QwtPlotAbstractBarChart(const QwtText &title)
enum MQTTPropertyCodes value
static double qwtTransformWidth(const QwtScaleMap &map, double value, double width)
lu_byte right
Definition: lparser.c:1229
QWT_CONSTEXPR float qwtMaxF(float a, float b)
Definition: qwt_math.h:123
double sDist() const
virtual ~QwtPlotAbstractBarChart()
Destructor.
lu_byte left
Definition: lparser.c:1228
Abstract base class for bar chart items.
QwtPlotAbstractBarChart::LayoutPolicy layoutPolicy
void setMargin(int)
Set the margin.
void setSpacing(int)
Set the spacing.
LayoutPolicy
Mode how to calculate the bar width.
The item is represented on the legend.
double sampleWidth(const QwtScaleMap &map, double canvasSize, double boundingSize, double value) const
A class representing a text.
Definition: qwt_text.h:51
void setZ(double z)
Set the z value.
A scale map.
Definition: qwt_scale_map.h:26
virtual void getCanvasMarginHint(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, double &left, double &top, double &right, double &bottom) const QWT_OVERRIDE
Calculate a hint for the canvas margin.
virtual void itemChanged()
int top(lua_State *L)
Definition: sol.hpp:10543
virtual size_t dataSize() const =0
void setBaseline(double)
Set the baseline.
Base class for plot items representing a series of samples.
void setItemAttribute(ItemAttribute, bool on=true)
double transform(double s) const
virtual QRectF dataRect() const =0
const QwtText & title() const


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10