NAPISD
PAHdb website C++ backend
Loading...
Searching...
No Matches
Axis.cpp
1#include "Axis.h"
2
3Axis::Axis()
4 : _title(""), _axisoptstr("bcnst"), _precision(1), _maxdigits(6),
5 _style(Axis::Style::Default), _label_callback(nullptr),
6 _tick_callback(nullptr) {}
7
8void Axis::_set(char option, bool on = true) {
9
10 std::string::size_type i = _axisoptstr.find(option);
11
12 if (on && i == std::string::npos) {
13
14 _axisoptstr.append(1, option);
15 }
16
17 if (!on && i != std::string::npos) {
18
19 _axisoptstr.erase(i, 1);
20 }
21}
22
23void Axis::_reciprocal_labeller(PLINT axis, PLFLT value, PLCHAR_NC_VECTOR label,
24 PLINT length, PLPointer data) {
25
26 if (value == 0.0) {
27
28 *label = '\0';
29
30 return;
31 }
32
33 snprintf(label, length, "%g", 1e4 / value);
34}
35
36PLINT Axis::_reciprocal_tickfinder(PLINT axis, PLINT nticks, PLFLT *ticks,
37 PLFLT min, PLFLT max, PLPointer data) {
38
39 PLFLT density = 0.02;
40
41 if (min > max) {
42
43 std::swap(min, max);
44 }
45
46 PLFLT w_min = 1e4 / max;
47 PLFLT w_max = 1e4 / min;
48
49 PLFLT o_min = log10(w_min);
50 PLFLT o_max = log10(w_max);
51 PLFLT o_rng = log10(w_max - w_min);
52
53 PLFLT order = (o_max - o_min) < 1.0 ? round(o_rng) - 1.0 : floor(o_min);
54
55 PLFLT delta = pow(10.0, order);
56
57 PLINT n = 0;
58
59 PLFLT tick = pow(10, order) * ceil(w_min * pow(10, -order));
60
61 if (tick != w_min) {
62 PLFLT t = w_min * pow(10.0, -floor(o_min));
63 if (fmod(t, 0.1) == 0.0 || fmod(t, 0.25) == 0.0) {
64 if (n < nticks) {
65 ticks[n++] = w_min;
66 }
67 }
68 }
69
70 while (tick < w_max) {
71 if (n < nticks) {
72 ticks[n++] = tick;
73 }
74 tick += delta;
75 if ((1e4 / ticks[n - 1] - 1e4 / tick) / (max - min) < density) {
76 break;
77 }
78 }
79
80 if (ticks[n - 1] != w_max) {
81 PLFLT t = w_max * pow(10.0, -floor(o_max));
82 if (fmod(t, 0.1) == 0.0 || fmod(t, 0.25) == 0.0) {
83 if (n < nticks) {
84 ticks[n++] = w_max;
85 }
86 }
87 }
88
89 for (PLINT i = 0; i < n; i++) {
90 ticks[i] = 1e4 / ticks[i];
91 }
92
93 return n;
94}
Definition Axis.h:16

Since FY2019 the NASA Ames PAH IR Spectroscopic Database is being supported through a directed Work Package at NASA Ames titled: "Laboratory Astrophysics - The NASA Ames PAH IR Spectroscopic Database".
Since FY2023 the NASA Ames PAH IR Spectroscopic Database is being supported through the Laboratory Astrophysics Rd 2 directed Work Package at NASA Ames.
© Copyright 2021-2025, Christiaan Boersma