Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add binary chart #2094

Merged
merged 37 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
fde91fb
add binary charts
Terdious Jun 3, 2024
fcc9cd6
Merge branch 'master' into add-binary-chart
Terdious Jun 4, 2024
62489dd
chore: Update y-axis label formatting in ApexChartTimelineOptions.js
Terdious Jun 6, 2024
4e014e9
fix: eslint
Terdious Jun 6, 2024
4688e6a
fix: Update y-axis label formatting and x-axis min/max in ApexChartTi…
Terdious Jun 8, 2024
db73645
fix: Update condition for checking values length in Chart.jsx
Terdious Jun 10, 2024
43ced17
fix: review me
Terdious Jun 10, 2024
0d77b17
fix: Update height calculation in ApexChartComponent
Terdious Jun 10, 2024
0854ef0
Merge branch 'master' into add-binary-chart
Terdious Jun 12, 2024
1acf5a5
fix: prettier
Terdious Jun 12, 2024
85e4754
Merge branch 'master' into add-binary-chart
Terdious Jun 17, 2024
7781260
fix: If select a binary device, then unselect it, then select a non-b…
Terdious Jun 17, 2024
d29a752
debug: add console.log to debug
Terdious Jun 17, 2024
2e94147
fix: On mobile, the popup is outside of the screen
Terdious Jun 17, 2024
f519dd4
fix: prettier + eslint (1 error for debug
Terdious Jun 17, 2024
a27ae0b
refactor: Limit the length of chart labels in ApexChartTimelineOptions
Terdious Jun 17, 2024
7ba0229
Merge branch 'GladysAssistant:master' into add-binary-chart
Terdious Aug 29, 2024
594dbbb
Normalize all the line endings
Terdious Aug 30, 2024
47a3d8d
refactor(chart): Update date format in ApexChartComponent
Terdious Aug 30, 2024
e799d63
chore(chart): Update y-axis label positioning in ApexChartTimelineOpt…
Terdious Sep 2, 2024
b731728
chore(chart): Update y-axis label positioning in ApexChartTimelineOpt…
Terdious Sep 3, 2024
cebce56
feat(chart): Add support for selecting device features and loading ch…
Terdious Sep 3, 2024
ead8043
chore(chart): Update y-axis label positioning in ApexChartTimelineOpt…
Terdious Sep 4, 2024
455a8d4
chore(chart): Update y-axis label positioning in ApexChartTimelineOpt…
Terdious Sep 5, 2024
806b03a
chore(chart): Refactor tooltip content creation in ApexChartComponent
Terdious Sep 5, 2024
c4aa751
feat(chart): Update max_states based on chart type in Chart.jsx
Terdious Sep 5, 2024
500265e
feat(i18n): Add missing data message for different languages
Terdious Sep 13, 2024
28f5f37
feat(chart): Update max_states to 300 in Chart.jsx
Terdious Sep 13, 2024
a7a274e
refactor(chart): Update date format in Chart.jsx
Terdious Sep 13, 2024
4ad7110
refactor(chart): Update date format and max_states in Chart.jsx
Terdious Sep 13, 2024
4f4cb5b
Merge branch 'master' into add-binary-chart
Terdious Sep 13, 2024
276ebb9
refactor(i18n): Remove "missingDataOnInterval" key from language files
Terdious Sep 13, 2024
08df11d
refactor(chart): Update max_states parameter in Chart.jsx
Terdious Sep 30, 2024
49e7ab8
refactor(device): Simplify getDeviceFeaturesAggregates function
Terdious Sep 30, 2024
c29a841
Merge branch 'master' into add-binary-chart
Terdious Oct 4, 2024
04d796e
fixes review
Terdious Oct 4, 2024
8e4932a
prettier
Terdious Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 93 additions & 2 deletions front/src/components/boxs/chart/ApexChartComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getApexChartBarOptions } from './ApexChartBarOptions';
import { getApexChartAreaOptions } from './ApexChartAreaOptions';
import { getApexChartLineOptions } from './ApexChartLineOptions';
import { getApexChartStepLineOptions } from './ApexChartStepLineOptions';
import { getApexChartTimelineOptions } from './ApexChartTimelineOptions';
import mergeArray from '../../../utils/mergeArray';

