Skip to content

Adding strict- pattern to the PlotlyViaCDNModule.setPlotlyVersion method #238

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

Merged
merged 19 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Changelog


## [5.1.1] - 2023-06-15
### Changed
- Adding support to strict version of bundle plotly (see https://github.com/plotly/angular-plotly.js/issues/237)

## [5.1.0] - 2023-04-10
### Changed
- Updated to Angular 15

## [5.0.0] - 2023-03-29
### Changed
- Updated to Angular 13
Expand Down
27 changes: 23 additions & 4 deletions projects/plotly/src/lib/plotly-via-cdn.module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,31 @@ describe('PlotlyViaCDNModule', () => {
});

it('should NOT set Plotly version', () => {
const version = "invalid";
const errorMsg= "Invalid plotly version. Please set 'latest' or version number (i.e.: 1.4.3) or strict version number (i.e.: strict-1.4.3)";
spyOn(PlotlyViaCDNModule, "loadViaCDN").and.callThrough();

expect(() => {
PlotlyViaCDNModule.setPlotlyVersion(version);
}).toThrowError("Invalid plotly version. Please set 'latest' or version number (i.e.: 1.4.3)");
let version = "invalid";
expect(() => { PlotlyViaCDNModule.setPlotlyVersion(version); }).toThrowError(errorMsg);

version = "strict-1";
expect(() => { PlotlyViaCDNModule.setPlotlyVersion(version); }).toThrowError(errorMsg);

version = "1";
expect(() => { PlotlyViaCDNModule.setPlotlyVersion(version); }).toThrowError(errorMsg);

version = "strict-1.1.a";
expect(() => { PlotlyViaCDNModule.setPlotlyVersion(version); }).toThrowError(errorMsg);

version = "strit-1.1.1";
expect(() => { PlotlyViaCDNModule.setPlotlyVersion(version); }).toThrowError(errorMsg);
});

it('should allow Plotly version with strict- at the beginning', () => {
const version = "strict-2.24.1";
spyOn(PlotlyViaCDNModule, "loadViaCDN");

PlotlyViaCDNModule.setPlotlyVersion(version);
expect((PlotlyViaCDNModule as any).plotlyVersion).toBe(version);
});
});
});
4 changes: 2 additions & 2 deletions projects/plotly/src/lib/plotly-via-cdn.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export class PlotlyViaCDNModule {
}

public static setPlotlyVersion(version: string): void {
const isOk = version === 'latest' || /^\d\.\d{1,2}\.\d{1,2}$/.test(version);
const isOk = version === 'latest' || /^(strict-)?\d\.\d{1,2}\.\d{1,2}$/.test(version);
if (!isOk) {
throw new Error(`Invalid plotly version. Please set 'latest' or version number (i.e.: 1.4.3)`);
throw new Error(`Invalid plotly version. Please set 'latest' or version number (i.e.: 1.4.3) or strict version number (i.e.: strict-1.4.3)`);
}

PlotlyViaCDNModule.loadViaCDN();
Expand Down
20 changes: 14 additions & 6 deletions projects/plotly/src/lib/plotly.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class PlotlyComponent implements OnInit, OnChanges, OnDestroy, DoCheck {
@Output() animationInterrupted = new EventEmitter();
@Output() autoSize = new EventEmitter();
@Output() beforeExport = new EventEmitter();
@Output() beforeHover = new EventEmitter();
@Output() buttonClicked = new EventEmitter();
/**
* @deprecated DEPRECATED: Reconsider using `(plotlyClick)` instead of `(click)` to avoid event conflict. Please check https://github.com/plotly/angular-plotly.js#FAQ
Expand All @@ -83,27 +84,34 @@ export class PlotlyComponent implements OnInit, OnChanges, OnDestroy, DoCheck {
@Output() hover = new EventEmitter();
@Output() legendClick = new EventEmitter();
@Output() legendDoubleClick = new EventEmitter();
/**
* @deprecated DEPRECATED: Event react is not list as an plotly.js event
*/
@Output() react = new EventEmitter();
@Output() relayout = new EventEmitter();
@Output() relayouting = new EventEmitter();
@Output() restyle = new EventEmitter();
@Output() redraw = new EventEmitter();
@Output() selected = new EventEmitter();
@Output() selecting = new EventEmitter();
@Output() sliderChange = new EventEmitter();
@Output() sliderEnd = new EventEmitter();
@Output() sliderStart = new EventEmitter();
@Output() sunburstclick = new EventEmitter();
@Output() transitioning = new EventEmitter();
@Output() transitionInterrupted = new EventEmitter();
@Output() unhover = new EventEmitter();
@Output() relayouting = new EventEmitter();
/**
* @deprecated DEPRECATED: Event treemapclick is not list as an plotly.js event
*/
@Output() treemapclick = new EventEmitter();
@Output() sunburstclick = new EventEmitter();
@Output() webglcontextlost = new EventEmitter();


public eventNames = ['afterExport', 'afterPlot', 'animated', 'animatingFrame', 'animationInterrupted', 'autoSize',
'beforeExport', 'buttonClicked', 'clickAnnotation', 'deselect', 'doubleClick', 'framework', 'hover',
'legendClick', 'legendDoubleClick', 'react', 'relayout', 'restyle', 'redraw', 'selected', 'selecting', 'sliderChange',
'sliderEnd', 'sliderStart', 'transitioning', 'transitionInterrupted', 'unhover', 'relayouting', 'treemapclick',
'sunburstclick'];
'beforeExport', 'beforeHover', 'buttonClicked', 'clickAnnotation', 'deselect', 'doubleClick', 'framework', 'hover',
'legendClick', 'legendDoubleClick', 'react', 'relayout', 'relayouting', 'restyle', 'redraw', 'selected', 'selecting', 'sliderChange',
'sliderEnd', 'sliderStart', 'sunburstclick', 'transitioning', 'transitionInterrupted', 'unhover', 'treemapclick', 'webglcontextlost'];

constructor(
public plotly: PlotlyService,
Expand Down