dayjs.extend(localizedFormat);
Expand Down Expand Up @@ -51,6 +52,66 @@ class ApexChartComponent extends Component {
}
};
}
addDateFormatterRangeBar(options) {
let formatter_custom;
if (this.props.interval <= 24 * 60) {
formatter_custom = opts => {
const startDate = dayjs(opts.y1)
.locale(this.props.user.language)
.format('LLL:ss');
const endDate = dayjs(opts.y2)
.locale(this.props.user.language)
.format('LLL:ss');
const w = opts.ctx.w;
let seriesName = w.config.series[opts.seriesIndex].name ? w.config.series[opts.seriesIndex].name : '';
let ylabel = w.globals.seriesX[opts.seriesIndex][opts.dataPointIndex];
const color = w.globals.colors[opts.seriesIndex];

return `<div class="apexcharts-tooltip-rangebar">
<div> <span class="series-name" style="color: ${color}">
${seriesName ? seriesName : ''}
</span></div>
<div> <span class="category">
${ylabel}:
</span> <span class="value start-value"></br>&nbsp;&nbsp;
Début le: ${startDate}
</span> <span class="value end-value"></br>&nbsp;&nbsp;
Fin le: ${endDate}
</span></div>
</div>`;
};
} else {
formatter_custom = opts => {
const startDate = dayjs(opts.y1)
.locale(this.props.user.language)
.format('LL');
const endDate = dayjs(opts.y2)
.locale(this.props.user.language)
.format('LL');

const w = opts.ctx.w;
const seriesName = w.config.series[opts.seriesIndex].name ? w.config.series[opts.seriesIndex].name : '';
const ylabel = w.globals.seriesX[opts.seriesIndex][opts.dataPointIndex];
const color = w.globals.colors[opts.seriesIndex];

return `<div class="apexcharts-tooltip-rangebar">
<div> <span class="series-name" style="color: ${color}">
${seriesName ? seriesName : ''}
</span></div>
<div> <span class="category">
${ylabel}:
</span> <span class="value start-value"></br>&nbsp;&nbsp;
Début le: ${startDate}
</span> <span class="value end-value"></br>&nbsp;&nbsp;
Fin le: ${endDate}
</span></div>
</div>`;
};
}
options.tooltip.custom = function(opts) {
return formatter_custom(opts);
};
}
getBarChartOptions = () => {
const options = getApexChartBarOptions({
displayAxes: this.props.display_axes,
Expand Down Expand Up @@ -123,9 +184,31 @@ class ApexChartComponent extends Component {
this.addDateFormatter(options);
return options;
};
getTimelineChartOptions = () => {
let height;
if (this.props.size === 'small' && !this.props.display_axes) {
height = 40;
} else if (this.props.size === 'big' && !this.props.display_axes) {
height = 80;
} else {
height = 200 + this.props.heightAdditional;
}
const options = getApexChartTimelineOptions({
height,
colors: mergeArray(this.props.colors, DEFAULT_COLORS),
displayAxes: this.props.display_axes,
series: this.props.series,
locales: [fr, en, de],
defaultLocale: this.props.user.language
});
Terdious marked this conversation as resolved.
Show resolved Hide resolved
this.addDateFormatterRangeBar(options);
return options;
};
displayChart = () => {
let options;
if (this.props.chart_type === 'area') {
if (this.props.chart_type === 'timeline') {
options = this.getTimelineChartOptions();
} else if (this.props.chart_type === 'area') {
options = this.getAreaChartOptions();
} else if (this.props.chart_type === 'line') {
options = this.getLineChartOptions();
Expand All @@ -152,7 +235,15 @@ class ApexChartComponent extends Component {
const displayAxesDifferent = nextProps.display_axes !== this.props.display_axes;
const intervalDifferent = nextProps.interval !== this.props.interval;
const sizeDifferent = nextProps.size !== this.props.size;
if (seriesDifferent || chartTypeDifferent || displayAxesDifferent || intervalDifferent || sizeDifferent) {
const heightAdditionalDifferent = nextProps.heightAdditional !== this.props.heightAdditional;
if (
seriesDifferent ||
chartTypeDifferent ||
displayAxesDifferent ||
intervalDifferent ||
sizeDifferent ||
heightAdditionalDifferent
) {
this.displayChart();
}
}
Expand Down
134 changes: 134 additions & 0 deletions front/src/components/boxs/chart/ApexChartTimelineOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
const addYAxisStyles = () => {
const yAxisLabel = document.querySelectorAll('.apexcharts-yaxis-label');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this coming from?

ApexChart documentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I found this solution on stackoverflow and on apexcharts github

let fontSize = '12px';
yAxisLabel.forEach(text => {
const title = text.querySelector('title');
if (title) {
const textContent = title.textContent;
let lines = textContent.split('\n');
text.innerHTML = '';
lines.forEach((line, index) => {
const tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
if (line.length > 12) {
line = `${line.substring(0, 12)}...`;
}
tspan.setAttribute('x', text.getAttribute('x'));
tspan.setAttribute('dy', index === 0 ? '-0.4em' : '1.2em');
tspan.setAttribute('font-size', fontSize);
tspan.textContent = line;
text.appendChild(tspan);
});
const newTitle = document.createElementNS('http://www.w3.org/2000/svg', 'title');
newTitle.textContent = textContent;
text.appendChild(newTitle);
}
});
};

const getApexChartTimelineOptions = ({ displayAxes, height, series, colors, locales, defaultLocale }) => {
const options = {
series,
chart: {
locales,
defaultLocale,
type: 'rangeBar',
fontFamily: 'inherit',
height,
parentHeightOffset: 0,
sparkline: {
enabled: !displayAxes
},
toolbar: {
show: false
},
animations: {
enabled: true
},
events: {
mounted: addYAxisStyles,
updated: addYAxisStyles
}
},
grid: {
strokeDashArray: 4,
padding: {
left: 1
}
},
plotOptions: {
bar: {
horizontal: true,
barHeight: '50%',
rangeBarGroupRows: true
}
},
colors,
fill: {
type: 'solid'
},
xaxis: {
labels: {
padding: 0,
datetimeUTC: false
},
axisBorder: {
show: false
},
type: 'datetime',
min: Math.min(...series.flatMap(s => s.data.map(d => d.y[0]))),
max: Math.max(...series.flatMap(s => s.data.map(d => d.y[1])))
},
yaxis: {
showAlways: false,
dataLabels: {
enabled: false,
textAnchor: 'start'
},
axisBorder: {
show: true
},
labels: {
align: 'left',
maxWidth: 80,
margin: 0,
formatter: function(value) {

Check warning on line 94 in front/src/components/boxs/chart/ApexChartTimelineOptions.js

View workflow job for this annotation

GitHub Actions / Front test

Expected method shorthand
if (value.length > 12) {
const deviceName = value.split(' (')[0];
const featureName = value.split(' (')[1].replace(')', '');
const newValue = `${deviceName}\n(${featureName})`;
return newValue;
}
return value;
},
offsetX: -20,
offsetY: 0
}
},
legend: {
show: displayAxes,
position: 'bottom',
itemMargin: {
horizontal: 20
}
},
tooltip: {
// theme: 'dark',
marker: {
show: true
},
onDatasetHover: {
highlightDataSeries: true
},
items: {
display: 'flex'
},
fillSeriesColor: false,
fixed: {
enabled: false
}
}
};
return options;
};

export { getApexChartTimelineOptions };
Loading
Loading